send-email: add sendmail email aliases format
Teach send-email to read aliases in the sendmail aliases format, i.e. <alias>: <address|alias>[, <address|alias>...] Examples: alice: Alice W Land <awol@example.com> bob: Robert Bobbyton <bob@example.com> # this is a comment # this is also a comment chloe: chloe@example.com abgroup: alice, bob bcgrp: bob, chloe, Other <o@example.com> - Quoted aliases and quoted addresses are not supported. - Line continuations are not supported. Warnings are printed for explicitly unsupported constructs, and any other lines that are not matched by the parser. Signed-off-by: Allen Hubbe <allenbh@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
9532ead987
commit
3169e06daf
@ -383,7 +383,23 @@ sendemail.aliasesFile::
|
|||||||
|
|
||||||
sendemail.aliasFileType::
|
sendemail.aliasFileType::
|
||||||
Format of the file(s) specified in sendemail.aliasesFile. Must be
|
Format of the file(s) specified in sendemail.aliasesFile. Must be
|
||||||
one of 'mutt', 'mailrc', 'pine', 'elm', or 'gnus'.
|
one of 'mutt', 'mailrc', 'pine', 'elm', or 'gnus', or 'sendmail'.
|
||||||
|
+
|
||||||
|
What an alias file in each format looks like can be found in
|
||||||
|
the documentation of the email program of the same name. The
|
||||||
|
differences and limitations from the standard formats are
|
||||||
|
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.
|
||||||
|
* Warnings are printed on the standard error output for any
|
||||||
|
explicitly unsupported constructs, and any other lines that are not
|
||||||
|
recognized by the parser.
|
||||||
|
--
|
||||||
|
|
||||||
sendemail.multiEdit::
|
sendemail.multiEdit::
|
||||||
If true (default), a single editor instance will be spawned to edit
|
If true (default), a single editor instance will be spawned to edit
|
||||||
|
@ -516,6 +516,31 @@ 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 "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";
|
||||||
|
}}},
|
||||||
|
|
||||||
gnus => sub { my $fh = shift; while (<$fh>) {
|
gnus => sub { my $fh = shift; while (<$fh>) {
|
||||||
if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
|
if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
|
||||||
$aliases{$1} = [ $2 ];
|
$aliases{$1} = [ $2 ];
|
||||||
|
@ -1549,6 +1549,33 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
|
|||||||
grep "^!someone@example\.org!$" commandline1
|
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 &&
|
||||||
|
alice: Alice W Land <awol@example.com>
|
||||||
|
bob: Robert Bobbyton <bob@example.com>
|
||||||
|
# this is a comment
|
||||||
|
# this is also a comment
|
||||||
|
chloe: chloe@example.com
|
||||||
|
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
|
||||||
|
'
|
||||||
|
|
||||||
do_xmailer_test () {
|
do_xmailer_test () {
|
||||||
expected=$1 params=$2 &&
|
expected=$1 params=$2 &&
|
||||||
git format-patch -1 &&
|
git format-patch -1 &&
|
||||||
|
Reference in New Issue
Block a user