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