Skip to content

Commit 7a36987

Browse files
bk2204gitster
authored andcommitted
send-email: add an auto option for transfer encoding
For most patches, using a transfer encoding of 8bit provides good compatibility with most servers and makes it as easy as possible to view patches. However, there are some patches for which 8bit is not a valid encoding: RFC 5322 specifies that a message must not have lines exceeding 998 octets. Add a transfer encoding value, auto, which indicates that a patch should use 8bit where allowed and quoted-printable otherwise. Choose quoted-printable instead of base64, since base64-encoded plain text is treated as suspicious by some spam filters. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53f9a3e commit 7a36987

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

Documentation/git-send-email.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,18 @@ Note that no attempts whatsoever are made to validate the encoding.
137137
Specify encoding of compose message. Default is the value of the
138138
'sendemail.composeencoding'; if that is unspecified, UTF-8 is assumed.
139139

140-
--transfer-encoding=(7bit|8bit|quoted-printable|base64)::
140+
--transfer-encoding=(7bit|8bit|quoted-printable|base64|auto)::
141141
Specify the transfer encoding to be used to send the message over SMTP.
142142
7bit will fail upon encountering a non-ASCII message. quoted-printable
143143
can be useful when the repository contains files that contain carriage
144144
returns, but makes the raw patch email file (as saved from a MUA) much
145145
harder to inspect manually. base64 is even more fool proof, but also
146-
even more opaque. Default is the value of the `sendemail.transferEncoding`
147-
configuration value; if that is unspecified, git will use 8bit and not
148-
add a Content-Transfer-Encoding header.
146+
even more opaque. auto will use 8bit when possible, and quoted-printable
147+
otherwise.
148+
+
149+
Default is the value of the `sendemail.transferEncoding` configuration
150+
value; if that is unspecified, git will use 8bit and not add a
151+
Content-Transfer-Encoding header.
149152

150153
--xmailer::
151154
--no-xmailer::

git-send-email.perl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,9 +1739,8 @@ sub process_file {
17391739
}
17401740
if (defined $target_xfer_encoding) {
17411741
$xfer_encoding = '8bit' if not defined $xfer_encoding;
1742-
$message = apply_transfer_encoding(
1742+
($message, $xfer_encoding) = apply_transfer_encoding(
17431743
$message, $xfer_encoding, $target_xfer_encoding);
1744-
$xfer_encoding = $target_xfer_encoding;
17451744
}
17461745
if (defined $xfer_encoding) {
17471746
push @xh, "Content-Transfer-Encoding: $xfer_encoding";
@@ -1852,13 +1851,16 @@ sub apply_transfer_encoding {
18521851
$message = MIME::Base64::decode($message)
18531852
if ($from eq 'base64');
18541853

1854+
$to = ($message =~ /.{999,}/) ? 'quoted-printable' : '8bit'
1855+
if $to eq 'auto';
1856+
18551857
die __("cannot send message as 7bit")
18561858
if ($to eq '7bit' and $message =~ /[^[:ascii:]]/);
1857-
return $message
1859+
return ($message, $to)
18581860
if ($to eq '7bit' or $to eq '8bit');
1859-
return MIME::QuotedPrint::encode($message, "\n", 0)
1861+
return (MIME::QuotedPrint::encode($message, "\n", 0), $to)
18601862
if ($to eq 'quoted-printable');
1861-
return MIME::Base64::encode($message, "\n")
1863+
return (MIME::Base64::encode($message, "\n"), $to)
18621864
if ($to eq 'base64');
18631865
die __("invalid transfer encoding");
18641866
}

t/t9001-send-email.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,29 @@ test_expect_success $PREREQ 'allow long lines with --no-validate' '
456456
2>errors
457457
'
458458

459+
test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
460+
clean_fake_sendmail &&
461+
git send-email \
462+
--from="A <[email protected]>" \
463+
464+
--smtp-server="$(pwd)/fake.sendmail" \
465+
--transfer-encoding=auto \
466+
$patches &&
467+
grep "Content-Transfer-Encoding: 8bit" msgtxt1
468+
'
469+
470+
test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
471+
clean_fake_sendmail &&
472+
git send-email \
473+
--from="Example <[email protected]>" \
474+
475+
--smtp-server="$(pwd)/fake.sendmail" \
476+
--transfer-encoding=auto \
477+
--no-validate \
478+
longline.patch &&
479+
grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
480+
'
481+
459482
test_expect_success $PREREQ 'Invalid In-Reply-To' '
460483
clean_fake_sendmail &&
461484
git send-email \

0 commit comments

Comments
 (0)