mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 21:36:30 +03:00
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:
18
src/tools.rs
18
src/tools.rs
@@ -34,6 +34,7 @@ use num_traits::PrimInt;
|
|||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use tokio::{fs, io};
|
use tokio::{fs, io};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::chat::{add_device_msg, add_device_msg_with_importance};
|
use crate::chat::{add_device_msg, add_device_msg_with_importance};
|
||||||
use crate::config::Config;
|
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.
|
/// Generate an unique ID.
|
||||||
///
|
///
|
||||||
/// The generated ID should be short but unique:
|
/// 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
|
/// - unique as two IDs generated on two devices should not be the same
|
||||||
///
|
///
|
||||||
/// IDs generated by this function have 144 bits of entropy
|
/// 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
|
/// - the message ID should be globally unique
|
||||||
/// - do not add a counter or any private data as this leaks information unnecessarily
|
/// - do not add a counter or any private data as this leaks information unnecessarily
|
||||||
pub(crate) fn create_outgoing_rfc724_mid() -> String {
|
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
|
// the returned suffix is lower-case
|
||||||
@@ -979,7 +986,8 @@ DKIM Results: Passed=true";
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_create_outgoing_rfc724_mid() {
|
fn test_create_outgoing_rfc724_mid() {
|
||||||
let mid = 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"));
|
assert!(mid.ends_with("@localhost"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user