send-email: default to quoted-printable when CR is present

In 7a36987fff ("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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Apr 13, 2019 at 22:45 UTC 74d76a17013411d72ebda7c230b9898f3adb1fcc
2 files changed +15 -1
git-send-email.perl
+1 -1
@@ -1866,7 +1866,7 @@ sub apply_transfer_encoding {
1866 $message = MIME::Base64::decode($message)
1867 if ($from eq 'base64');
1868
1869 - $to = ($message =~ /.{999,}/) ? 'quoted-printable' : '8bit'
1869 + $to = ($message =~ /(?:.{999,}|\r)/) ? 'quoted-printable' : '8bit'
1870 if $to eq 'auto';
1871
1872 die __("cannot send message as 7bit")
t/t9001-send-email.sh
+14
@@ -481,6 +481,20 @@ test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable'
481 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
482 '
483
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 <nobody@example.com>" \
490 + --to=nobody@example.com \
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 +
498 for enc in auto quoted-printable base64
499 do
500 test_expect_success $PREREQ "--validate passes with encoding $enc" '