@@ -11,6 +11,7 @@ use iroh_gossip::proto::TopicId;
1111use mail_builder:: headers:: HeaderType ;
1212use mail_builder:: headers:: address:: { Address , EmailAddress } ;
1313use mail_builder:: mime:: MimePart ;
14+ use rand:: Rng as _;
1415use tokio:: fs;
1516
1617use crate :: aheader:: { Aheader , EncryptPreference } ;
@@ -998,6 +999,32 @@ impl MimeFactory {
998999 } else {
9991000 unprotected_headers. push ( header. clone ( ) ) ;
10001001 }
1002+ } else if is_encrypted && header_name == "date" {
1003+ protected_headers. push ( header. clone ( ) ) ;
1004+
1005+ // Randomized date goes to unprotected header.
1006+ //
1007+ // We cannot just send "Thu, 01 Jan 1970 00:00:00 +0000"
1008+ // or omit the header because GMX then fails with
1009+ //
1010+ // host mx00.emig.gmx.net[212.227.15.9] said:
1011+ // 554-Transaction failed
1012+ // 554-Reject due to policy restrictions.
1013+ // 554 For explanation visit https://postmaster.gmx.net/en/case?...
1014+ // (in reply to end of DATA command)
1015+ //
1016+ // and the explanation page says
1017+ // "The time information deviates too much from the actual time".
1018+ let timestamp_offset = rand:: thread_rng ( ) . gen_range ( 0 ..1000000 ) ;
1019+ let protected_timestamp = self . timestamp . saturating_sub ( timestamp_offset) ;
1020+ let unprotected_date =
1021+ chrono:: DateTime :: < chrono:: Utc > :: from_timestamp ( protected_timestamp, 0 )
1022+ . unwrap ( )
1023+ . to_rfc2822 ( ) ;
1024+ unprotected_headers. push ( (
1025+ "Date" ,
1026+ mail_builder:: headers:: raw:: Raw :: new ( unprotected_date) . into ( ) ,
1027+ ) ) ;
10011028 } else if is_encrypted {
10021029 protected_headers. push ( header. clone ( ) ) ;
10031030
@@ -1008,8 +1035,7 @@ impl MimeFactory {
10081035 mail_builder:: headers:: raw:: Raw :: new ( "[...]" ) . into ( ) ,
10091036 ) ) ;
10101037 }
1011- "date"
1012- | "in-reply-to"
1038+ "in-reply-to"
10131039 | "references"
10141040 | "auto-submitted"
10151041 | "chat-version"
0 commit comments