send-email: allow aliases in patch header and command script outputs

Interpret aliases in: - Header fields of patches generated by git format-patch (using --to, --cc, --add-header for example) or manually modified. Example of fields in header: To: alias1 Cc: alias2 Cc: alias3 - Outputs of command scripts specified by --cc-cmd and --to-cmd. Example of script: #!/bin/sh echo alias1 echo alias2 Signed-off-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Remi Lespinet committed Jun 30, 2015 at 14:16 UTC f6f79e5ee3d0b0fa1d2084bae31f8ea8e7d5c3f8
2 files changed +62
git-send-email.perl
+2
@@ -1535,7 +1535,9 @@ foreach my $t (@files) {
1535 ($confirm =~ /^(?:auto|compose)$/ && $compose && $message_num == 1));
1536 $needs_confirm = "inform" if ($needs_confirm && $confirm_unconfigured && @cc);
1537
1538 + @to = expand_aliases(@to);
1539 @to = validate_address_list(sanitize_address_list(@to));
1540 + @cc = expand_aliases(@cc);
1541 @cc = validate_address_list(sanitize_address_list(@cc));
1542
1543 @to = (@initial_to, @to);
t/t9001-send-email.sh
+60
@@ -1552,6 +1552,66 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1552 grep "^!someone@example\.org!$" commandline1
1553 '
1554
1555 +test_expect_success $PREREQ 'alias support in To header' '
1556 + clean_fake_sendmail &&
1557 + echo "alias sbd someone@example.org" >.mailrc &&
1558 + test_config sendemail.aliasesfile ".mailrc" &&
1559 + test_config sendemail.aliasfiletype mailrc &&
1560 + git format-patch --stdout -1 --to=sbd >aliased.patch &&
1561 + git send-email \
1562 + --from="Example <nobody@example.com>" \
1563 + --smtp-server="$(pwd)/fake.sendmail" \
1564 + aliased.patch \
1565 + 2>errors >out &&
1566 + grep "^!someone@example\.org!$" commandline1
1567 +'
1568 +
1569 +test_expect_success $PREREQ 'alias support in Cc header' '
1570 + clean_fake_sendmail &&
1571 + echo "alias sbd someone@example.org" >.mailrc &&
1572 + test_config sendemail.aliasesfile ".mailrc" &&
1573 + test_config sendemail.aliasfiletype mailrc &&
1574 + git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1575 + git send-email \
1576 + --from="Example <nobody@example.com>" \
1577 + --smtp-server="$(pwd)/fake.sendmail" \
1578 + aliased.patch \
1579 + 2>errors >out &&
1580 + grep "^!someone@example\.org!$" commandline1
1581 +'
1582 +
1583 +test_expect_success $PREREQ 'tocmd works with aliases' '
1584 + clean_fake_sendmail &&
1585 + echo "alias sbd someone@example.org" >.mailrc &&
1586 + test_config sendemail.aliasesfile ".mailrc" &&
1587 + test_config sendemail.aliasfiletype mailrc &&
1588 + git format-patch --stdout -1 >tocmd.patch &&
1589 + echo tocmd--sbd >>tocmd.patch &&
1590 + git send-email \
1591 + --from="Example <nobody@example.com>" \
1592 + --to-cmd=./tocmd-sed \
1593 + --smtp-server="$(pwd)/fake.sendmail" \
1594 + tocmd.patch \
1595 + 2>errors >out &&
1596 + grep "^!someone@example\.org!$" commandline1
1597 +'
1598 +
1599 +test_expect_success $PREREQ 'cccmd works with aliases' '
1600 + clean_fake_sendmail &&
1601 + echo "alias sbd someone@example.org" >.mailrc &&
1602 + test_config sendemail.aliasesfile ".mailrc" &&
1603 + test_config sendemail.aliasfiletype mailrc &&
1604 + git format-patch --stdout -1 >cccmd.patch &&
1605 + echo cccmd--sbd >>cccmd.patch &&
1606 + git send-email \
1607 + --from="Example <nobody@example.com>" \
1608 + --cc-cmd=./cccmd-sed \
1609 + --smtp-server="$(pwd)/fake.sendmail" \
1610 + cccmd.patch \
1611 + 2>errors >out &&
1612 + grep "^!someone@example\.org!$" commandline1
1613 +'
1614 +
1615 do_xmailer_test () {
1616 expected=$1 params=$2 &&
1617 git format-patch -1 &&