static void handle_body(void) { struct strbuf prev = STRBUF_INIT; /* Skip up to the first boundary */ if (*content_top) { if (!find_boundary()) goto handle_body_out; } do { /* process any boundary lines */ if (*content_top && is_multipart_boundary(&line)) { /* flush any leftover */ if (prev.len) { handle_filter(&prev); strbuf_reset(&prev); } if (!handle_boundary()) goto handle_body_out; } /* Unwrap transfer encoding */ decode_transfer_encoding(&line); switch (transfer_encoding) { case TE_BASE64: case TE_QP: { struct strbuf **lines, **it, *sb; /* Prepend any previous partial lines */ strbuf_insert(&line, 0, prev.buf, prev.len); strbuf_reset(&prev); /* binary data most likely doesn't have newlines */ if (message_type != TYPE_TEXT) { handle_filter(&line); break; } /* * This is a decoded line that may contain * multiple new lines. Pass only one chunk * at a time to handle_filter() */ lines = strbuf_split(&line, '\n'); for (it = lines; (sb = *it); it++) { if (*(it + 1) == NULL) /* The last line */ if (sb->buf[sb->len - 1] != '\n') { /* Partial line, save it for later. */ strbuf_addbuf(&prev, sb); break; } handle_filter(sb); } /* * The partial chunk is saved in "prev" and will be * appended by the next iteration of read_line_with_nul(). */ strbuf_list_free(lines); break; } default: handle_filter(&line); } } while (!strbuf_getwholeline(&line, fin, '\n')); handle_body_out: strbuf_release(&prev); }
static void handle_body(void) { int rc = 0; static char newline[2000]; static char *np = newline; /* Skip up to the first boundary */ if (content_top->boundary) { if (!find_boundary()) return; } do { /* process any boundary lines */ if (content_top->boundary && is_multipart_boundary(line)) { /* flush any leftover */ if ((transfer_encoding == TE_BASE64) && (np != newline)) { handle_filter(newline, sizeof(newline)); } if (!handle_boundary()) return; } /* Unwrap transfer encoding */ decode_transfer_encoding(line, sizeof(line)); switch (transfer_encoding) { case TE_BASE64: case TE_QP: { char *op = line; /* binary data most likely doesn't have newlines */ if (message_type != TYPE_TEXT) { rc = handle_filter(line, sizeof(newline)); break; } /* this is a decoded line that may contain * multiple new lines. Pass only one chunk * at a time to handle_filter() */ do { while (*op != '\n' && *op != 0) *np++ = *op++; *np = *op; if (*np != 0) { /* should be sitting on a new line */ *(++np) = 0; op++; rc = handle_filter(newline, sizeof(newline)); np = newline; } } while (*op != 0); /* the partial chunk is saved in newline and * will be appended by the next iteration of fgets */ break; } default: rc = handle_filter(line, sizeof(newline)); } if (rc) /* nothing left to filter */ break; } while (fgets(line, sizeof(line), fin)); return; }