src/pEpmodule.cc
author Volker Birk <vb@pep-project.org>
Sun, 14 Apr 2019 20:56:24 +0200
branchsync
changeset 268 81bfa5a09184
parent 265 90b64446e536
child 278 e97e3f2fd083
permissions -rw-r--r--
adding SYNC_NOTIFY_SOLE and SYNC_NOTIFY_IN_GROUP
vb@180
     1
// This file is under GNU Affero General Public License 3.0
vb@180
     2
// see LICENSE.txt
vb@180
     3
vb@0
     4
#include "pEpmodule.hh"
vb@20
     5
#include <boost/locale.hpp>
vb@1
     6
#include <string>
vb@29
     7
#include <sstream>
vb@65
     8
#include <iomanip>
vb@35
     9
#include "basic_api.hh"
vb@38
    10
#include "message_api.hh"
vb@181
    11
#include "user_interface.hh"
vb@183
    12
#include "adapter.hh"
vb@0
    13
krista@171
    14
#include <mutex>
krista@171
    15
vb@260
    16
#include <pEp/key_reset.h>
edouard@127
    17
#include <pEp/message_api.h>
vb@180
    18
#include <pEp/sync_api.h>
edouard@127
    19
vb@0
    20
namespace pEp {
vb@0
    21
    namespace PythonAdapter {
vb@1
    22
        using namespace std;
vb@1
    23
vb@189
    24
        Adapter adapter(true);
vb@258
    25
vb@258
    26
        void config_passive_mode(bool enable)
vb@258
    27
        {
vb@259
    28
            ::config_passive_mode(adapter.session(), enable);
vb@258
    29
        }
vb@258
    30
vb@258
    31
        void config_unencrypted_subject(bool enable)
vb@258
    32
        {
vb@259
    33
            ::config_unencrypted_subject(adapter.session(), enable);
vb@258
    34
        }
vb@258
    35
vb@260
    36
        void key_reset_user(string user_id, string fpr)
vb@260
    37
        {
vb@260
    38
            if (user_id == "")
vb@260
    39
                throw invalid_argument("user_id required");
vb@260
    40
vb@260
    41
            PEP_STATUS status = ::key_reset_user(adapter.session(),
vb@260
    42
                    user_id.c_str(), fpr != "" ?  fpr.c_str() : nullptr);
vb@260
    43
            _throw_status(status);
vb@260
    44
        }
vb@260
    45
vb@260
    46
        void key_reset_user2(string user_id)
vb@260
    47
        {
vb@260
    48
            key_reset_user(user_id, "");
vb@260
    49
        }
vb@260
    50
vb@260
    51
        void key_reset_all_own_keys()
vb@260
    52
        {
vb@260
    53
            PEP_STATUS status = ::key_reset_all_own_keys(adapter.session());
vb@260
    54
            _throw_status(status);
vb@260
    55
        }
vb@260
    56
vb@190
    57
        scope *_scope = NULL;
vb@181
    58
vb@199
    59
        static const char *version_string = "p≡p Python adapter version 0.3";
vb@21
    60
        static string about()
vb@0
    61
        {
vb@1
    62
            string version = string(version_string) + "\np≡p version "
vb@1
    63
                + PEP_VERSION + "\n";
vb@8
    64
            return version;
vb@0
    65
        }
vb@29
    66
vb@38
    67
        void _throw_status(PEP_STATUS status)
vb@38
    68
        {
vb@38
    69
            if (status == PEP_STATUS_OK)
vb@38
    70
                return;
vb@38
    71
            if (status >= 0x400 && status <= 0x4ff)
vb@38
    72
                return;
vb@38
    73
            if (status == PEP_OUT_OF_MEMORY)
vb@38
    74
                throw bad_alloc();
vb@38
    75
            if (status == PEP_ILLEGAL_VALUE)
vb@38
    76
                throw invalid_argument("illegal value");
vb@38
    77
vb@38
    78
            stringstream build;
vb@65
    79
            build << setfill('0') << "p≡p 0x" << setw(4) << hex << status;
vb@38
    80
            throw runtime_error(build.str());
vb@38
    81
        }
vb@190
    82
vb@190
    83
        PEP_STATUS _messageToSend(::message *msg)
vb@190
    84
        {
vb@190
    85
            if (!_scope)
vb@190
    86
                return PEP_SEND_FUNCTION_NOT_REGISTERED;
vb@190
    87
vb@190
    88
            try {
vb@190
    89
                object m = _scope->attr("messageToSend");
vb@190
    90
                call< void >(m.ptr(), Message(msg));
vb@190
    91
            }
vb@190
    92
            catch (exception& e) { }
vb@190
    93
vb@190
    94
            return PEP_STATUS_OK;
vb@190
    95
        }
vb@190
    96
vb@190
    97
        void messageToSend(Message msg) {
vb@190
    98
            throw runtime_error("implement pEp.messageToSend(msg)");
vb@190
    99
        }
vb@0
   100
    }
vb@0
   101
}
vb@0
   102
vb@8
   103
BOOST_PYTHON_MODULE(pEp)
vb@0
   104
{
vb@8
   105
    using namespace boost::python;
vb@20
   106
    using namespace boost::locale;
vb@8
   107
    using namespace pEp::PythonAdapter;
vb@9
   108
vb@86
   109
    docstring_options doc_options(true, false, false);
vb@9
   110
vb@20
   111
    generator gen;
vb@20
   112
    std::locale::global(gen(""));
vb@190
   113
    _scope = new scope();
vb@20
   114
vb@21
   115
    scope().attr("about") = about();
edouard@112
   116
    
vb@259
   117
    def("passive_mode", pEp::PythonAdapter::config_passive_mode,
vb@258
   118
            "do not attach pub keys to all messages");
vb@258
   119
vb@259
   120
    def("unencrypted_subject", pEp::PythonAdapter::config_unencrypted_subject,
vb@258
   121
            "do not encrypt the subject of messages");
vb@258
   122
vb@260
   123
    def("key_reset", pEp::PythonAdapter::key_reset_user,
vb@260
   124
            "reset the default database status for the user / keypair provided\n"
vb@260
   125
            "This will effectively perform key_reset on each identity\n"
vb@260
   126
            "associated with the key and user_id, if a key is provided, and for\n"
vb@260
   127
            "each key (and all of their identities) if an fpr is not.");
vb@260
   128
vb@260
   129
    def("key_reset", pEp::PythonAdapter::key_reset_user2,
vb@260
   130
            "reset the default database status for the user / keypair provided\n"
vb@260
   131
            "This will effectively perform key_reset on each identity\n"
vb@260
   132
            "associated with the key and user_id, if a key is provided, and for\n"
vb@260
   133
            "each key (and all of their identities) if an fpr is not.");
vb@260
   134
vb@260
   135
    def("key_reset_all_own_keys", pEp::PythonAdapter::key_reset_all_own_keys,
vb@260
   136
            "revoke and mistrust all own keys, generate new keys for all\n"
vb@260
   137
            "own identities, and opportunistically communicate key reset\n"
vb@260
   138
            "information to people we have recently contacted.");
vb@260
   139
edouard@138
   140
    auto identity_class = class_<pEp::PythonAdapter::Identity>("Identity",
vb@86
   141
    "Identity(address, username, user_id='', fpr='', comm_type=0, lang='en')\n"
vb@86
   142
    "\n"
vb@86
   143
    "represents a p≡p identity\n"
vb@86
   144
    "\n"
vb@86
   145
    "an identity is a network address, under which a user is represented in\n"
vb@86
   146
    "the network\n"
vb@86
   147
    "\n"
vb@86
   148
    "   address     network address, either an SMTP address or a URI\n"
vb@86
   149
    "   username    real name or nickname for user\n"
vb@86
   150
    "   user_id     ID this user is handled by the application\n"
vb@86
   151
    "   fpr         full fingerprint of the key being used as key ID,\n"
vb@86
   152
    "               hex encoded\n"
vb@86
   153
    "   comm_type   first rating level of this communication channel\n"
vb@86
   154
    "   lang        ISO 639-1 language code for language being preferred\n"
vb@92
   155
    "               on this communication channel\n"
vb@86
   156
        )
edouard@137
   157
        .def(boost::python::init<string>())
edouard@137
   158
        .def(boost::python::init<string, string>())
edouard@137
   159
        .def(boost::python::init<string, string, string>())
edouard@137
   160
        .def(boost::python::init<string, string, string, string>())
edouard@137
   161
        .def(boost::python::init<string, string, string, string, int>())
edouard@137
   162
        .def(boost::python::init<string, string, string, string, int, string>())
edouard@138
   163
        .def("__repr__", &pEp::PythonAdapter::Identity::_repr)
edouard@138
   164
        .def("__str__", &pEp::PythonAdapter::Identity::_str,
vb@260
   165
            "string representation of this identity\n"
vb@260
   166
            "following the pattern 'username < address >'\n"
vb@86
   167
                )
vb@260
   168
        .def("key_reset", &pEp::PythonAdapter::Identity::key_reset,
vb@260
   169
                boost::python::arg("fpr")=object(""),
vb@260
   170
            "reset the default database status for the identity / keypair provided. If this\n"
vb@260
   171
            "corresponds to the own user and a private key, also revoke the key, generate a\n"
vb@260
   172
            "new one, and communicate the reset to recently contacted pEp partners for this\n"
vb@260
   173
            "identity. If it does not, remove the key from the keyring; the key's status is\n"
vb@260
   174
            "completely fresh on next contact from the partner.")
vb@260
   175
edouard@138
   176
        .add_property("address", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::address,
edouard@138
   177
                (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::address,
vb@10
   178
                "email address or URI")
edouard@138
   179
        .add_property("fpr", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::fpr,
edouard@138
   180
                (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::fpr,
vb@21
   181
                "key ID (full fingerprint, hex encoded)")
edouard@138
   182
        .add_property("user_id", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::user_id,
edouard@138
   183
                (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::user_id,
vb@21
   184
                "ID of person associated or 'pEp_own_userId' if own identity")
edouard@138
   185
        .add_property("username", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::username,
edouard@138
   186
                (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::username,
vb@21
   187
                "name in full of person associated")
edouard@138
   188
        .add_property("comm_type", (int(pEp::PythonAdapter::Identity::*)())
edouard@138
   189
                (PEP_comm_type(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::comm_type,
edouard@138
   190
                (void(pEp::PythonAdapter::Identity::*)(int))
edouard@138
   191
                (void(pEp::PythonAdapter::Identity::*)(PEP_comm_type)) &pEp::PythonAdapter::Identity::comm_type,
vb@86
   192
                 "communication type, first rating level (p≡p internal)")
edouard@138
   193
        .add_property("lang", (string(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::lang,
edouard@138
   194
                (void(pEp::PythonAdapter::Identity::*)(string)) &pEp::PythonAdapter::Identity::lang,
vb@10
   195
                "ISO 639-1 language code")
edouard@138
   196
        .add_property("flags", (identity_flags_t(pEp::PythonAdapter::Identity::*)()) &pEp::PythonAdapter::Identity::flags,
edouard@138
   197
                (void(pEp::PythonAdapter::Identity::*)(identity_flags_t)) &pEp::PythonAdapter::Identity::flags,
vb@55
   198
                "flags (p≡p internal)")
edouard@138
   199
        .add_property("rating", &pEp::PythonAdapter::Identity::rating, "rating of Identity")
edouard@138
   200
        .add_property("color", &pEp::PythonAdapter::Identity::color, "color of Identity")
edouard@138
   201
        .def("__deepcopy__", &pEp::PythonAdapter::Identity::deepcopy)
vb@178
   202
        .def("update", &pEp::PythonAdapter::Identity::update, "update Identity")
edouard@138
   203
        .def("__copy__", &pEp::PythonAdapter::Identity::copy);
vb@21
   204
    
vb@21
   205
    identity_class.attr("PEP_OWN_USERID") = "pEp_own_userId";
vb@20
   206
vb@86
   207
    auto blob_class = class_<Message::Blob>("Blob",
vb@86
   208
    "Blob(data, mime_type='', filename='')\n"
vb@86
   209
    "\n"
vb@86
   210
    "Binary large object\n"
vb@86
   211
    "\n"
vb@86
   212
    "   data            bytes-like object\n"
vb@86
   213
    "   mime_type       MIME type for the data\n"
vb@86
   214
    "   filename        filename to store the data\n" ,
edouard@137
   215
            boost::python::init< object, char const*, char const* >(args("data", "mime_type", "filename")))
edouard@137
   216
        .def(boost::python::init<object, string>())
edouard@137
   217
        .def(boost::python::init<object>())
vb@30
   218
        .def("__repr__", &Message::Blob::_repr)
vb@81
   219
        .def("__len__", &Message::Blob::size, "size of Blob data in bytes")
vb@86
   220
        .def("decode", (string(Message::Blob::*)()) &Message::Blob::decode)
vb@86
   221
        .def("decode", (string(Message::Blob::*)(string)) &Message::Blob::decode,
vb@90
   222
    "text = blob.decode(encoding='')\n"
vb@86
   223
    "\n"
vb@86
   224
    "decode Blob data into string depending on MIME type if encoding=''\n"
vb@89
   225
    "\n"
vb@86
   226
    "   mime_type='application/pEp.sync'    decode as 'pEp.sync'\n"
vb@86
   227
    "   other mime_type                     decode as 'ascii' by default\n"
vb@86
   228
                )
vb@20
   229
        .add_property("mime_type", (string(Message::Blob::*)()) &Message::Blob::mime_type,
vb@20
   230
                (void(Message::Blob::*)(string)) &Message::Blob::mime_type,
vb@20
   231
                "MIME type of object in Blob")
vb@20
   232
        .add_property("filename", (string(Message::Blob::*)()) &Message::Blob::filename,
vb@20
   233
                (void(Message::Blob::*)(string)) &Message::Blob::filename,
vb@80
   234
                "filename of object in Blob");
vb@20
   235
vb@21
   236
    ((PyTypeObject *)(void *)blob_class.ptr())->tp_as_buffer = &Message::Blob::bp;
vb@21
   237
vb@86
   238
    auto message_class = class_<Message>("Message",
vb@88
   239
    "Message(dir=1, from=None)\n"
vb@88
   240
    "\n"
vb@88
   241
    "new p≡p message\n"
vb@88
   242
    "\n"
vb@88
   243
    "   dir         1 for outgoing, 2 for incoming\n"
vb@88
   244
    "   from        Identity() of sender\n"
vb@88
   245
    "\n"
vb@86
   246
    "Message(mime_text)\n"
vb@86
   247
    "\n"
vb@88
   248
    "new incoming p≡p message\n"
vb@86
   249
    "\n"
vb@86
   250
    "   mime_text       text in Multipurpose Internet Mail Extensions format\n"
vb@86
   251
                )
edouard@137
   252
        .def(boost::python::init<int>())
edouard@138
   253
        .def(boost::python::init<int, pEp::PythonAdapter::Identity *>())
edouard@137
   254
        .def(boost::python::init<string>())
vb@86
   255
        .def("__str__", &Message::_str,
vb@86
   256
    "the string representation of a Message is it's MIME text"
vb@86
   257
                )
vb@42
   258
        .def("__repr__", &Message::_repr)
vb@21
   259
        .add_property("dir", (int(Message::*)())
vb@21
   260
                (PEP_msg_direction(Message::*)()) &Message::dir,
vb@21
   261
                (void(Message::*)(int))
vb@21
   262
                (void(Message::*)(PEP_msg_direction)) &Message::dir,
vb@21
   263
                "0: incoming, 1: outgoing message")
vb@21
   264
        .add_property("id", (string(Message::*)()) &Message::id,
vb@21
   265
                (void(Message::*)(string)) &Message::id,
vb@21
   266
                "message ID")
vb@21
   267
        .add_property("shortmsg", (string(Message::*)()) &Message::shortmsg,
vb@21
   268
                (void(Message::*)(string)) &Message::shortmsg,
vb@21
   269
                "subject or short message")
vb@21
   270
        .add_property("longmsg", (string(Message::*)()) &Message::longmsg,
vb@21
   271
                (void(Message::*)(string)) &Message::longmsg,
vb@21
   272
                "body or long version of message")
vb@21
   273
        .add_property("longmsg_formatted", (string(Message::*)()) &Message::longmsg_formatted,
vb@21
   274
                (void(Message::*)(string)) &Message::longmsg_formatted,
vb@21
   275
                "HTML body or fromatted long version of message")
vb@57
   276
        .add_property("attachments", (boost::python::tuple(Message::*)()) &Message::attachments,
vb@176
   277
                (void(Message::*)(boost::python::list)) &Message::attachments,
vb@21
   278
                "tuple of Blobs with attachments; setting moves Blobs to attachment tuple")
vb@21
   279
        .add_property("sent", (time_t(Message::*)()) &Message::sent,
vb@21
   280
                (void(Message::*)(time_t)) &Message::sent,
vb@21
   281
                "time when message was sent in UTC seconds since epoch")
vb@21
   282
        .add_property("recv", (time_t(Message::*)()) &Message::recv,
vb@21
   283
                (void(Message::*)(time_t)) &Message::recv,
vb@21
   284
                "time when message was received in UTC seconds since epoch")
edouard@138
   285
        .add_property("from_", (pEp::PythonAdapter::Identity(Message::*)()) &Message::from,
vb@21
   286
                (void(Message::*)(object)) &Message::from,
vb@21
   287
                "identity where message is from")
vb@176
   288
        .add_property("to", (boost::python::list(Message::*)()) &Message::to,
vb@176
   289
                (void(Message::*)(boost::python::list)) &Message::to,
vb@21
   290
                "list of identities message is going to")
edouard@138
   291
        .add_property("recv_by", (pEp::PythonAdapter::Identity(Message::*)()) &Message::recv_by,
vb@21
   292
                (void(Message::*)(object)) &Message::recv_by,
vb@21
   293
                "identity where message was received by")
vb@176
   294
        .add_property("cc", (boost::python::list(Message::*)()) &Message::cc,
vb@176
   295
                (void(Message::*)(boost::python::list)) &Message::cc,
vb@21
   296
                "list of identities message is going cc")
vb@176
   297
        .add_property("bcc", (boost::python::list(Message::*)()) &Message::bcc,
vb@176
   298
                (void(Message::*)(boost::python::list)) &Message::bcc,
vb@21
   299
                "list of identities message is going bcc")
vb@176
   300
        .add_property("reply_to", (boost::python::list(Message::*)()) &Message::reply_to,
vb@176
   301
                (void(Message::*)(boost::python::list)) &Message::reply_to,
vb@23
   302
                "list of identities where message will be replied to")
vb@176
   303
        .add_property("in_reply_to", (boost::python::list(Message::*)()) &Message::in_reply_to,
vb@176
   304
                (void(Message::*)(boost::python::list)) &Message::in_reply_to,
vb@24
   305
                "in_reply_to list")
vb@176
   306
        .add_property("references", (boost::python::list(Message::*)()) &Message::references,
vb@176
   307
                (void(Message::*)(boost::python::list)) &Message::references,
vb@25
   308
                "message IDs of messages this one is referring to")
vb@176
   309
        .add_property("keywords", (boost::python::list(Message::*)()) &Message::keywords,
vb@176
   310
                (void(Message::*)(boost::python::list)) &Message::keywords,
vb@26
   311
                "keywords this message should be stored under")
vb@26
   312
        .add_property("comments", (string(Message::*)()) &Message::comments,
vb@26
   313
                (void(Message::*)(string)) &Message::comments,
vb@27
   314
                "comments added to message")
vb@27
   315
        .add_property("opt_fields", (dict(Message::*)()) &Message::opt_fields,
vb@27
   316
                (void(Message::*)(dict)) &Message::opt_fields,
vb@28
   317
                "opt_fields of message")
vb@28
   318
        .add_property("enc_format", (int(Message::*)())
vb@28
   319
                (PEP_enc_format(Message::*)()) &Message::enc_format,
vb@28
   320
                (void(Message::*)(int))
vb@28
   321
                (void(Message::*)(PEP_enc_format)) &Message::enc_format,
vb@41
   322
                "0: unencrypted, 1: inline PGP, 2: S/MIME, 3: PGP/MIME, 4: p≡p format")
vb@86
   323
        .def("encrypt", (Message(Message::*)())&Message::encrypt)
vb@176
   324
        .def("encrypt", (Message(Message::*)(boost::python::list))&Message::_encrypt)
vb@176
   325
        .def("encrypt", (Message(Message::*)(boost::python::list,int))&Message::_encrypt)
vb@176
   326
        .def("encrypt", (Message(Message::*)(boost::python::list,int,int))&Message::_encrypt,
vb@90
   327
    "msg2 = msg1.encrypt(extra_keys=[], enc_format='pEp', flags=0)\n"
vb@86
   328
    "\n"
vb@86
   329
    "encrypts a p≡p message and returns the encrypted message\n"
vb@86
   330
    "\n"
vb@86
   331
    "   extra_keys      list of strings with fingerprints for extra keys to use\n"
vb@86
   332
    "                   for encryption\n"
vb@93
   333
    "   enc_format      0 for none, 1 for partitioned, 2 for S/MIME,\n"
vb@93
   334
    "                   3 for PGP/MIME, 4 for pEp\n"
vb@86
   335
    "   flags           1 is force encryption\n"
vb@86
   336
                )
vb@241
   337
        .def("decrypt", &Message::decrypt, boost::python::arg("flags")=0,
vb@188
   338
    "msg2, keys, rating, flags = msg1.decrypt()\n"
vb@86
   339
    "\n"
vb@86
   340
    "decrypts a p≡p message and returns a tuple with data\n"
vb@86
   341
    "\n"
vb@86
   342
    "   msg             the decrypted p≡p message\n"
vb@86
   343
    "   keys            a list of keys being used\n"
vb@86
   344
    "   rating          the rating of the message as integer\n"
vb@184
   345
    "   flags           flags set while decryption\n"
vb@86
   346
                )
vb@55
   347
        .add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have")
vb@60
   348
        .add_property("outgoing_color", &Message::outgoing_color, "color outgoing message will have")
vb@61
   349
        .def("__deepcopy__", &Message::deepcopy)
vb@61
   350
        .def("__copy__", &Message::copy);
vb@29
   351
vb@38
   352
    // basic API
vb@38
   353
edouard@127
   354
    def("update_identity", &pEp::PythonAdapter::update_identity,
vb@86
   355
    "update_identity(ident)\n"
vb@86
   356
    "\n"
vb@86
   357
    "update identity information\n"
vb@86
   358
    "call this to complete identity information when you at least have an address\n"
vb@86
   359
            );
edouard@127
   360
    def("myself", &pEp::PythonAdapter::myself,
vb@86
   361
    "myself(ident)\n"
vb@86
   362
    "\n"
vb@86
   363
    "ensures that the own identity is being complete\n"
vb@86
   364
    "supply ident.address and ident.username\n"
vb@86
   365
            );
edouard@127
   366
    def("trust_personal_key", &pEp::PythonAdapter::trust_personal_key,
edouard@103
   367
    "trust_personal_key(ident)\n"
edouard@103
   368
    "\n"
edouard@103
   369
    "mark a key as trusted with a person\n"
edouard@103
   370
            );
vb@35
   371
edouard@127
   372
    enum_<identity_flags>("identity_flags")
edouard@127
   373
        .value("PEP_idf_not_for_sync", PEP_idf_not_for_sync)
edouard@127
   374
        .value("PEP_idf_list", PEP_idf_list)
edouard@127
   375
        .value("PEP_idf_devicegroup", PEP_idf_devicegroup);
edouard@127
   376
edouard@127
   377
    def("set_identity_flags", &pEp::PythonAdapter::set_identity_flags,
edouard@127
   378
    "set_identity_flags(ident, flags)\n"
edouard@127
   379
    "\n"
edouard@127
   380
    "set identity flags\n"
edouard@127
   381
            );
edouard@127
   382
edouard@127
   383
    def("unset_identity_flags", &pEp::PythonAdapter::unset_identity_flags,
edouard@127
   384
    "unset_identity_flags(ident, flags)\n"
edouard@127
   385
    "\n"
edouard@127
   386
    "unset identity flags\n"
edouard@127
   387
            );
edouard@127
   388
vb@222
   389
    def("key_reset_trust", &pEp::PythonAdapter::key_reset_trust,
vb@222
   390
            "key_reset_trust(ident)\n"
vb@222
   391
            "\n"
vb@222
   392
            "reset trust bit or explicitly mistrusted status for an identity and "
vb@222
   393
            "its accompanying key/user_id pair\n"
vb@222
   394
        );
vb@222
   395
vb@38
   396
    // message API
vb@38
   397
edouard@127
   398
    enum_<PEP_rating>("PEP_rating")
edouard@127
   399
        .value("PEP_rating_undefined", PEP_rating_undefined)
edouard@127
   400
        .value("PEP_rating_cannot_decrypt", PEP_rating_cannot_decrypt)
edouard@127
   401
        .value("PEP_rating_have_no_key", PEP_rating_have_no_key)
edouard@127
   402
        .value("PEP_rating_unencrypted", PEP_rating_unencrypted)
edouard@127
   403
        .value("PEP_rating_unencrypted_for_some", PEP_rating_unencrypted_for_some)
edouard@127
   404
        .value("PEP_rating_unreliable", PEP_rating_unreliable)
edouard@127
   405
        .value("PEP_rating_reliable", PEP_rating_reliable)
edouard@127
   406
        .value("PEP_rating_trusted", PEP_rating_trusted)
edouard@127
   407
        .value("PEP_rating_trusted_and_anonymized", PEP_rating_trusted_and_anonymized)
edouard@127
   408
        .value("PEP_rating_fully_anonymous", PEP_rating_fully_anonymous)
edouard@127
   409
        .value("PEP_rating_mistrust", PEP_rating_mistrust)
edouard@127
   410
        .value("PEP_rating_b0rken", PEP_rating_b0rken)
edouard@127
   411
        .value("PEP_rating_under_attack", PEP_rating_under_attack);
edouard@127
   412
vb@86
   413
    def("incoming_message", &incoming_message,
vb@86
   414
    "msg = incoming_message(mime_text)\n"
vb@86
   415
    "\n"
vb@86
   416
    "create an incoming message from a MIME text"
vb@86
   417
            );
vb@86
   418
    def("outgoing_message", &outgoing_message,
vb@86
   419
    "msg = outgoing_message(ident)\n"
vb@86
   420
    "\n"
vb@86
   421
    "create an outgoing message using an own identity"
vb@86
   422
            );
vb@86
   423
    def("color", &_color,
vb@86
   424
    "c = color(rating)\n"
vb@86
   425
    "\n"
vb@86
   426
    "calculate color value out of rating"
vb@86
   427
            );
vb@86
   428
    def("trustwords", &_trustwords,
vb@86
   429
    "text = trustwords(ident_own, ident_partner)\n"
vb@86
   430
    "\n"
vb@86
   431
    "calculate trustwords for two Identities");
vb@38
   432
vb@190
   433
    // messageToSend()
vb@190
   434
vb@190
   435
    def("messageToSend", &pEp::PythonAdapter::messageToSend,
vb@190
   436
    "messageToSend(msg)\n"
vb@190
   437
    "\n"
vb@190
   438
    "override pEp.messageToSend(msg) with your own implementation\n"
vb@190
   439
    "this callback is being called when a p≡p management message needs to be sent");
vb@190
   440
vb@182
   441
    // Sync API
vb@47
   442
edouard@138
   443
    enum_<sync_handshake_signal>("sync_handshake_signal")
edouard@139
   444
        .value("SYNC_NOTIFY_UNDEFINED"             , SYNC_NOTIFY_UNDEFINED)
edouard@139
   445
        .value("SYNC_NOTIFY_INIT_ADD_OUR_DEVICE"   , SYNC_NOTIFY_INIT_ADD_OUR_DEVICE)
edouard@139
   446
        .value("SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE" , SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE)
edouard@139
   447
        .value("SYNC_NOTIFY_INIT_FORM_GROUP"       , SYNC_NOTIFY_INIT_FORM_GROUP)
edouard@139
   448
        .value("SYNC_NOTIFY_TIMEOUT"               , SYNC_NOTIFY_TIMEOUT)
edouard@139
   449
        .value("SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED" , SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED)
edouard@147
   450
        .value("SYNC_NOTIFY_ACCEPTED_GROUP_CREATED", SYNC_NOTIFY_ACCEPTED_GROUP_CREATED)
vb@268
   451
        .value("SYNC_NOTIFY_OVERTAKEN"             , SYNC_NOTIFY_OVERTAKEN)
vb@268
   452
        .value("SYNC_NOTIFY_SOLE"                  , SYNC_NOTIFY_SOLE)
vb@268
   453
        .value("SYNC_NOTIFY_IN_GROUP"              , SYNC_NOTIFY_IN_GROUP);
edouard@138
   454
vb@182
   455
    auto user_interface_class = class_<UserInterface, UserInterface_callback, boost::noncopyable>(
vb@181
   456
            "UserInterface",
vb@182
   457
    "class MyUserInterface(UserInterface):\n"
edouard@138
   458
    "   def notifyHandshake(self, me, partner):\n"
edouard@138
   459
    "       ...\n"
edouard@138
   460
    "\n"
vb@182
   461
    "p≡p User Interface class\n"
vb@182
   462
    "To be used as a mixin\n"
vb@182
   463
    )
vb@181
   464
        .def("notifyHandshake", &UserInterface::notifyHandshake,
edouard@138
   465
    "notifyHandshake(self, me, partner)\n"
vb@86
   466
    "\n"
vb@86
   467
    "   me              own identity\n"
vb@86
   468
    "   partner         identity of communication partner\n"
vb@86
   469
    "\n"
vb@182
   470
    "overwrite this method with an implementation of a handshake dialog")
vb@181
   471
        .def("deliverHandshakeResult", &UserInterface::deliverHandshakeResult,
vb@254
   472
                boost::python::arg("identities")=object(),
vb@254
   473
    "deliverHandshakeResult(self, result, identities=None)\n"
vb@86
   474
    "\n"
vb@86
   475
    "   result          -1: cancel, 0: accepted, 1: rejected\n"
vb@254
   476
    "   identities      list of identities to share or None for all\n"
vb@86
   477
    "\n"
vb@182
   478
    "call to deliver the handshake result of the handshake dialog")
vb@181
   479
    ;
vb@182
   480
vb@83
   481
    // codecs
vb@83
   482
vb@83
   483
    call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search));
vb@182
   484
}
vb@83
   485