update mail barcodes for kode256. fix encoding for non-utf mails

workspace
Brendan Howell 4 years ago
parent fd093cb46e
commit f86474367c

@ -126,13 +126,15 @@ class MailRoom(Bureau):
for part in msg_obj.walk(): for part in msg_obj.walk():
# TODO: save interesting attachments to files # TODO: save interesting attachments to files
# should clean these up on delete # should clean these up on delete
part_content = ""
if part.get_content_type() == "text/plain": if part.get_content_type() == "text/plain":
msg.content = part.get_payload(decode=True) part_content = part.get_content()
print("msg content:", msg.content) print("msg part content:", part_content)
msg.content = msg.content.decode("utf-8") # part_content = msg.content.decode("utf-8")
msg.content = msg.content.replace("<", "&lt;") part_content = msg.content.replace("<", "&lt;")
msg.content = msg.content.replace(">", "&gt;") part_content = msg.content.replace(">", "&gt;")
msg.content = msg.content.replace("\n", "<br />") part_content = msg.content.replace("\n", "<br />")
msg.content += part_content
return msg return msg
@ -186,18 +188,24 @@ class MailRoom(Bureau):
msg = self._make_msg_object(imap_id, resp) msg = self._make_msg_object(imap_id, resp)
# make action barcodes # make action barcodes
msg.un_bc = os.path.join("/tmp", "POun." + shortcode + ".svg")
kode256.image("POun." + shortcode).save(msg.un_bc)
msg.d_bc = os.path.join("/tmp", "POd." + shortcode + ".svg") msg.d_bc = os.path.join("/tmp", "POd." + shortcode + ".svg")
kode256.image("POd." + shortcode).save(msg.d_bc) with open(msg.d_bc, "w") as svgfile:
msg.sp_bc = os.path.join("/tmp", "POsp." + shortcode + ".svg") svgfile.write(kode256.svg("POd." + shortcode))
kode256.image("POsp." + shortcode).save(msg.sp_bc) msg.r_bc = os.path.join("/tmp", "POr." + shortcode + ".svg")
with open(msg.r_bc, "w") as svgfile:
svgfile.write(kode256.svg("POr." + shortcode))
msg.sp_bc = os.path.join("/tmp", "POd." + shortcode + ".svg")
with open(msg.sp_bc, "w") as svgfile:
svgfile.write(kode256.svg("POsp." + shortcode))
msg.un_bc = os.path.join("/tmp", "POun." + shortcode + ".svg")
with open(msg.un_bc, "w") as svgfile:
svgfile.write(kode256.svg("POun." + shortcode))
msg.re_bc = os.path.join("/tmp", "POre." + shortcode + ".svg") msg.re_bc = os.path.join("/tmp", "POre." + shortcode + ".svg")
kode256.image("POre." + shortcode).save(msg.re_bc) with open(msg.re_bc, "w") as svgfile:
svgfile.write(kode256.svg("POre." + shortcode))
msg.rea_bc = os.path.join("/tmp", "POrea." + shortcode + ".svg") msg.rea_bc = os.path.join("/tmp", "POrea." + shortcode + ".svg")
kode256.image("POrea." + shortcode).save(msg.rea_bc) with open(msg.rea_bc, "w") as svgfile:
msg.r_bc = os.path.join("/tmp", "POr." + shortcode + ".svg") svgfile.write(kode256.svg("POrea." + shortcode))
kode256.image("POr." + shortcode).save(msg.r_bc)
self.print_full("email.html", msg=msg, shortcode=shortcode) self.print_full("email.html", msg=msg, shortcode=shortcode)

Loading…
Cancel
Save