From: Eric Wong <hidden> Date: 2016-06-15 22:42:22
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
From: Eric Wong <hidden> Date: 2016-06-15 22:42:22
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 <redacted>
---
git-send-email.perl | 66 ++++++++++++++++++++++++++++++++-------------------
1 files changed, 41 insertions(+), 25 deletions(-)
7155ae6e5f94a8fdf55f50029af27279dd36fd0a
@@ -19,11 +19,17 @@usestrict;usewarnings;useTerm::ReadLine;-useMail::Sendmailqw(sendmail %mailcfg);useGetopt::Long;useData::Dumper;+useNet::SMTP;useEmail::Valid;+# most mail servers generate the Date: header, but not all...+$ENV{LC_ALL}='C';+usePOSIXqw/strftime/;++my$smtp;+subunique_email_list(@);subcleanup_compose_files();
From: Eric Wong <hidden> Date: 2016-06-15 22:42:22
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 <redacted>
---
git-send-email.perl | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
8bc65d178dd755ecd1f3c038b975b9bbe58c1015
@@ -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;+openmy$ma,'<',$mutt_aliasesordie"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? ",
From: Eric Wong <hidden> Date: 2016-06-15 22:42:22
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 <redacted>
---
git-send-email.perl | 16 +++++++++++++---
1 files changed, 13 insertions(+), 3 deletions(-)
140eaf9b9d438ea489e6c72e2148feb3e355aea8
@@ -22,12 +22,12 @@ use Term::ReadLine;useGetopt::Long;useData::Dumper;useNet::SMTP;-useEmail::Valid;# most mail servers generate the Date: header, but not all...$ENV{LC_ALL}='C';usePOSIXqw/strftime/;+my$have_email_valid=eval{requireEmail::Validorundef};my$smtp;subunique_email_list(@);
@@ -250,6 +250,16 @@ EOT# Variables we set as part of the loop over filesour($message_id,$cc,%mail,$subject,$reply_to,$message);+subextract_valid_address{+my$address=shift;+if($have_email_valid){+returnEmail::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>";submake_message_id
@@ -412,7 +422,7 @@ sub unique_email_list(@) {my@emails;foreachmy$entry(@_){-my$clean=Email::Valid->address($entry);+my$clean=extract_valid_address($entry);nextif$seen{$clean}++;push@emails,$entry;}
@@ -264,8 +264,7 @@ my $message_id_template = "<%s-git-send-submake_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
From: Randal L. Schwartz <hidden> Date: 2016-06-15 22:42:22
quoted
quoted
quoted
quoted
"Eric" == Eric Wong [off-list ref] 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
[off-list ref] <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!
From: Ryan Anderson <hidden> Date: 2016-06-15 22:42:22
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?"
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
From: Eric Wong <hidden> Date: 2016-06-15 22:42:22
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 <redacted>
---
git-send-email.perl | 16 +++++++++++++---
1 files changed, 13 insertions(+), 3 deletions(-)
3f09a822e3871eeae521da80c748602862fc52ce
@@ -22,12 +22,12 @@ use Term::ReadLine;useGetopt::Long;useData::Dumper;useNet::SMTP;-useEmail::Valid;# most mail servers generate the Date: header, but not all...$ENV{LC_ALL}='C';usePOSIXqw/strftime/;+my$have_email_valid=eval{requireEmail::Valid;1};my$smtp;subunique_email_list(@);
@@ -250,6 +250,16 @@ EOT# Variables we set as part of the loop over filesour($message_id,$cc,%mail,$subject,$reply_to,$message);+subextract_valid_address{+my$address=shift;+if($have_email_valid){+returnEmail::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>";submake_message_id
@@ -412,7 +422,7 @@ sub unique_email_list(@) {my@emails;foreachmy$entry(@_){-my$clean=Email::Valid->address($entry);+my$clean=extract_valid_address($entry);nextif$seen{$clean}++;push@emails,$entry;}
From: Eric Wong <hidden> Date: 2016-06-15 22:42:22
Ryan Anderson [off-list ref] wrote:
On Sat, Mar 25, 2006 at 02:43:30AM -0800, Eric Wong wrote:
quoted
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?"
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.
From: Eric Wong <hidden> Date: 2016-06-15 22:42:22
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 <redacted>
---
Notes: Reverted printf => print change from earlier.
git-send-email.perl | 64 ++++++++++++++++++++++++++++++++-------------------
1 files changed, 40 insertions(+), 24 deletions(-)
8d65a0a4121ade9f48f186d0dcf9f41adc62b22c
@@ -19,11 +19,17 @@usestrict;usewarnings;useTerm::ReadLine;-useMail::Sendmailqw(sendmail %mailcfg);useGetopt::Long;useData::Dumper;+useNet::SMTP;useEmail::Valid;+# most mail servers generate the Date: header, but not all...+$ENV{LC_ALL}='C';+usePOSIXqw/strftime/;++my$smtp;+subunique_email_list(@);subcleanup_compose_files();
From: Martin Langhoff <hidden> Date: 2016-06-15 22:42:24
On 3/26/06, Eric Wong [off-list ref] 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