git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* [PATCH] send-email: default to quoted-printable when CR is present
@ 2019-04-10 23:34 brian m. carlson
  2019-04-11 17:44 ` Eric Sunshine
  2019-04-13 22:45 ` [PATCH v2] " brian m. carlson
  0 siblings, 2 replies; 4+ messages in thread
From: brian m. carlson @ 2019-04-10 23:34 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Heinrich Schuchardt

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(-)

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" '

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] send-email: default to quoted-printable when CR is present
  2019-04-10 23:34 [PATCH] send-email: default to quoted-printable when CR is present brian m. carlson
@ 2019-04-11 17:44 ` Eric Sunshine
  2019-04-12  0:01   ` brian m. carlson
  2019-04-13 22:45 ` [PATCH v2] " brian m. carlson
  1 sibling, 1 reply; 4+ messages in thread
From: Eric Sunshine @ 2019-04-11 17:44 UTC (permalink / raw)
  To: brian m. carlson; +Cc: Git List, Junio C Hamano, Heinrich Schuchardt

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".)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] send-email: default to quoted-printable when CR is present
  2019-04-11 17:44 ` Eric Sunshine
@ 2019-04-12  0:01   ` brian m. carlson
  0 siblings, 0 replies; 4+ messages in thread
From: brian m. carlson @ 2019-04-12  0:01 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List, Junio C Hamano, Heinrich Schuchardt

[-- Attachment #1: Type: text/plain, Size: 668 bytes --]

On Thu, Apr 11, 2019 at 01:44:06PM -0400, Eric Sunshine wrote:
> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] send-email: default to quoted-printable when CR is present
  2019-04-10 23:34 [PATCH] send-email: default to quoted-printable when CR is present brian m. carlson
  2019-04-11 17:44 ` Eric Sunshine
@ 2019-04-13 22:45 ` " brian m. carlson
  1 sibling, 0 replies; 4+ messages in thread
From: brian m. carlson @ 2019-04-13 22:45 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Heinrich Schuchardt, Eric Sunshine

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(-)

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" '

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-10 23:34 [PATCH] send-email: default to quoted-printable when CR is present brian m. carlson
2019-04-11 17:44 ` Eric Sunshine
2019-04-12  0:01   ` brian m. carlson
2019-04-13 22:45 ` [PATCH v2] " brian m. carlson

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox