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