fix reconnect exception handling. layout tweaks. html entities in headers.

workspace
Brendan Howell 8 years ago
parent 27857a5a31
commit f11a1327c2

@ -5,8 +5,11 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<style> <style>
body { body {
font-family: "FreeUniversal"; font-family: "CMU Serif";
font-size: 11pt; font-size: 10pt;
}
#header {
font-family: "CMU Sans Serif";
} }
#main { #main {
margin-top: 2em; margin-top: 2em;
@ -15,6 +18,7 @@
float: left; float: left;
width: 63%; width: 63%;
padding-right: 3%; padding-right: 3%;
line-height: 0.9em;
} }
#menu { #menu {
width: 30%; width: 30%;

@ -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("<", "&lt;")
header = header.replace(">", "&gt;")
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("<", "&lt;")
msg.content = msg.content.replace(">", "&gt;")
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)

Loading…
Cancel
Save