Skip to content

Commit 74d76a1

Browse files
bk2204gitster
authored andcommitted
send-email: default to quoted-printable when CR is present
In 7a36987 ("send-email: add an auto option for transfer encoding", 2018-07-08), git send-email learned how to automatically determine the transfer encoding for a patch. However, the only criterion considered was the length of the lines. Another case we need to consider is that of carriage returns. Because emails have CRLF endings when canonicalized, we don't want to write raw carriage returns into a patch, lest they be stripped off as an artifact of the transport. Ensure that we choose quoted-printable encoding if the patch we're sending contains carriage returns. Note that we are guaranteed to always correctly encode carriage returns when writing quoted-printable since we explicitly specify the line ending as "\n", forcing MIME::QuotedPrint to encode our carriage return as "=0D". Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb582a commit 74d76a1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

git-send-email.perl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ sub apply_transfer_encoding {
18661866
$message = MIME::Base64::decode($message)
18671867
if ($from eq 'base64');
18681868

1869-
$to = ($message =~ /.{999,}/) ? 'quoted-printable' : '8bit'
1869+
$to = ($message =~ /(?:.{999,}|\r)/) ? 'quoted-printable' : '8bit'
18701870
if $to eq 'auto';
18711871

18721872
die __("cannot send message as 7bit")

t/t9001-send-email.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,20 @@ test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable'
481481
grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
482482
'
483483

484+
test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
485+
clean_fake_sendmail &&
486+
cp $patches cr.patch &&
487+
printf "this is a line\r\n" >>cr.patch &&
488+
git send-email \
489+
--from="Example <[email protected]>" \
490+
491+
--smtp-server="$(pwd)/fake.sendmail" \
492+
--transfer-encoding=auto \
493+
--no-validate \
494+
cr.patch &&
495+
grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
496+
'
497+
484498
for enc in auto quoted-printable base64
485499
do
486500
test_expect_success $PREREQ "--validate passes with encoding $enc" '

0 commit comments

Comments
 (0)