|
|
|
@ -7,6 +7,16 @@ import imapclient
|
|
|
|
|
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):
|
|
|
|
|
"""
|
|
|
|
|
This is just a convenience class for holding email message data.
|
|
|
|
@ -57,8 +67,9 @@ class MailRoom(Bureau):
|
|
|
|
|
def _connect_imap(self):
|
|
|
|
|
try:
|
|
|
|
|
self.imapserv.select_folder("INBOX")
|
|
|
|
|
except imaplib.error:
|
|
|
|
|
except imaplib.abort:
|
|
|
|
|
self.imapserv.login(self.login, self.password)
|
|
|
|
|
self.imapserv.select_folder("INBOX")
|
|
|
|
|
|
|
|
|
|
def get_imap_id(self, msgid):
|
|
|
|
|
"""
|
|
|
|
@ -94,11 +105,11 @@ class MailRoom(Bureau):
|
|
|
|
|
|
|
|
|
|
# format and tidy header data
|
|
|
|
|
msg = Message()
|
|
|
|
|
msg.fromstr = make_header(decode_header(msg_obj['From']))
|
|
|
|
|
msg.tostr = make_header(decode_header(msg_obj['To']))
|
|
|
|
|
msg.subject = make_header(decode_header(msg_obj['Subject']))
|
|
|
|
|
msg.fromstr = clean_header(msg_obj['From'])
|
|
|
|
|
msg.tostr = clean_header(msg_obj['To'])
|
|
|
|
|
msg.subject = clean_header(msg_obj['Subject'])
|
|
|
|
|
if 'Cc' in msg_obj:
|
|
|
|
|
msg.cc = make_header(decode_header(msg_obj['Cc']))
|
|
|
|
|
msg.cc = clean_header(msg_obj['Cc'])
|
|
|
|
|
else:
|
|
|
|
|
msg.cc = None
|
|
|
|
|
msg.date = internaldate
|
|
|
|
@ -114,6 +125,9 @@ class MailRoom(Bureau):
|
|
|
|
|
# should clean these up on delete
|
|
|
|
|
if part.get_content_type() == "text/plain":
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|