From 1adea3c6788dbe16c8661085d3928a7649583492 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 24 Mar 2024 23:08:09 +0000 Subject: [PATCH] fix: put overridden sender name into message info --- src/message.rs | 14 ++++++++------ src/receive_imf.rs | 3 +++ src/receive_imf/tests.rs | 19 +++++++++++++++++++ test-data/message/list-from.eml | 28 ++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 test-data/message/list-from.eml diff --git a/src/message.rs b/src/message.rs index 550864f53..912cef51a 100644 --- a/src/message.rs +++ b/src/message.rs @@ -201,12 +201,14 @@ WHERE id=?; let fts = timestamp_to_str(msg.get_timestamp()); ret += &format!("Sent: {fts}"); - let name = Contact::get_by_id(context, msg.from_id) - .await - .map(|contact| contact.get_name_n_addr()) - .unwrap_or_default(); - - ret += &format!(" by {name}"); + let from_contact = Contact::get_by_id(context, msg.from_id).await?; + let name = from_contact.get_name_n_addr(); + if let Some(override_sender_name) = msg.get_override_sender_name() { + let addr = from_contact.get_addr(); + ret += &format!(" by ~{override_sender_name} ({addr})"); + } else { + ret += &format!(" by {name}"); + } ret += "\n"; if msg.from_id != ContactId::SELF { diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 752f3e3d6..53497276e 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -316,6 +316,9 @@ pub(crate) async fn receive_imf_inner( // // If this is a mailing list email (i.e. list_id_header is some), don't change the displayname because in // a mailing list the sender displayname sometimes does not belong to the sender email address. + // For example, GitHub sends messages from `notifications@github.com`, + // but uses display name of the user whose action generated the notification + // as the display name. let (from_id, _from_id_blocked, incoming_origin) = match from_field_to_contact_id(context, &mime_parser.from, prevent_rename).await? { Some(contact_id_res) => contact_id_res, diff --git a/src/receive_imf/tests.rs b/src/receive_imf/tests.rs index 525a553be..d4f19f71b 100644 --- a/src/receive_imf/tests.rs +++ b/src/receive_imf/tests.rs @@ -4393,3 +4393,22 @@ async fn test_references() -> Result<()> { Ok(()) } + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_list_from() -> Result<()> { + let t = &TestContext::new_alice().await; + + let raw = include_bytes!("../../test-data/message/list-from.eml"); + let received = receive_imf(t, raw, false).await?.unwrap(); + let msg = Message::load_from_db(t, *received.msg_ids.last().unwrap()).await?; + assert_eq!(msg.get_override_sender_name().unwrap(), "ÖAMTC"); + let sender_contact = Contact::get_by_id(t, msg.from_id).await?; + assert_eq!( + sender_contact.get_display_name(), + "clubinfo@donotreply.oeamtc.at" + ); + let info = msg.id.get_info(t).await?; + assert!(info.contains("Sent: 2024.03.20 09:00:01 by ~ÖAMTC (clubinfo@donotreply.oeamtc.at)")); + + Ok(()) +} diff --git a/test-data/message/list-from.eml b/test-data/message/list-from.eml new file mode 100644 index 000000000..01840f17d --- /dev/null +++ b/test-data/message/list-from.eml @@ -0,0 +1,28 @@ +Return-Path: +Delivered-To: alice@example.org +To: alice@example.org +Subject: Vorteile sind zum Teilen da! +X-Mailer: class SMTPMail +From: "=?ISO-8859-1?Q?=D6AMTC?=" +MIME-Version: 1.0 +List-Id: 134722648 <=?ISO-8859-1?Q?=D6AMTC?=> +List-Unsubscribe: , +List-Unsubscribe-Post: List-Unsubscribe=One-Click +Content-Type: multipart/alternative; + boundary="--=_---NextPart--=_-wFcVesztLV" +Message-ID: +Date: Wed, 20 Mar 2024 10:00:01 +0100 + + +----=_---NextPart--=_-wFcVesztLV +Content-Type: text/plain; charset=iso-8859-1 +Content-transfer-encoding: quoted-printable + +Plain text spam + +----=_---NextPart--=_-wFcVesztLV +Content-Type: text/html; charset=iso-8859-1 +Content-transfer-encoding: quoted-printable + +HTML SPAM +----=_---NextPart--=_-wFcVesztLV--