@matheusbsbs / matheus-bagliano / commits / 994d6c66d3
Fork 0

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>

Eric Wong committed May 14, 2006 at 19:13 UTC 994d6c66d360198c16eb483e4f33d412358f30a1
1 file changed +48
git-send-email.perl
+48
@@ -89,6 +89,41 @@ sub gitvar_ident {
89 my ($author) = gitvar_ident('GIT_AUTHOR_IDENT');
90 my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
91
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 +
127 my $prompting = 0;
128 if (!defined $from) {
129 $from = $author || $committer;
@@ -112,6 +147,19 @@ if (!@to) {
147 $prompting++;
148 }
149
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 +
163 if (!defined $initial_subject && $compose) {
164 do {
165 $_ = $term->readline("What subject should the emails start with? ",