From 3169e06daf297227362fb64a9d5c2cc451fefcbb Mon Sep 17 00:00:00 2001 From: Allen Hubbe Date: Tue, 26 May 2015 17:32:03 -0400 Subject: [PATCH 1/2] send-email: add sendmail email aliases format Teach send-email to read aliases in the sendmail aliases format, i.e. : [, ...] Examples: alice: Alice W Land bob: Robert Bobbyton # this is a comment # this is also a comment chloe: chloe@example.com abgroup: alice, bob bcgrp: bob, chloe, Other - 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 Signed-off-by: Junio C Hamano --- Documentation/git-send-email.txt | 18 +++++++++++++++++- git-send-email.perl | 25 +++++++++++++++++++++++++ t/t9001-send-email.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index 804554609d..b48a764320 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -383,7 +383,23 @@ 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'. ++ +What an alias file in each format looks like can be found in +the documentation of the email program of the same name. The +differences and limitations from the standard formats are +described below: ++ +-- +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 e1e9b1460c..6bedf745e7 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 7be14a4e37..01c7ef4d9b 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 + bob: Robert Bobbyton + # this is a comment + # this is also a comment + chloe: chloe@example.com + abgroup: alice, bob + bcgrp: bob, chloe, Other + EOF + git config --replace-all sendemail.aliasesfile \ + "$(pwd)/.tmp-email-aliases" && + git config sendemail.aliasfiletype sendmail && + git send-email \ + --from="Example " \ + --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 && From 587089c1950199c3dcc14d159adb69be992d8d18 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 23 May 2015 11:07:50 -0700 Subject: [PATCH 2/2] t9001: write $HOME/, not ~/, to help shells without tilde expansion Even though it is in POSIX, we do not have to use it, only to hurt shells that may lack the support. The .mailrc test tries to define an alias in .mailrc in the home directory by shell redirection, and then tries to see ~/.mailrc in config is tilde-expanded by Git without help from shell. So the creation should become $HOME/ to be portable for shells that may lack tilde expansion but the reference should be done as "~/.mailrc". Signed-off-by: Junio C Hamano --- t/t9001-send-email.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 01c7ef4d9b..a3663da49b 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1537,7 +1537,7 @@ test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' ' test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' ' clean_fake_sendmail && - echo "alias sbd someone@example.org" >~/.mailrc && + echo "alias sbd someone@example.org" >"$HOME/.mailrc" && git config --replace-all sendemail.aliasesfile "~/.mailrc" && git config sendemail.aliasfiletype mailrc && git send-email \