From e96fd30553bb57a76ad38f703a3fea5b53c45ff9 Mon Sep 17 00:00:00 2001 From: "Horst H. von Brand" Date: Sat, 3 Jun 2006 13:11:48 -0400 Subject: Cleanup git-send-email.perl:extract_valid_email - Fix the regular expressions for local addresses - Fix the fallback regexp for non-local addresses, simplify the logic Signed-off-by: Horst H. von Brand Signed-off-by: Junio C Hamano --- git-send-email.perl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index ed1d89b3f7..a7a7797778 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -314,18 +314,15 @@ sub extract_valid_address { my $address = shift; # check for a local address: - return $address if ($address =~ /^([\w\-]+)$/); + return $address if ($address =~ /^([\w\-.]+)$/); 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 - my $cleaned_address; - if ($address =~ /([^\"<>\s]+@[^<>\s]+)/) { - $cleaned_address = $1; - } - return $cleaned_address; + $address =~ /([\w\-.]+@[\w\-.]+)/; + return $1; } } -- cgit v1.2.3 From ad9c18f5045281ddd109c54451f1b4ebfb0d3567 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 6 Jun 2006 00:05:56 -0700 Subject: send-email: be more lenient and just catch obvious mistakes. 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 --- git-send-email.perl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index a7a7797778..700d0c3e15 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -312,16 +312,18 @@ our ($message_id, $cc, %mail, $subject, $reply_to, $references, $message); 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; } } @@ -384,7 +386,7 @@ X-Mailer: git-send-email $gitversion 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"; -- cgit v1.2.3 From 09302e177e8dc789c03d9df3620e12e095b4acfb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 6 Jun 2006 14:12:46 -0700 Subject: send-email: a bit more careful domain regexp. This tightens the regexp a bit to make sure there is no double dots. Signed-off-by: Junio C Hamano --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index 700d0c3e15..7b1cca70ab 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -313,7 +313,7 @@ our ($message_id, $cc, %mail, $subject, $reply_to, $references, $message); sub extract_valid_address { my $address = shift; my $local_part_regexp = '[^<>"\s@]+'; - my $domain_regexp = '[^.<>"\s@]+\.[^<>"\s@]+'; + my $domain_regexp = '[^.<>"\s@]+(?:\.[^.<>"\s@]+)+'; # check for a local address: return $address if ($address =~ /^($local_part_regexp)$/); -- cgit v1.2.3