Skip to content

Commit 994d6c6

Browse files
Eric WongJunio C Hamano
authored andcommitted
send-email: address expansion for common mailers
mutt, gnus, pine, mailrc formats should be supported. Testing and feedback for correctness and completeness of all formats and support for additional formats would be good. Nested expansions are also supported. More than one alias file to be used. All alias file formats must still of be the same type, though. Two git repo-config keys are required for this (as suggested by Ryan Anderson): sendemail.aliasesfile = <filename of aliases file> sendemail.aliasfiletype = (mutt|gnus|pine|mailrc) Signed-off-by: Eric Wong <normalperson@yhbt.net> Acked-by: Ryan Anderson <ryan@michonline.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent cc908b8 commit 994d6c6

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

git-send-email.perl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,41 @@ sub gitvar_ident {
8989
my ($author) = gitvar_ident('GIT_AUTHOR_IDENT');
9090
my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
9191

92+
my %aliases;
93+
chomp(my @alias_files = `git-repo-config --get-all sendemail.aliasesfile`);
94+
chomp(my $aliasfiletype = `git-repo-config sendemail.aliasfiletype`);
95+
my %parse_alias = (
96+
# multiline formats can be supported in the future
97+
mutt => sub { my $fh = shift; while (<$fh>) {
98+
if (/^alias\s+(\S+)\s+(.*)$/) {
99+
my ($alias, $addr) = ($1, $2);
100+
$addr =~ s/#.*$//; # mutt allows # comments
101+
# commas delimit multiple addresses
102+
$aliases{$alias} = [ split(/\s*,\s*/, $addr) ];
103+
}}},
104+
mailrc => sub { my $fh = shift; while (<$fh>) {
105+
if (/^alias\s+(\S+)\s+(.*)$/) {
106+
# spaces delimit multiple addresses
107+
$aliases{$1} = [ split(/\s+/, $2) ];
108+
}}},
109+
pine => sub { my $fh = shift; while (<$fh>) {
110+
if (/^(\S+)\s+(.*)$/) {
111+
$aliases{$1} = [ split(/\s*,\s*/, $2) ];
112+
}}},
113+
gnus => sub { my $fh = shift; while (<$fh>) {
114+
if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
115+
$aliases{$1} = [ $2 ];
116+
}}}
117+
);
118+
119+
if (@alias_files && defined $parse_alias{$aliasfiletype}) {
120+
foreach my $file (@alias_files) {
121+
open my $fh, '<', $file or die "opening $file: $!\n";
122+
$parse_alias{$aliasfiletype}->($fh);
123+
close $fh;
124+
}
125+
}
126+
92127
my $prompting = 0;
93128
if (!defined $from) {
94129
$from = $author || $committer;
@@ -112,6 +147,19 @@ sub gitvar_ident {
112147
$prompting++;
113148
}
114149

150+
sub expand_aliases {
151+
my @cur = @_;
152+
my @last;
153+
do {
154+
@last = @cur;
155+
@cur = map { $aliases{$_} ? @{$aliases{$_}} : $_ } @last;
156+
} while (join(',',@cur) ne join(',',@last));
157+
return @cur;
158+
}
159+
160+
@to = expand_aliases(@to);
161+
@initial_cc = expand_aliases(@initial_cc);
162+
115163
if (!defined $initial_subject && $compose) {
116164
do {
117165
$_ = $term->readline("What subject should the emails start with? ",

0 commit comments

Comments
 (0)