Skip to contentSkip to conversation

make git-send-email.perl handle email addresses with no names when Email::Valid is present

PATCH In review Greg KH 4 participants 7 messages Jun 15, 2016

lore
Share & tools
lore

Greg KH

author
#0 lore raw

PATCH 1/1 make git-send-email.perl handle email addresses with no names when Email::Valid is present

When using git-send-email.perl on a changeset that has:
Cc: <[email protected]>
in the body of the description, and the Email::Valid perl module is installed on the system, the email address will be deemed "invalid" for some reason (Email::Valid isn't smart enough to handle this?) and complain and not send the address the email.

Anyway, this tiny patch fixes this problem for me. Note, my perl-foo is quite week, so this could probably be easily done in one line for those with better reg-ex skills.

git-send-email.perl +3 -0
@@ -410,6 +410,9 @@ sub extract_valid_address {
 	return $address if ($address =~ /^($local_part_regexp)$/);
 
 	if ($have_email_valid) {
+		if ($address =~ s/^<//) {
+			$address =~ s/>$//;
+		}
 		return scalar Email::Valid->address($address);
 	} else {
 		# less robust/correct than the monster regexp in Email::Valid,
#1 lore raw
Quoted 6 lines · Greg KH

When using git-send-email.perl on a changeset that has:
Cc: <[email protected]>
in the body of the description, and the Email::Valid perl module is installed on the system, the email address will be deemed "invalid" for some reason (Email::Valid isn't smart enough to handle this?) and complain and not send the address the email.

That appears to be the case.

bad foo
bad <[email protected]>
ok [email protected]
ok Foo <[email protected]>

Quoted 7 lines

Anyway, this tiny patch fixes this problem for me. Note, my perl-foo is quite week, so this could probably be easily done in one line for those with better reg-ex skills.

git-send-email.perl sub extract_valid_address { · line 417

Quoted 8 lines
git-send-email.perl +3 -0
@@ -410,6 +410,9 @@ sub extract_valid_address {
 	return $address if ($address =~ /^($local_part_regexp)$/);
 
 	if ($have_email_valid) {
+		if ($address =~ s/^<//) {
+			$address =~ s/>$//;
+		}
 		return scalar Email::Valid->address($address);
 	} else {

I'd probably do:

	if ($have_email_valid) {
		$address =~ s/^<(.*)>$/$1/;
		return scalar Email::Valid->address($address);
	} else {

instead, but they are moral equivalents.

Thanks for a fix.

author
#2 lore raw
Quoted 34 lines · Junio C Hamano
Quoted 6 lines · Greg KH

When using git-send-email.perl on a changeset that has:
Cc: <[email protected]>
in the body of the description, and the Email::Valid perl module is installed on the system, the email address will be deemed "invalid" for some reason (Email::Valid isn't smart enough to handle this?) and complain and not send the address the email.

That appears to be the case.

bad foo
bad <[email protected]>
ok [email protected]
ok Foo <[email protected]>

Quoted 7 lines

Anyway, this tiny patch fixes this problem for me. Note, my perl-foo is quite week, so this could probably be easily done in one line for those with better reg-ex skills.

git-send-email.perl sub extract_valid_address { · line 417

Quoted 8 lines
git-send-email.perl +3 -0
@@ -410,6 +410,9 @@ sub extract_valid_address {
 	return $address if ($address =~ /^($local_part_regexp)$/);
 
 	if ($have_email_valid) {
+		if ($address =~ s/^<//) {
+			$address =~ s/>$//;
+		}
 		return scalar Email::Valid->address($address);
 	} else {

I'd probably do:

Quoted 2 lines
	if ($have_email_valid) {
		$address =~ s/^<(.*)>$/$1/;

Ah, yeah, that looks better :)

Thanks for the fix,

greg k-h

#3 lore raw
Quoted 11 lines · On Thu, 12 Jul 2007 23:34:14 -0700 Greg KH <[email protected]> wrote:
Quoted 9 lines · Junio C Hamano
Quoted 6 lines · Greg KH

When using git-send-email.perl on a changeset that has:
Cc: <[email protected]>
in the body of the description, and the Email::Valid perl module is installed on the system, the email address will be deemed "invalid" for some reason (Email::Valid isn't smart enough to handle this?) and complain and not send the address the email.

Quoted 6 lines
Quoted 6 lines

That appears to be the case.

bad foo
bad <[email protected]>
ok [email protected]
ok Foo <[email protected]>

This would be a bug in Email::Valid as it complains that the second address fails the rfc822 check, however rfc822 says that the "display name" before the '<' is optional.

Quoted 4 lines
Quoted 4 lines

I'd probably do:

	if ($have_email_valid) {
		$address =~ s/^<(.*)>$/$1/;
	$address =~ s/^\s*<(.*)>\s*$/$1/;
Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
author
#4 lore raw
Quoted 14 lines · Stephen Rothwell
Quoted 13 lines · On Thu, 12 Jul 2007 23:34:14 -0700 Greg KH <[email protected]> wrote:
Quoted 11 lines · Junio C Hamano
Quoted 6 lines · Greg KH

When using git-send-email.perl on a changeset that has:
Cc: <[email protected]>
in the body of the description, and the Email::Valid perl module is installed on the system, the email address will be deemed "invalid" for some reason (Email::Valid isn't smart enough to handle this?) and complain and not send the address the email.

That appears to be the case.

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

bad foo
bad <[email protected]>
ok [email protected]
ok Foo <[email protected]>

This would be a bug in Email::Valid as it complains that the second address fails the rfc822 check, however rfc822 says that the "display name" before the '<' is optional.

I agree, do you know how to get such a fix made?

thanks,

greg k-h

#5 lore raw
Quoted 8 lines · On Fri, 13 Jul 2007 21:00:50 -0700 Greg KH <[email protected]> wrote:
Quoted 4 lines · Stephen Rothwell

This would be a bug in Email::Valid as it complains that the second address fails the rfc822 check, however rfc822 says that the "display name" before the '<' is optional.

I agree, do you know how to get such a fix made?

I would be inclined to make it my distribution's problem :-) i.e. on Debian I would report a bug against libemail-valid-perl.

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#6 lore raw
In reply to Greg KH

Hello,

Quoted 6 lines · Greg KH

When using git-send-email.perl on a changeset that has:
Cc: <[email protected]>
in the body of the description, and the Email::Valid perl module is installed on the system, the email address will be deemed "invalid" for some reason (Email::Valid isn't smart enough to handle this?) and complain and not send the address the email.

The reason is probably that it is indeed invalid. From rfc822:

mailbox = addr-spec / phrase route-addr
addr-spec = local-part "@" domain
phrase = 1*word
word = atom / quoted-string
atom = 1*<any CHAR except specials, SPACE and CTLs>
quoted-string = <"> *(qtext/quoted-pair) <">
route-addr = "<" [route] addr-spec ">"
...

where 1* means "at least one of".

That is, either you must not use <...> or you need a non-empty phrase.

Actually this grammar looks wrong, because as I read it it would not allow spaces between words in phrase. But that's another issue.

BTW: Outlook depends on this, because if you use Cc:
<[email protected]>, it doesn't show anything in the Cc: line---at least in the default configuration.

So I suggest the following:

---- >8 ----
send-email: rfc822 forbids using <address@domain> without a non-empty "phrase"

Email::Valid does respect this considering such a mailbox specification invalid. b06c6bc831cbb9e9eb82fd3ffd5a2b674cd940d0 addressed the issue, but only if Email::Valid is available.

---
 git-send-email.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
git-send-email.perl +1 -1
index 39e433b..a02ab96 100755
@@ -408,8 +408,8 @@ sub extract_valid_address {
 	# check for a local address:
 	return $address if ($address =~ /^($local_part_regexp)$/);
 
+	$address =~ s/^\s*<(.*)>\s*$/$1/;
 	if ($have_email_valid) {
-		$address =~ s/^\s*<(.*)>\s*$/$1/;
 		return scalar Email::Valid->address($address);
 	} else {
 		# less robust/correct than the monster regexp in Email::Valid,
Signature · 7 lines
1.5.3.rc3.943.g14c81

-- 
Uwe Kleine-König

If a lawyer and an IRS agent were both drowning, and you could only save
one of them, would you go to lunch or read the paper?