From f86474367ccb0dfe66a2fedac5fe42060c53d68b Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Tue, 11 Aug 2020 11:16:30 +0200 Subject: [PATCH] update mail barcodes for kode256. fix encoding for non-utf mails --- screenless/bureau/mailroom/mailroom.py | 38 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/screenless/bureau/mailroom/mailroom.py b/screenless/bureau/mailroom/mailroom.py index 48da3be..3c1e2fc 100644 --- a/screenless/bureau/mailroom/mailroom.py +++ b/screenless/bureau/mailroom/mailroom.py @@ -126,13 +126,15 @@ class MailRoom(Bureau): 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": - msg.content = part.get_payload(decode=True) - print("msg content:", msg.content) - msg.content = msg.content.decode("utf-8") - msg.content = msg.content.replace("<", "<") - msg.content = msg.content.replace(">", ">") - msg.content = msg.content.replace("\n", "
") + 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 @@ -186,18 +188,24 @@ class MailRoom(Bureau): msg = self._make_msg_object(imap_id, resp) # 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") - kode256.image("POd." + shortcode).save(msg.d_bc) - msg.sp_bc = os.path.join("/tmp", "POsp." + shortcode + ".svg") - kode256.image("POsp." + shortcode).save(msg.sp_bc) + with open(msg.d_bc, "w") as svgfile: + svgfile.write(kode256.svg("POd." + shortcode)) + 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") - 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") - kode256.image("POrea." + shortcode).save(msg.rea_bc) - msg.r_bc = os.path.join("/tmp", "POr." + shortcode + ".svg") - kode256.image("POr." + shortcode).save(msg.r_bc) + with open(msg.rea_bc, "w") as svgfile: + svgfile.write(kode256.svg("POrea." + shortcode)) self.print_full("email.html", msg=msg, shortcode=shortcode)