Browse Source

Now handles consumed messaged

master
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 flags = (int) _flags;
bool consumed = status == PEP_MESSAGE_CONSUMED;
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)

5
src/pEpmodule.cc

@ -32,6 +32,8 @@ namespace pEp {
return;
if (status >= 0x400 && status <= 0x4ff)
return;
if (status == PEP_MESSAGE_CONSUMED)
return;
if (status == PEP_OUT_OF_MEMORY)
throw bad_alloc();
if (status == PEP_ILLEGAL_VALUE)
@ -249,13 +251,14 @@ BOOST_PYTHON_MODULE(pEp)
" flags 1 is force encryption\n"
)
.def("decrypt", &Message::decrypt,
"msg2, keys, rating, flags = msg1.decrypt()\n"
"msg2, keys, rating, consumed, flags = msg1.decrypt()\n"
"\n"
"decrypts a p≡p message and returns a tuple with data\n"
"\n"
" msg the decrypted p≡p message\n"
" keys a list of keys being used\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"
)
.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
handler = None
own_addresses = []
indent = 0
i_name = ""
def create_account(address, name):
global own_addresses
@ -15,41 +17,56 @@ def create_account(address, name):
pEp.myself(i)
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:
return "-" * 80
printi("-" * 80)
indent = indent - 1
else:
return ("-" * (39 - int(len(blah)/2)) +
" " + blah + " " +
"-" * (39 - len(blah) + int(len(blah)/2)))
indent = indent + 1
printi("-" * (39 - 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):
global pEp, handler, own_addresses
global pEp, handler, own_addresses, i_name
i_name = iname
pEp = importlib.import_module("pEp")
class Handler(pEp.SyncMixIn):
def messageToSend(self, msg):
print(header("SYNC MESSAGE from instance"+iname))
print("from :", msg.from_)
print("to :", msg.to)
print("short :", msg.shortmsg)
print("long :", (msg.longmsg[:250]+" [...]"
if len(msg.longmsg)>250
else msg.longmsg))
print(msg.attachments)
print(header())
printheader("SYNC MESSAGE to send")
printmsg(msg)
printheader()
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.append(str(msg))
msgs_folders[rcpt.address] = msgs
def showHandshake(self, me, partner):
print(header("HANDSHAKE from instance"+iname))
print("handshake needed between " + repr(me) + " and " + repr(partner))
print(header())
printheader("show HANDSHAKE dialog")
printi("handshake needed between " + repr(me) + " and " + repr(partner))
printheader()
# TODO: accept or reject
handler = Handler()
@ -61,27 +78,38 @@ def pEp_instance_run(iname, conn, msgs_folders):
func = order[0]
print(header("DECRYPT messages for instance "+iname))
printheader("DECRYPT messages")
# decrypt every non-consumed message for all instance accounts
for own_address in own_addresses:
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)
decrypt_result = msg.decrypt()
# TODO get status instead of an exception when consumed...
#if decrypt_result == 0xff02: #PEP_MESSAGE_CONSUMED
# msgs_for_me.pop(idx)
print(header())
printi("--- decrypt()")
printmsg(msg)
msg2, keys, rating, consumed, flags = msg.decrypt()
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
if func is not None:
print(header("Instance " + iname + " : function " + func.__name__))
printheader("Executing function " + func.__name__)
args, kwargs = order[1:] + [[], {}][len(order) - 1:]
print("args :", args)
print("kwargs :", kwargs)
printi("args :", args)
printi("kwargs :", kwargs)
res = func(*args,**kwargs)
print(" -> ", res)
print(header())
printi("function " + func.__name__ + " returned :", res)
printheader()
conn.send(res)

Loading…
Cancel
Save