From d1593f0258414708cce73412ddd3c1eac1ccd2aa Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 1 Jul 2019 15:57:00 +0200 Subject: [PATCH 1/8] fix run-integration-test.sh to run without arguments --- run-integration-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run-integration-tests.sh b/run-integration-tests.sh index 579a7b662..12633addc 100755 --- a/run-integration-tests.sh +++ b/run-integration-tests.sh @@ -25,9 +25,9 @@ fi pushd python toxargs="$@" if [ -e liveconfig ]; then - toxargs="--liveconfig liveconfig $@" + toxargs="--liveconfig liveconfig tests/ $@" fi -tox $toxargs +tox -- $toxargs ret=$? popd exit $ret From 06e16c81f93b1c7aff865e82965d229c6953bef3 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 1 Jul 2019 18:06:16 +0200 Subject: [PATCH 2/8] Wip --- python/tests/test_account.py | 19 +++++++++++++++++++ run-integration-tests.sh | 2 +- src/smtp.rs | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index dc2e1c9ca..d1f97b918 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -204,6 +204,25 @@ class TestOfflineAccount: class TestOnlineAccount: + def test_one_account_init(self, acfactory): + ac1 = acfactory.get_online_configuring_account() + wait_successful_IMAP_SMTP_connection(ac1) + wait_configuration_progress(ac1, 1000) + + def test_one_account_send(self, acfactory): + ac1 = acfactory.get_online_configuring_account() + c2 = ac1.create_contact(email=ac1.get_config("addr")) + chat = ac1.create_chat_by_contact(c2) + assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL + #wait_successful_IMAP_SMTP_connection(ac1) + wait_configuration_progress(ac1, 1000) + + msg_out = chat.send_text("message2") + # wait for other account to receive + ev = ac1._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED") + assert ev[1] == msg_out.id + assert 0 + def test_forward_messages(self, acfactory): ac1 = acfactory.get_online_configuring_account() ac2 = acfactory.get_online_configuring_account() diff --git a/run-integration-tests.sh b/run-integration-tests.sh index 12633addc..00cbaaaff 100755 --- a/run-integration-tests.sh +++ b/run-integration-tests.sh @@ -25,7 +25,7 @@ fi pushd python toxargs="$@" if [ -e liveconfig ]; then - toxargs="--liveconfig liveconfig tests/ $@" + toxargs="--liveconfig liveconfig $@" fi tox -- $toxargs ret=$? diff --git a/src/smtp.rs b/src/smtp.rs index 85f172d90..901c9f90f 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -48,6 +48,16 @@ impl Smtp { /// Connect using the provided login params pub fn connect(&mut self, context: &Context, lp: *const dc_loginparam_t) -> usize { + warn!(context, 0, "SMTP ***************** CONNECT"); + unsafe { + dc_log_event( + context, + Event::INFO, + 0, + b"SMTP ***************************************************** connect starts" as *const u8 as *const libc::c_char, + ); + } + if lp.is_null() { return 0; } @@ -137,6 +147,15 @@ impl Smtp { .credentials(creds) .connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited); self.transport = Some(client.transport()); + unsafe { + dc_log_event( + context, + Event::SMTP_CONNECTED, + 0, + b"SMTP-LOGIN ok" as *const u8 + as *const libc::c_char, + ); + } 1 } Err(err) => { From 384822b5eb6af9861caf2ad67125c0ad4b12070f Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 1 Jul 2019 18:57:37 +0200 Subject: [PATCH 3/8] replace unsafe use of dc logging with info! macro as per advise from @flub --- python/tests/test_account.py | 19 +++++++++++++++++++ src/smtp.rs | 11 ++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index d1f97b918..e2429b2ee 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -223,6 +223,25 @@ class TestOnlineAccount: assert ev[1] == msg_out.id assert 0 + def test_two_acocunts_send_receive(self, acfactory): + ac1 = acfactory.get_online_configuring_account() + ac2 = acfactory.get_online_configuring_account() + c2 = ac1.create_contact(email=ac2.get_config("addr")) + chat = ac1.create_chat_by_contact(c2) + assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL + #wait_successful_IMAP_SMTP_connection(ac1) + wait_configuration_progress(ac1, 1000) + #wait_successful_IMAP_SMTP_connection(ac2) + wait_configuration_progress(ac2, 1000) + + msg_out = chat.send_text("message1") + + # wait for other account to receive + ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED") + assert ev[2] == msg_out.id + msg_in = ac2.get_message_by_id(msg_out.id) + assert msg_in.text == "message1" + def test_forward_messages(self, acfactory): ac1 = acfactory.get_online_configuring_account() ac2 = acfactory.get_online_configuring_account() diff --git a/src/smtp.rs b/src/smtp.rs index 901c9f90f..fb15da8b8 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -10,6 +10,7 @@ use crate::dc_log::*; use crate::dc_loginparam::*; use crate::dc_tools::*; use crate::oauth2::*; +use crate::types::*; pub struct Smtp { transport: Option, @@ -48,15 +49,7 @@ impl Smtp { /// Connect using the provided login params pub fn connect(&mut self, context: &Context, lp: *const dc_loginparam_t) -> usize { - warn!(context, 0, "SMTP ***************** CONNECT"); - unsafe { - dc_log_event( - context, - Event::INFO, - 0, - b"SMTP ***************************************************** connect starts" as *const u8 as *const libc::c_char, - ); - } + info!(context, 0, "SMTP ***************** CONNECT"); if lp.is_null() { return 0; From 183a49eca0dbd4cd45ae61774ef0b69a88dfb3f4 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 1 Jul 2019 20:11:35 +0200 Subject: [PATCH 4/8] remove superflous debug attempts --- python/install_py_bindings.sh | 1 + python/tests/conftest.py | 2 ++ src/dc_configure.rs | 1 - src/smtp.rs | 2 -- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/install_py_bindings.sh b/python/install_py_bindings.sh index c145036fe..1b5c71cf6 100755 --- a/python/install_py_bindings.sh +++ b/python/install_py_bindings.sh @@ -3,4 +3,5 @@ set -ex cargo build -p deltachat_ffi --release +rm -rf build/ DCC_RS_DEV=`pwd`/.. pip install -e . diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 4189b02a5..ff1d4425c 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -142,8 +142,10 @@ def wait_successful_IMAP_SMTP_connection(account): account._evlogger.get_matching("DC_EVENT_(IMAP|SMTP)_CONNECTED") if evt_name == "DC_EVENT_IMAP_CONNECTED": imap_ok = True + print("** IMAP OK", account) if evt_name == "DC_EVENT_SMTP_CONNECTED": smtp_ok = True + print("** SMTP OK", account) print("** IMAP and SMTP logins successful", account) diff --git a/src/dc_configure.rs b/src/dc_configure.rs index 1ec517cde..e93a33b3c 100644 --- a/src/dc_configure.rs +++ b/src/dc_configure.rs @@ -10,7 +10,6 @@ use crate::dc_strencode::*; use crate::dc_tools::*; use crate::imap::*; use crate::oauth2::*; -use crate::types::*; use crate::x::*; /* ****************************************************************************** diff --git a/src/smtp.rs b/src/smtp.rs index fb15da8b8..cc34fd34e 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -49,8 +49,6 @@ impl Smtp { /// Connect using the provided login params pub fn connect(&mut self, context: &Context, lp: *const dc_loginparam_t) -> usize { - info!(context, 0, "SMTP ***************** CONNECT"); - if lp.is_null() { return 0; } From 7a053b9f9363edcf0a136184540c5799e2f311e8 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 1 Jul 2019 22:27:44 +0200 Subject: [PATCH 5/8] add SMTP_CONNECTED and IMAP_CONNECTED events --- run-integration-tests.sh | 2 +- src/dc_configure.rs | 1 + src/imap.rs | 3 +++ src/smtp.rs | 12 +++--------- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/run-integration-tests.sh b/run-integration-tests.sh index 00cbaaaff..579a7b662 100755 --- a/run-integration-tests.sh +++ b/run-integration-tests.sh @@ -27,7 +27,7 @@ toxargs="$@" if [ -e liveconfig ]; then toxargs="--liveconfig liveconfig $@" fi -tox -- $toxargs +tox $toxargs ret=$? popd exit $ret diff --git a/src/dc_configure.rs b/src/dc_configure.rs index e93a33b3c..1ec517cde 100644 --- a/src/dc_configure.rs +++ b/src/dc_configure.rs @@ -10,6 +10,7 @@ use crate::dc_strencode::*; use crate::dc_tools::*; use crate::imap::*; use crate::oauth2::*; +use crate::types::*; use crate::x::*; /* ****************************************************************************** diff --git a/src/imap.rs b/src/imap.rs index 43696b2ee..31c22fb14 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -554,6 +554,9 @@ impl Imap { s }); + log_event!(context, Event::IMAP_CONNECTED, + 0, "IMAP-LOGIN as {} ok", as_str(lp.mail_user), + ); info!(context, 0, "IMAP-capabilities:{}", caps_list); let mut config = self.config.write().unwrap(); diff --git a/src/smtp.rs b/src/smtp.rs index cc34fd34e..0e2a4ac70 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -138,15 +138,9 @@ impl Smtp { .credentials(creds) .connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited); self.transport = Some(client.transport()); - unsafe { - dc_log_event( - context, - Event::SMTP_CONNECTED, - 0, - b"SMTP-LOGIN ok" as *const u8 - as *const libc::c_char, - ); - } + log_event!(context, Event::SMTP_CONNECTED, + 0, "SMTP-LOGIN as {} ok", as_str(lp.send_user), + ); 1 } Err(err) => { From 2c26f4f2abb3a7afe7e53cefa4fc226ec5e8c503 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 1 Jul 2019 22:56:47 +0200 Subject: [PATCH 6/8] convert the last two unsafe event emissions in smtp.rs --- python/tests/test_account.py | 3 +-- src/smtp.rs | 27 ++++++++------------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index e2429b2ee..50e88c38c 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -214,14 +214,13 @@ class TestOnlineAccount: c2 = ac1.create_contact(email=ac1.get_config("addr")) chat = ac1.create_chat_by_contact(c2) assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL - #wait_successful_IMAP_SMTP_connection(ac1) + wait_successful_IMAP_SMTP_connection(ac1) wait_configuration_progress(ac1, 1000) msg_out = chat.send_text("message2") # wait for other account to receive ev = ac1._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED") assert ev[1] == msg_out.id - assert 0 def test_two_acocunts_send_receive(self, acfactory): ac1 = acfactory.get_online_configuring_account() diff --git a/src/smtp.rs b/src/smtp.rs index 0e2a4ac70..db039c801 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -6,7 +6,6 @@ use lettre::*; use crate::constants::Event; use crate::constants::*; use crate::context::Context; -use crate::dc_log::*; use crate::dc_loginparam::*; use crate::dc_tools::*; use crate::oauth2::*; @@ -62,14 +61,10 @@ impl Smtp { let lp = unsafe { *lp }; if lp.addr.is_null() || lp.send_server.is_null() || lp.send_port == 0 { - unsafe { - dc_log_event( - context, - Event::ERROR_NETWORK, - 0, - b"SMTP bad parameters.\x00" as *const u8 as *const libc::c_char, - ); - } + log_event!( + context, Event::ERROR_NETWORK, 0, + "SMTP bad parameters.", + ); } let raw_addr = unsafe { @@ -166,21 +161,15 @@ impl Smtp { match transport.send(mail) { Ok(_) => { - unsafe { - dc_log_event( - context, - Event::SMTP_MESSAGE_SENT, - 0, - b"Message was sent to SMTP server\x00" as *const u8 - as *const libc::c_char, - ); - } + log_event!( + context, Event::SMTP_MESSAGE_SENT, 0, + "Message was sent to SMTP server", + ); self.transport_connected = true; 1 } Err(err) => { warn!(context, 0, "SMTP failed to send message: {}", err); - 0 } } From 08bade2c7c230d4710b4049bd3763af87ce8582c Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 2 Jul 2019 08:36:15 +0200 Subject: [PATCH 7/8] fix fmt --- src/imap.rs | 8 ++++++-- src/smtp.rs | 17 ++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/imap.rs b/src/imap.rs index 31c22fb14..0e436d985 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -554,8 +554,12 @@ impl Imap { s }); - log_event!(context, Event::IMAP_CONNECTED, - 0, "IMAP-LOGIN as {} ok", as_str(lp.mail_user), + log_event!( + context, + Event::IMAP_CONNECTED, + 0, + "IMAP-LOGIN as {} ok", + as_str(lp.mail_user), ); info!(context, 0, "IMAP-capabilities:{}", caps_list); diff --git a/src/smtp.rs b/src/smtp.rs index db039c801..1c8bc235e 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -61,10 +61,7 @@ impl Smtp { let lp = unsafe { *lp }; if lp.addr.is_null() || lp.send_server.is_null() || lp.send_port == 0 { - log_event!( - context, Event::ERROR_NETWORK, 0, - "SMTP bad parameters.", - ); + log_event!(context, Event::ERROR_NETWORK, 0, "SMTP bad parameters.",); } let raw_addr = unsafe { @@ -133,8 +130,12 @@ impl Smtp { .credentials(creds) .connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited); self.transport = Some(client.transport()); - log_event!(context, Event::SMTP_CONNECTED, - 0, "SMTP-LOGIN as {} ok", as_str(lp.send_user), + log_event!( + context, + Event::SMTP_CONNECTED, + 0, + "SMTP-LOGIN as {} ok", + as_str(lp.send_user), ); 1 } @@ -162,7 +163,9 @@ impl Smtp { match transport.send(mail) { Ok(_) => { log_event!( - context, Event::SMTP_MESSAGE_SENT, 0, + context, + Event::SMTP_MESSAGE_SENT, + 0, "Message was sent to SMTP server", ); self.transport_connected = true; From e597aade1051fe22ed7ccbb56e64761820577aad Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 2 Jul 2019 10:05:54 +0200 Subject: [PATCH 8/8] fix comment --- python/tests/test_account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 50e88c38c..c9249675c 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -218,7 +218,7 @@ class TestOnlineAccount: wait_configuration_progress(ac1, 1000) msg_out = chat.send_text("message2") - # wait for other account to receive + # wait for own account to receive ev = ac1._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED") assert ev[1] == msg_out.id