git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: `git-send-email' doesn't specify `Content-Type'

From
Jeff King <peff@peff.net>
Date
Nov 11, 2007, 08:56 UTC
Message-ID
<20071111085605.GE30299@sigill.intra.peff.net>
In-Reply-To
<20071111083224.GA30299@sigill.intra.peff.net>
On Sun, Nov 11, 2007 at 03:32:24AM -0500, Jeff King wrote:
> came out of git-format-patch with default-ish settings). So the easy,
> hackish way is probably to just add the MIME-Version and 'Content-type:
> text/plain; charset=utf-8' headers if we unquoted the author field.

Here is the quick and dirty patch. It is totally untested (as in, I didn't even run git-send-email once), but maybe it can get somebody started (I left some comments about how to make it less quick and dirty). My head is going to explode if I read any more of the ad-hoc header parsing in git-send-email.perl.

-Peff
---
diff --git a/git-send-email.perl b/git-send-email.perl
index f9bd2e5..4a071f2 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();
Previous: Jeff King
Message 13 of 13 in “`git-send-email' doesn't specify `Content-Type'”
  1. Ludovic CourtèsNov 10, 2007
  2. Johannes SchindelinNov 10, 2007
  3. Brian SwetlandNov 10, 2007
  4. Björn SteinbrinkNov 10, 2007
  5. Brian SwetlandNov 10, 2007
  6. Björn SteinbrinkNov 10, 2007
  7. Jeff KingNov 11, 2007
  8. Jeff KingNov 11, 2007
  9. Brian SwetlandNov 11, 2007
  10. Jeff KingNov 11, 2007
  11. Brian SwetlandNov 11, 2007
  12. Jeff KingNov 11, 2007
  13. Jeff KingNov 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.