t / t9001-send-email.shon commit t9001: test --envelope-sender option of send-email (4f333bc)
   1#!/bin/sh
   2
   3test_description='git send-email'
   4. ./test-lib.sh
   5
   6if ! test_have_prereq PERL; then
   7        say 'skipping git send-email tests, perl not available'
   8        test_done
   9fi
  10
  11PROG='git send-email'
  12test_expect_success \
  13    'prepare reference tree' \
  14    'echo "1A quick brown fox jumps over the" >file &&
  15     echo "lazy dog" >>file &&
  16     git add file &&
  17     GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
  18
  19test_expect_success \
  20    'Setup helper tool' \
  21    '(echo "#!$SHELL_PATH"
  22      echo shift
  23      echo output=1
  24      echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
  25      echo for a
  26      echo do
  27      echo "  echo \"!\$a!\""
  28      echo "done >commandline\$output"
  29      echo "cat > msgtxt\$output"
  30      ) >fake.sendmail &&
  31     chmod +x ./fake.sendmail &&
  32     git add fake.sendmail &&
  33     GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
  34
  35clean_fake_sendmail() {
  36        rm -f commandline* msgtxt*
  37}
  38
  39test_expect_success 'Extract patches' '
  40    patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
  41'
  42
  43# Test no confirm early to ensure remaining tests will not hang
  44test_no_confirm () {
  45        rm -f no_confirm_okay
  46        echo n | \
  47                GIT_SEND_EMAIL_NOTTY=1 \
  48                git send-email \
  49                --from="Example <from@example.com>" \
  50                --to=nobody@example.com \
  51                --smtp-server="$(pwd)/fake.sendmail" \
  52                $@ \
  53                $patches > stdout &&
  54                test_must_fail grep "Send this email" stdout &&
  55                > no_confirm_okay
  56}
  57
  58# Exit immediately to prevent hang if a no-confirm test fails
  59check_no_confirm () {
  60        test -f no_confirm_okay || {
  61                say 'No confirm test failed; skipping remaining tests to prevent hanging'
  62                test_done
  63        }
  64}
  65
  66test_expect_success 'No confirm with --suppress-cc' '
  67        test_no_confirm --suppress-cc=sob
  68'
  69check_no_confirm
  70
  71test_expect_success 'No confirm with --confirm=never' '
  72        test_no_confirm --confirm=never
  73'
  74check_no_confirm
  75
  76# leave sendemail.confirm set to never after this so that none of the
  77# remaining tests prompt unintentionally.
  78test_expect_success 'No confirm with sendemail.confirm=never' '
  79        git config sendemail.confirm never &&
  80        test_no_confirm --compose --subject=foo
  81'
  82check_no_confirm
  83
  84test_expect_success 'Send patches' '
  85     git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
  86'
  87
  88cat >expected <<\EOF
  89!nobody@example.com!
  90!author@example.com!
  91!one@example.com!
  92!two@example.com!
  93EOF
  94test_expect_success \
  95    'Verify commandline' \
  96    'test_cmp expected commandline1'
  97
  98test_expect_success 'Send patches with --envelope-sender' '
  99    clean_fake_sendmail &&
 100     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
 101'
 102
 103cat >expected <<\EOF
 104!patch@example.com!
 105!-i!
 106!nobody@example.com!
 107!author@example.com!
 108!one@example.com!
 109!two@example.com!
 110EOF
 111test_expect_success \
 112    'Verify commandline' \
 113    'test_cmp expected commandline1'
 114
 115cat >expected-show-all-headers <<\EOF
 1160001-Second.patch
 117(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 118(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 119(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 120Dry-OK. Log says:
 121Server: relay.example.com
 122MAIL FROM:<from@example.com>
 123RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<bcc@example.com>
 124From: Example <from@example.com>
 125To: to@example.com
 126Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com
 127Subject: [PATCH 1/1] Second.
 128Date: DATE-STRING
 129Message-Id: MESSAGE-ID-STRING
 130X-Mailer: X-MAILER-STRING
 131In-Reply-To: <unique-message-id@example.com>
 132References: <unique-message-id@example.com>
 133
 134Result: OK
 135EOF
 136
 137test_expect_success 'Show all headers' '
 138        git send-email \
 139                --dry-run \
 140                --suppress-cc=sob \
 141                --from="Example <from@example.com>" \
 142                --to=to@example.com \
 143                --cc=cc@example.com \
 144                --bcc=bcc@example.com \
 145                --in-reply-to="<unique-message-id@example.com>" \
 146                --smtp-server relay.example.com \
 147                $patches |
 148        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
 149                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
 150                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
 151                >actual-show-all-headers &&
 152        test_cmp expected-show-all-headers actual-show-all-headers
 153'
 154
 155test_expect_success 'Prompting works' '
 156        clean_fake_sendmail &&
 157        (echo "Example <from@example.com>"
 158         echo "to@example.com"
 159         echo ""
 160        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
 161                --smtp-server="$(pwd)/fake.sendmail" \
 162                $patches \
 163                2>errors &&
 164                grep "^From: Example <from@example.com>$" msgtxt1 &&
 165                grep "^To: to@example.com$" msgtxt1
 166'
 167
 168test_expect_success 'cccmd works' '
 169        clean_fake_sendmail &&
 170        cp $patches cccmd.patch &&
 171        echo cccmd--cccmd@example.com >>cccmd.patch &&
 172        {
 173          echo "#!$SHELL_PATH"
 174          echo sed -n -e s/^cccmd--//p \"\$1\"
 175        } > cccmd-sed &&
 176        chmod +x cccmd-sed &&
 177        git send-email \
 178                --from="Example <nobody@example.com>" \
 179                --to=nobody@example.com \
 180                --cc-cmd=./cccmd-sed \
 181                --smtp-server="$(pwd)/fake.sendmail" \
 182                cccmd.patch \
 183                &&
 184        grep ^Cc:.*cccmd@example.com msgtxt1
 185'
 186
 187z8=zzzzzzzz
 188z64=$z8$z8$z8$z8$z8$z8$z8$z8
 189z512=$z64$z64$z64$z64$z64$z64$z64$z64
 190test_expect_success 'reject long lines' '
 191        clean_fake_sendmail &&
 192        cp $patches longline.patch &&
 193        echo $z512$z512 >>longline.patch &&
 194        test_must_fail git send-email \
 195                --from="Example <nobody@example.com>" \
 196                --to=nobody@example.com \
 197                --smtp-server="$(pwd)/fake.sendmail" \
 198                $patches longline.patch \
 199                2>errors &&
 200        grep longline.patch errors
 201'
 202
 203test_expect_success 'no patch was sent' '
 204        ! test -e commandline1
 205'
 206
 207test_expect_success 'Author From: in message body' '
 208        clean_fake_sendmail &&
 209        git send-email \
 210                --from="Example <nobody@example.com>" \
 211                --to=nobody@example.com \
 212                --smtp-server="$(pwd)/fake.sendmail" \
 213                $patches &&
 214        sed "1,/^$/d" < msgtxt1 > msgbody1
 215        grep "From: A <author@example.com>" msgbody1
 216'
 217
 218test_expect_success 'Author From: not in message body' '
 219        clean_fake_sendmail &&
 220        git send-email \
 221                --from="A <author@example.com>" \
 222                --to=nobody@example.com \
 223                --smtp-server="$(pwd)/fake.sendmail" \
 224                $patches &&
 225        sed "1,/^$/d" < msgtxt1 > msgbody1
 226        ! grep "From: A <author@example.com>" msgbody1
 227'
 228
 229test_expect_success 'allow long lines with --no-validate' '
 230        git send-email \
 231                --from="Example <nobody@example.com>" \
 232                --to=nobody@example.com \
 233                --smtp-server="$(pwd)/fake.sendmail" \
 234                --novalidate \
 235                $patches longline.patch \
 236                2>errors
 237'
 238
 239test_expect_success 'Invalid In-Reply-To' '
 240        clean_fake_sendmail &&
 241        git send-email \
 242                --from="Example <nobody@example.com>" \
 243                --to=nobody@example.com \
 244                --in-reply-to=" " \
 245                --smtp-server="$(pwd)/fake.sendmail" \
 246                $patches
 247                2>errors
 248        ! grep "^In-Reply-To: < *>" msgtxt1
 249'
 250
 251test_expect_success 'Valid In-Reply-To when prompting' '
 252        clean_fake_sendmail &&
 253        (echo "From Example <from@example.com>"
 254         echo "To Example <to@example.com>"
 255         echo ""
 256        ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
 257                --smtp-server="$(pwd)/fake.sendmail" \
 258                $patches 2>errors &&
 259        ! grep "^In-Reply-To: < *>" msgtxt1
 260'
 261
 262test_expect_success 'setup fake editor' '
 263        (echo "#!$SHELL_PATH" &&
 264         echo "echo fake edit >>\"\$1\""
 265        ) >fake-editor &&
 266        chmod +x fake-editor
 267'
 268
 269test_set_editor "$(pwd)/fake-editor"
 270
 271test_expect_success '--compose works' '
 272        clean_fake_sendmail &&
 273        git send-email \
 274        --compose --subject foo \
 275        --from="Example <nobody@example.com>" \
 276        --to=nobody@example.com \
 277        --smtp-server="$(pwd)/fake.sendmail" \
 278        $patches \
 279        2>errors
 280'
 281
 282test_expect_success 'first message is compose text' '
 283        grep "^fake edit" msgtxt1
 284'
 285
 286test_expect_success 'second message is patch' '
 287        grep "Subject:.*Second" msgtxt2
 288'
 289
 290cat >expected-suppress-sob <<\EOF
 2910001-Second.patch
 292(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 293(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 294(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 295Dry-OK. Log says:
 296Server: relay.example.com
 297MAIL FROM:<from@example.com>
 298RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
 299From: Example <from@example.com>
 300To: to@example.com
 301Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com
 302Subject: [PATCH 1/1] Second.
 303Date: DATE-STRING
 304Message-Id: MESSAGE-ID-STRING
 305X-Mailer: X-MAILER-STRING
 306
 307Result: OK
 308EOF
 309
 310test_suppression () {
 311        git send-email \
 312                --dry-run \
 313                --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
 314                --from="Example <from@example.com>" \
 315                --to=to@example.com \
 316                --smtp-server relay.example.com \
 317                $patches |
 318        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
 319                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
 320                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
 321                >actual-suppress-$1${2+"-$2"} &&
 322        test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
 323}
 324
 325test_expect_success 'sendemail.cc set' '
 326        git config sendemail.cc cc@example.com &&
 327        test_suppression sob
 328'
 329
 330cat >expected-suppress-sob <<\EOF
 3310001-Second.patch
 332(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 333(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 334(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 335Dry-OK. Log says:
 336Server: relay.example.com
 337MAIL FROM:<from@example.com>
 338RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
 339From: Example <from@example.com>
 340To: to@example.com
 341Cc: A <author@example.com>, One <one@example.com>, two@example.com
 342Subject: [PATCH 1/1] Second.
 343Date: DATE-STRING
 344Message-Id: MESSAGE-ID-STRING
 345X-Mailer: X-MAILER-STRING
 346
 347Result: OK
 348EOF
 349
 350test_expect_success 'sendemail.cc unset' '
 351        git config --unset sendemail.cc &&
 352        test_suppression sob
 353'
 354
 355cat >expected-suppress-cccmd <<\EOF
 3560001-Second.patch
 357(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 358(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 359(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 360(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 361Dry-OK. Log says:
 362Server: relay.example.com
 363MAIL FROM:<from@example.com>
 364RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com>
 365From: Example <from@example.com>
 366To: to@example.com
 367Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com>
 368Subject: [PATCH 1/1] Second.
 369Date: DATE-STRING
 370Message-Id: MESSAGE-ID-STRING
 371X-Mailer: X-MAILER-STRING
 372
 373Result: OK
 374EOF
 375
 376test_expect_success 'sendemail.cccmd' '
 377        echo echo cc-cmd@example.com > cccmd &&
 378        chmod +x cccmd &&
 379        git config sendemail.cccmd ./cccmd &&
 380        test_suppression cccmd
 381'
 382
 383cat >expected-suppress-all <<\EOF
 3840001-Second.patch
 385Dry-OK. Log says:
 386Server: relay.example.com
 387MAIL FROM:<from@example.com>
 388RCPT TO:<to@example.com>
 389From: Example <from@example.com>
 390To: to@example.com
 391Subject: [PATCH 1/1] Second.
 392Date: DATE-STRING
 393Message-Id: MESSAGE-ID-STRING
 394X-Mailer: X-MAILER-STRING
 395
 396Result: OK
 397EOF
 398
 399test_expect_success '--suppress-cc=all' '
 400        test_suppression all
 401'
 402
 403cat >expected-suppress-body <<\EOF
 4040001-Second.patch
 405(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 406(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 407(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 408(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
 409Dry-OK. Log says:
 410Server: relay.example.com
 411MAIL FROM:<from@example.com>
 412RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<cc-cmd@example.com>
 413From: Example <from@example.com>
 414To: to@example.com
 415Cc: A <author@example.com>, One <one@example.com>, two@example.com, cc-cmd@example.com
 416Subject: [PATCH 1/1] Second.
 417Date: DATE-STRING
 418Message-Id: MESSAGE-ID-STRING
 419X-Mailer: X-MAILER-STRING
 420
 421Result: OK
 422EOF
 423
 424test_expect_success '--suppress-cc=body' '
 425        test_suppression body
 426'
 427
 428cat >expected-suppress-body-cccmd <<\EOF
 4290001-Second.patch
 430(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 431(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 432(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 433Dry-OK. Log says:
 434Server: relay.example.com
 435MAIL FROM:<from@example.com>
 436RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
 437From: Example <from@example.com>
 438To: to@example.com
 439Cc: A <author@example.com>, One <one@example.com>, two@example.com
 440Subject: [PATCH 1/1] Second.
 441Date: DATE-STRING
 442Message-Id: MESSAGE-ID-STRING
 443X-Mailer: X-MAILER-STRING
 444
 445Result: OK
 446EOF
 447
 448test_expect_success '--suppress-cc=body --suppress-cc=cccmd' '
 449        test_suppression body cccmd
 450'
 451
 452cat >expected-suppress-sob <<\EOF
 4530001-Second.patch
 454(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 455(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 456(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 457Dry-OK. Log says:
 458Server: relay.example.com
 459MAIL FROM:<from@example.com>
 460RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
 461From: Example <from@example.com>
 462To: to@example.com
 463Cc: A <author@example.com>, One <one@example.com>, two@example.com
 464Subject: [PATCH 1/1] Second.
 465Date: DATE-STRING
 466Message-Id: MESSAGE-ID-STRING
 467X-Mailer: X-MAILER-STRING
 468
 469Result: OK
 470EOF
 471
 472test_expect_success '--suppress-cc=sob' '
 473        git config --unset sendemail.cccmd
 474        test_suppression sob
 475'
 476
 477cat >expected-suppress-bodycc <<\EOF
 4780001-Second.patch
 479(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 480(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 481(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 482(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 483Dry-OK. Log says:
 484Server: relay.example.com
 485MAIL FROM:<from@example.com>
 486RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com>
 487From: Example <from@example.com>
 488To: to@example.com
 489Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com>
 490Subject: [PATCH 1/1] Second.
 491Date: DATE-STRING
 492Message-Id: MESSAGE-ID-STRING
 493X-Mailer: X-MAILER-STRING
 494
 495Result: OK
 496EOF
 497
 498test_expect_success '--suppress-cc=bodycc' '
 499        test_suppression bodycc
 500'
 501
 502cat >expected-suppress-cc <<\EOF
 5030001-Second.patch
 504(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 505(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 506Dry-OK. Log says:
 507Server: relay.example.com
 508MAIL FROM:<from@example.com>
 509RCPT TO:<to@example.com>,<author@example.com>,<committer@example.com>
 510From: Example <from@example.com>
 511To: to@example.com
 512Cc: A <author@example.com>, C O Mitter <committer@example.com>
 513Subject: [PATCH 1/1] Second.
 514Date: DATE-STRING
 515Message-Id: MESSAGE-ID-STRING
 516X-Mailer: X-MAILER-STRING
 517
 518Result: OK
 519EOF
 520
 521test_expect_success '--suppress-cc=cc' '
 522        test_suppression cc
 523'
 524
 525test_confirm () {
 526        echo y | \
 527                GIT_SEND_EMAIL_NOTTY=1 \
 528                git send-email \
 529                --from="Example <nobody@example.com>" \
 530                --to=nobody@example.com \
 531                --smtp-server="$(pwd)/fake.sendmail" \
 532                $@ $patches > stdout &&
 533        grep "Send this email" stdout
 534}
 535
 536test_expect_success '--confirm=always' '
 537        test_confirm --confirm=always --suppress-cc=all
 538'
 539
 540test_expect_success '--confirm=auto' '
 541        test_confirm --confirm=auto
 542'
 543
 544test_expect_success '--confirm=cc' '
 545        test_confirm --confirm=cc
 546'
 547
 548test_expect_success '--confirm=compose' '
 549        test_confirm --confirm=compose --compose
 550'
 551
 552test_expect_success 'confirm by default (due to cc)' '
 553        CONFIRM=$(git config --get sendemail.confirm) &&
 554        git config --unset sendemail.confirm &&
 555        test_confirm
 556        ret="$?"
 557        git config sendemail.confirm ${CONFIRM:-never}
 558        test $ret = "0"
 559'
 560
 561test_expect_success 'confirm by default (due to --compose)' '
 562        CONFIRM=$(git config --get sendemail.confirm) &&
 563        git config --unset sendemail.confirm &&
 564        test_confirm --suppress-cc=all --compose
 565        ret="$?"
 566        git config sendemail.confirm ${CONFIRM:-never}
 567        test $ret = "0"
 568'
 569
 570test_expect_success 'confirm detects EOF (inform assumes y)' '
 571        CONFIRM=$(git config --get sendemail.confirm) &&
 572        git config --unset sendemail.confirm &&
 573        rm -fr outdir &&
 574        git format-patch -2 -o outdir &&
 575        GIT_SEND_EMAIL_NOTTY=1 \
 576                git send-email \
 577                        --from="Example <nobody@example.com>" \
 578                        --to=nobody@example.com \
 579                        --smtp-server="$(pwd)/fake.sendmail" \
 580                        outdir/*.patch < /dev/null
 581        ret="$?"
 582        git config sendemail.confirm ${CONFIRM:-never}
 583        test $ret = "0"
 584'
 585
 586test_expect_success 'confirm detects EOF (auto causes failure)' '
 587        CONFIRM=$(git config --get sendemail.confirm) &&
 588        git config sendemail.confirm auto &&
 589        GIT_SEND_EMAIL_NOTTY=1 &&
 590        export GIT_SEND_EMAIL_NOTTY &&
 591                test_must_fail git send-email \
 592                        --from="Example <nobody@example.com>" \
 593                        --to=nobody@example.com \
 594                        --smtp-server="$(pwd)/fake.sendmail" \
 595                        $patches < /dev/null
 596        ret="$?"
 597        git config sendemail.confirm ${CONFIRM:-never}
 598        test $ret = "0"
 599'
 600
 601test_expect_success 'confirm doesnt loop forever' '
 602        CONFIRM=$(git config --get sendemail.confirm) &&
 603        git config sendemail.confirm auto &&
 604        GIT_SEND_EMAIL_NOTTY=1 &&
 605        export GIT_SEND_EMAIL_NOTTY &&
 606                yes "bogus" | test_must_fail git send-email \
 607                        --from="Example <nobody@example.com>" \
 608                        --to=nobody@example.com \
 609                        --smtp-server="$(pwd)/fake.sendmail" \
 610                        $patches
 611        ret="$?"
 612        git config sendemail.confirm ${CONFIRM:-never}
 613        test $ret = "0"
 614'
 615
 616test_expect_success 'utf8 Cc is rfc2047 encoded' '
 617        clean_fake_sendmail &&
 618        rm -fr outdir &&
 619        git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
 620        git send-email \
 621        --from="Example <nobody@example.com>" \
 622        --to=nobody@example.com \
 623        --smtp-server="$(pwd)/fake.sendmail" \
 624        outdir/*.patch &&
 625        grep "^Cc:" msgtxt1 |
 626        grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
 627'
 628
 629test_expect_success '--compose adds MIME for utf8 body' '
 630        clean_fake_sendmail &&
 631        (echo "#!$SHELL_PATH" &&
 632         echo "echo utf8 body: àéìöú >>\"\$1\""
 633        ) >fake-editor-utf8 &&
 634        chmod +x fake-editor-utf8 &&
 635          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 636          git send-email \
 637          --compose --subject foo \
 638          --from="Example <nobody@example.com>" \
 639          --to=nobody@example.com \
 640          --smtp-server="$(pwd)/fake.sendmail" \
 641          $patches &&
 642        grep "^utf8 body" msgtxt1 &&
 643        grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
 644'
 645
 646test_expect_success '--compose respects user mime type' '
 647        clean_fake_sendmail &&
 648        (echo "#!$SHELL_PATH" &&
 649         echo "(echo MIME-Version: 1.0"
 650         echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
 651         echo " echo Content-Transfer-Encoding: 8bit"
 652         echo " echo Subject: foo"
 653         echo " echo "
 654         echo " echo utf8 body: àéìöú) >\"\$1\""
 655        ) >fake-editor-utf8-mime &&
 656        chmod +x fake-editor-utf8-mime &&
 657          GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
 658          git send-email \
 659          --compose --subject foo \
 660          --from="Example <nobody@example.com>" \
 661          --to=nobody@example.com \
 662          --smtp-server="$(pwd)/fake.sendmail" \
 663          $patches &&
 664        grep "^utf8 body" msgtxt1 &&
 665        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
 666        ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
 667'
 668
 669test_expect_success '--compose adds MIME for utf8 subject' '
 670        clean_fake_sendmail &&
 671          GIT_EDITOR="\"$(pwd)/fake-editor\"" \
 672          git send-email \
 673          --compose --subject utf8-sübjëct \
 674          --from="Example <nobody@example.com>" \
 675          --to=nobody@example.com \
 676          --smtp-server="$(pwd)/fake.sendmail" \
 677          $patches &&
 678        grep "^fake edit" msgtxt1 &&
 679        grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
 680'
 681
 682test_expect_success 'detects ambiguous reference/file conflict' '
 683        echo master > master &&
 684        git add master &&
 685        git commit -m"add master" &&
 686        test_must_fail git send-email --dry-run master 2>errors &&
 687        grep disambiguate errors
 688'
 689
 690test_expect_success 'feed two files' '
 691        rm -fr outdir &&
 692        git format-patch -2 -o outdir &&
 693        git send-email \
 694        --dry-run \
 695        --from="Example <nobody@example.com>" \
 696        --to=nobody@example.com \
 697        outdir/000?-*.patch 2>errors >out &&
 698        grep "^Subject: " out >subjects &&
 699        test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
 700        test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
 701'
 702
 703test_expect_success 'in-reply-to but no threading' '
 704        git send-email \
 705                --dry-run \
 706                --from="Example <nobody@example.com>" \
 707                --to=nobody@example.com \
 708                --in-reply-to="<in-reply-id@example.com>" \
 709                --nothread \
 710                $patches |
 711        grep "In-Reply-To: <in-reply-id@example.com>"
 712'
 713
 714test_expect_success 'no in-reply-to and no threading' '
 715        git send-email \
 716                --dry-run \
 717                --from="Example <nobody@example.com>" \
 718                --to=nobody@example.com \
 719                --nothread \
 720                $patches $patches >stdout &&
 721        ! grep "In-Reply-To: " stdout
 722'
 723
 724test_expect_success 'threading but no chain-reply-to' '
 725        git send-email \
 726                --dry-run \
 727                --from="Example <nobody@example.com>" \
 728                --to=nobody@example.com \
 729                --thread \
 730                --nochain-reply-to \
 731                $patches $patches >stdout &&
 732        grep "In-Reply-To: " stdout
 733'
 734
 735test_done