diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py
index d2f79fa..4479cb1 100644
--- a/screenless/bureau/bureau.py
+++ b/screenless/bureau/bureau.py
@@ -340,23 +340,22 @@ class Bureau(object):
self.log.debug("got method: " + ref)
if (ref in self.commands) or (ref in self.api):
- # catch TypeErrors for case of bogus params
- try:
- if ref in self.api:
- if data:
- data = json.loads(data)
- ret = json.dumps(self.api[ref](data))
- else:
- ret = json.dumps(self.api[ref]())
+ # TODO: cope with data for calls with no params
+ if ref in self.api:
+ if data:
+ data = json.loads(data)
+ ret = json.dumps(self.api[ref](data))
else:
- if data:
- ret = self.commands[ref](data)
- else:
- ret = self.commands[ref]()
- if ret is None:
- ret = ""
- ret = "0" + ret
- self._recv.send_string(ret)
+ ret = json.dumps(self.api[ref]())
+ else:
+ if data:
+ ret = self.commands[ref](data)
+ else:
+ ret = self.commands[ref]()
+ if ret is None:
+ ret = ""
+ ret = "0" + ret
+ self._recv.send_string(ret)
else:
self.log.warning("error! Command/API %s not found", ref)
self._recv.send_unicode("Error! Command/API not found.")
diff --git a/screenless/bureau/mailroom/mailroom.py b/screenless/bureau/mailroom/mailroom.py
index 6fb7b45..0a54f11 100644
--- a/screenless/bureau/mailroom/mailroom.py
+++ b/screenless/bureau/mailroom/mailroom.py
@@ -3,9 +3,11 @@ import email.mime.application
import email.mime.multipart
import email.mime.text
from email.header import decode_header, make_header
-import imaplib
+#import imaplib
import os.path
+import random
import smtplib
+import string
import code128
import imapclient
@@ -87,9 +89,9 @@ class MailRoom(Bureau):
"""
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)
# format and tidy header data
@@ -112,7 +114,9 @@ class MailRoom(Bureau):
# TODO: save interesting attachments to files
# should clean these up on delete
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("\n", "
")
@@ -132,18 +136,19 @@ class MailRoom(Bureau):
returns a short code for a given IMAP id (creating a new mapping if
needed)
"""
- with self.dbenv.begin(db=self.postdb_rev) as txn:
- shortcode = txn.get(msgid.encode())
+ msgid = str(msgid).encode()
+ with self.dbenv.begin(db=self.postdb_rev, write=True) as txn:
+ shortcode = txn.get(msgid)
if shortcode is not None:
return shortcode
else:
shortcode = ''.join(random.choice(string.ascii_letters +
- string.digits) for _ in range(5))
- txn.put(msgid.encode(), shortcode.encode())
- with self.dbenv.begin(db=self.postdb) as txn:
- txn.put(shortcode.encode(), msgid.encode())
- return shortcode
-
+ string.digits) for _ in range(5)).encode()
+ print("saving msgid", msgid, shortcode)
+ txn.put(msgid, shortcode)
+ with self.dbenv.begin(db=self.postdb, write=True) as txn:
+ txn.put(shortcode, msgid)
+ return shortcode.decode()
@add_command("fax", "Send a Document Camera Image via Email")
def fax(self, data):
@@ -293,15 +298,25 @@ class MailRoom(Bureau):
msgs = []
for msgid, data in resp.items():
- msg = self._make_msg_object(msgid, data)
- shortcode = self._imap2shortcode(msgid)
+ #msg = self._make_msg_object(msgid, data)
+ 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
- msg.d_bc = code128.svg("POd." + shortcode).encode()
- msg.sp_bc = code128.svg("POsp." + shortcode).encode()
- msg.r_bc = code128.svg("POr." + shortcode).encode()
+ msg.d_bc = code128.svg("POd." + shortcode)
+ msg.sp_bc = code128.svg("POsp." + shortcode)
+ msg.r_bc = code128.svg("POr." + shortcode)
- msgs.append(msg)
+ msgs.append(msg.__dict__)
return msgs
diff --git a/screenless/bureau/publications/news.html b/screenless/bureau/publications/news.html
index 345f2e6..f5af043 100644
--- a/screenless/bureau/publications/news.html
+++ b/screenless/bureau/publications/news.html
@@ -3,9 +3,17 @@