mailinfo: move read_one_header_line() closer to its callers
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Oct 14, 2015 at 17:44 UTC
9cc243f7a9b06fefb29cd8e4d91ecf97298c0cb5
1 file changed
+68
-68
builtin/mailinfo.c
+68
-68
@@ -379,74 +379,6 @@ check_header_out:
379
return ret;
380
}
381
382
-static int is_rfc2822_header(const struct strbuf *line)
383
-{
384
- /*
385
- * The section that defines the loosest possible
386
- * field name is "3.6.8 Optional fields".
387
- *
388
- * optional-field = field-name ":" unstructured CRLF
389
- * field-name = 1*ftext
390
- * ftext = %d33-57 / %59-126
391
- */
392
- int ch;
393
- char *cp = line->buf;
394
-
395
- /* Count mbox From headers as headers */
396
- if (starts_with(cp, "From ") || starts_with(cp, ">From "))
397
- return 1;
398
-
399
- while ((ch = *cp++)) {
400
- if (ch == ':')
401
- return 1;
402
- if ((33 <= ch && ch <= 57) ||
403
- (59 <= ch && ch <= 126))
404
- continue;
405
- break;
406
- }
407
- return 0;
408
-}
409
-
410
-static int read_one_header_line(struct strbuf *line, FILE *in)
411
-{
412
- struct strbuf continuation = STRBUF_INIT;
413
-
414
- /* Get the first part of the line. */
415
- if (strbuf_getline(line, in, '\n'))
416
- return 0;
417
-
418
- /*
419
- * Is it an empty line or not a valid rfc2822 header?
420
- * If so, stop here, and return false ("not a header")
421
- */
422
- strbuf_rtrim(line);
423
- if (!line->len || !is_rfc2822_header(line)) {
424
- /* Re-add the newline */
425
- strbuf_addch(line, '\n');
426
- return 0;
427
- }
428
-
429
- /*
430
- * Now we need to eat all the continuation lines..
431
- * Yuck, 2822 header "folding"
432
- */
433
- for (;;) {
434
- int peek;
435
-
436
- peek = fgetc(in); ungetc(peek, in);
437
- if (peek != ' ' && peek != '\t')
438
- break;
439
- if (strbuf_getline(&continuation, in, '\n'))
440
- break;
441
- continuation.buf[0] = ' ';
442
- strbuf_rtrim(&continuation);
443
- strbuf_addbuf(line, &continuation);
444
- }
445
- strbuf_release(&continuation);
446
-
447
- return 1;
448
-}
449
-
382
static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047)
383
{
384
const char *in = q_seg->buf;
@@ -795,6 +727,74 @@ static void handle_filter(struct strbuf *line)
727
}
728
}
729
730
+static int is_rfc2822_header(const struct strbuf *line)
731
+{
732
+ /*
733
+ * The section that defines the loosest possible
734
+ * field name is "3.6.8 Optional fields".
735
+ *
736
+ * optional-field = field-name ":" unstructured CRLF
737
+ * field-name = 1*ftext
738
+ * ftext = %d33-57 / %59-126
739
+ */
740
+ int ch;
741
+ char *cp = line->buf;
742
+
743
+ /* Count mbox From headers as headers */
744
+ if (starts_with(cp, "From ") || starts_with(cp, ">From "))
745
+ return 1;
746
+
747
+ while ((ch = *cp++)) {
748
+ if (ch == ':')
749
+ return 1;
750
+ if ((33 <= ch && ch <= 57) ||
751
+ (59 <= ch && ch <= 126))
752
+ continue;
753
+ break;
754
+ }
755
+ return 0;
756
+}
757
+
758
+static int read_one_header_line(struct strbuf *line, FILE *in)
759
+{
760
+ struct strbuf continuation = STRBUF_INIT;
761
+
762
+ /* Get the first part of the line. */
763
+ if (strbuf_getline(line, in, '\n'))
764
+ return 0;
765
+
766
+ /*
767
+ * Is it an empty line or not a valid rfc2822 header?
768
+ * If so, stop here, and return false ("not a header")
769
+ */
770
+ strbuf_rtrim(line);
771
+ if (!line->len || !is_rfc2822_header(line)) {
772
+ /* Re-add the newline */
773
+ strbuf_addch(line, '\n');
774
+ return 0;
775
+ }
776
+
777
+ /*
778
+ * Now we need to eat all the continuation lines..
779
+ * Yuck, 2822 header "folding"
780
+ */
781
+ for (;;) {
782
+ int peek;
783
+
784
+ peek = fgetc(in); ungetc(peek, in);
785
+ if (peek != ' ' && peek != '\t')
786
+ break;
787
+ if (strbuf_getline(&continuation, in, '\n'))
788
+ break;
789
+ continuation.buf[0] = ' ';
790
+ strbuf_rtrim(&continuation);
791
+ strbuf_addbuf(line, &continuation);
792
+ }
793
+ strbuf_release(&continuation);
794
+
795
+ return 1;
796
+}
797
+
798
static int find_boundary(void)
799
{
800
while (!strbuf_getline(&line, fin, '\n')) {