t / t9001-send-email.shon commit wrap-for-bin: make bin-wrappers chainable (8bade1e)
   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 'sendemail.composeencoding works' '
 960        clean_fake_sendmail &&
 961        git config sendemail.composeencoding iso-8859-1 &&
 962        (echo "#!$SHELL_PATH" &&
 963         echo "echo utf8 body: àéìöú >>\"\$1\""
 964        ) >fake-editor-utf8 &&
 965        chmod +x fake-editor-utf8 &&
 966          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 967          git send-email \
 968          --compose --subject foo \
 969          --from="Example <nobody@example.com>" \
 970          --to=nobody@example.com \
 971          --smtp-server="$(pwd)/fake.sendmail" \
 972          $patches &&
 973        grep "^utf8 body" msgtxt1 &&
 974        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
 975'
 976
 977test_expect_success $PREREQ '--compose-encoding works' '
 978        clean_fake_sendmail &&
 979        (echo "#!$SHELL_PATH" &&
 980         echo "echo utf8 body: àéìöú >>\"\$1\""
 981        ) >fake-editor-utf8 &&
 982        chmod +x fake-editor-utf8 &&
 983          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 984          git send-email \
 985          --compose-encoding iso-8859-1 \
 986          --compose --subject foo \
 987          --from="Example <nobody@example.com>" \
 988          --to=nobody@example.com \
 989          --smtp-server="$(pwd)/fake.sendmail" \
 990          $patches &&
 991        grep "^utf8 body" msgtxt1 &&
 992        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
 993'
 994
 995test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
 996        clean_fake_sendmail &&
 997        git config sendemail.composeencoding iso-8859-1 &&
 998        (echo "#!$SHELL_PATH" &&
 999         echo "echo utf8 body: àéìöú >>\"\$1\""
1000        ) >fake-editor-utf8 &&
1001        chmod +x fake-editor-utf8 &&
1002          GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1003          git send-email \
1004          --compose-encoding iso-8859-2 \
1005          --compose --subject foo \
1006          --from="Example <nobody@example.com>" \
1007          --to=nobody@example.com \
1008          --smtp-server="$(pwd)/fake.sendmail" \
1009          $patches &&
1010        grep "^utf8 body" msgtxt1 &&
1011        grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1012'
1013
1014test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1015        clean_fake_sendmail &&
1016          GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1017          git send-email \
1018          --compose-encoding iso-8859-2 \
1019          --compose --subject utf8-sübjëct \
1020          --from="Example <nobody@example.com>" \
1021          --to=nobody@example.com \
1022          --smtp-server="$(pwd)/fake.sendmail" \
1023          $patches &&
1024        grep "^fake edit" msgtxt1 &&
1025        grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1026'
1027
1028test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1029        echo master > master &&
1030        git add master &&
1031        git commit -m"add master" &&
1032        test_must_fail git send-email --dry-run master 2>errors &&
1033        grep disambiguate errors
1034'
1035
1036test_expect_success $PREREQ 'feed two files' '
1037        rm -fr outdir &&
1038        git format-patch -2 -o outdir &&
1039        git send-email \
1040        --dry-run \
1041        --from="Example <nobody@example.com>" \
1042        --to=nobody@example.com \
1043        outdir/000?-*.patch 2>errors >out &&
1044        grep "^Subject: " out >subjects &&
1045        test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1046        test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1047'
1048
1049test_expect_success $PREREQ 'in-reply-to but no threading' '
1050        git send-email \
1051                --dry-run \
1052                --from="Example <nobody@example.com>" \
1053                --to=nobody@example.com \
1054                --in-reply-to="<in-reply-id@example.com>" \
1055                --nothread \
1056                $patches |
1057        grep "In-Reply-To: <in-reply-id@example.com>"
1058'
1059
1060test_expect_success $PREREQ 'no in-reply-to and no threading' '
1061        git send-email \
1062                --dry-run \
1063                --from="Example <nobody@example.com>" \
1064                --to=nobody@example.com \
1065                --nothread \
1066                $patches $patches >stdout &&
1067        ! grep "In-Reply-To: " stdout
1068'
1069
1070test_expect_success $PREREQ 'threading but no chain-reply-to' '
1071        git send-email \
1072                --dry-run \
1073                --from="Example <nobody@example.com>" \
1074                --to=nobody@example.com \
1075                --thread \
1076                --nochain-reply-to \
1077                $patches $patches >stdout &&
1078        grep "In-Reply-To: " stdout
1079'
1080
1081test_expect_success $PREREQ 'sendemail.to works' '
1082        git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1083        git send-email \
1084                --dry-run \
1085                --from="Example <nobody@example.com>" \
1086                $patches $patches >stdout &&
1087        grep "To: Somebody <somebody@ex.com>" stdout
1088'
1089
1090test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1091        git send-email \
1092                --dry-run \
1093                --from="Example <nobody@example.com>" \
1094                --no-to \
1095                --to=nobody@example.com \
1096                $patches $patches >stdout &&
1097        grep "To: nobody@example.com" stdout &&
1098        ! grep "To: Somebody <somebody@ex.com>" stdout
1099'
1100
1101test_expect_success $PREREQ 'sendemail.cc works' '
1102        git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1103        git send-email \
1104                --dry-run \
1105                --from="Example <nobody@example.com>" \
1106                --to=nobody@example.com \
1107                $patches $patches >stdout &&
1108        grep "Cc: Somebody <somebody@ex.com>" stdout
1109'
1110
1111test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1112        git send-email \
1113                --dry-run \
1114                --from="Example <nobody@example.com>" \
1115                --no-cc \
1116                --cc=bodies@example.com \
1117                --to=nobody@example.com \
1118                $patches $patches >stdout &&
1119        grep "Cc: bodies@example.com" stdout &&
1120        ! grep "Cc: Somebody <somebody@ex.com>" stdout
1121'
1122
1123test_expect_success $PREREQ 'sendemail.bcc works' '
1124        git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1125        git send-email \
1126                --dry-run \
1127                --from="Example <nobody@example.com>" \
1128                --to=nobody@example.com \
1129                --smtp-server relay.example.com \
1130                $patches $patches >stdout &&
1131        grep "RCPT TO:<other@ex.com>" stdout
1132'
1133
1134test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1135        git send-email \
1136                --dry-run \
1137                --from="Example <nobody@example.com>" \
1138                --no-bcc \
1139                --bcc=bodies@example.com \
1140                --to=nobody@example.com \
1141                --smtp-server relay.example.com \
1142                $patches $patches >stdout &&
1143        grep "RCPT TO:<bodies@example.com>" stdout &&
1144        ! grep "RCPT TO:<other@ex.com>" stdout
1145'
1146
1147test_expect_success $PREREQ 'patches To headers are used by default' '
1148        patch=`git format-patch -1 --to="bodies@example.com"` &&
1149        test_when_finished "rm $patch" &&
1150        git send-email \
1151                --dry-run \
1152                --from="Example <nobody@example.com>" \
1153                --smtp-server relay.example.com \
1154                $patch >stdout &&
1155        grep "RCPT TO:<bodies@example.com>" stdout
1156'
1157
1158test_expect_success $PREREQ 'patches To headers are appended to' '
1159        patch=`git format-patch -1 --to="bodies@example.com"` &&
1160        test_when_finished "rm $patch" &&
1161        git send-email \
1162                --dry-run \
1163                --from="Example <nobody@example.com>" \
1164                --to=nobody@example.com \
1165                --smtp-server relay.example.com \
1166                $patch >stdout &&
1167        grep "RCPT TO:<bodies@example.com>" stdout &&
1168        grep "RCPT TO:<nobody@example.com>" stdout
1169'
1170
1171test_expect_success $PREREQ 'To headers from files reset each patch' '
1172        patch1=`git format-patch -1 --to="bodies@example.com"` &&
1173        patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1174        test_when_finished "rm $patch1 && rm $patch2" &&
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                $patch1 $patch2 >stdout &&
1181        test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1182        test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1183        test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1184'
1185
1186test_expect_success $PREREQ 'setup expect' '
1187cat >email-using-8bit <<EOF
1188From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1189Message-Id: <bogus-message-id@example.com>
1190From: author@example.com
1191Date: Sat, 12 Jun 2010 15:53:58 +0200
1192Subject: subject goes here
1193
1194Dieser deutsche Text enthält einen Umlaut!
1195EOF
1196'
1197
1198test_expect_success $PREREQ 'setup expect' '
1199cat >expected <<EOF
1200Subject: subject goes here
1201EOF
1202'
1203
1204test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1205        clean_fake_sendmail &&
1206        echo bogus |
1207        git send-email --from=author@example.com --to=nobody@example.com \
1208                        --smtp-server="$(pwd)/fake.sendmail" \
1209                        --8bit-encoding=UTF-8 \
1210                        email-using-8bit >stdout &&
1211        grep "Subject" msgtxt1 >actual &&
1212        test_cmp expected actual
1213'
1214
1215test_expect_success $PREREQ 'setup expect' '
1216cat >content-type-decl <<EOF
1217MIME-Version: 1.0
1218Content-Type: text/plain; charset=UTF-8
1219Content-Transfer-Encoding: 8bit
1220EOF
1221'
1222
1223test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1224        clean_fake_sendmail &&
1225        echo |
1226        git send-email --from=author@example.com --to=nobody@example.com \
1227                        --smtp-server="$(pwd)/fake.sendmail" \
1228                        email-using-8bit >stdout &&
1229        grep "do not declare a Content-Transfer-Encoding" stdout &&
1230        grep email-using-8bit stdout &&
1231        grep "Which 8bit encoding" stdout &&
1232        egrep "Content|MIME" msgtxt1 >actual &&
1233        test_cmp actual content-type-decl
1234'
1235
1236test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1237        clean_fake_sendmail &&
1238        git config sendemail.assume8bitEncoding UTF-8 &&
1239        echo bogus |
1240        git send-email --from=author@example.com --to=nobody@example.com \
1241                        --smtp-server="$(pwd)/fake.sendmail" \
1242                        email-using-8bit >stdout &&
1243        egrep "Content|MIME" msgtxt1 >actual &&
1244        test_cmp actual content-type-decl
1245'
1246
1247test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1248        clean_fake_sendmail &&
1249        git config sendemail.assume8bitEncoding "bogus too" &&
1250        echo bogus |
1251        git send-email --from=author@example.com --to=nobody@example.com \
1252                        --smtp-server="$(pwd)/fake.sendmail" \
1253                        --8bit-encoding=UTF-8 \
1254                        email-using-8bit >stdout &&
1255        egrep "Content|MIME" msgtxt1 >actual &&
1256        test_cmp actual content-type-decl
1257'
1258
1259test_expect_success $PREREQ 'setup expect' '
1260cat >email-using-8bit <<EOF
1261From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1262Message-Id: <bogus-message-id@example.com>
1263From: author@example.com
1264Date: Sat, 12 Jun 2010 15:53:58 +0200
1265Subject: Dieser Betreff enthält auch einen Umlaut!
1266
1267Nothing to see here.
1268EOF
1269'
1270
1271test_expect_success $PREREQ 'setup expect' '
1272cat >expected <<EOF
1273Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1274EOF
1275'
1276
1277test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1278        clean_fake_sendmail &&
1279        echo bogus |
1280        git send-email --from=author@example.com --to=nobody@example.com \
1281                        --smtp-server="$(pwd)/fake.sendmail" \
1282                        --8bit-encoding=UTF-8 \
1283                        email-using-8bit >stdout &&
1284        grep "Subject" msgtxt1 >actual &&
1285        test_cmp expected actual
1286'
1287
1288# Note that the patches in this test are deliberately out of order; we
1289# want to make sure it works even if the cover-letter is not in the
1290# first mail.
1291test_expect_success $PREREQ 'refusing to send cover letter template' '
1292        clean_fake_sendmail &&
1293        rm -fr outdir &&
1294        git format-patch --cover-letter -2 -o outdir &&
1295        test_must_fail git send-email \
1296          --from="Example <nobody@example.com>" \
1297          --to=nobody@example.com \
1298          --smtp-server="$(pwd)/fake.sendmail" \
1299          outdir/0002-*.patch \
1300          outdir/0000-*.patch \
1301          outdir/0001-*.patch \
1302          2>errors >out &&
1303        grep "SUBJECT HERE" errors &&
1304        test -z "$(ls msgtxt*)"
1305'
1306
1307test_expect_success $PREREQ '--force sends cover letter template anyway' '
1308        clean_fake_sendmail &&
1309        rm -fr outdir &&
1310        git format-patch --cover-letter -2 -o outdir &&
1311        git send-email \
1312          --force \
1313          --from="Example <nobody@example.com>" \
1314          --to=nobody@example.com \
1315          --smtp-server="$(pwd)/fake.sendmail" \
1316          outdir/0002-*.patch \
1317          outdir/0000-*.patch \
1318          outdir/0001-*.patch \
1319          2>errors >out &&
1320        ! grep "SUBJECT HERE" errors &&
1321        test -n "$(ls msgtxt*)"
1322'
1323
1324test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1325        clean_fake_sendmail &&
1326        echo "alias sbd  somebody@example.org" >.mailrc &&
1327        git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1328        git config sendemail.aliasfiletype mailrc &&
1329        git send-email \
1330          --from="Example <nobody@example.com>" \
1331          --to=sbd \
1332          --smtp-server="$(pwd)/fake.sendmail" \
1333          outdir/0001-*.patch \
1334          2>errors >out &&
1335        grep "^!somebody@example\.org!$" commandline1
1336'
1337
1338test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1339        clean_fake_sendmail &&
1340        echo "alias sbd  someone@example.org" >~/.mailrc &&
1341        git config --replace-all sendemail.aliasesfile "~/.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 "^!someone@example\.org!$" commandline1
1350'
1351
1352test_done