git-send-email: add charset header if we add encoded 'From'
We sometimes pick out the original rfc822 'From' header and include it in the body of the message. If the original author's name needs encoding, then we should specify that in the content-type header. If we already had a content-type header in the mail, then we may need to re-encode. The logic is there to detect this case, but it doesn't actually do the re-encoding. Signed-off-by: Jeff King <peff@peff.net> Acked-by: Uwe Kleine-König <Uwe.Kleine-Koenig@digi.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Nov 16, 2007 at 05:49 UTC
8291db6f584076b60efa47d72c604b1949508ef8
1 file changed
+31
-3
git-send-email.perl
+31
-3
@@ -468,11 +468,13 @@ $time = time - scalar $#files;
468
469
sub unquote_rfc2047 {
470
local ($_) = @_;
471
- if (s/=\?utf-8\?q\?(.*)\?=/$1/g) {
471
+ my $encoding;
472
+ if (s/=\?([^?]+)\?q\?(.*)\?=/$2/g) {
473
+ $encoding = $1;
474
s/_/ /g;
475
s/=([0-9A-F]{2})/chr(hex($1))/eg;
476
}
475
- return "$_";
477
+ return wantarray ? ($_, $encoding) : $_;
478
}
479
480
# use the simplest quoting being able to handle the recipient
@@ -599,6 +601,9 @@ foreach my $t (@files) {
601
open(F,"<",$t) or die "can't open file $t";
602
603
my $author = undef;
604
+ my $author_encoding;
605
+ my $has_content_type;
606
+ my $body_encoding;
607
@cc = @initial_cc;
608
@xh = ();
609
my $input_format = undef;
@@ -624,12 +629,20 @@ foreach my $t (@files) {
629
next if ($suppress_from);
630
}
631
elsif ($1 eq 'From') {
627
- $author = unquote_rfc2047($2);
632
+ ($author, $author_encoding)
633
+ = unquote_rfc2047($2);
634
}
635
printf("(mbox) Adding cc: %s from line '%s'\n",
636
$2, $_) unless $quiet;
637
push @cc, $2;
638
}
639
+ elsif (/^Content-type:/i) {
640
+ $has_content_type = 1;
641
+ if (/charset="?[^ "]+/) {
642
+ $body_encoding = $1;
643
+ }
644
+ push @xh, $_;
645
+ }
646
elsif (!/^Date:\s/ && /^[-A-Za-z]+:\s+\S/) {
647
push @xh, $_;
648
}
@@ -686,6 +699,21 @@ foreach my $t (@files) {
699
700
if (defined $author) {
701
$message = "From: $author\n\n$message";
702
+ if (defined $author_encoding) {
703
+ if ($has_content_type) {
704
+ if ($body_encoding eq $author_encoding) {
705
+ # ok, we already have the right encoding
706
+ }
707
+ else {
708
+ # uh oh, we should re-encode
709
+ }
710
+ }
711
+ else {
712
+ push @xh,
713
+ 'MIME-Version: 1.0',
714
+ "Content-Type: text/plain; charset=$author_encoding";
715
+ }
716
+ }
717
}
718
719
send_message();