@@ -346,11 +346,16 @@ static const char *header[MAX_HDR_PARSED] = {
346
346
"From" ,"Subject" ,"Date" ,
347
347
};
348
348
349
- static inline int cmp_header (const struct strbuf * line , const char * hdr )
349
+ static inline int skip_header (const struct strbuf * line , const char * hdr ,
350
+ const char * * outval )
350
351
{
351
- int len = strlen (hdr );
352
- return !strncasecmp (line -> buf , hdr , len ) && line -> len > len &&
353
- line -> buf [len ] == ':' && isspace (line -> buf [len + 1 ]);
352
+ const char * val ;
353
+ if (!skip_iprefix (line -> buf , hdr , & val ) ||
354
+ * val ++ != ':' ||
355
+ !isspace (* val ++ ))
356
+ return 0 ;
357
+ * outval = val ;
358
+ return 1 ;
354
359
}
355
360
356
361
static int is_format_patch_separator (const char * line , int len )
@@ -547,17 +552,18 @@ static int check_header(struct mailinfo *mi,
547
552
const struct strbuf * line ,
548
553
struct strbuf * hdr_data [], int overwrite )
549
554
{
550
- int i , ret = 0 , len ;
555
+ int i , ret = 0 ;
551
556
struct strbuf sb = STRBUF_INIT ;
557
+ const char * val ;
552
558
553
559
/* search for the interesting parts */
554
560
for (i = 0 ; header [i ]; i ++ ) {
555
- int len = strlen ( header [i ]);
556
- if ((! hdr_data [ i ] || overwrite ) && cmp_header (line , header [i ])) {
561
+ if ((! hdr_data [i ] || overwrite ) &&
562
+ skip_header (line , header [i ], & val )) {
557
563
/* Unwrap inline B and Q encoding, and optionally
558
564
* normalize the meta information to utf8.
559
565
*/
560
- strbuf_addstr (& sb , line -> buf + len + 2 );
566
+ strbuf_addstr (& sb , val );
561
567
decode_header (mi , & sb );
562
568
handle_header (& hdr_data [i ], & sb );
563
569
ret = 1 ;
@@ -566,25 +572,22 @@ static int check_header(struct mailinfo *mi,
566
572
}
567
573
568
574
/* Content stuff */
569
- if (cmp_header (line , "Content-Type" )) {
570
- len = strlen ("Content-Type: " );
571
- strbuf_addstr (& sb , line -> buf + len );
575
+ if (skip_header (line , "Content-Type" , & val )) {
576
+ strbuf_addstr (& sb , val );
572
577
decode_header (mi , & sb );
573
578
handle_content_type (mi , & sb );
574
579
ret = 1 ;
575
580
goto check_header_out ;
576
581
}
577
- if (cmp_header (line , "Content-Transfer-Encoding" )) {
578
- len = strlen ("Content-Transfer-Encoding: " );
579
- strbuf_addstr (& sb , line -> buf + len );
582
+ if (skip_header (line , "Content-Transfer-Encoding" , & val )) {
583
+ strbuf_addstr (& sb , val );
580
584
decode_header (mi , & sb );
581
585
handle_content_transfer_encoding (mi , & sb );
582
586
ret = 1 ;
583
587
goto check_header_out ;
584
588
}
585
- if (cmp_header (line , "Message-Id" )) {
586
- len = strlen ("Message-Id: " );
587
- strbuf_addstr (& sb , line -> buf + len );
589
+ if (skip_header (line , "Message-Id" , & val )) {
590
+ strbuf_addstr (& sb , val );
588
591
decode_header (mi , & sb );
589
592
if (mi -> add_message_id )
590
593
mi -> message_id = strbuf_detach (& sb , NULL );
@@ -606,8 +609,9 @@ static int is_inbody_header(const struct mailinfo *mi,
606
609
const struct strbuf * line )
607
610
{
608
611
int i ;
612
+ const char * val ;
609
613
for (i = 0 ; header [i ]; i ++ )
610
- if (!mi -> s_hdr_data [i ] && cmp_header (line , header [i ]))
614
+ if (!mi -> s_hdr_data [i ] && skip_header (line , header [i ], & val ))
611
615
return 1 ;
612
616
return 0 ;
613
617
}
0 commit comments