format-patch: make cover letters always text/plain
authorbrian m. carlson <sandals@crustytoothpaste.net>
Wed, 2 May 2018 02:20:52 +0000 (02:20 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 May 2018 03:55:00 +0000 (12:55 +0900)
When formatting a series of patches using --attach and --cover-letter,
the cover letter lacks the closing MIME boundary, violating RFC 2046.
Certain clients, such as Thunderbird, discard the message body in such a
case.

Since the cover letter is just one part and sending it as
multipart/mixed is not very useful, always emit it as text/plain,
avoiding the boundary problem altogether.

Reported-by: Patrick Hemmer <git@stormcloud9.net>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
log-tree.c
log-tree.h
t/t4014-format-patch.sh
index 94ee177d56d6ff9c82b02ebfb2d27cf789527974..dc7f5f4642152a141e43786fe4655256be75fccb 100644 (file)
@@ -1019,7 +1019,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
            open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
                return;
 
-       log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte);
+       log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte, 0);
 
        for (i = 0; !need_8bit_cte && i < nr; i++) {
                const char *buf = get_commit_buffer(list[i], NULL);
index bdf23c5f7b89eda2997057285d1fff64acb0d30c..b00a56f57ee0c91728a5daf218e33da9922527e7 100644 (file)
@@ -362,7 +362,8 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
 
 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
                             const char **extra_headers_p,
-                            int *need_8bit_cte_p)
+                            int *need_8bit_cte_p,
+                            int maybe_multipart)
 {
        const char *extra_headers = opt->extra_headers;
        const char *name = oid_to_hex(opt->zero_commit ?
@@ -385,7 +386,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
                               opt->ref_message_ids->items[i].string);
                graph_show_oneline(opt->graph);
        }
-       if (opt->mime_boundary) {
+       if (opt->mime_boundary && maybe_multipart) {
                static char subject_buffer[1024];
                static char buffer[1024];
                struct strbuf filename =  STRBUF_INIT;
@@ -610,7 +611,7 @@ void show_log(struct rev_info *opt)
 
        if (cmit_fmt_is_mail(opt->commit_format)) {
                log_write_email_headers(opt, commit, &extra_headers,
-                                       &ctx.need_8bit_cte);
+                                       &ctx.need_8bit_cte, 1);
                ctx.rev = opt;
                ctx.print_email_subject = 1;
        } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
index deba035187185bc28a83520b47480c3141d8398e..e66862807463a12e28573be04cbcfcf2d200e6f3 100644 (file)
@@ -27,7 +27,8 @@ void format_decorations_extended(struct strbuf *sb, const struct commit *commit,
 void show_decorations(struct rev_info *opt, struct commit *commit);
 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
                             const char **extra_headers_p,
-                            int *need_8bit_cte_p);
+                            int *need_8bit_cte_p,
+                            int maybe_multipart);
 void load_ref_decorations(struct decoration_filter *filter, int flags);
 
 #define FORMAT_PATCH_NAME_MAX 64
index 482112ca339f05fc31e6f9c2c6168971a1121e87..6ea08fd5e9c21bc1efe9726c8745dd1397c3ddab 100755 (executable)
@@ -1661,6 +1661,15 @@ test_expect_success 'format-patch --base with --attach' '
        test_write_lines 1 2 >expect &&
        test_cmp expect actual
 '
+test_expect_success 'format-patch --attach cover-letter only is non-multipart' '
+       test_when_finished "rm -fr patches" &&
+       git format-patch -o patches --cover-letter --attach=mimemime --base=HEAD~ -1 &&
+       ! egrep "^--+mimemime" patches/0000*.patch &&
+       egrep "^--+mimemime$" patches/0001*.patch >output &&
+       test_line_count = 2 output &&
+       egrep "^--+mimemime--$" patches/0001*.patch >output &&
+       test_line_count = 1 output
+'
 
 test_expect_success 'format-patch --pretty=mboxrd' '
        sp=" " &&