]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-email: default to quoted-printable when CR is present
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sat, 13 Apr 2019 22:45:51 +0000 (22:45 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 14 Apr 2019 02:47:03 +0000 (11:47 +0900)
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>
git-send-email.perl
t/t9001-send-email.sh

index 8eb63b5a2f8d07038f6c8ef645a483cd77ffd99f..3f66e1cdc216dec39ff52bef2e2520ea8b2959e2 100755 (executable)
@@ -1866,7 +1866,7 @@ sub apply_transfer_encoding {
        $message = MIME::Base64::decode($message)
                if ($from eq 'base64');
 
-       $to = ($message =~ /.{999,}/) ? 'quoted-printable' : '8bit'
+       $to = ($message =~ /(?:.{999,}|\r)/) ? 'quoted-printable' : '8bit'
                if $to eq 'auto';
 
        die __("cannot send message as 7bit")
index ee1efcc59dcddfdb7e1b448999531e2c1937444a..1e3ac3c3846342ac84baa096ab00ed602e4cdf27 100755 (executable)
@@ -481,6 +481,20 @@ test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable'
        grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
 '
 
+test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
+       clean_fake_sendmail &&
+       cp $patches cr.patch &&
+       printf "this is a line\r\n" >>cr.patch &&
+       git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               --transfer-encoding=auto \
+               --no-validate \
+               cr.patch &&
+       grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
+'
+
 for enc in auto quoted-printable base64
 do
        test_expect_success $PREREQ "--validate passes with encoding $enc" '