1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-05 10:36:11 +02:00

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:
Jeff King 2007-11-16 05:49:09 -05:00 committed by Junio C Hamano
parent b57321f57b
commit 8291db6f58

View File

@ -468,11 +468,13 @@ sub make_message_id
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 @@ sub send_message
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 @@ sub send_message
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 @@ sub send_message
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();