|
|
@ -3,9 +3,11 @@ import email.mime.application
|
|
|
|
import email.mime.multipart
|
|
|
|
import email.mime.multipart
|
|
|
|
import email.mime.text
|
|
|
|
import email.mime.text
|
|
|
|
from email.header import decode_header, make_header
|
|
|
|
from email.header import decode_header, make_header
|
|
|
|
import imaplib
|
|
|
|
#import imaplib
|
|
|
|
import os.path
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
import random
|
|
|
|
import smtplib
|
|
|
|
import smtplib
|
|
|
|
|
|
|
|
import string
|
|
|
|
|
|
|
|
|
|
|
|
import code128
|
|
|
|
import code128
|
|
|
|
import imapclient
|
|
|
|
import imapclient
|
|
|
@ -87,9 +89,9 @@ class MailRoom(Bureau):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
util tidies up message headers deals with encoding
|
|
|
|
util tidies up message headers deals with encoding
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
internaldate = resp_obj[imap_id][b'INTERNALDATE']
|
|
|
|
internaldate = resp_obj[b'INTERNALDATE']
|
|
|
|
|
|
|
|
|
|
|
|
msg_data = resp_obj[imap_id][b'RFC822'].decode('utf-8')
|
|
|
|
msg_data = resp_obj[b'RFC822'].decode('utf-8')
|
|
|
|
msg_obj = email.message_from_string(msg_data)
|
|
|
|
msg_obj = email.message_from_string(msg_data)
|
|
|
|
|
|
|
|
|
|
|
|
# format and tidy header data
|
|
|
|
# format and tidy header data
|
|
|
@ -112,7 +114,9 @@ class MailRoom(Bureau):
|
|
|
|
# TODO: save interesting attachments to files
|
|
|
|
# TODO: save interesting attachments to files
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
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(">", ">")
|
|
|
|
msg.content = msg.content.replace(">", ">")
|
|
|
|
msg.content = msg.content.replace("\n", "<br />")
|
|
|
|
msg.content = msg.content.replace("\n", "<br />")
|
|
|
@ -132,18 +136,19 @@ class MailRoom(Bureau):
|
|
|
|
returns a short code for a given IMAP id (creating a new mapping if
|
|
|
|
returns a short code for a given IMAP id (creating a new mapping if
|
|
|
|
needed)
|
|
|
|
needed)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
with self.dbenv.begin(db=self.postdb_rev) as txn:
|
|
|
|
msgid = str(msgid).encode()
|
|
|
|
shortcode = txn.get(msgid.encode())
|
|
|
|
with self.dbenv.begin(db=self.postdb_rev, write=True) as txn:
|
|
|
|
|
|
|
|
shortcode = txn.get(msgid)
|
|
|
|
if shortcode is not None:
|
|
|
|
if shortcode is not None:
|
|
|
|
return shortcode
|
|
|
|
return shortcode
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
shortcode = ''.join(random.choice(string.ascii_letters +
|
|
|
|
shortcode = ''.join(random.choice(string.ascii_letters +
|
|
|
|
string.digits) for _ in range(5))
|
|
|
|
string.digits) for _ in range(5)).encode()
|
|
|
|
txn.put(msgid.encode(), shortcode.encode())
|
|
|
|
print("saving msgid", msgid, shortcode)
|
|
|
|
with self.dbenv.begin(db=self.postdb) as txn:
|
|
|
|
txn.put(msgid, shortcode)
|
|
|
|
txn.put(shortcode.encode(), msgid.encode())
|
|
|
|
with self.dbenv.begin(db=self.postdb, write=True) as txn:
|
|
|
|
return shortcode
|
|
|
|
txn.put(shortcode, msgid)
|
|
|
|
|
|
|
|
return shortcode.decode()
|
|
|
|
|
|
|
|
|
|
|
|
@add_command("fax", "Send a Document Camera Image via Email")
|
|
|
|
@add_command("fax", "Send a Document Camera Image via Email")
|
|
|
|
def fax(self, data):
|
|
|
|
def fax(self, data):
|
|
|
@ -293,15 +298,25 @@ class MailRoom(Bureau):
|
|
|
|
msgs = []
|
|
|
|
msgs = []
|
|
|
|
|
|
|
|
|
|
|
|
for msgid, data in resp.items():
|
|
|
|
for msgid, data in resp.items():
|
|
|
|
msg = self._make_msg_object(msgid, data)
|
|
|
|
#msg = self._make_msg_object(msgid, data)
|
|
|
|
shortcode = self._imap2shortcode(msgid)
|
|
|
|
msg = Message()
|
|
|
|
|
|
|
|
shortcode = self._imap2shortcode(msgid).decode("utf-8")
|
|
|
|
|
|
|
|
envelope = data[b"ENVELOPE"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msg.msgid = str(msgid)
|
|
|
|
|
|
|
|
sender = envelope.from_[0]
|
|
|
|
|
|
|
|
msg.fromaddr = sender.mailbox + b"@" + sender.host
|
|
|
|
|
|
|
|
msg.fromaddr = clean_header(msg.fromaddr.decode("utf-8"))
|
|
|
|
|
|
|
|
msg.fromname = clean_header(sender.name.decode("utf-8"))
|
|
|
|
|
|
|
|
msg.date = data[b"INTERNALDATE"].strftime("%d. %B %Y %I:%M%p")
|
|
|
|
|
|
|
|
msg.subject = clean_header(envelope.subject.decode("utf-8"))
|
|
|
|
|
|
|
|
|
|
|
|
# make action barcodes
|
|
|
|
# make action barcodes
|
|
|
|
msg.d_bc = code128.svg("POd." + shortcode).encode()
|
|
|
|
msg.d_bc = code128.svg("POd." + shortcode)
|
|
|
|
msg.sp_bc = code128.svg("POsp." + shortcode).encode()
|
|
|
|
msg.sp_bc = code128.svg("POsp." + shortcode)
|
|
|
|
msg.r_bc = code128.svg("POr." + shortcode).encode()
|
|
|
|
msg.r_bc = code128.svg("POr." + shortcode)
|
|
|
|
|
|
|
|
|
|
|
|
msgs.append(msg)
|
|
|
|
msgs.append(msg.__dict__)
|
|
|
|
|
|
|
|
|
|
|
|
return msgs
|
|
|
|
return msgs
|
|
|
|
|
|
|
|
|
|
|
|