diff --git a/src/mimeparser.rs b/src/mimeparser.rs index db5ec6556..93ac53651 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -2240,12 +2240,22 @@ async fn handle_ndn( } else { "Delivery to at least one recipient failed.".to_string() }; + let err_msg = &error; let mut first = true; for msg in msgs { let (msg_id, chat_id, chat_type) = msg?; let mut message = Message::load_from_db(context, msg_id).await?; - set_msg_failed(context, &mut message, &error).await?; + let aggregated_error = message + .error + .as_ref() + .map(|err| format!("{}\n\n{}", err, err_msg)); + set_msg_failed( + context, + &mut message, + aggregated_error.as_ref().unwrap_or(err_msg), + ) + .await?; if first { // Add only one info msg for all failed messages ndn_maybe_add_info_msg(context, failed, chat_id, chat_type).await?; diff --git a/src/receive_imf/tests.rs b/src/receive_imf/tests.rs index 4868a69e8..b9dd661cf 100644 --- a/src/receive_imf/tests.rs +++ b/src/receive_imf/tests.rs @@ -883,6 +883,54 @@ async fn test_parse_ndn_group_msg() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_concat_multiple_ndns() -> Result<()> { + let t = TestContext::new().await; + t.configure_addr("alice@posteo.org").await; + let mid = "1234@mail.gmail.com"; + receive_imf( + &t, + b"Received: (Postfix, from userid 1000); Mon, 4 Dec 2006 14:51:39 +0100 (CET)\n\ + From: alice@posteo.org\n\ + To: hanerthaertidiuea@gmx.de\n\ + Subject: foo\n\ + Message-ID: <1234@mail.gmail.com>\n\ + Chat-Version: 1.0\n\ + Chat-Disposition-Notification-To: alice@example.org\n\ + Date: Sun, 22 Mar 2020 22:37:57 +0000\n\ + \n\ + hello\n", + false, + ) + .await?; + + let chats = Chatlist::try_load(&t, 0, None, None).await?; + let msg_id = chats.get_msg_id(0)?.unwrap(); + + let raw = include_str!("../../test-data/message/posteo_ndn.eml"); + let raw = raw.replace( + "Message-ID: <04422840-f884-3e37-5778-8192fe22d8e1@posteo.de>", + &format!("Message-ID: <{}>", mid), + ); + receive_imf(&t, raw.as_bytes(), false).await?; + + let msg = Message::load_from_db(&t, msg_id).await?; + + let err = "Undelivered Mail Returned to Sender – This is the mail system at host mout01.posteo.de.\n\nI'm sorry to have to inform you that your message could not\nbe delivered to one or more recipients. It's attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can\ndelete your own text from the attached returned message.\n\n The mail system\n\n: host mx01.emig.gmx.net[212.227.17.5] said: 550\n Requested action not taken: mailbox unavailable (in reply to RCPT TO\n command)".to_string(); + assert_eq!(msg.error(), Some(err.clone())); + assert_eq!(msg.state, MessageState::OutFailed); + + let raw = raw.replace( + "Message-Id: <20200609184422.DCB6B1200DD@mout01.posteo.de>", + "Message-Id: ", + ); + receive_imf(&t, raw.as_bytes(), false).await?; + let msg = Message::load_from_db(&t, msg_id).await?; + + assert_eq!(msg.error(), Some([err.clone(), err].join("\n\n"))); + Ok(()) +} + async fn load_imf_email(context: &Context, imf_raw: &[u8]) -> Message { context .set_config(Config::ShowEmails, Some("2"))