diff --git a/src/tools.rs b/src/tools.rs index db70e9e0b..b23f3b482 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -34,6 +34,7 @@ use num_traits::PrimInt; use rand::{thread_rng, Rng}; use tokio::{fs, io}; use url::Url; +use uuid::Uuid; use crate::chat::{add_device_msg, add_device_msg_with_importance}; use crate::config::Config; @@ -275,12 +276,10 @@ async fn maybe_warn_on_outdated(context: &Context, now: i64, approx_compile_time } } -/* Message-ID tools */ - /// Generate an unique ID. /// /// The generated ID should be short but unique: -/// - short, because it used in Message-ID and Chat-Group-ID headers and in QR codes +/// - short, because it used in Chat-Group-ID headers and in QR codes /// - unique as two IDs generated on two devices should not be the same /// /// IDs generated by this function have 144 bits of entropy @@ -312,7 +311,15 @@ pub(crate) fn validate_id(s: &str) -> bool { /// - the message ID should be globally unique /// - do not add a counter or any private data as this leaks information unnecessarily pub(crate) fn create_outgoing_rfc724_mid() -> String { - format!("{}@localhost", create_id()) + // We use UUID similarly to iCloud web mail client + // because it seems their spam filter does not like Message-IDs + // without hyphens. + // + // However, we use `localhost` instead of the real domain to avoid + // leaking the domain when resent by otherwise anonymizing + // From-rewriting mailing lists and forwarders. + let uuid = Uuid::new_v4(); + format!("{uuid}@localhost") } // the returned suffix is lower-case @@ -979,7 +986,8 @@ DKIM Results: Passed=true"; #[test] fn test_create_outgoing_rfc724_mid() { let mid = create_outgoing_rfc724_mid(); - assert_eq!(mid.len(), 34); + assert_eq!(mid.len(), 46); + assert!(mid.contains("-")); // It has an UUID inside. assert!(mid.ends_with("@localhost")); }