send-email: automatically determine transfer-encoding

git send-email, when invoked without a --transfer-encoding option, sends 8bit data without a MIME version or a transfer encoding. This has several downsides. First, unless the transfer encoding is specified, it defaults to 7bit, meaning that non-ASCII data isn't allowed. Second, if lines longer than 998 bytes are used, we will send an message that is invalid according to RFC 5322. The --validate option, which is the default, catches this issue, but it isn't clear to many people how to resolve this. To solve these issues, default the transfer encoding to "auto", so that we explicitly specify 8bit encoding when lines don't exceed 998 bytes and quoted-printable otherwise. This means that we now always emit Content-Transfer-Encoding and MIME-Version headers, so remove the conditionals from this portion of the code. It is unlikely that the unconditional inclusion of these two headers will affect the deliverability of messages in anything but a positive way, since MIME is already widespread and well understood by most email programs. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jul 8, 2018 at 22:17 UTC e67a228cd8afa7a645a321df90393deceaa57a0e
3 files changed +28 -14
Documentation/git-send-email.txt
+1 -2
@@ -147,8 +147,7 @@ Note that no attempts whatsoever are made to validate the encoding.
147 otherwise.
148 +
149 Default is the value of the `sendemail.transferEncoding` configuration
150 -value; if that is unspecified, git will use 8bit and not add a
151 -Content-Transfer-Encoding header.
150 +value; if that is unspecified, default to `auto`.
151
152 --xmailer::
153 --no-xmailer::
git-send-email.perl
+6 -12
@@ -231,7 +231,7 @@ my ($validate, $confirm);
231 my (@suppress_cc);
232 my ($auto_8bit_encoding);
233 my ($compose_encoding);
234 -my ($target_xfer_encoding);
234 +my $target_xfer_encoding = 'auto';
235
236 my ($debug_net_smtp) = 0; # Net::SMTP, see send_message()
237
@@ -1737,17 +1737,11 @@ sub process_file {
1737 }
1738 }
1739 }
1740 - if (defined $target_xfer_encoding) {
1741 - $xfer_encoding = '8bit' if not defined $xfer_encoding;
1742 - ($message, $xfer_encoding) = apply_transfer_encoding(
1743 - $message, $xfer_encoding, $target_xfer_encoding);
1744 - }
1745 - if (defined $xfer_encoding) {
1746 - push @xh, "Content-Transfer-Encoding: $xfer_encoding";
1747 - }
1748 - if (defined $xfer_encoding or $has_content_type) {
1749 - unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
1750 - }
1740 + $xfer_encoding = '8bit' if not defined $xfer_encoding;
1741 + ($message, $xfer_encoding) = apply_transfer_encoding(
1742 + $message, $xfer_encoding, $target_xfer_encoding);
1743 + push @xh, "Content-Transfer-Encoding: $xfer_encoding";
1744 + unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
1745
1746 $needs_confirm = (
1747 $confirm eq "always" or
t/t9001-send-email.sh
+21
@@ -225,6 +225,8 @@ X-Mailer: X-MAILER-STRING
225 In-Reply-To: <unique-message-id@example.com>
226 References: <unique-message-id@example.com>
227 Reply-To: Reply <reply@example.com>
228 +MIME-Version: 1.0
229 +Content-Transfer-Encoding: 8bit
230
231 Result: OK
232 EOF
@@ -415,6 +417,7 @@ test_expect_success $PREREQ 'reject long lines' '
417 --from="Example <nobody@example.com>" \
418 --to=nobody@example.com \
419 --smtp-server="$(pwd)/fake.sendmail" \
420 + --transfer-encoding=8bit \
421 $patches longline.patch \
422 2>errors &&
423 grep longline.patch errors
@@ -609,6 +612,8 @@ Subject: [PATCH 1/1] Second.
612 Date: DATE-STRING
613 Message-Id: MESSAGE-ID-STRING
614 X-Mailer: X-MAILER-STRING
615 +MIME-Version: 1.0
616 +Content-Transfer-Encoding: 8bit
617
618 Result: OK
619 EOF
@@ -653,6 +658,8 @@ Subject: [PATCH 1/1] Second.
658 Date: DATE-STRING
659 Message-Id: MESSAGE-ID-STRING
660 X-Mailer: X-MAILER-STRING
661 +MIME-Version: 1.0
662 +Content-Transfer-Encoding: 8bit
663
664 Result: OK
665 EOF
@@ -688,6 +695,8 @@ Subject: [PATCH 1/1] Second.
695 Date: DATE-STRING
696 Message-Id: MESSAGE-ID-STRING
697 X-Mailer: X-MAILER-STRING
698 +MIME-Version: 1.0
699 +Content-Transfer-Encoding: 8bit
700
701 Result: OK
702 EOF
@@ -714,6 +723,8 @@ Subject: [PATCH 1/1] Second.
723 Date: DATE-STRING
724 Message-Id: MESSAGE-ID-STRING
725 X-Mailer: X-MAILER-STRING
726 +MIME-Version: 1.0
727 +Content-Transfer-Encoding: 8bit
728
729 Result: OK
730 EOF
@@ -748,6 +759,8 @@ Subject: [PATCH 1/1] Second.
759 Date: DATE-STRING
760 Message-Id: MESSAGE-ID-STRING
761 X-Mailer: X-MAILER-STRING
762 +MIME-Version: 1.0
763 +Content-Transfer-Encoding: 8bit
764
765 Result: OK
766 EOF
@@ -779,6 +792,8 @@ Subject: [PATCH 1/1] Second.
792 Date: DATE-STRING
793 Message-Id: MESSAGE-ID-STRING
794 X-Mailer: X-MAILER-STRING
795 +MIME-Version: 1.0
796 +Content-Transfer-Encoding: 8bit
797
798 Result: OK
799 EOF
@@ -810,6 +825,8 @@ Subject: [PATCH 1/1] Second.
825 Date: DATE-STRING
826 Message-Id: MESSAGE-ID-STRING
827 X-Mailer: X-MAILER-STRING
828 +MIME-Version: 1.0
829 +Content-Transfer-Encoding: 8bit
830
831 Result: OK
832 EOF
@@ -845,6 +862,8 @@ Subject: [PATCH 1/1] Second.
862 Date: DATE-STRING
863 Message-Id: MESSAGE-ID-STRING
864 X-Mailer: X-MAILER-STRING
865 +MIME-Version: 1.0
866 +Content-Transfer-Encoding: 8bit
867
868 Result: OK
869 EOF
@@ -873,6 +892,8 @@ Subject: [PATCH 1/1] Second.
892 Date: DATE-STRING
893 Message-Id: MESSAGE-ID-STRING
894 X-Mailer: X-MAILER-STRING
895 +MIME-Version: 1.0
896 +Content-Transfer-Encoding: 8bit
897
898 Result: OK
899 EOF