# [PATCH v6] send-email: Add sendmail email aliases format

2 messages from 2015-05-26 to 2015-05-27. Participants: Allen Hubbe, Junio C Hamano.
Thread: https://gitlist.dev/t/39429

## Allen Hubbe, 2015-05-26 21:32

Subject: [PATCH v6] send-email: Add sendmail email aliases format
Message-ID: <950e3a77f09d62f77c9a40c843284b3686bdb7b0.1432675817.git.allenbh@gmail.com>
URL: https://gitlist.dev/e/950e3a77f09d62f77c9a40c843284b3686bdb7b0.1432675817.git.allenbh%40gmail.com

```
Add support for the sendmail email aliases format.

Synopsis:

	<alias>: <address|alias>[, <address|alias>...]

Example:

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

Notes:
    This v6 makes the following changes from v5:
    
    * In the documentation:
    ** Move 'sendmail' to the end of the list of formats.
    ** Remove the description, synopsis, and example of sendmail aliases.
    ** Specify exceptions to the sendmail format as a sub-definition.
    ** Note: A general 'where to find documentation' paragraph will be added
       by Junio, appearing either before or after this patch in the series.
    * Changes to the parser:
    ** Reword a comment to mention blank lines and comment lines.
    ** Resolve inconsistent use of the keyword `next` by not using it.
    ** Use non-greedy quantifier in the capture group for the alias name.
    ** Use greedy quantifier in the capture group for email addresses.
    * Changes to the test case:
    ** Test alias input is written to the current dir, not the home dir.
    ** Note: A fix to other tests to eliminate the use of tilde for the home
       dir will be added by Junio, appearing either before or after this
       patch in the series.

 Documentation/git-send-email.txt | 13 ++++++++++++-
 git-send-email.perl              | 25 +++++++++++++++++++++++++
 t/t9001-send-email.sh            | 27 +++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 804554609def..36fd0b86353c 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -383,7 +383,18 @@ sendemail.aliasesFile::
 
 sendemail.aliasFileType::
 	Format of the file(s) specified in sendemail.aliasesFile. Must be
-	one of 'mutt', 'mailrc', 'pine', 'elm', or 'gnus'.
+	one of 'mutt', 'mailrc', 'pine', 'elm', or 'gnus', or 'sendmail'.
++
+--
+sendmail;;
+*	Quoted aliases and quoted addresses are not supported: lines that
+	contain a `"` symbol are ignored.
+*	Line continuations are not supported: lines that start with
+	whitespace characters, or end with a `\` symbol are ignored.
+*	Warnings are printed on the standard error output for any
+	explicitly unsupported constructs, and any other lines that are not
+	recognized by the parser.
+--
 
 sendemail.multiEdit::
 	If true (default), a single editor instance will be spawned to edit
diff --git a/git-send-email.perl b/git-send-email.perl
index e1e9b1460ced..6bedf745e72d 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -516,6 +516,31 @@ my %parse_alias = (
 			  }
 		      } },
 
+	sendmail => sub { my $fh = shift; while (<$fh>) {
+		# ignore blank lines and comment lines
+		if (/^\s*(?:#.*)?$/) { }
+
+		# warn on lines that contain quotes
+		elsif (/"/) {
+			print STDERR "sendmail alias with quotes is not supported: $_\n";
+		}
+
+		# warn on lines that continue
+		elsif (/^\s|\\$/) {
+			print STDERR "sendmail continuation line is not supported: $_\n";
+		}
+
+		# recognize lines that look like an alias
+		elsif (/^(\S+?)\s*:\s*(.+)$/) {
+			my ($alias, $addr) = ($1, $2);
+			$aliases{$alias} = [ split_addrs($addr) ];
+		}
+
+		# warn on lines that are not recognized
+		else {
+			print STDERR "sendmail line is not recognized: $_\n";
+		}}},
+
 	gnus => sub { my $fh = shift; while (<$fh>) {
 		if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
 			$aliases{$1} = [ $2 ];
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 7be14a4e37f7..01c7ef4d9b67 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -1549,6 +1549,33 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
 	grep "^!someone@example\.org!$" commandline1
 '
 
+test_expect_success $PREREQ 'sendemail.aliasfiletype=sendmail' '
+	clean_fake_sendmail && rm -fr outdir &&
+	git format-patch -1 -o outdir &&
+	cat >>.tmp-email-aliases <<-\EOF &&
+	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>
+	EOF
+	git config --replace-all sendemail.aliasesfile \
+		"$(pwd)/.tmp-email-aliases" &&
+	git config sendemail.aliasfiletype sendmail &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--to=alice --to=bcgrp \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		outdir/0001-*.patch \
+		2>errors >out &&
+	grep "^!awol@example\.com!$" commandline1 &&
+	grep "^!bob@example\.com!$" commandline1 &&
+	grep "^!chloe@example\.com!$" commandline1 &&
+	grep "^!o@example\.com!$" commandline1
+'
+
 do_xmailer_test () {
 	expected=$1 params=$2 &&
 	git format-patch -1 &&
-- 
2.3.4

```

## Junio C Hamano, 2015-05-27 20:08

Subject: Re: [PATCH v6] send-email: Add sendmail email aliases format
Message-ID: <xmqqbnh5lr5k.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqbnh5lr5k.fsf%40gitster.dls.corp.google.com
In-Reply-To: <950e3a77f09d62f77c9a40c843284b3686bdb7b0.1432675817.git.allenbh@gmail.com>

```
Allen Hubbe <allenbh@gmail.com> writes:

> Add support for the sendmail email aliases format.

Thanks.

>     ** Note: A general 'where to find documentation' paragraph will be added
>        by Junio, appearing either before or after this patch in the series.

You didn't have to do this to me; as long as you agree with me that
the paragraph is a good thing to have, it is OK (and even more
preferable) to include it in this patch.

That's called collaboration.

If other person's contribution was really significant and the change
can stand on its own, then a split two-patch series with the author
set to the other person may not be a bad idea, and if other person's
contribution was really significant but the change by the other
person cannot stand on its own, "Helped-by" in the log message would
be sufficient.  My contribution in this case is much less than that.

>     ** Note: A fix to other tests to eliminate the use of tilde for the home
>        dir will be added by Junio, appearing either before or after this
>        patch in the series.

That is a sensible thing to do, as it does not relate to this
change.

Thanks.  Will queue and let's start merging this topic to 'next' and
down.

```
