fix: put overridden sender name into message info

This commit is contained in:
link2xt
2024-03-24 23:08:09 +00:00
parent 9af812a3e7
commit 1adea3c678
4 changed files with 58 additions and 6 deletions

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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(())
}

View File

@@ -0,0 +1,28 @@
Return-Path: <wwwrun@xpressus.emsmtp.com>
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?=" <clubinfo@donotreply.oeamtc.at>
MIME-Version: 1.0
List-Id: 134722648 <=?ISO-8859-1?Q?=D6AMTC?=>
List-Unsubscribe: <mailto:list-unsubscribe+xxx@emarsys.net>, <https://list-unsubscribe.eservice.emarsys.net/api/unsubscribe/xxx>
List-Unsubscribe-Post: List-Unsubscribe=One-Click
Content-Type: multipart/alternative;
boundary="--=_---NextPart--=_-wFcVesztLV"
Message-ID: <foobarbaz@pmta41019.emsmtp.com>
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--