git-send-email: use compose-encoding for Subject

The commit "git-send-email: introduce compose-encoding" introduced the compose-encoding option to specify the introduction email encoding (--compose option), but the email Subject encoding was still hardcoded to UTF-8. Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net> Signed-off-by: Jeff King <peff@peff.net>

Krzysztof Mazur committed Oct 22, 2012 at 14:41 UTC 4a47a4ddec0d4d37e81ad63385ca287abfe90f9b
2 files changed +18 -4
git-send-email.perl
+4 -4
@@ -636,15 +636,15 @@ EOT
636 my $need_8bit_cte = file_has_nonascii($compose_filename);
637 my $in_body = 0;
638 my $summary_empty = 1;
639 + if (!defined $compose_encoding) {
640 + $compose_encoding = "UTF-8";
641 + }
642 while(<$c>) {
643 next if m/^GIT:/;
644 if ($in_body) {
645 $summary_empty = 0 unless (/^\n$/);
646 } elsif (/^\n$/) {
647 $in_body = 1;
645 - if (!defined $compose_encoding) {
646 - $compose_encoding = "UTF-8";
647 - }
648 if ($need_8bit_cte) {
649 print $c2 "MIME-Version: 1.0\n",
650 "Content-Type: text/plain; ",
@@ -658,7 +658,7 @@ EOT
658 my $subject = $initial_subject;
659 $_ = "Subject: " .
660 ($subject =~ /[^[:ascii:]]/ ?
661 - quote_rfc2047($subject) :
661 + quote_rfc2047($subject, $compose_encoding) :
662 $subject) .
663 "\n";
664 } elsif (/^In-Reply-To:\s*(.+)\s*$/i) {
t/t9001-send-email.sh
+14
@@ -909,6 +909,20 @@ test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencod
909 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
910 '
911
912 +test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
913 + clean_fake_sendmail &&
914 + GIT_EDITOR="\"$(pwd)/fake-editor\"" \
915 + git send-email \
916 + --compose-encoding iso-8859-2 \
917 + --compose --subject utf8-sübjëct \
918 + --from="Example <nobody@example.com>" \
919 + --to=nobody@example.com \
920 + --smtp-server="$(pwd)/fake.sendmail" \
921 + $patches &&
922 + grep "^fake edit" msgtxt1 &&
923 + grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
924 +'
925 +
926 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
927 echo master > master &&
928 git add master &&