git-send-email: delay creation of MIME headers
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Paolo Bonzini committed
Nov 25, 2014 at 15:00 UTC
bb29456c89599acfc3ef3046e6a55ce0f48c9865
1 file changed
+19
-6
git-send-email.perl
+19
-6
@@ -1324,6 +1324,8 @@ foreach my $t (@files) {
1324
my $author_encoding;
1325
my $has_content_type;
1326
my $body_encoding;
1327
+ my $xfer_encoding;
1328
+ my $has_mime_version;
1329
@to = ();
1330
@cc = ();
1331
@xh = ();
@@ -1394,9 +1396,16 @@ foreach my $t (@files) {
1396
}
1397
push @xh, $_;
1398
}
1399
+ elsif (/^MIME-Version/i) {
1400
+ $has_mime_version = 1;
1401
+ push @xh, $_;
1402
+ }
1403
elsif (/^Message-Id: (.*)/i) {
1404
$message_id = $1;
1405
}
1406
+ elsif (/^Content-Transfer-Encoding: (.*)/i) {
1407
+ $xfer_encoding = $1 if not defined $xfer_encoding;
1408
+ }
1409
elsif (!/^Date:\s/i && /^[-A-Za-z]+:\s+\S/) {
1410
push @xh, $_;
1411
}
@@ -1444,10 +1453,9 @@ foreach my $t (@files) {
1453
if defined $cc_cmd && !$suppress_cc{'cccmd'};
1454
1455
if ($broken_encoding{$t} && !$has_content_type) {
1456
+ $xfer_encoding = '8bit' if not defined $xfer_encoding;
1457
$has_content_type = 1;
1448
- push @xh, "MIME-Version: 1.0",
1449
- "Content-Type: text/plain; charset=$auto_8bit_encoding",
1450
- "Content-Transfer-Encoding: 8bit";
1458
+ push @xh, "Content-Type: text/plain; charset=$auto_8bit_encoding";
1459
$body_encoding = $auto_8bit_encoding;
1460
}
1461
@@ -1467,14 +1475,19 @@ foreach my $t (@files) {
1475
}
1476
}
1477
else {
1478
+ $xfer_encoding = '8bit' if not defined $xfer_encoding;
1479
$has_content_type = 1;
1480
push @xh,
1472
- 'MIME-Version: 1.0',
1473
- "Content-Type: text/plain; charset=$author_encoding",
1474
- 'Content-Transfer-Encoding: 8bit';
1481
+ "Content-Type: text/plain; charset=$author_encoding";
1482
}
1483
}
1484
}
1485
+ if (defined $xfer_encoding) {
1486
+ push @xh, "Content-Transfer-Encoding: $xfer_encoding";
1487
+ }
1488
+ if (defined $xfer_encoding or $has_content_type) {
1489
+ unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
1490
+ }
1491
1492
$needs_confirm = (
1493
$confirm eq "always" or