8aa7c0335f576a54aa5555932291c2ebed957d2a
   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' '
  91cat >expected <<\EOF
  92!nobody@example.com!
  93!author@example.com!
  94!one@example.com!
  95!two@example.com!
  96EOF
  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' '
 109cat >expected <<\EOF
 110!patch@example.com!
 111!-i!
 112!nobody@example.com!
 113!author@example.com!
 114!one@example.com!
 115!two@example.com!
 116EOF
 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' '
 129cat >expected <<\EOF
 130!nobody@example.com!
 131!-i!
 132!nobody@example.com!
 133!author@example.com!
 134!one@example.com!
 135!two@example.com!
 136EOF
 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' '
1207cat >expected <<EOF
1208Subject: subject goes here
1209EOF
1210'
1211
1212test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1213        clean_fake_sendmail &&
1214        echo bogus |
1215        git send-email --from=author@example.com --to=nobody@example.com \
1216                        --smtp-server="$(pwd)/fake.sendmail" \
1217                        --8bit-encoding=UTF-8 \
1218                        email-using-8bit >stdout &&
1219        grep "Subject" msgtxt1 >actual &&
1220        test_cmp expected actual
1221'
1222
1223test_expect_success $PREREQ 'setup expect' '
1224cat >content-type-decl <<EOF
1225MIME-Version: 1.0
1226Content-Type: text/plain; charset=UTF-8
1227Content-Transfer-Encoding: 8bit
1228EOF
1229'
1230
1231test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1232        clean_fake_sendmail &&
1233        echo |
1234        git send-email --from=author@example.com --to=nobody@example.com \
1235                        --smtp-server="$(pwd)/fake.sendmail" \
1236                        email-using-8bit >stdout &&
1237        grep "do not declare a Content-Transfer-Encoding" stdout &&
1238        grep email-using-8bit stdout &&
1239        grep "Which 8bit encoding" stdout &&
1240        egrep "Content|MIME" msgtxt1 >actual &&
1241        test_cmp actual content-type-decl
1242'
1243
1244test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1245        clean_fake_sendmail &&
1246        git config sendemail.assume8bitEncoding UTF-8 &&
1247        echo bogus |
1248        git send-email --from=author@example.com --to=nobody@example.com \
1249                        --smtp-server="$(pwd)/fake.sendmail" \
1250                        email-using-8bit >stdout &&
1251        egrep "Content|MIME" msgtxt1 >actual &&
1252        test_cmp actual content-type-decl
1253'
1254
1255test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1256        clean_fake_sendmail &&
1257        git config sendemail.assume8bitEncoding "bogus too" &&
1258        echo bogus |
1259        git send-email --from=author@example.com --to=nobody@example.com \
1260                        --smtp-server="$(pwd)/fake.sendmail" \
1261                        --8bit-encoding=UTF-8 \
1262                        email-using-8bit >stdout &&
1263        egrep "Content|MIME" msgtxt1 >actual &&
1264        test_cmp actual content-type-decl
1265'
1266
1267test_expect_success $PREREQ 'setup expect' '
1268cat >email-using-8bit <<EOF
1269From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1270Message-Id: <bogus-message-id@example.com>
1271From: author@example.com
1272Date: Sat, 12 Jun 2010 15:53:58 +0200
1273Subject: Dieser Betreff enthält auch einen Umlaut!
1274
1275Nothing to see here.
1276EOF
1277'
1278
1279test_expect_success $PREREQ 'setup expect' '
1280cat >expected <<EOF
1281Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1282EOF
1283'
1284
1285test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1286        clean_fake_sendmail &&
1287        echo bogus |
1288        git send-email --from=author@example.com --to=nobody@example.com \
1289                        --smtp-server="$(pwd)/fake.sendmail" \
1290                        --8bit-encoding=UTF-8 \
1291                        email-using-8bit >stdout &&
1292        grep "Subject" msgtxt1 >actual &&
1293        test_cmp expected actual
1294'
1295
1296test_expect_success $PREREQ 'setup expect' '
1297cat >email-using-8bit <<EOF
1298From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1299Message-Id: <bogus-message-id@example.com>
1300From: A U Thor <author@example.com>
1301Date: Sat, 12 Jun 2010 15:53:58 +0200
1302Content-Type: text/plain; charset=UTF-8
1303Subject: Nothing to see here.
1304
1305Dieser Betreff enthält auch einen Umlaut!
1306EOF
1307'
1308
1309test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1310        clean_fake_sendmail &&
1311        git config sendemail.transferEncoding 7bit &&
1312        test_must_fail git send-email \
1313                --transfer-encoding=7bit \
1314                --smtp-server="$(pwd)/fake.sendmail" \
1315                email-using-8bit \
1316                2>errors >out &&
1317        grep "cannot send message as 7bit" errors &&
1318        test -z "$(ls msgtxt*)"
1319'
1320
1321test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1322        clean_fake_sendmail &&
1323        git config sendemail.transferEncoding 8bit
1324        test_must_fail git send-email \
1325                --transfer-encoding=7bit \
1326                --smtp-server="$(pwd)/fake.sendmail" \
1327                email-using-8bit \
1328                2>errors >out &&
1329        grep "cannot send message as 7bit" errors &&
1330        test -z "$(ls msgtxt*)"
1331'
1332
1333test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1334        clean_fake_sendmail &&
1335        git send-email \
1336                --transfer-encoding=8bit \
1337                --smtp-server="$(pwd)/fake.sendmail" \
1338                email-using-8bit \
1339                2>errors >out &&
1340        sed '1,/^$/d' msgtxt1 >actual &&
1341        sed '1,/^$/d' email-using-8bit >expected &&
1342        test_cmp expected actual
1343'
1344
1345test_expect_success $PREREQ 'setup expect' '
1346cat >expected <<EOF
1347Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1348EOF
1349'
1350
1351test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1352        clean_fake_sendmail &&
1353        git send-email \
1354                --transfer-encoding=quoted-printable \
1355                --smtp-server="$(pwd)/fake.sendmail" \
1356                email-using-8bit \
1357                2>errors >out &&
1358        sed '1,/^$/d' msgtxt1 >actual &&
1359        test_cmp expected actual
1360'
1361
1362test_expect_success $PREREQ 'setup expect' '
1363cat >expected <<EOF
1364RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1365EOF
1366'
1367
1368test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1369        clean_fake_sendmail &&
1370        git send-email \
1371                --transfer-encoding=base64 \
1372                --smtp-server="$(pwd)/fake.sendmail" \
1373                email-using-8bit \
1374                2>errors >out &&
1375        sed '1,/^$/d' msgtxt1 >actual &&
1376        test_cmp expected actual
1377'
1378
1379test_expect_success $PREREQ 'setup expect' '
1380cat >email-using-qp <<EOF
1381From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1382Message-Id: <bogus-message-id@example.com>
1383From: A U Thor <author@example.com>
1384Date: Sat, 12 Jun 2010 15:53:58 +0200
1385MIME-Version: 1.0
1386Content-Transfer-Encoding: quoted-printable
1387Content-Type: text/plain; charset=UTF-8
1388Subject: Nothing to see here.
1389
1390Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1391EOF
1392'
1393
1394test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1395        clean_fake_sendmail &&
1396        git send-email \
1397                --transfer-encoding=base64 \
1398                --smtp-server="$(pwd)/fake.sendmail" \
1399                email-using-qp \
1400                2>errors >out &&
1401        sed '1,/^$/d' msgtxt1 >actual &&
1402        test_cmp expected actual
1403'
1404
1405test_expect_success $PREREQ 'setup expect' "
1406tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1407From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1408Message-Id: <bogus-message-id@example.com>
1409From: A U Thor <author@example.com>
1410Date: Sat, 12 Jun 2010 15:53:58 +0200
1411Content-Type: text/plain; charset=UTF-8
1412Subject: Nothing to see here.
1413
1414Look, I have a CRLF and an = sign!%
1415EOF
1416"
1417
1418test_expect_success $PREREQ 'setup expect' '
1419cat >expected <<EOF
1420Look, I have a CRLF and an =3D sign!=0D
1421EOF
1422'
1423
1424test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1425        clean_fake_sendmail &&
1426        git send-email \
1427                --transfer-encoding=quoted-printable \
1428                --smtp-server="$(pwd)/fake.sendmail" \
1429                email-using-crlf \
1430                2>errors >out &&
1431        sed '1,/^$/d' msgtxt1 >actual &&
1432        test_cmp expected actual
1433'
1434
1435test_expect_success $PREREQ 'setup expect' '
1436cat >expected <<EOF
1437TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1438EOF
1439'
1440
1441test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1442        clean_fake_sendmail &&
1443        git send-email \
1444                --transfer-encoding=base64 \
1445                --smtp-server="$(pwd)/fake.sendmail" \
1446                email-using-crlf \
1447                2>errors >out &&
1448        sed '1,/^$/d' msgtxt1 >actual &&
1449        test_cmp expected actual
1450'
1451
1452
1453# Note that the patches in this test are deliberately out of order; we
1454# want to make sure it works even if the cover-letter is not in the
1455# first mail.
1456test_expect_success $PREREQ 'refusing to send cover letter template' '
1457        clean_fake_sendmail &&
1458        rm -fr outdir &&
1459        git format-patch --cover-letter -2 -o outdir &&
1460        test_must_fail git send-email \
1461                --from="Example <nobody@example.com>" \
1462                --to=nobody@example.com \
1463                --smtp-server="$(pwd)/fake.sendmail" \
1464                outdir/0002-*.patch \
1465                outdir/0000-*.patch \
1466                outdir/0001-*.patch \
1467                2>errors >out &&
1468        grep "SUBJECT HERE" errors &&
1469        test -z "$(ls msgtxt*)"
1470'
1471
1472test_expect_success $PREREQ '--force sends cover letter template anyway' '
1473        clean_fake_sendmail &&
1474        rm -fr outdir &&
1475        git format-patch --cover-letter -2 -o outdir &&
1476        git send-email \
1477                --force \
1478                --from="Example <nobody@example.com>" \
1479                --to=nobody@example.com \
1480                --smtp-server="$(pwd)/fake.sendmail" \
1481                outdir/0002-*.patch \
1482                outdir/0000-*.patch \
1483                outdir/0001-*.patch \
1484                2>errors >out &&
1485        ! grep "SUBJECT HERE" errors &&
1486        test -n "$(ls msgtxt*)"
1487'
1488
1489test_cover_addresses () {
1490        header="$1"
1491        shift
1492        clean_fake_sendmail &&
1493        rm -fr outdir &&
1494        git format-patch --cover-letter -2 -o outdir &&
1495        cover=`echo outdir/0000-*.patch` &&
1496        mv $cover cover-to-edit.patch &&
1497        perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1498        git send-email \
1499                --force \
1500                --from="Example <nobody@example.com>" \
1501                --no-to --no-cc \
1502                "$@" \
1503                --smtp-server="$(pwd)/fake.sendmail" \
1504                outdir/0000-*.patch \
1505                outdir/0001-*.patch \
1506                outdir/0002-*.patch \
1507                2>errors >out &&
1508        grep "^$header: extra@address.com" msgtxt1 >to1 &&
1509        grep "^$header: extra@address.com" msgtxt2 >to2 &&
1510        grep "^$header: extra@address.com" msgtxt3 >to3 &&
1511        test_line_count = 1 to1 &&
1512        test_line_count = 1 to2 &&
1513        test_line_count = 1 to3
1514}
1515
1516test_expect_success $PREREQ 'to-cover adds To to all mail' '
1517        test_cover_addresses "To" --to-cover
1518'
1519
1520test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1521        test_cover_addresses "Cc" --cc-cover
1522'
1523
1524test_expect_success $PREREQ 'tocover adds To to all mail' '
1525        test_config sendemail.tocover true &&
1526        test_cover_addresses "To"
1527'
1528
1529test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1530        test_config sendemail.cccover true &&
1531        test_cover_addresses "Cc"
1532'
1533
1534test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1535        clean_fake_sendmail &&
1536        echo "alias sbd  somebody@example.org" >.mailrc &&
1537        git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1538        git config sendemail.aliasfiletype mailrc &&
1539        git send-email \
1540                --from="Example <nobody@example.com>" \
1541                --to=sbd \
1542                --smtp-server="$(pwd)/fake.sendmail" \
1543                outdir/0001-*.patch \
1544                2>errors >out &&
1545        grep "^!somebody@example\.org!$" commandline1
1546'
1547
1548test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1549        clean_fake_sendmail &&
1550        echo "alias sbd  someone@example.org" >~/.mailrc &&
1551        git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1552        git config sendemail.aliasfiletype mailrc &&
1553        git send-email \
1554                --from="Example <nobody@example.com>" \
1555                --to=sbd \
1556                --smtp-server="$(pwd)/fake.sendmail" \
1557                outdir/0001-*.patch \
1558                2>errors >out &&
1559        grep "^!someone@example\.org!$" commandline1
1560'
1561
1562test_done