From e3fdbcc8e16474f50749a384175f78908c4f038e Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Thu, 13 Oct 2016 07:47:27 +0200 Subject: parse_mailboxes: accept extra text after <...> address The test introduced in this commit succeeds without the patch to Git.pm if Mail::Address is installed, but fails otherwise because our in-house parser does not accept any text after the email address. They succeed both with and without Mail::Address after this commit. Mail::Address accepts extra text and considers it as part of the name, iff the address is surrounded with <...>. The implementation mimics this behavior as closely as possible. This mostly restores the behavior we had before b1c8a11 (send-email: allow multiple emails using --cc, --to and --bcc, 2015-06-30), but we keep the possibility to handle comma-separated lists. Reported-by: Larry Finger Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- perl/Git.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 19ef081103..42e0895ef7 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -878,6 +878,7 @@ sub parse_mailboxes { # divide the string in tokens of the above form my $re_token = qr/(?:$re_quote|$re_word|$re_comment|\S)/; my @tokens = map { $_ =~ /\s*($re_token)\s*/g } @_; + my $end_of_addr_seen = 0; # add a delimiter to simplify treatment for the last mailbox push @tokens, ","; @@ -887,10 +888,10 @@ sub parse_mailboxes { if ($token =~ /^[,;]$/) { # if buffer still contains undeterminated strings # append it at the end of @address or @phrase - if (@address) { - push @address, @buffer; - } else { + if ($end_of_addr_seen) { push @phrase, @buffer; + } else { + push @address, @buffer; } my $str_phrase = join ' ', @phrase; @@ -914,16 +915,16 @@ sub parse_mailboxes { push @addr_list, $str_mailbox if ($str_mailbox); @phrase = @address = @comment = @buffer = (); + $end_of_addr_seen = 0; } elsif ($token =~ /^\(/) { push @comment, $token; } elsif ($token eq "<") { push @phrase, (splice @address), (splice @buffer); } elsif ($token eq ">") { + $end_of_addr_seen = 1; push @address, (splice @buffer); - } elsif ($token eq "@") { + } elsif ($token eq "@" && !$end_of_addr_seen) { push @address, (splice @buffer), "@"; - } elsif ($token eq ".") { - push @address, (splice @buffer), "."; } else { push @buffer, $token; } -- cgit v1.2.3 From dcfafc5214e6af277aa8565af4f63b20046d65bf Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Fri, 21 Oct 2016 11:20:24 +0200 Subject: Git.pm: add comment pointing to t9000 parse_mailboxes should probably eventually be completely equivalent to Mail::Address, and if this happens we can drop the Mail::Address dependency. Add a comment in the code reminding the current state of the code, and point to the corresponding failing test to help future contributors to get it right. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- perl/Git.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 42e0895ef7..8bb2b7c7e3 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -870,6 +870,8 @@ Return an array of mailboxes extracted from a string. =cut +# Very close to Mail::Address's parser, but we still have minor +# differences in some cases (see t9000 for examples). sub parse_mailboxes { my $re_comment = qr/\((?:[^)]*)\)/; my $re_quote = qr/"(?:[^\"\\]|\\.)*"/; -- cgit v1.2.3