threads / patch / 50914

patchsend-email: default to quoted-printable when CR is present

Subject: [PATCH] send-email: default to quoted-printable when CR is present

## tl;dr

4 messages between Apr 10, 2019 and Apr 13, 2019. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

brian m. carlson· Apr 10, 2019, 23:34 UTC · lore

In 7a36987fff ("send-email: add an auto option for transfer encoding", 2018-07-08), git send-email learned how to automatically determine the transfer encoding for a patch. However, the only criterion considered was the length of the lines.

Another case we need to consider is that of carriage returns. Because emails have CRLF endings when canonicalized, we don't want to write raw carriage returns into a patch, lest they be stripped off as an artifact of the transport. Ensure that we choose quoted-printable encoding if the patch we're sending contains carriage returns.

Note that we are guaranteed to always correctly encode carriage returns when writing quoted-printable since we explicitly specify the line ending as "\n", forcing MIME::QuotedPrint to encode our carriage return as "=OD".

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 git-send-email.perl   |  2 +-
 t/t9001-send-email.sh | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
Show changes to 2 files +15 −1

git-send-email.perl, t/t9001-send-email.sh

diff --git a/git-send-email.perl b/git-send-email.perl
index 8200d58cdc..751cabf479 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1872,7 +1872,7 @@ sub apply_transfer_encoding {
 	$message = MIME::Base64::decode($message)
 		if ($from eq 'base64');
 
-	$to = ($message =~ /.{999,}/) ? 'quoted-printable' : '8bit'
+	$to = ($message =~ /(?:.{999,}|\r)/) ? 'quoted-printable' : '8bit'
 		if $to eq 'auto';
 
 	die __("cannot send message as 7bit")
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index ee1efcc59d..1e3ac3c384 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -481,6 +481,20 @@ test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable'
 	grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
 '
 
+test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
+	clean_fake_sendmail &&
+	cp $patches cr.patch &&
+	printf "this is a line\r\n" >>cr.patch &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--to=nobody@example.com \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		--transfer-encoding=auto \
+		--no-validate \
+		cr.patch &&
+	grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
+'
+
 for enc in auto quoted-printable base64
 do
 	test_expect_success $PREREQ "--validate passes with encoding $enc" '
Eric Sunshine· Apr 11, 2019, 17:44 UTC · re: brian m. carlson · lore

Re: [PATCH] send-email: default to quoted-printable when CR is present

On Wed, Apr 10, 2019 at 7:35 PM brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 5 quoted lines
> [...]
> Note that we are guaranteed to always correctly encode carriage returns
> when writing quoted-printable since we explicitly specify the line
> ending as "\n", forcing MIME::QuotedPrint to encode our carriage return
> as "=OD".
s/=OD/=0D/
(That is, replace capital "O" with zero "0".)
brian m. carlson· Apr 12, 2019, 00:01 UTC · re: Eric Sunshine · lore

Re: [PATCH] send-email: default to quoted-printable when CR is present

On Thu, Apr 11, 2019 at 01:44:06PM -0400, Eric Sunshine wrote:
Show 11 quoted lines
> On Wed, Apr 10, 2019 at 7:35 PM brian m. carlson
> <sandals@crustytoothpaste.net> wrote:
> > [...]
> > Note that we are guaranteed to always correctly encode carriage returns
> > when writing quoted-printable since we explicitly specify the line
> > ending as "\n", forcing MIME::QuotedPrint to encode our carriage return
> > as "=OD".
> 
> s/=OD/=0D/
> 
> (That is, replace capital "O" with zero "0".)
Ah, yes. Thanks for pointing that out.
I'll wait to see if there's any other feedback and then reroll.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204
brian m. carlson· Apr 13, 2019, 22:45 UTC · re: brian m. carlson · lore

[PATCH v2] send-email: default to quoted-printable when CR is present

In 7a36987fff ("send-email: add an auto option for transfer encoding", 2018-07-08), git send-email learned how to automatically determine the transfer encoding for a patch. However, the only criterion considered was the length of the lines.

Another case we need to consider is that of carriage returns. Because emails have CRLF endings when canonicalized, we don't want to write raw carriage returns into a patch, lest they be stripped off as an artifact of the transport. Ensure that we choose quoted-printable encoding if the patch we're sending contains carriage returns.

Note that we are guaranteed to always correctly encode carriage returns when writing quoted-printable since we explicitly specify the line ending as "\n", forcing MIME::QuotedPrint to encode our carriage return as "=0D".

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
Changes from v1:
* Fix typo "=OD" for "=0D".
 git-send-email.perl   |  2 +-
 t/t9001-send-email.sh | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
Show changes to 2 files +15 −1

git-send-email.perl, t/t9001-send-email.sh

diff --git a/git-send-email.perl b/git-send-email.perl
index 8200d58cdc..751cabf479 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1872,7 +1872,7 @@ sub apply_transfer_encoding {
 	$message = MIME::Base64::decode($message)
 		if ($from eq 'base64');
 
-	$to = ($message =~ /.{999,}/) ? 'quoted-printable' : '8bit'
+	$to = ($message =~ /(?:.{999,}|\r)/) ? 'quoted-printable' : '8bit'
 		if $to eq 'auto';
 
 	die __("cannot send message as 7bit")
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index ee1efcc59d..1e3ac3c384 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -481,6 +481,20 @@ test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable'
 	grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
 '
 
+test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
+	clean_fake_sendmail &&
+	cp $patches cr.patch &&
+	printf "this is a line\r\n" >>cr.patch &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--to=nobody@example.com \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		--transfer-encoding=auto \
+		--no-validate \
+		cr.patch &&
+	grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
+'
+
 for enc in auto quoted-printable base64
 do
 	test_expect_success $PREREQ "--validate passes with encoding $enc" '

← back to recent threads