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