Don't ignore incoming mails without Received-header

fix #2149
This commit is contained in:
Hocuri
2021-01-17 13:51:27 +01:00
parent 08c46af3aa
commit ccee289a5c
2 changed files with 18 additions and 17 deletions

View File

@@ -1134,9 +1134,10 @@ class TestOnlineAccount:
def test_dont_show_emails_in_draft_folder(self, acfactory):
"""Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them.
So: If there is no Received header AND it's not in the sentbox, then ignore the email."""
So: If it's outgoing AND there is no Received header AND it's not in the sentbox, then ignore the email."""
ac1 = acfactory.get_online_configuring_account()
ac1.set_config("show_emails", "2")
ac1.create_contact("alice@example.com").create_chat()
acfactory.wait_configure(ac1)
ac1.direct_imap.create_folder("Drafts")
@@ -1148,23 +1149,23 @@ class TestOnlineAccount:
ac1.stop_io()
ac1.direct_imap.append("Drafts", """
From: Bob <bob@example.org>
From: ac1 <{}>
Subject: subj
To: alice@example.com
Message-ID: <aepiors@example.org>
Content-Type: text/plain; charset=utf-8
message in Drafts
""")
""".format(ac1.get_config("configured_addr")))
ac1.direct_imap.append("Sent", """
From: Bob <bob@example.org>
From: ac1 <{}>
Subject: subj
To: alice@example.com
Message-ID: <hsabaeni@example.org>
Content-Type: text/plain; charset=utf-8
message in Sent
""")
""".format(ac1.get_config("configured_addr")))
ac1.set_config("scan_all_folders_debounce_secs", "0")
ac1.start_io()

View File

@@ -407,14 +407,6 @@ async fn add_parts(
}
}
if !context.is_sentbox(&server_folder).await && mime_parser.get(HeaderDef::Received).is_none() {
// Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them
// So: If there is no Received header AND it's not in the sentbox, then ignore the email.
info!(context, "Email is probably just a draft (TRASH)");
*chat_id = ChatId::new(DC_CHAT_ID_TRASH);
allow_creation = false;
}
// check if the message introduces a new chat:
// - outgoing messages introduce a chat with the first to: address if they are sent by a messenger
// - incoming messages introduce a chat only for known contacts if they are sent by a messenger
@@ -597,6 +589,16 @@ async fn add_parts(
}
}
if !context.is_sentbox(&server_folder).await
&& mime_parser.get(HeaderDef::Received).is_none()
{
// Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them
// So: If it's outgoing AND there is no Received header AND it's not in the sentbox, then ignore the email.
info!(context, "Email is probably just a draft (TRASH)");
*chat_id = ChatId::new(DC_CHAT_ID_TRASH);
allow_creation = false;
}
if !to_ids.is_empty() {
if chat_id.is_unset() {
let (new_chat_id, new_chat_id_blocked) = create_or_lookup_group(
@@ -2364,8 +2366,7 @@ mod tests {
let chat_id = chat::create_by_contact_id(&t, contact_id).await.unwrap();
dc_receive_imf(
&t,
b"Received: (Postfix, from userid 1000); Mon, 4 Dec 2006 14:51:39 +0100 (CET)\n\
From: =?UTF-8?B?0JjQvNGPLCDQpNCw0LzQuNC70LjRjw==?= <foobar@example.com>\n\
b"From: =?UTF-8?B?0JjQvNGPLCDQpNCw0LzQuNC70LjRjw==?= <foobar@example.com>\n\
To: alice@example.com\n\
Subject: foo\n\
Message-ID: <asdklfjjaweofi@example.com>\n\
@@ -2413,8 +2414,7 @@ mod tests {
dc_receive_imf(
&t,
b"Received: (Postfix, from userid 1000); Mon, 4 Dec 2006 14:51:39 +0100 (CET)\n\
From: Foobar <foobar@example.com>\n\
b"From: Foobar <foobar@example.com>\n\
To: =?UTF-8?B?0JjQvNGPLCDQpNCw0LzQuNC70LjRjw==?= alice@example.com\n\
Cc: =?utf-8?q?=3Ch2=3E?= <carl@host.tld>\n\
Subject: foo\n\