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>

Allen Hubbe committed May 26, 2015 at 17:32 UTC 3169e06daf297227362fb64a9d5c2cc451fefcbb
3 files changed +69 -1
Documentation/git-send-email.txt
+17 -1
@@ -383,7 +383,23 @@ sendemail.aliasesFile::
383
384 sendemail.aliasFileType::
385 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 +--
403
404 sendemail.multiEdit::
405 If true (default), a single editor instance will be spawned to edit
git-send-email.perl
+25
@@ -516,6 +516,31 @@ my %parse_alias = (
516 }
517 } },
518
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 +
544 gnus => sub { my $fh = shift; while (<$fh>) {
545 if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
546 $aliases{$1} = [ $2 ];
t/t9001-send-email.sh
+27
@@ -1549,6 +1549,33 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1549 grep "^!someone@example\.org!$" commandline1
1550 '
1551
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 <awol@example.com>
1557 + bob: Robert Bobbyton <bob@example.com>
1558 + # this is a comment
1559 + # this is also a comment
1560 + chloe: chloe@example.com
1561 + abgroup: alice, bob
1562 + bcgrp: bob, chloe, Other <o@example.com>
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 <nobody@example.com>" \
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 +
1579 do_xmailer_test () {
1580 expected=$1 params=$2 &&
1581 git format-patch -1 &&