Methods to form a dictionary for inbox and sent messages
This commit is contained in:
parent
45b0659e4c
commit
7cafe402be
177
src/api.py
177
src/api.py
|
@ -314,6 +314,41 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler, object):
|
||||||
|
|
||||||
return (status, addressVersionNumber, streamNumber, ripe)
|
return (status, addressVersionNumber, streamNumber, ripe)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _dump_inbox_message(
|
||||||
|
msgid, toAddress, fromAddress, subject, received,
|
||||||
|
message, encodingtype, read):
|
||||||
|
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||||
|
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||||
|
return {
|
||||||
|
'msgid': hexlify(msgid),
|
||||||
|
'toAddress': toAddress,
|
||||||
|
'fromAddress': fromAddress,
|
||||||
|
'subject': base64.b64encode(subject),
|
||||||
|
'message': base64.b64encode(message),
|
||||||
|
'encodingType': encodingtype,
|
||||||
|
'receivedTime': received,
|
||||||
|
'read': read
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _dump_sent_message(
|
||||||
|
msgid, toAddress, fromAddress, subject, lastactiontime,
|
||||||
|
message, encodingtype, status, ackdata):
|
||||||
|
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||||
|
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
||||||
|
return {
|
||||||
|
'msgid': hexlify(msgid),
|
||||||
|
'toAddress': toAddress,
|
||||||
|
'fromAddress': fromAddress,
|
||||||
|
'subject': base64.b64encode(subject),
|
||||||
|
'message': base64.b64encode(message),
|
||||||
|
'encodingType': encodingtype,
|
||||||
|
'lastActionTime': lastactiontime,
|
||||||
|
'status': status,
|
||||||
|
'ackData': hexlify(ackdata)
|
||||||
|
}
|
||||||
|
|
||||||
# Request Handlers
|
# Request Handlers
|
||||||
|
|
||||||
@command('listAddresses', 'listAddresses2')
|
@command('listAddresses', 'listAddresses2')
|
||||||
|
@ -610,22 +645,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler, object):
|
||||||
" encodingtype, read FROM inbox WHERE folder='inbox'"
|
" encodingtype, read FROM inbox WHERE folder='inbox'"
|
||||||
" ORDER BY received"
|
" ORDER BY received"
|
||||||
)
|
)
|
||||||
data = []
|
return {"inboxMessages": [
|
||||||
for (msgid, toAddress, fromAddress, subject, received, message,
|
self._dump_inbox_message(*data) for data in queryreturn
|
||||||
encodingtype, read) in queryreturn:
|
]}
|
||||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
|
||||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
|
||||||
data.append({
|
|
||||||
'msgid': hexlify(msgid),
|
|
||||||
'toAddress': toAddress,
|
|
||||||
'fromAddress': fromAddress,
|
|
||||||
'subject': base64.b64encode(subject),
|
|
||||||
'message': base64.b64encode(message),
|
|
||||||
'encodingType': encodingtype,
|
|
||||||
'receivedTime': received,
|
|
||||||
'read': read
|
|
||||||
})
|
|
||||||
return {"inboxMessages": data}
|
|
||||||
|
|
||||||
@command('getAllInboxMessageIds', 'getAllInboxMessageIDs')
|
@command('getAllInboxMessageIds', 'getAllInboxMessageIDs')
|
||||||
def HandleGetAllInboxMessageIds(self):
|
def HandleGetAllInboxMessageIds(self):
|
||||||
|
@ -663,24 +685,11 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler, object):
|
||||||
"SELECT toaddress, fromaddress, subject, received, message,"
|
"SELECT toaddress, fromaddress, subject, received, message,"
|
||||||
" encodingtype, read FROM inbox WHERE msgid=?", msgid
|
" encodingtype, read FROM inbox WHERE msgid=?", msgid
|
||||||
)
|
)
|
||||||
data = []
|
|
||||||
try:
|
try:
|
||||||
(toAddress, fromAddress, subject, received, message, encodingtype,
|
return {"inboxMessage": [
|
||||||
read) = queryreturn[0]
|
self._dump_inbox_message(*queryreturn[0])]}
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return # FIXME inconsistent
|
pass # FIXME inconsistent
|
||||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
|
||||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
|
||||||
return {"inboxMessage": [{
|
|
||||||
'msgid': hid,
|
|
||||||
'toAddress': toAddress,
|
|
||||||
'fromAddress': fromAddress,
|
|
||||||
'subject': base64.b64encode(subject),
|
|
||||||
'message': base64.b64encode(message),
|
|
||||||
'encodingType': encodingtype,
|
|
||||||
'receivedTime': received,
|
|
||||||
'read': read
|
|
||||||
}]}
|
|
||||||
|
|
||||||
@command('getAllSentMessages')
|
@command('getAllSentMessages')
|
||||||
def HandleGetAllSentMessages(self):
|
def HandleGetAllSentMessages(self):
|
||||||
|
@ -691,23 +700,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler, object):
|
||||||
" message, encodingtype, status, ackdata FROM sent"
|
" message, encodingtype, status, ackdata FROM sent"
|
||||||
" WHERE folder='sent' ORDER BY lastactiontime"
|
" WHERE folder='sent' ORDER BY lastactiontime"
|
||||||
)
|
)
|
||||||
data = []
|
return {"sentMessages": [
|
||||||
for (msgid, toAddress, fromAddress, subject, lastactiontime, message,
|
self._dump_sent_message(*data) for data in queryreturn
|
||||||
encodingtype, status, ackdata) in queryreturn:
|
]}
|
||||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
|
||||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
|
||||||
data.append({
|
|
||||||
'msgid': hexlify(msgid),
|
|
||||||
'toAddress': toAddress,
|
|
||||||
'fromAddress': fromAddress,
|
|
||||||
'subject': base64.b64encode(subject),
|
|
||||||
'message': base64.b64encode(message),
|
|
||||||
'encodingType': encodingtype,
|
|
||||||
'lastActionTime': lastactiontime,
|
|
||||||
'status': status,
|
|
||||||
'ackData': hexlify(ackdata)
|
|
||||||
})
|
|
||||||
return {"sentMessages": data}
|
|
||||||
|
|
||||||
@command('getAllSentMessageIds', 'getAllSentMessageIDs')
|
@command('getAllSentMessageIds', 'getAllSentMessageIDs')
|
||||||
def HandleGetAllSentMessageIds(self):
|
def HandleGetAllSentMessageIds(self):
|
||||||
|
@ -727,24 +722,12 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler, object):
|
||||||
"""Handle a request to get inbox messages by receiver"""
|
"""Handle a request to get inbox messages by receiver"""
|
||||||
|
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
"SELECT msgid, toaddress, fromaddress, subject, received, message,"
|
"SELECT msgid, toaddress, fromaddress, subject, received,"
|
||||||
" encodingtype FROM inbox WHERE folder='inbox' AND toAddress=?",
|
" message, encodingtype, read FROM inbox WHERE folder='inbox'"
|
||||||
toAddress)
|
" AND toAddress=?", toAddress)
|
||||||
data = []
|
return {"inboxMessages": [
|
||||||
for (msgid, toAddress, fromAddress, subject, received, message,
|
self._dump_inbox_message(*data) for data in queryreturn
|
||||||
encodingtype) in queryreturn:
|
]}
|
||||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
|
||||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
|
||||||
data.append({
|
|
||||||
'msgid': hexlify(msgid),
|
|
||||||
'toAddress': toAddress,
|
|
||||||
'fromAddress': fromAddress,
|
|
||||||
'subject': base64.b64encode(subject),
|
|
||||||
'message': base64.b64encode(message),
|
|
||||||
'encodingType': encodingtype,
|
|
||||||
'receivedTime': received
|
|
||||||
})
|
|
||||||
return {"inboxMessages": data}
|
|
||||||
|
|
||||||
@command('getSentMessageById', 'getSentMessageByID')
|
@command('getSentMessageById', 'getSentMessageByID')
|
||||||
def HandleGetSentMessageById(self, hid):
|
def HandleGetSentMessageById(self, hid):
|
||||||
|
@ -757,23 +740,11 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler, object):
|
||||||
msgid
|
msgid
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
(toAddress, fromAddress, subject, lastactiontime, message,
|
return {"sentMessage": [
|
||||||
encodingtype, status, ackdata) = queryreturn[0]
|
self._dump_sent_message(*queryreturn[0])
|
||||||
|
]}
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return # FIXME inconsistent
|
pass # FIXME inconsistent
|
||||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
|
||||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
|
||||||
return {"sentMessage": [{
|
|
||||||
'msgid': hid,
|
|
||||||
'toAddress': toAddress,
|
|
||||||
'fromAddress': fromAddress,
|
|
||||||
'subject': base64.b64encode(subject),
|
|
||||||
'message': base64.b64encode(message),
|
|
||||||
'encodingType': encodingtype,
|
|
||||||
'lastActionTime': lastactiontime,
|
|
||||||
'status': status,
|
|
||||||
'ackData': hexlify(ackdata)
|
|
||||||
}]}
|
|
||||||
|
|
||||||
@command('getSentMessagesByAddress', 'getSentMessagesBySender')
|
@command('getSentMessagesByAddress', 'getSentMessagesBySender')
|
||||||
def HandleGetSentMessagesByAddress(self, fromAddress):
|
def HandleGetSentMessagesByAddress(self, fromAddress):
|
||||||
|
@ -785,23 +756,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler, object):
|
||||||
" WHERE folder='sent' AND fromAddress=? ORDER BY lastactiontime",
|
" WHERE folder='sent' AND fromAddress=? ORDER BY lastactiontime",
|
||||||
fromAddress
|
fromAddress
|
||||||
)
|
)
|
||||||
data = []
|
return {"sentMessages": [
|
||||||
for (msgid, toAddress, fromAddress, subject, lastactiontime, message,
|
self._dump_sent_message(*data) for data in queryreturn
|
||||||
encodingtype, status, ackdata) in queryreturn:
|
]}
|
||||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
|
||||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
|
||||||
data.append({
|
|
||||||
'msgid': hexlify(msgid),
|
|
||||||
'toAddress': toAddress,
|
|
||||||
'fromAddress': fromAddress,
|
|
||||||
'subject': base64.b64encode(subject),
|
|
||||||
'message': base64.b64encode(message),
|
|
||||||
'encodingType': encodingtype,
|
|
||||||
'lastActionTime': lastactiontime,
|
|
||||||
'status': status,
|
|
||||||
'ackData': hexlify(ackdata)
|
|
||||||
})
|
|
||||||
return {"sentMessages": data}
|
|
||||||
|
|
||||||
@command('getSentMessageByAckData')
|
@command('getSentMessageByAckData')
|
||||||
def HandleGetSentMessagesByAckData(self, ackData):
|
def HandleGetSentMessagesByAckData(self, ackData):
|
||||||
|
@ -815,23 +772,11 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler, object):
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(msgid, toAddress, fromAddress, subject, lastactiontime,
|
return {"sentMessage": [
|
||||||
message, encodingtype, status, ackdata) = queryreturn[0]
|
self._dump_sent_message(*queryreturn[0])
|
||||||
|
]}
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return # FIXME inconsistent
|
pass # FIXME inconsistent
|
||||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
|
||||||
message = shared.fixPotentiallyInvalidUTF8Data(message)
|
|
||||||
return {"sentMessage": [{
|
|
||||||
'msgid': hexlify(msgid),
|
|
||||||
'toAddress': toAddress,
|
|
||||||
'fromAddress': fromAddress,
|
|
||||||
'subject': base64.b64encode(subject),
|
|
||||||
'message': base64.b64encode(message),
|
|
||||||
'encodingType': encodingtype,
|
|
||||||
'lastActionTime': lastactiontime,
|
|
||||||
'status': status,
|
|
||||||
'ackData': hexlify(ackdata)
|
|
||||||
}]}
|
|
||||||
|
|
||||||
@command('trashMessage')
|
@command('trashMessage')
|
||||||
def HandleTrashMessage(self, msgid):
|
def HandleTrashMessage(self, msgid):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user