send-email: avoid empty transfer encoding header
authorAaron Lindsay <aaron@aclindsay.com>
Fri, 2 Nov 2018 09:52:38 +0000 (05:52 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Nov 2018 14:59:53 +0000 (23:59 +0900)
Fix a small bug introduced by "7a36987ff (send-email: add an auto option
for transfer encoding, 2018-07-14)".

I saw the following message when setting --transfer-encoding for a file
with the same encoding:

$ git send-email --transfer-encoding=8bit example.patch
Use of uninitialized value $xfer_encoding in concatenation (.) or string
at /usr/lib/git-core/git-send-email line 1744.

The new tests are by brian m. carlson.

Signed-off-by: Aaron Lindsay <aaron@aclindsay.com>
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 f4c07908d2737203031bdcab7f4f30404e64d4e5..6b5d746bdef5a0aaf70a68ee03eb48aaaeefcbbf 100755 (executable)
@@ -1835,7 +1835,7 @@ sub apply_transfer_encoding {
        my $from = shift;
        my $to = shift;
 
-       return $message if ($from eq $to and $from ne '7bit');
+       return ($message, $to) if ($from eq $to and $from ne '7bit');
 
        require MIME::QuotedPrint;
        require MIME::Base64;
index 1da282c415b81215ddb149f6230ff2a5a8eb4c95..8e36a67b3ac5329426da3c093fbf4655b3978bd9 100755 (executable)
@@ -493,6 +493,21 @@ do
                        --validate \
                        $patches longline.patch
        '
+
+done
+
+for enc in 7bit 8bit quoted-printable base64
+do
+       test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
+               clean_fake_sendmail &&
+               git send-email \
+                       --from="Example <nobody@example.com>" \
+                       --to=nobody@example.com \
+                       --smtp-server="$(pwd)/fake.sendmail" \
+                       --transfer-encoding=$enc \
+                       $patches &&
+               grep "Content-Transfer-Encoding: $enc" msgtxt1
+       '
 done
 
 test_expect_success $PREREQ 'Invalid In-Reply-To' '