Merge branch 'es/send-email-sendmail-alias'

"git send-email" learned to handle more forms of sendmail style
aliases file.

* es/send-email-sendmail-alias:
  send-email: further warn about unsupported sendmail aliases features
  t9001: add sendmail aliases line continuation tests
  t9001: refactor sendmail aliases test infrastructure
  send-email: implement sendmail aliases line continuation support
  send-email: simplify sendmail aliases comment and blank line recognizer
  send-email: refactor sendmail aliases parser
  send-email: fix style: cuddle 'elsif' and 'else' with closing brace
  send-email: drop noise comments which merely repeat what code says
  send-email: visually distinguish sendmail aliases parser warnings
  send-email: further document missing sendmail aliases functionality
This commit is contained in:
Junio C Hamano 2015-06-24 12:21:39 -07:00
Родитель 59c465d5c0 86b898487a
Коммит 8c17d5a3c0
3 изменённых файлов: 98 добавлений и 46 удалений

Просмотреть файл

@ -394,8 +394,9 @@ 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.
* Warnings are printed on the standard error output for any
explicitly unsupported constructs, and any other lines that are not
recognized by the parser.

Просмотреть файл

@ -487,6 +487,37 @@ sub split_addrs {
}
my %aliases;
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) ];
} else {
print STDERR "warning: sendmail line is not recognized: $_\n";
}
}
sub parse_sendmail_aliases {
my $fh = shift;
my $s = '';
while (<$fh>) {
chomp;
next if /^\s*$/ || /^\s*#/;
$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 = (
# multiline formats can be supported in the future
mutt => sub { my $fh = shift; while (<$fh>) {
@ -515,32 +546,7 @@ my %parse_alias = (
$aliases{$alias} = [ split_addrs($addr) ];
}
} },
sendmail => sub { my $fh = shift; while (<$fh>) {
# ignore blank lines and comment lines
if (/^\s*(?:#.*)?$/) { }
# warn on lines that contain quotes
elsif (/"/) {
print STDERR "sendmail alias with quotes is not supported: $_\n";
}
# warn on lines that continue
elsif (/^\s|\\$/) {
print STDERR "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 "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 ];

Просмотреть файл

@ -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 <nobody@example.com>" \
--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 <awol@example.com>
bob: Robert Bobbyton <bob@example.com>
# this is a comment
@ -1561,20 +1586,40 @@ test_expect_success $PREREQ 'sendemail.aliasfiletype=sendmail' '
abgroup: alice, bob
bcgrp: bob, chloe, Other <o@example.com>
EOF
git config --replace-all sendemail.aliasesfile \
"$(pwd)/.tmp-email-aliases" &&
git config sendemail.aliasfiletype sendmail &&
git send-email \
--from="Example <nobody@example.com>" \
--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
'
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 &&