Skip to content

Commit

Permalink
send-email: lazy-load Email::Valid and make it optional
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Eric Wong authored and Junio C Hamano committed Mar 26, 2006
1 parent a5370b1 commit 567ffeb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
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(@);
Expand Down Expand Up @@ -250,6 +250,16 @@ sub gitvar_ident {
# 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.

Expand All @@ -259,7 +269,7 @@ sub gitvar_ident {
# 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
Expand Down Expand Up @@ -413,7 +423,7 @@ (@)
my @emails;

foreach my $entry (@_) {
my $clean = Email::Valid->address($entry);
my $clean = extract_valid_address($entry);
next if $seen{$clean}++;
push @emails, $entry;
}
Expand Down

0 comments on commit 567ffeb

Please sign in to comment.