send-email: accept long lines with suitable transfer encoding
With --validate (which is the default), we warn about lines exceeding 998 characters due to the limits specified in RFC 5322. However, if we're using a suitable transfer encoding (quoted-printable or base64), we're guaranteed not to have lines exceeding 76 characters, so there's no need to fail in this case. The auto transfer encoding handles this specific case, so accept it as well. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Jul 8, 2018 at 22:17 UTC
f2d06fb13fc93c50067e75768a89db098a3d1809
3 files changed
+29
-9
Documentation/git-send-email.txt
+5
-2
@@ -401,8 +401,11 @@ have been specified, in which case default to 'compose'.
401
+
402
--
403
* Invoke the sendemail-validate hook if present (see linkgit:githooks[5]).
404
- * Warn of patches that contain lines longer than 998 characters; this
405
- is due to SMTP limits as described by http://www.ietf.org/rfc/rfc2821.txt.
404
+ * Warn of patches that contain lines longer than
405
+ 998 characters unless a suitable transfer encoding
406
+ ('auto', 'base64', or 'quoted-printable') is used;
407
+ this is due to SMTP limits as described by
408
+ http://www.ietf.org/rfc/rfc2821.txt.
409
--
410
+
411
Default is the value of `sendemail.validate`; if this is not set,
git-send-email.perl
+11
-7
@@ -645,7 +645,7 @@ if (@rev_list_opts) {
645
if ($validate) {
646
foreach my $f (@files) {
647
unless (-p $f) {
648
- my $error = validate_patch($f);
648
+ my $error = validate_patch($f, $target_xfer_encoding);
649
$error and die sprintf(__("fatal: %s: %s\nwarning: no patches were sent\n"),
650
$f, $error);
651
}
@@ -1879,7 +1879,7 @@ sub unique_email_list {
1879
}
1880
1881
sub validate_patch {
1882
- my $fn = shift;
1882
+ my ($fn, $xfer_encoding) = @_;
1883
1884
if ($repo) {
1885
my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
@@ -1899,11 +1899,15 @@ sub validate_patch {
1899
return $hook_error if $hook_error;
1900
}
1901
1902
- open(my $fh, '<', $fn)
1903
- or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
1904
- while (my $line = <$fh>) {
1905
- if (length($line) > 998) {
1906
- return sprintf(__("%s: patch contains a line longer than 998 characters"), $.);
1902
+ # Any long lines will be automatically fixed if we use a suitable transfer
1903
+ # encoding.
1904
+ unless ($xfer_encoding =~ /^(?:auto|quoted-printable|base64)$/) {
1905
+ open(my $fh, '<', $fn)
1906
+ or die sprintf(__("unable to open %s: %s\n"), $fn, $!);
1907
+ while (my $line = <$fh>) {
1908
+ if (length($line) > 998) {
1909
+ return sprintf(__("%s: patch contains a line longer than 998 characters"), $.);
1910
+ }
1911
}
1912
}
1913
return;
t/t9001-send-email.sh
+13
@@ -479,6 +479,19 @@ test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable'
479
grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
480
'
481
482
+for enc in auto quoted-printable base64
483
+do
484
+ test_expect_success $PREREQ "--validate passes with encoding $enc" '
485
+ git send-email \
486
+ --from="Example <nobody@example.com>" \
487
+ --to=nobody@example.com \
488
+ --smtp-server="$(pwd)/fake.sendmail" \
489
+ --transfer-encoding=$enc \
490
+ --validate \
491
+ $patches longline.patch
492
+ '
493
+done
494
+
495
test_expect_success $PREREQ 'Invalid In-Reply-To' '
496
clean_fake_sendmail &&
497
git send-email \