Skip to content

Commit 9cc243f

Browse files
committed
mailinfo: move read_one_header_line() closer to its callers
Signed-off-by: Junio C Hamano <[email protected]>
1 parent 39afcd3 commit 9cc243f

File tree

1 file changed

+68
-68
lines changed

1 file changed

+68
-68
lines changed

builtin/mailinfo.c

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -379,74 +379,6 @@ static int check_header(const struct strbuf *line,
379379
return ret;
380380
}
381381

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-
450382
static struct strbuf *decode_q_segment(const struct strbuf *q_seg, int rfc2047)
451383
{
452384
const char *in = q_seg->buf;
@@ -795,6 +727,74 @@ static void handle_filter(struct strbuf *line)
795727
}
796728
}
797729

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+
798798
static int find_boundary(void)
799799
{
800800
while (!strbuf_getline(&line, fin, '\n')) {

0 commit comments

Comments
 (0)