X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=builtin-mailinfo.c;h=e890f7a6d1ff7248aed4f03ebbcdfafd7e472dad;hb=6e13921b4f7adcc7316a76c0c4955b85b1589a65;hp=f974b9df968c74c5d62d58b2a09493e6abb4322e;hpb=57b0fc4516249e1aa86169718d148fbf2940dc0c;p=git.git diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c index f974b9df9..e890f7a6d 100644 --- a/builtin-mailinfo.c +++ b/builtin-mailinfo.c @@ -107,7 +107,7 @@ static void handle_from(const struct strbuf *from) el = strcspn(at, " \n\t\r\v\f>"); strbuf_reset(&email); strbuf_add(&email, at, el); - strbuf_remove(&f, at - f.buf, el + 1); + strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0)); /* The remainder is name. It could be "John Doe " * or "john.doe@xz (John Doe)", but we have removed the @@ -175,7 +175,7 @@ static void handle_content_type(struct strbuf *line) message_type = TYPE_OTHER; if (slurp_attr(line->buf, "boundary=", boundary)) { strbuf_insert(boundary, 0, "--", 2); - if (content_top++ >= &content[MAX_BOUNDARIES]) { + if (++content_top > &content[MAX_BOUNDARIES]) { fprintf(stderr, "Too many boundaries to handle\n"); exit(1); } @@ -203,7 +203,8 @@ static void handle_content_transfer_encoding(const struct strbuf *line) static int is_multipart_boundary(const struct strbuf *line) { - return !strbuf_cmp(line, *content_top); + return (((*content_top)->len <= line->len) && + !memcmp(line->buf, (*content_top)->buf, (*content_top)->len)); } static void cleanup_subject(struct strbuf *subject) @@ -602,7 +603,7 @@ static void handle_filter(struct strbuf *line); static int find_boundary(void) { while (!strbuf_getline(&line, fin, '\n')) { - if (is_multipart_boundary(&line)) + if (*content_top && is_multipart_boundary(&line)) return 1; } return 0; @@ -625,7 +626,7 @@ again: /* technically won't happen as is_multipart_boundary() will fail first. But just in case.. */ - if (content_top-- < content) { + if (--content_top < content) { fprintf(stderr, "Detected mismatched boundaries, " "can't recover\n"); exit(1); @@ -649,8 +650,11 @@ again: check_header(&line, p_hdr_data, 0); strbuf_release(&newline); - /* eat the blank line after section info */ - return (strbuf_getline(&line, fin, '\n') == 0); + /* replenish line */ + if (strbuf_getline(&line, fin, '\n')) + return 0; + strbuf_addch(&line, '\n'); + return 1; } static inline int patchbreak(const struct strbuf *line) @@ -757,9 +761,10 @@ static void handle_body(void) /* process any boundary lines */ if (*content_top && is_multipart_boundary(&line)) { /* flush any leftover */ - if (line.len) - handle_filter(&line); - + if (prev.len) { + handle_filter(&prev); + strbuf_reset(&prev); + } if (!handle_boundary()) goto handle_body_out; }