get correct names of .xt.local mailinglists (#2665)

* add a test for .xt.local mailinglists

* get correct names of .xt.local mailinglists

these mailinglist probably come from the xt:Commerce system
and are pretty widely used.

i have not seen an .xt.local mailinglist with name set in List-Id,
however, if that happens, it will still be taken.

only if the name is unset,
we use the name from the From-header.
This commit is contained in:
bjoern
2021-09-12 15:34:29 +02:00
committed by GitHub
parent 50a5e715d2
commit da2f30786b
3 changed files with 274 additions and 3 deletions

View File

@@ -1713,14 +1713,17 @@ async fn create_or_lookup_mailinglist(
}
// if we do not have a name yet and `From` indicates, that this is a notification list,
// a usable name is often in the `From` header.
// this pattern was seen for parcel service notifications
// and is similar to mailchimp above, however, with weaker conditions.
// a usable name is often in the `From` header (seen for several parcel service notifications).
// same, if we do not have a name yet and `List-Id` has a known suffix (`.xt.local`)
//
// this pattern is similar to mailchimp above, however,
// with weaker conditions and does not overwrite existing names.
if name.is_empty() {
if let Some(from) = mime_parser.from.first() {
if from.addr.contains("noreply")
|| from.addr.contains("no-reply")
|| from.addr.starts_with("notifications@")
|| listid.ends_with(".xt.local")
{
if let Some(display_name) = &from.display_name {
name = display_name.clone();
@@ -3321,6 +3324,40 @@ mod tests {
assert_eq!(chat.name, "DPD");
}
#[async_std::test]
async fn test_xt_local_mailing_list() -> Result<()> {
let t = TestContext::new_alice().await;
t.set_config(Config::ShowEmails, Some("2")).await?;
dc_receive_imf(
&t,
include_bytes!("../test-data/message/mailinglist_xt_local_microsoft.eml"),
"INBOX",
1,
false,
)
.await?;
let chat = Chat::load_from_db(&t, t.get_last_msg().await.chat_id).await?;
assert_eq!(chat.typ, Chattype::Mailinglist);
assert_eq!(chat.grpid, "96540.xt.local");
assert_eq!(chat.name, "Microsoft Store");
dc_receive_imf(
&t,
include_bytes!("../test-data/message/mailinglist_xt_local_spiegel.eml"),
"INBOX",
2,
false,
)
.await?;
let chat = Chat::load_from_db(&t, t.get_last_msg().await.chat_id).await?;
assert_eq!(chat.typ, Chattype::Mailinglist);
assert_eq!(chat.grpid, "121231234.xt.local");
assert_eq!(chat.name, "DER SPIEGEL Kundenservice");
Ok(())
}
#[async_std::test]
async fn test_mailing_list_with_mimepart_footer() {
let t = TestContext::new_alice().await;