send-email: allow multiple emails using --cc, --to and --bcc

Accept a list of emails separated by commas in flags --cc, --to and --bcc. Multiple addresses can already be given by using these options multiple times, but it is more convenient to allow cutting-and-pasting a list of addresses from the header of an existing e-mail message, which already lists them as comma-separated list, as a value to a single parameter. The following format can now be used: $ git send-email --to='Jane <jdoe@example.com>, mike@example.com' Remove the limitation imposed by 79ee555b (Check and document the options to prevent mistakes, 2006-06-21) which rejected every argument with comma in --cc, --to and --bcc. Signed-off-by: Mathieu Lienard--Mayor <Mathieu.Lienard--Mayor@ensimag.imag.fr> Signed-off-by: Jorge Juan Garcia Garcia <Jorge-Juan.Garcia-Garcia@ensimag.imag.fr> Signed-off-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> 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 b1c8a11c8024c88346a06274f87a0605afd4a53b
3 files changed +52 -21
Documentation/git-send-email.txt
+6 -6
@@ -49,17 +49,17 @@ Composing
49 of 'sendemail.annotate'. See the CONFIGURATION section for
50 'sendemail.multiEdit'.
51
52 ---bcc=<address>::
52 +--bcc=<address>,...::
53 Specify a "Bcc:" value for each email. Default is the value of
54 'sendemail.bcc'.
55 +
56 -The --bcc option must be repeated for each user you want on the bcc list.
56 +This option may be specified multiple times.
57
58 ---cc=<address>::
58 +--cc=<address>,...::
59 Specify a starting "Cc:" value for each email.
60 Default is the value of 'sendemail.cc'.
61 +
62 -The --cc option must be repeated for each user you want on the cc list.
62 +This option may be specified multiple times.
63
64 --compose::
65 Invoke a text editor (see GIT_EDITOR in linkgit:git-var[1])
@@ -110,13 +110,13 @@ is not set, this will be prompted for.
110 Only necessary if --compose is also set. If --compose
111 is not set, this will be prompted for.
112
113 ---to=<address>::
113 +--to=<address>,...::
114 Specify the primary recipient of the emails generated. Generally, this
115 will be the upstream maintainer of the project involved. Default is the
116 value of the 'sendemail.to' configuration value; if that is unspecified,
117 and --to-cmd is not specified, this will be prompted for.
118 +
119 -The --to option must be repeated for each user you want on the to list.
119 +This option may be specified multiple times.
120
121 --8bit-encoding=<encoding>::
122 When encountering a non-ASCII message or subject that does not
git-send-email.perl
+2 -15
@@ -460,20 +460,6 @@ my ($repoauthor, $repocommitter);
460 ($repoauthor) = Git::ident_person(@repo, 'author');
461 ($repocommitter) = Git::ident_person(@repo, 'committer');
462
463 -# Verify the user input
464 -
465 -foreach my $entry (@initial_to) {
466 - die "Comma in --to entry: $entry'\n" unless $entry !~ m/,/;
467 -}
468 -
469 -foreach my $entry (@initial_cc) {
470 - die "Comma in --cc entry: $entry'\n" unless $entry !~ m/,/;
471 -}
472 -
473 -foreach my $entry (@bcclist) {
474 - die "Comma in --bcclist entry: $entry'\n" unless $entry !~ m/,/;
475 -}
476 -
463 sub parse_address_line {
464 if ($have_mail_address) {
465 return map { $_->format } Mail::Address->parse($_[0]);
@@ -1026,7 +1012,8 @@ sub sanitize_address_list {
1012 }
1013
1014 sub process_address_list {
1029 - my @addr_list = expand_aliases(@_);
1015 + my @addr_list = map { parse_address_line($_) } @_;
1016 + @addr_list = expand_aliases(@addr_list);
1017 @addr_list = sanitize_address_list(@addr_list);
1018 @addr_list = validate_address_list(@addr_list);
1019 return @addr_list;
t/t9001-send-email.sh
+44
@@ -1648,4 +1648,48 @@ test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1648 do_xmailer_test 1 "--xmailer"
1649 '
1650
1651 +test_expect_success $PREREQ 'setup expected-list' '
1652 + git send-email \
1653 + --dry-run \
1654 + --from="Example <from@example.com>" \
1655 + --to="To 1 <to1@example.com>" \
1656 + --to="to2@example.com" \
1657 + --to="to3@example.com" \
1658 + --cc="Cc 1 <cc1@example.com>" \
1659 + --cc="Cc2 <cc2@example.com>" \
1660 + --bcc="bcc1@example.com" \
1661 + --bcc="bcc2@example.com" \
1662 + 0001-add-master.patch | replace_variable_fields \
1663 + >expected-list
1664 +'
1665 +
1666 +test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
1667 + git send-email \
1668 + --dry-run \
1669 + --from="Example <from@example.com>" \
1670 + --to="To 1 <to1@example.com>, to2@example.com" \
1671 + --to="to3@example.com" \
1672 + --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1673 + --bcc="bcc1@example.com, bcc2@example.com" \
1674 + 0001-add-master.patch | replace_variable_fields \
1675 + >actual-list &&
1676 + test_cmp expected-list actual-list
1677 +'
1678 +
1679 +test_expect_success $PREREQ 'aliases work with email list' '
1680 + echo "alias to2 to2@example.com" >.mutt &&
1681 + echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1682 + test_config sendemail.aliasesfile ".mutt" &&
1683 + test_config sendemail.aliasfiletype mutt &&
1684 + git send-email \
1685 + --dry-run \
1686 + --from="Example <from@example.com>" \
1687 + --to="To 1 <to1@example.com>, to2, to3@example.com" \
1688 + --cc="cc1, Cc2 <cc2@example.com>" \
1689 + --bcc="bcc1@example.com, bcc2@example.com" \
1690 + 0001-add-master.patch | replace_variable_fields \
1691 + >actual-list &&
1692 + test_cmp expected-list actual-list
1693 +'
1694 +
1695 test_done