1
1
//! # MIME message production.
2
2
3
+ use std:: collections:: HashSet ;
3
4
use std:: convert:: TryInto ;
4
5
5
6
use anyhow:: { bail, ensure, Context as _, Result } ;
@@ -517,6 +518,7 @@ impl<'a> MimeFactory<'a> {
517
518
// <https://datatracker.ietf.org/doc/html/rfc5322#appendix-A.1.1>.
518
519
let from_header = Header :: new_with_value ( "From" . into ( ) , vec ! [ from] ) . unwrap ( ) ;
519
520
headers. unprotected . push ( from_header. clone ( ) ) ;
521
+ headers. protected . push ( from_header) ;
520
522
521
523
if let Some ( sender_displayname) = & self . sender_displayname {
522
524
let sender =
@@ -704,8 +706,6 @@ impl<'a> MimeFactory<'a> {
704
706
)
705
707
} ;
706
708
let outer_message = if is_encrypted {
707
- headers. protected . push ( from_header) ;
708
-
709
709
// Store protected headers in the inner message.
710
710
let message = headers
711
711
. protected
@@ -800,12 +800,18 @@ impl<'a> MimeFactory<'a> {
800
800
// Store protected headers in the outer message.
801
801
let message = headers
802
802
. protected
803
- . into_iter ( )
804
- . fold ( message, |message, header| message. header ( header) ) ;
803
+ . iter ( )
804
+ . fold ( message, |message, header| message. header ( header. clone ( ) ) ) ;
805
805
806
806
if self . should_skip_autocrypt ( )
807
807
|| !context. get_config_bool ( Config :: SignUnencrypted ) . await ?
808
808
{
809
+ let protected: HashSet < Header > = HashSet :: from_iter ( headers. protected . into_iter ( ) ) ;
810
+ for h in headers. unprotected . split_off ( 0 ) {
811
+ if !protected. contains ( & h) {
812
+ headers. unprotected . push ( h) ;
813
+ }
814
+ }
809
815
message
810
816
} else {
811
817
let message = message. header ( get_content_type_directives_header ( ) ) ;
@@ -2216,6 +2222,7 @@ mod tests {
2216
2222
2217
2223
let part = payload. next ( ) . unwrap ( ) ;
2218
2224
assert_eq ! ( part. match_indices( "multipart/signed" ) . count( ) , 1 ) ;
2225
+ assert_eq ! ( part. match_indices( "From:" ) . count( ) , 1 ) ;
2219
2226
assert_eq ! ( part. match_indices( "Subject:" ) . count( ) , 0 ) ;
2220
2227
assert_eq ! ( part. match_indices( "Autocrypt:" ) . count( ) , 1 ) ;
2221
2228
assert_eq ! ( part. match_indices( "Chat-User-Avatar:" ) . count( ) , 0 ) ;
@@ -2226,12 +2233,14 @@ mod tests {
2226
2233
. count( ) ,
2227
2234
1
2228
2235
) ;
2236
+ assert_eq ! ( part. match_indices( "From:" ) . count( ) , 1 ) ;
2229
2237
assert_eq ! ( part. match_indices( "Subject:" ) . count( ) , 1 ) ;
2230
2238
assert_eq ! ( part. match_indices( "Autocrypt:" ) . count( ) , 0 ) ;
2231
2239
assert_eq ! ( part. match_indices( "Chat-User-Avatar:" ) . count( ) , 0 ) ;
2232
2240
2233
2241
let part = payload. next ( ) . unwrap ( ) ;
2234
2242
assert_eq ! ( part. match_indices( "text/plain" ) . count( ) , 1 ) ;
2243
+ assert_eq ! ( part. match_indices( "From:" ) . count( ) , 0 ) ;
2235
2244
assert_eq ! ( part. match_indices( "Chat-User-Avatar:" ) . count( ) , 1 ) ;
2236
2245
assert_eq ! ( part. match_indices( "Subject:" ) . count( ) , 0 ) ;
2237
2246
@@ -2258,12 +2267,14 @@ mod tests {
2258
2267
2259
2268
let part = payload. next ( ) . unwrap ( ) ;
2260
2269
assert_eq ! ( part. match_indices( "multipart/signed" ) . count( ) , 1 ) ;
2270
+ assert_eq ! ( part. match_indices( "From:" ) . count( ) , 1 ) ;
2261
2271
assert_eq ! ( part. match_indices( "Subject:" ) . count( ) , 0 ) ;
2262
2272
assert_eq ! ( part. match_indices( "Autocrypt:" ) . count( ) , 1 ) ;
2263
2273
assert_eq ! ( part. match_indices( "Chat-User-Avatar:" ) . count( ) , 0 ) ;
2264
2274
2265
2275
let part = payload. next ( ) . unwrap ( ) ;
2266
2276
assert_eq ! ( part. match_indices( "text/plain" ) . count( ) , 1 ) ;
2277
+ assert_eq ! ( part. match_indices( "From:" ) . count( ) , 1 ) ;
2267
2278
assert_eq ! ( part. match_indices( "Subject:" ) . count( ) , 1 ) ;
2268
2279
assert_eq ! ( part. match_indices( "Autocrypt:" ) . count( ) , 0 ) ;
2269
2280
assert_eq ! ( part. match_indices( "multipart/mixed" ) . count( ) , 0 ) ;
@@ -2272,6 +2283,7 @@ mod tests {
2272
2283
let body = payload. next ( ) . unwrap ( ) ;
2273
2284
assert_eq ! ( body. match_indices( "this is the text!" ) . count( ) , 1 ) ;
2274
2285
assert_eq ! ( body. match_indices( "text/plain" ) . count( ) , 0 ) ;
2286
+ assert_eq ! ( body. match_indices( "From:" ) . count( ) , 0 ) ;
2275
2287
assert_eq ! ( body. match_indices( "Chat-User-Avatar:" ) . count( ) , 0 ) ;
2276
2288
assert_eq ! ( body. match_indices( "Subject:" ) . count( ) , 0 ) ;
2277
2289
0 commit comments