t / t9001-send-email.shon commit t9001: use existing helper in send-email test (ec3b4b0)
   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
   9replace_variable_fields () {
  10        sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
  11                -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
  12                -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
  13}
  14
  15test_expect_success $PREREQ 'prepare reference tree' '
  16        echo "1A quick brown fox jumps over the" >file &&
  17        echo "lazy dog" >>file &&
  18        git add file &&
  19        GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
  20'
  21
  22test_expect_success $PREREQ 'Setup helper tool' '
  23        write_script fake.sendmail <<-\EOF &&
  24        shift
  25        output=1
  26        while test -f commandline$output
  27        do
  28                output=$(($output+1))
  29        done
  30        for a
  31        do
  32                echo "!$a!"
  33        done >commandline$output
  34        cat >"msgtxt$output"
  35        EOF
  36        git add fake.sendmail &&
  37        GIT_AUTHOR_NAME="A" git commit -a -m "Second."
  38'
  39
  40clean_fake_sendmail () {
  41        rm -f commandline* msgtxt*
  42}
  43
  44test_expect_success $PREREQ 'Extract patches' '
  45        patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1)
  46'
  47
  48# Test no confirm early to ensure remaining tests will not hang
  49test_no_confirm () {
  50        rm -f no_confirm_okay
  51        echo n | \
  52                GIT_SEND_EMAIL_NOTTY=1 \
  53                git send-email \
  54                --from="Example <from@example.com>" \
  55                --to=nobody@example.com \
  56                --smtp-server="$(pwd)/fake.sendmail" \
  57                $@ \
  58                $patches >stdout &&
  59                test_must_fail grep "Send this email" stdout &&
  60                >no_confirm_okay
  61}
  62
  63# Exit immediately to prevent hang if a no-confirm test fails
  64check_no_confirm () {
  65        if ! test -f no_confirm_okay
  66        then
  67                say 'confirm test failed; skipping remaining tests to prevent hanging'
  68                PREREQ="$PREREQ,CHECK_NO_CONFIRM"
  69        fi
  70        return 0
  71}
  72
  73test_expect_success $PREREQ 'No confirm with --suppress-cc' '
  74        test_no_confirm --suppress-cc=sob &&
  75        check_no_confirm
  76'
  77
  78
  79test_expect_success $PREREQ 'No confirm with --confirm=never' '
  80        test_no_confirm --confirm=never &&
  81        check_no_confirm
  82'
  83
  84# leave sendemail.confirm set to never after this so that none of the
  85# remaining tests prompt unintentionally.
  86test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
  87        git config sendemail.confirm never &&
  88        test_no_confirm --compose --subject=foo &&
  89        check_no_confirm
  90'
  91
  92test_expect_success $PREREQ 'Send patches' '
  93        git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
  94'
  95
  96test_expect_success $PREREQ 'setup expect' '
  97        cat >expected <<-\EOF
  98        !nobody@example.com!
  99        !author@example.com!
 100        !one@example.com!
 101        !two@example.com!
 102        EOF
 103'
 104
 105test_expect_success $PREREQ 'Verify commandline' '
 106        test_cmp expected commandline1
 107'
 108
 109test_expect_success $PREREQ 'Send patches with --envelope-sender' '
 110        clean_fake_sendmail &&
 111        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
 112'
 113
 114test_expect_success $PREREQ 'setup expect' '
 115        cat >expected <<-\EOF
 116        !patch@example.com!
 117        !-i!
 118        !nobody@example.com!
 119        !author@example.com!
 120        !one@example.com!
 121        !two@example.com!
 122        EOF
 123'
 124
 125test_expect_success $PREREQ 'Verify commandline' '
 126        test_cmp expected commandline1
 127'
 128
 129test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
 130        clean_fake_sendmail &&
 131        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
 132'
 133
 134test_expect_success $PREREQ 'setup expect' '
 135        cat >expected <<-\EOF
 136        !nobody@example.com!
 137        !-i!
 138        !nobody@example.com!
 139        !author@example.com!
 140        !one@example.com!
 141        !two@example.com!
 142        EOF
 143'
 144
 145test_expect_success $PREREQ 'Verify commandline' '
 146        test_cmp expected commandline1
 147'
 148
 149test_expect_success $PREREQ 'setup expect for cc trailer' "
 150cat >expected-cc <<\EOF
 151!recipient@example.com!
 152!author@example.com!
 153!one@example.com!
 154!two@example.com!
 155!three@example.com!
 156!four@example.com!
 157!five@example.com!
 158EOF
 159"
 160
 161test_expect_success $PREREQ 'cc trailer with various syntax' '
 162        test_commit cc-trailer &&
 163        test_when_finished "git reset --hard HEAD^" &&
 164        git commit --amend -F - <<-EOF &&
 165        Test Cc: trailers.
 166
 167        Cc: one@example.com
 168        Cc: <two@example.com> # this is part of the name
 169        Cc: <three@example.com>, <four@example.com> # not.five@example.com
 170        Cc: "Some # Body" <five@example.com> [part.of.name.too]
 171        EOF
 172        clean_fake_sendmail &&
 173        git send-email -1 --to=recipient@example.com \
 174                --smtp-server="$(pwd)/fake.sendmail" &&
 175        test_cmp expected-cc commandline1
 176'
 177
 178test_expect_success $PREREQ 'setup expect' "
 179cat >expected-show-all-headers <<\EOF
 1800001-Second.patch
 181(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 182(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 183(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 184Dry-OK. Log says:
 185Server: relay.example.com
 186MAIL FROM:<from@example.com>
 187RCPT TO:<to@example.com>
 188RCPT TO:<cc@example.com>
 189RCPT TO:<author@example.com>
 190RCPT TO:<one@example.com>
 191RCPT TO:<two@example.com>
 192RCPT TO:<bcc@example.com>
 193From: Example <from@example.com>
 194To: to@example.com
 195Cc: cc@example.com,
 196        A <author@example.com>,
 197        One <one@example.com>,
 198        two@example.com
 199Subject: [PATCH 1/1] Second.
 200Date: DATE-STRING
 201Message-Id: MESSAGE-ID-STRING
 202X-Mailer: X-MAILER-STRING
 203In-Reply-To: <unique-message-id@example.com>
 204References: <unique-message-id@example.com>
 205
 206Result: OK
 207EOF
 208"
 209
 210test_suppress_self () {
 211        test_commit $3 &&
 212        test_when_finished "git reset --hard HEAD^" &&
 213
 214        write_script cccmd-sed <<-EOF &&
 215                sed -n -e s/^cccmd--//p "\$1"
 216        EOF
 217
 218        git commit --amend --author="$1 <$2>" -F - &&
 219        clean_fake_sendmail &&
 220        git format-patch --stdout -1 >"suppress-self-$3.patch" &&
 221
 222        git send-email --from="$1 <$2>" \
 223                --to=nobody@example.com \
 224                --cc-cmd=./cccmd-sed \
 225                --suppress-cc=self \
 226                --smtp-server="$(pwd)/fake.sendmail" \
 227                suppress-self-$3.patch &&
 228
 229        mv msgtxt1 msgtxt1-$3 &&
 230        sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
 231        >"expected-no-cc-$3" &&
 232
 233        (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
 234         test_cmp expected-no-cc-$3 actual-no-cc-$3)
 235}
 236
 237test_suppress_self_unquoted () {
 238        test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
 239                test suppress-cc.self unquoted-$3 with name $1 email $2
 240
 241                unquoted-$3
 242
 243                cccmd--$1 <$2>
 244
 245                Cc: $1 <$2>
 246                Signed-off-by: $1 <$2>
 247        EOF
 248}
 249
 250test_suppress_self_quoted () {
 251        test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
 252                test suppress-cc.self quoted-$3 with name $1 email $2
 253
 254                quoted-$3
 255
 256                cccmd--"$1" <$2>
 257
 258                Cc: $1 <$2>
 259                Cc: "$1" <$2>
 260                Signed-off-by: $1 <$2>
 261                Signed-off-by: "$1" <$2>
 262        EOF
 263}
 264
 265test_expect_success $PREREQ 'self name is suppressed' "
 266        test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
 267                'self_name_suppressed'
 268"
 269
 270test_expect_success $PREREQ 'self name with dot is suppressed' "
 271        test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
 272                'self_name_dot_suppressed'
 273"
 274
 275test_expect_success $PREREQ 'non-ascii self name is suppressed' "
 276        test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
 277                'non_ascii_self_suppressed'
 278"
 279
 280# This name is long enough to force format-patch to split it into multiple
 281# encoded-words, assuming it uses UTF-8 with the "Q" encoding.
 282test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
 283        test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
 284                'long_non_ascii_self_suppressed'
 285"
 286
 287test_expect_success $PREREQ 'sanitized self name is suppressed' "
 288        test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
 289                'self_name_sanitized_suppressed'
 290"
 291
 292test_expect_success $PREREQ 'Show all headers' '
 293        git send-email \
 294                --dry-run \
 295                --suppress-cc=sob \
 296                --from="Example <from@example.com>" \
 297                --to=to@example.com \
 298                --cc=cc@example.com \
 299                --bcc=bcc@example.com \
 300                --in-reply-to="<unique-message-id@example.com>" \
 301                --smtp-server relay.example.com \
 302                $patches | replace_variable_fields \
 303                >actual-show-all-headers &&
 304        test_cmp expected-show-all-headers actual-show-all-headers
 305'
 306
 307test_expect_success $PREREQ 'Prompting works' '
 308        clean_fake_sendmail &&
 309        (echo "to@example.com"
 310         echo ""
 311        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
 312                --smtp-server="$(pwd)/fake.sendmail" \
 313                $patches \
 314                2>errors &&
 315                grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
 316                grep "^To: to@example.com\$" msgtxt1
 317'
 318
 319test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
 320        clean_fake_sendmail &&
 321        (sane_unset GIT_AUTHOR_NAME &&
 322        sane_unset GIT_AUTHOR_EMAIL &&
 323        sane_unset GIT_COMMITTER_NAME &&
 324        sane_unset GIT_COMMITTER_EMAIL &&
 325        GIT_SEND_EMAIL_NOTTY=1 git send-email \
 326                --smtp-server="$(pwd)/fake.sendmail" \
 327                --to=to@example.com \
 328                $patches </dev/null 2>errors
 329        )
 330'
 331
 332test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
 333        clean_fake_sendmail &&
 334        (sane_unset GIT_AUTHOR_NAME &&
 335        sane_unset GIT_AUTHOR_EMAIL &&
 336        sane_unset GIT_COMMITTER_NAME &&
 337        sane_unset GIT_COMMITTER_EMAIL &&
 338        GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
 339        test_must_fail git send-email \
 340                --smtp-server="$(pwd)/fake.sendmail" \
 341                --to=to@example.com \
 342                $patches </dev/null 2>errors &&
 343        test_i18ngrep "tell me who you are" errors
 344        )
 345'
 346
 347test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
 348        write_script tocmd-sed <<-\EOF &&
 349        sed -n -e "s/^tocmd--//p" "$1"
 350        EOF
 351        write_script cccmd-sed <<-\EOF
 352        sed -n -e "s/^cccmd--//p" "$1"
 353        EOF
 354'
 355
 356test_expect_success $PREREQ 'tocmd works' '
 357        clean_fake_sendmail &&
 358        cp $patches tocmd.patch &&
 359        echo tocmd--tocmd@example.com >>tocmd.patch &&
 360        git send-email \
 361                --from="Example <nobody@example.com>" \
 362                --to-cmd=./tocmd-sed \
 363                --smtp-server="$(pwd)/fake.sendmail" \
 364                tocmd.patch \
 365                &&
 366        grep "^To: tocmd@example.com" msgtxt1
 367'
 368
 369test_expect_success $PREREQ 'cccmd works' '
 370        clean_fake_sendmail &&
 371        cp $patches cccmd.patch &&
 372        echo "cccmd--  cccmd@example.com" >>cccmd.patch &&
 373        git send-email \
 374                --from="Example <nobody@example.com>" \
 375                --to=nobody@example.com \
 376                --cc-cmd=./cccmd-sed \
 377                --smtp-server="$(pwd)/fake.sendmail" \
 378                cccmd.patch \
 379                &&
 380        grep "^ cccmd@example.com" msgtxt1
 381'
 382
 383test_expect_success $PREREQ 'reject long lines' '
 384        z8=zzzzzzzz &&
 385        z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
 386        z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
 387        clean_fake_sendmail &&
 388        cp $patches longline.patch &&
 389        echo $z512$z512 >>longline.patch &&
 390        test_must_fail git send-email \
 391                --from="Example <nobody@example.com>" \
 392                --to=nobody@example.com \
 393                --smtp-server="$(pwd)/fake.sendmail" \
 394                $patches longline.patch \
 395                2>errors &&
 396        grep longline.patch errors
 397'
 398
 399test_expect_success $PREREQ 'no patch was sent' '
 400        ! test -e commandline1
 401'
 402
 403test_expect_success $PREREQ 'Author From: in message body' '
 404        clean_fake_sendmail &&
 405        git send-email \
 406                --from="Example <nobody@example.com>" \
 407                --to=nobody@example.com \
 408                --smtp-server="$(pwd)/fake.sendmail" \
 409                $patches &&
 410        sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
 411        grep "From: A <author@example.com>" msgbody1
 412'
 413
 414test_expect_success $PREREQ 'Author From: not in message body' '
 415        clean_fake_sendmail &&
 416        git send-email \
 417                --from="A <author@example.com>" \
 418                --to=nobody@example.com \
 419                --smtp-server="$(pwd)/fake.sendmail" \
 420                $patches &&
 421        sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
 422        ! grep "From: A <author@example.com>" msgbody1
 423'
 424
 425test_expect_success $PREREQ 'allow long lines with --no-validate' '
 426        git send-email \
 427                --from="Example <nobody@example.com>" \
 428                --to=nobody@example.com \
 429                --smtp-server="$(pwd)/fake.sendmail" \
 430                --no-validate \
 431                $patches longline.patch \
 432                2>errors
 433'
 434
 435test_expect_success $PREREQ 'Invalid In-Reply-To' '
 436        clean_fake_sendmail &&
 437        git send-email \
 438                --from="Example <nobody@example.com>" \
 439                --to=nobody@example.com \
 440                --in-reply-to=" " \
 441                --smtp-server="$(pwd)/fake.sendmail" \
 442                $patches \
 443                2>errors &&
 444        ! grep "^In-Reply-To: < *>" msgtxt1
 445'
 446
 447test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
 448        clean_fake_sendmail &&
 449        (echo "From Example <from@example.com>"
 450         echo "To Example <to@example.com>"
 451         echo ""
 452        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
 453                --smtp-server="$(pwd)/fake.sendmail" \
 454                $patches 2>errors &&
 455        ! grep "^In-Reply-To: < *>" msgtxt1
 456'
 457
 458test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
 459        clean_fake_sendmail &&
 460        echo "<unique-message-id@example.com>" >expect &&
 461        git send-email \
 462                --from="Example <nobody@example.com>" \
 463                --to=nobody@example.com \
 464                --no-chain-reply-to \
 465                --in-reply-to="$(cat expect)" \
 466                --smtp-server="$(pwd)/fake.sendmail" \
 467                $patches $patches $patches \
 468                2>errors &&
 469        # The first message is a reply to --in-reply-to
 470        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
 471        test_cmp expect actual &&
 472        # Second and subsequent messages are replies to the first one
 473        sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
 474        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
 475        test_cmp expect actual &&
 476        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
 477        test_cmp expect actual
 478'
 479
 480test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
 481        clean_fake_sendmail &&
 482        echo "<unique-message-id@example.com>" >expect &&
 483        git send-email \
 484                --from="Example <nobody@example.com>" \
 485                --to=nobody@example.com \
 486                --chain-reply-to \
 487                --in-reply-to="$(cat expect)" \
 488                --smtp-server="$(pwd)/fake.sendmail" \
 489                $patches $patches $patches \
 490                2>errors &&
 491        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
 492        test_cmp expect actual &&
 493        sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
 494        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
 495        test_cmp expect actual &&
 496        sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
 497        sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
 498        test_cmp expect actual
 499'
 500
 501test_expect_success $PREREQ 'setup fake editor' '
 502        write_script fake-editor <<-\EOF
 503        echo fake edit >>"$1"
 504        EOF
 505'
 506
 507test_set_editor "$(pwd)/fake-editor"
 508
 509test_expect_success $PREREQ '--compose works' '
 510        clean_fake_sendmail &&
 511        git send-email \
 512        --compose --subject foo \
 513        --from="Example <nobody@example.com>" \
 514        --to=nobody@example.com \
 515        --smtp-server="$(pwd)/fake.sendmail" \
 516        $patches \
 517        2>errors
 518'
 519
 520test_expect_success $PREREQ 'first message is compose text' '
 521        grep "^fake edit" msgtxt1
 522'
 523
 524test_expect_success $PREREQ 'second message is patch' '
 525        grep "Subject:.*Second" msgtxt2
 526'
 527
 528test_expect_success $PREREQ 'setup expect' "
 529cat >expected-suppress-sob <<\EOF
 5300001-Second.patch
 531(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 532(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 533(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 534Dry-OK. Log says:
 535Server: relay.example.com
 536MAIL FROM:<from@example.com>
 537RCPT TO:<to@example.com>
 538RCPT TO:<cc@example.com>
 539RCPT TO:<author@example.com>
 540RCPT TO:<one@example.com>
 541RCPT TO:<two@example.com>
 542From: Example <from@example.com>
 543To: to@example.com
 544Cc: cc@example.com,
 545        A <author@example.com>,
 546        One <one@example.com>,
 547        two@example.com
 548Subject: [PATCH 1/1] Second.
 549Date: DATE-STRING
 550Message-Id: MESSAGE-ID-STRING
 551X-Mailer: X-MAILER-STRING
 552
 553Result: OK
 554EOF
 555"
 556
 557test_suppression () {
 558        git send-email \
 559                --dry-run \
 560                --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
 561                --from="Example <from@example.com>" \
 562                --to=to@example.com \
 563                --smtp-server relay.example.com \
 564                $patches | replace_variable_fields \
 565                >actual-suppress-$1${2+"-$2"} &&
 566        test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
 567}
 568
 569test_expect_success $PREREQ 'sendemail.cc set' '
 570        git config sendemail.cc cc@example.com &&
 571        test_suppression sob
 572'
 573
 574test_expect_success $PREREQ 'setup expect' "
 575cat >expected-suppress-sob <<\EOF
 5760001-Second.patch
 577(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 578(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 579(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 580Dry-OK. Log says:
 581Server: relay.example.com
 582MAIL FROM:<from@example.com>
 583RCPT TO:<to@example.com>
 584RCPT TO:<author@example.com>
 585RCPT TO:<one@example.com>
 586RCPT TO:<two@example.com>
 587From: Example <from@example.com>
 588To: to@example.com
 589Cc: A <author@example.com>,
 590        One <one@example.com>,
 591        two@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.cc unset' '
 602        git config --unset sendemail.cc &&
 603        test_suppression sob
 604'
 605
 606test_expect_success $PREREQ 'setup expect' "
 607cat >expected-suppress-cccmd <<\EOF
 6080001-Second.patch
 609(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 610(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 611(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 612(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 613Dry-OK. Log says:
 614Server: relay.example.com
 615MAIL FROM:<from@example.com>
 616RCPT TO:<to@example.com>
 617RCPT TO:<author@example.com>
 618RCPT TO:<one@example.com>
 619RCPT TO:<two@example.com>
 620RCPT TO:<committer@example.com>
 621From: Example <from@example.com>
 622To: to@example.com
 623Cc: A <author@example.com>,
 624        One <one@example.com>,
 625        two@example.com,
 626        C O Mitter <committer@example.com>
 627Subject: [PATCH 1/1] Second.
 628Date: DATE-STRING
 629Message-Id: MESSAGE-ID-STRING
 630X-Mailer: X-MAILER-STRING
 631
 632Result: OK
 633EOF
 634"
 635
 636test_expect_success $PREREQ 'sendemail.cccmd' '
 637        write_script cccmd <<-\EOF &&
 638        echo cc-cmd@example.com
 639        EOF
 640        git config sendemail.cccmd ./cccmd &&
 641        test_suppression cccmd
 642'
 643
 644test_expect_success $PREREQ 'setup expect' '
 645cat >expected-suppress-all <<\EOF
 6460001-Second.patch
 647Dry-OK. Log says:
 648Server: relay.example.com
 649MAIL FROM:<from@example.com>
 650RCPT TO:<to@example.com>
 651From: Example <from@example.com>
 652To: to@example.com
 653Subject: [PATCH 1/1] Second.
 654Date: DATE-STRING
 655Message-Id: MESSAGE-ID-STRING
 656X-Mailer: X-MAILER-STRING
 657
 658Result: OK
 659EOF
 660'
 661
 662test_expect_success $PREREQ '--suppress-cc=all' '
 663        test_suppression all
 664'
 665
 666test_expect_success $PREREQ 'setup expect' "
 667cat >expected-suppress-body <<\EOF
 6680001-Second.patch
 669(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 670(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 671(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 672(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
 673Dry-OK. Log says:
 674Server: relay.example.com
 675MAIL FROM:<from@example.com>
 676RCPT TO:<to@example.com>
 677RCPT TO:<author@example.com>
 678RCPT TO:<one@example.com>
 679RCPT TO:<two@example.com>
 680RCPT TO:<cc-cmd@example.com>
 681From: Example <from@example.com>
 682To: to@example.com
 683Cc: A <author@example.com>,
 684        One <one@example.com>,
 685        two@example.com,
 686        cc-cmd@example.com
 687Subject: [PATCH 1/1] Second.
 688Date: DATE-STRING
 689Message-Id: MESSAGE-ID-STRING
 690X-Mailer: X-MAILER-STRING
 691
 692Result: OK
 693EOF
 694"
 695
 696test_expect_success $PREREQ '--suppress-cc=body' '
 697        test_suppression body
 698'
 699
 700test_expect_success $PREREQ 'setup expect' "
 701cat >expected-suppress-body-cccmd <<\EOF
 7020001-Second.patch
 703(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 704(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 705(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 706Dry-OK. Log says:
 707Server: relay.example.com
 708MAIL FROM:<from@example.com>
 709RCPT TO:<to@example.com>
 710RCPT TO:<author@example.com>
 711RCPT TO:<one@example.com>
 712RCPT TO:<two@example.com>
 713From: Example <from@example.com>
 714To: to@example.com
 715Cc: A <author@example.com>,
 716        One <one@example.com>,
 717        two@example.com
 718Subject: [PATCH 1/1] Second.
 719Date: DATE-STRING
 720Message-Id: MESSAGE-ID-STRING
 721X-Mailer: X-MAILER-STRING
 722
 723Result: OK
 724EOF
 725"
 726
 727test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
 728        test_suppression body cccmd
 729'
 730
 731test_expect_success $PREREQ 'setup expect' "
 732cat >expected-suppress-sob <<\EOF
 7330001-Second.patch
 734(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 735(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 736(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 737Dry-OK. Log says:
 738Server: relay.example.com
 739MAIL FROM:<from@example.com>
 740RCPT TO:<to@example.com>
 741RCPT TO:<author@example.com>
 742RCPT TO:<one@example.com>
 743RCPT TO:<two@example.com>
 744From: Example <from@example.com>
 745To: to@example.com
 746Cc: A <author@example.com>,
 747        One <one@example.com>,
 748        two@example.com
 749Subject: [PATCH 1/1] Second.
 750Date: DATE-STRING
 751Message-Id: MESSAGE-ID-STRING
 752X-Mailer: X-MAILER-STRING
 753
 754Result: OK
 755EOF
 756"
 757
 758test_expect_success $PREREQ '--suppress-cc=sob' '
 759        test_might_fail git config --unset sendemail.cccmd &&
 760        test_suppression sob
 761'
 762
 763test_expect_success $PREREQ 'setup expect' "
 764cat >expected-suppress-bodycc <<\EOF
 7650001-Second.patch
 766(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 767(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
 768(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
 769(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 770Dry-OK. Log says:
 771Server: relay.example.com
 772MAIL FROM:<from@example.com>
 773RCPT TO:<to@example.com>
 774RCPT TO:<author@example.com>
 775RCPT TO:<one@example.com>
 776RCPT TO:<two@example.com>
 777RCPT TO:<committer@example.com>
 778From: Example <from@example.com>
 779To: to@example.com
 780Cc: A <author@example.com>,
 781        One <one@example.com>,
 782        two@example.com,
 783        C O Mitter <committer@example.com>
 784Subject: [PATCH 1/1] Second.
 785Date: DATE-STRING
 786Message-Id: MESSAGE-ID-STRING
 787X-Mailer: X-MAILER-STRING
 788
 789Result: OK
 790EOF
 791"
 792
 793test_expect_success $PREREQ '--suppress-cc=bodycc' '
 794        test_suppression bodycc
 795'
 796
 797test_expect_success $PREREQ 'setup expect' "
 798cat >expected-suppress-cc <<\EOF
 7990001-Second.patch
 800(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
 801(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
 802Dry-OK. Log says:
 803Server: relay.example.com
 804MAIL FROM:<from@example.com>
 805RCPT TO:<to@example.com>
 806RCPT TO:<author@example.com>
 807RCPT TO:<committer@example.com>
 808From: Example <from@example.com>
 809To: to@example.com
 810Cc: A <author@example.com>,
 811        C O Mitter <committer@example.com>
 812Subject: [PATCH 1/1] Second.
 813Date: DATE-STRING
 814Message-Id: MESSAGE-ID-STRING
 815X-Mailer: X-MAILER-STRING
 816
 817Result: OK
 818EOF
 819"
 820
 821test_expect_success $PREREQ '--suppress-cc=cc' '
 822        test_suppression cc
 823'
 824
 825test_confirm () {
 826        echo y | \
 827                GIT_SEND_EMAIL_NOTTY=1 \
 828                git send-email \
 829                --from="Example <nobody@example.com>" \
 830                --to=nobody@example.com \
 831                --smtp-server="$(pwd)/fake.sendmail" \
 832                $@ $patches >stdout &&
 833        grep "Send this email" stdout
 834}
 835
 836test_expect_success $PREREQ '--confirm=always' '
 837        test_confirm --confirm=always --suppress-cc=all
 838'
 839
 840test_expect_success $PREREQ '--confirm=auto' '
 841        test_confirm --confirm=auto
 842'
 843
 844test_expect_success $PREREQ '--confirm=cc' '
 845        test_confirm --confirm=cc
 846'
 847
 848test_expect_success $PREREQ '--confirm=compose' '
 849        test_confirm --confirm=compose --compose
 850'
 851
 852test_expect_success $PREREQ 'confirm by default (due to cc)' '
 853        test_when_finished git config sendemail.confirm never &&
 854        git config --unset sendemail.confirm &&
 855        test_confirm
 856'
 857
 858test_expect_success $PREREQ 'confirm by default (due to --compose)' '
 859        test_when_finished git config sendemail.confirm never &&
 860        git config --unset sendemail.confirm &&
 861        test_confirm --suppress-cc=all --compose
 862'
 863
 864test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
 865        test_when_finished git config sendemail.confirm never &&
 866        git config --unset sendemail.confirm &&
 867        rm -fr outdir &&
 868        git format-patch -2 -o outdir &&
 869        GIT_SEND_EMAIL_NOTTY=1 \
 870                git send-email \
 871                        --from="Example <nobody@example.com>" \
 872                        --to=nobody@example.com \
 873                        --smtp-server="$(pwd)/fake.sendmail" \
 874                        outdir/*.patch </dev/null
 875'
 876
 877test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
 878        test_when_finished git config sendemail.confirm never &&
 879        git config sendemail.confirm auto &&
 880        GIT_SEND_EMAIL_NOTTY=1 &&
 881        export GIT_SEND_EMAIL_NOTTY &&
 882                test_must_fail git send-email \
 883                        --from="Example <nobody@example.com>" \
 884                        --to=nobody@example.com \
 885                        --smtp-server="$(pwd)/fake.sendmail" \
 886                        $patches </dev/null
 887'
 888
 889test_expect_success $PREREQ 'confirm does not loop forever' '
 890        test_when_finished git config sendemail.confirm never &&
 891        git config sendemail.confirm auto &&
 892        GIT_SEND_EMAIL_NOTTY=1 &&
 893        export GIT_SEND_EMAIL_NOTTY &&
 894                yes "bogus" | test_must_fail git send-email \
 895                        --from="Example <nobody@example.com>" \
 896                        --to=nobody@example.com \
 897                        --smtp-server="$(pwd)/fake.sendmail" \
 898                        $patches
 899'
 900
 901test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
 902        clean_fake_sendmail &&
 903        rm -fr outdir &&
 904        git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
 905        git send-email \
 906        --from="Example <nobody@example.com>" \
 907        --to=nobody@example.com \
 908        --smtp-server="$(pwd)/fake.sendmail" \
 909        outdir/*.patch &&
 910        grep "^ " msgtxt1 |
 911        grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
 912'
 913
 914test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
 915        clean_fake_sendmail &&
 916        write_script fake-editor-utf8 <<-\EOF &&
 917        echo "utf8 body: àéìöú" >>"$1"
 918        EOF
 919        GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
 920        git send-email \
 921                --compose --subject foo \
 922                --from="Example <nobody@example.com>" \
 923                --to=nobody@example.com \
 924                --smtp-server="$(pwd)/fake.sendmail" \
 925                $patches &&
 926        grep "^utf8 body" msgtxt1 &&
 927        grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
 928'
 929
 930test_expect_success $PREREQ '--compose respects user mime type' '
 931        clean_fake_sendmail &&
 932        write_script fake-editor-utf8-mime <<-\EOF &&
 933        cat >"$1" <<-\EOM
 934        MIME-Version: 1.0
 935        Content-Type: text/plain; charset=iso-8859-1
 936        Content-Transfer-Encoding: 8bit
 937        Subject: foo
 938
 939        utf8 body: àéìöú
 940        EOM
 941        EOF
 942        GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
 943        git send-email \
 944                --compose --subject foo \
 945                --from="Example <nobody@example.com>" \
 946                --to=nobody@example.com \
 947                --smtp-server="$(pwd)/fake.sendmail" \
 948                $patches &&
 949        grep "^utf8 body" msgtxt1 &&
 950        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
 951        ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
 952'
 953
 954test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
 955        clean_fake_sendmail &&
 956        GIT_EDITOR="\"$(pwd)/fake-editor\"" \
 957        git send-email \
 958                --compose --subject utf8-sübjëct \
 959                --from="Example <nobody@example.com>" \
 960                --to=nobody@example.com \
 961                --smtp-server="$(pwd)/fake.sendmail" \
 962                $patches &&
 963        grep "^fake edit" msgtxt1 &&
 964        grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
 965'
 966
 967test_expect_success $PREREQ 'utf8 author is correctly passed on' '
 968        clean_fake_sendmail &&
 969        test_commit weird_author &&
 970        test_when_finished "git reset --hard HEAD^" &&
 971        git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
 972        git format-patch --stdout -1 >funny_name.patch &&
 973        git send-email --from="Example <nobody@example.com>" \
 974                --to=nobody@example.com \
 975                --smtp-server="$(pwd)/fake.sendmail" \
 976                funny_name.patch &&
 977        grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
 978'
 979
 980test_expect_success $PREREQ 'utf8 sender is not duplicated' '
 981        clean_fake_sendmail &&
 982        test_commit weird_sender &&
 983        test_when_finished "git reset --hard HEAD^" &&
 984        git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
 985        git format-patch --stdout -1 >funny_name.patch &&
 986        git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
 987                --to=nobody@example.com \
 988                --smtp-server="$(pwd)/fake.sendmail" \
 989                funny_name.patch &&
 990        grep "^From: " msgtxt1 >msgfrom &&
 991        test_line_count = 1 msgfrom
 992'
 993
 994test_expect_success $PREREQ 'sendemail.composeencoding works' '
 995        clean_fake_sendmail &&
 996        git config sendemail.composeencoding iso-8859-1 &&
 997        write_script fake-editor-utf8 <<-\EOF &&
 998        echo "utf8 body: àéìöú" >>"$1"
 999        EOF
1000        GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1001        git send-email \
1002                --compose --subject foo \
1003                --from="Example <nobody@example.com>" \
1004                --to=nobody@example.com \
1005                --smtp-server="$(pwd)/fake.sendmail" \
1006                $patches &&
1007        grep "^utf8 body" msgtxt1 &&
1008        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1009'
1010
1011test_expect_success $PREREQ '--compose-encoding works' '
1012        clean_fake_sendmail &&
1013        write_script fake-editor-utf8 <<-\EOF &&
1014        echo "utf8 body: àéìöú" >>"$1"
1015        EOF
1016        GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1017        git send-email \
1018                --compose-encoding iso-8859-1 \
1019                --compose --subject foo \
1020                --from="Example <nobody@example.com>" \
1021                --to=nobody@example.com \
1022                --smtp-server="$(pwd)/fake.sendmail" \
1023                $patches &&
1024        grep "^utf8 body" msgtxt1 &&
1025        grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1026'
1027
1028test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1029        clean_fake_sendmail &&
1030        git config sendemail.composeencoding iso-8859-1 &&
1031        write_script fake-editor-utf8 <<-\EOF &&
1032        echo "utf8 body: àéìöú" >>"$1"
1033        EOF
1034        GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1035        git send-email \
1036                --compose-encoding iso-8859-2 \
1037                --compose --subject foo \
1038                --from="Example <nobody@example.com>" \
1039                --to=nobody@example.com \
1040                --smtp-server="$(pwd)/fake.sendmail" \
1041                $patches &&
1042        grep "^utf8 body" msgtxt1 &&
1043        grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1044'
1045
1046test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1047        clean_fake_sendmail &&
1048        GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1049        git send-email \
1050                --compose-encoding iso-8859-2 \
1051                --compose --subject utf8-sübjëct \
1052                --from="Example <nobody@example.com>" \
1053                --to=nobody@example.com \
1054                --smtp-server="$(pwd)/fake.sendmail" \
1055                $patches &&
1056        grep "^fake edit" msgtxt1 &&
1057        grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1058'
1059
1060test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1061        echo master >master &&
1062        git add master &&
1063        git commit -m"add master" &&
1064        test_must_fail git send-email --dry-run master 2>errors &&
1065        grep disambiguate errors
1066'
1067
1068test_expect_success $PREREQ 'feed two files' '
1069        rm -fr outdir &&
1070        git format-patch -2 -o outdir &&
1071        git send-email \
1072                --dry-run \
1073                --from="Example <nobody@example.com>" \
1074                --to=nobody@example.com \
1075                outdir/000?-*.patch 2>errors >out &&
1076        grep "^Subject: " out >subjects &&
1077        test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1078        test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1079'
1080
1081test_expect_success $PREREQ 'in-reply-to but no threading' '
1082        git send-email \
1083                --dry-run \
1084                --from="Example <nobody@example.com>" \
1085                --to=nobody@example.com \
1086                --in-reply-to="<in-reply-id@example.com>" \
1087                --no-thread \
1088                $patches |
1089        grep "In-Reply-To: <in-reply-id@example.com>"
1090'
1091
1092test_expect_success $PREREQ 'no in-reply-to and no threading' '
1093        git send-email \
1094                --dry-run \
1095                --from="Example <nobody@example.com>" \
1096                --to=nobody@example.com \
1097                --no-thread \
1098                $patches $patches >stdout &&
1099        ! grep "In-Reply-To: " stdout
1100'
1101
1102test_expect_success $PREREQ 'threading but no chain-reply-to' '
1103        git send-email \
1104                --dry-run \
1105                --from="Example <nobody@example.com>" \
1106                --to=nobody@example.com \
1107                --thread \
1108                --no-chain-reply-to \
1109                $patches $patches >stdout &&
1110        grep "In-Reply-To: " stdout
1111'
1112
1113test_expect_success $PREREQ 'sendemail.to works' '
1114        git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1115        git send-email \
1116                --dry-run \
1117                --from="Example <nobody@example.com>" \
1118                $patches $patches >stdout &&
1119        grep "To: Somebody <somebody@ex.com>" stdout
1120'
1121
1122test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1123        git send-email \
1124                --dry-run \
1125                --from="Example <nobody@example.com>" \
1126                --no-to \
1127                --to=nobody@example.com \
1128                $patches $patches >stdout &&
1129        grep "To: nobody@example.com" stdout &&
1130        ! grep "To: Somebody <somebody@ex.com>" stdout
1131'
1132
1133test_expect_success $PREREQ 'sendemail.cc works' '
1134        git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1135        git send-email \
1136                --dry-run \
1137                --from="Example <nobody@example.com>" \
1138                --to=nobody@example.com \
1139                $patches $patches >stdout &&
1140        grep "Cc: Somebody <somebody@ex.com>" stdout
1141'
1142
1143test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1144        git send-email \
1145                --dry-run \
1146                --from="Example <nobody@example.com>" \
1147                --no-cc \
1148                --cc=bodies@example.com \
1149                --to=nobody@example.com \
1150                $patches $patches >stdout &&
1151        grep "Cc: bodies@example.com" stdout &&
1152        ! grep "Cc: Somebody <somebody@ex.com>" stdout
1153'
1154
1155test_expect_success $PREREQ 'sendemail.bcc works' '
1156        git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1157        git send-email \
1158                --dry-run \
1159                --from="Example <nobody@example.com>" \
1160                --to=nobody@example.com \
1161                --smtp-server relay.example.com \
1162                $patches $patches >stdout &&
1163        grep "RCPT TO:<other@ex.com>" stdout
1164'
1165
1166test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1167        git send-email \
1168                --dry-run \
1169                --from="Example <nobody@example.com>" \
1170                --no-bcc \
1171                --bcc=bodies@example.com \
1172                --to=nobody@example.com \
1173                --smtp-server relay.example.com \
1174                $patches $patches >stdout &&
1175        grep "RCPT TO:<bodies@example.com>" stdout &&
1176        ! grep "RCPT TO:<other@ex.com>" stdout
1177'
1178
1179test_expect_success $PREREQ 'patches To headers are used by default' '
1180        patch=$(git format-patch -1 --to="bodies@example.com") &&
1181        test_when_finished "rm $patch" &&
1182        git send-email \
1183                --dry-run \
1184                --from="Example <nobody@example.com>" \
1185                --smtp-server relay.example.com \
1186                $patch >stdout &&
1187        grep "RCPT TO:<bodies@example.com>" stdout
1188'
1189
1190test_expect_success $PREREQ 'patches To headers are appended to' '
1191        patch=$(git format-patch -1 --to="bodies@example.com") &&
1192        test_when_finished "rm $patch" &&
1193        git send-email \
1194                --dry-run \
1195                --from="Example <nobody@example.com>" \
1196                --to=nobody@example.com \
1197                --smtp-server relay.example.com \
1198                $patch >stdout &&
1199        grep "RCPT TO:<bodies@example.com>" stdout &&
1200        grep "RCPT TO:<nobody@example.com>" stdout
1201'
1202
1203test_expect_success $PREREQ 'To headers from files reset each patch' '
1204        patch1=$(git format-patch -1 --to="bodies@example.com") &&
1205        patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1206        test_when_finished "rm $patch1 && rm $patch2" &&
1207        git send-email \
1208                --dry-run \
1209                --from="Example <nobody@example.com>" \
1210                --to="nobody@example.com" \
1211                --smtp-server relay.example.com \
1212                $patch1 $patch2 >stdout &&
1213        test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1214        test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1215        test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1216'
1217
1218test_expect_success $PREREQ 'setup expect' '
1219cat >email-using-8bit <<\EOF
1220From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1221Message-Id: <bogus-message-id@example.com>
1222From: author@example.com
1223Date: Sat, 12 Jun 2010 15:53:58 +0200
1224Subject: subject goes here
1225
1226Dieser deutsche Text enthält einen Umlaut!
1227EOF
1228'
1229
1230test_expect_success $PREREQ 'setup expect' '
1231        echo "Subject: subject goes here" >expected
1232'
1233
1234test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1235        clean_fake_sendmail &&
1236        echo bogus |
1237        git send-email --from=author@example.com --to=nobody@example.com \
1238                        --smtp-server="$(pwd)/fake.sendmail" \
1239                        --8bit-encoding=UTF-8 \
1240                        email-using-8bit >stdout &&
1241        grep "Subject" msgtxt1 >actual &&
1242        test_cmp expected actual
1243'
1244
1245test_expect_success $PREREQ 'setup expect' '
1246        cat >content-type-decl <<-\EOF
1247        MIME-Version: 1.0
1248        Content-Type: text/plain; charset=UTF-8
1249        Content-Transfer-Encoding: 8bit
1250        EOF
1251'
1252
1253test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1254        clean_fake_sendmail &&
1255        echo |
1256        git send-email --from=author@example.com --to=nobody@example.com \
1257                        --smtp-server="$(pwd)/fake.sendmail" \
1258                        email-using-8bit >stdout &&
1259        grep "do not declare a Content-Transfer-Encoding" stdout &&
1260        grep email-using-8bit stdout &&
1261        grep "Which 8bit encoding" stdout &&
1262        egrep "Content|MIME" msgtxt1 >actual &&
1263        test_cmp actual content-type-decl
1264'
1265
1266test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1267        clean_fake_sendmail &&
1268        git config sendemail.assume8bitEncoding UTF-8 &&
1269        echo bogus |
1270        git send-email --from=author@example.com --to=nobody@example.com \
1271                        --smtp-server="$(pwd)/fake.sendmail" \
1272                        email-using-8bit >stdout &&
1273        egrep "Content|MIME" msgtxt1 >actual &&
1274        test_cmp actual content-type-decl
1275'
1276
1277test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1278        clean_fake_sendmail &&
1279        git config sendemail.assume8bitEncoding "bogus too" &&
1280        echo bogus |
1281        git send-email --from=author@example.com --to=nobody@example.com \
1282                        --smtp-server="$(pwd)/fake.sendmail" \
1283                        --8bit-encoding=UTF-8 \
1284                        email-using-8bit >stdout &&
1285        egrep "Content|MIME" msgtxt1 >actual &&
1286        test_cmp actual content-type-decl
1287'
1288
1289test_expect_success $PREREQ 'setup expect' '
1290        cat >email-using-8bit <<-\EOF
1291        From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1292        Message-Id: <bogus-message-id@example.com>
1293        From: author@example.com
1294        Date: Sat, 12 Jun 2010 15:53:58 +0200
1295        Subject: Dieser Betreff enthält auch einen Umlaut!
1296
1297        Nothing to see here.
1298        EOF
1299'
1300
1301test_expect_success $PREREQ 'setup expect' '
1302        cat >expected <<-\EOF
1303        Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1304        EOF
1305'
1306
1307test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1308        clean_fake_sendmail &&
1309        echo bogus |
1310        git send-email --from=author@example.com --to=nobody@example.com \
1311                        --smtp-server="$(pwd)/fake.sendmail" \
1312                        --8bit-encoding=UTF-8 \
1313                        email-using-8bit >stdout &&
1314        grep "Subject" msgtxt1 >actual &&
1315        test_cmp expected actual
1316'
1317
1318test_expect_success $PREREQ 'setup expect' '
1319        cat >email-using-8bit <<-\EOF
1320        From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1321        Message-Id: <bogus-message-id@example.com>
1322        From: A U Thor <author@example.com>
1323        Date: Sat, 12 Jun 2010 15:53:58 +0200
1324        Content-Type: text/plain; charset=UTF-8
1325        Subject: Nothing to see here.
1326
1327        Dieser Betreff enthält auch einen Umlaut!
1328        EOF
1329'
1330
1331test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1332        clean_fake_sendmail &&
1333        git config sendemail.transferEncoding 7bit &&
1334        test_must_fail git send-email \
1335                --transfer-encoding=7bit \
1336                --smtp-server="$(pwd)/fake.sendmail" \
1337                email-using-8bit \
1338                2>errors >out &&
1339        grep "cannot send message as 7bit" errors &&
1340        test -z "$(ls msgtxt*)"
1341'
1342
1343test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1344        clean_fake_sendmail &&
1345        git config sendemail.transferEncoding 8bit &&
1346        test_must_fail git send-email \
1347                --transfer-encoding=7bit \
1348                --smtp-server="$(pwd)/fake.sendmail" \
1349                email-using-8bit \
1350                2>errors >out &&
1351        grep "cannot send message as 7bit" errors &&
1352        test -z "$(ls msgtxt*)"
1353'
1354
1355test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1356        clean_fake_sendmail &&
1357        git send-email \
1358                --transfer-encoding=8bit \
1359                --smtp-server="$(pwd)/fake.sendmail" \
1360                email-using-8bit \
1361                2>errors >out &&
1362        sed '1,/^$/d' msgtxt1 >actual &&
1363        sed '1,/^$/d' email-using-8bit >expected &&
1364        test_cmp expected actual
1365'
1366
1367test_expect_success $PREREQ 'setup expect' '
1368        cat >expected <<-\EOF
1369        Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1370        EOF
1371'
1372
1373test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1374        clean_fake_sendmail &&
1375        git send-email \
1376                --transfer-encoding=quoted-printable \
1377                --smtp-server="$(pwd)/fake.sendmail" \
1378                email-using-8bit \
1379                2>errors >out &&
1380        sed '1,/^$/d' msgtxt1 >actual &&
1381        test_cmp expected actual
1382'
1383
1384test_expect_success $PREREQ 'setup expect' '
1385        cat >expected <<-\EOF
1386        RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1387        EOF
1388'
1389
1390test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1391        clean_fake_sendmail &&
1392        git send-email \
1393                --transfer-encoding=base64 \
1394                --smtp-server="$(pwd)/fake.sendmail" \
1395                email-using-8bit \
1396                2>errors >out &&
1397        sed '1,/^$/d' msgtxt1 >actual &&
1398        test_cmp expected actual
1399'
1400
1401test_expect_success $PREREQ 'setup expect' '
1402        cat >email-using-qp <<-\EOF
1403        From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1404        Message-Id: <bogus-message-id@example.com>
1405        From: A U Thor <author@example.com>
1406        Date: Sat, 12 Jun 2010 15:53:58 +0200
1407        MIME-Version: 1.0
1408        Content-Transfer-Encoding: quoted-printable
1409        Content-Type: text/plain; charset=UTF-8
1410        Subject: Nothing to see here.
1411
1412        Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1413        EOF
1414'
1415
1416test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1417        clean_fake_sendmail &&
1418        git send-email \
1419                --transfer-encoding=base64 \
1420                --smtp-server="$(pwd)/fake.sendmail" \
1421                email-using-qp \
1422                2>errors >out &&
1423        sed '1,/^$/d' msgtxt1 >actual &&
1424        test_cmp expected actual
1425'
1426
1427test_expect_success $PREREQ 'setup expect' "
1428tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1429From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1430Message-Id: <bogus-message-id@example.com>
1431From: A U Thor <author@example.com>
1432Date: Sat, 12 Jun 2010 15:53:58 +0200
1433Content-Type: text/plain; charset=UTF-8
1434Subject: Nothing to see here.
1435
1436Look, I have a CRLF and an = sign!%
1437EOF
1438"
1439
1440test_expect_success $PREREQ 'setup expect' '
1441        cat >expected <<-\EOF
1442        Look, I have a CRLF and an =3D sign!=0D
1443        EOF
1444'
1445
1446test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1447        clean_fake_sendmail &&
1448        git send-email \
1449                --transfer-encoding=quoted-printable \
1450                --smtp-server="$(pwd)/fake.sendmail" \
1451                email-using-crlf \
1452                2>errors >out &&
1453        sed '1,/^$/d' msgtxt1 >actual &&
1454        test_cmp expected actual
1455'
1456
1457test_expect_success $PREREQ 'setup expect' '
1458        cat >expected <<-\EOF
1459        TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1460        EOF
1461'
1462
1463test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1464        clean_fake_sendmail &&
1465        git send-email \
1466                --transfer-encoding=base64 \
1467                --smtp-server="$(pwd)/fake.sendmail" \
1468                email-using-crlf \
1469                2>errors >out &&
1470        sed '1,/^$/d' msgtxt1 >actual &&
1471        test_cmp expected actual
1472'
1473
1474
1475# Note that the patches in this test are deliberately out of order; we
1476# want to make sure it works even if the cover-letter is not in the
1477# first mail.
1478test_expect_success $PREREQ 'refusing to send cover letter template' '
1479        clean_fake_sendmail &&
1480        rm -fr outdir &&
1481        git format-patch --cover-letter -2 -o outdir &&
1482        test_must_fail git send-email \
1483                --from="Example <nobody@example.com>" \
1484                --to=nobody@example.com \
1485                --smtp-server="$(pwd)/fake.sendmail" \
1486                outdir/0002-*.patch \
1487                outdir/0000-*.patch \
1488                outdir/0001-*.patch \
1489                2>errors >out &&
1490        grep "SUBJECT HERE" errors &&
1491        test -z "$(ls msgtxt*)"
1492'
1493
1494test_expect_success $PREREQ '--force sends cover letter template anyway' '
1495        clean_fake_sendmail &&
1496        rm -fr outdir &&
1497        git format-patch --cover-letter -2 -o outdir &&
1498        git send-email \
1499                --force \
1500                --from="Example <nobody@example.com>" \
1501                --to=nobody@example.com \
1502                --smtp-server="$(pwd)/fake.sendmail" \
1503                outdir/0002-*.patch \
1504                outdir/0000-*.patch \
1505                outdir/0001-*.patch \
1506                2>errors >out &&
1507        ! grep "SUBJECT HERE" errors &&
1508        test -n "$(ls msgtxt*)"
1509'
1510
1511test_cover_addresses () {
1512        header="$1"
1513        shift
1514        clean_fake_sendmail &&
1515        rm -fr outdir &&
1516        git format-patch --cover-letter -2 -o outdir &&
1517        cover=$(echo outdir/0000-*.patch) &&
1518        mv $cover cover-to-edit.patch &&
1519        perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1520        git send-email \
1521                --force \
1522                --from="Example <nobody@example.com>" \
1523                --no-to --no-cc \
1524                "$@" \
1525                --smtp-server="$(pwd)/fake.sendmail" \
1526                outdir/0000-*.patch \
1527                outdir/0001-*.patch \
1528                outdir/0002-*.patch \
1529                2>errors >out &&
1530        grep "^$header: extra@address.com" msgtxt1 >to1 &&
1531        grep "^$header: extra@address.com" msgtxt2 >to2 &&
1532        grep "^$header: extra@address.com" msgtxt3 >to3 &&
1533        test_line_count = 1 to1 &&
1534        test_line_count = 1 to2 &&
1535        test_line_count = 1 to3
1536}
1537
1538test_expect_success $PREREQ 'to-cover adds To to all mail' '
1539        test_cover_addresses "To" --to-cover
1540'
1541
1542test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1543        test_cover_addresses "Cc" --cc-cover
1544'
1545
1546test_expect_success $PREREQ 'tocover adds To to all mail' '
1547        test_config sendemail.tocover true &&
1548        test_cover_addresses "To"
1549'
1550
1551test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1552        test_config sendemail.cccover true &&
1553        test_cover_addresses "Cc"
1554'
1555
1556test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1557        clean_fake_sendmail &&
1558        echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1559        git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1560        git config sendemail.aliasfiletype mutt &&
1561        git send-email \
1562                --from="Example <nobody@example.com>" \
1563                --to=sbd \
1564                --smtp-server="$(pwd)/fake.sendmail" \
1565                outdir/0001-*.patch \
1566                2>errors >out &&
1567        grep "^!somebody@example\.org!$" commandline1 &&
1568        grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1569'
1570
1571test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1572        clean_fake_sendmail &&
1573        echo "alias sbd  somebody@example.org" >.mailrc &&
1574        git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1575        git config sendemail.aliasfiletype mailrc &&
1576        git send-email \
1577                --from="Example <nobody@example.com>" \
1578                --to=sbd \
1579                --smtp-server="$(pwd)/fake.sendmail" \
1580                outdir/0001-*.patch \
1581                2>errors >out &&
1582        grep "^!somebody@example\.org!$" commandline1
1583'
1584
1585test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1586        clean_fake_sendmail &&
1587        echo "alias sbd  someone@example.org" >"$HOME/.mailrc" &&
1588        git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1589        git config sendemail.aliasfiletype mailrc &&
1590        git send-email \
1591                --from="Example <nobody@example.com>" \
1592                --to=sbd \
1593                --smtp-server="$(pwd)/fake.sendmail" \
1594                outdir/0001-*.patch \
1595                2>errors >out &&
1596        grep "^!someone@example\.org!$" commandline1
1597'
1598
1599test_dump_aliases () {
1600        msg="$1" && shift &&
1601        filetype="$1" && shift &&
1602        printf '%s\n' "$@" >expect &&
1603        cat >.tmp-email-aliases &&
1604
1605        test_expect_success $PREREQ "$msg" '
1606                clean_fake_sendmail && rm -fr outdir &&
1607                git config --replace-all sendemail.aliasesfile \
1608                        "$(pwd)/.tmp-email-aliases" &&
1609                git config sendemail.aliasfiletype "$filetype" &&
1610                git send-email --dump-aliases 2>errors >actual &&
1611                test_cmp expect actual
1612        '
1613}
1614
1615test_dump_aliases '--dump-aliases sendmail format' \
1616        'sendmail' \
1617        'abgroup' \
1618        'alice' \
1619        'bcgrp' \
1620        'bob' \
1621        'chloe' <<-\EOF
1622        alice: Alice W Land <awol@example.com>
1623        bob: Robert Bobbyton <bob@example.com>
1624        chloe: chloe@example.com
1625        abgroup: alice, bob
1626        bcgrp: bob, chloe, Other <o@example.com>
1627        EOF
1628
1629test_dump_aliases '--dump-aliases mutt format' \
1630        'mutt' \
1631        'alice' \
1632        'bob' \
1633        'chloe' \
1634        'donald' <<-\EOF
1635        alias alice Alice W Land <awol@example.com>
1636        alias donald Donald C Carlton <donc@example.com>
1637        alias bob Robert Bobbyton <bob@example.com>
1638        alias chloe chloe@example.com
1639        EOF
1640
1641test_dump_aliases '--dump-aliases mailrc format' \
1642        'mailrc' \
1643        'alice' \
1644        'bob' \
1645        'chloe' \
1646        'eve' <<-\EOF
1647        alias alice   Alice W Land <awol@example.com>
1648        alias eve     Eve <eve@example.com>
1649        alias bob     Robert Bobbyton <bob@example.com>
1650        alias chloe   chloe@example.com
1651        EOF
1652
1653test_dump_aliases '--dump-aliases pine format' \
1654        'pine' \
1655        'alice' \
1656        'bob' \
1657        'chloe' \
1658        'eve' <<-\EOF
1659        alice   Alice W Land    <awol@example.com>
1660        eve     Eve     <eve@example.com>
1661        bob     Robert  Bobbyton <bob@example.com>
1662        chloe           chloe@example.com
1663        EOF
1664
1665test_dump_aliases '--dump-aliases gnus format' \
1666        'gnus' \
1667        'alice' \
1668        'bob' \
1669        'chloe' \
1670        'eve' <<-\EOF
1671        (define-mail-alias "alice" "awol@example.com")
1672        (define-mail-alias "eve" "eve@example.com")
1673        (define-mail-alias "bob" "bob@example.com")
1674        (define-mail-alias "chloe" "chloe@example.com")
1675        EOF
1676
1677test_expect_success '--dump-aliases must be used alone' '
1678        test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1679'
1680
1681test_sendmail_aliases () {
1682        msg="$1" && shift &&
1683        expect="$@" &&
1684        cat >.tmp-email-aliases &&
1685
1686        test_expect_success $PREREQ "$msg" '
1687                clean_fake_sendmail && rm -fr outdir &&
1688                git format-patch -1 -o outdir &&
1689                git config --replace-all sendemail.aliasesfile \
1690                        "$(pwd)/.tmp-email-aliases" &&
1691                git config sendemail.aliasfiletype sendmail &&
1692                git send-email \
1693                        --from="Example <nobody@example.com>" \
1694                        --to=alice --to=bcgrp \
1695                        --smtp-server="$(pwd)/fake.sendmail" \
1696                        outdir/0001-*.patch \
1697                        2>errors >out &&
1698                for i in $expect
1699                do
1700                        grep "^!$i!$" commandline1 || return 1
1701                done
1702        '
1703}
1704
1705test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1706        'awol@example\.com' \
1707        'bob@example\.com' \
1708        'chloe@example\.com' \
1709        'o@example\.com' <<-\EOF
1710        alice: Alice W Land <awol@example.com>
1711        bob: Robert Bobbyton <bob@example.com>
1712        # this is a comment
1713           # this is also a comment
1714        chloe: chloe@example.com
1715        abgroup: alice, bob
1716        bcgrp: bob, chloe, Other <o@example.com>
1717        EOF
1718
1719test_sendmail_aliases 'sendmail aliases line folding' \
1720        alice1 \
1721        bob1 bob2 \
1722        chuck1 chuck2 \
1723        darla1 darla2 darla3 \
1724        elton1 elton2 elton3 \
1725        fred1 fred2 \
1726        greg1 <<-\EOF
1727        alice: alice1
1728        bob: bob1,\
1729        bob2
1730        chuck: chuck1,
1731            chuck2
1732        darla: darla1,\
1733        darla2,
1734            darla3
1735        elton: elton1,
1736            elton2,\
1737        elton3
1738        fred: fred1,\
1739            fred2
1740        greg: greg1
1741        bcgrp: bob, chuck, darla, elton, fred, greg
1742        EOF
1743
1744test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1745        alice1 bob1 <<-\EOF
1746            alice: alice1
1747        bcgrp: bob1\
1748        EOF
1749
1750test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1751        EOF
1752
1753test_expect_success $PREREQ 'alias support in To header' '
1754        clean_fake_sendmail &&
1755        echo "alias sbd  someone@example.org" >.mailrc &&
1756        test_config sendemail.aliasesfile ".mailrc" &&
1757        test_config sendemail.aliasfiletype mailrc &&
1758        git format-patch --stdout -1 --to=sbd >aliased.patch &&
1759        git send-email \
1760                --from="Example <nobody@example.com>" \
1761                --smtp-server="$(pwd)/fake.sendmail" \
1762                aliased.patch \
1763                2>errors >out &&
1764        grep "^!someone@example\.org!$" commandline1
1765'
1766
1767test_expect_success $PREREQ 'alias support in Cc header' '
1768        clean_fake_sendmail &&
1769        echo "alias sbd  someone@example.org" >.mailrc &&
1770        test_config sendemail.aliasesfile ".mailrc" &&
1771        test_config sendemail.aliasfiletype mailrc &&
1772        git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1773        git send-email \
1774                --from="Example <nobody@example.com>" \
1775                --smtp-server="$(pwd)/fake.sendmail" \
1776                aliased.patch \
1777                2>errors >out &&
1778        grep "^!someone@example\.org!$" commandline1
1779'
1780
1781test_expect_success $PREREQ 'tocmd works with aliases' '
1782        clean_fake_sendmail &&
1783        echo "alias sbd  someone@example.org" >.mailrc &&
1784        test_config sendemail.aliasesfile ".mailrc" &&
1785        test_config sendemail.aliasfiletype mailrc &&
1786        git format-patch --stdout -1 >tocmd.patch &&
1787        echo tocmd--sbd >>tocmd.patch &&
1788        git send-email \
1789                --from="Example <nobody@example.com>" \
1790                --to-cmd=./tocmd-sed \
1791                --smtp-server="$(pwd)/fake.sendmail" \
1792                tocmd.patch \
1793                2>errors >out &&
1794        grep "^!someone@example\.org!$" commandline1
1795'
1796
1797test_expect_success $PREREQ 'cccmd works with aliases' '
1798        clean_fake_sendmail &&
1799        echo "alias sbd  someone@example.org" >.mailrc &&
1800        test_config sendemail.aliasesfile ".mailrc" &&
1801        test_config sendemail.aliasfiletype mailrc &&
1802        git format-patch --stdout -1 >cccmd.patch &&
1803        echo cccmd--sbd >>cccmd.patch &&
1804        git send-email \
1805                --from="Example <nobody@example.com>" \
1806                --cc-cmd=./cccmd-sed \
1807                --smtp-server="$(pwd)/fake.sendmail" \
1808                cccmd.patch \
1809                2>errors >out &&
1810        grep "^!someone@example\.org!$" commandline1
1811'
1812
1813do_xmailer_test () {
1814        expected=$1 params=$2 &&
1815        git format-patch -1 &&
1816        git send-email \
1817                --from="Example <nobody@example.com>" \
1818                --to=someone@example.com \
1819                --smtp-server="$(pwd)/fake.sendmail" \
1820                $params \
1821                0001-*.patch \
1822                2>errors >out &&
1823        { grep '^X-Mailer:' out || :; } >mailer &&
1824        test_line_count = $expected mailer
1825}
1826
1827test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1828        do_xmailer_test 1 "--xmailer" &&
1829        do_xmailer_test 0 "--no-xmailer"
1830'
1831
1832test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1833        test_config sendemail.xmailer true &&
1834        do_xmailer_test 1 "" &&
1835        do_xmailer_test 0 "--no-xmailer" &&
1836        do_xmailer_test 1 "--xmailer"
1837'
1838
1839test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1840        test_config sendemail.xmailer false &&
1841        do_xmailer_test 0 "" &&
1842        do_xmailer_test 0 "--no-xmailer" &&
1843        do_xmailer_test 1 "--xmailer"
1844'
1845
1846test_expect_success $PREREQ 'setup expected-list' '
1847        git send-email \
1848        --dry-run \
1849        --from="Example <from@example.com>" \
1850        --to="To 1 <to1@example.com>" \
1851        --to="to2@example.com" \
1852        --to="to3@example.com" \
1853        --cc="Cc 1 <cc1@example.com>" \
1854        --cc="Cc2 <cc2@example.com>" \
1855        --bcc="bcc1@example.com" \
1856        --bcc="bcc2@example.com" \
1857        0001-add-master.patch | replace_variable_fields \
1858        >expected-list
1859'
1860
1861test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
1862        git send-email \
1863        --dry-run \
1864        --from="Example <from@example.com>" \
1865        --to="To 1 <to1@example.com>, to2@example.com" \
1866        --to="to3@example.com" \
1867        --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1868        --bcc="bcc1@example.com, bcc2@example.com" \
1869        0001-add-master.patch | replace_variable_fields \
1870        >actual-list &&
1871        test_cmp expected-list actual-list
1872'
1873
1874test_expect_success $PREREQ 'aliases work with email list' '
1875        echo "alias to2 to2@example.com" >.mutt &&
1876        echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1877        test_config sendemail.aliasesfile ".mutt" &&
1878        test_config sendemail.aliasfiletype mutt &&
1879        git send-email \
1880        --dry-run \
1881        --from="Example <from@example.com>" \
1882        --to="To 1 <to1@example.com>, to2, to3@example.com" \
1883        --cc="cc1, Cc2 <cc2@example.com>" \
1884        --bcc="bcc1@example.com, bcc2@example.com" \
1885        0001-add-master.patch | replace_variable_fields \
1886        >actual-list &&
1887        test_cmp expected-list actual-list
1888'
1889
1890test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
1891        echo "alias to2 to2@example.com" >.mutt &&
1892        echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1893        test_config sendemail.aliasesfile ".mutt" &&
1894        test_config sendemail.aliasfiletype mutt &&
1895        TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
1896        TO2=$(echo "QZto2" | qz_to_tab_space) &&
1897        CC1=$(echo "cc1" | append_cr) &&
1898        BCC1=$(echo "Q bcc1@example.com Q" | q_to_nul) &&
1899        git send-email \
1900        --dry-run \
1901        --from="        Example <from@example.com>" \
1902        --to="$TO1" \
1903        --to="$TO2" \
1904        --to="  to3@example.com   " \
1905        --cc="$CC1" \
1906        --cc="Cc2 <cc2@example.com>" \
1907        --bcc="$BCC1" \
1908        --bcc="bcc2@example.com" \
1909        0001-add-master.patch | replace_variable_fields \
1910        >actual-list &&
1911        test_cmp expected-list actual-list
1912'
1913
1914test_done