Skip to content

Commit

Permalink
git-send-email: add charset header if we add encoded 'From'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Nov 17, 2007
1 parent b57321f commit 8291db6
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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, $_;
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8291db6

Please sign in to comment.