mailinfo: don't require "text" mime type for attachments

Currently "git am" does insane things if the mbox it is given contains attachments with a MIME type that aren't "text/*". In particular, it will still decode them, and pass them "one line at a time" to the mail body filter, but because it has determined that they aren't text (without actually looking at the contents, just at the mime type) the "line" will be the encoding line (eg 'base64') rather than a line of *content*. Which then will cause the text filtering to fail, because we won't correctly notice when the attachment text switches from the commit message to the actual patch. Resulting in a patch failure, even if patch may be a perfectly well-formed attachment, it's just that the message type may be (for example) "application/octet-stream" instead of "text/plain". Just remove all the bogus games with the message_type. The only difference that code creates is how the data is passed to the filter function (chunked per-pred-code line or per post-decode line), and that difference is *wrong*, since chunking things per pre-decode line can never be a sensible operation, and cannot possibly matter for binary data anyway. This code goes all the way back to March of 2007, in commit 87ab79923463 ("builtin-mailinfo.c infrastrcture changes"), and apparently Don used to pass random mbox contents to git. However, the pre-decode vs post-decode logic really shouldn't matter even for that case, and more importantly, "I fed git am crap" is not a valid reason to break *real* patch attachments. If somebody really cares, and determines that some attachment is binary data (by looking at the data, not the MIME-type), the whole attachment should be dismissed, rather than fed in random-sized chunks to "handle_filter()". Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Don Zickus <dzickus@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Sep 30, 2012 at 15:10 UTC 9d55b2e12f82b344709b0f2981eaf142b0b1f7a8
1 file changed -11
builtin/mailinfo.c
-11
@@ -19,9 +19,6 @@ static struct strbuf email = STRBUF_INIT;
19 static enum {
20 TE_DONTCARE, TE_QP, TE_BASE64
21 } transfer_encoding;
22 -static enum {
23 - TYPE_TEXT, TYPE_OTHER
24 -} message_type;
22
23 static struct strbuf charset = STRBUF_INIT;
24 static int patch_lines;
@@ -185,8 +182,6 @@ static void handle_content_type(struct strbuf *line)
182 struct strbuf *boundary = xmalloc(sizeof(struct strbuf));
183 strbuf_init(boundary, line->len);
184
188 - if (!strcasestr(line->buf, "text/"))
189 - message_type = TYPE_OTHER;
185 if (slurp_attr(line->buf, "boundary=", boundary)) {
186 strbuf_insert(boundary, 0, "--", 2);
187 if (++content_top > &content[MAX_BOUNDARIES]) {
@@ -671,7 +666,6 @@ again:
666 /* set some defaults */
667 transfer_encoding = TE_DONTCARE;
668 strbuf_reset(&charset);
674 - message_type = TYPE_TEXT;
669
670 /* slurp in this section's info */
671 while (read_one_header_line(&line, fin))
@@ -885,11 +879,6 @@ static void handle_body(void)
879 strbuf_insert(&line, 0, prev.buf, prev.len);
880 strbuf_reset(&prev);
881
888 - /* binary data most likely doesn't have newlines */
889 - if (message_type != TYPE_TEXT) {
890 - handle_filter(&line);
891 - break;
892 - }
882 /*
883 * This is a decoded line that may contain
884 * multiple new lines. Pass only one chunk