Skip to content

Commit

Permalink
send-email: be more lenient and just catch obvious mistakes.
Browse files Browse the repository at this point in the history
This cleans up the pattern matching subroutine by introducing
two variables to hold regexp to approximately match local-part
and domain in the e-mail address.  It is meant to catch obvious
mistakes with a cheap check.

The patch also moves "scalar" to force Email::Valid->address()
to work in !wantarray environment to extract_valid_address;
earlier it was in the caller of the subroutine, which was way
too error prone.

Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Jun 6, 2006
1 parent e96fd30 commit ad9c18f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,18 @@ sub expand_aliases {

sub extract_valid_address {
my $address = shift;
my $local_part_regexp = '[^<>"\s@]+';
my $domain_regexp = '[^.<>"\s@]+\.[^<>"\s@]+';

# check for a local address:
return $address if ($address =~ /^([\w\-.]+)$/);
return $address if ($address =~ /^($local_part_regexp)$/);

if ($have_email_valid) {
return Email::Valid->address($address);
return scalar 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
$address =~ /([\w\-.]+@[\w\-.]+)/;
$address =~ /($local_part_regexp\@$domain_regexp)/;
return $1;
}
}
Expand Down Expand Up @@ -384,7 +386,7 @@ sub send_message
defined $pid or die $!;
if (!$pid) {
exec($smtp_server,'-i',
map { scalar extract_valid_address($_) }
map { extract_valid_address($_) }
@recipients) or die $!;
}
print $sm "$header\n$message";
Expand Down

0 comments on commit ad9c18f

Please sign in to comment.