-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Ignore protected headers in outer message part (#6357) #6370
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,20 +419,9 @@ impl MimeMessage { | |
gossip_headers, | ||
) | ||
.await?; | ||
// Remove unsigned opportunistically protected headers from messages considered | ||
// Autocrypt-encrypted / displayed with padlock. | ||
// For "Subject" see <https://github.com/deltachat/deltachat-core-rust/issues/1790>. | ||
for h in [ | ||
HeaderDef::Subject, | ||
HeaderDef::ChatGroupId, | ||
HeaderDef::ChatGroupName, | ||
HeaderDef::ChatGroupNameChanged, | ||
HeaderDef::ChatGroupAvatar, | ||
HeaderDef::ChatGroupMemberRemoved, | ||
HeaderDef::ChatGroupMemberAdded, | ||
] { | ||
headers.remove(h.get_headername()); | ||
} | ||
// Other headers are removed by `MimeMessage::merge_headers()`. | ||
headers.remove("subject"); | ||
} | ||
|
||
// let known protected headers from the decrypted | ||
|
@@ -1528,12 +1517,15 @@ impl MimeMessage { | |
chat_disposition_notification_to: &mut Option<SingleInfo>, | ||
fields: &[mailparse::MailHeader<'_>], | ||
) { | ||
// Keep Subject so that it's displayed for signed-only messages. They are shown w/o a | ||
// padlock anyway. | ||
headers.retain(|k, _| !is_protected(k) || k == "subject"); | ||
for field in fields { | ||
// lowercasing all headers is technically not correct, but makes things work better | ||
let key = field.get_key().to_lowercase(); | ||
if !headers.contains_key(&key) || // key already exists, only overwrite known types (protected headers) | ||
is_known(&key) || key.starts_with("chat-") | ||
{ | ||
// Don't overwrite unprotected headers, but overwrite protected ones because DKIM | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this comment, why is it important here that DKIM signature applies to last headers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least |
||
// signature applies to the last headers. | ||
if !headers.contains_key(&key) || is_protected(&key) { | ||
if key == HeaderDef::ChatDispositionNotificationTo.get_headername() { | ||
match addrparse_header(field) { | ||
Ok(addrlist) => { | ||
|
@@ -1929,23 +1921,26 @@ pub(crate) fn parse_message_id(ids: &str) -> Result<String> { | |
|
||
/// Returns true if the header overwrites outer header | ||
/// when it comes from protected headers. | ||
fn is_known(key: &str) -> bool { | ||
matches!( | ||
key, | ||
"return-path" | ||
| "date" | ||
| "from" | ||
| "sender" | ||
| "reply-to" | ||
| "to" | ||
| "cc" | ||
| "bcc" | ||
| "message-id" | ||
| "in-reply-to" | ||
| "references" | ||
| "subject" | ||
| "secure-join" | ||
) | ||
fn is_protected(key: &str) -> bool { | ||
key.starts_with("chat-") | ||
|| matches!( | ||
key, | ||
"return-path" | ||
| "auto-submitted" | ||
| "autocrypt-setup-message" | ||
| "date" | ||
| "from" | ||
| "sender" | ||
| "reply-to" | ||
| "to" | ||
| "cc" | ||
| "bcc" | ||
| "message-id" | ||
| "in-reply-to" | ||
| "references" | ||
| "subject" | ||
| "secure-join" | ||
) | ||
} | ||
|
||
/// Parsed MIME part. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also extend a test
test_is_bot
with a non-chat message? It's important that non-DC unencrypted messages from auto-repliers havedc_msg_is_bot
returning true. Seems to work because for such messagesmerge_headers
is never called, but better test it explicitly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, but this doesn't work, if it's a non-chat message, we don't mark a contact as bot and this looks intentional:
Anyway i improved the test to record the current behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a bug, message should be marked as a bot message, but the contact should not become a bot in this case. I created an issue #6373
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the second commit because you're fixing this in #6374