Skip to content

Commit

Permalink
feat: Use "From" address instead of "" as a fallback contact display …
Browse files Browse the repository at this point in the history
…name (#5184)

If we cannot use the display name from the "From" header for a new contact, e.g. for mailing list
messages, use the "From" address, it's better than an empty string.
  • Loading branch information
iequidoo committed Feb 28, 2024
1 parent 08a3003 commit dae55ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,12 @@ pub async fn from_field_to_contact_id(
prevent_rename: bool,
) -> Result<Option<(ContactId, bool, Origin)>> {
let display_name = if prevent_rename {
Some("")
Some(
match Contact::lookup_id_by_addr(context, &from.addr, Origin::Unknown).await? {
None => from.addr.as_str(),
Some(_) => "",
},
)
} else {
from.display_name.as_deref()
};
Expand Down
10 changes: 10 additions & 0 deletions src/receive_imf/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,16 @@ Hello mailinglist!\r\n"
let chat = chat::Chat::load_from_db(&t.ctx, chat_id).await?;
assert!(chat.can_send(&t.ctx).await?);

for addr in ["bob@posteo.org", "charlie@posteo.org"] {
let contact_id = Contact::lookup_id_by_addr(&t, addr, Origin::Unknown)
.await
.unwrap()
.unwrap();
let contact = Contact::get_by_id(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), addr);
assert_eq!(contact.get_display_name(), addr);
}

Ok(())
}

Expand Down

0 comments on commit dae55ee

Please sign in to comment.