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