diff --git a/README.md b/README.md index 7d80a411e..af01a779e 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,15 @@ $ cargo test --all $ cargo build -p deltachat_ffi --release ``` +## Debugging environment variables + +- `DCC_IMAP_DEBUG`: if set IMAP protocol commands and responses will be + printed + +- `DCC_MIME_DEBUG`: if set outgoing and incoming message will be printed + + + ### Expensive tests Some tests are expensive and marked with `#[ignore]`, to run these diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 66070548b..7e8cc0364 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -670,6 +670,32 @@ class TestOnlineAccount: ev = ac1._evlogger.get_matching("DC_EVENT_SMTP_MESSAGE_SENT") assert not msg.is_encrypted() + def test_send_first_message_as_long_unicode_with_cr(self, acfactory, lp): + ac1, ac2 = acfactory.get_two_online_accounts() + ac2.set_config("save_mime_headers", "1") + + lp.sec("ac1: create chat with ac2") + chat = self.get_chat(ac1, ac2, both_created=True) + + lp.sec("sending multi-line non-unicode message from ac1 to ac2") + text1 = "hello\nworld" + msg_out = chat.send_text(text1) + assert not msg_out.is_encrypted() + + lp.sec("sending multi-line unicode text message from ac1 to ac2") + text2 = "äalis\nthis is ßßÄ" + msg_out = chat.send_text(text2) + assert not msg_out.is_encrypted() + + lp.sec("wait for ac2 to receive multi-line non-unicode message") + msg_in = ac2.wait_next_incoming_message() + assert msg_in.text == text1 + + lp.sec("wait for ac2 to receive multi-line unicode message") + msg_in = ac2.wait_next_incoming_message() + assert msg_in.text == text2 + assert ac1.get_config("addr") in msg_in.chat.get_name() + def test_reply_encrypted(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 9b976af37..65738870f 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -47,6 +47,11 @@ pub fn dc_receive_imf( server_uid, ); + if std::env::var(crate::DCC_MIME_DEBUG).is_ok() { + info!(context, "dc_receive_imf: incoming message mime-body:"); + println!("{}", String::from_utf8_lossy(imf_raw)); + } + let mime_parser = MimeParser::from_bytes(context, imf_raw); let mut mime_parser = if let Err(err) = mime_parser { warn!(context, "dc_receive_imf parse error: {}", err); diff --git a/src/dc_strencode.rs b/src/dc_strencode.rs index 787c5b41c..d321863a7 100644 --- a/src/dc_strencode.rs +++ b/src/dc_strencode.rs @@ -23,7 +23,8 @@ pub fn dc_encode_header_words(input: impl AsRef) -> String { } fn must_encode(byte: u8) -> bool { - static SPECIALS: &[u8] = b",:!\"#$@[\\]^`{|}~=?_"; + // XXX do we need to put ":" in here? + static SPECIALS: &[u8] = b",!\"#$@[\\]^`{|}~=?_"; SPECIALS.iter().any(|b| *b == byte) } diff --git a/src/imap_client.rs b/src/imap_client.rs index df4340660..b25d12dc0 100644 --- a/src/imap_client.rs +++ b/src/imap_client.rs @@ -11,8 +11,6 @@ use async_tls::client::TlsStream; use crate::login_param::{dc_build_tls_config, CertificateChecks}; -const DCC_IMAP_DEBUG: &str = "DCC_IMAP_DEBUG"; - #[derive(Debug)] pub(crate) enum Client { Secure(ImapClient>), @@ -42,7 +40,7 @@ impl Client { let tls_connector: async_tls::TlsConnector = Arc::new(tls_config).into(); let tls_stream = tls_connector.connect(domain.as_ref(), stream)?.await?; let mut client = ImapClient::new(tls_stream); - if std::env::var(DCC_IMAP_DEBUG).is_ok() { + if std::env::var(crate::DCC_IMAP_DEBUG).is_ok() { client.debug = true; } @@ -58,7 +56,7 @@ impl Client { let stream = TcpStream::connect(addr).await?; let mut client = ImapClient::new(stream); - if std::env::var(DCC_IMAP_DEBUG).is_ok() { + if std::env::var(crate::DCC_IMAP_DEBUG).is_ok() { client.debug = true; } let _greeting = client diff --git a/src/job.rs b/src/job.rs index 46a4afa5f..9b880b94e 100644 --- a/src/job.rs +++ b/src/job.rs @@ -192,6 +192,10 @@ impl Job { // was sent we need to mark it in the database ASAP as we // otherwise might send it twice. let mut smtp = context.smtp.lock().unwrap(); + if std::env::var(crate::DCC_MIME_DEBUG).is_ok() { + info!(context, "smtp-sending out mime message:"); + println!("{}", String::from_utf8_lossy(&body)); + } match smtp.send(context, recipients_list, body, self.job_id) { Err(crate::smtp::send::Error::SendError(err)) => { // Remote error, retry later. diff --git a/src/lib.rs b/src/lib.rs index fc8c59c78..f595d6b3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,5 +78,11 @@ mod dc_simplify; mod dc_strencode; pub mod dc_tools; +/// if set imap/incoming and smtp/outgoing MIME messages will be printed +pub const DCC_MIME_DEBUG: &str = "DCC_MIME_DEBUG"; + +/// if set IMAP protocol commands and responses will be printed +pub const DCC_IMAP_DEBUG: &str = "DCC_IMAP_DEBUG"; + #[cfg(test)] mod test_utils; diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 9d6a82b73..594596d38 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -333,13 +333,19 @@ impl<'a, 'b> MimeFactory<'a, 'b> { Loaded::Message => { match self.chat { Some(ref chat) => { - let raw_subject = message::get_summarytext_by_raw( + let raw = message::get_summarytext_by_raw( self.msg.type_0, self.msg.text.as_ref(), &self.msg.param, 32, self.context, ); + let mut lines = raw.lines(); + let raw_subject = if let Some(line) = lines.next() { + line + } else { + "" + }; let afwd_email = self.msg.param.exists(Param::Forwarded); let fwd = if afwd_email { "Fwd: " } else { "" };