Skip to content

Commit e67a228

Browse files
bk2204gitster
authored andcommittedJul 9, 2018
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2d06fb commit e67a228

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed
 

‎Documentation/git-send-email.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ Note that no attempts whatsoever are made to validate the encoding.
147147
otherwise.
148148
+
149149
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`.
152151

153152
--xmailer::
154153
--no-xmailer::

‎git-send-email.perl

+6-12
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ sub do_edit {
231231
my (@suppress_cc);
232232
my ($auto_8bit_encoding);
233233
my ($compose_encoding);
234-
my ($target_xfer_encoding);
234+
my $target_xfer_encoding = 'auto';
235235

236236
my ($debug_net_smtp) = 0; # Net::SMTP, see send_message()
237237

@@ -1737,17 +1737,11 @@ sub process_file {
17371737
}
17381738
}
17391739
}
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;
17511745

17521746
$needs_confirm = (
17531747
$confirm eq "always" or

‎t/t9001-send-email.sh

+21
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ X-Mailer: X-MAILER-STRING
225225
In-Reply-To: <unique-message-id@example.com>
226226
References: <unique-message-id@example.com>
227227
Reply-To: Reply <reply@example.com>
228+
MIME-Version: 1.0
229+
Content-Transfer-Encoding: 8bit
228230
229231
Result: OK
230232
EOF
@@ -415,6 +417,7 @@ test_expect_success $PREREQ 'reject long lines' '
415417
--from="Example <nobody@example.com>" \
416418
--to=nobody@example.com \
417419
--smtp-server="$(pwd)/fake.sendmail" \
420+
--transfer-encoding=8bit \
418421
$patches longline.patch \
419422
2>errors &&
420423
grep longline.patch errors
@@ -609,6 +612,8 @@ Subject: [PATCH 1/1] Second.
609612
Date: DATE-STRING
610613
Message-Id: MESSAGE-ID-STRING
611614
X-Mailer: X-MAILER-STRING
615+
MIME-Version: 1.0
616+
Content-Transfer-Encoding: 8bit
612617
613618
Result: OK
614619
EOF
@@ -653,6 +658,8 @@ Subject: [PATCH 1/1] Second.
653658
Date: DATE-STRING
654659
Message-Id: MESSAGE-ID-STRING
655660
X-Mailer: X-MAILER-STRING
661+
MIME-Version: 1.0
662+
Content-Transfer-Encoding: 8bit
656663
657664
Result: OK
658665
EOF
@@ -688,6 +695,8 @@ Subject: [PATCH 1/1] Second.
688695
Date: DATE-STRING
689696
Message-Id: MESSAGE-ID-STRING
690697
X-Mailer: X-MAILER-STRING
698+
MIME-Version: 1.0
699+
Content-Transfer-Encoding: 8bit
691700
692701
Result: OK
693702
EOF
@@ -714,6 +723,8 @@ Subject: [PATCH 1/1] Second.
714723
Date: DATE-STRING
715724
Message-Id: MESSAGE-ID-STRING
716725
X-Mailer: X-MAILER-STRING
726+
MIME-Version: 1.0
727+
Content-Transfer-Encoding: 8bit
717728
718729
Result: OK
719730
EOF
@@ -748,6 +759,8 @@ Subject: [PATCH 1/1] Second.
748759
Date: DATE-STRING
749760
Message-Id: MESSAGE-ID-STRING
750761
X-Mailer: X-MAILER-STRING
762+
MIME-Version: 1.0
763+
Content-Transfer-Encoding: 8bit
751764
752765
Result: OK
753766
EOF
@@ -779,6 +792,8 @@ Subject: [PATCH 1/1] Second.
779792
Date: DATE-STRING
780793
Message-Id: MESSAGE-ID-STRING
781794
X-Mailer: X-MAILER-STRING
795+
MIME-Version: 1.0
796+
Content-Transfer-Encoding: 8bit
782797
783798
Result: OK
784799
EOF
@@ -810,6 +825,8 @@ Subject: [PATCH 1/1] Second.
810825
Date: DATE-STRING
811826
Message-Id: MESSAGE-ID-STRING
812827
X-Mailer: X-MAILER-STRING
828+
MIME-Version: 1.0
829+
Content-Transfer-Encoding: 8bit
813830
814831
Result: OK
815832
EOF
@@ -845,6 +862,8 @@ Subject: [PATCH 1/1] Second.
845862
Date: DATE-STRING
846863
Message-Id: MESSAGE-ID-STRING
847864
X-Mailer: X-MAILER-STRING
865+
MIME-Version: 1.0
866+
Content-Transfer-Encoding: 8bit
848867
849868
Result: OK
850869
EOF
@@ -873,6 +892,8 @@ Subject: [PATCH 1/1] Second.
873892
Date: DATE-STRING
874893
Message-Id: MESSAGE-ID-STRING
875894
X-Mailer: X-MAILER-STRING
895+
MIME-Version: 1.0
896+
Content-Transfer-Encoding: 8bit
876897
877898
Result: OK
878899
EOF

0 commit comments

Comments
 (0)
Please sign in to comment.