feat: use UUID v4 to generate Message-IDs

This hopefully does not trigger Apple spam filter
which seems to pass thorugh Message-IDs with hyphens.
It is not confirmed, but better blend in
by mimicking existing popular email
where possible.
This commit is contained in:
link2xt
2025-02-17 10:38:44 +00:00
committed by l
parent 41c2a80bd7
commit 130bef8c4a

View File

@@ -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"));
}