[PATCH/RFC] send-email: allow multiple emails using --cc --to and --bcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jorge Juan Garcia Garcia <Jorge-Juan.Garcia-Garcia@xxxxxxxxxxxxxxx>

Add the possibility to use a list of emails separated by commas
in flags --cc --to and --bcc instead of having to use one flag
per email address.

The use-case is to copy-paste a list of addresses from an email.
This change makes it so that we no longer need to cut the list.

The format of email list handled is basic for now:
	$ git send-email --to='Foo <foo@xxxxxxxxxxx>, bar@xxxxxxxxxxx'
We thought it would be nice to have a "first-step" version which works
before handling more complex ones such as names with commas:
	$ git send-email --to='Foo, Bar <foobar@xxxxxxxxxxx>'

This artificial limitation is imposed by 79ee555b (Check and document
the options to prevent mistakes, 2006-06-21).

Signed-off-by: Mathieu Lienard--Mayor <Mathieu.Lienard--Mayor@xxxxxxxxxxxxxxx>
Signed-off-by: Jorge Juan Garcia Garcia <Jorge-Juan.Garcia-Garcia@xxxxxxxxxxxxxxx>
Signed-off-by: Matthieu Moy <Matthieu.Moy@xxxxxxxxxxxxxxx>
Contributions-by: Remi Lespinet <remi.lespinet@xxxxxxxxxxxxxxxxxxxxxxx>
---
 Documentation/git-send-email.txt | 23 ++++++++++++++--------
 git-send-email.perl              | 21 ++++++--------------
 t/t9001-send-email.sh            | 41 ++++++++++++++++++++++++++++++++++++----
 3 files changed, 58 insertions(+), 27 deletions(-)

diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 043f345..0aeddcb 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -49,17 +49,21 @@ 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.
+	The format supported for email list is the following:
+	"Foo <foo@xxxxxxxxxxx>, bar@xxxxxxxxxxx".
+	Please notice that the email list does not handle commas in
+	email names such as "Foo, Bar <foobar@xxxxxxxxxxx>".
 
---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.
+	The format supported for email list is the following:
+	"Foo <foo@xxxxxxxxxxx>, bar@xxxxxxxxxxx".
+	Please notice that the email list does not handle commas in
+	email names such as "Foo, Bar <foobar@xxxxxxxxxxx>".
 
 --compose::
 	Invoke a text editor (see GIT_EDITOR in linkgit:git-var[1])
@@ -111,12 +115,15 @@ is not set, this will be prompted for.
 	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.
+	The format supported for email list is the following:
+	"Foo <foo@xxxxxxxxxxx>, bar@xxxxxxxxxxx".
+	Please notice that the email list does not handle commas in
+	email names such as "Foo, Bar <foobar@xxxxxxxxxxx>".
 
 --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 ffea500..409ff45 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]);
@@ -1052,7 +1038,8 @@ sub sanitize_address {
 }
 
 sub sanitize_address_list {
-	return (map { sanitize_address($_) } @_);
+	my @addr_list = split_address_list(@_);
+	return (map { sanitize_address($_) } @addr_list);
 }
 
 # Returns the local Fully Qualified Domain Name (FQDN) if available.
@@ -1193,6 +1180,10 @@ sub file_name_is_absolute {
 	return File::Spec::Functions::file_name_is_absolute($path);
 }
 
+sub split_address_list {
+	return (map { split /\s*,\s*/, $_ } @_);
+}
+
 # Returns 1 if the message was sent, and 0 otherwise.
 # In actuality, the whole program dies when there
 # is an error sending a message.
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index a3663da..4245c06 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -519,6 +519,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 \
@@ -526,10 +532,7 @@ test_suppression () {
 		--from="Example <from@xxxxxxxxxxx>" \
 		--to=to@xxxxxxxxxxx \
 		--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"}
 }
@@ -1609,4 +1612,34 @@ 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@xxxxxxxxxxx>" \
+	--to="to1@xxxxxxxxxxx" \
+	--to="to2@xxxxxxxxxxx" \
+	--to="to3@xxxxxxxxxxx" \
+	--cc="cc1@xxxxxxxxxxx" \
+	--cc="Cc 1 <cc1@xxxxxxxxxxx>" \
+	--cc="Cc 2 <cc2@xxxxxxxxxxx>" \
+	--bcc="bcc1@xxxxxxxxxxx" \
+	--bcc="bcc2@xxxxxxxxxxx" \
+	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@xxxxxxxxxxx>" \
+	--to="to1@xxxxxxxxxxx, to2@xxxxxxxxxxx" \
+	--to="to3@xxxxxxxxxxx" \
+	--cc="cc1@xxxxxxxxxxx, Cc 1 <cc1@xxxxxxxxxxx>" \
+	--cc="Cc 2 <cc2@xxxxxxxxxxx>" \
+	--bcc="bcc1@xxxxxxxxxxx, bcc2@xxxxxxxxxxx" \
+	0001-add-master.patch |	replace_variable_fields \
+	 >actual-list &&
+	test_cmp expected-list actual-list
+'
+
 test_done
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]