Krzysztof Mazur [off-list ref] writes:
On Tue, Nov 20, 2012 at 11:28:39AM +0100, Felipe Contreras wrote:
quoted
On Tue, Nov 20, 2012 at 8:56 AM, Krzysztof Mazur [off-list ref] wrote:
quoted
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -925,8 +925,11 @@ sub quote_subject {
sub sanitize_address {
my ($recipient) = @_;
+ my $local_part_regexp = qr/[^<>"\s@]+/;
+ my $domain_regexp = qr/[^.<>"\s@]+(?:\.[^.<>"\s@]+)+/;
+
# remove garbage after email address
- $recipient =~ s/(.*>).*$/$1/;
+ $recipient =~ s/^(.*?<$local_part_regexp\@$domain_regexp>).*/$1/;
I don't think all that extra complexity is warranted, to me
s/(.*?>)(.*)$/$1/ is just fine.
Yeah, it's a little bit too complex, but "s/(.*?>)(.*)$/$1/"
How about "s/(.*?<[^>]*>).*$/$1/"? That will still fail on "<foo@bar>"
<foo@bar>, but you'll need a full rfc822 parser to handle the general
case anyway.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
On Tue, Nov 20, 2012 at 08:58:20PM +0100, Andreas Schwab wrote:
How about "s/(.*?<[^>]*>).*$/$1/"? That will still fail on "<foo@bar>"
<foo@bar>, but you'll need a full rfc822 parser to handle the general
case anyway.
That will fail also on "<something>" <foo@bar>.
I think it's good compromise between complexity and correctness.
Felipe, may you check, it again? This time the change is trivial.
Andreas, may I add you in Thanks-to?
Thanks,
Krzysiek
-- >8 --
Subject: [PATCH] git-send-email: remove garbage after email address
In some cases it's very useful to add some additional information
after email in Cc-list, for instance:
"Cc: Stable kernel [off-list ref] #v3.4 v3.5 v3.6"
Currently the git refuses to add such invalid email to Cc-list,
when the Email::Valid perl module is available or just uses whole line
as the email address.
Now in sanitize_address() everything after the email address is
removed, so the resulting line is correct email address and Email::Valid
validates it correctly.
To avoid unnecessary complexity this code assumes that in phrase before
email address '<something>' never exists.
Signed-off-by: Krzysztof Mazur <redacted>
---
git-send-email.perl | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/git-send-email.perl b/git-send-email.perl
index 5a7c29d..157eabc 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -924,6 +924,10 @@ sub quote_subject {
# use the simplest quoting being able to handle the recipient
sub sanitize_address {
my ($recipient) = @_;
+
+ # remove garbage after email address
+ $recipient =~ s/(.*?<[^>]*>).*$/$1/;
+
my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*)/);
if (not $recipient_name) {--
1.8.0.283.gc57d856
On Tue, Nov 20, 2012 at 10:21 PM, Krzysztof Mazur [off-list ref] wrote:
quoted hunk
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -924,6 +924,10 @@ sub quote_subject {
# use the simplest quoting being able to handle the recipient
sub sanitize_address {
my ($recipient) = @_;
+
+ # remove garbage after email address
+ $recipient =~ s/(.*?<[^>]*>).*$/$1/;
That won't work for 'foo@bar.com # test'. I think we should abandon
hopes of properly parsing an email address and just do:
$recipient =~ s/(.*?) #.*$/$1/;
Cheers.
--
Felipe Contreras