static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch) { int peek; fin = in; fout = out; cmitmsg = fopen(msg, "w"); if (!cmitmsg) { perror(msg); return -1; } patchfile = fopen(patch, "w"); if (!patchfile) { perror(patch); fclose(cmitmsg); return -1; } p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*p_hdr_data)); s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*s_hdr_data)); do { peek = fgetc(in); } while (isspace(peek)); ungetc(peek, in); /* process the email header */ while (read_one_header_line(&line, fin)) check_header(&line, p_hdr_data, 1); handle_body(); handle_info(); return 0; }
static int handle_boundary(struct mailinfo *mi, struct strbuf *line) { struct strbuf newline = STRBUF_INIT; strbuf_addch(&newline, '\n'); again: if (line->len >= (*(mi->content_top))->len + 2 && !memcmp(line->buf + (*(mi->content_top))->len, "--", 2)) { /* we hit an end boundary */ /* pop the current boundary off the stack */ strbuf_release(*(mi->content_top)); free(*(mi->content_top)); *(mi->content_top) = NULL; /* technically won't happen as is_multipart_boundary() will fail first. But just in case.. */ if (--mi->content_top < mi->content) { error("Detected mismatched boundaries, can't recover"); mi->input_error = -1; mi->content_top = mi->content; return 0; } handle_filter(mi, &newline); strbuf_release(&newline); if (mi->input_error) return 0; /* skip to the next boundary */ if (!find_boundary(mi, line)) return 0; goto again; } /* set some defaults */ mi->transfer_encoding = TE_DONTCARE; strbuf_reset(&mi->charset); /* slurp in this section's info */ while (read_one_header_line(line, mi->input)) check_header(mi, line, mi->p_hdr_data, 0); strbuf_release(&newline); /* replenish line */ if (strbuf_getline_lf(line, mi->input)) return 0; strbuf_addch(line, '\n'); return 1; }
static int handle_boundary(void) { struct strbuf newline = STRBUF_INIT; strbuf_addch(&newline, '\n'); again: if (line.len >= (*content_top)->len + 2 && !memcmp(line.buf + (*content_top)->len, "--", 2)) { /* we hit an end boundary */ /* pop the current boundary off the stack */ strbuf_release(*content_top); free(*content_top); *content_top = NULL; /* technically won't happen as is_multipart_boundary() will fail first. But just in case.. */ if (--content_top < content) { fprintf(stderr, "Detected mismatched boundaries, " "can't recover\n"); exit(1); } handle_filter(&newline); strbuf_release(&newline); /* skip to the next boundary */ if (!find_boundary()) return 0; goto again; } /* set some defaults */ transfer_encoding = TE_DONTCARE; strbuf_reset(&charset); message_type = TYPE_TEXT; /* slurp in this section's info */ while (read_one_header_line(&line, fin)) check_header(&line, p_hdr_data, 0); strbuf_release(&newline); /* replenish line */ if (strbuf_getline(&line, fin, '\n')) return 0; strbuf_addch(&line, '\n'); return 1; }
int mailinfo(struct mailinfo *mi, const char *msg, const char *patch) { FILE *cmitmsg; int peek; struct strbuf line = STRBUF_INIT; cmitmsg = fopen(msg, "w"); if (!cmitmsg) { perror(msg); return -1; } mi->patchfile = fopen(patch, "w"); if (!mi->patchfile) { perror(patch); fclose(cmitmsg); return -1; } mi->p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->p_hdr_data))); mi->s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*(mi->s_hdr_data))); do { peek = fgetc(mi->input); if (peek == EOF) { fclose(cmitmsg); return error("empty patch: '%s'", patch); } } while (isspace(peek)); ungetc(peek, mi->input); /* process the email header */ while (read_one_header_line(&line, mi->input)) check_header(mi, &line, mi->p_hdr_data, 1); handle_body(mi, &line); fwrite(mi->log_message.buf, 1, mi->log_message.len, cmitmsg); fclose(cmitmsg); fclose(mi->patchfile); handle_info(mi); strbuf_release(&line); return mi->input_error; }
static int handle_boundary(void) { char newline[]="\n"; again: if (!memcmp(line+content_top->boundary_len, "--", 2)) { /* we hit an end boundary */ /* pop the current boundary off the stack */ free(content_top->boundary); /* technically won't happen as is_multipart_boundary() will fail first. But just in case.. */ if (content_top-- < content) { fprintf(stderr, "Detected mismatched boundaries, " "can't recover\n"); exit(1); } handle_filter(newline, sizeof(newline)); /* skip to the next boundary */ if (!find_boundary()) return 0; goto again; } /* set some defaults */ transfer_encoding = TE_DONTCARE; charset[0] = 0; message_type = TYPE_TEXT; /* slurp in this section's info */ while (read_one_header_line(line, sizeof(line), fin)) check_header(line, sizeof(line), p_hdr_data, 0); /* eat the blank line after section info */ return (fgets(line, sizeof(line), fin) != NULL); }