From ccc4f57d97a80c165389aeb36aab76dbbaf73f11 Mon Sep 17 00:00:00 2001 From: Gernot Date: Fri, 20 Jan 2023 13:49:19 +0100 Subject: [PATCH] sketch out exceptions that need to be caught or raised --- src/pEpTransportMail.cc | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/pEpTransportMail.cc b/src/pEpTransportMail.cc index b931f67..97a1f35 100644 --- a/src/pEpTransportMail.cc +++ b/src/pEpTransportMail.cc @@ -47,8 +47,10 @@ namespace pEp { pEpLogClass("called"); if (allCallbacksRegistered()) { if (ConfigMail *cfg = dynamic_cast(const_cast(&config))) { + // or should I just save cfg? login_imap = cfg->login_recv; login_smtp = cfg->login_send; + own_ident = cfg->ident; } else { throw ConfigError("configure(): object has to be of type ConfigMail"); } @@ -80,10 +82,20 @@ namespace pEp { // and then populate rx_queue via conn_imap.select() try { conn_imap = new mailio::imaps(login_imap.server, login_imap.port); - } catch (mailio::imap_error e) { - pEpLogClass(e.what()); + } catch (mailio::dialog_error e) { + pEpLogClass("dialog error: " + std::string(e.what())); + // TODO: // set tsc and PEP_STATUS + // Possible values: + // PEP_tsc_cannot_reach_imap_server = 0x01802001 + // PEP_tsc_network_timeout = 0x0080000a, + // PEP_tsc_no_recv_config = 0x00800007, + // PEP_tsc_recv_config_incomplete_or_wrong = 0x00800009, + // return. If IMAP connection failed, this transport can and must not be used. } + // Does auth get its own error handling or do I put it into the previous try block? + // may fail with imap_error, + // PEP_tsc_recv_config_incomplete_or_wrong = 0x00800009, conn_imap->authenticate(login_imap.username, login_imap.passphrase, login_imap.auth_method); if (!protocol_thread.joinable()) { protocol_thread_stop.store(false); @@ -127,7 +139,14 @@ namespace pEp { mailio_message mmsg(msg); ::PEP_transport_status_code pep_tsc = PEP_tsc_message_on_the_way; + // creating conn may fail. -> seperate variable definition and connection, meaning we need conn to be a pointer of some sort and call new inside a try block. + // Possible tsc values: + // PEP_tsc_cannot_reach_smtp_server + // PEP_tsc_network_timeout + // PEP_tsc_no_send_config + // PEP_tsc_send_config_incomplete_or_wrong mailio::smtps conn(login_smtp.server, login_smtp.port); + // That would make this check obsolete (and it doesn't work as intended anyways) if (conn.source_hostname().empty()) { pEpLogClass("SMTP no connection"); } else { @@ -140,6 +159,8 @@ namespace pEp { // Other possible values: // PEP_tsc_network_timeout = 0x0080000a, // PEP_tsc_unknown_smtp_error = 0x01801fff, + // PEP_tsc_no_send_config + // PEP_tsc_send_config_incomplete_or_wrong } try { std::string answer = conn.submit(mmsg); // TODO: log the result @@ -148,6 +169,7 @@ namespace pEp { pEpLogClass(e.what()); pep_tsc = PEP_tsc_could_not_deliver_giving_up; // Possible values depending on the error code: + // If we get a good enough error code, that is. Another point to question the use of mailio. // PEP_tsc_some_recipients_unreachable = 0x00800002, // PEP_tsc_no_recipients_reachable = 0x00800003, // PEP_tsc_network_timeout = 0x0080000a, @@ -158,7 +180,9 @@ namespace pEp { // if nothing failed, pep_tsc is still PEP_tsc_message_on_the_way cb_sendto_result(get_id(), msg->id, pep_tsc); try { - conn_imap->append("sent", mmsg); + conn_imap->append("Sent", mmsg); + // This usually fails in the test, I don't know why. + // And I'm not even sure if it's a) needed or b) even asked for? } catch (mailio::imap_error e) { pEpLogClass(e.what()); } @@ -182,6 +206,10 @@ namespace pEp { mailio::codec::line_len_policy_t::MANDATORY); // get that mail from mailio + // this might fail. + // Possible tsc values: + // PEP_tsc_cannot_reach_imap_server = 0x01802001, + // PEP_tsc_unknown_imap_error = 0x01802fff, conn_imap->fetch("inbox", message_id, mmsg, false); // Convert the mailio message struct into a pEp message struct using our conversion operator. @@ -205,7 +233,7 @@ namespace pEp { std::string pEpTransportMail::own_address() { throwInvalidState(); - return "alice@pep.foundation"; + return std::string(own_ident->address); } bool pEpTransportMail::shortmsg_supported()