Code

send-email: ensure quoted addresses are rfc2047 encoded
authorJay Soffian <jaysoffian@gmail.com>
Tue, 31 Mar 2009 16:22:14 +0000 (12:22 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Apr 2009 17:46:21 +0000 (10:46 -0700)
sanitize_address assumes that quoted addresses (e.g., "first last"
<first.last@example.com) do not need rfc2047 encoding, but this is
not always the case.

For example, various places in send-email extract addresses using
parse_address_line. parse_address_line returns the addresses already
quoted (e.g., "first last" <first.last@example.com), but not rfc2047
encoded.

This patch makes sanitize_address stricter about what needs rfc2047
encoding and adds a test demonstrating where I noticed the problem.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-send-email.perl
t/t9001-send-email.sh

index fc153f9459a9b39aab159b16adf5d2b884e5285a..6bbdfec84983b23d3ab380e63975987b6078b4ca 100755 (executable)
@@ -776,12 +776,13 @@ sub sanitize_address
        }
 
        # if recipient_name is already quoted, do nothing
-       if ($recipient_name =~ /^(".*"|=\?utf-8\?q\?.*\?=)$/) {
+       if ($recipient_name =~ /^("[[:ascii:]]*"|=\?utf-8\?q\?.*\?=)$/) {
                return $recipient;
        }
 
        # rfc2047 is needed if a non-ascii char is included
        if ($recipient_name =~ /[^[:ascii:]]/) {
+               $recipient_name =~ s/^"(.*)"$/$1/;
                $recipient_name = quote_rfc2047($recipient_name);
        }
 
index 84238f7197757ee1b5cc8d1e2d275d85ee09f915..192b97b2d6cdc16045e5c71b7beaf03713e6a631 100755 (executable)
@@ -505,6 +505,19 @@ test_expect_success 'confirm doesnt loop forever' '
        test $ret = "0"
 '
 
+test_expect_success 'utf8 Cc is rfc2047 encoded' '
+       clean_fake_sendmail &&
+       rm -fr outdir &&
+       git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
+       git send-email \
+       --from="Example <nobody@example.com>" \
+       --to=nobody@example.com \
+       --smtp-server="$(pwd)/fake.sendmail" \
+       outdir/*.patch &&
+       grep "^Cc:" msgtxt1 |
+       grep "=?utf-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
+'
+
 test_expect_success '--compose adds MIME for utf8 body' '
        clean_fake_sendmail &&
        (echo "#!$SHELL_PATH" &&