summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e96fd30)
raw | patch | inline | side by side (parent: e96fd30)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 6 Jun 2006 07:05:56 +0000 (00:05 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 6 Jun 2006 07:05:56 +0000 (00:05 -0700) |
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>
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>
git-send-email.perl | patch | blob | history |
diff --git a/git-send-email.perl b/git-send-email.perl
index a7a77977787d1d1fcc98d9fa4dc745162d6fde04..700d0c3e1506599b12fd8093021066314e1c0e8d 100755 (executable)
--- a/git-send-email.perl
+++ b/git-send-email.perl
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;
}
}
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";