diff --git a/screenless/bureau/mailroom/mailroom.py b/screenless/bureau/mailroom/mailroom.py index 0c3e441..94cefa7 100644 --- a/screenless/bureau/mailroom/mailroom.py +++ b/screenless/bureau/mailroom/mailroom.py @@ -102,10 +102,13 @@ class MailRoom(Bureau): """ util tidies up message headers deals with encoding """ + #TODO: consider replacing this whole mess with + # https://pypi.python.org/pypi/mail-parser internaldate = resp_obj[b'INTERNALDATE'] msg_data = resp_obj[imap_id][b'RFC822'].decode('utf-8') - msg_obj = email.message_from_string(msg_data) + msg_obj = email.message_from_string(msg_data, + policy=email.policy.default) # format and tidy header data msg = Message() @@ -120,21 +123,26 @@ class MailRoom(Bureau): msg.attachments = [] # TODO: deal with attachments # TODO: should use msg_obj.get_body and deal with HTML - msg.content = "" + msg.content = msg.get_body(('plain',)) + if msg.content: + msg.content = msg.content.get_content() + else: + msg.content = "ERROR COULD NOT FIND EMAIL BODY!\n Big shrug." # extract other sub-messages / attachments - for part in msg_obj.walk(): - # TODO: save interesting attachments to files - # should clean these up on delete - part_content = "" - if part.get_content_type() == "text/plain": - part_content = part.get_content() - print("msg part content:", part_content) - # part_content = msg.content.decode("utf-8") - part_content = msg.content.replace("<", "<") - part_content = msg.content.replace(">", ">") - part_content = msg.content.replace("\n", "
") - msg.content += part_content + #for part in msg_obj.walk(): + # # TODO: save interesting attachments to files + # # should clean these up on delete + # part_content = "" + # if part.get_content_type() == "text/plain": + # #part_content = part.get_content() + # part_content = part.get_content() + # print("msg part content:", part_content) + # # part_content = msg.content.decode("utf-8") + # part_content = msg.content.replace("<", "<") + # part_content = msg.content.replace(">", ">") + # part_content = msg.content.replace("\n", "
") + # msg.content += part_content return msg