diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 5c0f979bc..bbf512bcf 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -2382,6 +2382,7 @@ mod tests { .await; } + // ndn = Non Delivery Notification async fn test_parse_ndn( self_addr: &str, foreign_addr: &str, @@ -2415,6 +2416,14 @@ mod tests { let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let msg_id = chats.get_msg_id(0).unwrap(); + // Check that the ndn would be downloaded: + let headers = mailparse::parse_mail(raw_ndn).unwrap().headers; + assert!( + crate::imap::prefetch_should_download(&t.ctx, &headers, ShowEmails::Off) + .await + .unwrap() + ); + dc_receive_imf(&t.ctx, raw_ndn, "INBOX", 1, false) .await .unwrap(); diff --git a/src/headerdef.rs b/src/headerdef.rs index 10beaf4c8..36d763b8d 100644 --- a/src/headerdef.rs +++ b/src/headerdef.rs @@ -21,6 +21,7 @@ pub enum HeaderDef { References, InReplyTo, Precedence, + ContentType, ChatVersion, ChatGroupId, ChatGroupName, diff --git a/src/imap/mod.rs b/src/imap/mod.rs index fb3eecda8..c2b4f05b7 100644 --- a/src/imap/mod.rs +++ b/src/imap/mod.rs @@ -1449,7 +1449,7 @@ async fn prefetch_is_reply_to_chat_message( false } -async fn prefetch_should_download( +pub(crate) async fn prefetch_should_download( context: &Context, headers: &[mailparse::MailHeader<'_>], show_emails: ShowEmails, @@ -1457,6 +1457,16 @@ async fn prefetch_should_download( let is_chat_message = headers.get_header_value(HeaderDef::ChatVersion).is_some(); let is_reply_to_chat_message = prefetch_is_reply_to_chat_message(context, &headers).await; + let maybe_ndn = if let Some(subject) = headers.get_header_value(HeaderDef::Subject) { + subject.to_ascii_lowercase().contains("fail") + } else { + false + } || if let Some(ctype) = headers.get_header_value(HeaderDef::ContentType) { + ctype.starts_with("multipart/report") + } else { + false + }; + // Autocrypt Setup Message should be shown even if it is from non-chat client. let is_autocrypt_setup_message = headers .get_header_value(HeaderDef::AutocryptSetupMessage) @@ -1467,6 +1477,7 @@ async fn prefetch_should_download( let accepted_contact = origin.is_known(); let show = is_autocrypt_setup_message + || maybe_ndn || match show_emails { ShowEmails::Off => is_chat_message || is_reply_to_chat_message, ShowEmails::AcceptedContacts => { diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 6be66de6b..79c313044 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -900,7 +900,9 @@ impl MimeMessage { Ok(None) } - /// Some providers like GMX and Yahoo do not send standard NDNs (Non Delivery notifications) + /// Some providers like GMX and Yahoo do not send standard NDNs (Non Delivery notifications). + /// If you improve heuristics here you might also have to change prefetch_should_download() in imap/mod.rs. + /// Also you should add a test in dc_receive_imf.rs (there already are lots of test_parse_ndn_* tests). async fn heuristically_parse_ndn(&mut self, context: &Context) -> Option<()> { if self .get(HeaderDef::Subject)?