Merge branch 'lh/send-email-hide-x-mailer'
[gitweb.git] / t / t9001-send-email.sh
index 6a24e59b27fa1365d9df558724faf9cd849147ba..af6a3e8904ab1d953b359707de1e0c9a09b3ce1f 100755 (executable)
@@ -14,22 +14,24 @@ test_expect_success $PREREQ 'prepare reference tree' '
 '
 
 test_expect_success $PREREQ 'Setup helper tool' '
-       (echo "#!$SHELL_PATH"
-       echo shift
-       echo output=1
-       echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
-       echo for a
-       echo do
-       echo "  echo \"!\$a!\""
-       echo "done >commandline\$output"
-       echo "cat > msgtxt\$output"
-       ) >fake.sendmail &&
-       chmod +x ./fake.sendmail &&
+       write_script fake.sendmail <<-\EOF &&
+       shift
+       output=1
+       while test -f commandline$output
+       do
+               output=$(($output+1))
+       done
+       for a
+       do
+               echo "!$a!"
+       done >commandline$output
+       cat >"msgtxt$output"
+       EOF
        git add fake.sendmail &&
        GIT_AUTHOR_NAME="A" git commit -a -m "Second."
 '
 
-clean_fake_sendmail() {
+clean_fake_sendmail () {
        rm -f commandline* msgtxt*
 }
 
@@ -47,9 +49,9 @@ test_no_confirm () {
                --to=nobody@example.com \
                --smtp-server="$(pwd)/fake.sendmail" \
                $@ \
-               $patches > stdout &&
+               $patches >stdout &&
                test_must_fail grep "Send this email" stdout &&
-               > no_confirm_okay
+               >no_confirm_okay
 }
 
 # Exit immediately to prevent hang if a no-confirm test fails
@@ -86,12 +88,12 @@ test_expect_success $PREREQ 'Send patches' '
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >expected <<\EOF
-!nobody@example.com!
-!author@example.com!
-!one@example.com!
-!two@example.com!
-EOF
+       cat >expected <<-\EOF
+       !nobody@example.com!
+       !author@example.com!
+       !one@example.com!
+       !two@example.com!
+       EOF
 '
 
 test_expect_success $PREREQ 'Verify commandline' '
@@ -104,14 +106,14 @@ test_expect_success $PREREQ 'Send patches with --envelope-sender' '
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >expected <<\EOF
-!patch@example.com!
-!-i!
-!nobody@example.com!
-!author@example.com!
-!one@example.com!
-!two@example.com!
-EOF
+       cat >expected <<-\EOF
+       !patch@example.com!
+       !-i!
+       !nobody@example.com!
+       !author@example.com!
+       !one@example.com!
+       !two@example.com!
+       EOF
 '
 
 test_expect_success $PREREQ 'Verify commandline' '
@@ -124,14 +126,14 @@ test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >expected <<\EOF
-!nobody@example.com!
-!-i!
-!nobody@example.com!
-!author@example.com!
-!one@example.com!
-!two@example.com!
-EOF
+       cat >expected <<-\EOF
+       !nobody@example.com!
+       !-i!
+       !nobody@example.com!
+       !author@example.com!
+       !one@example.com!
+       !two@example.com!
+       EOF
 '
 
 test_expect_success $PREREQ 'Verify commandline' '
@@ -240,6 +242,13 @@ test_expect_success $PREREQ 'non-ascii self name is suppressed' "
                'non_ascii_self_suppressed'
 "
 
+# This name is long enough to force format-patch to split it into multiple
+# encoded-words, assuming it uses UTF-8 with the "Q" encoding.
+test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
+       test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
+               'long_non_ascii_self_suppressed'
+"
+
 test_expect_success $PREREQ 'sanitized self name is suppressed' "
        test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
                'self_name_sanitized_suppressed'
@@ -307,11 +316,9 @@ test_expect_success $PREREQ 'tocmd works' '
        clean_fake_sendmail &&
        cp $patches tocmd.patch &&
        echo tocmd--tocmd@example.com >>tocmd.patch &&
-       {
-         echo "#!$SHELL_PATH"
-         echo sed -n -e s/^tocmd--//p \"\$1\"
-       } > tocmd-sed &&
-       chmod +x tocmd-sed &&
+       write_script tocmd-sed <<-\EOF &&
+       sed -n -e "s/^tocmd--//p" "$1"
+       EOF
        git send-email \
                --from="Example <nobody@example.com>" \
                --to-cmd=./tocmd-sed \
@@ -325,11 +332,9 @@ test_expect_success $PREREQ 'cccmd works' '
        clean_fake_sendmail &&
        cp $patches cccmd.patch &&
        echo "cccmd--  cccmd@example.com" >>cccmd.patch &&
-       {
-         echo "#!$SHELL_PATH"
-         echo sed -n -e s/^cccmd--//p \"\$1\"
-       } > cccmd-sed &&
-       chmod +x cccmd-sed &&
+       write_script cccmd-sed <<-\EOF &&
+       sed -n -e "s/^cccmd--//p" "$1"
+       EOF
        git send-email \
                --from="Example <nobody@example.com>" \
                --to=nobody@example.com \
@@ -367,7 +372,7 @@ test_expect_success $PREREQ 'Author From: in message body' '
                --to=nobody@example.com \
                --smtp-server="$(pwd)/fake.sendmail" \
                $patches &&
-       sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
+       sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
        grep "From: A <author@example.com>" msgbody1
 '
 
@@ -378,7 +383,7 @@ test_expect_success $PREREQ 'Author From: not in message body' '
                --to=nobody@example.com \
                --smtp-server="$(pwd)/fake.sendmail" \
                $patches &&
-       sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
+       sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
        ! grep "From: A <author@example.com>" msgbody1
 '
 
@@ -459,10 +464,9 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
 '
 
 test_expect_success $PREREQ 'setup fake editor' '
-       (echo "#!$SHELL_PATH" &&
-        echo "echo fake edit >>\"\$1\""
-       ) >fake-editor &&
-       chmod +x fake-editor
+       write_script fake-editor <<-\EOF
+       echo fake edit >>"$1"
+       EOF
 '
 
 test_set_editor "$(pwd)/fake-editor"
@@ -598,8 +602,9 @@ EOF
 "
 
 test_expect_success $PREREQ 'sendemail.cccmd' '
-       echo echo cc-cmd@example.com > cccmd &&
-       chmod +x cccmd &&
+       write_script cccmd <<-\EOF &&
+       echo cc-cmd@example.com
+       EOF
        git config sendemail.cccmd ./cccmd &&
        test_suppression cccmd
 '
@@ -792,7 +797,7 @@ test_confirm () {
                --from="Example <nobody@example.com>" \
                --to=nobody@example.com \
                --smtp-server="$(pwd)/fake.sendmail" \
-               $@ $patches > stdout &&
+               $@ $patches >stdout &&
        grep "Send this email" stdout
 }
 
@@ -840,7 +845,7 @@ test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
                        --from="Example <nobody@example.com>" \
                        --to=nobody@example.com \
                        --smtp-server="$(pwd)/fake.sendmail" \
-                       outdir/*.patch < /dev/null
+                       outdir/*.patch </dev/null
        ret="$?"
        git config sendemail.confirm ${CONFIRM:-never}
        test $ret = "0"
@@ -855,7 +860,7 @@ test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
                        --from="Example <nobody@example.com>" \
                        --to=nobody@example.com \
                        --smtp-server="$(pwd)/fake.sendmail" \
-                       $patches < /dev/null
+                       $patches </dev/null
        ret="$?"
        git config sendemail.confirm ${CONFIRM:-never}
        test $ret = "0"
@@ -891,10 +896,9 @@ test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
 
 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
        clean_fake_sendmail &&
-       (echo "#!$SHELL_PATH" &&
-        echo "echo utf8 body: àéìöú >>\"\$1\""
-       ) >fake-editor-utf8 &&
-       chmod +x fake-editor-utf8 &&
+       write_script fake-editor-utf8 <<-\EOF &&
+       echo "utf8 body: àéìöú" >>"$1"
+       EOF
        GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
        git send-email \
                --compose --subject foo \
@@ -908,15 +912,16 @@ test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
 
 test_expect_success $PREREQ '--compose respects user mime type' '
        clean_fake_sendmail &&
-       (echo "#!$SHELL_PATH" &&
-        echo "(echo MIME-Version: 1.0"
-        echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
-        echo " echo Content-Transfer-Encoding: 8bit"
-        echo " echo Subject: foo"
-        echo " echo "
-        echo " echo utf8 body: àéìöú) >\"\$1\""
-       ) >fake-editor-utf8-mime &&
-       chmod +x fake-editor-utf8-mime &&
+       write_script fake-editor-utf8-mime <<-\EOF &&
+       cat >"$1" <<-\EOM
+       MIME-Version: 1.0
+       Content-Type: text/plain; charset=iso-8859-1
+       Content-Transfer-Encoding: 8bit
+       Subject: foo
+
+       utf8 body: àéìöú
+       EOM
+       EOF
        GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
        git send-email \
                --compose --subject foo \
@@ -972,10 +977,9 @@ test_expect_success $PREREQ 'utf8 sender is not duplicated' '
 test_expect_success $PREREQ 'sendemail.composeencoding works' '
        clean_fake_sendmail &&
        git config sendemail.composeencoding iso-8859-1 &&
-       (echo "#!$SHELL_PATH" &&
-        echo "echo utf8 body: àéìöú >>\"\$1\""
-       ) >fake-editor-utf8 &&
-       chmod +x fake-editor-utf8 &&
+       write_script fake-editor-utf8 <<-\EOF &&
+       echo "utf8 body: àéìöú" >>"$1"
+       EOF
        GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
        git send-email \
                --compose --subject foo \
@@ -989,10 +993,9 @@ test_expect_success $PREREQ 'sendemail.composeencoding works' '
 
 test_expect_success $PREREQ '--compose-encoding works' '
        clean_fake_sendmail &&
-       (echo "#!$SHELL_PATH" &&
-        echo "echo utf8 body: àéìöú >>\"\$1\""
-       ) >fake-editor-utf8 &&
-       chmod +x fake-editor-utf8 &&
+       write_script fake-editor-utf8 <<-\EOF &&
+       echo "utf8 body: àéìöú" >>"$1"
+       EOF
        GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
        git send-email \
                --compose-encoding iso-8859-1 \
@@ -1008,10 +1011,9 @@ test_expect_success $PREREQ '--compose-encoding works' '
 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
        clean_fake_sendmail &&
        git config sendemail.composeencoding iso-8859-1 &&
-       (echo "#!$SHELL_PATH" &&
-        echo "echo utf8 body: àéìöú >>\"\$1\""
-       ) >fake-editor-utf8 &&
-       chmod +x fake-editor-utf8 &&
+       write_script fake-editor-utf8 <<-\EOF &&
+       echo "utf8 body: àéìöú" >>"$1"
+       EOF
        GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
        git send-email \
                --compose-encoding iso-8859-2 \
@@ -1039,7 +1041,7 @@ test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
 '
 
 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
-       echo master > master &&
+       echo master >master &&
        git add master &&
        git commit -m"add master" &&
        test_must_fail git send-email --dry-run master 2>errors &&
@@ -1197,7 +1199,7 @@ test_expect_success $PREREQ 'To headers from files reset each patch' '
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >email-using-8bit <<EOF
+cat >email-using-8bit <<\EOF
 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
 Message-Id: <bogus-message-id@example.com>
 From: author@example.com
@@ -1209,9 +1211,7 @@ EOF
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >expected <<EOF
-Subject: subject goes here
-EOF
+       echo "Subject: subject goes here" >expected
 '
 
 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
@@ -1226,11 +1226,11 @@ test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >content-type-decl <<EOF
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-EOF
+       cat >content-type-decl <<-\EOF
+       MIME-Version: 1.0
+       Content-Type: text/plain; charset=UTF-8
+       Content-Transfer-Encoding: 8bit
+       EOF
 '
 
 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
@@ -1270,21 +1270,21 @@ test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >email-using-8bit <<EOF
-From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
-Message-Id: <bogus-message-id@example.com>
-From: author@example.com
-Date: Sat, 12 Jun 2010 15:53:58 +0200
-Subject: Dieser Betreff enthält auch einen Umlaut!
-
-Nothing to see here.
-EOF
+       cat >email-using-8bit <<-\EOF
+       From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
+       Message-Id: <bogus-message-id@example.com>
+       From: author@example.com
+       Date: Sat, 12 Jun 2010 15:53:58 +0200
+       Subject: Dieser Betreff enthält auch einen Umlaut!
+
+       Nothing to see here.
+       EOF
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >expected <<EOF
-Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
-EOF
+       cat >expected <<-\EOF
+       Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
+       EOF
 '
 
 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
@@ -1299,16 +1299,16 @@ test_expect_success $PREREQ '--8bit-encoding also treats subject' '
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >email-using-8bit <<EOF
-From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
-Message-Id: <bogus-message-id@example.com>
-From: A U Thor <author@example.com>
-Date: Sat, 12 Jun 2010 15:53:58 +0200
-Content-Type: text/plain; charset=UTF-8
-Subject: Nothing to see here.
-
-Dieser Betreff enthält auch einen Umlaut!
-EOF
+       cat >email-using-8bit <<-\EOF
+       From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
+       Message-Id: <bogus-message-id@example.com>
+       From: A U Thor <author@example.com>
+       Date: Sat, 12 Jun 2010 15:53:58 +0200
+       Content-Type: text/plain; charset=UTF-8
+       Subject: Nothing to see here.
+
+       Dieser Betreff enthält auch einen Umlaut!
+       EOF
 '
 
 test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
@@ -1348,9 +1348,9 @@ test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >expected <<EOF
-Dieser Betreff enth=C3=A4lt auch einen Umlaut!
-EOF
+       cat >expected <<-\EOF
+       Dieser Betreff enth=C3=A4lt auch einen Umlaut!
+       EOF
 '
 
 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
@@ -1365,9 +1365,9 @@ test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printab
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >expected <<EOF
-RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
-EOF
+       cat >expected <<-\EOF
+       RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
+       EOF
 '
 
 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
@@ -1382,18 +1382,18 @@ test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >email-using-qp <<EOF
-From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
-Message-Id: <bogus-message-id@example.com>
-From: A U Thor <author@example.com>
-Date: Sat, 12 Jun 2010 15:53:58 +0200
-MIME-Version: 1.0
-Content-Transfer-Encoding: quoted-printable
-Content-Type: text/plain; charset=UTF-8
-Subject: Nothing to see here.
-
-Dieser Betreff enth=C3=A4lt auch einen Umlaut!
-EOF
+       cat >email-using-qp <<-\EOF
+       From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
+       Message-Id: <bogus-message-id@example.com>
+       From: A U Thor <author@example.com>
+       Date: Sat, 12 Jun 2010 15:53:58 +0200
+       MIME-Version: 1.0
+       Content-Transfer-Encoding: quoted-printable
+       Content-Type: text/plain; charset=UTF-8
+       Subject: Nothing to see here.
+
+       Dieser Betreff enth=C3=A4lt auch einen Umlaut!
+       EOF
 '
 
 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
@@ -1408,7 +1408,7 @@ test_expect_success $PREREQ 'convert from quoted-printable to base64' '
 '
 
 test_expect_success $PREREQ 'setup expect' "
-tr -d '\\015' | tr '%' '\\015' > email-using-crlf <<EOF
+tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
 Message-Id: <bogus-message-id@example.com>
 From: A U Thor <author@example.com>
@@ -1421,9 +1421,9 @@ EOF
 "
 
 test_expect_success $PREREQ 'setup expect' '
-cat >expected <<EOF
-Look, I have a CRLF and an =3D sign!=0D
-EOF
+       cat >expected <<-\EOF
+       Look, I have a CRLF and an =3D sign!=0D
+       EOF
 '
 
 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
@@ -1438,9 +1438,9 @@ test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printabl
 '
 
 test_expect_success $PREREQ 'setup expect' '
-cat >expected <<EOF
-TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
-EOF
+       cat >expected <<-\EOF
+       TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
+       EOF
 '
 
 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
@@ -1564,4 +1564,37 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
        grep "^!someone@example\.org!$" commandline1
 '
 
+do_xmailer_test () {
+       expected=$1 params=$2 &&
+       git format-patch -1 &&
+       git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=someone@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               $params \
+               0001-*.patch \
+               2>errors >out &&
+       { grep '^X-Mailer:' out || :; } >mailer &&
+       test_line_count = $expected mailer
+}
+
+test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
+       do_xmailer_test 1 "--xmailer" &&
+       do_xmailer_test 0 "--no-xmailer"
+'
+
+test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
+       test_config sendemail.xmailer true &&
+       do_xmailer_test 1 "" &&
+       do_xmailer_test 0 "--no-xmailer" &&
+       do_xmailer_test 1 "--xmailer"
+'
+
+test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
+       test_config sendemail.xmailer false &&
+       do_xmailer_test 0 "" &&
+       do_xmailer_test 0 "--no-xmailer" &&
+       do_xmailer_test 1 "--xmailer"
+'
+
 test_done