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

[PATCH 1/2] git-send-email: delay creation of MIME headers

From
Paolo Bonzini <bonzini@gnu.org>
Date
Nov 25, 2014, 14:00 UTC
Message-ID
<1416924027-29862-2-git-send-email-bonzini@gnu.org>
In-Reply-To
<1416924027-29862-1-git-send-email-bonzini@gnu.org>
From: Paolo Bonzini <pbonzini@redhat.com>

After the next patch, git-send-email will sometimes modify existing Content-Transfer-Encoding headers. Delay the addition of the header to @xh until just before sending. Do the same for MIME-Version, to avoid adding it twice.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 git-send-email.perl | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index 9949db0..b29a304 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1324,6 +1324,8 @@ foreach my $t (@files) {
 	my $author_encoding;
 	my $has_content_type;
 	my $body_encoding;
+	my $xfer_encoding;
+	my $has_mime_version;
 	@to = ();
 	@cc = ();
 	@xh = ();
@@ -1394,9 +1396,16 @@ foreach my $t (@files) {
 				}
 				push @xh, $_;
 			}
+			elsif (/^MIME-Version/i) {
+				$has_mime_version = 1;
+				push @xh, $_;
+			}
 			elsif (/^Message-Id: (.*)/i) {
 				$message_id = $1;
 			}
+			elsif (/^Content-Transfer-Encoding: (.*)/i) {
+				$xfer_encoding = $1 if not defined $xfer_encoding;
+			}
 			elsif (!/^Date:\s/i && /^[-A-Za-z]+:\s+\S/) {
 				push @xh, $_;
 			}
@@ -1444,10 +1453,9 @@ foreach my $t (@files) {
 		if defined $cc_cmd && !$suppress_cc{'cccmd'};
 
 	if ($broken_encoding{$t} && !$has_content_type) {
+		$xfer_encoding = '8bit' if not defined $xfer_encoding;
 		$has_content_type = 1;
-		push @xh, "MIME-Version: 1.0",
-			"Content-Type: text/plain; charset=$auto_8bit_encoding",
-			"Content-Transfer-Encoding: 8bit";
+		push @xh, "Content-Type: text/plain; charset=$auto_8bit_encoding";
 		$body_encoding = $auto_8bit_encoding;
 	}
 
@@ -1467,14 +1475,19 @@ foreach my $t (@files) {
 				}
 			}
 			else {
+				$xfer_encoding = '8bit' if not defined $xfer_encoding;
 				$has_content_type = 1;
 				push @xh,
-				  'MIME-Version: 1.0',
-				  "Content-Type: text/plain; charset=$author_encoding",
-				  'Content-Transfer-Encoding: 8bit';
+				  "Content-Type: text/plain; charset=$author_encoding";
 			}
 		}
 	}
+	if (defined $xfer_encoding) {
+		push @xh, "Content-Transfer-Encoding: $xfer_encoding";
+	}
+	if (defined $xfer_encoding or $has_content_type) {
+		unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
+	}
 
 	$needs_confirm = (
 		$confirm eq "always" or
-- 
2.1.0
Previous: Paolo BonziniNext: Paolo Bonzini
Message 2 of 5 in “git-send-email: add --transfer-encoding option for conversion to specified encoding”
  1. 0/2 git-send-email: add --transfer-encoding option for conversion to specified encodingPaolo Bonzini, Nov 25, 2014
  2. 1/2 git-send-email: delay creation of MIME headersPaolo Bonzini, Nov 25, 2014
  3. 2/2 git-send-email: add --transfer-encoding optionPaolo Bonzini, Nov 25, 2014
  4. Eric SunshineNov 25, 2014
  5. Junio C HamanoNov 25, 2014

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.