@@ -549,47 +549,54 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
549549 mi -> input_error = -1 ;
550550}
551551
552+ /*
553+ * Returns true if "line" contains a header matching "hdr", in which case "val"
554+ * will contain the value of the header with any RFC2047 B and Q encoding
555+ * unwrapped, and optionally normalize the meta information to utf8.
556+ */
557+ static int parse_header (const struct strbuf * line ,
558+ const char * hdr ,
559+ struct mailinfo * mi ,
560+ struct strbuf * val )
561+ {
562+ const char * val_str ;
563+
564+ if (!skip_header (line , hdr , & val_str ))
565+ return 0 ;
566+ strbuf_addstr (val , val_str );
567+ decode_header (mi , val );
568+ return 1 ;
569+ }
570+
552571static int check_header (struct mailinfo * mi ,
553572 const struct strbuf * line ,
554573 struct strbuf * hdr_data [], int overwrite )
555574{
556575 int i , ret = 0 ;
557576 struct strbuf sb = STRBUF_INIT ;
558- const char * val ;
559577
560578 /* search for the interesting parts */
561579 for (i = 0 ; header [i ]; i ++ ) {
562580 if ((!hdr_data [i ] || overwrite ) &&
563- skip_header (line , header [i ], & val )) {
564- /* Unwrap inline B and Q encoding, and optionally
565- * normalize the meta information to utf8.
566- */
567- strbuf_addstr (& sb , val );
568- decode_header (mi , & sb );
581+ parse_header (line , header [i ], mi , & sb )) {
569582 handle_header (& hdr_data [i ], & sb );
570583 ret = 1 ;
571584 goto check_header_out ;
572585 }
573586 }
574587
575588 /* Content stuff */
576- if (skip_header (line , "Content-Type" , & val )) {
577- strbuf_addstr (& sb , val );
578- decode_header (mi , & sb );
589+ if (parse_header (line , "Content-Type" , mi , & sb )) {
579590 handle_content_type (mi , & sb );
580591 ret = 1 ;
581592 goto check_header_out ;
582593 }
583- if (skip_header (line , "Content-Transfer-Encoding" , & val )) {
584- strbuf_addstr (& sb , val );
585- decode_header (mi , & sb );
594+ if (parse_header (line , "Content-Transfer-Encoding" , mi , & sb )) {
586595 handle_content_transfer_encoding (mi , & sb );
587596 ret = 1 ;
588597 goto check_header_out ;
589598 }
590- if (skip_header (line , "Message-Id" , & val )) {
591- strbuf_addstr (& sb , val );
592- decode_header (mi , & sb );
599+ if (parse_header (line , "Message-Id" , mi , & sb )) {
593600 if (mi -> add_message_id )
594601 mi -> message_id = strbuf_detach (& sb , NULL );
595602 ret = 1 ;
0 commit comments