Skip to content

Commit 412e63f

Browse files
committed
Merge branch 'ah/send-email-sendmail-alias'
"git send-email" learned the alias file format used by the sendmail program (in an abbreviated form). * ah/send-email-sendmail-alias: t9001: write $HOME/, not ~/, to help shells without tilde expansion send-email: add sendmail email aliases format
2 parents a5fe668 + 587089c commit 412e63f

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

Documentation/git-send-email.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,23 @@ sendemail.aliasesFile::
383383

384384
sendemail.aliasFileType::
385385
Format of the file(s) specified in sendemail.aliasesFile. Must be
386-
one of 'mutt', 'mailrc', 'pine', 'elm', or 'gnus'.
386+
one of 'mutt', 'mailrc', 'pine', 'elm', or 'gnus', or 'sendmail'.
387+
+
388+
What an alias file in each format looks like can be found in
389+
the documentation of the email program of the same name. The
390+
differences and limitations from the standard formats are
391+
described below:
392+
+
393+
--
394+
sendmail;;
395+
* Quoted aliases and quoted addresses are not supported: lines that
396+
contain a `"` symbol are ignored.
397+
* Line continuations are not supported: lines that start with
398+
whitespace characters, or end with a `\` symbol are ignored.
399+
* Warnings are printed on the standard error output for any
400+
explicitly unsupported constructs, and any other lines that are not
401+
recognized by the parser.
402+
--
387403

388404
sendemail.multiEdit::
389405
If true (default), a single editor instance will be spawned to edit

git-send-email.perl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,31 @@ sub split_addrs {
516516
}
517517
} },
518518

519+
sendmail => sub { my $fh = shift; while (<$fh>) {
520+
# ignore blank lines and comment lines
521+
if (/^\s*(?:#.*)?$/) { }
522+
523+
# warn on lines that contain quotes
524+
elsif (/"/) {
525+
print STDERR "sendmail alias with quotes is not supported: $_\n";
526+
}
527+
528+
# warn on lines that continue
529+
elsif (/^\s|\\$/) {
530+
print STDERR "sendmail continuation line is not supported: $_\n";
531+
}
532+
533+
# recognize lines that look like an alias
534+
elsif (/^(\S+?)\s*:\s*(.+)$/) {
535+
my ($alias, $addr) = ($1, $2);
536+
$aliases{$alias} = [ split_addrs($addr) ];
537+
}
538+
539+
# warn on lines that are not recognized
540+
else {
541+
print STDERR "sendmail line is not recognized: $_\n";
542+
}}},
543+
519544
gnus => sub { my $fh = shift; while (<$fh>) {
520545
if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
521546
$aliases{$1} = [ $2 ];

t/t9001-send-email.sh

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
15371537

15381538
test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
15391539
clean_fake_sendmail &&
1540-
echo "alias sbd [email protected]" >~/.mailrc &&
1540+
echo "alias sbd [email protected]" >"$HOME/.mailrc" &&
15411541
git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
15421542
git config sendemail.aliasfiletype mailrc &&
15431543
git send-email \
@@ -1549,6 +1549,33 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
15491549
grep "^!someone@example\.org!$" commandline1
15501550
'
15511551

1552+
test_expect_success $PREREQ 'sendemail.aliasfiletype=sendmail' '
1553+
clean_fake_sendmail && rm -fr outdir &&
1554+
git format-patch -1 -o outdir &&
1555+
cat >>.tmp-email-aliases <<-\EOF &&
1556+
alice: Alice W Land <[email protected]>
1557+
bob: Robert Bobbyton <[email protected]>
1558+
# this is a comment
1559+
# this is also a comment
1560+
1561+
abgroup: alice, bob
1562+
bcgrp: bob, chloe, Other <[email protected]>
1563+
EOF
1564+
git config --replace-all sendemail.aliasesfile \
1565+
"$(pwd)/.tmp-email-aliases" &&
1566+
git config sendemail.aliasfiletype sendmail &&
1567+
git send-email \
1568+
--from="Example <[email protected]>" \
1569+
--to=alice --to=bcgrp \
1570+
--smtp-server="$(pwd)/fake.sendmail" \
1571+
outdir/0001-*.patch \
1572+
2>errors >out &&
1573+
grep "^!awol@example\.com!$" commandline1 &&
1574+
grep "^!bob@example\.com!$" commandline1 &&
1575+
grep "^!chloe@example\.com!$" commandline1 &&
1576+
grep "^!o@example\.com!$" commandline1
1577+
'
1578+
15521579
do_xmailer_test () {
15531580
expected=$1 params=$2 &&
15541581
git format-patch -1 &&

0 commit comments

Comments
 (0)