Skip to content

Commit f2d06fb

Browse files
bk2204gitster
authored andcommittedJul 9, 2018
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7a36987 commit f2d06fb

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed
 

‎Documentation/git-send-email.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,11 @@ have been specified, in which case default to 'compose'.
401401
+
402402
--
403403
* 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.
406409
--
407410
+
408411
Default is the value of `sendemail.validate`; if this is not set,

‎git-send-email.perl

+11-7
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ sub is_format_patch_arg {
645645
if ($validate) {
646646
foreach my $f (@files) {
647647
unless (-p $f) {
648-
my $error = validate_patch($f);
648+
my $error = validate_patch($f, $target_xfer_encoding);
649649
$error and die sprintf(__("fatal: %s: %s\nwarning: no patches were sent\n"),
650650
$f, $error);
651651
}
@@ -1879,7 +1879,7 @@ sub unique_email_list {
18791879
}
18801880

18811881
sub validate_patch {
1882-
my $fn = shift;
1882+
my ($fn, $xfer_encoding) = @_;
18831883

18841884
if ($repo) {
18851885
my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
@@ -1899,11 +1899,15 @@ sub validate_patch {
18991899
return $hook_error if $hook_error;
19001900
}
19011901

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+
}
19071911
}
19081912
}
19091913
return;

‎t/t9001-send-email.sh

+13
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,19 @@ test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable'
479479
grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
480480
'
481481

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+
482495
test_expect_success $PREREQ 'Invalid In-Reply-To' '
483496
clean_fake_sendmail &&
484497
git send-email \

0 commit comments

Comments
 (0)
Please sign in to comment.