@@ -549,47 +549,54 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
549
549
mi -> input_error = -1 ;
550
550
}
551
551
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
+
552
571
static int check_header (struct mailinfo * mi ,
553
572
const struct strbuf * line ,
554
573
struct strbuf * hdr_data [], int overwrite )
555
574
{
556
575
int i , ret = 0 ;
557
576
struct strbuf sb = STRBUF_INIT ;
558
- const char * val ;
559
577
560
578
/* search for the interesting parts */
561
579
for (i = 0 ; header [i ]; i ++ ) {
562
580
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 )) {
569
582
handle_header (& hdr_data [i ], & sb );
570
583
ret = 1 ;
571
584
goto check_header_out ;
572
585
}
573
586
}
574
587
575
588
/* 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 )) {
579
590
handle_content_type (mi , & sb );
580
591
ret = 1 ;
581
592
goto check_header_out ;
582
593
}
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 )) {
586
595
handle_content_transfer_encoding (mi , & sb );
587
596
ret = 1 ;
588
597
goto check_header_out ;
589
598
}
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 )) {
593
600
if (mi -> add_message_id )
594
601
mi -> message_id = strbuf_detach (& sb , NULL );
595
602
ret = 1 ;
0 commit comments