From 630754b52efe0d97b35c5633a051f57456db3b0b Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 2 Jan 2022 00:20:44 +0000 Subject: [PATCH] dc_receive_imf: don't fail on invalid address in the To field This is an irrecoverable error, dc_receive_imf must not fail on it as it prevents last seen UID from advancing, so the same message is prefetched on each iteration of IMAP loop. --- src/dc_receive_imf.rs | 25 +++++++++++++++++++++---- test-data/message/invalid_email_to.eml | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 test-data/message/invalid_email_to.eml diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 2dd97702c..e24b85ba9 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -17,7 +17,9 @@ use crate::constants::{ Blocked, Chattype, ShowEmails, Viewtype, DC_CHAT_ID_TRASH, DC_CONTACT_ID_LAST_SPECIAL, DC_CONTACT_ID_SELF, }; -use crate::contact::{addr_cmp, normalize_name, Contact, Origin, VerifiedStatus}; +use crate::contact::{ + addr_cmp, may_be_valid_addr, normalize_name, Contact, Origin, VerifiedStatus, +}; use crate::context::Context; use crate::dc_tools::{dc_extract_grpid_from_rfc724_mid, dc_smeared_time}; use crate::download::DownloadState; @@ -2284,14 +2286,17 @@ async fn dc_add_or_lookup_contacts_by_address_list( ) -> Result> { let mut contact_ids = BTreeSet::new(); for info in address_list.iter() { + let addr = &info.addr; + if !may_be_valid_addr(addr) { + continue; + } let display_name = if prevent_rename { Some("") } else { info.display_name.as_deref() }; - contact_ids.insert( - add_or_lookup_contact_by_addr(context, display_name, &info.addr, origin).await?, - ); + contact_ids + .insert(add_or_lookup_contact_by_addr(context, display_name, addr, origin).await?); } Ok(contact_ids.into_iter().collect::>()) @@ -4989,4 +4994,16 @@ Message with references."#; Ok(()) } + + #[async_std::test] + async fn test_invalid_to_address() -> Result<()> { + let alice = TestContext::new_alice().await; + + let mime = include_bytes!("../test-data/message/invalid_email_to.eml"); + + // dc_receive_imf should not fail on this mail with invalid To: field + dc_receive_imf(&alice, mime, "Inbox", false).await?; + + Ok(()) + } } diff --git a/test-data/message/invalid_email_to.eml b/test-data/message/invalid_email_to.eml new file mode 100644 index 000000000..b5a87050e --- /dev/null +++ b/test-data/message/invalid_email_to.eml @@ -0,0 +1,15 @@ +Subject: Some subject +Date: Sat, 01 Jan 2022 21:14:26 +0000 +Chat-Version: 1.0 +MIME-Version: 1.0 +Message-ID: +To: , , + +From: Claire +Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no +X-Spam: Yes + +Some message.