diff --git a/src/adapter.cc b/src/adapter.cc index e411a4c..305fca2 100644 --- a/src/adapter.cc +++ b/src/adapter.cc @@ -7,7 +7,8 @@ namespace pEp { namespace PythonAdapter { Adapter::Adapter(bool unregister_this) - : flag_unregister(unregister_this) + : flag_unregister(unregister_this), passive_mode(false), + unencrypted_subject(false) { session(init); } @@ -41,8 +42,13 @@ namespace pEp { case init: ++booked; - if (!_session) + if (!_session) { status = ::init(&_session, _messageToSend, _inject_sync_event); + if (!status) { + ::config_passive_mode(_session, passive_mode); + ::config_unencrypted_subject(_session, unencrypted_subject); + } + } break; default: @@ -55,6 +61,16 @@ namespace pEp { return _session; } + void Adapter::config_passive_mode(bool enable) + { + ::config_passive_mode(session(), enable); + } + + void Adapter::config_unencrypted_subject(bool enable) + { + ::config_unencrypted_subject(session(), enable); + } + PyObject *Adapter::ui_object(PyObject *value) { lock_guard lock(mtx()); diff --git a/src/adapter.hh b/src/adapter.hh index 8ae71ff..fcee9fc 100644 --- a/src/adapter.hh +++ b/src/adapter.hh @@ -14,6 +14,8 @@ namespace pEp { class Adapter { bool flag_unregister; + bool passive_mode; + bool unencrypted_subject; public: Adapter(bool unregister_this = false); @@ -32,6 +34,9 @@ namespace pEp { return q; } + void config_passive_mode(bool enable); + void config_unencrypted_subject(bool enable); + protected: static PyObject *ui_object(PyObject *value = nullptr); static int _inject_sync_event(SYNC_EVENT ev, void *management); diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index b950b21..4f53eec 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -21,6 +21,17 @@ namespace pEp { using namespace std; Adapter adapter(true); + + void config_passive_mode(bool enable) + { + adapter.config_passive_mode(enable); + } + + void config_unencrypted_subject(bool enable) + { + adapter.config_unencrypted_subject(enable); + } + scope *_scope = NULL; static const char *version_string = "p≡p Python adapter version 0.3"; @@ -81,6 +92,12 @@ BOOST_PYTHON_MODULE(pEp) scope().attr("about") = about(); + def("config_passive_mode", pEp::PythonAdapter::config_passive_mode, + "do not attach pub keys to all messages"); + + def("config_unencrypted_subject", pEp::PythonAdapter::config_unencrypted_subject, + "do not encrypt the subject of messages"); + auto identity_class = class_("Identity", "Identity(address, username, user_id='', fpr='', comm_type=0, lang='en')\n" "\n" diff --git a/test/minimail.py b/test/minimail.py index 11fb91a..354ca4c 100644 --- a/test/minimail.py +++ b/test/minimail.py @@ -82,7 +82,7 @@ def recv_all(inbox, marker): if newer(p, inbox / marker): with open(p, "rb") as f: t = f.read(-1) - r.append(t) + r.append((p, t)) (inbox / marker).touch(exist_ok=True) if not r: sleep(1) diff --git a/test/sync_handshake.py b/test/sync_handshake.py index 1ca0751..bea16dd 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -44,6 +44,7 @@ output = print DONT_TRIGGER_SYNC = 0x200 SYNC_HANDSHAKE_ACCEPTED = 0 +SYNC_HANDSHAKE_REJECTED = 1 def print_msg(p): @@ -85,8 +86,13 @@ class UserInterface(pEp.UserInterface): def notifyHandshake(self, me, partner, signal): output("on " + device_name + " signal " + str(signal) + " for identities " + str(me.fpr) + " " + str(partner.fpr)) - - self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) + try: + if options.reject: + self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED) + else: + self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) + except NameError: + self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) def run(name, color=None): @@ -105,11 +111,9 @@ def run(name, color=None): try: while True: l = minimail.recv_all(inbox, name) - for m in l: + for n, m in l: msg = pEp.Message(m) msg2, keys, rating, flags = msg.decrypt() - #text = "\n" + msg2.attachments[0].decode() - #output(text) except KeyboardInterrupt: pass @@ -126,6 +130,10 @@ if __name__=="__main__": "(default: name of actual directory)") optParser.add_option("--color", action="store", type="string", dest="color", help="print debug output in this color", default=None) + optParser.add_option("--reject", action="store_true", dest="reject", + help="reject device group") + optParser.add_option("--accept", action="store_false", dest="reject", + help="accept device group (default)") options, args = optParser.parse_args() if not options.exec_for: