Skip to content

Commit b40d2d4

Browse files
committed
fix: always prefer the last header
Headers are normally added at the top of the message, e.g. when forwarding new `Received` headers are added at the top. When headers are protected with DKIM-Signature and oversigning is not used, forged headers may be added on top so headers from the top are generally less trustworthy. This is tested with `test_take_last_header`, but so far last header was only preferred for known headers. This change extends preference of the last header to all headers.
1 parent f5e8c80 commit b40d2d4

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/mimeparser.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,20 +1568,16 @@ impl MimeMessage {
15681568
for field in fields {
15691569
// lowercasing all headers is technically not correct, but makes things work better
15701570
let key = field.get_key().to_lowercase();
1571-
if !headers.contains_key(&key) || // key already exists, only overwrite known types (protected headers)
1572-
is_known(&key) || key.starts_with("chat-")
1573-
{
1574-
if key == HeaderDef::ChatDispositionNotificationTo.get_headername() {
1575-
match addrparse_header(field) {
1576-
Ok(addrlist) => {
1577-
*chat_disposition_notification_to = addrlist.extract_single_info();
1578-
}
1579-
Err(e) => warn!(context, "Could not read {} address: {}", key, e),
1571+
if key == HeaderDef::ChatDispositionNotificationTo.get_headername() {
1572+
match addrparse_header(field) {
1573+
Ok(addrlist) => {
1574+
*chat_disposition_notification_to = addrlist.extract_single_info();
15801575
}
1581-
} else {
1582-
let value = field.get_value();
1583-
headers.insert(key.to_string(), value);
1576+
Err(e) => warn!(context, "Could not read {} address: {}", key, e),
15841577
}
1578+
} else {
1579+
let value = field.get_value();
1580+
headers.insert(key.to_string(), value);
15851581
}
15861582
}
15871583
let recipients_new = get_recipients(fields);

0 commit comments

Comments
 (0)