|
|
@ -7,6 +7,16 @@ import imapclient
|
|
|
|
from bureau import Bureau, add_command, add_api
|
|
|
|
from bureau import Bureau, add_command, add_api
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clean_header(header):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Converts header string to unicode with HTML entities
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
header = str(make_header(decode_header(header)))
|
|
|
|
|
|
|
|
header = header.replace("<", "<")
|
|
|
|
|
|
|
|
header = header.replace(">", ">")
|
|
|
|
|
|
|
|
return header
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Message(object):
|
|
|
|
class Message(object):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
This is just a convenience class for holding email message data.
|
|
|
|
This is just a convenience class for holding email message data.
|
|
|
@ -57,8 +67,9 @@ class MailRoom(Bureau):
|
|
|
|
def _connect_imap(self):
|
|
|
|
def _connect_imap(self):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.imapserv.select_folder("INBOX")
|
|
|
|
self.imapserv.select_folder("INBOX")
|
|
|
|
except imaplib.error:
|
|
|
|
except imaplib.abort:
|
|
|
|
self.imapserv.login(self.login, self.password)
|
|
|
|
self.imapserv.login(self.login, self.password)
|
|
|
|
|
|
|
|
self.imapserv.select_folder("INBOX")
|
|
|
|
|
|
|
|
|
|
|
|
def get_imap_id(self, msgid):
|
|
|
|
def get_imap_id(self, msgid):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -94,11 +105,11 @@ class MailRoom(Bureau):
|
|
|
|
|
|
|
|
|
|
|
|
# format and tidy header data
|
|
|
|
# format and tidy header data
|
|
|
|
msg = Message()
|
|
|
|
msg = Message()
|
|
|
|
msg.fromstr = make_header(decode_header(msg_obj['From']))
|
|
|
|
msg.fromstr = clean_header(msg_obj['From'])
|
|
|
|
msg.tostr = make_header(decode_header(msg_obj['To']))
|
|
|
|
msg.tostr = clean_header(msg_obj['To'])
|
|
|
|
msg.subject = make_header(decode_header(msg_obj['Subject']))
|
|
|
|
msg.subject = clean_header(msg_obj['Subject'])
|
|
|
|
if 'Cc' in msg_obj:
|
|
|
|
if 'Cc' in msg_obj:
|
|
|
|
msg.cc = make_header(decode_header(msg_obj['Cc']))
|
|
|
|
msg.cc = clean_header(msg_obj['Cc'])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
msg.cc = None
|
|
|
|
msg.cc = None
|
|
|
|
msg.date = internaldate
|
|
|
|
msg.date = internaldate
|
|
|
@ -114,6 +125,9 @@ class MailRoom(Bureau):
|
|
|
|
# should clean these up on delete
|
|
|
|
# should clean these up on delete
|
|
|
|
if part.get_content_type() == "text/plain":
|
|
|
|
if part.get_content_type() == "text/plain":
|
|
|
|
msg.content = part.get_payload(decode=True).decode("utf-8")
|
|
|
|
msg.content = part.get_payload(decode=True).decode("utf-8")
|
|
|
|
|
|
|
|
msg.content = msg.content.replace("<", "<")
|
|
|
|
|
|
|
|
msg.content = msg.content.replace(">", ">")
|
|
|
|
|
|
|
|
msg.content = msg.content.replace("\n", "<br />")
|
|
|
|
|
|
|
|
|
|
|
|
self.print_full("email.html", msg=msg, shortcode=shortcode)
|
|
|
|
self.print_full("email.html", msg=msg, shortcode=shortcode)
|
|
|
|
|
|
|
|
|
|
|
|