diff --git a/python/install_py_bindings.sh b/python/install_py_bindings.sh index 75005b7d0..f9074f7a3 100755 --- a/python/install_py_bindings.sh +++ b/python/install_py_bindings.sh @@ -2,6 +2,8 @@ set -ex -cargo build -p deltachat_ffi +export DCC_RS_TARGET=release + +cargo build -p deltachat_ffi --${DCC_RS_TARGET} rm -rf build/ src/deltachat/*.so DCC_RS_DEV=`pwd`/.. pip install -e . diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 289deafc0..c6ca2d438 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -36,6 +36,7 @@ class Account(object): lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL), _destroy_dc_context, ) + self._threads = IOThreads(self._dc_context) if hasattr(db_path, "encode"): db_path = db_path.encode("utf8") if not lib.dc_open(self._dc_context, db_path, ffi.NULL): @@ -43,7 +44,6 @@ class Account(object): if eventlogging: self._evlogger = EventLogger(self._dc_context, logid) deltachat.set_context_callback(self._dc_context, self._process_event) - self._threads = IOThreads(self._dc_context) self._configkeys = self.get_config("sys.config_keys").split() self._imex_completed = threading.Event() diff --git a/python/tests/test_account.py b/python/tests/test_account.py index b24ebb367..ef101c776 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -1,12 +1,18 @@ from __future__ import print_function import pytest import os -from deltachat import const +from deltachat import const, Account from datetime import datetime, timedelta from conftest import wait_configuration_progress, wait_successful_IMAP_SMTP_connection class TestOfflineAccount: + def test_wrong_db(self, tmpdir): + p = tmpdir.join("hello.db") + p.write("123") + with pytest.raises(ValueError): + Account(p.strpath) + def test_getinfo(self, acfactory): ac1 = acfactory.get_unconfigured_account() d = ac1.get_info() diff --git a/python/tests/test_lowlevel.py b/python/tests/test_lowlevel.py index b8eeb2dd7..94aa471dc 100644 --- a/python/tests/test_lowlevel.py +++ b/python/tests/test_lowlevel.py @@ -2,6 +2,7 @@ from __future__ import print_function import pytest from deltachat import capi, Account, const, set_context_callback, clear_context_callback from deltachat.capi import ffi +from deltachat.capi import lib from deltachat.account import EventLogger @@ -23,17 +24,31 @@ def test_dc_close_events(): evlog.set_timeout(5) set_context_callback(ctx, lambda ctx, evt_name, data1, data2: evlog(evt_name, data1, data2)) capi.lib.dc_close(ctx) - # test that we get events from dc_close - print(evlog.get_matching("DC_EVENT_INFO", check_error=False)) - print(evlog.get_matching("DC_EVENT_INFO", check_error=False)) - print(evlog.get_matching("DC_EVENT_INFO", check_error=False)) - print(evlog.get_matching("DC_EVENT_INFO", check_error=False)) + def find(info_string): + while 1: + ev = evlog.get_matching("DC_EVENT_INFO", check_error=False) + data2 = ev[2] + if info_string in data2: + return + else: + print("skipping info event", data2) + + find("disconnecting INBOX-watch") + find("disconnecting sentbox-thread") + find("disconnecting mvbox-thread") + find("disconnecting SMTP") + find("Database closed") def test_wrong_db(tmpdir): - tmpdir.join("hello.db").write("123") - with pytest.raises(ValueError): - Account(db_path=tmpdir.strpath) + dc_context = ffi.gc( + lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL), + lib.dc_context_unref, + ) + p = tmpdir.join("hello.db") + # write an invalid database file + p.write("x123" * 10) + assert not lib.dc_open(dc_context, p.strpath.encode("ascii"), ffi.NULL) def test_event_defines(): diff --git a/src/dc_configure.rs b/src/dc_configure.rs index 80ce94630..92753974a 100644 --- a/src/dc_configure.rs +++ b/src/dc_configure.rs @@ -1248,15 +1248,20 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: *mut dc_j } } - if imap_connected_here { - // XXX why do we want to disconnect here? - // context.inbox.read().unwrap().disconnect(context); - info!(context, 0, "Skipping INBOX/IMAP disconnect"); - } - if smtp_connected_here { - // XXX why do we want to disconnect here? - // context.smtp.clone().lock().unwrap().disconnect(); - info!(context, 0, "Skipping SMTP disconnect"); + if !success { + // disconnect if configure did not succeed + if imap_connected_here { + // context.inbox.read().unwrap().disconnect(context); + } + if smtp_connected_here { + // context.smtp.clone().lock().unwrap().disconnect(); + } + } else { + assert!(imap_connected_here && smtp_connected_here); + info!( + context, + 0, "Keeping IMAP/SMTP connections open after successful configuration" + ); } dc_loginparam_unref(param); dc_loginparam_unref(param_autoconfig); diff --git a/src/dc_job.rs b/src/dc_job.rs index 3680f0b6f..72a7e5b90 100644 --- a/src/dc_job.rs +++ b/src/dc_job.rs @@ -60,7 +60,6 @@ pub unsafe fn dc_perform_imap_jobs(context: &Context) { } unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: libc::c_int) { - // info!(context, 0, "dc_job_perform {} {}", thread, probe_network); let mut select_stmt: *mut sqlite3_stmt; let mut job = dc_job_t { job_id: 0, @@ -127,7 +126,6 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: let mut tries: libc::c_int = 0i32; while tries <= 1i32 { job.try_again = 0i32; - // info!(context, 0, "dc_job_perform action {}", job.action); match job.action { 5901 => { dc_job_do_DC_JOB_SEND(context, &mut job); diff --git a/src/imap.rs b/src/imap.rs index a473e7993..7b48b8ae7 100644 --- a/src/imap.rs +++ b/src/imap.rs @@ -1060,7 +1060,7 @@ impl Imap { let (sender, receiver) = std::sync::mpsc::channel(); let v = self.watch.clone(); - warn!(context, 0, "IMAP-IDLE SPAWNING"); + info!(context, 0, "IMAP-IDLE SPAWNING"); std::thread::spawn(move || { let &(ref lock, ref cvar) = &*v; if let Some(ref mut session) = &mut *session.lock().unwrap() {