mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 23:46:31 +03:00
Fix #3507 Note that this is not intended for a release at this point! We first have to test whether it runs stable enough. If we want to make a release while we are not confident enough in authres-checking, then we have to disable it. BTW, most of the 3000 new lines are in `test_data/messages/dkimchecks...`, not the actual code da3a4b94 adds the results to the Message info. It currently does this by adding them to `hop_info`. Maybe we should rename `hop_info` to `extra_info` or something; this has the disadvantage that we can't rename the sql column name though. Follow-ups for this could be: - In `update_authservid_candidates()`: Implement the rest of the algorithm @hpk42 and me thought about. What's missing is remembering how sure we are that these are the right authserv-ids. Esp., when receiving a message sent from another account at the same domain, we can be quite sure that the authserv-ids in there are the ones of our email server. This will make authres-checking work with buzon.uy, disroot.org, yandex.ru, mailo.com, and riseup.net. - Think about how we present this to the user - e.g. currently the only change is that we don't accept key changes, which will mean that the small lock on the message is not shown. - And it will mean that we can fully enable AEAP, after revisiting the security implications of this, and assuming everyone (esp. @link2xt who pointed out the problems in the first place) feels comfortable with it.
123 lines
3.3 KiB
Rust
123 lines
3.3 KiB
Rust
//! # List of email headers.
|
|
|
|
use mailparse::{MailHeader, MailHeaderMap};
|
|
|
|
#[derive(Debug, Display, Clone, PartialEq, Eq, EnumVariantNames, IntoStaticStr)]
|
|
#[strum(serialize_all = "kebab_case")]
|
|
pub enum HeaderDef {
|
|
MessageId,
|
|
Subject,
|
|
Date,
|
|
From_,
|
|
To,
|
|
Cc,
|
|
Disposition,
|
|
|
|
/// Used in the "Body Part Header" of MDNs as of RFC 8098.
|
|
/// Indicates the Message-ID of the message for which the MDN is being issued.
|
|
OriginalMessageId,
|
|
|
|
/// Delta Chat extension for message IDs in combined MDNs
|
|
AdditionalMessageIds,
|
|
|
|
/// Outlook-SMTP-server replace the `Message-ID:`-header
|
|
/// and write the original ID to `X-Microsoft-Original-Message-ID`.
|
|
/// To sort things correctly and to not show outgoing messages twice,
|
|
/// we need to check that header as well.
|
|
XMicrosoftOriginalMessageId,
|
|
|
|
/// Thunderbird header used to store Draft information.
|
|
///
|
|
/// Thunderbird 78.11.0 does not set \Draft flag on messages saved as "Template", but sets this
|
|
/// header, so it can be used to ignore such messages.
|
|
XMozillaDraftInfo,
|
|
|
|
ListId,
|
|
ListPost,
|
|
References,
|
|
InReplyTo,
|
|
Precedence,
|
|
ContentType,
|
|
ContentId,
|
|
ChatVersion,
|
|
ChatGroupId,
|
|
ChatGroupName,
|
|
ChatGroupNameChanged,
|
|
ChatVerified,
|
|
ChatGroupAvatar,
|
|
ChatUserAvatar,
|
|
ChatVoiceMessage,
|
|
ChatGroupMemberRemoved,
|
|
ChatGroupMemberAdded,
|
|
ChatContent,
|
|
ChatDuration,
|
|
ChatDispositionNotificationTo,
|
|
ChatWebrtcRoom,
|
|
Autocrypt,
|
|
AutocryptSetupMessage,
|
|
SecureJoin,
|
|
SecureJoinGroup,
|
|
SecureJoinFingerprint,
|
|
SecureJoinInvitenumber,
|
|
SecureJoinAuth,
|
|
Sender,
|
|
EphemeralTimer,
|
|
Received,
|
|
|
|
/// A header that includes the results of the DKIM, SPF and DMARC checks.
|
|
/// See <https://datatracker.ietf.org/doc/html/rfc8601>
|
|
AuthenticationResults,
|
|
|
|
_TestHeader,
|
|
}
|
|
|
|
impl HeaderDef {
|
|
/// Returns the corresponding header string.
|
|
pub fn get_headername(&self) -> &'static str {
|
|
self.into()
|
|
}
|
|
}
|
|
|
|
pub trait HeaderDefMap {
|
|
fn get_header_value(&self, headerdef: HeaderDef) -> Option<String>;
|
|
fn get_header(&self, headerdef: HeaderDef) -> Option<&MailHeader>;
|
|
}
|
|
|
|
impl HeaderDefMap for [MailHeader<'_>] {
|
|
fn get_header_value(&self, headerdef: HeaderDef) -> Option<String> {
|
|
self.get_first_value(headerdef.get_headername())
|
|
}
|
|
fn get_header(&self, headerdef: HeaderDef) -> Option<&MailHeader> {
|
|
self.get_first_header(headerdef.get_headername())
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
/// Test that kebab_case serialization works as expected
|
|
fn kebab_test() {
|
|
assert_eq!(HeaderDef::From_.get_headername(), "from");
|
|
|
|
assert_eq!(HeaderDef::_TestHeader.get_headername(), "test-header");
|
|
}
|
|
|
|
#[test]
|
|
/// Test that headers are parsed case-insensitively
|
|
fn test_get_header_value_case() {
|
|
let (headers, _) =
|
|
mailparse::parse_headers(b"fRoM: Bob\naUtoCryPt-SeTup-MessAge: v99").unwrap();
|
|
assert_eq!(
|
|
headers.get_header_value(HeaderDef::AutocryptSetupMessage),
|
|
Some("v99".to_string())
|
|
);
|
|
assert_eq!(
|
|
headers.get_header_value(HeaderDef::From_),
|
|
Some("Bob".to_string())
|
|
);
|
|
assert_eq!(headers.get_header_value(HeaderDef::Autocrypt), None);
|
|
}
|
|
}
|