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