From 17b35b97d468d84992cd8c2b9ea65ad64d7db06b Mon Sep 17 00:00:00 2001 From: Jimmy Song Date: Thu, 29 May 2014 09:00:28 +0000 Subject: [PATCH 1/3] Issue #10: Fix the broken Thunderbird Connection Fix handleLIST to handle non-argumented LIST command properly Fix handleUIDL to make Thunderbird handle UIDL correctly Tested and working in both Thunderbird and fetchmail This fixes issue #10 --- incoming.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/incoming.py b/incoming.py index 209afd4..614f789 100644 --- a/incoming.py +++ b/incoming.py @@ -61,9 +61,11 @@ def handleStat(data): return returnData def handleList(data): - cmd, msgId = data.split() + dataList = data.split() + cmd = dataList[0] msgSizes = _getMsgSizes() - if msgId is not None: + if len(dataList) > 1: + msgId = dataList[1] # means the server wants a single message response i = int(msgId) - 1 if i >= len(msgSizes): @@ -120,7 +122,9 @@ def handleQuit(data): def handleCapa(data): returnData = "+OK List of capabilities follows\r\n" - returnData += "CAPA\r\nTOP\r\nUSER\r\nPASS\r\nUIDL\r\n." + for k in dispatch: + returnData += "%s\r\n" % k + returnData += "." return returnData def handleUIDL(data): @@ -128,16 +132,15 @@ def handleUIDL(data): logging.debug(data) if len(data) == 1: refdata = bminterface.getUIDLforAll() + logging.debug(refdata) + returnData = '+OK\r\n' + for msgID, d in enumerate(refdata): + returnData += "%s %s\r\n" % (msgID+1, d) + returnData += '.' else: refdata = bminterface.getUIDLforSingle(int(data[1])-1) - logging.debug(refdata) - if len(refdata) == 1: + logging.debug(refdata) returnData = '+OK ' + data[0] + str(refdata[0]) - else: - returnData = '+OK listing UIDL numbers...\r\n' - for msgID in range(len(refdata)): - returnData += str(msgID+1) + ' ' + refdata[msgID] + '\r\n' - returnData += '.' return returnData def makeEmail(dateTime, toAddress, fromAddress, subject, body): @@ -247,6 +250,7 @@ def incomingServer_main(host, port, run_event): conn.sendall("+OK server ready") while run_event.is_set(): data = conn.recvall() + logging.debug("Answering %s" % data) command = data.split(None, 1)[0] try: cmd = dispatch[command] From a5e07738fcff7c7b868b404db49d20ab6ca7146f Mon Sep 17 00:00:00 2001 From: Jimmy Song Date: Thu, 29 May 2014 09:54:16 +0000 Subject: [PATCH 2/3] Issue #12: Allow per-address fetches Add "currentAddress" to the bminterface as a global variable Change handleUser to set the currentAddress if username begins with "BM-" This change is meant to allow different users to access their bitmessages Note this will not work concurrently! once USER is sent, all subsequent messages assume the same user until a different USER is defined. This closes issue #12 --- bminterface.py | 14 ++++++++++++++ incoming.py | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/bminterface.py b/bminterface.py index a9a9092..423af94 100644 --- a/bminterface.py +++ b/bminterface.py @@ -9,6 +9,7 @@ purgeList = [] allMessages = [] +currentAddress = None def _getKeyLocation(): #make this not suck later return '~/.config/PyBitmessage/keys.dat' @@ -64,6 +65,11 @@ def _stripAddress(address): logging.info("converted address " + orig + " to " + retstring) return retstring +def registerAddress(address): + global currentAddress + currentAddress = address + logging.debug("Set current address to %s" % currentAddress) + def send(toAddress, fromAddress, subject, body): toAddress = _stripAddress(toAddress) fromAddress = _stripAddress(fromAddress) @@ -76,9 +82,17 @@ def send(toAddress, fromAddress, subject, body): def _getAll(): global allMessages + global currentAddress if not allMessages: api = _makeApi(_getKeyLocation()) allMessages = json.loads(api.getAllInboxMessages()) + logging.debug("current address is %s" % currentAddress) + if currentAddress is not None: + ret = [] + for msg in allMessages['inboxMessages']: + if msg['toAddress'] == currentAddress: + ret.append(msg) + return dict(inboxMessages=ret) return allMessages def get(msgID): diff --git a/incoming.py b/incoming.py index 614f789..7a8987a 100644 --- a/incoming.py +++ b/incoming.py @@ -9,6 +9,7 @@ import select import logging + class ChatterboxConnection(object): END = "\r\n" def __init__(self, conn): @@ -36,6 +37,15 @@ def recvall(self, END=END): def handleUser(data): + d = data.split() + logging.debug("data:%s" % d) + username = d[-1] + if username[:3] == 'BM-': + logging.debug("Only showing messages for %s" % username) + bminterface.registerAddress(username) + else: + logging.debug("Showing all messages in the inbox") + bminterface.registerAddress(None) return "+OK user accepted" def handlePass(data): From 99537d552e9783ec578c7ccd982ff6f288be2a1a Mon Sep 17 00:00:00 2001 From: Jimmy Song Date: Fri, 30 May 2014 09:45:51 +0000 Subject: [PATCH 3/3] Issue #14: Make replies look normal For normal replies, the quoted text (prepended lines of "> ") get put at the end. I've removed this functionality. --- outgoing.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/outgoing.py b/outgoing.py index c2e787d..608a9c6 100644 --- a/outgoing.py +++ b/outgoing.py @@ -13,7 +13,10 @@ def process_message(self, peer, mailfrom, rcpttos, data): toAddress = msg['To'] fromAddress = msg['From'] subject = u' '.join(unicode(t[0], t[1] or 'UTF-8') for t in email.header.decode_header(msg['Subject'])).encode('UTF-8') - body = self._bmformat(msg) + if msg.is_multipart(): + body = self._bmformat(msg) + else: + body = msg.get_payload() #Make sure we don't send an actually blank subject or body--this can cause problems. if not subject: