send-email: rfc2047-quote subject lines with non-ascii characters
We always use 'utf-8' as the encoding, since we currently have no way of getting the information from the user. This also refactors the quoting of recipient names, since both processes can share the rfc2047 quoting code. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Mar 28, 2008 at 17:29 UTC
d54eaaa268eb79a51ac11bfa8bbfb456c0b1a1fa
2 files changed
+32
-2
git-send-email.perl
+17
-2
@@ -534,6 +534,14 @@ EOT
534
if (!$in_body && /^MIME-Version:/i) {
535
$need_8bit_cte = 0;
536
}
537
+ if (!$in_body && /^Subject: ?(.*)/i) {
538
+ my $subject = $1;
539
+ $_ = "Subject: " .
540
+ ($subject =~ /[^[:ascii:]]/ ?
541
+ quote_rfc2047($subject) :
542
+ $subject) .
543
+ "\n";
544
+ }
545
print C2 $_;
546
}
547
close(C);
@@ -624,6 +632,14 @@ sub unquote_rfc2047 {
632
return wantarray ? ($_, $encoding) : $_;
633
}
634
635
+sub quote_rfc2047 {
636
+ local $_ = shift;
637
+ my $encoding = shift || 'utf-8';
638
+ s/([^-a-zA-Z0-9!*+\/])/sprintf("=%02X", ord($1))/eg;
639
+ s/(.*)/=\?$encoding\?q\?$1\?=/;
640
+ return $_;
641
+}
642
+
643
# use the simplest quoting being able to handle the recipient
644
sub sanitize_address
645
{
@@ -641,8 +657,7 @@ sub sanitize_address
657
658
# rfc2047 is needed if a non-ascii char is included
659
if ($recipient_name =~ /[^[:ascii:]]/) {
644
- $recipient_name =~ s/([^-a-zA-Z0-9!*+\/])/sprintf("=%02X", ord($1))/eg;
645
- $recipient_name =~ s/(.*)/=\?utf-8\?q\?$1\?=/;
660
+ $recipient_name = quote_rfc2047($recipient_name);
661
}
662
663
# double quotes are needed if specials or CTLs are included
t/t9001-send-email.sh
+15
@@ -210,4 +210,19 @@ test_expect_success '--compose respects user mime type' '
210
! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
211
'
212
213
+test_expect_success '--compose adds MIME for utf8 subject' '
214
+ clean_fake_sendmail &&
215
+ echo y | \
216
+ GIT_EDITOR=$(pwd)/fake-editor \
217
+ GIT_SEND_EMAIL_NOTTY=1 \
218
+ git send-email \
219
+ --compose --subject utf8-sübjëct \
220
+ --from="Example <nobody@example.com>" \
221
+ --to=nobody@example.com \
222
+ --smtp-server="$(pwd)/fake.sendmail" \
223
+ $patches &&
224
+ grep "^fake edit" msgtxt1 &&
225
+ grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
226
+'
227
+
228
test_done