git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: Junio C Hamano <junkio@cox.net>
Cc: git <git@vger.kernel.org>, Ryan Anderson <ryan@michonline.com>,
	Greg KH <greg@kroah.com>, Eric Wong <normalperson@yhbt.net>
Subject: [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional
Date: Sat, 25 Mar 2006 02:43:31 -0800	[thread overview]
Message-ID: <11432834111972-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: <11432834101430-git-send-email-normalperson@yhbt.net>

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

  parent reply	other threads:[~2006-03-25 10:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Eric Wong [this message]
2006-03-25 15:07   ` [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional 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
2006-03-25 10:43 ` [PATCH 2/4] send-email: use built-in time() instead of /bin/date '+%s' Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11432834111972-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=git@vger.kernel.org \
    --cc=greg@kroah.com \
    --cc=junkio@cox.net \
    --cc=ryan@michonline.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).