From 5c3494ed880b56eb2e487fd5504bc66674151bae Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 31 May 2015 18:29:23 -0400 Subject: [PATCH 01/10] send-email: further document missing sendmail aliases functionality Sendmail aliases[1] supports expansion to a file ("/path/name") or pipe ("|command"), as well as file inclusion (":include: /path/name"), however, our implementation does not support such functionality. [1]: https://www.freebsd.org/cgi/man.cgi?query=aliases&sektion=5 Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- Documentation/git-send-email.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index b48a764320..e6d466e9a5 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -396,6 +396,9 @@ sendmail;; contain a `"` symbol are ignored. * Line continuations are not supported: lines that start with whitespace characters, or end with a `\` symbol are ignored. +* Redirection to a file (`/path/name`) or pipe (`|command`) is not + supported. +* File inclusion (`:include: /path/name`) is not supported. * Warnings are printed on the standard error output for any explicitly unsupported constructs, and any other lines that are not recognized by the parser. From 818a2d7722de03a16177e2323fa7b77624722e2a Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 31 May 2015 18:29:24 -0400 Subject: [PATCH 02/10] send-email: visually distinguish sendmail aliases parser warnings Although emitted to stderr, warnings from the sendmail aliases parser are not visually distinguished as such, and thus can easily be overlooked in the normal noisy send-email output. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- git-send-email.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 6bedf745e7..819f87e8df 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -522,12 +522,12 @@ my %parse_alias = ( # warn on lines that contain quotes elsif (/"/) { - print STDERR "sendmail alias with quotes is not supported: $_\n"; + print STDERR "warning: sendmail alias with quotes is not supported: $_\n"; } # warn on lines that continue elsif (/^\s|\\$/) { - print STDERR "sendmail continuation line is not supported: $_\n"; + print STDERR "warning: sendmail continuation line is not supported: $_\n"; } # recognize lines that look like an alias @@ -538,7 +538,7 @@ my %parse_alias = ( # warn on lines that are not recognized else { - print STDERR "sendmail line is not recognized: $_\n"; + print STDERR "warning: sendmail line is not recognized: $_\n"; }}}, gnus => sub { my $fh = shift; while (<$fh>) { From 2cdaabb6f9294a6ee618abcd1d60a21569a1fd51 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 31 May 2015 18:29:25 -0400 Subject: [PATCH 03/10] send-email: drop noise comments which merely repeat what code says Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- git-send-email.perl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 819f87e8df..0b1868200b 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -517,26 +517,21 @@ my %parse_alias = ( } }, sendmail => sub { my $fh = shift; while (<$fh>) { - # ignore blank lines and comment lines if (/^\s*(?:#.*)?$/) { } - # warn on lines that contain quotes elsif (/"/) { print STDERR "warning: sendmail alias with quotes is not supported: $_\n"; } - # warn on lines that continue elsif (/^\s|\\$/) { print STDERR "warning: sendmail continuation line is not supported: $_\n"; } - # recognize lines that look like an alias elsif (/^(\S+?)\s*:\s*(.+)$/) { my ($alias, $addr) = ($1, $2); $aliases{$alias} = [ split_addrs($addr) ]; } - # warn on lines that are not recognized else { print STDERR "warning: sendmail line is not recognized: $_\n"; }}}, From 22e3b46ff95ac01add2d1e8874708b06c9e7db91 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 31 May 2015 18:29:26 -0400 Subject: [PATCH 04/10] send-email: fix style: cuddle 'elsif' and 'else' with closing brace Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- git-send-email.perl | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 0b1868200b..1380e6e163 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -517,22 +517,15 @@ my %parse_alias = ( } }, sendmail => sub { my $fh = shift; while (<$fh>) { - if (/^\s*(?:#.*)?$/) { } - - elsif (/"/) { + if (/^\s*(?:#.*)?$/) { + } elsif (/"/) { print STDERR "warning: sendmail alias with quotes is not supported: $_\n"; - } - - elsif (/^\s|\\$/) { + } elsif (/^\s|\\$/) { print STDERR "warning: sendmail continuation line is not supported: $_\n"; - } - - elsif (/^(\S+?)\s*:\s*(.+)$/) { + } elsif (/^(\S+?)\s*:\s*(.+)$/) { my ($alias, $addr) = ($1, $2); $aliases{$alias} = [ split_addrs($addr) ]; - } - - else { + } else { print STDERR "warning: sendmail line is not recognized: $_\n"; }}}, From 09f1157bbf5daa8a4fd8de1d25edbb8961d44521 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 31 May 2015 18:29:27 -0400 Subject: [PATCH 05/10] send-email: refactor sendmail aliases parser The sendmail aliases parser inlined into %parse_alias is already uncomfortably large and is expected to grow as additional functionality is implemented, so extract it to improve manageability. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- git-send-email.perl | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 1380e6e163..76bb499fbb 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -487,6 +487,29 @@ sub split_addrs { } my %aliases; + +sub parse_sendmail_alias { + local $_ = shift; + if (/"/) { + print STDERR "warning: sendmail alias with quotes is not supported: $_\n"; + } elsif (/^\s|\\$/) { + print STDERR "warning: sendmail continuation line is not supported: $_\n"; + } elsif (/^(\S+?)\s*:\s*(.+)$/) { + my ($alias, $addr) = ($1, $2); + $aliases{$alias} = [ split_addrs($addr) ]; + } else { + print STDERR "warning: sendmail line is not recognized: $_\n"; + } +} + +sub parse_sendmail_aliases { + my $fh = shift; + while (<$fh>) { + if (/^\s*(?:#.*)?$/) { next; } + parse_sendmail_alias($_); + } +} + my %parse_alias = ( # multiline formats can be supported in the future mutt => sub { my $fh = shift; while (<$fh>) { @@ -515,20 +538,7 @@ my %parse_alias = ( $aliases{$alias} = [ split_addrs($addr) ]; } } }, - - sendmail => sub { my $fh = shift; while (<$fh>) { - if (/^\s*(?:#.*)?$/) { - } elsif (/"/) { - print STDERR "warning: sendmail alias with quotes is not supported: $_\n"; - } elsif (/^\s|\\$/) { - print STDERR "warning: sendmail continuation line is not supported: $_\n"; - } elsif (/^(\S+?)\s*:\s*(.+)$/) { - my ($alias, $addr) = ($1, $2); - $aliases{$alias} = [ split_addrs($addr) ]; - } else { - print STDERR "warning: sendmail line is not recognized: $_\n"; - }}}, - + sendmail => \&parse_sendmail_aliases, gnus => sub { my $fh = shift; while (<$fh>) { if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) { $aliases{$1} = [ $2 ]; From 020be85f5153e2a3a231e40fe81af9e4a1c01cd4 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 31 May 2015 18:29:28 -0400 Subject: [PATCH 06/10] send-email: simplify sendmail aliases comment and blank line recognizer Replace unnecessarily complex regular expression for recognizing comment and blank lines in sendmail aliases with idiomatic expressions which can be easily understood at a glance. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index 76bb499fbb..e777bd3a60 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -505,7 +505,7 @@ sub parse_sendmail_alias { sub parse_sendmail_aliases { my $fh = shift; while (<$fh>) { - if (/^\s*(?:#.*)?$/) { next; } + next if /^\s*$/ || /^\s*#/; parse_sendmail_alias($_); } } From 2532dd0605b15eeed41312558bf5babb50290236 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 31 May 2015 18:29:29 -0400 Subject: [PATCH 07/10] send-email: implement sendmail aliases line continuation support Logical lines in sendmail aliases files can be spread over multiple physical lines[1]. A line beginning with whitespace is folded into the preceding line. A line ending with '\' consumes the following line. [1]: https://www.freebsd.org/cgi/man.cgi?query=aliases&sektion=5 Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- Documentation/git-send-email.txt | 2 -- git-send-email.perl | 10 +++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index e6d466e9a5..7ae467ba41 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -394,8 +394,6 @@ described below: sendmail;; * Quoted aliases and quoted addresses are not supported: lines that contain a `"` symbol are ignored. -* Line continuations are not supported: lines that start with - whitespace characters, or end with a `\` symbol are ignored. * Redirection to a file (`/path/name`) or pipe (`|command`) is not supported. * File inclusion (`:include: /path/name`) is not supported. diff --git a/git-send-email.perl b/git-send-email.perl index e777bd3a60..eb1d678fb0 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -492,8 +492,6 @@ sub parse_sendmail_alias { local $_ = shift; if (/"/) { print STDERR "warning: sendmail alias with quotes is not supported: $_\n"; - } elsif (/^\s|\\$/) { - print STDERR "warning: sendmail continuation line is not supported: $_\n"; } elsif (/^(\S+?)\s*:\s*(.+)$/) { my ($alias, $addr) = ($1, $2); $aliases{$alias} = [ split_addrs($addr) ]; @@ -504,10 +502,16 @@ sub parse_sendmail_alias { sub parse_sendmail_aliases { my $fh = shift; + my $s = ''; while (<$fh>) { + chomp; next if /^\s*$/ || /^\s*#/; - parse_sendmail_alias($_); + $s .= $_, next if $s =~ s/\\$// || s/^\s+//; + parse_sendmail_alias($s) if $s; + $s = $_; } + $s =~ s/\\$//; # silently tolerate stray '\' on last line + parse_sendmail_alias($s) if $s; } my %parse_alias = ( From 514554cf53757298f948e3b53ddb55f7c922bfa1 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 31 May 2015 18:29:30 -0400 Subject: [PATCH 08/10] t9001: refactor sendmail aliases test infrastructure Several new tests of sendmail aliases parsing will be added in a subsequent patch, so factor out functionality common to all of them into a new helper function. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- t/t9001-send-email.sh | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index a3663da49b..1012fa3ad6 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1549,10 +1549,35 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' ' grep "^!someone@example\.org!$" commandline1 ' -test_expect_success $PREREQ 'sendemail.aliasfiletype=sendmail' ' - clean_fake_sendmail && rm -fr outdir && - git format-patch -1 -o outdir && - cat >>.tmp-email-aliases <<-\EOF && +test_sendmail_aliases () { + msg="$1" && shift && + expect="$@" && + cat >.tmp-email-aliases && + + test_expect_success $PREREQ "$msg" ' + clean_fake_sendmail && rm -fr outdir && + git format-patch -1 -o outdir && + git config --replace-all sendemail.aliasesfile \ + "$(pwd)/.tmp-email-aliases" && + git config sendemail.aliasfiletype sendmail && + git send-email \ + --from="Example " \ + --to=alice --to=bcgrp \ + --smtp-server="$(pwd)/fake.sendmail" \ + outdir/0001-*.patch \ + 2>errors >out && + for i in $expect + do + grep "^!$i!$" commandline1 || return 1 + done + ' +} + +test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \ + 'awol@example\.com' \ + 'bob@example\.com' \ + 'chloe@example\.com' \ + 'o@example\.com' <<-\EOF alice: Alice W Land bob: Robert Bobbyton # this is a comment @@ -1561,20 +1586,6 @@ test_expect_success $PREREQ 'sendemail.aliasfiletype=sendmail' ' abgroup: alice, bob bcgrp: bob, chloe, Other EOF - git config --replace-all sendemail.aliasesfile \ - "$(pwd)/.tmp-email-aliases" && - git config sendemail.aliasfiletype sendmail && - git send-email \ - --from="Example " \ - --to=alice --to=bcgrp \ - --smtp-server="$(pwd)/fake.sendmail" \ - outdir/0001-*.patch \ - 2>errors >out && - grep "^!awol@example\.com!$" commandline1 && - grep "^!bob@example\.com!$" commandline1 && - grep "^!chloe@example\.com!$" commandline1 && - grep "^!o@example\.com!$" commandline1 -' do_xmailer_test () { expected=$1 params=$2 && From 6be02640301a7517c76792f5b0e7c978e6961022 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 31 May 2015 18:29:31 -0400 Subject: [PATCH 09/10] t9001: add sendmail aliases line continuation tests A line beginning with whitespace is folded into the preceding line. A line ending with '\' consumes the following line. While here, also test an empty sendmail aliases file. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- t/t9001-send-email.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 1012fa3ad6..db2f45e83b 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1587,6 +1587,40 @@ test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \ bcgrp: bob, chloe, Other EOF +test_sendmail_aliases 'sendmail aliases line folding' \ + alice1 \ + bob1 bob2 \ + chuck1 chuck2 \ + darla1 darla2 darla3 \ + elton1 elton2 elton3 \ + fred1 fred2 \ + greg1 <<-\EOF + alice: alice1 + bob: bob1,\ + bob2 + chuck: chuck1, + chuck2 + darla: darla1,\ + darla2, + darla3 + elton: elton1, + elton2,\ + elton3 + fred: fred1,\ + fred2 + greg: greg1 + bcgrp: bob, chuck, darla, elton, fred, greg + EOF + +test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \ + alice1 bob1 <<-\EOF + alice: alice1 + bcgrp: bob1\ + EOF + +test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF + EOF + do_xmailer_test () { expected=$1 params=$2 && git format-patch -1 && From 86b898487a13483a1b6a5dc7f26a1f103fb2574d Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Mon, 1 Jun 2015 14:22:36 -0400 Subject: [PATCH 10/10] send-email: further warn about unsupported sendmail aliases features The sendmail aliases parser diagnoses unsupported features and unrecognized lines. For completeness, also warn about unsupported redirection to "/path/name" and "|command", as well as ":include:". Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- git-send-email.perl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git-send-email.perl b/git-send-email.perl index eb1d678fb0..ae9f8698c5 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -492,6 +492,10 @@ sub parse_sendmail_alias { local $_ = shift; if (/"/) { print STDERR "warning: sendmail alias with quotes is not supported: $_\n"; + } elsif (/:include:/) { + print STDERR "warning: `:include:` not supported: $_\n"; + } elsif (/[\/|]/) { + print STDERR "warning: `/file` or `|pipe` redirection not supported: $_\n"; } elsif (/^(\S+?)\s*:\s*(.+)$/) { my ($alias, $addr) = ($1, $2); $aliases{$alias} = [ split_addrs($addr) ];