send-email: Honor multi-part email messages
PATCH 1/1 send-email: Honor multi-part email messages
"git format-patch --attach/--inline" generates multi-part messages. Every part of such messages can contain non-ASCII characters with its own "Content-Type" and "Content-Transfer-Encoding" headers.
But git-send-mail script interprets a patch-file as one-part message and does not recognize multi-part messages.
So already quoted printable email subject may be encoded as quoted printable again. Due to this bug email subject looks corrupted in email clients.
--- git-send-email.perl | 5 +++ t/t9001-send-email.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 0 deletions(-)
git-send-email.perl +5 -0
@@ -1403,12 +1403,17 @@ sub file_has_nonascii { sub body_or_subject_has_nonascii { my $fn = shift; + my $multipart = 0; open(my $fh, '<', $fn) or die "unable to open $fn: $!\n"; while (my $line = <$fh>) { last if $line =~ /^$/; + if ($line =~ /^Content-Type:\s*multipart\/mixed.*$/) { + $multipart = 1; + } return 1 if $line =~ /^Subject.*[^[:ascii:]]/; } + return 0 if $multipart; while (my $line = <$fh>) { return 1 if $line =~ /[^[:ascii:]]/; }
t/t9001-send-email.sh +66 -0
70 lines not on this page · raw message
Signature · 1 line
1.7.6.3.4.gf71f
Quoted 9 lines · Alexey Shumkin
git-send-email.perl +1
-0@@ -1403,12 +1403,17 @@ sub file_has_nonascii { sub body_or_subject_has_nonascii { my $fn = shift; + my $multipart = 0;
git-send-email.perl sub file_has_nonascii { · line 1416
Quoted 10 lines
git-send-email.perl +4
-0open(my $fh, '<', $fn) or die "unable to open $fn: $!\n"; while (my $line = <$fh>) { last if $line =~ /^$/; + if ($line =~ /^Content-Type:\s*multipart\/mixed.*$/) { + $multipart = 1; + } return 1 if $line =~ /^Subject.*[^[:ascii:]]/; } + return 0 if $multipart;
Looks as if you can lose the extra variable and return 0 immediately when you find a line with that Content-Type inside the loop.
What am I missing?
Quoted 17 lines
Quoted 15 lines · Alexey Shumkin
git-send-email.perl +2
-0@@ -1403,12 +1403,17 @@ sub file_has_nonascii { sub body_or_subject_has_nonascii { my $fn = shift; + my $multipart = 0; open(my $fh, '<', $fn) or die "unable to open $fn: $!\n"; while (my $line = <$fh>) { last if $line =~ /^$/; + if ($line =~ /^Content-Type:\s*multipart\/mixed.*$/) {
Quoted 8 lines
git-send-email.perl sub file_has_nonascii { · line 1416
Quoted 5 lines
git-send-email.perl +3
-0+ $multipart = 1; + } return 1 if $line =~ /^Subject.*[^[:ascii:]]/; } + return 0 if $multipart;Looks as if you can lose the extra variable and return 0 immediately when you find a line with that Content-Type inside the loop.
Well, as I understand "current" algorithm:
1. It assumes that file is one-part email message
2. Function searches non-ASCII characters in Subject header
3. If none then it looks non-ASCII characters at message body
my changes are to skip looking at message body of a multi-part message as it has parts with their own Content-Type headers
The said above in details:
1. To set flag when we meet Content-Type: multipart/mixed header
2. After we processed all headers and did not found non-ASCII characters in a Subject we take a look at this flag and exit with 0
if it is a multi-part message
Bump
Quoted 1 line · Alexey Shumkin
Bump
Bump what???
I've meant you did not reply to my last message in this thread
http://thread.gmane.org/gmane.comp.version-control.git/181791
2013/1/24 Junio C Hamano <[email protected]>
Quoted 6 lines
Quoted 1 line · Alexey Shumkin
Bump
Bump what???
Quoted 2 lines · Shumkin Alexey
I've meant you did not reply to my last message in this thread
http://thread.gmane.org/gmane.comp.version-control.git/181791
Please repost the patch (with possible updates) for review when attempting to resurrect an ancient topic, instead of forcing people to hunt for an ancient message.
I think your patch is wrong. What happens when we see a Subject:
line with a non-ascii on it that causes an early return of the loop before your new code has a chance to see Content-Type: header?