# [PATCH 0/7] changes from last version

8 messages from 2015-06-09 to 2015-06-10. Participants: Remi Lespinet, Matthieu Moy, Junio C Hamano.
Thread: https://gitlist.dev/t/39575

## Remi Lespinet, 2015-06-09 17:56

Subject: [PATCH 0/7] changes from last version
Message-ID: <1433872587-15515-1-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>
URL: https://gitlist.dev/e/1433872587-15515-1-git-send-email-remi.lespinet%40ensimag.grenoble-inp.fr

```
CHANGES (since last submitted version)

1/7 : identical to previous 1/5
2/7 : identical to previous 2/5
3/7 : identical to previous 3/5
4/7 : Modification previously done by 5/5 (refactoring address process)
5/7 : identical modulo a minor change at hunk @@ -1023,8 +1009,13 @@
       in the function process_address_list due to 4/7
6/7 : new commit
7/7 : new commit

CONFLICT (if merging to pu)

There will be a trivial conflict if merging to pu (with 514554cf,
3169e06d and 6be02640 from Eric Sunshine and Allen Hubbe patch series).
Suppressing conflict marks resolve it.

```

## Remi Lespinet, 2015-06-09 17:56

Subject: [PATCH v3 1/7] t9001-send-email: move script creation in a setup test
Message-ID: <1433872587-15515-2-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>
URL: https://gitlist.dev/e/1433872587-15515-2-git-send-email-remi.lespinet%40ensimag.grenoble-inp.fr
In-Reply-To: <1433872587-15515-1-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>

```
Move the creation of the scripts used in to-cmd and cc-cmd tests
in a setup test to make them available for later tests.

This will be used in the next commit.

Signed-off-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
---
 t/t9001-send-email.sh | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 7be14a4..e63fc83 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -312,13 +312,19 @@ test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email'
 	)
 '
 
+test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
+	write_script tocmd-sed <<-\EOF &&
+	sed -n -e "s/^tocmd--//p" "$1"
+	EOF
+	write_script cccmd-sed <<-\EOF
+	sed -n -e "s/^cccmd--//p" "$1"
+	EOF
+'
+
 test_expect_success $PREREQ 'tocmd works' '
 	clean_fake_sendmail &&
 	cp $patches tocmd.patch &&
 	echo tocmd--tocmd@example.com >>tocmd.patch &&
-	write_script tocmd-sed <<-\EOF &&
-	sed -n -e "s/^tocmd--//p" "$1"
-	EOF
 	git send-email \
 		--from="Example <nobody@example.com>" \
 		--to-cmd=./tocmd-sed \
@@ -332,9 +338,6 @@ test_expect_success $PREREQ 'cccmd works' '
 	clean_fake_sendmail &&
 	cp $patches cccmd.patch &&
 	echo "cccmd--  cccmd@example.com" >>cccmd.patch &&
-	write_script cccmd-sed <<-\EOF &&
-	sed -n -e "s/^cccmd--//p" "$1"
-	EOF
 	git send-email \
 		--from="Example <nobody@example.com>" \
 		--to=nobody@example.com \
-- 
1.9.1

```

## Remi Lespinet, 2015-06-09 17:56

Subject: [PATCH v3 2/7] send-email: allow aliases in patch header and command script outputs
Message-ID: <1433872587-15515-3-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>
URL: https://gitlist.dev/e/1433872587-15515-3-git-send-email-remi.lespinet%40ensimag.grenoble-inp.fr
In-Reply-To: <1433872587-15515-1-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>

```
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

--

Note that the --from option of git format-patch takes an argument which
must be formated as .*<.*> (if not, git format-patch will be aborted with
fatal: invalid ident line). For this reason, passing an alias as an
argument of --from is not possible, but modifying the from field in
the patch manually is.

Signed-off-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
---
 git-send-email.perl   |  2 ++
 t/t9001-send-email.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/git-send-email.perl b/git-send-email.perl
index e1e9b14..0cac4b0 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1535,7 +1535,9 @@ foreach my $t (@files) {
 		($confirm =~ /^(?:auto|compose)$/ && $compose && $message_num == 1));
 	$needs_confirm = "inform" if ($needs_confirm && $confirm_unconfigured && @cc);
 
+	@to = expand_aliases(@to);
 	@to = validate_address_list(sanitize_address_list(@to));
+	@cc = expand_aliases(@cc);
 	@cc = validate_address_list(sanitize_address_list(@cc));
 
 	@to = (@initial_to, @to);
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index e63fc83..062c703 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -1552,6 +1552,66 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
 	grep "^!someone@example\.org!$" commandline1
 '
 
+test_expect_success $PREREQ 'alias support in To header' '
+	clean_fake_sendmail &&
+	echo "alias sbd  someone@example.org" >.mailrc &&
+	test_config sendemail.aliasesfile ".mailrc" &&
+	test_config sendemail.aliasfiletype mailrc &&
+	git format-patch --stdout -1 --to=sbd >aliased.patch &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		aliased.patch \
+		2>errors >out &&
+	grep "^!someone@example\.org!$" commandline1
+'
+
+test_expect_success $PREREQ 'alias support in Cc header' '
+	clean_fake_sendmail &&
+	echo "alias sbd  someone@example.org" >.mailrc &&
+	test_config sendemail.aliasesfile ".mailrc" &&
+	test_config sendemail.aliasfiletype mailrc &&
+	git format-patch --stdout -1 --cc=sbd >aliased.patch &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		aliased.patch \
+		2>errors >out &&
+	grep "^!someone@example\.org!$" commandline1
+'
+
+test_expect_success $PREREQ 'tocmd works with aliases' '
+	clean_fake_sendmail &&
+	echo "alias sbd  someone@example.org" >.mailrc &&
+	test_config sendemail.aliasesfile ".mailrc" &&
+	test_config sendemail.aliasfiletype mailrc &&
+	git format-patch --stdout -1 >tocmd.patch &&
+	echo tocmd--sbd >>tocmd.patch &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--to-cmd=./tocmd-sed \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		tocmd.patch \
+		2>errors >out &&
+	grep "^!someone@example\.org!$" commandline1
+'
+
+test_expect_success $PREREQ 'cccmd works with aliases' '
+	clean_fake_sendmail &&
+	echo "alias sbd  someone@example.org" >.mailrc &&
+	test_config sendemail.aliasesfile ".mailrc" &&
+	test_config sendemail.aliasfiletype mailrc &&
+	git format-patch --stdout -1 >cccmd.patch &&
+	echo cccmd--sbd >>cccmd.patch &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--cc-cmd=./cccmd-sed \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		cccmd.patch \
+		2>errors >out &&
+	grep "^!someone@example\.org!$" commandline1
+'
+
 do_xmailer_test () {
 	expected=$1 params=$2 &&
 	git format-patch -1 &&
-- 
1.9.1

```

## Remi Lespinet, 2015-06-09 17:56

Subject: [PATCH v3 3/7] t9001-send-email: refactor header variable fields replacement
Message-ID: <1433872587-15515-4-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>
URL: https://gitlist.dev/e/1433872587-15515-4-git-send-email-remi.lespinet%40ensimag.grenoble-inp.fr
In-Reply-To: <1433872587-15515-1-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>

```
Create a function which replaces Date, Message-Id and
X-Mailer lines generated by git-send-email by a specific string

Date:.*$       -> Date: DATE-STRING
Message-Id:.*$ -> Message-Id: MESSAGE-ID-STRING
X-Mailer:.*$   -> X-Mailer: X-MAILER-STRING

This is a preparatory for the next commit.

Signed-off-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
---
 t/t9001-send-email.sh | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 062c703..806f066 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -522,6 +522,12 @@ Result: OK
 EOF
 "
 
+replace_variable_fields () {
+	sed	-e "s/^\(Date:\).*/\1 DATE-STRING/" \
+		-e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
+		-e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
+}
+
 test_suppression () {
 	git send-email \
 		--dry-run \
@@ -529,10 +535,7 @@ test_suppression () {
 		--from="Example <from@example.com>" \
 		--to=to@example.com \
 		--smtp-server relay.example.com \
-		$patches |
-	sed	-e "s/^\(Date:\).*/\1 DATE-STRING/" \
-		-e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
-		-e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
+		$patches | replace_variable_fields \
 		>actual-suppress-$1${2+"-$2"} &&
 	test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
 }
-- 
1.9.1

```

## Remi Lespinet, 2015-06-09 17:56

Subject: [PATCH v3 4/7] send-email: refactor address list process
Message-ID: <1433872587-15515-5-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>
URL: https://gitlist.dev/e/1433872587-15515-5-git-send-email-remi.lespinet%40ensimag.grenoble-inp.fr
In-Reply-To: <1433872587-15515-1-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>

```
Simplify code by creating a funct (comma separated, with aliases ...)
into a simple list of valid email addresses.

Signed-off-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
---
 git-send-email.perl | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 0cac4b0..59dcfe3 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -808,12 +808,9 @@ sub expand_one_alias {
 	return $aliases{$alias} ? expand_aliases(@{$aliases{$alias}}) : $alias;
 }
 
-@initial_to = expand_aliases(@initial_to);
-@initial_to = validate_address_list(sanitize_address_list(@initial_to));
-@initial_cc = expand_aliases(@initial_cc);
-@initial_cc = validate_address_list(sanitize_address_list(@initial_cc));
-@bcclist = expand_aliases(@bcclist);
-@bcclist = validate_address_list(sanitize_address_list(@bcclist));
+@initial_to = process_address_list(@initial_to);
+@initial_cc = process_address_list(@initial_cc);
+@bcclist = process_address_list(@bcclist);
 
 if ($thread && !defined $initial_reply_to && $prompting) {
 	$initial_reply_to = ask(
@@ -1026,6 +1023,13 @@ sub sanitize_address_list {
 	return (map { sanitize_address($_) } @_);
 }
 
+sub process_address_list {
+    my @addr_list = expand_aliases(@_);
+    @addr_list = sanitize_address_list(@addr_list);
+    @addr_list = validate_address_list(@addr_list);
+    return @addr_list;
+}
+
 # Returns the local Fully Qualified Domain Name (FQDN) if available.
 #
 # Tightly configured MTAa require that a caller sends a real DNS
@@ -1535,10 +1539,8 @@ foreach my $t (@files) {
 		($confirm =~ /^(?:auto|compose)$/ && $compose && $message_num == 1));
 	$needs_confirm = "inform" if ($needs_confirm && $confirm_unconfigured && @cc);
 
-	@to = expand_aliases(@to);
-	@to = validate_address_list(sanitize_address_list(@to));
-	@cc = expand_aliases(@cc);
-	@cc = validate_address_list(sanitize_address_list(@cc));
+	@to = process_address_list(@to);
+	@cc = process_address_list(@cc);
 
 	@to = (@initial_to, @to);
 	@cc = (@initial_cc, @cc);
-- 
1.9.1

```

## Remi Lespinet, 2015-06-09 17:56

Subject: [PATCH v3 5/7] send-email: allow multiple emails using --cc, --to and --bcc
Message-ID: <1433872587-15515-6-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>
URL: https://gitlist.dev/e/1433872587-15515-6-git-send-email-remi.lespinet%40ensimag.grenoble-inp.fr
In-Reply-To: <1433872587-15515-1-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>

```
From: Jorge Juan Garcia Garcia <Jorge-Juan.Garcia-Garcia@ensimag.imag.fr>

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'

However format using commas in names doesn't work:

    $ git send-email --to='"Jane, Doe" <jdoe@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.

Helped-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
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>
---
 Documentation/git-send-email.txt | 21 +++++++++++++------
 git-send-email.perl              | 21 ++++++-------------
 t/t9001-send-email.sh            | 44 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 21 deletions(-)

diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 8045546..0146164 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -49,17 +49,23 @@ Composing
 	of 'sendemail.annotate'. See the CONFIGURATION section for
 	'sendemail.multiEdit'.
 
---bcc=<address>::
+--bcc=<address>,...::
 	Specify a "Bcc:" value for each email. Default is the value of
 	'sendemail.bcc'.
 +
-The --bcc option must be repeated for each user you want on the bcc list.
+Addresses containing commas ("Doe, Jane" <foobar@example.com>) are not
+currently supported.
++
+This option may be specified multiple times.
 
---cc=<address>::
+--cc=<address>,...::
 	Specify a starting "Cc:" value for each email.
 	Default is the value of 'sendemail.cc'.
 +
-The --cc option must be repeated for each user you want on the cc list.
+Addresses containing commas ("Doe, Jane" <foobar@example.com>) are not
+currently supported.
++
+This option may be specified multiple times.
 
 --compose::
 	Invoke a text editor (see GIT_EDITOR in linkgit:git-var[1])
@@ -110,13 +116,16 @@ is not set, this will be prompted for.
 	Only necessary if --compose is also set.  If --compose
 	is not set, this will be prompted for.
 
---to=<address>::
+--to=<address>,...::
 	Specify the primary recipient of the emails generated. Generally, this
 	will be the upstream maintainer of the project involved. Default is the
 	value of the 'sendemail.to' configuration value; if that is unspecified,
 	and --to-cmd is not specified, this will be prompted for.
 +
-The --to option must be repeated for each user you want on the to list.
+Addresses containing commas ("Doe, Jane" <foobar@example.com>) are not
+currently supported.
++
+This option may be specified multiple times.
 
 --8bit-encoding=<encoding>::
 	When encountering a non-ASCII message or subject that does not
diff --git a/git-send-email.perl b/git-send-email.perl
index 59dcfe3..ea03308 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -460,20 +460,6 @@ my ($repoauthor, $repocommitter);
 ($repoauthor) = Git::ident_person(@repo, 'author');
 ($repocommitter) = Git::ident_person(@repo, 'committer');
 
-# Verify the user input
-
-foreach my $entry (@initial_to) {
-	die "Comma in --to entry: $entry'\n" unless $entry !~ m/,/;
-}
-
-foreach my $entry (@initial_cc) {
-	die "Comma in --cc entry: $entry'\n" unless $entry !~ m/,/;
-}
-
-foreach my $entry (@bcclist) {
-	die "Comma in --bcclist entry: $entry'\n" unless $entry !~ m/,/;
-}
-
 sub parse_address_line {
 	if ($have_mail_address) {
 		return map { $_->format } Mail::Address->parse($_[0]);
@@ -1023,8 +1009,13 @@ sub sanitize_address_list {
 	return (map { sanitize_address($_) } @_);
 }
 
+sub split_at_commas {
+	return (map { split /\s*,\s*/, $_ } @_);
+}
+
 sub process_address_list {
-    my @addr_list = expand_aliases(@_);
+    my @addr_list = split_at_commas(@_);
+    @addr_list = expand_aliases(@addr_list);
     @addr_list = sanitize_address_list(@addr_list);
     @addr_list = validate_address_list(@addr_list);
     return @addr_list;
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 806f066..9aee474 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -1648,4 +1648,48 @@ test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
 	do_xmailer_test 1 "--xmailer"
 '
 
+test_expect_success $PREREQ 'setup expected-list' '
+	git send-email \
+	--dry-run \
+	--from="Example <from@example.com>" \
+	--to="To 1 <to1@example.com>" \
+	--to="to2@example.com" \
+	--to="to3@example.com" \
+	--cc="Cc 1 <cc1@example.com>" \
+	--cc="Cc2 <cc2@example.com>" \
+	--bcc="bcc1@example.com" \
+	--bcc="bcc2@example.com" \
+	0001-add-master.patch | replace_variable_fields \
+	>expected-list
+'
+
+test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
+	git send-email \
+	--dry-run \
+	--from="Example <from@example.com>" \
+	--to="To 1 <to1@example.com>, to2@example.com" \
+	--to="to3@example.com" \
+	--cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
+	--bcc="bcc1@example.com, bcc2@example.com" \
+	0001-add-master.patch | replace_variable_fields \
+	>actual-list &&
+	test_cmp expected-list actual-list
+'
+
+test_expect_success $PREREQ 'aliases work with email list' '
+	echo "alias to2 to2@example.com" >.mutt &&
+	echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
+	test_config sendemail.aliasesfile ".mutt" &&
+	test_config sendemail.aliasfiletype mutt &&
+	git send-email \
+	--dry-run \
+	--from="Example <from@example.com>" \
+	--to="To 1 <to1@example.com>, to2, to3@example.com" \
+	--cc="cc1, Cc2 <cc2@example.com>" \
+	--bcc="bcc1@example.com, bcc2@example.com" \
+	0001-add-master.patch | replace_variable_fields \
+	>actual-list &&
+	test_cmp expected-list actual-list
+'
+
 test_done
-- 
1.9.1

```

## Matthieu Moy, 2015-06-10 08:10

Subject: Re: [PATCH 0/7] changes from last version
Message-ID: <vpq1thkasqu.fsf@anie.imag.fr>
URL: https://gitlist.dev/e/vpq1thkasqu.fsf%40anie.imag.fr
In-Reply-To: <1433872587-15515-1-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>

```
> Subject: Re: [PATCH 0/7] changes from last version

This is not a good subject. You want the subject to say what the series
is about.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Junio C Hamano, 2015-06-10 15:18

Subject: Re: [PATCH v3 5/7] send-email: allow multiple emails using --cc, --to and --bcc
Message-ID: <xmqq616voam4.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqq616voam4.fsf%40gitster.dls.corp.google.com
In-Reply-To: <1433872587-15515-6-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>

```
Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr> writes:

> From: Jorge Juan Garcia Garcia <Jorge-Juan.Garcia-Garcia@ensimag.imag.fr>
>
> 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'
>
> However format using commas in names doesn't work:
>
>     $ git send-email --to='"Jane, Doe" <jdoe@example.com>'

That should be "Doe, Jane <jdoe@example.com>", shouldn't it?  When
writing "firstname lastname", people do not put comma in between.

```
