зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
b57321f57b
Коммит
8291db6f58
|
@ -468,11 +468,13 @@ $time = time - scalar $#files;
|
|||
|
||||
sub unquote_rfc2047 {
|
||||
local ($_) = @_;
|
||||
if (s/=\?utf-8\?q\?(.*)\?=/$1/g) {
|
||||
my $encoding;
|
||||
if (s/=\?([^?]+)\?q\?(.*)\?=/$2/g) {
|
||||
$encoding = $1;
|
||||
s/_/ /g;
|
||||
s/=([0-9A-F]{2})/chr(hex($1))/eg;
|
||||
}
|
||||
return "$_";
|
||||
return wantarray ? ($_, $encoding) : $_;
|
||||
}
|
||||
|
||||
# use the simplest quoting being able to handle the recipient
|
||||
|
@ -599,6 +601,9 @@ foreach my $t (@files) {
|
|||
open(F,"<",$t) or die "can't open file $t";
|
||||
|
||||
my $author = undef;
|
||||
my $author_encoding;
|
||||
my $has_content_type;
|
||||
my $body_encoding;
|
||||
@cc = @initial_cc;
|
||||
@xh = ();
|
||||
my $input_format = undef;
|
||||
|
@ -624,12 +629,20 @@ foreach my $t (@files) {
|
|||
next if ($suppress_from);
|
||||
}
|
||||
elsif ($1 eq 'From') {
|
||||
$author = unquote_rfc2047($2);
|
||||
($author, $author_encoding)
|
||||
= unquote_rfc2047($2);
|
||||
}
|
||||
printf("(mbox) Adding cc: %s from line '%s'\n",
|
||||
$2, $_) unless $quiet;
|
||||
push @cc, $2;
|
||||
}
|
||||
elsif (/^Content-type:/i) {
|
||||
$has_content_type = 1;
|
||||
if (/charset="?[^ "]+/) {
|
||||
$body_encoding = $1;
|
||||
}
|
||||
push @xh, $_;
|
||||
}
|
||||
elsif (!/^Date:\s/ && /^[-A-Za-z]+:\s+\S/) {
|
||||
push @xh, $_;
|
||||
}
|
||||
|
@ -686,6 +699,21 @@ foreach my $t (@files) {
|
|||
|
||||
if (defined $author) {
|
||||
$message = "From: $author\n\n$message";
|
||||
if (defined $author_encoding) {
|
||||
if ($has_content_type) {
|
||||
if ($body_encoding eq $author_encoding) {
|
||||
# ok, we already have the right encoding
|
||||
}
|
||||
else {
|
||||
# uh oh, we should re-encode
|
||||
}
|
||||
}
|
||||
else {
|
||||
push @xh,
|
||||
'MIME-Version: 1.0',
|
||||
"Content-Type: text/plain; charset=$author_encoding";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
send_message();
|
||||
|
|
Загрузка…
Ссылка в новой задаче