Skip to content

Commit bb29456

Browse files
bonzinigitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 652e759 commit bb29456

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

git-send-email.perl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,8 @@ sub send_message {
13241324
my $author_encoding;
13251325
my $has_content_type;
13261326
my $body_encoding;
1327+
my $xfer_encoding;
1328+
my $has_mime_version;
13271329
@to = ();
13281330
@cc = ();
13291331
@xh = ();
@@ -1394,9 +1396,16 @@ sub send_message {
13941396
}
13951397
push @xh, $_;
13961398
}
1399+
elsif (/^MIME-Version/i) {
1400+
$has_mime_version = 1;
1401+
push @xh, $_;
1402+
}
13971403
elsif (/^Message-Id: (.*)/i) {
13981404
$message_id = $1;
13991405
}
1406+
elsif (/^Content-Transfer-Encoding: (.*)/i) {
1407+
$xfer_encoding = $1 if not defined $xfer_encoding;
1408+
}
14001409
elsif (!/^Date:\s/i && /^[-A-Za-z]+:\s+\S/) {
14011410
push @xh, $_;
14021411
}
@@ -1444,10 +1453,9 @@ sub send_message {
14441453
if defined $cc_cmd && !$suppress_cc{'cccmd'};
14451454

14461455
if ($broken_encoding{$t} && !$has_content_type) {
1456+
$xfer_encoding = '8bit' if not defined $xfer_encoding;
14471457
$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";
14511459
$body_encoding = $auto_8bit_encoding;
14521460
}
14531461

@@ -1467,14 +1475,19 @@ sub send_message {
14671475
}
14681476
}
14691477
else {
1478+
$xfer_encoding = '8bit' if not defined $xfer_encoding;
14701479
$has_content_type = 1;
14711480
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";
14751482
}
14761483
}
14771484
}
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+
}
14781491

14791492
$needs_confirm = (
14801493
$confirm eq "always" or

0 commit comments

Comments
 (0)