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