git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* send-email: dependency removal, cleanup, + small feature
@ 2006-03-25 10:43 Eric Wong
  2006-03-25 10:43 ` [PATCH 1/4] send-email: Change from Mail::Sendmail to Net::SMTP Eric Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: Eric Wong @ 2006-03-25 10:43 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git, Ryan Anderson, Greg KH


1 - Change from Mail::Sendmail to Net::SMTP
2 - use built-in time() instead of /bin/date '+%s'
3 - lazy-load Email::Valid and make it optional
4 - add support for mutt aliases files

Patches 1 and 3 make git-send-email easily runnable with any
reasonable Perl installation.  2 is just a good idea.  4 makes
my life a lot easier.

-- 
Eric Wong

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 1/4] send-email: Change from Mail::Sendmail to Net::SMTP
  2006-03-25 10:43 send-email: dependency removal, cleanup, + small feature Eric Wong
@ 2006-03-25 10:43 ` Eric Wong
  2006-03-25 23:58   ` Ryan Anderson
  2006-03-25 10:43 ` [PATCH 2/4] send-email: use built-in time() instead of /bin/date '+%s' Eric Wong
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 24+ messages in thread
From: Eric Wong @ 2006-03-25 10:43 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git, Ryan Anderson, Greg KH, Eric Wong

Net::SMTP is in the base Perl distribution, so users are more
likely to have it.  Net::SMTP also allows reusing the SMTP
connection, so sending multiple emails is faster.

Signed-off-by: Eric Wong <normalperson@yhbt.net>

---

 git-send-email.perl |   66 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 41 insertions(+), 25 deletions(-)

7155ae6e5f94a8fdf55f50029af27279dd36fd0a
diff --git a/git-send-email.perl b/git-send-email.perl
index b220d11..efaf457 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -19,11 +19,17 @@
 use strict;
 use warnings;
 use Term::ReadLine;
-use Mail::Sendmail qw(sendmail %mailcfg);
 use Getopt::Long;
 use Data::Dumper;
+use Net::SMTP;
 use Email::Valid;
 
+# most mail servers generate the Date: header, but not all...
+$ENV{LC_ALL} = 'C';
+use POSIX qw/strftime/;
+
+my $smtp;
+
 sub unique_email_list(@);
 sub cleanup_compose_files();
 
@@ -271,35 +277,45 @@ $cc = "";
 
 sub send_message
 {
-	my $to = join (", ", unique_email_list(@to));
-
-	%mail = (	To	=>	$to,
-			From	=>	$from,
-			CC	=>	$cc,
-			Subject	=>	$subject,
-			Message	=>	$message,
-			'Reply-to'	=>	$from,
-			'In-Reply-To'	=>	$reply_to,
-			'Message-ID'	=>	$message_id,
-			'X-Mailer'	=>	"git-send-email",
-		);
-
-	$mail{smtp} = $smtp_server;
-	$mailcfg{mime} = 0;
-
-	#print Data::Dumper->Dump([\%mail],[qw(*mail)]);
-
-	sendmail(%mail) or die $Mail::Sendmail::error;
+	my @recipients = unique_email_list(@to);
+	my $to = join (",\n\t", @recipients);
+	@recipients = unique_email_list(@recipients,@cc);
+	my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime(time));
+
+	my $header = "From: $from
+To: $to
+Cc: $cc
+Subject: $subject
+Reply-To: $from
+Date: $date
+Message-Id: $message_id
+X-Mailer: git-send-email
+";
+	$header .= "In-Reply-To: $reply_to\n" if $reply_to;
+
+	$smtp ||= Net::SMTP->new( $smtp_server );
+	$smtp->mail( $from ) or die $smtp->message;
+	$smtp->to( @recipients ) or die $smtp->message;
+	$smtp->data or die $smtp->message;
+	$smtp->datasend("$header\n$message") or die $smtp->message;
+	$smtp->dataend() or die $smtp->message;
+	$smtp->ok or die "Failed to send $subject\n".$smtp->message;
 
 	if ($quiet) {
-		printf "Sent %s\n", $subject;
+		print "Sent $subject\n";
 	} else {
-		print "OK. Log says:\n", $Mail::Sendmail::log;
-		print "\n\n"
+		print "OK. Log says:
+Date: $date
+Server: $smtp_server Port: 25
+From: $from
+Subject: $subject
+Cc: $cc
+To: $to
+
+Result: ", $smtp->code, ' ', ($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
 	}
 }
 
-
 $reply_to = $initial_reply_to;
 make_message_id();
 $subject = $initial_subject;
@@ -390,7 +406,7 @@ sub cleanup_compose_files() {
 
 }
 
-
+$smtp->quit if $smtp;
 
 sub unique_email_list(@) {
 	my %seen;
-- 
1.2.4.gb622a

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 4/4] send-email: add support for mutt aliases files
  2006-03-25 10:43 send-email: dependency removal, cleanup, + small feature Eric Wong
                   ` (2 preceding siblings ...)
  2006-03-25 10:43 ` [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional Eric Wong
@ 2006-03-25 10:43 ` Eric Wong
  2006-03-25 20:31   ` Junio C Hamano
  3 siblings, 1 reply; 24+ messages in thread
From: Eric Wong @ 2006-03-25 10:43 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git, Ryan Anderson, Greg KH, Eric Wong

I got rid of the Email::Valid dependency since writing
RFC-correct email addresses is probably not a problem for most
users.

In my experience, misspelled usernames are a much bigger
problem.  I am prone to doing things like leaving out the 'k' in
Junio's email address and other things that Email::Valid can't
catch.

Since I use mutt and the aliases file is pretty simple, I've
added basic support for mutt alias files.

To setup git-send-email to use a mutt aliases file for a repo,
do this:

  git-repo-config sendemail.muttaliases <mutt_alias_file_path>

More email clients/address book formats can easily be supported
in the future.

Signed-off-by: Eric Wong <normalperson@yhbt.net>

---

 git-send-email.perl |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

8bc65d178dd755ecd1f3c038b975b9bbe58c1015
diff --git a/git-send-email.perl b/git-send-email.perl
index 73bba19..207b1fb 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -89,6 +89,15 @@ sub gitvar_ident {
 my ($author) = gitvar_ident('GIT_AUTHOR_IDENT');
 my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
 
+my %aliases;
+if (my $mutt_aliases = `git-repo-config sendemail.muttaliases`) {
+    chomp $mutt_aliases;
+    open my $ma, '<', $mutt_aliases or die "opening $mutt_aliases: $!\n";
+    while (<$ma>) { if (/^alias\s+(\S+)\s+(.*)/) { $aliases{$1} = $2 } }
+    close $ma;
+}
+# aliases for more mail clients can be supported here:
+
 my $prompting = 0;
 if (!defined $from) {
 	$from = $author || $committer;
@@ -112,6 +121,9 @@ if (!@to) {
 	$prompting++;
 }
 
+@to = map { $aliases{$_} || $_ } @to;
+@initial_cc = map { $aliases{$_} || $_ } @initial_cc;
+
 if (!defined $initial_subject && $compose) {
 	do {
 		$_ = $term->readline("What subject should the emails start with? ",
-- 
1.2.4.gb622a

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional
  2006-03-25 10:43 send-email: dependency removal, cleanup, + small feature Eric Wong
  2006-03-25 10:43 ` [PATCH 1/4] send-email: Change from Mail::Sendmail to Net::SMTP Eric Wong
  2006-03-25 10:43 ` [PATCH 2/4] send-email: use built-in time() instead of /bin/date '+%s' Eric Wong
@ 2006-03-25 10:43 ` Eric Wong
  2006-03-25 15:07   ` Randal L. Schwartz
  2006-03-25 20:33   ` Junio C Hamano
  2006-03-25 10:43 ` [PATCH 4/4] send-email: add support for mutt aliases files Eric Wong
  3 siblings, 2 replies; 24+ messages in thread
From: Eric Wong @ 2006-03-25 10:43 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git, Ryan Anderson, Greg KH, Eric Wong

It's not installed on enough machines, and is overkill most of
the time.  We'll fallback to a very basic regexp (that is a
looser variant of what Email::Valid allows) just in case, but
nothing like the monster regexp Email::Valid has to offer :)

Signed-off-by: Eric Wong <normalperson@yhbt.net>

---

 git-send-email.perl |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

140eaf9b9d438ea489e6c72e2148feb3e355aea8
diff --git a/git-send-email.perl b/git-send-email.perl
index 5e08817..73bba19 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -22,12 +22,12 @@ use Term::ReadLine;
 use Getopt::Long;
 use Data::Dumper;
 use Net::SMTP;
-use Email::Valid;
 
 # most mail servers generate the Date: header, but not all...
 $ENV{LC_ALL} = 'C';
 use POSIX qw/strftime/;
 
+my $have_email_valid = eval { require Email::Valid or undef };
 my $smtp;
 
 sub unique_email_list(@);
@@ -250,6 +250,16 @@ EOT
 # Variables we set as part of the loop over files
 our ($message_id, $cc, %mail, $subject, $reply_to, $message);
 
+sub extract_valid_address {
+	my $address = shift;
+	if ($have_email_valid) {
+		return Email::Valid->address($address);
+	} else {
+		# less robust/correct than the monster regexp in Email::Valid,
+		# but still does a 99% job, and one less dependency
+		return ($address =~ /([^\"<>\s]+@[^<>\s]+)/);
+	}
+}
 
 # Usually don't need to change anything below here.
 
@@ -259,7 +269,7 @@ our ($message_id, $cc, %mail, $subject, 
 # 1 second since the last time we were called.
 
 # We'll setup a template for the message id, using the "from" address:
-my $message_id_from = Email::Valid->address($from);
+my $message_id_from = extract_valid_address($from);
 my $message_id_template = "<%s-git-send-email-$message_id_from>";
 
 sub make_message_id
@@ -412,7 +422,7 @@ sub unique_email_list(@) {
 	my @emails;
 
 	foreach my $entry (@_) {
-		my $clean = Email::Valid->address($entry);
+		my $clean = extract_valid_address($entry);
 		next if $seen{$clean}++;
 		push @emails, $entry;
 	}
-- 
1.2.4.gb622a

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 2/4] send-email: use built-in time() instead of /bin/date '+%s'
  2006-03-25 10:43 send-email: dependency removal, cleanup, + small feature Eric Wong
  2006-03-25 10:43 ` [PATCH 1/4] send-email: Change from Mail::Sendmail to Net::SMTP Eric Wong
@ 2006-03-25 10:43 ` Eric Wong
  2006-03-25 10:43 ` [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional Eric Wong
  2006-03-25 10:43 ` [PATCH 4/4] send-email: add support for mutt aliases files Eric Wong
  3 siblings, 0 replies; 24+ messages in thread
From: Eric Wong @ 2006-03-25 10:43 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git, Ryan Anderson, Greg KH, Eric Wong

Signed-off-by: Eric Wong <normalperson@yhbt.net>

---

 git-send-email.perl |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

079ce058710240643369589448660620cd925f5c
diff --git a/git-send-email.perl b/git-send-email.perl
index efaf457..5e08817 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -264,8 +264,7 @@ my $message_id_template = "<%s-git-send-
 
 sub make_message_id
 {
-	my $date = `date "+\%s"`;
-	chomp($date);
+	my $date = time;
 	my $pseudo_rand = int (rand(4200));
 	$message_id = sprintf $message_id_template, "$date$pseudo_rand";
 	#print "new message id = $message_id\n"; # Was useful for debugging
-- 
1.2.4.gb622a

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional
  2006-03-25 10:43 ` [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional Eric Wong
@ 2006-03-25 15:07   ` Randal L. Schwartz
  2006-03-25 20:33   ` Junio C Hamano
  1 sibling, 0 replies; 24+ messages in thread
From: Randal L. Schwartz @ 2006-03-25 15:07 UTC (permalink / raw
  To: Eric Wong; +Cc: Junio C Hamano, git, Ryan Anderson, Greg KH

>>>>> "Eric" == Eric Wong <normalperson@yhbt.net> writes:

Eric> +my $have_email_valid = eval { require Email::Valid or undef };

This is not necessary... if eval fails, it returns undef by definition.  Your
code presumes that the non-zero last-expression-evaluated of a require is also
returned from the require, which I believe is only accidentally true, although
the behavior may be recently documented and therefore promised.  (On perl 5.8,
it looks a bit fishy to me at a quick glance.)

My favorite idiom for a possibly failing eval-step is:

        my $can_I_do_this = eval { riskything; 1 };

If riskything fails, eval returns undef.  If it succeeds, it evaluates the 1,
and returns that.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] send-email: add support for mutt aliases files
  2006-03-25 10:43 ` [PATCH 4/4] send-email: add support for mutt aliases files Eric Wong
@ 2006-03-25 20:31   ` Junio C Hamano
  2006-03-25 23:50     ` Ryan Anderson
  0 siblings, 1 reply; 24+ messages in thread
From: Junio C Hamano @ 2006-03-25 20:31 UTC (permalink / raw
  To: Eric Wong; +Cc: git

Eric Wong <normalperson@yhbt.net> writes:

> More email clients/address book formats can easily be supported
> in the future.

> +if (my $mutt_aliases = `git-repo-config sendemail.muttaliases`) {
> +    chomp $mutt_aliases;
> +    open my $ma, '<', $mutt_aliases or die "opening $mutt_aliases: $!\n";
> +    while (<$ma>) { if (/^alias\s+(\S+)\s+(.*)/) { $aliases{$1} = $2 } }
> +    close $ma;
> +}
> +# aliases for more mail clients can be supported here:
> +

I'd rather avoid proliferation of sendemail.{foo,bar,mutt,pine,...}aliases
variables.  Can we autodetect the alias file format and parse
the given file accordingly?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional
  2006-03-25 10:43 ` [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional Eric Wong
  2006-03-25 15:07   ` Randal L. Schwartz
@ 2006-03-25 20:33   ` Junio C Hamano
  2006-03-26  0:47     ` [PATCH] " Eric Wong
  1 sibling, 1 reply; 24+ messages in thread
From: Junio C Hamano @ 2006-03-25 20:33 UTC (permalink / raw
  To: Eric Wong; +Cc: git

Eric Wong <normalperson@yhbt.net> writes:

> +my $have_email_valid = eval { require Email::Valid or undef };

Merlyn already commented on this and I'd appreciate this part to
be redone.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/4] send-email: add support for mutt aliases files
  2006-03-25 20:31   ` Junio C Hamano
@ 2006-03-25 23:50     ` Ryan Anderson
  2006-03-26  1:10       ` [PATCH] send-email: address expansion for common mailers Eric Wong
  0 siblings, 1 reply; 24+ messages in thread
From: Ryan Anderson @ 2006-03-25 23:50 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Eric Wong, git

On Sat, Mar 25, 2006 at 12:31:18PM -0800, Junio C Hamano wrote:
> Eric Wong <normalperson@yhbt.net> writes:
> 
> > More email clients/address book formats can easily be supported
> > in the future.
> 
> > +if (my $mutt_aliases = `git-repo-config sendemail.muttaliases`) {
> > +    chomp $mutt_aliases;
> > +    open my $ma, '<', $mutt_aliases or die "opening $mutt_aliases: $!\n";
> > +    while (<$ma>) { if (/^alias\s+(\S+)\s+(.*)/) { $aliases{$1} = $2 } }
> > +    close $ma;
> > +}
> > +# aliases for more mail clients can be supported here:
> > +
> 
> I'd rather avoid proliferation of sendemail.{foo,bar,mutt,pine,...}aliases
> variables.  Can we autodetect the alias file format and parse
> the given file accordingly?

Don't bother - instead of lots of variables, just have two:
	sendemail.aliasesfile
	sendemail.aliasfiletype

-- 

Ryan Anderson
  sometimes Pug Majere

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/4] send-email: Change from Mail::Sendmail to Net::SMTP
  2006-03-25 10:43 ` [PATCH 1/4] send-email: Change from Mail::Sendmail to Net::SMTP Eric Wong
@ 2006-03-25 23:58   ` Ryan Anderson
  2006-03-26  0:54     ` Eric Wong
  2006-03-26  1:20     ` [PATCH] " Eric Wong
  0 siblings, 2 replies; 24+ messages in thread
From: Ryan Anderson @ 2006-03-25 23:58 UTC (permalink / raw
  To: Eric Wong; +Cc: Junio C Hamano, git, Greg KH

On Sat, Mar 25, 2006 at 02:43:30AM -0800, Eric Wong wrote:
> Net::SMTP is in the base Perl distribution, so users are more
> likely to have it.  Net::SMTP also allows reusing the SMTP
> connection, so sending multiple emails is faster.

Overall, I like this set of cleanups, just one thing struck me as,
"why?"

>  	if ($quiet) {
> -		printf "Sent %s\n", $subject;
> +		print "Sent $subject\n";

This seems to be a pointless change, and actually, might be long-term
counterproductive.

Assumption: Eventually, we're going to want to internationalize git.

If that is true, we'll eventually do something like this to lines like
that:
	printf( gettext("Send %s\n"), $subject);

The alternative:
	print gettext("Send $subject\n");
does not work.

(The line that xgettext will see is 'Send $subject\n', but when the
program actually runs, gettext will see the interpolated version, which
fails.)

Internationalization may still be a ways off, but I think we're reaching
the point where it might be something we care to think about.

-- 

Ryan Anderson
  sometimes Pug Majere

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH] send-email: lazy-load Email::Valid and make it optional
  2006-03-25 20:33   ` Junio C Hamano
@ 2006-03-26  0:47     ` Eric Wong
  0 siblings, 0 replies; 24+ messages in thread
From: Eric Wong @ 2006-03-26  0:47 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git, Eric Wong

It's not installed on enough machines, and is overkill most of
the time.  We'll fallback to a very basic regexp just in case,
but nothing like the monster regexp Email::Valid has to offer :)

Small cleanup from Merlyn.

Signed-off-by: Eric Wong <normalperson@yhbt.net>

---

 git-send-email.perl |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

3f09a822e3871eeae521da80c748602862fc52ce
diff --git a/git-send-email.perl b/git-send-email.perl
index 5e08817..7cbf11d 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -22,12 +22,12 @@ use Term::ReadLine;
 use Getopt::Long;
 use Data::Dumper;
 use Net::SMTP;
-use Email::Valid;
 
 # most mail servers generate the Date: header, but not all...
 $ENV{LC_ALL} = 'C';
 use POSIX qw/strftime/;
 
+my $have_email_valid = eval { require Email::Valid; 1 };
 my $smtp;
 
 sub unique_email_list(@);
@@ -250,6 +250,16 @@ EOT
 # Variables we set as part of the loop over files
 our ($message_id, $cc, %mail, $subject, $reply_to, $message);
 
+sub extract_valid_address {
+	my $address = shift;
+	if ($have_email_valid) {
+		return Email::Valid->address($address);
+	} else {
+		# less robust/correct than the monster regexp in Email::Valid,
+		# but still does a 99% job, and one less dependency
+		return ($address =~ /([^\"<>\s]+@[^<>\s]+)/);
+	}
+}
 
 # Usually don't need to change anything below here.
 
@@ -259,7 +269,7 @@ our ($message_id, $cc, %mail, $subject, 
 # 1 second since the last time we were called.
 
 # We'll setup a template for the message id, using the "from" address:
-my $message_id_from = Email::Valid->address($from);
+my $message_id_from = extract_valid_address($from);
 my $message_id_template = "<%s-git-send-email-$message_id_from>";
 
 sub make_message_id
@@ -412,7 +422,7 @@ sub unique_email_list(@) {
 	my @emails;
 
 	foreach my $entry (@_) {
-		my $clean = Email::Valid->address($entry);
+		my $clean = extract_valid_address($entry);
 		next if $seen{$clean}++;
 		push @emails, $entry;
 	}
-- 
1.2.4.gb622a

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/4] send-email: Change from Mail::Sendmail to Net::SMTP
  2006-03-25 23:58   ` Ryan Anderson
@ 2006-03-26  0:54     ` Eric Wong
  2006-03-26  1:09       ` Junio C Hamano
  2006-03-26  1:20     ` [PATCH] " Eric Wong
  1 sibling, 1 reply; 24+ messages in thread
From: Eric Wong @ 2006-03-26  0:54 UTC (permalink / raw
  To: Ryan Anderson; +Cc: Junio C Hamano, git, Greg KH

Ryan Anderson <ryan@michonline.com> wrote:
> On Sat, Mar 25, 2006 at 02:43:30AM -0800, Eric Wong wrote:
> > Net::SMTP is in the base Perl distribution, so users are more
> > likely to have it.  Net::SMTP also allows reusing the SMTP
> > connection, so sending multiple emails is faster.
> 
> Overall, I like this set of cleanups, just one thing struck me as,
> "why?"
> 
> >  	if ($quiet) {
> > -		printf "Sent %s\n", $subject;
> > +		print "Sent $subject\n";
> 
> This seems to be a pointless change, and actually, might be long-term
> counterproductive.

Force of habit, I think.  I originally rewrote that portion but thought
I reverted it back to the way it was.  Besides, it's even slightly
faster this way :)  It could still be faster(!) if I just printed a list
(like below).

> Assumption: Eventually, we're going to want to internationalize git.
> 
> If that is true, we'll eventually do something like this to lines like
> that:
> 	printf( gettext("Send %s\n"), $subject);
> 
> The alternative:
> 	print gettext("Send $subject\n");
> does not work.

print gettext('Send '),$subject,"\n";

> (The line that xgettext will see is 'Send $subject\n', but when the
> program actually runs, gettext will see the interpolated version, which
> fails.)
> 
> Internationalization may still be a ways off, but I think we're reaching
> the point where it might be something we care to think about.

-- 
Eric Wong

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 1/4] send-email: Change from Mail::Sendmail to Net::SMTP
  2006-03-26  0:54     ` Eric Wong
@ 2006-03-26  1:09       ` Junio C Hamano
  0 siblings, 0 replies; 24+ messages in thread
From: Junio C Hamano @ 2006-03-26  1:09 UTC (permalink / raw
  To: Eric Wong; +Cc: git

Eric Wong <normalperson@yhbt.net> writes:

> print gettext('Send '),$subject,"\n";

Nak; who said all languages have verb before what the verb acts
upon?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH] send-email: address expansion for common mailers
  2006-03-25 23:50     ` Ryan Anderson
@ 2006-03-26  1:10       ` Eric Wong
  2006-03-26  1:30         ` Junio C Hamano
  0 siblings, 1 reply; 24+ messages in thread
From: Eric Wong @ 2006-03-26  1:10 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Ryan Anderson, git, Eric Wong

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.

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)

I was initially working on auto-detection, but mailrc and mutt formats
tend to throw each other off (they're alike, but handle multiple
addresses per-alias differently).

Signed-off-by: Eric Wong <normalperson@yhbt.net>

---

 git-send-email.perl |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

aea3aaf9571ab639c67608f62771e73104842294
diff --git a/git-send-email.perl b/git-send-email.perl
index 7cbf11d..208c119 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -89,6 +89,39 @@ sub gitvar_ident {
 my ($author) = gitvar_ident('GIT_AUTHOR_IDENT');
 my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
 
+my %aliases;
+chomp(my $aliases_file = `git-repo-config sendemail.aliasesfile`);
+chomp(my $aliasfiletype = `git-repo-config sendemail.aliasfiletype`);
+my %parse_alias = (
+	# multiline formats can be supported in the future
+	mutt => sub { my $fh = shift; while (<$fh>) {
+		if (/^alias\s+(\S+)\s+(.*)$/) {
+			my ($alias, $addr) = ($1, $2);
+			$addr =~ s/#.*$//; # mutt allows # comments
+			 # commas delimit multiple addresses
+			$aliases{$alias} = [ split(/\s*,\s*/, $addr) ];
+		}}},
+	mailrc => sub { my $fh = shift; while (<$fh>) {
+		if (/^alias\s+(\S+)\s+(.*)$/) {
+			# spaces delimit multiple addresses
+			$aliases{$1} = [ split(/\s+/, $2) ];
+		}}},
+	pine => sub { my $fh = shift; while (<$fh>) {
+		if (/^(\S+)\s+(.*)$/) {
+			$aliases{$1} = [ split(/\s*,\s*/, $2) ];
+		}}},
+	gnus => sub { my $fh = shift; while (<$fh>) {
+		if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
+			$aliases{$1} = [ $2 ];
+		}}}
+);
+
+if ($aliases_file && defined $parse_alias{$aliasfiletype}) {
+	open my $fh, '<', $aliases_file or die "opening $aliases_file: $!\n";
+	$parse_alias{$aliasfiletype}->($fh);
+	close $fh;
+}
+
 my $prompting = 0;
 if (!defined $from) {
 	$from = $author || $committer;
@@ -112,6 +145,19 @@ if (!@to) {
 	$prompting++;
 }
 
+sub expand_aliases {
+	my @cur = @_;
+	my @last;
+	do {
+		@last = @cur;
+		@cur = map { $aliases{$_} ? @{$aliases{$_}} : $_ } @last;
+	} while (join(',',@cur) ne join(',',@last));
+	return @cur;
+}
+
+@to = expand_aliases(@to);
+@initial_cc = expand_aliases(@initial_cc);
+
 if (!defined $initial_subject && $compose) {
 	do {
 		$_ = $term->readline("What subject should the emails start with? ",
-- 
1.2.4.gb622a

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH] send-email: Change from Mail::Sendmail to Net::SMTP
  2006-03-25 23:58   ` Ryan Anderson
  2006-03-26  0:54     ` Eric Wong
@ 2006-03-26  1:20     ` Eric Wong
  2006-04-26  0:45       ` Martin Langhoff
  1 sibling, 1 reply; 24+ messages in thread
From: Eric Wong @ 2006-03-26  1:20 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git, Ryan Anderson, Eric Wong

Net::SMTP is in the base Perl distribution, so users are more
likely to have it.  Net::SMTP also allows reusing the SMTP
connection, so sending multiple emails is faster.

Signed-off-by: Eric Wong <normalperson@yhbt.net>

---

 Notes: Reverted printf => print change from earlier.

 git-send-email.perl |   64 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 40 insertions(+), 24 deletions(-)

8d65a0a4121ade9f48f186d0dcf9f41adc62b22c
diff --git a/git-send-email.perl b/git-send-email.perl
index b220d11..25daf16 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -19,11 +19,17 @@
 use strict;
 use warnings;
 use Term::ReadLine;
-use Mail::Sendmail qw(sendmail %mailcfg);
 use Getopt::Long;
 use Data::Dumper;
+use Net::SMTP;
 use Email::Valid;
 
+# most mail servers generate the Date: header, but not all...
+$ENV{LC_ALL} = 'C';
+use POSIX qw/strftime/;
+
+my $smtp;
+
 sub unique_email_list(@);
 sub cleanup_compose_files();
 
@@ -271,35 +277,45 @@ $cc = "";
 
 sub send_message
 {
-	my $to = join (", ", unique_email_list(@to));
-
-	%mail = (	To	=>	$to,
-			From	=>	$from,
-			CC	=>	$cc,
-			Subject	=>	$subject,
-			Message	=>	$message,
-			'Reply-to'	=>	$from,
-			'In-Reply-To'	=>	$reply_to,
-			'Message-ID'	=>	$message_id,
-			'X-Mailer'	=>	"git-send-email",
-		);
-
-	$mail{smtp} = $smtp_server;
-	$mailcfg{mime} = 0;
-
-	#print Data::Dumper->Dump([\%mail],[qw(*mail)]);
-
-	sendmail(%mail) or die $Mail::Sendmail::error;
+	my @recipients = unique_email_list(@to);
+	my $to = join (",\n\t", @recipients);
+	@recipients = unique_email_list(@recipients,@cc);
+	my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime(time));
+
+	my $header = "From: $from
+To: $to
+Cc: $cc
+Subject: $subject
+Reply-To: $from
+Date: $date
+Message-Id: $message_id
+X-Mailer: git-send-email
+";
+	$header .= "In-Reply-To: $reply_to\n" if $reply_to;
+
+	$smtp ||= Net::SMTP->new( $smtp_server );
+	$smtp->mail( $from ) or die $smtp->message;
+	$smtp->to( @recipients ) or die $smtp->message;
+	$smtp->data or die $smtp->message;
+	$smtp->datasend("$header\n$message") or die $smtp->message;
+	$smtp->dataend() or die $smtp->message;
+	$smtp->ok or die "Failed to send $subject\n".$smtp->message;
 
 	if ($quiet) {
 		printf "Sent %s\n", $subject;
 	} else {
-		print "OK. Log says:\n", $Mail::Sendmail::log;
-		print "\n\n"
+		print "OK. Log says:
+Date: $date
+Server: $smtp_server Port: 25
+From: $from
+Subject: $subject
+Cc: $cc
+To: $to
+
+Result: ", $smtp->code, ' ', ($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
 	}
 }
 
-
 $reply_to = $initial_reply_to;
 make_message_id();
 $subject = $initial_subject;
@@ -390,7 +406,7 @@ sub cleanup_compose_files() {
 
 }
 
-
+$smtp->quit if $smtp;
 
 sub unique_email_list(@) {
 	my %seen;
-- 
1.2.4.gb622a

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH] send-email: address expansion for common mailers
  2006-03-26  1:10       ` [PATCH] send-email: address expansion for common mailers Eric Wong
@ 2006-03-26  1:30         ` Junio C Hamano
  2006-03-26  2:44           ` Eric Wong
  0 siblings, 1 reply; 24+ messages in thread
From: Junio C Hamano @ 2006-03-26  1:30 UTC (permalink / raw
  To: Eric Wong; +Cc: git

Eric Wong <normalperson@yhbt.net> writes:

> 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)
>
> I was initially working on auto-detection, but mailrc and mutt formats
> tend to throw each other off (they're alike, but handle multiple
> addresses per-alias differently).

I think specifying the type explicitly is probably not too much
hassle for the end user, so that is fine.  Now, do we want to
support more than one aliases file?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] send-email: address expansion for common mailers
  2006-03-26  1:30         ` Junio C Hamano
@ 2006-03-26  2:44           ` Eric Wong
  2006-05-15  2:13             ` [PATCH (resend)] " Eric Wong
  0 siblings, 1 reply; 24+ messages in thread
From: Eric Wong @ 2006-03-26  2:44 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git

Junio C Hamano <junkio@cox.net> wrote:
> Eric Wong <normalperson@yhbt.net> writes:
> 
> > 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)
> >
> > I was initially working on auto-detection, but mailrc and mutt formats
> > tend to throw each other off (they're alike, but handle multiple
> > addresses per-alias differently).
> 
> I think specifying the type explicitly is probably not too much
> hassle for the end user, so that is fine.  Now, do we want to
> support more than one aliases file?

If they're different types, probably not.  But if it's the same type,
it's pretty easy and I don't see why not.  This patch applies on top
of the previous one.

Subject: [PATCH] send-email: allow more than one alias file to be used

The aliasfiletype must be the same for all aliasesfiles, though.

Signed-off-by: Eric Wong <normalperson@yhbt.net>

---

 git-send-email.perl |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

16306f761b34505672a04bff333d6342724756c8
diff --git a/git-send-email.perl b/git-send-email.perl
index d3e1768..5d1e95c 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -90,7 +90,7 @@ my ($author) = gitvar_ident('GIT_AUTHOR_
 my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
 
 my %aliases;
-chomp(my $aliases_file = `git-repo-config sendemail.aliasesfile`);
+chomp(my @alias_files = `git-repo-config --get-all sendemail.aliasesfile`);
 chomp(my $aliasfiletype = `git-repo-config sendemail.aliasfiletype`);
 my %parse_alias = (
 	# multiline formats can be supported in the future
@@ -116,10 +116,12 @@ my %parse_alias = (
 		}}}
 );
 
-if ($aliases_file && defined $parse_alias{$aliasfiletype}) {
-	open my $fh, '<', $aliases_file or die "opening $aliases_file: $!\n";
-	$parse_alias{$aliasfiletype}->($fh);
-	close $fh;
+if (@alias_files && defined $parse_alias{$aliasfiletype}) {
+	foreach my $file (@alias_files) {
+		open my $fh, '<', $file or die "opening $file: $!\n";
+		$parse_alias{$aliasfiletype}->($fh);
+		close $fh;
+	}
 }
 
 my $prompting = 0;
-- 
1.2.4.gb622a

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH] send-email: Change from Mail::Sendmail to Net::SMTP
  2006-03-26  1:20     ` [PATCH] " Eric Wong
@ 2006-04-26  0:45       ` Martin Langhoff
  2006-04-26 20:17         ` Junio C Hamano
  0 siblings, 1 reply; 24+ messages in thread
From: Martin Langhoff @ 2006-04-26  0:45 UTC (permalink / raw
  To: Eric Wong; +Cc: Junio C Hamano, git, Ryan Anderson

On 3/26/06, Eric Wong <normalperson@yhbt.net> wrote:
> Net::SMTP is in the base Perl distribution, so users are more
> likely to have it.  Net::SMTP also allows reusing the SMTP
> connection, so sending multiple emails is faster.

This is causing problems for me on my Debian sarge dev box.

 * If I have to believe strace(), Net::SMTP is trying to look up
"localhost" via DNS. Sketchy workaround: use 127.0.0.1.

 * This box has nothing listening on port 25. It doesn't get email
from the net, being a LAN machine, so I've told the debian config
system that we don't need an smtp daemon. Net::SMTP doesn't know how
to use /usr/bin/sendmail

 * That nasty @@VERSION@@ thing isn't valid perl, so working on this
code is a pain. Something like this (warning! broken diff ahead!)
fixes it for me.

@@ -292,6 +292,11 @@ sub send_message
        @recipients = unique_email_list(@recipients,@cc);
        my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime($time++));

+       my $gitversion = '@@GIT_VERSION@@';
+       if ($gitversion eq '@@'.'GIT_VERSION@@') {
+           $gitversion = `git --version`;
+       }
+
        my $header = "From: $from
 To: $to
 Cc: $cc
@@ -299,11 +304,11 @@ Subject: $subject
 Reply-To: $from
 Date: $date
 Message-Id: $message_id
-X-Mailer: git-send-email @@GIT_VERSION@@
+X-Mailer: git-send-email $gitversion
 ";
        $header .= "In-Reply-To: $reply_to\n" if $reply_to;

cheers,


martin

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] send-email: Change from Mail::Sendmail to Net::SMTP
  2006-04-26  0:45       ` Martin Langhoff
@ 2006-04-26 20:17         ` Junio C Hamano
  2006-04-26 20:24           ` Martin Langhoff
  0 siblings, 1 reply; 24+ messages in thread
From: Junio C Hamano @ 2006-04-26 20:17 UTC (permalink / raw
  To: Martin Langhoff; +Cc: Eric Wong, Junio C Hamano, git, Ryan Anderson

"Martin Langhoff" <martin.langhoff@gmail.com> writes:

>  * This box has nothing listening on port 25. It doesn't get email
> from the net, being a LAN machine, so I've told the debian config
> system that we don't need an smtp daemon. Net::SMTP doesn't know how
> to use /usr/bin/sendmail

Wouldn't --smtp-server=that.smtp.server work for you?  Ah, that
would not work if your use is to send a local mail.  Hmph...

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] send-email: Change from Mail::Sendmail to Net::SMTP
  2006-04-26 20:17         ` Junio C Hamano
@ 2006-04-26 20:24           ` Martin Langhoff
  2006-04-28  0:27             ` Eric Wong
  0 siblings, 1 reply; 24+ messages in thread
From: Martin Langhoff @ 2006-04-26 20:24 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Eric Wong, git, Ryan Anderson

On 4/27/06, Junio C Hamano <junkio@cox.net> wrote:
> > system that we don't need an smtp daemon. Net::SMTP doesn't know how
> > to use /usr/bin/sendmail


> Wouldn't --smtp-server=that.smtp.server work for you?  Ah, that
> would not work if your use is to send a local mail.  Hmph...

Well, the machine knows that the smtp server is (I mean, files in /etc
have the right values in them), but I don't think often about it. Only
when I am installing OSs or MTAs...

I know... I'm a whiner! ;-) I'll probably do something that does an
eval and tries Mail::Sendmail and post it.



martin

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] send-email: Change from Mail::Sendmail to Net::SMTP
  2006-04-26 20:24           ` Martin Langhoff
@ 2006-04-28  0:27             ` Eric Wong
  2006-04-28  1:04               ` Martin Langhoff
  0 siblings, 1 reply; 24+ messages in thread
From: Eric Wong @ 2006-04-28  0:27 UTC (permalink / raw
  To: Martin Langhoff; +Cc: Junio C Hamano, git, Ryan Anderson

Martin Langhoff <martin.langhoff@gmail.com> wrote:
> On 4/27/06, Junio C Hamano <junkio@cox.net> wrote:
> > > system that we don't need an smtp daemon. Net::SMTP doesn't know how
> > > to use /usr/bin/sendmail
> 
> 
> > Wouldn't --smtp-server=that.smtp.server work for you?  Ah, that
> > would not work if your use is to send a local mail.  Hmph...
> 
> Well, the machine knows that the smtp server is (I mean, files in /etc
> have the right values in them), but I don't think often about it. Only
> when I am installing OSs or MTAs...
> 
> I know... I'm a whiner! ;-) I'll probably do something that does an
> eval and tries Mail::Sendmail and post it.

You should be able to just open a pipe to:
	/usr/sbin/sendmail @recipients
and just write headers\nbody to that pipe.

Perhaps allow and detect --smtp-server=/path/to/sendmail ?

-- 
Eric Wong

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] send-email: Change from Mail::Sendmail to Net::SMTP
  2006-04-28  0:27             ` Eric Wong
@ 2006-04-28  1:04               ` Martin Langhoff
  0 siblings, 0 replies; 24+ messages in thread
From: Martin Langhoff @ 2006-04-28  1:04 UTC (permalink / raw
  To: Eric Wong; +Cc: Junio C Hamano, git, Ryan Anderson

On 4/28/06, Eric Wong <normalperson@yhbt.net> wrote:
> You should be able to just open a pipe to:
>         /usr/sbin/sendmail @recipients
> and just write headers\nbody to that pipe.

Sounds reasonable. I just looked at what Mail::Sendmail does and it
isn't specially interesting. (There used to be a different Perl module
that did smart things, depending on what MTA it found, but I can't
find it now).

> Perhaps allow and detect --smtp-server=/path/to/sendmail ?

Oh, it should just work with sendmail if it's there and we don't
provide --smtp-server ;-)



m

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH (resend)] send-email: address expansion for common mailers
  2006-03-26  2:44           ` Eric Wong
@ 2006-05-15  2:13             ` Eric Wong
  2006-05-15  4:12               ` Ryan Anderson
  0 siblings, 1 reply; 24+ messages in thread
From: Eric Wong @ 2006-05-15  2:13 UTC (permalink / raw
  To: Junio C Hamano, git, Ryan Anderson; +Cc: Eric Wong

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>

---

Looks like this patch got forgotten a while ago, and I never noticed
because I forgot to set WITH_SEND_EMAIL when doing make install.
Of course, WITH_SEND_EMAIL should no longer be needed...

 git-send-email.perl |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

ff6593287dc500853c1cf05bdb0f32f970f10c9d
diff --git a/git-send-email.perl b/git-send-email.perl
index 703dd1f..d8c4b1f 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -89,6 +89,41 @@ sub gitvar_ident {
 my ($author) = gitvar_ident('GIT_AUTHOR_IDENT');
 my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
 
+my %aliases;
+chomp(my @alias_files = `git-repo-config --get-all sendemail.aliasesfile`);
+chomp(my $aliasfiletype = `git-repo-config sendemail.aliasfiletype`);
+my %parse_alias = (
+	# multiline formats can be supported in the future
+	mutt => sub { my $fh = shift; while (<$fh>) {
+		if (/^alias\s+(\S+)\s+(.*)$/) {
+			my ($alias, $addr) = ($1, $2);
+			$addr =~ s/#.*$//; # mutt allows # comments
+			 # commas delimit multiple addresses
+			$aliases{$alias} = [ split(/\s*,\s*/, $addr) ];
+		}}},
+	mailrc => sub { my $fh = shift; while (<$fh>) {
+		if (/^alias\s+(\S+)\s+(.*)$/) {
+			# spaces delimit multiple addresses
+			$aliases{$1} = [ split(/\s+/, $2) ];
+		}}},
+	pine => sub { my $fh = shift; while (<$fh>) {
+		if (/^(\S+)\s+(.*)$/) {
+			$aliases{$1} = [ split(/\s*,\s*/, $2) ];
+		}}},
+	gnus => sub { my $fh = shift; while (<$fh>) {
+		if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
+			$aliases{$1} = [ $2 ];
+		}}}
+);
+
+if (@alias_files && defined $parse_alias{$aliasfiletype}) {
+	foreach my $file (@alias_files) {
+		open my $fh, '<', $file or die "opening $file: $!\n";
+		$parse_alias{$aliasfiletype}->($fh);
+		close $fh;
+	}
+}
+
 my $prompting = 0;
 if (!defined $from) {
 	$from = $author || $committer;
@@ -112,6 +147,19 @@ if (!@to) {
 	$prompting++;
 }
 
+sub expand_aliases {
+	my @cur = @_;
+	my @last;
+	do {
+		@last = @cur;
+		@cur = map { $aliases{$_} ? @{$aliases{$_}} : $_ } @last;
+	} while (join(',',@cur) ne join(',',@last));
+	return @cur;
+}
+
+@to = expand_aliases(@to);
+@initial_cc = expand_aliases(@initial_cc);
+
 if (!defined $initial_subject && $compose) {
 	do {
 		$_ = $term->readline("What subject should the emails start with? ",
-- 
1.3.2.g1c9b

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH (resend)] send-email: address expansion for common mailers
  2006-05-15  2:13             ` [PATCH (resend)] " Eric Wong
@ 2006-05-15  4:12               ` Ryan Anderson
  0 siblings, 0 replies; 24+ messages in thread
From: Ryan Anderson @ 2006-05-15  4:12 UTC (permalink / raw
  To: Eric Wong; +Cc: Junio C Hamano, git, Ryan Anderson

On Sun, May 14, 2006 at 07:13:44PM -0700, Eric Wong wrote:
> 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>

> ---
> 
> Looks like this patch got forgotten a while ago, and I never noticed
> because I forgot to set WITH_SEND_EMAIL when doing make install.
> Of course, WITH_SEND_EMAIL should no longer be needed...
> 
>  git-send-email.perl |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 48 insertions(+), 0 deletions(-)
> 
> ff6593287dc500853c1cf05bdb0f32f970f10c9d
> diff --git a/git-send-email.perl b/git-send-email.perl
> index 703dd1f..d8c4b1f 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -89,6 +89,41 @@ sub gitvar_ident {
>  my ($author) = gitvar_ident('GIT_AUTHOR_IDENT');
>  my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
>  
> +my %aliases;
> +chomp(my @alias_files = `git-repo-config --get-all sendemail.aliasesfile`);
> +chomp(my $aliasfiletype = `git-repo-config sendemail.aliasfiletype`);
> +my %parse_alias = (
> +	# multiline formats can be supported in the future
> +	mutt => sub { my $fh = shift; while (<$fh>) {
> +		if (/^alias\s+(\S+)\s+(.*)$/) {
> +			my ($alias, $addr) = ($1, $2);
> +			$addr =~ s/#.*$//; # mutt allows # comments
> +			 # commas delimit multiple addresses
> +			$aliases{$alias} = [ split(/\s*,\s*/, $addr) ];
> +		}}},
> +	mailrc => sub { my $fh = shift; while (<$fh>) {
> +		if (/^alias\s+(\S+)\s+(.*)$/) {
> +			# spaces delimit multiple addresses
> +			$aliases{$1} = [ split(/\s+/, $2) ];
> +		}}},
> +	pine => sub { my $fh = shift; while (<$fh>) {
> +		if (/^(\S+)\s+(.*)$/) {
> +			$aliases{$1} = [ split(/\s*,\s*/, $2) ];
> +		}}},
> +	gnus => sub { my $fh = shift; while (<$fh>) {
> +		if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
> +			$aliases{$1} = [ $2 ];
> +		}}}
> +);
> +
> +if (@alias_files && defined $parse_alias{$aliasfiletype}) {
> +	foreach my $file (@alias_files) {
> +		open my $fh, '<', $file or die "opening $file: $!\n";
> +		$parse_alias{$aliasfiletype}->($fh);
> +		close $fh;
> +	}
> +}
> +
>  my $prompting = 0;
>  if (!defined $from) {
>  	$from = $author || $committer;
> @@ -112,6 +147,19 @@ if (!@to) {
>  	$prompting++;
>  }
>  
> +sub expand_aliases {
> +	my @cur = @_;
> +	my @last;
> +	do {
> +		@last = @cur;
> +		@cur = map { $aliases{$_} ? @{$aliases{$_}} : $_ } @last;
> +	} while (join(',',@cur) ne join(',',@last));
> +	return @cur;
> +}
> +
> +@to = expand_aliases(@to);
> +@initial_cc = expand_aliases(@initial_cc);
> +
>  if (!defined $initial_subject && $compose) {
>  	do {
>  		$_ = $term->readline("What subject should the emails start with? ",
> -- 
> 1.3.2.g1c9b
> 
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2006-05-15  4:13 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-25 10:43 send-email: dependency removal, cleanup, + small feature Eric Wong
2006-03-25 10:43 ` [PATCH 1/4] send-email: Change from Mail::Sendmail to Net::SMTP Eric Wong
2006-03-25 23:58   ` Ryan Anderson
2006-03-26  0:54     ` Eric Wong
2006-03-26  1:09       ` Junio C Hamano
2006-03-26  1:20     ` [PATCH] " Eric Wong
2006-04-26  0:45       ` Martin Langhoff
2006-04-26 20:17         ` Junio C Hamano
2006-04-26 20:24           ` Martin Langhoff
2006-04-28  0:27             ` Eric Wong
2006-04-28  1:04               ` Martin Langhoff
2006-03-25 10:43 ` [PATCH 2/4] send-email: use built-in time() instead of /bin/date '+%s' Eric Wong
2006-03-25 10:43 ` [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional Eric Wong
2006-03-25 15:07   ` Randal L. Schwartz
2006-03-25 20:33   ` Junio C Hamano
2006-03-26  0:47     ` [PATCH] " Eric Wong
2006-03-25 10:43 ` [PATCH 4/4] send-email: add support for mutt aliases files Eric Wong
2006-03-25 20:31   ` Junio C Hamano
2006-03-25 23:50     ` Ryan Anderson
2006-03-26  1:10       ` [PATCH] send-email: address expansion for common mailers Eric Wong
2006-03-26  1:30         ` Junio C Hamano
2006-03-26  2:44           ` Eric Wong
2006-05-15  2:13             ` [PATCH (resend)] " Eric Wong
2006-05-15  4:12               ` Ryan Anderson

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).