From fba402ab186001cab36fc8a9da174e3c9bca2847 Mon Sep 17 00:00:00 2001 From: "jordan@hall05.co.uk" <1337One> Date: Wed, 19 Jun 2013 11:57:41 +0000 Subject: [PATCH 1/7] Added 'getSentMessageById' command to API --- src/bitmessagemain.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 74d4b211..1a61438d 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -3712,6 +3712,22 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): data += json.dumps({'msgid':msgid.encode('hex'),'toAddress':toAddress,'fromAddress':fromAddress,'subject':subject.encode('base64'),'message':message.encode('base64'),'encodingType':2,'lastActionTime':lastactiontime,'status':status},indent=4, separators=(',', ': ')) data += ']}' return data + elif method == 'getSentMessageById': + msgid = params[0].decode('hex') + v = (msgid,) + shared.sqlLock.acquire() + shared.sqlSubmitQueue.put('''SELECT msgid, toaddress, fromaddress, subject, lastactiontime, message, status FROM sent WHERE msgid=?''') + shared.sqlSubmitQueue.put(v) + queryreturn = shared.sqlReturnQueue.get() + shared.sqlLock.release() + data = '{"sentMessage":[' + for row in queryreturn: + toAddress, fromAddress, subject, received, message, = row + subject = shared.fixPotentiallyInvalidUTF8Data(subject) + message = shared.fixPotentiallyInvalidUTF8Data(message) + data += json.dumps({'msgid':msgid.encode('hex'),'toAddress':toAddress,'fromAddress':fromAddress,'subject':subject.encode('base64'),'message':message.encode('base64'),'encodingType':2,'receivedTime':received},indent=4, separators=(',', ': ')) + data += ']}' + return data elif method == 'trashMessage': if len(params) == 0: return 'API Error 0000: I need parameters!' From ce8113b36e14a20763fae1cbdd52accd2cd38108 Mon Sep 17 00:00:00 2001 From: "jordan@hall05.co.uk" <1337One> Date: Wed, 19 Jun 2013 12:02:52 +0000 Subject: [PATCH 2/7] Changed received to 'lastActionTime' for 'getSentMessageById' command. --- src/bitmessagemain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 1a61438d..7397fbb5 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -3725,7 +3725,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): toAddress, fromAddress, subject, received, message, = row subject = shared.fixPotentiallyInvalidUTF8Data(subject) message = shared.fixPotentiallyInvalidUTF8Data(message) - data += json.dumps({'msgid':msgid.encode('hex'),'toAddress':toAddress,'fromAddress':fromAddress,'subject':subject.encode('base64'),'message':message.encode('base64'),'encodingType':2,'receivedTime':received},indent=4, separators=(',', ': ')) + data += json.dumps({'msgid':msgid.encode('hex'),'toAddress':toAddress,'fromAddress':fromAddress,'subject':subject.encode('base64'),'message':message.encode('base64'),'encodingType':2,'lastActionTime':lastactiontime},indent=4, separators=(',', ': ')) data += ']}' return data elif method == 'trashMessage': From 3f07f895bc1389f630bc393ecd5aafcf0db41e34 Mon Sep 17 00:00:00 2001 From: "jordan@hall05.co.uk" <1337One> Date: Wed, 19 Jun 2013 12:06:46 +0000 Subject: [PATCH 3/7] Added 'getAllInboxMessages' command to API. --- src/bitmessagemain.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 7397fbb5..346d8a66 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -3696,6 +3696,22 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): data += json.dumps({'msgid':msgid.encode('hex'),'toAddress':toAddress,'fromAddress':fromAddress,'subject':subject.encode('base64'),'message':message.encode('base64'),'encodingType':2,'receivedTime':received},indent=4, separators=(',', ': ')) data += ']}' return data + elif method == 'getInboxMessageById': + msgid = params[0].decode('hex') + v = (msgid,) + shared.sqlLock.acquire() + shared.sqlSubmitQueue.put('''SELECT msgid, toaddress, fromaddress, subject, received, message FROM inbox WHERE msgid=?''') + shared.sqlSubmitQueue.put(v) + queryreturn = shared.sqlReturnQueue.get() + shared.sqlLock.release() + data = '{"inboxMessage":[' + for row in queryreturn: + msgid, toAddress, fromAddress, subject, received, message, = row + subject = shared.fixPotentiallyInvalidUTF8Data(subject) + message = shared.fixPotentiallyInvalidUTF8Data(message) + data += json.dumps({'msgid':msgid.encode('hex'),'toAddress':toAddress,'fromAddress':fromAddress,'subject':subject.encode('base64'),'message':message.encode('base64'),'encodingType':2,'receivedTime':received},indent=4, separators=(',', ': ')) + data += ']}' + return data elif method == 'getAllSentMessages': shared.sqlLock.acquire() shared.sqlSubmitQueue.put('''SELECT msgid, toaddress, fromaddress, subject, lastactiontime, message, status FROM sent where folder='sent' ORDER BY lastactiontime''') From b8250ae04f10670d55b49d93896ffa1dab812e61 Mon Sep 17 00:00:00 2001 From: "jordan@hall05.co.uk" <1337One> Date: Wed, 19 Jun 2013 13:10:25 +0100 Subject: [PATCH 4/7] Fixed indentation error. From 28ed9676ccc768e6877747d9a5a5cc2f5a57eb79 Mon Sep 17 00:00:00 2001 From: "jordan@hall05.co.uk" <1337One> Date: Wed, 19 Jun 2013 12:29:28 +0000 Subject: [PATCH 5/7] Fixed indentation error (previous commit contained no files) --- src/bitmessagemain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 346d8a66..a0da58fa 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -3728,7 +3728,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): data += json.dumps({'msgid':msgid.encode('hex'),'toAddress':toAddress,'fromAddress':fromAddress,'subject':subject.encode('base64'),'message':message.encode('base64'),'encodingType':2,'lastActionTime':lastactiontime,'status':status},indent=4, separators=(',', ': ')) data += ']}' return data - elif method == 'getSentMessageById': + elif method == 'getSentMessageById': msgid = params[0].decode('hex') v = (msgid,) shared.sqlLock.acquire() From 72643471829e0bca5cb7f2f9d9480dfd348d1d76 Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Wed, 19 Jun 2013 22:50:00 +0100 Subject: [PATCH 6/7] Added parameters check for getInboxMessageById and getSentMessageById API commands --- src/bitmessagemain.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index a0da58fa..fc7ce7fe 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -3697,6 +3697,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): data += ']}' return data elif method == 'getInboxMessageById': + if len(params) == 0: + return 'API Error 0000: I need parameters!' msgid = params[0].decode('hex') v = (msgid,) shared.sqlLock.acquire() @@ -3729,6 +3731,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): data += ']}' return data elif method == 'getSentMessageById': + if len(params) == 0: + return 'API Error 0000: I need parameters!' msgid = params[0].decode('hex') v = (msgid,) shared.sqlLock.acquire() From 21ec1de7ca58bd700705bd4a862b0f0040d1d613 Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Wed, 19 Jun 2013 23:02:36 +0100 Subject: [PATCH 7/7] Created API commands: 'trashInboxMessage' and 'trashSentMessage'. Also, identation fix caused by accidental tabs instead of spaces. --- src/bitmessagemain.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index fc7ce7fe..2335540a 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -3697,7 +3697,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): data += ']}' return data elif method == 'getInboxMessageById': - if len(params) == 0: + if len(params) == 0: return 'API Error 0000: I need parameters!' msgid = params[0].decode('hex') v = (msgid,) @@ -3731,7 +3731,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): data += ']}' return data elif method == 'getSentMessageById': - if len(params) == 0: + if len(params) == 0: return 'API Error 0000: I need parameters!' msgid = params[0].decode('hex') v = (msgid,) @@ -3748,7 +3748,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): data += json.dumps({'msgid':msgid.encode('hex'),'toAddress':toAddress,'fromAddress':fromAddress,'subject':subject.encode('base64'),'message':message.encode('base64'),'encodingType':2,'lastActionTime':lastactiontime},indent=4, separators=(',', ': ')) data += ']}' return data - elif method == 'trashMessage': + elif (method == 'trashMessage') or (method == 'trashInboxMessage'): if len(params) == 0: return 'API Error 0000: I need parameters!' msgid = params[0].decode('hex') @@ -3760,7 +3760,20 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): shared.sqlSubmitQueue.put('commit') shared.sqlLock.release() shared.UISignalQueue.put(('removeInboxRowByMsgid',msgid)) - return 'Trashed message (assuming message existed).' + return 'Trashed inbox message (assuming message existed).' + elif method == 'trashSentMessage': + if len(params) == 0: + return 'API Error 0000: I need parameters!' + msgid = params[0].decode('hex') + t = (msgid,) + shared.sqlLock.acquire() + shared.sqlSubmitQueue.put('''UPDATE sent SET folder='trash' WHERE msgid=?''') + shared.sqlSubmitQueue.put(t) + shared.sqlReturnQueue.get() + shared.sqlSubmitQueue.put('commit') + shared.sqlLock.release() + shared.UISignalQueue.put(('removeSentRowByMsgid',msgid)) + return 'Trashed sent message (assuming message existed).' elif method == 'sendMessage': if len(params) == 0: return 'API Error 0000: I need parameters!'