@@ -949,28 +949,24 @@ fn parse_mail_recursive(
949949 let ( headers, ix_body) = parse_headers ( raw_data) ?;
950950 let ctype = headers
951951 . get_first_value ( "Content-Type" )
952- . map ( |s| parse_content_type ( & s) )
952+ . as_deref ( )
953+ . map ( parse_content_type)
953954 . unwrap_or_else ( || ParsedContentType :: default_conditional ( in_multipart_digest) ) ;
954955
955- let mut result = ParsedMail {
956- raw_bytes : raw_data,
957- header_bytes : & raw_data[ 0 ..ix_body] ,
958- headers,
959- ctype,
960- body_bytes : & raw_data[ ix_body..] ,
961- subparts : Vec :: < ParsedMail > :: new ( ) ,
962- } ;
963- if result. ctype . mimetype . starts_with ( "multipart/" )
964- && result. ctype . params . contains_key ( "boundary" )
956+ let mut subparts = Vec :: new ( ) ;
957+ let mut body_bytes = & raw_data[ ix_body..] ;
958+
959+ if ctype. mimetype . starts_with ( "multipart/" )
960+ && let Some ( boundary) = ctype. params . get ( "boundary" )
965961 && raw_data. len ( ) > ix_body
966962 {
967- let in_multipart_digest = result . ctype . mimetype == "multipart/digest" ;
968- let boundary = String :: from ( "--" ) + & result . ctype . params [ "boundary" ] ;
963+ let boundary = String :: from ( "--" ) + boundary ;
964+ let in_multipart_digest = ctype. mimetype == "multipart/digest" ;
969965 if let Some ( ix_boundary_start) =
970966 find_from_u8_line_prefix ( raw_data, ix_body, boundary. as_bytes ( ) )
971967 {
972968 let ix_body_end = strip_trailing_crlf ( raw_data, ix_body, ix_boundary_start) ;
973- result . body_bytes = & raw_data[ ix_body..ix_body_end] ;
969+ body_bytes = & raw_data[ ix_body..ix_body_end] ;
974970 let mut ix_boundary_end = ix_boundary_start + boundary. len ( ) ;
975971 while let Some ( ix_part_start) =
976972 find_from_u8 ( raw_data, ix_boundary_end, b"\n " ) . map ( |v| v + 1 )
@@ -982,7 +978,7 @@ fn parse_mail_recursive(
982978 // if there is no terminating boundary, assume the part end is the end of the email
983979 . unwrap_or ( raw_data. len ( ) ) ;
984980
985- result . subparts . push ( parse_mail_recursive (
981+ subparts. push ( parse_mail_recursive (
986982 & raw_data[ ix_part_start..ix_part_end] ,
987983 in_multipart_digest,
988984 ) ?) ;
@@ -997,7 +993,15 @@ fn parse_mail_recursive(
997993 }
998994 }
999995 }
1000- Ok ( result)
996+
997+ Ok ( ParsedMail {
998+ raw_bytes : raw_data,
999+ header_bytes : & raw_data[ ..ix_body] ,
1000+ headers,
1001+ ctype,
1002+ body_bytes,
1003+ subparts,
1004+ } )
10011005}
10021006
10031007/// Used to store params for content-type and content-disposition
0 commit comments