summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/git-send-email.txt5
-rwxr-xr-xgit-send-email.perl58
-rwxr-xr-xt/t9001-send-email.sh81
3 files changed, 98 insertions, 46 deletions
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index b48a764320..7ae467ba41 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -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.
diff --git a/git-send-email.perl b/git-send-email.perl
index 6bedf745e7..ae9f8698c5 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -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 ];
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index a3663da49b..db2f45e83b 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 <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 &&