From: Jeff King <peff@peff.net>
To: "Uwe Kleine-König" <Uwe.Kleine-Koenig@digi.com>,
"Junio C Hamano" <gitster@pobox.com>
Cc: git@vger.kernel.org, Brian Swetland <swetland@google.com>,
Russell King - ARM Linux <linux@arm.linux.org.uk>,
Nicolas Pitre <nico@cam.org>
Subject: Re: [BUG] encoding problem with format-patch + send-email
Date: Fri, 16 Nov 2007 05:49:09 -0500 [thread overview]
Message-ID: <20071116104907.GA13087@sigill.intra.peff.net> (raw)
In-Reply-To: <20071115105726.GA18555@bre-cln-ukleine.digi.com>
On Thu, Nov 15, 2007 at 11:57:26AM +0100, Uwe Kleine-König wrote:
> send-email adds "From: A. U. Thor <author@tld>" to the body if sender
> and From: in the patch to send differ.
>
> Both is just fine, but if the author has some non-ascii characters in
> her name but the body is ascii-only the resulting mail is broken.
I posted an untested fix to this and discussed the issue in
http://article.gmane.org/gmane.comp.version-control.git/64426
http://article.gmane.org/gmane.comp.version-control.git/64436
but nobody seems to have been interested after that (I don't even use
git-send-email myself).
Below is an updated patch (there was a typo in one of the regexes in the
original) that meets my limited testing for the all-utf8 case (I don't
know how people actually use alternate encodings with git, if at all, so
I don't know that I can put together a good test case). My test case was
something like:
git-clone git test && cd test
echo junk >>Makefile
git-commit -m junk --author 'Uwe Kleine-König <peff@peff.net>' -a
git-format-patch HEAD^
git-send-email 0001-junk.patch
> What about adding the Content-Type and Content-Transfer-Encoding headers
> in any case?
You could probably add them unconditionally, but it would be nice to
have them match the encoding, so you'd still want to pick them out of
the rfc2047 encoding in the from header.
-Peff
-- >8 --
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>
---
git-send-email.perl | 34 +++++++++++++++++++++++++++++++---
1 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index f9bd2e5..fd0a4ad 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -514,11 +514,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
@@ -667,6 +669,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;
@@ -692,12 +697,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, $_;
}
@@ -756,6 +769,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();
--
1.5.3.1.47.g88b7d-dirty
next prev parent reply other threads:[~2007-11-16 10:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-15 10:57 [BUG] encoding problem with format-patch + send-email Uwe Kleine-König
2007-11-16 10:49 ` Jeff King [this message]
2007-11-16 11:14 ` Uwe Kleine-König
2007-11-17 0:48 ` Junio C Hamano
2007-11-19 10:49 ` Uwe Kleine-König
2007-11-19 10:58 ` Brian Swetland
2007-11-20 12:54 ` [PATCH] send-email: add transfer encoding header with content-type Jeff King
2007-11-20 13:49 ` Uwe Kleine-König
2007-11-21 6:58 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071116104907.GA13087@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Uwe.Kleine-Koenig@digi.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=linux@arm.linux.org.uk \
--cc=nico@cam.org \
--cc=swetland@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).