mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
Merge pull request #165 from deltachat/fixtests1
get liveconfig tests working, add imap/smtp connected events and tests
This commit is contained in:
@@ -3,4 +3,5 @@
|
|||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
cargo build -p deltachat_ffi --release
|
cargo build -p deltachat_ffi --release
|
||||||
|
rm -rf build/
|
||||||
DCC_RS_DEV=`pwd`/.. pip install -e .
|
DCC_RS_DEV=`pwd`/.. pip install -e .
|
||||||
|
|||||||
@@ -142,8 +142,10 @@ def wait_successful_IMAP_SMTP_connection(account):
|
|||||||
account._evlogger.get_matching("DC_EVENT_(IMAP|SMTP)_CONNECTED")
|
account._evlogger.get_matching("DC_EVENT_(IMAP|SMTP)_CONNECTED")
|
||||||
if evt_name == "DC_EVENT_IMAP_CONNECTED":
|
if evt_name == "DC_EVENT_IMAP_CONNECTED":
|
||||||
imap_ok = True
|
imap_ok = True
|
||||||
|
print("** IMAP OK", account)
|
||||||
if evt_name == "DC_EVENT_SMTP_CONNECTED":
|
if evt_name == "DC_EVENT_SMTP_CONNECTED":
|
||||||
smtp_ok = True
|
smtp_ok = True
|
||||||
|
print("** SMTP OK", account)
|
||||||
print("** IMAP and SMTP logins successful", account)
|
print("** IMAP and SMTP logins successful", account)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -204,6 +204,43 @@ class TestOfflineAccount:
|
|||||||
|
|
||||||
|
|
||||||
class TestOnlineAccount:
|
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 own account to receive
|
||||||
|
ev = ac1._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
|
assert ev[1] == msg_out.id
|
||||||
|
|
||||||
|
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):
|
def test_forward_messages(self, acfactory):
|
||||||
ac1 = acfactory.get_online_configuring_account()
|
ac1 = acfactory.get_online_configuring_account()
|
||||||
ac2 = acfactory.get_online_configuring_account()
|
ac2 = acfactory.get_online_configuring_account()
|
||||||
|
|||||||
@@ -554,6 +554,13 @@ impl Imap {
|
|||||||
s
|
s
|
||||||
});
|
});
|
||||||
|
|
||||||
|
log_event!(
|
||||||
|
context,
|
||||||
|
Event::IMAP_CONNECTED,
|
||||||
|
0,
|
||||||
|
"IMAP-LOGIN as {} ok",
|
||||||
|
as_str(lp.mail_user),
|
||||||
|
);
|
||||||
info!(context, 0, "IMAP-capabilities:{}", caps_list);
|
info!(context, 0, "IMAP-capabilities:{}", caps_list);
|
||||||
|
|
||||||
let mut config = self.config.write().unwrap();
|
let mut config = self.config.write().unwrap();
|
||||||
|
|||||||
34
src/smtp.rs
34
src/smtp.rs
@@ -6,10 +6,10 @@ use lettre::*;
|
|||||||
use crate::constants::Event;
|
use crate::constants::Event;
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::dc_log::*;
|
|
||||||
use crate::dc_loginparam::*;
|
use crate::dc_loginparam::*;
|
||||||
use crate::dc_tools::*;
|
use crate::dc_tools::*;
|
||||||
use crate::oauth2::*;
|
use crate::oauth2::*;
|
||||||
|
use crate::types::*;
|
||||||
|
|
||||||
pub struct Smtp {
|
pub struct Smtp {
|
||||||
transport: Option<lettre::smtp::SmtpTransport>,
|
transport: Option<lettre::smtp::SmtpTransport>,
|
||||||
@@ -61,14 +61,7 @@ impl Smtp {
|
|||||||
let lp = unsafe { *lp };
|
let lp = unsafe { *lp };
|
||||||
|
|
||||||
if lp.addr.is_null() || lp.send_server.is_null() || lp.send_port == 0 {
|
if lp.addr.is_null() || lp.send_server.is_null() || lp.send_port == 0 {
|
||||||
unsafe {
|
log_event!(context, Event::ERROR_NETWORK, 0, "SMTP bad parameters.",);
|
||||||
dc_log_event(
|
|
||||||
context,
|
|
||||||
Event::ERROR_NETWORK,
|
|
||||||
0,
|
|
||||||
b"SMTP bad parameters.\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let raw_addr = unsafe {
|
let raw_addr = unsafe {
|
||||||
@@ -137,6 +130,13 @@ impl Smtp {
|
|||||||
.credentials(creds)
|
.credentials(creds)
|
||||||
.connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited);
|
.connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited);
|
||||||
self.transport = Some(client.transport());
|
self.transport = Some(client.transport());
|
||||||
|
log_event!(
|
||||||
|
context,
|
||||||
|
Event::SMTP_CONNECTED,
|
||||||
|
0,
|
||||||
|
"SMTP-LOGIN as {} ok",
|
||||||
|
as_str(lp.send_user),
|
||||||
|
);
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -162,21 +162,17 @@ impl Smtp {
|
|||||||
|
|
||||||
match transport.send(mail) {
|
match transport.send(mail) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
unsafe {
|
log_event!(
|
||||||
dc_log_event(
|
context,
|
||||||
context,
|
Event::SMTP_MESSAGE_SENT,
|
||||||
Event::SMTP_MESSAGE_SENT,
|
0,
|
||||||
0,
|
"Message was sent to SMTP server",
|
||||||
b"Message was sent to SMTP server\x00" as *const u8
|
);
|
||||||
as *const libc::c_char,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
self.transport_connected = true;
|
self.transport_connected = true;
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(context, 0, "SMTP failed to send message: {}", err);
|
warn!(context, 0, "SMTP failed to send message: {}", err);
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user