Merge branch 'mm/send-email-cc-cruft-after-address' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 29 Nov 2016 21:27:54 +0000 (13:27 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 Nov 2016 21:27:55 +0000 (13:27 -0800)
"git send-email" attempts to pick up valid e-mails from the
trailers, but people in real world write non-addresses there, like
"Cc: Stable <add@re.ss> # 4.8+", which broke the output depending
on the availability and vintage of Mail::Address perl module.

* mm/send-email-cc-cruft-after-address:
Git.pm: add comment pointing to t9000
t9000-addresses: update expected results after fix
parse_mailboxes: accept extra text after <...> address

perl/Git.pm
t/t9000/test.pl
t/t9001-send-email.sh
index ce7e4e8da3947bb2c527c49d6d09e1e49b0392c3..864123fe8e61f7469b58fef06a04edeb561edd53 100644 (file)
@@ -871,6 +871,8 @@ sub ident_person {
 
 =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/"(?:[^\"\\]|\\.)*"/;
@@ -879,6 +881,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, ",";
@@ -888,10 +891,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;
@@ -915,16 +918,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;
                }
index 2d05d3eeab3f801fcf74a93c9305d067ac628937..dfeaa9c6550eac1f9beeca64682cecfebfe2c7d3 100755 (executable)
        q["Jane\" Doe" <jdoe@example.com>],
        q[Doe, jane <jdoe@example.com>],
        q["Jane Doe <jdoe@example.com>],
-       q['Jane 'Doe' <jdoe@example.com>]);
+       q['Jane 'Doe' <jdoe@example.com>],
+       q[Jane@:;\.,()<>Doe <jdoe@example.com>],
+       q[Jane <jdoe@example.com> Doe],
+       q[<jdoe@example.com> Jane Doe]);
 
 my @known_failure_list = (q[Jane\ Doe <jdoe@example.com>],
        q["Doe, Ja"ne <jdoe@example.com>],
        q["Doe, Katarina" Jane <jdoe@example.com>],
-       q[Jane@:;\.,()<>Doe <jdoe@example.com>],
        q[Jane jdoe@example.com],
-       q[<jdoe@example.com> Jane Doe],
-       q[Jane <jdoe@example.com> Doe],
        q["Jane "Kat"a" ri"na" ",Doe" <jdoe@example.com>],
        q[Jane Doe],
        q[Jane "Doe <jdoe@example.com>"],
index b3355d2c7016e55e99a465414f230569c3807230..3dc4a3454d223d37e85de6fa4ae8656046370e99 100755 (executable)
@@ -140,6 +140,35 @@ test_expect_success $PREREQ 'Verify commandline' '
        test_cmp expected commandline1
 '
 
+test_expect_success $PREREQ 'setup expect for cc trailer' "
+cat >expected-cc <<\EOF
+!recipient@example.com!
+!author@example.com!
+!one@example.com!
+!two@example.com!
+!three@example.com!
+!four@example.com!
+!five@example.com!
+EOF
+"
+
+test_expect_success $PREREQ 'cc trailer with various syntax' '
+       test_commit cc-trailer &&
+       test_when_finished "git reset --hard HEAD^" &&
+       git commit --amend -F - <<-EOF &&
+       Test Cc: trailers.
+
+       Cc: one@example.com
+       Cc: <two@example.com> # this is part of the name
+       Cc: <three@example.com>, <four@example.com> # not.five@example.com
+       Cc: "Some # Body" <five@example.com> [part.of.name.too]
+       EOF
+       clean_fake_sendmail &&
+       git send-email -1 --to=recipient@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" &&
+       test_cmp expected-cc commandline1
+'
+
 test_expect_success $PREREQ 'setup expect' "
 cat >expected-show-all-headers <<\EOF
 0001-Second.patch