mailinfo: do not let handle_body() touch global "line" directly
This function has a single caller, and called with the global "line" holding the first line of the e-mail body after the caller finished processing the e-mail headers. The function then goes into a loop to process each line of the input, starting from what was given by its caller, and fills the same global "line" variable from the input as it needs to process more lines. Let the caller explicitly pass a pointer to this global "line" variable as an argument, and have the function itself use that strbuf throughout, instead of referring to the global "line" itself. There are helper functions that this function calls that still touch the global directly; they will be updated as the series progresses. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
269e239c48
commit
fde00d50f6
@ -842,7 +842,7 @@ again:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_body(void)
|
static void handle_body(struct strbuf *line)
|
||||||
{
|
{
|
||||||
struct strbuf prev = STRBUF_INIT;
|
struct strbuf prev = STRBUF_INIT;
|
||||||
int filter_stage = 0;
|
int filter_stage = 0;
|
||||||
@ -856,7 +856,7 @@ static void handle_body(void)
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
/* process any boundary lines */
|
/* process any boundary lines */
|
||||||
if (*content_top && is_multipart_boundary(&line)) {
|
if (*content_top && is_multipart_boundary(line)) {
|
||||||
/* flush any leftover */
|
/* flush any leftover */
|
||||||
if (prev.len) {
|
if (prev.len) {
|
||||||
handle_filter(&prev, &filter_stage, &header_stage);
|
handle_filter(&prev, &filter_stage, &header_stage);
|
||||||
@ -867,7 +867,7 @@ static void handle_body(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Unwrap transfer encoding */
|
/* Unwrap transfer encoding */
|
||||||
decode_transfer_encoding(&line);
|
decode_transfer_encoding(line);
|
||||||
|
|
||||||
switch (transfer_encoding) {
|
switch (transfer_encoding) {
|
||||||
case TE_BASE64:
|
case TE_BASE64:
|
||||||
@ -876,7 +876,7 @@ static void handle_body(void)
|
|||||||
struct strbuf **lines, **it, *sb;
|
struct strbuf **lines, **it, *sb;
|
||||||
|
|
||||||
/* Prepend any previous partial lines */
|
/* Prepend any previous partial lines */
|
||||||
strbuf_insert(&line, 0, prev.buf, prev.len);
|
strbuf_insert(line, 0, prev.buf, prev.len);
|
||||||
strbuf_reset(&prev);
|
strbuf_reset(&prev);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -884,7 +884,7 @@ static void handle_body(void)
|
|||||||
* multiple new lines. Pass only one chunk
|
* multiple new lines. Pass only one chunk
|
||||||
* at a time to handle_filter()
|
* at a time to handle_filter()
|
||||||
*/
|
*/
|
||||||
lines = strbuf_split(&line, '\n');
|
lines = strbuf_split(line, '\n');
|
||||||
for (it = lines; (sb = *it); it++) {
|
for (it = lines; (sb = *it); it++) {
|
||||||
if (*(it + 1) == NULL) /* The last line */
|
if (*(it + 1) == NULL) /* The last line */
|
||||||
if (sb->buf[sb->len - 1] != '\n') {
|
if (sb->buf[sb->len - 1] != '\n') {
|
||||||
@ -902,10 +902,10 @@ static void handle_body(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
handle_filter(&line, &filter_stage, &header_stage);
|
handle_filter(line, &filter_stage, &header_stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (!strbuf_getwholeline(&line, fin, '\n'));
|
} while (!strbuf_getwholeline(line, fin, '\n'));
|
||||||
|
|
||||||
handle_body_out:
|
handle_body_out:
|
||||||
strbuf_release(&prev);
|
strbuf_release(&prev);
|
||||||
@ -991,7 +991,7 @@ static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch)
|
|||||||
while (read_one_header_line(&line, fin))
|
while (read_one_header_line(&line, fin))
|
||||||
check_header(&line, p_hdr_data, 1);
|
check_header(&line, p_hdr_data, 1);
|
||||||
|
|
||||||
handle_body();
|
handle_body(&line);
|
||||||
fclose(patchfile);
|
fclose(patchfile);
|
||||||
|
|
||||||
handle_info();
|
handle_info();
|
||||||
|
Loading…
Reference in New Issue
Block a user