Browse Source

Now handles consumed messaged

PYADPT-55
Edouard Tisserant 9 years ago
parent
commit
2b014528e6
  1. 3
      src/message_api.cc
  2. 5
      src/pEpmodule.cc
  3. 92
      test/multipEp.py

3
src/message_api.cc

@ -51,9 +51,10 @@ namespace pEp {
int rating = (int) _rating; int rating = (int) _rating;
int flags = (int) _flags; int flags = (int) _flags;
bool consumed = status == PEP_MESSAGE_CONSUMED;
Message dst = _dst ? Message(_dst) : Message(src); Message dst = _dst ? Message(_dst) : Message(src);
return boost::python::make_tuple(dst, keylist, rating, flags); return boost::python::make_tuple(dst, keylist, rating, consumed, flags);
} }
int _color(int rating) int _color(int rating)

5
src/pEpmodule.cc

@ -32,6 +32,8 @@ namespace pEp {
return; return;
if (status >= 0x400 && status <= 0x4ff) if (status >= 0x400 && status <= 0x4ff)
return; return;
if (status == PEP_MESSAGE_CONSUMED)
return;
if (status == PEP_OUT_OF_MEMORY) if (status == PEP_OUT_OF_MEMORY)
throw bad_alloc(); throw bad_alloc();
if (status == PEP_ILLEGAL_VALUE) if (status == PEP_ILLEGAL_VALUE)
@ -249,13 +251,14 @@ BOOST_PYTHON_MODULE(pEp)
" flags 1 is force encryption\n" " flags 1 is force encryption\n"
) )
.def("decrypt", &Message::decrypt, .def("decrypt", &Message::decrypt,
"msg2, keys, rating, flags = msg1.decrypt()\n" "msg2, keys, rating, consumed, flags = msg1.decrypt()\n"
"\n" "\n"
"decrypts a p≡p message and returns a tuple with data\n" "decrypts a p≡p message and returns a tuple with data\n"
"\n" "\n"
" msg the decrypted p≡p message\n" " msg the decrypted p≡p message\n"
" keys a list of keys being used\n" " keys a list of keys being used\n"
" rating the rating of the message as integer\n" " rating the rating of the message as integer\n"
" consumed boolean denoting message is consumed by sync\n"
" flags flags set while decryption (reserved)\n" " flags flags set while decryption (reserved)\n"
) )
.add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have") .add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have")

92
test/multipEp.py

@ -8,6 +8,8 @@ from collections import OrderedDict
pEp = None pEp = None
handler = None handler = None
own_addresses = [] own_addresses = []
indent = 0
i_name = ""
def create_account(address, name): def create_account(address, name):
global own_addresses global own_addresses
@ -15,41 +17,56 @@ def create_account(address, name):
pEp.myself(i) pEp.myself(i)
own_addresses.append(address) own_addresses.append(address)
def header(blah=None): def printi(*args):
global indent
print(i_name + ">" * indent, *args)
def printheader(blah=None):
global indent
if blah is None: if blah is None:
return "-" * 80 printi("-" * 80)
indent = indent - 1
else: else:
return ("-" * (39 - int(len(blah)/2)) + indent = indent + 1
" " + blah + " " + printi("-" * (39 - int(len(blah)/2)) +
"-" * (39 - len(blah) + int(len(blah)/2))) " " + blah + " " +
"-" * (39 - len(blah) + int(len(blah)/2)))
def printmsg(msg):
printi("from :", msg.from_)
printi("to :", msg.to)
printi("short :", msg.shortmsg)
printi("opt_fields :", msg.opt_fields)
lng = msg.longmsg.splitlines()
lngcut = lng[:20]+["[...]"] if len(lng)>20 else lng
pfx = "long : "
for l in lngcut :
printi(pfx + l)
pfx = " "
printi("attachments : ", msg.attachments)
def pEp_instance_run(iname, conn, msgs_folders): def pEp_instance_run(iname, conn, msgs_folders):
global pEp, handler, own_addresses global pEp, handler, own_addresses, i_name
i_name = iname
pEp = importlib.import_module("pEp") pEp = importlib.import_module("pEp")
class Handler(pEp.SyncMixIn): class Handler(pEp.SyncMixIn):
def messageToSend(self, msg): def messageToSend(self, msg):
print(header("SYNC MESSAGE from instance"+iname)) printheader("SYNC MESSAGE to send")
print("from :", msg.from_) printmsg(msg)
print("to :", msg.to) printheader()
print("short :", msg.shortmsg)
print("long :", (msg.longmsg[:250]+" [...]"
if len(msg.longmsg)>250
else msg.longmsg))
print(msg.attachments)
print(header())
for rcpt in msg.to + msg.cc + msg.bcc: for rcpt in msg.to + msg.cc + msg.bcc:
# list inside dict from MP manager are not mutable, apparently. # list inside dict from MP manager are not proxified.
msgs = msgs_folders.get(rcpt.address,[]) msgs = msgs_folders.get(rcpt.address,[])
msgs.append(str(msg)) msgs.append(str(msg))
msgs_folders[rcpt.address] = msgs msgs_folders[rcpt.address] = msgs
def showHandshake(self, me, partner): def showHandshake(self, me, partner):
print(header("HANDSHAKE from instance"+iname)) printheader("show HANDSHAKE dialog")
print("handshake needed between " + repr(me) + " and " + repr(partner)) printi("handshake needed between " + repr(me) + " and " + repr(partner))
print(header()) printheader()
# TODO: accept or reject # TODO: accept or reject
handler = Handler() handler = Handler()
@ -61,27 +78,38 @@ def pEp_instance_run(iname, conn, msgs_folders):
func = order[0] func = order[0]
print(header("DECRYPT messages for instance "+iname)) printheader("DECRYPT messages")
# decrypt every non-consumed message for all instance accounts # decrypt every non-consumed message for all instance accounts
for own_address in own_addresses: for own_address in own_addresses:
msgs_for_me = msgs_folders[own_address] msgs_for_me = msgs_folders[own_address]
for idx, msgstr in enumerate(msgs_for_me): for msgstr in msgs_for_me:
msg = pEp.incoming_message(msgstr) msg = pEp.incoming_message(msgstr)
decrypt_result = msg.decrypt() printi("--- decrypt()")
# TODO get status instead of an exception when consumed... printmsg(msg)
#if decrypt_result == 0xff02: #PEP_MESSAGE_CONSUMED msg2, keys, rating, consumed, flags = msg.decrypt()
# msgs_for_me.pop(idx)
print(header()) if consumed: #PEP_MESSAGE_CONSUMED
printi("--- PEP_MESSAGE_CONSUMED")
# folder may have changed in the meantime,
# remove item directly from latest version of it.
folder = msgs_folders[own_address]
folder.remove(msgstr)
msgs_folders[own_address] = folder
else :
printi("->-")
printmsg(msg2)
printi("---")
printheader()
res = None res = None
if func is not None: if func is not None:
print(header("Instance " + iname + " : function " + func.__name__)) printheader("Executing function " + func.__name__)
args, kwargs = order[1:] + [[], {}][len(order) - 1:] args, kwargs = order[1:] + [[], {}][len(order) - 1:]
print("args :", args) printi("args :", args)
print("kwargs :", kwargs) printi("kwargs :", kwargs)
res = func(*args,**kwargs) res = func(*args,**kwargs)
print(" -> ", res) printi("function " + func.__name__ + " returned :", res)
print(header()) printheader()
conn.send(res) conn.send(res)

Loading…
Cancel
Save