@@ -224,7 +224,7 @@ impl<'x> MimePart<'x> {
224
224
let mut boundary: Option < Cow < str > > = None ;
225
225
226
226
loop {
227
- while let Some ( part) = it. next ( ) {
227
+ while let Some ( mut part) = it. next ( ) {
228
228
if let Some ( boundary) = boundary. as_ref ( ) {
229
229
output. write_all ( b"\r \n --" ) ?;
230
230
output. write_all ( boundary. as_bytes ( ) ) ?;
@@ -277,21 +277,45 @@ impl<'x> MimePart<'x> {
277
277
stack. push ( ( it, boundary) ) ;
278
278
}
279
279
280
- boundary = Some ( make_boundary ( ) . into ( ) ) ;
281
-
282
- for ( header_name, mut header_value) in part. headers {
283
- match & mut header_value {
284
- HeaderType :: ContentType ( ref mut content_type)
285
- if header_name == "Content-Type" =>
286
- {
280
+ output. write_all ( b"Content-Type: " ) ?;
281
+ boundary = if let Some ( value) = part. headers . remove ( "Content-Type" ) {
282
+ match value {
283
+ HeaderType :: ContentType ( mut ct) => {
287
284
if let Entry :: Vacant ( entry) =
288
- content_type . attributes . entry ( "boundary" . into ( ) )
285
+ ct . attributes . entry ( "boundary" . into ( ) )
289
286
{
290
- entry. insert ( boundary. as_ref ( ) . unwrap ( ) . as_ref ( ) . into ( ) ) ;
287
+ entry. insert ( make_boundary ( ) . into ( ) ) ;
288
+ }
289
+ ct. write_header ( & mut output, 14 ) ?;
290
+ ct. attributes . remove ( "boundary" )
291
+ }
292
+ HeaderType :: Raw ( raw) => {
293
+ if let Some ( pos) = raw. raw . find ( "boundary=\" " ) {
294
+ if let Some ( boundary) = raw. raw [ pos..] . split ( '"' ) . nth ( 1 ) {
295
+ Some ( boundary. to_string ( ) . into ( ) )
296
+ } else {
297
+ Some ( make_boundary ( ) . into ( ) )
298
+ }
299
+ } else {
300
+ let boundary = make_boundary ( ) ;
301
+ output. write_all ( raw. raw . as_bytes ( ) ) ?;
302
+ output. write_all ( b"; boundary=\" " ) ?;
303
+ output. write_all ( boundary. as_bytes ( ) ) ?;
304
+ output. write_all ( b"\" \r \n " ) ?;
305
+ Some ( boundary. into ( ) )
291
306
}
292
307
}
293
- _ => { }
308
+ _ => panic ! ( "Unsupported Content-Type header value." ) ,
294
309
}
310
+ } else {
311
+ let boundary = make_boundary ( ) ;
312
+ ContentType :: new ( "multipart/mixed" )
313
+ . attribute ( "boundary" , & boundary)
314
+ . write_header ( & mut output, 14 ) ?;
315
+ Some ( boundary. into ( ) )
316
+ } ;
317
+
318
+ for ( header_name, header_value) in part. headers {
295
319
output. write_all ( header_name. as_bytes ( ) ) ?;
296
320
output. write_all ( b": " ) ?;
297
321
header_value. write_header ( & mut output, header_name. len ( ) + 2 ) ?;
0 commit comments