@@ -284,7 +284,6 @@ static void cleanup_space(struct strbuf *sb)
284
284
}
285
285
}
286
286
287
- static void decode_header (struct strbuf * line );
288
287
static const char * header [MAX_HDR_PARSED ] = {
289
288
"From" ,"Subject" ,"Date" ,
290
289
};
@@ -312,73 +311,6 @@ static int is_format_patch_separator(const char *line, int len)
312
311
return !memcmp (SAMPLE + (cp - line ), cp , strlen (SAMPLE ) - (cp - line ));
313
312
}
314
313
315
- static int check_header (const struct strbuf * line ,
316
- struct strbuf * hdr_data [], int overwrite )
317
- {
318
- int i , ret = 0 , len ;
319
- struct strbuf sb = STRBUF_INIT ;
320
- /* search for the interesting parts */
321
- for (i = 0 ; header [i ]; i ++ ) {
322
- int len = strlen (header [i ]);
323
- if ((!hdr_data [i ] || overwrite ) && cmp_header (line , header [i ])) {
324
- /* Unwrap inline B and Q encoding, and optionally
325
- * normalize the meta information to utf8.
326
- */
327
- strbuf_add (& sb , line -> buf + len + 2 , line -> len - len - 2 );
328
- decode_header (& sb );
329
- handle_header (& hdr_data [i ], & sb );
330
- ret = 1 ;
331
- goto check_header_out ;
332
- }
333
- }
334
-
335
- /* Content stuff */
336
- if (cmp_header (line , "Content-Type" )) {
337
- len = strlen ("Content-Type: " );
338
- strbuf_add (& sb , line -> buf + len , line -> len - len );
339
- decode_header (& sb );
340
- strbuf_insert (& sb , 0 , "Content-Type: " , len );
341
- handle_content_type (& sb );
342
- ret = 1 ;
343
- goto check_header_out ;
344
- }
345
- if (cmp_header (line , "Content-Transfer-Encoding" )) {
346
- len = strlen ("Content-Transfer-Encoding: " );
347
- strbuf_add (& sb , line -> buf + len , line -> len - len );
348
- decode_header (& sb );
349
- handle_content_transfer_encoding (& sb );
350
- ret = 1 ;
351
- goto check_header_out ;
352
- }
353
- if (cmp_header (line , "Message-Id" )) {
354
- len = strlen ("Message-Id: " );
355
- strbuf_add (& sb , line -> buf + len , line -> len - len );
356
- decode_header (& sb );
357
- handle_message_id (& sb );
358
- ret = 1 ;
359
- goto check_header_out ;
360
- }
361
-
362
- /* for inbody stuff */
363
- if (starts_with (line -> buf , ">From" ) && isspace (line -> buf [5 ])) {
364
- ret = is_format_patch_separator (line -> buf + 1 , line -> len - 1 );
365
- goto check_header_out ;
366
- }
367
- if (starts_with (line -> buf , "[PATCH]" ) && isspace (line -> buf [7 ])) {
368
- for (i = 0 ; header [i ]; i ++ ) {
369
- if (!strcmp ("Subject" , header [i ])) {
370
- handle_header (& hdr_data [i ], line );
371
- ret = 1 ;
372
- goto check_header_out ;
373
- }
374
- }
375
- }
376
-
377
- check_header_out :
378
- strbuf_release (& sb );
379
- return ret ;
380
- }
381
-
382
314
static struct strbuf * decode_q_segment (const struct strbuf * q_seg , int rfc2047 )
383
315
{
384
316
const char * in = q_seg -> buf ;
@@ -539,6 +471,73 @@ static void decode_header(struct strbuf *it)
539
471
strbuf_release (& piecebuf );
540
472
}
541
473
474
+ static int check_header (const struct strbuf * line ,
475
+ struct strbuf * hdr_data [], int overwrite )
476
+ {
477
+ int i , ret = 0 , len ;
478
+ struct strbuf sb = STRBUF_INIT ;
479
+ /* search for the interesting parts */
480
+ for (i = 0 ; header [i ]; i ++ ) {
481
+ int len = strlen (header [i ]);
482
+ if ((!hdr_data [i ] || overwrite ) && cmp_header (line , header [i ])) {
483
+ /* Unwrap inline B and Q encoding, and optionally
484
+ * normalize the meta information to utf8.
485
+ */
486
+ strbuf_add (& sb , line -> buf + len + 2 , line -> len - len - 2 );
487
+ decode_header (& sb );
488
+ handle_header (& hdr_data [i ], & sb );
489
+ ret = 1 ;
490
+ goto check_header_out ;
491
+ }
492
+ }
493
+
494
+ /* Content stuff */
495
+ if (cmp_header (line , "Content-Type" )) {
496
+ len = strlen ("Content-Type: " );
497
+ strbuf_add (& sb , line -> buf + len , line -> len - len );
498
+ decode_header (& sb );
499
+ strbuf_insert (& sb , 0 , "Content-Type: " , len );
500
+ handle_content_type (& sb );
501
+ ret = 1 ;
502
+ goto check_header_out ;
503
+ }
504
+ if (cmp_header (line , "Content-Transfer-Encoding" )) {
505
+ len = strlen ("Content-Transfer-Encoding: " );
506
+ strbuf_add (& sb , line -> buf + len , line -> len - len );
507
+ decode_header (& sb );
508
+ handle_content_transfer_encoding (& sb );
509
+ ret = 1 ;
510
+ goto check_header_out ;
511
+ }
512
+ if (cmp_header (line , "Message-Id" )) {
513
+ len = strlen ("Message-Id: " );
514
+ strbuf_add (& sb , line -> buf + len , line -> len - len );
515
+ decode_header (& sb );
516
+ handle_message_id (& sb );
517
+ ret = 1 ;
518
+ goto check_header_out ;
519
+ }
520
+
521
+ /* for inbody stuff */
522
+ if (starts_with (line -> buf , ">From" ) && isspace (line -> buf [5 ])) {
523
+ ret = is_format_patch_separator (line -> buf + 1 , line -> len - 1 );
524
+ goto check_header_out ;
525
+ }
526
+ if (starts_with (line -> buf , "[PATCH]" ) && isspace (line -> buf [7 ])) {
527
+ for (i = 0 ; header [i ]; i ++ ) {
528
+ if (!strcmp ("Subject" , header [i ])) {
529
+ handle_header (& hdr_data [i ], line );
530
+ ret = 1 ;
531
+ goto check_header_out ;
532
+ }
533
+ }
534
+ }
535
+
536
+ check_header_out :
537
+ strbuf_release (& sb );
538
+ return ret ;
539
+ }
540
+
542
541
static void decode_transfer_encoding (struct strbuf * line )
543
542
{
544
543
struct strbuf * ret ;
0 commit comments