t / t9001-send-email.shon commit t/send-email: test suppress-cc=self on cccmd (d6ee445)
   1#!/bin/sh
   2
   3test_description='git send-email'
   4. ./test-lib.sh
   5
   6# May be altered later in the test
   7PREREQ="PERL"
   8
   9test_expect_success $PREREQ \
  10    'prepare reference tree' \
  11    'echo "1A quick brown fox jumps over the" >file &&
  12     echo "lazy dog" >>file &&
  13     git add file &&
  14     GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
  15
  16test_expect_success $PREREQ \
  17    'Setup helper tool' \
  18    '(echo "#!$SHELL_PATH"
  19      echo shift
  20      echo output=1
  21      echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
  22      echo for a
  23      echo do
  24      echo "  echo \"!\$a!\""
  25      echo "done >commandline\$output"
  26      test_have_prereq MINGW && echo "dos2unix commandline\$output"
  27      echo "cat > msgtxt\$output"
  28      ) >fake.sendmail &&
  29     chmod +x ./fake.sendmail &&
  30     git add fake.sendmail &&
  31     GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
  32
  33clean_fake_sendmail() {
  34        rm -f commandline* msgtxt*
  35}
  36
  37test_expect_success $PREREQ 'Extract patches' '
  38    patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
  39'
  40
  41# Test no confirm early to ensure remaining tests will not hang
  42test_no_confirm () {
  43        rm -f no_confirm_okay
  44        echo n | \
  45                GIT_SEND_EMAIL_NOTTY=1 \
  46                git send-email \
  47                --from="Example <from@example.com>" \
  48                --to=nobody@example.com \
  49                --smtp-server="$(pwd)/fake.sendmail" \
  50                $@ \
  51                $patches > stdout &&
  52                test_must_fail grep "Send this email" stdout &&
  53                > no_confirm_okay
  54}
  55
  56# Exit immediately to prevent hang if a no-confirm test fails
  57check_no_confirm () {
  58        if ! test -f no_confirm_okay
  59        then
  60                say 'confirm test failed; skipping remaining tests to prevent hanging'
  61                PREREQ="$PREREQ,CHECK_NO_CONFIRM"
  62        fi
  63        return 0
  64}
  65
  66test_expect_success $PREREQ 'No confirm with --suppress-cc' '
  67        test_no_confirm --suppress-cc=sob &&
  68        check_no_confirm
  69'
  70
  71
  72test_expect_success $PREREQ 'No confirm with --confirm=never' '
  73        test_no_confirm --confirm=never &&
  74        check_no_confirm
  75'
  76
  77# leave sendemail.confirm set to never after this so that none of the
  78# remaining tests prompt unintentionally.
  79test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
  80        git config sendemail.confirm never &&
  81        test_no_confirm --compose --subject=foo &&
  82        check_no_confirm
  83'
  84
  85test_expect_success $PREREQ 'Send patches' '
  86     git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
  87'
  88
  89test_expect_success $PREREQ 'setup expect' '
  90cat >expected <<\EOF
  91!nobody@example.com!
  92!author@example.com!
  93!one@example.com!
  94!two@example.com!
  95EOF
  96'
  97
  98test_expect_success $PREREQ \
  99    'Verify commandline' \
 100    'test_cmp expected commandline1'
 101
 102test_expect_success $PREREQ 'Send patches with --envelope-sender' '
 103    clean_fake_sendmail &&
 104     git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
 105'
 106
 107test_expect_success $PREREQ 'setup expect' '
 108cat >expected <<\EOF
 109!patch@example.com!
 110!-i!
 111!nobody@example.com!
 112!author@example.com!
 113!one@example.com!
 114!two@example.com!
 115EOF
 116'
 117
 118test_expect_success $PREREQ \
 119    'Verify commandline' \
 120    'test_cmp expected commandline1'
 121
 122test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
 123    clean_fake_sendmail &&
 124     git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
 125'
 126
 127test_expect_success $PREREQ 'setup expect' '
 128cat >expected <<\EOF
 129!nobody@example.com!
 130!-i!
 131!nobody@example.com!
 132!author@example.com!
 133!one@example.com!
 134!two@example.com!
 135EOF
 136'
 137
 138test_expect_success $PREREQ \
 139    'Verify commandline' \
 140    'test_cmp expected commandline1'
 141
 142test_expect_success $PREREQ 'setup expect' "
 143cat >expected-show-all-headers <<\EOF
 1440001-Second.patch
 145(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 146(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 147(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 148Dry-OK. Log says:
 149Server: relay.example.com
 150MAIL FROM:<from@example.com>
 151RCPT TO:<to@example.com>
 152RCPT TO:<cc@example.com>
 153RCPT TO:<author@example.com>
 154RCPT TO:<one@example.com>
 155RCPT TO:<two@example.com>
 156RCPT TO:<bcc@example.com>
 157From: Example <from@example.com>
 158To: to@example.com
 159Cc: cc@example.com,
 160        A <author@example.com>,
 161        One <one@example.com>,
 162        two@example.com
 163Subject: [PATCH 1/1] Second.
 164Date: DATE-STRING
 165Message-Id: MESSAGE-ID-STRING
 166X-Mailer: X-MAILER-STRING
 167In-Reply-To: <unique-message-id@example.com>
 168References: <unique-message-id@example.com>
 169
 170Result: OK
 171EOF
 172"
 173
 174test_suppress_self () {
 175        test_commit $3 &&
 176        test_when_finished "git reset --hard HEAD^" &&
 177
 178        write_script cccmd-sed <<-EOF &&
 179                sed -n -e s/^cccmd--//p "\$1"
 180        EOF
 181
 182        git commit --amend --author="$1 <$2>" -F - &&
 183        clean_fake_sendmail &&
 184        git format-patch --stdout -1 >"suppress-self-$3.patch" &&
 185
 186        git send-email --from="$1 <$2>" \
 187                --to=nobody@example.com \
 188                --cc-cmd=./cccmd-sed \
 189                --suppress-cc=self \
 190                --smtp-server="$(pwd)/fake.sendmail" \
 191                suppress-self-$3.patch &&
 192
 193        mv msgtxt1 msgtxt1-$3 &&
 194        sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
 195        >"expected-no-cc-$3" &&
 196
 197        (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
 198         test_cmp expected-no-cc-$3 actual-no-cc-$3)
 199}
 200
 201test_suppress_self_unquoted () {
 202        test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
 203                test suppress-cc.self unquoted-$3 with name $1 email $2
 204
 205                unquoted-$3
 206
 207                cccmd--$1 <$2>
 208
 209                Cc: $1 <$2>
 210                Signed-off-by: $1 <$2>
 211        EOF
 212}
 213
 214test_expect_success $PREREQ 'self name is suppressed' "
 215        test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
 216                'self_name_suppressed'
 217"
 218
 219test_expect_success $PREREQ 'Show all headers' '
 220        git send-email \
 221                --dry-run \
 222                --suppress-cc=sob \
 223                --from="Example <from@example.com>" \
 224                --to=to@example.com \
 225                --cc=cc@example.com \
 226                --bcc=bcc@example.com \
 227                --in-reply-to="<unique-message-id@example.com>" \
 228                --smtp-server relay.example.com \
 229                $patches |
 230        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
 231                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
 232                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
 233                >actual-show-all-headers &&
 234        test_cmp expected-show-all-headers actual-show-all-headers
 235'
 236
 237test_expect_success $PREREQ 'Prompting works' '
 238        clean_fake_sendmail &&
 239        (echo "to@example.com"
 240         echo ""
 241        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
 242                --smtp-server="$(pwd)/fake.sendmail" \
 243                $patches \
 244                2>errors &&
 245                grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
 246                grep "^To: to@example.com\$" msgtxt1
 247'
 248
 249test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
 250        clean_fake_sendmail &&
 251        (sane_unset GIT_AUTHOR_NAME &&
 252        sane_unset GIT_AUTHOR_EMAIL &&
 253        sane_unset GIT_COMMITTER_NAME &&
 254        sane_unset GIT_COMMITTER_EMAIL &&
 255        GIT_SEND_EMAIL_NOTTY=1 git send-email \
 256                --smtp-server="$(pwd)/fake.sendmail" \
 257                --to=to@example.com \
 258                $patches </dev/null 2>errors
 259        )
 260'
 261
 262test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
 263        clean_fake_sendmail &&
 264        (sane_unset GIT_AUTHOR_NAME &&
 265        sane_unset GIT_AUTHOR_EMAIL &&
 266        sane_unset GIT_COMMITTER_NAME &&
 267        sane_unset GIT_COMMITTER_EMAIL &&
 268        GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
 269        test_must_fail git send-email \
 270                --smtp-server="$(pwd)/fake.sendmail" \
 271                --to=to@example.com \
 272                $patches </dev/null 2>errors &&
 273        test_i18ngrep "tell me who you are" errors
 274        )
 275'
 276
 277test_expect_success $PREREQ 'tocmd works' '
 278        clean_fake_sendmail &&
 279        cp $patches tocmd.patch &&
 280        echo tocmd--tocmd@example.com >>tocmd.patch &&
 281        {
 282          echo "#!$SHELL_PATH"
 283          echo sed -n -e s/^tocmd--//p \"\$1\"
 284        } > tocmd-sed &&
 285        chmod +x tocmd-sed &&
 286        git send-email \
 287                --from="Example <nobody@example.com>" \
 288                --to-cmd=./tocmd-sed \
 289                --smtp-server="$(pwd)/fake.sendmail" \
 290                tocmd.patch \
 291                &&
 292        grep "^To: tocmd@example.com" msgtxt1
 293'
 294
 295test_expect_success $PREREQ 'cccmd works' '
 296        clean_fake_sendmail &&
 297        cp $patches cccmd.patch &&
 298        echo "cccmd--  cccmd@example.com" >>cccmd.patch &&
 299        {
 300          echo "#!$SHELL_PATH"
 301          echo sed -n -e s/^cccmd--//p \"\$1\"
 302        } > cccmd-sed &&
 303        chmod +x cccmd-sed &&
 304        git send-email \
 305                --from="Example <nobody@example.com>" \
 306                --to=nobody@example.com \
 307                --cc-cmd=./cccmd-sed \
 308                --smtp-server="$(pwd)/fake.sendmail" \
 309                cccmd.patch \
 310                &&
 311        grep "^ cccmd@example.com" msgtxt1
 312'
 313
 314test_expect_success $PREREQ 'reject long lines' '
 315        z8=zzzzzzzz &&
 316        z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
 317        z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
 318        clean_fake_sendmail &&
 319        cp $patches longline.patch &&
 320        echo $z512$z512 >>longline.patch &&
 321        test_must_fail git send-email \
 322                --from="Example <nobody@example.com>" \
 323                --to=nobody@example.com \
 324                --smtp-server="$(pwd)/fake.sendmail" \
 325                $patches longline.patch \
 326                2>errors &&
 327        grep longline.patch errors
 328'
 329
 330test_expect_success $PREREQ 'no patch was sent' '
 331        ! test -e commandline1
 332'
 333
 334test_expect_success $PREREQ 'Author From: in message body' '
 335        clean_fake_sendmail &&
 336        git send-email \
 337                --from="Example <nobody@example.com>" \
 338                --to=nobody@example.com \
 339                --smtp-server="$(pwd)/fake.sendmail" \
 340                $patches &&
 341        sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
 342        grep "From: A <author@example.com>" msgbody1
 343'
 344
 345test_expect_success $PREREQ 'Author From: not in message body' '
 346        clean_fake_sendmail &&
 347        git send-email \
 348                --from="A <author@example.com>" \
 349                --to=nobody@example.com \
 350                --smtp-server="$(pwd)/fake.sendmail" \
 351                $patches &&
 352        sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
 353        ! grep "From: A <author@example.com>" msgbody1
 354'
 355
 356test_expect_success $PREREQ 'allow long lines with --no-validate' '
 357        git send-email \
 358                --from="Example <nobody@example.com>" \
 359                --to=nobody@example.com \
 360                --smtp-server="$(pwd)/fake.sendmail" \
 361                --novalidate \
 362                $patches longline.patch \
 363                2>errors
 364'
 365
 366test_expect_success $PREREQ 'Invalid In-Reply-To' '
 367        clean_fake_sendmail &&
 368        git send-email \
 369                --from="Example <nobody@example.com>" \
 370                --to=nobody@example.com \
 371                --in-reply-to=" " \
 372                --smtp-server="$(pwd)/fake.sendmail" \
 373                $patches \
 374                2>errors &&
 375        ! grep "^In-Reply-To: < *>" msgtxt1
 376'
 377
 378test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
 379        clean_fake_sendmail &&
 380        (echo "From Example <from@example.com>"
 381         echo "To Example <to@example.com>"
 382         echo ""
 383        ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
 384                --smtp-server="$(pwd)/fake.sendmail" \
 385                $patches 2>errors &&
 386        ! grep "^In-Reply-To: < *>" msgtxt1
 387'
 388
 389test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
 390        clean_fake_sendmail &&
 391        echo "<unique-message-id@example.com>" >expect &&
 392        git send-email \
 393                --from="Example <nobody@example.com>" \
 394                --to=nobody@example.com \
 395                --nochain-reply-to \
 396                --in-reply-to="$(cat expect)" \
 397                --smtp-server="$(pwd)/fake.sendmail" \
 398                $patches $patches $patches \
 399                2>errors &&
 400        # The first message is a reply to --in-reply-to
 401        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
 402        test_cmp expect actual &&
 403        # Second and subsequent messages are replies to the first one
 404        sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
 405        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
 406        test_cmp expect actual &&
 407        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
 408        test_cmp expect actual
 409'
 410
 411test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
 412        clean_fake_sendmail &&
 413        echo "<unique-message-id@example.com>" >expect &&
 414        git send-email \
 415                --from="Example <nobody@example.com>" \
 416                --to=nobody@example.com \
 417                --chain-reply-to \
 418                --in-reply-to="$(cat expect)" \
 419                --smtp-server="$(pwd)/fake.sendmail" \
 420                $patches $patches $patches \
 421                2>errors &&
 422        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
 423        test_cmp expect actual &&
 424        sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
 425        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
 426        test_cmp expect actual &&
 427        sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
 428        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
 429        test_cmp expect actual
 430'
 431
 432test_expect_success $PREREQ 'setup fake editor' '
 433        (echo "#!$SHELL_PATH" &&
 434         echo "echo fake edit >>\"\$1\""
 435        ) >fake-editor &&
 436        chmod +x fake-editor
 437'
 438
 439test_set_editor "$(pwd)/fake-editor"
 440
 441test_expect_success $PREREQ '--compose works' '
 442        clean_fake_sendmail &&
 443        git send-email \
 444        --compose --subject foo \
 445        --from="Example <nobody@example.com>" \
 446        --to=nobody@example.com \
 447        --smtp-server="$(pwd)/fake.sendmail" \
 448        $patches \
 449        2>errors
 450'
 451
 452test_expect_success $PREREQ 'first message is compose text' '
 453        grep "^fake edit" msgtxt1
 454'
 455
 456test_expect_success $PREREQ 'second message is patch' '
 457        grep "Subject:.*Second" msgtxt2
 458'
 459
 460test_expect_success $PREREQ 'setup expect' "
 461cat >expected-suppress-sob <<\EOF
 4620001-Second.patch
 463(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 464(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 465(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 466Dry-OK. Log says:
 467Server: relay.example.com
 468MAIL FROM:<from@example.com>
 469RCPT TO:<to@example.com>
 470RCPT TO:<cc@example.com>
 471RCPT TO:<author@example.com>
 472RCPT TO:<one@example.com>
 473RCPT TO:<two@example.com>
 474From: Example <from@example.com>
 475To: to@example.com
 476Cc: cc@example.com,
 477        A <author@example.com>,
 478        One <one@example.com>,
 479        two@example.com
 480Subject: [PATCH 1/1] Second.
 481Date: DATE-STRING
 482Message-Id: MESSAGE-ID-STRING
 483X-Mailer: X-MAILER-STRING
 484
 485Result: OK
 486EOF
 487"
 488
 489test_suppression () {
 490        git send-email \
 491                --dry-run \
 492                --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
 493                --from="Example <from@example.com>" \
 494                --to=to@example.com \
 495                --smtp-server relay.example.com \
 496                $patches |
 497        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
 498                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
 499                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
 500                >actual-suppress-$1${2+"-$2"} &&
 501        test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
 502}
 503
 504test_expect_success $PREREQ 'sendemail.cc set' '
 505        git config sendemail.cc cc@example.com &&
 506        test_suppression sob
 507'
 508
 509test_expect_success $PREREQ 'setup expect' "
 510cat >expected-suppress-sob <<\EOF
 5110001-Second.patch
 512(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 513(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 514(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 515Dry-OK. Log says:
 516Server: relay.example.com
 517MAIL FROM:<from@example.com>
 518RCPT TO:<to@example.com>
 519RCPT TO:<author@example.com>
 520RCPT TO:<one@example.com>
 521RCPT TO:<two@example.com>
 522From: Example <from@example.com>
 523To: to@example.com
 524Cc: A <author@example.com>,
 525        One <one@example.com>,
 526        two@example.com
 527Subject: [PATCH 1/1] Second.
 528Date: DATE-STRING
 529Message-Id: MESSAGE-ID-STRING
 530X-Mailer: X-MAILER-STRING
 531
 532Result: OK
 533EOF
 534"
 535
 536test_expect_success $PREREQ 'sendemail.cc unset' '
 537        git config --unset sendemail.cc &&
 538        test_suppression sob
 539'
 540
 541test_expect_success $PREREQ 'setup expect' "
 542cat >expected-suppress-cccmd <<\EOF
 5430001-Second.patch
 544(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 545(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 546(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 547(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 548Dry-OK. Log says:
 549Server: relay.example.com
 550MAIL FROM:<from@example.com>
 551RCPT TO:<to@example.com>
 552RCPT TO:<author@example.com>
 553RCPT TO:<one@example.com>
 554RCPT TO:<two@example.com>
 555RCPT TO:<committer@example.com>
 556From: Example <from@example.com>
 557To: to@example.com
 558Cc: A <author@example.com>,
 559        One <one@example.com>,
 560        two@example.com,
 561        C O Mitter <committer@example.com>
 562Subject: [PATCH 1/1] Second.
 563Date: DATE-STRING
 564Message-Id: MESSAGE-ID-STRING
 565X-Mailer: X-MAILER-STRING
 566
 567Result: OK
 568EOF
 569"
 570
 571test_expect_success $PREREQ 'sendemail.cccmd' '
 572        echo echo cc-cmd@example.com > cccmd &&
 573        chmod +x cccmd &&
 574        git config sendemail.cccmd ./cccmd &&
 575        test_suppression cccmd
 576'
 577
 578test_expect_success $PREREQ 'setup expect' '
 579cat >expected-suppress-all <<\EOF
 5800001-Second.patch
 581Dry-OK. Log says:
 582Server: relay.example.com
 583MAIL FROM:<from@example.com>
 584RCPT TO:<to@example.com>
 585From: Example <from@example.com>
 586To: to@example.com
 587Subject: [PATCH 1/1] Second.
 588Date: DATE-STRING
 589Message-Id: MESSAGE-ID-STRING
 590X-Mailer: X-MAILER-STRING
 591
 592Result: OK
 593EOF
 594'
 595
 596test_expect_success $PREREQ '--suppress-cc=all' '
 597        test_suppression all
 598'
 599
 600test_expect_success $PREREQ 'setup expect' "
 601cat >expected-suppress-body <<\EOF
 6020001-Second.patch
 603(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 604(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 605(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 606(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
 607Dry-OK. Log says:
 608Server: relay.example.com
 609MAIL FROM:<from@example.com>
 610RCPT TO:<to@example.com>
 611RCPT TO:<author@example.com>
 612RCPT TO:<one@example.com>
 613RCPT TO:<two@example.com>
 614RCPT TO:<cc-cmd@example.com>
 615From: Example <from@example.com>
 616To: to@example.com
 617Cc: A <author@example.com>,
 618        One <one@example.com>,
 619        two@example.com,
 620        cc-cmd@example.com
 621Subject: [PATCH 1/1] Second.
 622Date: DATE-STRING
 623Message-Id: MESSAGE-ID-STRING
 624X-Mailer: X-MAILER-STRING
 625
 626Result: OK
 627EOF
 628"
 629
 630test_expect_success $PREREQ '--suppress-cc=body' '
 631        test_suppression body
 632'
 633
 634test_expect_success $PREREQ 'setup expect' "
 635cat >expected-suppress-body-cccmd <<\EOF
 6360001-Second.patch
 637(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 638(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 639(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 640Dry-OK. Log says:
 641Server: relay.example.com
 642MAIL FROM:<from@example.com>
 643RCPT TO:<to@example.com>
 644RCPT TO:<author@example.com>
 645RCPT TO:<one@example.com>
 646RCPT TO:<two@example.com>
 647From: Example <from@example.com>
 648To: to@example.com
 649Cc: A <author@example.com>,
 650        One <one@example.com>,
 651        two@example.com
 652Subject: [PATCH 1/1] Second.
 653Date: DATE-STRING
 654Message-Id: MESSAGE-ID-STRING
 655X-Mailer: X-MAILER-STRING
 656
 657Result: OK
 658EOF
 659"
 660
 661test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
 662        test_suppression body cccmd
 663'
 664
 665test_expect_success $PREREQ 'setup expect' "
 666cat >expected-suppress-sob <<\EOF
 6670001-Second.patch
 668(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 669(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 670(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 671Dry-OK. Log says:
 672Server: relay.example.com
 673MAIL FROM:<from@example.com>
 674RCPT TO:<to@example.com>
 675RCPT TO:<author@example.com>
 676RCPT TO:<one@example.com>
 677RCPT TO:<two@example.com>
 678From: Example <from@example.com>
 679To: to@example.com
 680Cc: A <author@example.com>,
 681        One <one@example.com>,
 682        two@example.com
 683Subject: [PATCH 1/1] Second.
 684Date: DATE-STRING
 685Message-Id: MESSAGE-ID-STRING
 686X-Mailer: X-MAILER-STRING
 687
 688Result: OK
 689EOF
 690"
 691
 692test_expect_success $PREREQ '--suppress-cc=sob' '
 693        test_might_fail git config --unset sendemail.cccmd &&
 694        test_suppression sob
 695'
 696
 697test_expect_success $PREREQ 'setup expect' "
 698cat >expected-suppress-bodycc <<\EOF
 6990001-Second.patch
 700(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 701(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 702(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 703(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 704Dry-OK. Log says:
 705Server: relay.example.com
 706MAIL FROM:<from@example.com>
 707RCPT TO:<to@example.com>
 708RCPT TO:<author@example.com>
 709RCPT TO:<one@example.com>
 710RCPT TO:<two@example.com>
 711RCPT TO:<committer@example.com>
 712From: Example <from@example.com>
 713To: to@example.com
 714Cc: A <author@example.com>,
 715        One <one@example.com>,
 716        two@example.com,
 717        C O Mitter <committer@example.com>
 718Subject: [PATCH 1/1] Second.
 719Date: DATE-STRING
 720Message-Id: MESSAGE-ID-STRING
 721X-Mailer: X-MAILER-STRING
 722
 723Result: OK
 724EOF
 725"
 726
 727test_expect_success $PREREQ '--suppress-cc=bodycc' '
 728        test_suppression bodycc
 729'
 730
 731test_expect_success $PREREQ 'setup expect' "
 732cat >expected-suppress-cc <<\EOF
 7330001-Second.patch
 734(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 735(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 736Dry-OK. Log says:
 737Server: relay.example.com
 738MAIL FROM:<from@example.com>
 739RCPT TO:<to@example.com>
 740RCPT TO:<author@example.com>
 741RCPT TO:<committer@example.com>
 742From: Example <from@example.com>
 743To: to@example.com
 744Cc: A <author@example.com>,
 745        C O Mitter <committer@example.com>
 746Subject: [PATCH 1/1] Second.
 747Date: DATE-STRING
 748Message-Id: MESSAGE-ID-STRING
 749X-Mailer: X-MAILER-STRING
 750
 751Result: OK
 752EOF
 753"
 754
 755test_expect_success $PREREQ '--suppress-cc=cc' '
 756        test_suppression cc
 757'
 758
 759test_confirm () {
 760        echo y | \
 761                GIT_SEND_EMAIL_NOTTY=1 \
 762                git send-email \
 763                --from="Example <nobody@example.com>" \
 764                --to=nobody@example.com \
 765                --smtp-server="$(pwd)/fake.sendmail" \
 766                $@ $patches > stdout &&
 767        grep "Send this email" stdout
 768}
 769
 770test_expect_success $PREREQ '--confirm=always' '
 771        test_confirm --confirm=always --suppress-cc=all
 772'
 773
 774test_expect_success $PREREQ '--confirm=auto' '
 775        test_confirm --confirm=auto
 776'
 777
 778test_expect_success $PREREQ '--confirm=cc' '
 779        test_confirm --confirm=cc
 780'
 781
 782test_expect_success $PREREQ '--confirm=compose' '
 783        test_confirm --confirm=compose --compose
 784'
 785
 786test_expect_success $PREREQ 'confirm by default (due to cc)' '
 787        CONFIRM=$(git config --get sendemail.confirm) &&
 788        git config --unset sendemail.confirm &&
 789        test_confirm
 790        ret="$?"
 791        git config sendemail.confirm ${CONFIRM:-never}
 792        test $ret = "0"
 793'
 794
 795test_expect_success $PREREQ 'confirm by default (due to --compose)' '
 796        CONFIRM=$(git config --get sendemail.confirm) &&
 797        git config --unset sendemail.confirm &&
 798        test_confirm --suppress-cc=all --compose
 799        ret="$?"
 800        git config sendemail.confirm ${CONFIRM:-never}
 801        test $ret = "0"
 802'
 803
 804test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
 805        CONFIRM=$(git config --get sendemail.confirm) &&
 806        git config --unset sendemail.confirm &&
 807        rm -fr outdir &&
 808        git format-patch -2 -o outdir &&
 809        GIT_SEND_EMAIL_NOTTY=1 \
 810                git send-email \
 811                        --from="Example <nobody@example.com>" \
 812                        --to=nobody@example.com \
 813                        --smtp-server="$(pwd)/fake.sendmail" \
 814                        outdir/*.patch < /dev/null
 815        ret="$?"
 816        git config sendemail.confirm ${CONFIRM:-never}
 817        test $ret = "0"
 818'
 819
 820test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
 821        CONFIRM=$(git config --get sendemail.confirm) &&
 822        git config sendemail.confirm auto &&
 823        GIT_SEND_EMAIL_NOTTY=1 &&
 824        export GIT_SEND_EMAIL_NOTTY &&
 825                test_must_fail git send-email \
 826                        --from="Example <nobody@example.com>" \
 827                        --to=nobody@example.com \
 828                        --smtp-server="$(pwd)/fake.sendmail" \
 829                        $patches < /dev/null
 830        ret="$?"
 831        git config sendemail.confirm ${CONFIRM:-never}
 832        test $ret = "0"
 833'
 834
 835test_expect_success $PREREQ 'confirm does not loop forever' '
 836        CONFIRM=$(git config --get sendemail.confirm) &&
 837        git config sendemail.confirm auto &&
 838        GIT_SEND_EMAIL_NOTTY=1 &&
 839        export GIT_SEND_EMAIL_NOTTY &&
 840                yes "bogus" | test_must_fail git send-email \
 841                        --from="Example <nobody@example.com>" \
 842                        --to=nobody@example.com \
 843                        --smtp-server="$(pwd)/fake.sendmail" \
 844                        $patches
 845        ret="$?"
 846        git config sendemail.confirm ${CONFIRM:-never}
 847        test $ret = "0"
 848'
 849
 850test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
 851        clean_fake_sendmail &&
 852        rm -fr outdir &&
 853        git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
 854        git send-email \
 855        --from="Example <nobody@example.com>" \
 856        --to=nobody@example.com \
 857        --smtp-server="$(pwd)/fake.sendmail" \
 858        outdir/*.patch &&
 859        grep "^ " msgtxt1 |
 860        grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
 861'
 862
 863test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
 864        clean_fake_sendmail &&
 865        (echo "#!$SHELL_PATH" &&
 866         echo "echo utf8 body: àéìöú >>\"\$1\""
 867        ) >fake-editor-utf8 &&
 868        chmod +x fake-editor-utf8 &&
 869          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 870          git send-email \
 871          --compose --subject foo \
 872          --from="Example <nobody@example.com>" \
 873          --to=nobody@example.com \
 874          --smtp-server="$(pwd)/fake.sendmail" \
 875          $patches &&
 876        grep "^utf8 body" msgtxt1 &&
 877        grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
 878'
 879
 880test_expect_success $PREREQ '--compose respects user mime type' '
 881        clean_fake_sendmail &&
 882        (echo "#!$SHELL_PATH" &&
 883         echo "(echo MIME-Version: 1.0"
 884         echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
 885         echo " echo Content-Transfer-Encoding: 8bit"
 886         echo " echo Subject: foo"
 887         echo " echo "
 888         echo " echo utf8 body: àéìöú) >\"\$1\""
 889        ) >fake-editor-utf8-mime &&
 890        chmod +x fake-editor-utf8-mime &&
 891          GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
 892          git send-email \
 893          --compose --subject foo \
 894          --from="Example <nobody@example.com>" \
 895          --to=nobody@example.com \
 896          --smtp-server="$(pwd)/fake.sendmail" \
 897          $patches &&
 898        grep "^utf8 body" msgtxt1 &&
 899        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
 900        ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
 901'
 902
 903test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
 904        clean_fake_sendmail &&
 905          GIT_EDITOR="\"$(pwd)/fake-editor\"" \
 906          git send-email \
 907          --compose --subject utf8-sübjëct \
 908          --from="Example <nobody@example.com>" \
 909          --to=nobody@example.com \
 910          --smtp-server="$(pwd)/fake.sendmail" \
 911          $patches &&
 912        grep "^fake edit" msgtxt1 &&
 913        grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
 914'
 915
 916test_expect_success $PREREQ 'utf8 author is correctly passed on' '
 917        clean_fake_sendmail &&
 918        test_commit weird_author &&
 919        test_when_finished "git reset --hard HEAD^" &&
 920        git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
 921        git format-patch --stdout -1 >funny_name.patch &&
 922        git send-email --from="Example <nobody@example.com>" \
 923          --to=nobody@example.com \
 924          --smtp-server="$(pwd)/fake.sendmail" \
 925          funny_name.patch &&
 926        grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
 927'
 928
 929test_expect_success $PREREQ 'sendemail.composeencoding works' '
 930        clean_fake_sendmail &&
 931        git config sendemail.composeencoding iso-8859-1 &&
 932        (echo "#!$SHELL_PATH" &&
 933         echo "echo utf8 body: àéìöú >>\"\$1\""
 934        ) >fake-editor-utf8 &&
 935        chmod +x fake-editor-utf8 &&
 936          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 937          git send-email \
 938          --compose --subject foo \
 939          --from="Example <nobody@example.com>" \
 940          --to=nobody@example.com \
 941          --smtp-server="$(pwd)/fake.sendmail" \
 942          $patches &&
 943        grep "^utf8 body" msgtxt1 &&
 944        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
 945'
 946
 947test_expect_success $PREREQ '--compose-encoding works' '
 948        clean_fake_sendmail &&
 949        (echo "#!$SHELL_PATH" &&
 950         echo "echo utf8 body: àéìöú >>\"\$1\""
 951        ) >fake-editor-utf8 &&
 952        chmod +x fake-editor-utf8 &&
 953          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 954          git send-email \
 955          --compose-encoding iso-8859-1 \
 956          --compose --subject foo \
 957          --from="Example <nobody@example.com>" \
 958          --to=nobody@example.com \
 959          --smtp-server="$(pwd)/fake.sendmail" \
 960          $patches &&
 961        grep "^utf8 body" msgtxt1 &&
 962        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
 963'
 964
 965test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
 966        clean_fake_sendmail &&
 967        git config sendemail.composeencoding iso-8859-1 &&
 968        (echo "#!$SHELL_PATH" &&
 969         echo "echo utf8 body: àéìöú >>\"\$1\""
 970        ) >fake-editor-utf8 &&
 971        chmod +x fake-editor-utf8 &&
 972          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 973          git send-email \
 974          --compose-encoding iso-8859-2 \
 975          --compose --subject foo \
 976          --from="Example <nobody@example.com>" \
 977          --to=nobody@example.com \
 978          --smtp-server="$(pwd)/fake.sendmail" \
 979          $patches &&
 980        grep "^utf8 body" msgtxt1 &&
 981        grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
 982'
 983
 984test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
 985        clean_fake_sendmail &&
 986          GIT_EDITOR="\"$(pwd)/fake-editor\"" \
 987          git send-email \
 988          --compose-encoding iso-8859-2 \
 989          --compose --subject utf8-sübjëct \
 990          --from="Example <nobody@example.com>" \
 991          --to=nobody@example.com \
 992          --smtp-server="$(pwd)/fake.sendmail" \
 993          $patches &&
 994        grep "^fake edit" msgtxt1 &&
 995        grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
 996'
 997
 998test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
 999        echo master > master &&
1000        git add master &&
1001        git commit -m"add master" &&
1002        test_must_fail git send-email --dry-run master 2>errors &&
1003        grep disambiguate errors
1004'
1005
1006test_expect_success $PREREQ 'feed two files' '
1007        rm -fr outdir &&
1008        git format-patch -2 -o outdir &&
1009        git send-email \
1010        --dry-run \
1011        --from="Example <nobody@example.com>" \
1012        --to=nobody@example.com \
1013        outdir/000?-*.patch 2>errors >out &&
1014        grep "^Subject: " out >subjects &&
1015        test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1016        test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1017'
1018
1019test_expect_success $PREREQ 'in-reply-to but no threading' '
1020        git send-email \
1021                --dry-run \
1022                --from="Example <nobody@example.com>" \
1023                --to=nobody@example.com \
1024                --in-reply-to="<in-reply-id@example.com>" \
1025                --nothread \
1026                $patches |
1027        grep "In-Reply-To: <in-reply-id@example.com>"
1028'
1029
1030test_expect_success $PREREQ 'no in-reply-to and no threading' '
1031        git send-email \
1032                --dry-run \
1033                --from="Example <nobody@example.com>" \
1034                --to=nobody@example.com \
1035                --nothread \
1036                $patches $patches >stdout &&
1037        ! grep "In-Reply-To: " stdout
1038'
1039
1040test_expect_success $PREREQ 'threading but no chain-reply-to' '
1041        git send-email \
1042                --dry-run \
1043                --from="Example <nobody@example.com>" \
1044                --to=nobody@example.com \
1045                --thread \
1046                --nochain-reply-to \
1047                $patches $patches >stdout &&
1048        grep "In-Reply-To: " stdout
1049'
1050
1051test_expect_success $PREREQ 'warning with an implicit --chain-reply-to' '
1052        git send-email \
1053        --dry-run \
1054        --from="Example <nobody@example.com>" \
1055        --to=nobody@example.com \
1056        outdir/000?-*.patch 2>errors >out &&
1057        grep "no-chain-reply-to" errors
1058'
1059
1060test_expect_success $PREREQ 'no warning with an explicit --chain-reply-to' '
1061        git send-email \
1062        --dry-run \
1063        --from="Example <nobody@example.com>" \
1064        --to=nobody@example.com \
1065        --chain-reply-to \
1066        outdir/000?-*.patch 2>errors >out &&
1067        ! grep "no-chain-reply-to" errors
1068'
1069
1070test_expect_success $PREREQ 'no warning with an explicit --no-chain-reply-to' '
1071        git send-email \
1072        --dry-run \
1073        --from="Example <nobody@example.com>" \
1074        --to=nobody@example.com \
1075        --nochain-reply-to \
1076        outdir/000?-*.patch 2>errors >out &&
1077        ! grep "no-chain-reply-to" errors
1078'
1079
1080test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = false' '
1081        git config sendemail.chainreplyto false &&
1082        git send-email \
1083        --dry-run \
1084        --from="Example <nobody@example.com>" \
1085        --to=nobody@example.com \
1086        outdir/000?-*.patch 2>errors >out &&
1087        ! grep "no-chain-reply-to" errors
1088'
1089
1090test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = true' '
1091        git config sendemail.chainreplyto true &&
1092        git send-email \
1093        --dry-run \
1094        --from="Example <nobody@example.com>" \
1095        --to=nobody@example.com \
1096        outdir/000?-*.patch 2>errors >out &&
1097        ! grep "no-chain-reply-to" errors
1098'
1099
1100test_expect_success $PREREQ 'sendemail.to works' '
1101        git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1102        git send-email \
1103                --dry-run \
1104                --from="Example <nobody@example.com>" \
1105                $patches $patches >stdout &&
1106        grep "To: Somebody <somebody@ex.com>" stdout
1107'
1108
1109test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1110        git send-email \
1111                --dry-run \
1112                --from="Example <nobody@example.com>" \
1113                --no-to \
1114                --to=nobody@example.com \
1115                $patches $patches >stdout &&
1116        grep "To: nobody@example.com" stdout &&
1117        ! grep "To: Somebody <somebody@ex.com>" stdout
1118'
1119
1120test_expect_success $PREREQ 'sendemail.cc works' '
1121        git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1122        git send-email \
1123                --dry-run \
1124                --from="Example <nobody@example.com>" \
1125                --to=nobody@example.com \
1126                $patches $patches >stdout &&
1127        grep "Cc: Somebody <somebody@ex.com>" stdout
1128'
1129
1130test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1131        git send-email \
1132                --dry-run \
1133                --from="Example <nobody@example.com>" \
1134                --no-cc \
1135                --cc=bodies@example.com \
1136                --to=nobody@example.com \
1137                $patches $patches >stdout &&
1138        grep "Cc: bodies@example.com" stdout &&
1139        ! grep "Cc: Somebody <somebody@ex.com>" stdout
1140'
1141
1142test_expect_success $PREREQ 'sendemail.bcc works' '
1143        git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1144        git send-email \
1145                --dry-run \
1146                --from="Example <nobody@example.com>" \
1147                --to=nobody@example.com \
1148                --smtp-server relay.example.com \
1149                $patches $patches >stdout &&
1150        grep "RCPT TO:<other@ex.com>" stdout
1151'
1152
1153test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1154        git send-email \
1155                --dry-run \
1156                --from="Example <nobody@example.com>" \
1157                --no-bcc \
1158                --bcc=bodies@example.com \
1159                --to=nobody@example.com \
1160                --smtp-server relay.example.com \
1161                $patches $patches >stdout &&
1162        grep "RCPT TO:<bodies@example.com>" stdout &&
1163        ! grep "RCPT TO:<other@ex.com>" stdout
1164'
1165
1166test_expect_success $PREREQ 'patches To headers are used by default' '
1167        patch=`git format-patch -1 --to="bodies@example.com"` &&
1168        test_when_finished "rm $patch" &&
1169        git send-email \
1170                --dry-run \
1171                --from="Example <nobody@example.com>" \
1172                --smtp-server relay.example.com \
1173                $patch >stdout &&
1174        grep "RCPT TO:<bodies@example.com>" stdout
1175'
1176
1177test_expect_success $PREREQ 'patches To headers are appended to' '
1178        patch=`git format-patch -1 --to="bodies@example.com"` &&
1179        test_when_finished "rm $patch" &&
1180        git send-email \
1181                --dry-run \
1182                --from="Example <nobody@example.com>" \
1183                --to=nobody@example.com \
1184                --smtp-server relay.example.com \
1185                $patch >stdout &&
1186        grep "RCPT TO:<bodies@example.com>" stdout &&
1187        grep "RCPT TO:<nobody@example.com>" stdout
1188'
1189
1190test_expect_success $PREREQ 'To headers from files reset each patch' '
1191        patch1=`git format-patch -1 --to="bodies@example.com"` &&
1192        patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1193        test_when_finished "rm $patch1 && rm $patch2" &&
1194        git send-email \
1195                --dry-run \
1196                --from="Example <nobody@example.com>" \
1197                --to="nobody@example.com" \
1198                --smtp-server relay.example.com \
1199                $patch1 $patch2 >stdout &&
1200        test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1201        test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1202        test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1203'
1204
1205test_expect_success $PREREQ 'setup expect' '
1206cat >email-using-8bit <<EOF
1207From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1208Message-Id: <bogus-message-id@example.com>
1209From: author@example.com
1210Date: Sat, 12 Jun 2010 15:53:58 +0200
1211Subject: subject goes here
1212
1213Dieser deutsche Text enthält einen Umlaut!
1214EOF
1215'
1216
1217test_expect_success $PREREQ 'setup expect' '
1218cat >expected <<EOF
1219Subject: subject goes here
1220EOF
1221'
1222
1223test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1224        clean_fake_sendmail &&
1225        echo bogus |
1226        git send-email --from=author@example.com --to=nobody@example.com \
1227                        --smtp-server="$(pwd)/fake.sendmail" \
1228                        --8bit-encoding=UTF-8 \
1229                        email-using-8bit >stdout &&
1230        grep "Subject" msgtxt1 >actual &&
1231        test_cmp expected actual
1232'
1233
1234test_expect_success $PREREQ 'setup expect' '
1235cat >content-type-decl <<EOF
1236MIME-Version: 1.0
1237Content-Type: text/plain; charset=UTF-8
1238Content-Transfer-Encoding: 8bit
1239EOF
1240'
1241
1242test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1243        clean_fake_sendmail &&
1244        echo |
1245        git send-email --from=author@example.com --to=nobody@example.com \
1246                        --smtp-server="$(pwd)/fake.sendmail" \
1247                        email-using-8bit >stdout &&
1248        grep "do not declare a Content-Transfer-Encoding" stdout &&
1249        grep email-using-8bit stdout &&
1250        grep "Which 8bit encoding" stdout &&
1251        egrep "Content|MIME" msgtxt1 >actual &&
1252        test_cmp actual content-type-decl
1253'
1254
1255test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1256        clean_fake_sendmail &&
1257        git config sendemail.assume8bitEncoding UTF-8 &&
1258        echo bogus |
1259        git send-email --from=author@example.com --to=nobody@example.com \
1260                        --smtp-server="$(pwd)/fake.sendmail" \
1261                        email-using-8bit >stdout &&
1262        egrep "Content|MIME" msgtxt1 >actual &&
1263        test_cmp actual content-type-decl
1264'
1265
1266test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1267        clean_fake_sendmail &&
1268        git config sendemail.assume8bitEncoding "bogus too" &&
1269        echo bogus |
1270        git send-email --from=author@example.com --to=nobody@example.com \
1271                        --smtp-server="$(pwd)/fake.sendmail" \
1272                        --8bit-encoding=UTF-8 \
1273                        email-using-8bit >stdout &&
1274        egrep "Content|MIME" msgtxt1 >actual &&
1275        test_cmp actual content-type-decl
1276'
1277
1278test_expect_success $PREREQ 'setup expect' '
1279cat >email-using-8bit <<EOF
1280From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1281Message-Id: <bogus-message-id@example.com>
1282From: author@example.com
1283Date: Sat, 12 Jun 2010 15:53:58 +0200
1284Subject: Dieser Betreff enthält auch einen Umlaut!
1285
1286Nothing to see here.
1287EOF
1288'
1289
1290test_expect_success $PREREQ 'setup expect' '
1291cat >expected <<EOF
1292Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1293EOF
1294'
1295
1296test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1297        clean_fake_sendmail &&
1298        echo bogus |
1299        git send-email --from=author@example.com --to=nobody@example.com \
1300                        --smtp-server="$(pwd)/fake.sendmail" \
1301                        --8bit-encoding=UTF-8 \
1302                        email-using-8bit >stdout &&
1303        grep "Subject" msgtxt1 >actual &&
1304        test_cmp expected actual
1305'
1306
1307# Note that the patches in this test are deliberately out of order; we
1308# want to make sure it works even if the cover-letter is not in the
1309# first mail.
1310test_expect_success $PREREQ 'refusing to send cover letter template' '
1311        clean_fake_sendmail &&
1312        rm -fr outdir &&
1313        git format-patch --cover-letter -2 -o outdir &&
1314        test_must_fail git send-email \
1315          --from="Example <nobody@example.com>" \
1316          --to=nobody@example.com \
1317          --smtp-server="$(pwd)/fake.sendmail" \
1318          outdir/0002-*.patch \
1319          outdir/0000-*.patch \
1320          outdir/0001-*.patch \
1321          2>errors >out &&
1322        grep "SUBJECT HERE" errors &&
1323        test -z "$(ls msgtxt*)"
1324'
1325
1326test_expect_success $PREREQ '--force sends cover letter template anyway' '
1327        clean_fake_sendmail &&
1328        rm -fr outdir &&
1329        git format-patch --cover-letter -2 -o outdir &&
1330        git send-email \
1331          --force \
1332          --from="Example <nobody@example.com>" \
1333          --to=nobody@example.com \
1334          --smtp-server="$(pwd)/fake.sendmail" \
1335          outdir/0002-*.patch \
1336          outdir/0000-*.patch \
1337          outdir/0001-*.patch \
1338          2>errors >out &&
1339        ! grep "SUBJECT HERE" errors &&
1340        test -n "$(ls msgtxt*)"
1341'
1342
1343test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1344        clean_fake_sendmail &&
1345        echo "alias sbd  somebody@example.org" >.mailrc &&
1346        git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1347        git config sendemail.aliasfiletype mailrc &&
1348        git send-email \
1349          --from="Example <nobody@example.com>" \
1350          --to=sbd \
1351          --smtp-server="$(pwd)/fake.sendmail" \
1352          outdir/0001-*.patch \
1353          2>errors >out &&
1354        grep "^!somebody@example\.org!$" commandline1
1355'
1356
1357test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1358        clean_fake_sendmail &&
1359        echo "alias sbd  someone@example.org" >~/.mailrc &&
1360        git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1361        git config sendemail.aliasfiletype mailrc &&
1362        git send-email \
1363          --from="Example <nobody@example.com>" \
1364          --to=sbd \
1365          --smtp-server="$(pwd)/fake.sendmail" \
1366          outdir/0001-*.patch \
1367          2>errors >out &&
1368        grep "^!someone@example\.org!$" commandline1
1369'
1370
1371test_done