From ee8c159657f6a9ca7ff20593f9b71ce770cd113b Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Sat, 18 Apr 2020 02:23:03 +0200 Subject: [PATCH] nice enums --- src/message.cc | 11 +++++++---- src/message.hh | 2 +- src/pEpmodule.cc | 39 +++++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/message.cc b/src/message.cc index 92cbb95..929813b 100644 --- a/src/message.cc +++ b/src/message.cc @@ -313,15 +313,18 @@ namespace pEp { return pEp::PythonAdapter::decrypt_message(*this, flags); } - int Message::outgoing_rating() + PEP_rating Message::outgoing_rating() { if (_msg->dir != PEP_dir_outgoing) throw invalid_argument("Message.dir must be outgoing"); if (from().address() == "") - throw invalid_argument("address needed"); + throw invalid_argument("from.address needed"); if (from().username() == "") - throw invalid_argument("username needed"); + throw invalid_argument("from.username needed"); + + if (len(to()) + len(cc()) == 0) + throw invalid_argument("either to or cc needed"); PEP_STATUS status = myself(adapter.session(), _msg->from); _throw_status(status); @@ -330,7 +333,7 @@ namespace pEp { status = outgoing_message_rating(adapter.session(), *this, &rating); _throw_status(status); - return (int) rating; + return rating; } PEP_color Message::outgoing_color() diff --git a/src/message.hh b/src/message.hh index 56dc67a..85f7242 100644 --- a/src/message.hh +++ b/src/message.hh @@ -132,7 +132,7 @@ namespace pEp { Message _encrypt(boost::python::list extra, int enc_format=4, int flags=0); boost::python::tuple decrypt(int flags=0); - int outgoing_rating(); + PEP_rating outgoing_rating(); PEP_color outgoing_color(); Message deepcopy(dict& memo); Message copy(); diff --git a/src/pEpmodule.cc b/src/pEpmodule.cc index 32b89c1..d79a7ff 100644 --- a/src/pEpmodule.cc +++ b/src/pEpmodule.cc @@ -462,26 +462,25 @@ BOOST_PYTHON_MODULE(pEp) // message API - enum_("PEP_rating") - .value("PEP_rating_undefined", PEP_rating_undefined) - .value("PEP_rating_cannot_decrypt", PEP_rating_cannot_decrypt) - .value("PEP_rating_have_no_key", PEP_rating_have_no_key) - .value("PEP_rating_unencrypted", PEP_rating_unencrypted) - .value("PEP_rating_unencrypted_for_some", PEP_rating_unencrypted_for_some) - .value("PEP_rating_unreliable", PEP_rating_unreliable) - .value("PEP_rating_reliable", PEP_rating_reliable) - .value("PEP_rating_trusted", PEP_rating_trusted) - .value("PEP_rating_trusted_and_anonymized", PEP_rating_trusted_and_anonymized) - .value("PEP_rating_fully_anonymous", PEP_rating_fully_anonymous) - .value("PEP_rating_mistrust", PEP_rating_mistrust) - .value("PEP_rating_b0rken", PEP_rating_b0rken) - .value("PEP_rating_under_attack", PEP_rating_under_attack); - - enum_("PEP_color") - .value("PEP_color_no_color", PEP_color_no_color) - .value("PEP_color_yellow", PEP_color_yellow) - .value("PEP_color_green", PEP_color_green) - .value("PEP_color_red", PEP_color_red); + enum_("rating") + .value("_undefined", PEP_rating_undefined) + .value("cannot_decrypt", PEP_rating_cannot_decrypt) + .value("have_no_key", PEP_rating_have_no_key) + .value("unencrypted", PEP_rating_unencrypted) + .value("unreliable", PEP_rating_unreliable) + .value("reliable", PEP_rating_reliable) + .value("trusted", PEP_rating_trusted) + .value("trusted_and_anonymized", PEP_rating_trusted_and_anonymized) + .value("fully_anonymous", PEP_rating_fully_anonymous) + .value("mistrust", PEP_rating_mistrust) + .value("b0rken", PEP_rating_b0rken) + .value("under_attack", PEP_rating_under_attack); + + enum_("colorvalue") + .value("no_color", PEP_color_no_color) + .value("yellow", PEP_color_yellow) + .value("green", PEP_color_green) + .value("red", PEP_color_red); def("incoming_message", &incoming_message,