Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t9001-send-email.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t9001-send-email.sh` 2866 lines · 83675 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='git send-email' 4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 6 7 . ./test-lib.sh 8 9 # May be altered later in the test 10 PREREQ="PERL" 11 12 replace_variable_fields () { 13 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ 14 -e "s/^\(Message-ID:\).*/\1 MESSAGE-ID-STRING/" \ 15 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" 16 } 17 18 test_expect_success $PREREQ 'prepare reference tree' ' 19 echo "1A quick brown fox jumps over the" >file && 20 echo "lazy dog" >>file && 21 git add file && 22 GIT_AUTHOR_NAME="A" git commit -a -m "Initial." 23 ' 24 25 test_expect_success $PREREQ 'Setup helper tool' ' 26 write_script fake.sendmail <<-\EOF && 27 shift 28 output=1 29 while test -f commandline$output 30 do 31 output=$(($output+1)) 32 done 33 for a 34 do 35 echo "!$a!" 36 done >commandline$output 37 cat >"msgtxt$output" 38 EOF 39 git add fake.sendmail && 40 GIT_AUTHOR_NAME="A" git commit -a -m "Second." 41 ' 42 43 clean_fake_sendmail () { 44 rm -f commandline* msgtxt* 45 } 46 47 test_expect_success $PREREQ 'Extract patches' ' 48 patches=$(git format-patch -s --cc="One " --cc=two@example.com -n HEAD^1) && 49 threaded_patches=$(git format-patch -o threaded --thread=shallow -s --in-reply-to="format" HEAD^1) 50 ' 51 52 # Test no confirm early to ensure remaining tests will not hang 53 test_no_confirm () { 54 rm -f no_confirm_okay 55 echo n | \ 56 GIT_SEND_EMAIL_NOTTY=1 \ 57 git send-email \ 58 --from="Example " \ 59 --to=nobody@example.com \ 60 --smtp-server="$(pwd)/fake.sendmail" \ 61 $@ \ 62 $patches >stdout && 63 ! grep "Send this email" stdout && 64 >no_confirm_okay 65 } 66 67 # Exit immediately to prevent hang if a no-confirm test fails 68 check_no_confirm () { 69 if ! test -f no_confirm_okay 70 then 71 say 'confirm test failed; skipping remaining tests to prevent hanging' 72 PREREQ="$PREREQ,CHECK_NO_CONFIRM" 73 fi 74 return 0 75 } 76 77 test_expect_success $PREREQ 'No confirm with --suppress-cc' ' 78 test_no_confirm --suppress-cc=sob && 79 check_no_confirm 80 ' 81 82 83 test_expect_success $PREREQ 'No confirm with --confirm=never' ' 84 test_no_confirm --confirm=never && 85 check_no_confirm 86 ' 87 88 # leave sendemail.confirm set to never after this so that none of the 89 # remaining tests prompt unintentionally. 90 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' ' 91 git config sendemail.confirm never && 92 test_no_confirm --compose --subject=foo && 93 check_no_confirm 94 ' 95 96 test_expect_success $PREREQ 'Send patches' ' 97 git send-email --suppress-cc=sob --from="Example " --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors 98 ' 99 100 test_expect_success $PREREQ 'setup expect' ' 101 cat >expected <<-\EOF 102 !nobody@example.com! 103 !author@example.com! 104 !one@example.com! 105 !two@example.com! 106 EOF 107 ' 108 109 test_expect_success $PREREQ 'Verify commandline' ' 110 test_cmp expected commandline1 111 ' 112 113 test_expect_success $PREREQ 'Send patches with --envelope-sender' ' 114 clean_fake_sendmail && 115 git send-email --envelope-sender="Patch Contributor " --suppress-cc=sob --from="Example " --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors 116 ' 117 118 test_expect_success $PREREQ 'setup expect' ' 119 cat >expected <<-\EOF 120 !patch@example.com! 121 !-i! 122 !nobody@example.com! 123 !author@example.com! 124 !one@example.com! 125 !two@example.com! 126 EOF 127 ' 128 129 test_expect_success $PREREQ 'Verify commandline' ' 130 test_cmp expected commandline1 131 ' 132 133 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' ' 134 clean_fake_sendmail && 135 git send-email --envelope-sender=auto --suppress-cc=sob --from="Example " --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors 136 ' 137 138 test_expect_success $PREREQ 'setup expect' ' 139 cat >expected <<-\EOF 140 !nobody@example.com! 141 !-i! 142 !nobody@example.com! 143 !author@example.com! 144 !one@example.com! 145 !two@example.com! 146 EOF 147 ' 148 149 test_expect_success $PREREQ 'Verify commandline' ' 150 test_cmp expected commandline1 151 ' 152 153 test_expect_success $PREREQ 'setup expect for cc trailer' " 154 cat >expected-cc <<\EOF 155 !recipient@example.com! 156 !author@example.com! 157 !one@example.com! 158 !two@example.com! 159 !three@example.com! 160 !four@example.com! 161 !five@example.com! 162 !six@example.com! 163 EOF 164 " 165 166 test_expect_success $PREREQ 'cc trailer with various syntax' ' 167 test_commit cc-trailer && 168 test_when_finished "git reset --hard HEAD^" && 169 git commit --amend -F - <<-EOF && 170 Test Cc: trailers. 171 172 Cc: one@example.com 173 Cc: # trailing comments are ignored 174 Cc: , one address per line 175 Cc: "Some # Body" [ ] 176 Cc: five@example.com # not.six@example.com 177 Cc: six@example.com, not.seven@example.com 178 EOF 179 clean_fake_sendmail && 180 git send-email -1 --to=recipient@example.com \ 181 --smtp-server="$(pwd)/fake.sendmail" && 182 test_cmp expected-cc commandline1 183 ' 184 185 test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' " 186 write_script expected-cc-script.sh <<-EOF 187 echo 'One Person (supporter:THIS (FOO/bar))' 188 echo 'Two Person (maintainer:THIS THING)' 189 echo 'Third List (moderated list:THIS THING (FOO/bar))' 190 echo ' (moderated list:FOR THING)' 191 echo 'five@example.com (open list:FOR THING (FOO/bar))' 192 echo 'six@example.com (open list)' 193 EOF 194 " 195 196 test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' ' 197 clean_fake_sendmail && 198 git send-email -1 --to=recipient@example.com \ 199 --cc-cmd=./expected-cc-script.sh \ 200 --smtp-server="$(pwd)/fake.sendmail" && 201 test_cmp expected-cc commandline1 202 ' 203 204 test_expect_failure $PREREQ 'invalid smtp server port value' ' 205 clean_fake_sendmail && 206 git send-email -1 --to=recipient@example.com \ 207 --smtp-server-port=bogus-symbolic-name \ 208 --smtp-server="$(pwd)/fake.sendmail" 209 ' 210 211 test_expect_success $PREREQ 'setup expect' " 212 cat >expected-show-all-headers <<\EOF 213 0001-Second.patch 214 (mbox) Adding cc: A from line 'From: A ' 215 (mbox) Adding cc: One from line 'Cc: One , two@example.com' 216 (mbox) Adding cc: two@example.com from line 'Cc: One , two@example.com' 217 Dry-OK. Log says: 218 Server: relay.example.com 219 MAIL FROM: 220 RCPT TO: 221 RCPT TO: 222 RCPT TO: 223 RCPT TO: 224 RCPT TO: 225 RCPT TO: 226 From: Example 227 To: to@example.com 228 Cc: cc@example.com, 229 A , 230 One , 231 two@example.com 232 Subject: [PATCH 1/1] Second. 233 Date: DATE-STRING 234 Message-ID: MESSAGE-ID-STRING 235 X-Mailer: X-MAILER-STRING 236 In-Reply-To: 237 References: 238 Reply-To: Reply 239 MIME-Version: 1.0 240 Content-Transfer-Encoding: 8bit 241 242 Result: OK 243 EOF 244 " 245 246 test_suppress_self () { 247 test_commit $3 && 248 test_when_finished "git reset --hard HEAD^" && 249 250 write_script cccmd-sed <<-EOF && 251 sed -n -e s/^cccmd--//p "\$1" 252 EOF 253 254 git commit --amend --author="$1 <$2>" -F - && 255 clean_fake_sendmail && 256 git format-patch --stdout -1 >"suppress-self-$3.patch" && 257 258 git send-email --from="$1 <$2>" \ 259 --to=nobody@example.com \ 260 --cc-cmd=./cccmd-sed \ 261 --suppress-cc=self \ 262 --smtp-server="$(pwd)/fake.sendmail" \ 263 suppress-self-$3.patch && 264 265 mv msgtxt1 msgtxt1-$3 && 266 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" && 267 268 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3"; 269 test_must_be_empty actual-no-cc-$3) 270 } 271 272 test_suppress_self_unquoted () { 273 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF 274 test suppress-cc.self unquoted-$3 with name $1 email $2 275 276 unquoted-$3 277 278 cccmd--$1 <$2> 279 280 Cc: $1 <$2> 281 Signed-off-by: $1 <$2> 282 EOF 283 } 284 285 test_suppress_self_quoted () { 286 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF 287 test suppress-cc.self quoted-$3 with name $1 email $2 288 289 quoted-$3 290 291 cccmd--"$1" <$2> 292 293 Cc: $1 <$2> 294 Cc: "$1" <$2> 295 Signed-off-by: $1 <$2> 296 Signed-off-by: "$1" <$2> 297 EOF 298 } 299 300 test_expect_success $PREREQ 'self name is suppressed' " 301 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \ 302 'self_name_suppressed' 303 " 304 305 test_expect_success $PREREQ 'self name with dot is suppressed' " 306 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \ 307 'self_name_dot_suppressed' 308 " 309 310 test_expect_success $PREREQ 'non-ascii self name is suppressed' " 311 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \ 312 'non_ascii_self_suppressed' 313 " 314 315 # This name is long enough to force format-patch to split it into multiple 316 # encoded-words, assuming it uses UTF-8 with the "Q" encoding. 317 test_expect_success $PREREQ 'long non-ascii self name is suppressed' " 318 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \ 319 'long_non_ascii_self_suppressed' 320 " 321 322 test_expect_success $PREREQ 'sanitized self name is suppressed' " 323 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \ 324 'self_name_sanitized_suppressed' 325 " 326 327 test_expect_success $PREREQ 'Show all headers' ' 328 git send-email \ 329 --dry-run \ 330 --suppress-cc=sob \ 331 --from="Example " \ 332 --reply-to="Reply " \ 333 --to=to@example.com \ 334 --cc=cc@example.com \ 335 --bcc=bcc@example.com \ 336 --in-reply-to="" \ 337 --smtp-server relay.example.com \ 338 $patches | replace_variable_fields \ 339 >actual-show-all-headers && 340 test_cmp expected-show-all-headers actual-show-all-headers 341 ' 342 343 test_expect_success $PREREQ 'Prompting works' ' 344 clean_fake_sendmail && 345 (echo "to@example.com" && 346 echo "my-message-id@example.com" 347 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \ 348 --smtp-server="$(pwd)/fake.sendmail" \ 349 $patches \ 350 2>errors && 351 test_grep "^From: A U Thor \$" msgtxt1 && 352 test_grep "^To: to@example.com\$" msgtxt1 && 353 test_grep "^In-Reply-To: " msgtxt1 354 ' 355 356 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' ' 357 clean_fake_sendmail && 358 (sane_unset GIT_AUTHOR_NAME && 359 sane_unset GIT_AUTHOR_EMAIL && 360 sane_unset GIT_COMMITTER_NAME && 361 sane_unset GIT_COMMITTER_EMAIL && 362 GIT_SEND_EMAIL_NOTTY=1 git send-email \ 363 --smtp-server="$(pwd)/fake.sendmail" \ 364 --to=to@example.com \ 365 $patches errors 366 ) 367 ' 368 369 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' ' 370 clean_fake_sendmail && 371 (sane_unset GIT_AUTHOR_NAME && 372 sane_unset GIT_AUTHOR_EMAIL && 373 sane_unset GIT_COMMITTER_NAME && 374 sane_unset GIT_COMMITTER_EMAIL && 375 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY && 376 test_must_fail git send-email \ 377 --smtp-server="$(pwd)/fake.sendmail" \ 378 --to=to@example.com \ 379 $patches errors && 380 test_grep "tell me who you are" errors 381 ) 382 ' 383 384 test_expect_success $PREREQ 'setup cmd scripts' ' 385 write_script tocmd-sed <<-\EOF && 386 sed -n -e "s/^tocmd--//p" "$1" 387 EOF 388 write_script cccmd-sed <<-\EOF && 389 sed -n -e "s/^cccmd--//p" "$1" 390 EOF 391 write_script headercmd-sed <<-\EOF 392 sed -n -e "s/^headercmd--//p" "$1" 393 EOF 394 ' 395 396 test_expect_success $PREREQ 'tocmd works' ' 397 clean_fake_sendmail && 398 cp $patches tocmd.patch && 399 echo tocmd--tocmd@example.com >>tocmd.patch && 400 git send-email \ 401 --from="Example " \ 402 --to-cmd=./tocmd-sed \ 403 --smtp-server="$(pwd)/fake.sendmail" \ 404 tocmd.patch \ 405 && 406 test_grep "^To: tocmd@example.com" msgtxt1 407 ' 408 409 test_expect_success $PREREQ 'cccmd works' ' 410 clean_fake_sendmail && 411 cp $patches cccmd.patch && 412 echo "cccmd-- cccmd@example.com" >>cccmd.patch && 413 git send-email \ 414 --from="Example " \ 415 --to=nobody@example.com \ 416 --cc-cmd=./cccmd-sed \ 417 --smtp-server="$(pwd)/fake.sendmail" \ 418 cccmd.patch \ 419 && 420 test_grep "^ cccmd@example.com" msgtxt1 421 ' 422 423 test_expect_success $PREREQ 'headercmd works' ' 424 clean_fake_sendmail && 425 cp $patches headercmd.patch && 426 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch && 427 git send-email \ 428 --from="Example " \ 429 --to=nobody@example.com \ 430 --header-cmd=./headercmd-sed \ 431 --smtp-server="$(pwd)/fake.sendmail" \ 432 headercmd.patch \ 433 && 434 test_grep "^X-Debbugs-CC: dummy@example.com" msgtxt1 435 ' 436 437 test_expect_success $PREREQ '--no-header-cmd works' ' 438 clean_fake_sendmail && 439 cp $patches headercmd.patch && 440 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch && 441 git send-email \ 442 --from="Example " \ 443 --to=nobody@example.com \ 444 --header-cmd=./headercmd-sed \ 445 --no-header-cmd \ 446 --smtp-server="$(pwd)/fake.sendmail" \ 447 headercmd.patch \ 448 && 449 test_grep ! "^X-Debbugs-CC: dummy@example.com" msgtxt1 450 ' 451 452 test_expect_success $PREREQ 'multiline fields are correctly unfolded' ' 453 clean_fake_sendmail && 454 cp $patches headercmd.patch && 455 write_script headercmd-multiline <<-\EOF && 456 echo "X-Debbugs-CC: someone@example.com 457 FoldedField: This is a tale 458 best told using 459 multiple lines." 460 EOF 461 git send-email \ 462 --from="Example " \ 463 --to=nobody@example.com \ 464 --header-cmd=./headercmd-multiline \ 465 --smtp-server="$(pwd)/fake.sendmail" \ 466 headercmd.patch && 467 test_grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1 468 ' 469 470 # Blank lines in the middle of the output of a command are invalid. 471 test_expect_success $PREREQ 'malform output reported on blank lines in command output' ' 472 clean_fake_sendmail && 473 cp $patches headercmd.patch && 474 write_script headercmd-malformed-output <<-\EOF && 475 echo "X-Debbugs-CC: someone@example.com 476 477 SomeOtherField: someone-else@example.com" 478 EOF 479 ! git send-email \ 480 --from="Example " \ 481 --to=nobody@example.com \ 482 --header-cmd=./headercmd-malformed-output \ 483 --smtp-server="$(pwd)/fake.sendmail" \ 484 headercmd.patch 485 ' 486 487 test_expect_success $PREREQ 'reject long lines' ' 488 z8=zzzzzzzz && 489 z64=$z8$z8$z8$z8$z8$z8$z8$z8 && 490 z512=$z64$z64$z64$z64$z64$z64$z64$z64 && 491 clean_fake_sendmail && 492 cp $patches longline.patch && 493 cat >>longline.patch <<-EOF && 494 $z512$z512 495 not a long line 496 $z512$z512 497 EOF 498 test_must_fail git send-email \ 499 --from="Example " \ 500 --to=nobody@example.com \ 501 --smtp-server="$(pwd)/fake.sendmail" \ 502 --transfer-encoding=8bit \ 503 $patches longline.patch \ 504 2>actual && 505 cat >expect <<-\EOF && 506 fatal: longline.patch:35 is longer than 998 characters 507 warning: no patches were sent 508 EOF 509 test_cmp expect actual 510 ' 511 512 test_expect_success $PREREQ 'no patch was sent' ' 513 ! test -e commandline1 514 ' 515 516 test_expect_success $PREREQ 'Author From: in message body' ' 517 clean_fake_sendmail && 518 git send-email \ 519 --from="Example " \ 520 --to=nobody@example.com \ 521 --smtp-server="$(pwd)/fake.sendmail" \ 522 $patches && 523 sed "1,/^\$/d" msgbody1 && 524 test_grep "From: A " msgbody1 525 ' 526 527 test_expect_success $PREREQ 'Author From: not in message body' ' 528 clean_fake_sendmail && 529 git send-email \ 530 --from="A " \ 531 --to=nobody@example.com \ 532 --smtp-server="$(pwd)/fake.sendmail" \ 533 $patches && 534 sed "1,/^\$/d" msgbody1 && 535 test_grep ! "From: A " msgbody1 536 ' 537 538 test_expect_success $PREREQ 'allow long lines with --no-validate' ' 539 git send-email \ 540 --from="Example " \ 541 --to=nobody@example.com \ 542 --smtp-server="$(pwd)/fake.sendmail" \ 543 --no-validate \ 544 $patches longline.patch \ 545 2>errors 546 ' 547 548 test_expect_success $PREREQ 'short lines with auto encoding are 8bit' ' 549 clean_fake_sendmail && 550 git send-email \ 551 --from="A " \ 552 --to=nobody@example.com \ 553 --smtp-server="$(pwd)/fake.sendmail" \ 554 --transfer-encoding=auto \ 555 $patches && 556 test_grep "Content-Transfer-Encoding: 8bit" msgtxt1 557 ' 558 559 test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' ' 560 clean_fake_sendmail && 561 git send-email \ 562 --from="Example " \ 563 --to=nobody@example.com \ 564 --smtp-server="$(pwd)/fake.sendmail" \ 565 --transfer-encoding=auto \ 566 --no-validate \ 567 longline.patch && 568 test_grep "Content-Transfer-Encoding: quoted-printable" msgtxt1 569 ' 570 571 test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' ' 572 clean_fake_sendmail && 573 cp $patches cr.patch && 574 printf "this is a line\r\n" >>cr.patch && 575 git send-email \ 576 --from="Example " \ 577 --to=nobody@example.com \ 578 --smtp-server="$(pwd)/fake.sendmail" \ 579 --transfer-encoding=auto \ 580 --no-validate \ 581 cr.patch && 582 test_grep "Content-Transfer-Encoding: quoted-printable" msgtxt1 583 ' 584 585 for enc in auto quoted-printable base64 586 do 587 test_expect_success $PREREQ "--validate passes with encoding $enc" ' 588 git send-email \ 589 --from="Example " \ 590 --to=nobody@example.com \ 591 --smtp-server="$(pwd)/fake.sendmail" \ 592 --transfer-encoding=$enc \ 593 --validate \ 594 $patches longline.patch 595 ' 596 597 done 598 599 test_expect_success $PREREQ "--validate respects relative core.hooksPath path" ' 600 clean_fake_sendmail && 601 mkdir my-hooks && 602 test_when_finished "rm my-hooks.ran" && 603 write_script my-hooks/sendemail-validate <<-\EOF && 604 >my-hooks.ran 605 exit 1 606 EOF 607 test_config core.hooksPath "my-hooks" && 608 test_must_fail git send-email \ 609 --from="Example " \ 610 --to=nobody@example.com \ 611 --smtp-server="$(pwd)/fake.sendmail" \ 612 --validate \ 613 longline.patch 2>actual && 614 test_path_is_file my-hooks.ran && 615 cat >expect <<-EOF && 616 fatal: longline.patch: rejected by sendemail-validate hook 617 fatal: command '"'"'git hook run --ignore-missing sendemail-validate --
'"'"' died with exit code 1 618 warning: no patches were sent 619 EOF 620 test_cmp expect actual 621 ' 622 623 test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" ' 624 hooks_path="$(pwd)/my-hooks" && 625 test_config core.hooksPath "$hooks_path" && 626 test_when_finished "rm my-hooks.ran" && 627 test_must_fail git send-email \ 628 --from="Example " \ 629 --to=nobody@example.com \ 630 --smtp-server="$(pwd)/fake.sendmail" \ 631 --validate \ 632 longline.patch 2>actual && 633 test_path_is_file my-hooks.ran && 634 cat >expect <<-EOF && 635 fatal: longline.patch: rejected by sendemail-validate hook 636 fatal: command '"'"'git hook run --ignore-missing sendemail-validate --
'"'"' died with exit code 1 637 warning: no patches were sent 638 EOF 639 test_cmp expect actual 640 ' 641 642 test_expect_success $PREREQ "--validate hook supports multiple addresses in arguments" ' 643 hooks_path="$(pwd)/my-hooks" && 644 test_config core.hooksPath "$hooks_path" && 645 test_when_finished "rm my-hooks.ran" && 646 test_must_fail git send-email \ 647 --from="Example " \ 648 --to=nobody@example.com,abc@example.com \ 649 --smtp-server="$(pwd)/fake.sendmail" \ 650 --validate \ 651 longline.patch 2>actual && 652 test_path_is_file my-hooks.ran && 653 cat >expect <<-EOF && 654 fatal: longline.patch: rejected by sendemail-validate hook 655 fatal: command '"'"'git hook run --ignore-missing sendemail-validate --
'"'"' died with exit code 1 656 warning: no patches were sent 657 EOF 658 test_cmp expect actual 659 ' 660 661 test_expect_success $PREREQ "--validate hook supports header argument" ' 662 write_script my-hooks/sendemail-validate <<-\EOF && 663 if test "$#" -ge 2 664 then 665 grep "X-test-header: v1.0" "$2" 666 else 667 echo "No header arg passed" 668 exit 1 669 fi 670 EOF 671 test_config core.hooksPath "my-hooks" && 672 rm -fr outdir && 673 git format-patch \ 674 --add-header="X-test-header: v1.0" \ 675 -n HEAD^1 -o outdir && 676 git send-email \ 677 --dry-run \ 678 --to=nobody@example.com \ 679 --smtp-server="$(pwd)/fake.sendmail" \ 680 --validate \ 681 outdir/000?-*.patch 682 ' 683 684 test_expect_success $PREREQ 'clear message-id before parsing a new message' ' 685 clean_fake_sendmail && 686 echo true | write_script my-hooks/sendemail-validate && 687 test_config core.hooksPath my-hooks && 688 git send-email --validate --to=recipient@example.com \ 689 --smtp-server="$(pwd)/fake.sendmail" \ 690 $patches $threaded_patches && 691 id0=$(grep "^Message-ID: " $threaded_patches) && 692 id1=$(grep "^Message-ID: " msgtxt1) && 693 id2=$(grep "^Message-ID: " msgtxt2) && 694 test "z$id0" = "z$id2" && 695 test "z$id1" != "z$id2" 696 ' 697 698 for enc in 7bit 8bit quoted-printable base64 699 do 700 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" ' 701 clean_fake_sendmail && 702 git send-email \ 703 --from="Example " \ 704 --to=nobody@example.com \ 705 --smtp-server="$(pwd)/fake.sendmail" \ 706 --transfer-encoding=$enc \ 707 $patches && 708 test_grep "Content-Transfer-Encoding: $enc" msgtxt1 709 ' 710 done 711 712 test_expect_success $PREREQ 'Invalid In-Reply-To' ' 713 clean_fake_sendmail && 714 git send-email \ 715 --from="Example " \ 716 --to=nobody@example.com \ 717 --in-reply-to=" " \ 718 --smtp-server="$(pwd)/fake.sendmail" \ 719 $patches \ 720 2>errors && 721 test_grep ! "^In-Reply-To: < *>" msgtxt1 722 ' 723 724 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' ' 725 clean_fake_sendmail && 726 (echo "From Example " && 727 echo "To Example " && 728 echo "" 729 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \ 730 --smtp-server="$(pwd)/fake.sendmail" \ 731 $patches 2>errors && 732 test_grep ! "^In-Reply-To: < *>" msgtxt1 733 ' 734 735 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' ' 736 clean_fake_sendmail && 737 echo "" >expect && 738 git send-email \ 739 --from="Example " \ 740 --to=nobody@example.com \ 741 --no-chain-reply-to \ 742 --in-reply-to="$(cat expect)" \ 743 --smtp-server="$(pwd)/fake.sendmail" \ 744 $patches $patches $patches \ 745 2>errors && 746 # The first message is a reply to --in-reply-to 747 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && 748 test_cmp expect actual && 749 # Second and subsequent messages are replies to the first one 750 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect && 751 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual && 752 test_cmp expect actual && 753 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual && 754 test_cmp expect actual 755 ' 756 757 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' 758 clean_fake_sendmail && 759 echo "" >expect && 760 git send-email \ 761 --from="Example " \ 762 --to=nobody@example.com \ 763 --chain-reply-to \ 764 --in-reply-to="$(cat expect)" \ 765 --smtp-server="$(pwd)/fake.sendmail" \ 766 $patches $patches $patches \ 767 2>errors && 768 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && 769 test_cmp expect actual && 770 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect && 771 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual && 772 test_cmp expect actual && 773 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt2 >expect && 774 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual && 775 test_cmp expect actual 776 ' 777 778 test_set_editor "$(pwd)/fake-editor" 779 780 test_expect_success $PREREQ 'setup erroring fake editor' ' 781 write_script fake-editor <<-\EOF 782 echo >&2 "I am about to error" 783 exit 1 784 EOF 785 ' 786 787 test_expect_success $PREREQ 'fake editor dies with error' ' 788 clean_fake_sendmail && 789 test_must_fail git send-email \ 790 --compose --subject foo \ 791 --from="Example " \ 792 --to=nobody@example.com \ 793 --smtp-server="$(pwd)/fake.sendmail" \ 794 $patches 2>err && 795 test_grep "I am about to error" err && 796 test_grep "the editor exited uncleanly, aborting everything" err 797 ' 798 799 test_expect_success $PREREQ 'setup fake editor' ' 800 write_script fake-editor <<-\EOF 801 echo fake edit >>"$1" 802 EOF 803 ' 804 805 test_expect_success $PREREQ '--compose works' ' 806 clean_fake_sendmail && 807 git send-email \ 808 --compose --subject foo \ 809 --from="Example " \ 810 --to=nobody@example.com \ 811 --smtp-server="$(pwd)/fake.sendmail" \ 812 $patches \ 813 2>errors 814 ' 815 816 test_expect_success $PREREQ 'first message is compose text' ' 817 test_grep "^fake edit" msgtxt1 818 ' 819 820 test_expect_success $PREREQ 'second message is patch' ' 821 test_grep "Subject:.*Second" msgtxt2 822 ' 823 824 test_expect_success $PREREQ 'setup expect' " 825 cat >expected-suppress-sob <<\EOF 826 0001-Second.patch 827 (mbox) Adding cc: A from line 'From: A ' 828 (mbox) Adding cc: One from line 'Cc: One , two@example.com' 829 (mbox) Adding cc: two@example.com from line 'Cc: One , two@example.com' 830 Dry-OK. Log says: 831 Server: relay.example.com 832 MAIL FROM: 833 RCPT TO: 834 RCPT TO: 835 RCPT TO: 836 RCPT TO: 837 RCPT TO: 838 From: Example 839 To: to@example.com 840 Cc: cc@example.com, 841 A , 842 One , 843 two@example.com 844 Subject: [PATCH 1/1] Second. 845 Date: DATE-STRING 846 Message-ID: MESSAGE-ID-STRING 847 X-Mailer: X-MAILER-STRING 848 MIME-Version: 1.0 849 Content-Transfer-Encoding: 8bit 850 851 Result: OK 852 EOF 853 " 854 855 test_suppression () { 856 git send-email \ 857 --dry-run \ 858 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \ 859 --from="Example " \ 860 --to=to@example.com \ 861 --smtp-server relay.example.com \ 862 $patches | replace_variable_fields \ 863 >actual-suppress-$1${2+"-$2"} && 864 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"} 865 } 866 867 test_expect_success $PREREQ 'sendemail.cc set' ' 868 git config sendemail.cc cc@example.com && 869 test_suppression sob 870 ' 871 872 test_expect_success $PREREQ 'setup expect' " 873 cat >expected-suppress-sob <<\EOF 874 0001-Second.patch 875 (mbox) Adding cc: A from line 'From: A ' 876 (mbox) Adding cc: One from line 'Cc: One , two@example.com' 877 (mbox) Adding cc: two@example.com from line 'Cc: One , two@example.com' 878 Dry-OK. Log says: 879 Server: relay.example.com 880 MAIL FROM: 881 RCPT TO: 882 RCPT TO: 883 RCPT TO: 884 RCPT TO: 885 From: Example 886 To: to@example.com 887 Cc: A , 888 One , 889 two@example.com 890 Subject: [PATCH 1/1] Second. 891 Date: DATE-STRING 892 Message-ID: MESSAGE-ID-STRING 893 X-Mailer: X-MAILER-STRING 894 MIME-Version: 1.0 895 Content-Transfer-Encoding: 8bit 896 897 Result: OK 898 EOF 899 " 900 901 test_expect_success $PREREQ 'sendemail.cc unset' ' 902 git config --unset sendemail.cc && 903 test_suppression sob 904 ' 905 906 test_expect_success $PREREQ 'setup expect' " 907 cat >expected-suppress-cccmd <<\EOF 908 0001-Second.patch 909 (mbox) Adding cc: A from line 'From: A ' 910 (mbox) Adding cc: One from line 'Cc: One , two@example.com' 911 (mbox) Adding cc: two@example.com from line 'Cc: One , two@example.com' 912 (body) Adding cc: C O Mitter from line 'Signed-off-by: C O Mitter ' 913 Dry-OK. Log says: 914 Server: relay.example.com 915 MAIL FROM: 916 RCPT TO: 917 RCPT TO: 918 RCPT TO: 919 RCPT TO: 920 RCPT TO: 921 From: Example 922 To: to@example.com 923 Cc: A , 924 One , 925 two@example.com, 926 C O Mitter 927 Subject: [PATCH 1/1] Second. 928 Date: DATE-STRING 929 Message-ID: MESSAGE-ID-STRING 930 X-Mailer: X-MAILER-STRING 931 MIME-Version: 1.0 932 Content-Transfer-Encoding: 8bit 933 934 Result: OK 935 EOF 936 " 937 938 test_expect_success $PREREQ 'sendemail.cccmd' ' 939 write_script cccmd <<-\EOF && 940 echo cc-cmd@example.com 941 EOF 942 git config sendemail.cccmd ./cccmd && 943 test_suppression cccmd 944 ' 945 946 test_expect_success $PREREQ 'setup expect' ' 947 cat >expected-suppress-all <<\EOF 948 0001-Second.patch 949 Dry-OK. Log says: 950 Server: relay.example.com 951 MAIL FROM: 952 RCPT TO: 953 From: Example 954 To: to@example.com 955 Subject: [PATCH 1/1] Second. 956 Date: DATE-STRING 957 Message-ID: MESSAGE-ID-STRING 958 X-Mailer: X-MAILER-STRING 959 MIME-Version: 1.0 960 Content-Transfer-Encoding: 8bit 961 962 Result: OK 963 EOF 964 ' 965 966 test_expect_success $PREREQ '--suppress-cc=all' ' 967 test_suppression all 968 ' 969 970 test_expect_success $PREREQ 'setup expect' " 971 cat >expected-suppress-body <<\EOF 972 0001-Second.patch 973 (mbox) Adding cc: A from line 'From: A ' 974 (mbox) Adding cc: One from line 'Cc: One , two@example.com' 975 (mbox) Adding cc: two@example.com from line 'Cc: One , two@example.com' 976 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd' 977 Dry-OK. Log says: 978 Server: relay.example.com 979 MAIL FROM: 980 RCPT TO: 981 RCPT TO: 982 RCPT TO: 983 RCPT TO: 984 RCPT TO: 985 From: Example 986 To: to@example.com 987 Cc: A , 988 One , 989 two@example.com, 990 cc-cmd@example.com 991 Subject: [PATCH 1/1] Second. 992 Date: DATE-STRING 993 Message-ID: MESSAGE-ID-STRING 994 X-Mailer: X-MAILER-STRING 995 MIME-Version: 1.0 996 Content-Transfer-Encoding: 8bit 997 998 Result: OK 999 EOF 1000 " 1001 1002 test_expect_success $PREREQ '--suppress-cc=body' ' 1003 test_suppression body 1004 ' 1005 1006 test_expect_success $PREREQ 'setup expect' " 1007 cat >expected-suppress-body-cccmd <<\EOF 1008 0001-Second.patch 1009 (mbox) Adding cc: A from line 'From: A ' 1010 (mbox) Adding cc: One from line 'Cc: One , two@example.com' 1011 (mbox) Adding cc: two@example.com from line 'Cc: One , two@example.com' 1012 Dry-OK. Log says: 1013 Server: relay.example.com 1014 MAIL FROM: 1015 RCPT TO: 1016 RCPT TO: 1017 RCPT TO: 1018 RCPT TO: 1019 From: Example 1020 To: to@example.com 1021 Cc: A , 1022 One , 1023 two@example.com 1024 Subject: [PATCH 1/1] Second. 1025 Date: DATE-STRING 1026 Message-ID: MESSAGE-ID-STRING 1027 X-Mailer: X-MAILER-STRING 1028 MIME-Version: 1.0 1029 Content-Transfer-Encoding: 8bit 1030 1031 Result: OK 1032 EOF 1033 " 1034 1035 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' ' 1036 test_suppression body cccmd 1037 ' 1038 1039 test_expect_success $PREREQ 'setup expect' " 1040 cat >expected-suppress-sob <<\EOF 1041 0001-Second.patch 1042 (mbox) Adding cc: A from line 'From: A ' 1043 (mbox) Adding cc: One from line 'Cc: One , two@example.com' 1044 (mbox) Adding cc: two@example.com from line 'Cc: One , two@example.com' 1045 Dry-OK. Log says: 1046 Server: relay.example.com 1047 MAIL FROM: 1048 RCPT TO: 1049 RCPT TO: 1050 RCPT TO: 1051 RCPT TO: 1052 From: Example 1053 To: to@example.com 1054 Cc: A , 1055 One , 1056 two@example.com 1057 Subject: [PATCH 1/1] Second. 1058 Date: DATE-STRING 1059 Message-ID: MESSAGE-ID-STRING 1060 X-Mailer: X-MAILER-STRING 1061 MIME-Version: 1.0 1062 Content-Transfer-Encoding: 8bit 1063 1064 Result: OK 1065 EOF 1066 " 1067 1068 test_expect_success $PREREQ '--suppress-cc=sob' ' 1069 test_might_fail git config --unset sendemail.cccmd && 1070 test_suppression sob 1071 ' 1072 1073 test_expect_success $PREREQ 'setup expect' " 1074 cat >expected-suppress-bodycc <<\EOF 1075 0001-Second.patch 1076 (mbox) Adding cc: A from line 'From: A ' 1077 (mbox) Adding cc: One from line 'Cc: One , two@example.com' 1078 (mbox) Adding cc: two@example.com from line 'Cc: One , two@example.com' 1079 (body) Adding cc: C O Mitter from line 'Signed-off-by: C O Mitter ' 1080 Dry-OK. Log says: 1081 Server: relay.example.com 1082 MAIL FROM: 1083 RCPT TO: 1084 RCPT TO: 1085 RCPT TO: 1086 RCPT TO: 1087 RCPT TO: 1088 From: Example 1089 To: to@example.com 1090 Cc: A , 1091 One , 1092 two@example.com, 1093 C O Mitter 1094 Subject: [PATCH 1/1] Second. 1095 Date: DATE-STRING 1096 Message-ID: MESSAGE-ID-STRING 1097 X-Mailer: X-MAILER-STRING 1098 MIME-Version: 1.0 1099 Content-Transfer-Encoding: 8bit 1100 1101 Result: OK 1102 EOF 1103 " 1104 1105 test_expect_success $PREREQ '--suppress-cc=bodycc' ' 1106 test_suppression bodycc 1107 ' 1108 1109 test_expect_success $PREREQ 'setup expect' " 1110 cat >expected-suppress-cc <<\EOF 1111 0001-Second.patch 1112 (mbox) Adding cc: A from line 'From: A ' 1113 (body) Adding cc: C O Mitter from line 'Signed-off-by: C O Mitter ' 1114 Dry-OK. Log says: 1115 Server: relay.example.com 1116 MAIL FROM: 1117 RCPT TO: 1118 RCPT TO: 1119 RCPT TO: 1120 From: Example 1121 To: to@example.com 1122 Cc: A , 1123 C O Mitter 1124 Subject: [PATCH 1/1] Second. 1125 Date: DATE-STRING 1126 Message-ID: MESSAGE-ID-STRING 1127 X-Mailer: X-MAILER-STRING 1128 MIME-Version: 1.0 1129 Content-Transfer-Encoding: 8bit 1130 1131 Result: OK 1132 EOF 1133 " 1134 1135 test_expect_success $PREREQ '--suppress-cc=cc' ' 1136 test_suppression cc 1137 ' 1138 1139 test_confirm () { 1140 echo y | \ 1141 GIT_SEND_EMAIL_NOTTY=1 \ 1142 git send-email \ 1143 --from="Example " \ 1144 --to=nobody@example.com \ 1145 --smtp-server="$(pwd)/fake.sendmail" \ 1146 $@ $patches >stdout && 1147 grep "Send this email" stdout 1148 } 1149 1150 test_expect_success $PREREQ '--confirm=always' ' 1151 test_confirm --confirm=always --suppress-cc=all 1152 ' 1153 1154 test_expect_success $PREREQ '--confirm=auto' ' 1155 test_confirm --confirm=auto 1156 ' 1157 1158 test_expect_success $PREREQ '--confirm=cc' ' 1159 test_confirm --confirm=cc 1160 ' 1161 1162 test_expect_success $PREREQ '--confirm=compose' ' 1163 test_confirm --confirm=compose --compose 1164 ' 1165 1166 test_expect_success $PREREQ 'confirm by default (due to cc)' ' 1167 test_when_finished git config sendemail.confirm never && 1168 git config --unset sendemail.confirm && 1169 test_confirm 1170 ' 1171 1172 test_expect_success $PREREQ 'confirm by default (due to --compose)' ' 1173 test_when_finished git config sendemail.confirm never && 1174 git config --unset sendemail.confirm && 1175 test_confirm --suppress-cc=all --compose 1176 ' 1177 1178 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' ' 1179 test_when_finished git config sendemail.confirm never && 1180 git config --unset sendemail.confirm && 1181 rm -fr outdir && 1182 git format-patch -2 -o outdir && 1183 GIT_SEND_EMAIL_NOTTY=1 \ 1184 git send-email \ 1185 --from="Example " \ 1186 --to=nobody@example.com \ 1187 --smtp-server="$(pwd)/fake.sendmail" \ 1188 outdir/*.patch " 1226 ' 1227 1228 test_expect_success $PREREQ '--compose adds MIME for utf8 body' ' 1229 clean_fake_sendmail && 1230 write_script fake-editor-utf8 <<-\EOF && 1231 echo "utf8 body: àéìöú" >>"$1" 1232 EOF 1233 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ 1234 git send-email \ 1235 --compose --subject foo \ 1236 --from="Example " \ 1237 --to=nobody@example.com \ 1238 --smtp-server="$(pwd)/fake.sendmail" \ 1239 $patches && 1240 test_grep "^utf8 body" msgtxt1 && 1241 test_grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 1242 ' 1243 1244 test_expect_success $PREREQ '--compose respects user mime type' ' 1245 clean_fake_sendmail && 1246 write_script fake-editor-utf8-mime <<-\EOF && 1247 cat >"$1" <<-\EOM 1248 MIME-Version: 1.0 1249 Content-Type: text/plain; charset=iso-8859-1 1250 Content-Transfer-Encoding: 8bit 1251 Subject: foo 1252 1253 utf8 body: àéìöú 1254 EOM 1255 EOF 1256 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \ 1257 git send-email \ 1258 --compose --subject foo \ 1259 --from="Example " \ 1260 --to=nobody@example.com \ 1261 --smtp-server="$(pwd)/fake.sendmail" \ 1262 $patches && 1263 test_grep "^utf8 body" msgtxt1 && 1264 test_grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 && 1265 test_grep ! "^Content-Type: text/plain; charset=UTF-8" msgtxt1 1266 ' 1267 1268 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' ' 1269 clean_fake_sendmail && 1270 GIT_EDITOR="\"$(pwd)/fake-editor\"" \ 1271 git send-email \ 1272 --compose --subject utf8-sübjëct \ 1273 --from="Example " \ 1274 --to=nobody@example.com \ 1275 --smtp-server="$(pwd)/fake.sendmail" \ 1276 $patches && 1277 test_grep "^fake edit" msgtxt1 && 1278 test_grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1 1279 ' 1280 1281 test_expect_success $PREREQ 'utf8 author is correctly passed on' ' 1282 clean_fake_sendmail && 1283 test_commit weird_author && 1284 test_when_finished "git reset --hard HEAD^" && 1285 git commit --amend --author "Füñný Nâmé " && 1286 git format-patch --stdout -1 >funny_name.patch && 1287 git send-email --from="Example " \ 1288 --to=nobody@example.com \ 1289 --smtp-server="$(pwd)/fake.sendmail" \ 1290 funny_name.patch && 1291 test_grep "^From: Füñný Nâmé " msgtxt1 1292 ' 1293 1294 test_expect_success $PREREQ 'utf8 sender is not duplicated' ' 1295 clean_fake_sendmail && 1296 test_commit weird_sender && 1297 test_when_finished "git reset --hard HEAD^" && 1298 git commit --amend --author "Füñný Nâmé " && 1299 git format-patch --stdout -1 >funny_name.patch && 1300 git send-email --from="Füñný Nâmé " \ 1301 --to=nobody@example.com \ 1302 --smtp-server="$(pwd)/fake.sendmail" \ 1303 funny_name.patch && 1304 grep "^From: " msgtxt1 >msgfrom && 1305 test_line_count = 1 msgfrom 1306 ' 1307 1308 test_expect_success $PREREQ 'setup expect for cc list' " 1309 cat >expected-cc <<\EOF 1310 !recipient@example.com! 1311 !author@example.com! 1312 !one@example.com! 1313 !os@example.com! 1314 !odd_?=mail@example.com! 1315 !doug@example.com! 1316 !codev@example.com! 1317 !thor.au@example.com! 1318 EOF 1319 " 1320 1321 test_expect_success $PREREQ 'cc list is sanitized' ' 1322 clean_fake_sendmail && 1323 test_commit weird_cc_body && 1324 test_when_finished "git reset --hard HEAD^" && 1325 git commit --amend -F - <<-EOF && 1326 Test Cc: sanitization. 1327 1328 Cc: Person, One 1329 Cc: Ronnie O${SQ}Sullivan 1330 Reviewed-by: Füñný Nâmé 1331 Reported-by: bugger on Jira 1332 Reported-by: Douglas Reporter [from Jira profile] 1333 BugID: 12345should-not-appear 1334 Co-developed-by: "C. O. Developer" 1335 Signed-off-by: A. U. Thor 1336 EOF 1337 git send-email -1 --to=recipient@example.com \ 1338 --smtp-server="$(pwd)/fake.sendmail" >actual-show-all-headers && 1339 test_cmp expected-cc commandline1 && 1340 test_grep "^(body) Adding cc: \"Person, One\" " actual-show-all-headers && 1341 test_grep "^(body) Adding cc: Ronnie O${SQ}Sullivan " actual-show-all-headers && 1342 test_grep "^(body) Adding cc: =?UTF-8?q?F=C3=BC=C3=B1n=C3=BD=20N=C3=A2m=C3=A9?="\ 1343 " " actual-show-all-headers && 1344 test_grep "^(body) Ignoring Reported-by .* bugger on Jira" actual-show-all-headers && 1345 test_grep "^(body) Adding cc: Douglas Reporter " actual-show-all-headers && 1346 test_grep ! "12345should-not-appear" actual-show-all-headers && 1347 test_grep "^(body) Adding cc: \"C. O. Developer\" " actual-show-all-headers && 1348 test_grep "^(body) Adding cc: \"A. U. Thor\" " actual-show-all-headers 1349 ' 1350 1351 test_expect_success $PREREQ 'sendemail.composeencoding works' ' 1352 clean_fake_sendmail && 1353 git config sendemail.composeencoding iso-8859-1 && 1354 write_script fake-editor-utf8 <<-\EOF && 1355 echo "utf8 body: àéìöú" >>"$1" 1356 EOF 1357 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ 1358 git send-email \ 1359 --compose --subject foo \ 1360 --from="Example " \ 1361 --to=nobody@example.com \ 1362 --smtp-server="$(pwd)/fake.sendmail" \ 1363 $patches && 1364 test_grep "^utf8 body" msgtxt1 && 1365 test_grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 1366 ' 1367 1368 test_expect_success $PREREQ '--compose-encoding works' ' 1369 clean_fake_sendmail && 1370 write_script fake-editor-utf8 <<-\EOF && 1371 echo "utf8 body: àéìöú" >>"$1" 1372 EOF 1373 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ 1374 git send-email \ 1375 --compose-encoding iso-8859-1 \ 1376 --compose --subject foo \ 1377 --from="Example " \ 1378 --to=nobody@example.com \ 1379 --smtp-server="$(pwd)/fake.sendmail" \ 1380 $patches && 1381 test_grep "^utf8 body" msgtxt1 && 1382 test_grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 1383 ' 1384 1385 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' ' 1386 clean_fake_sendmail && 1387 git config sendemail.composeencoding iso-8859-1 && 1388 write_script fake-editor-utf8 <<-\EOF && 1389 echo "utf8 body: àéìöú" >>"$1" 1390 EOF 1391 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ 1392 git send-email \ 1393 --compose-encoding iso-8859-2 \ 1394 --compose --subject foo \ 1395 --from="Example " \ 1396 --to=nobody@example.com \ 1397 --smtp-server="$(pwd)/fake.sendmail" \ 1398 $patches && 1399 test_grep "^utf8 body" msgtxt1 && 1400 test_grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1 1401 ' 1402 1403 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' ' 1404 clean_fake_sendmail && 1405 GIT_EDITOR="\"$(pwd)/fake-editor\"" \ 1406 git send-email \ 1407 --compose-encoding iso-8859-2 \ 1408 --compose --subject utf8-sübjëct \ 1409 --from="Example " \ 1410 --to=nobody@example.com \ 1411 --smtp-server="$(pwd)/fake.sendmail" \ 1412 $patches && 1413 test_grep "^fake edit" msgtxt1 && 1414 test_grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1 1415 ' 1416 1417 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' ' 1418 echo main >main && 1419 git add main && 1420 git commit -m"add main" && 1421 test_must_fail git send-email --dry-run main 2>errors && 1422 test_grep disambiguate errors 1423 ' 1424 1425 test_expect_success $PREREQ 'missing subject omits Perl location' ' 1426 cat >no-subject.patch <<-\EOF && 1427 This is the body. 1428 EOF 1429 test_must_fail git send-email \ 1430 --dry-run \ 1431 --from="Example " \ 1432 --to=nobody@example.com \ 1433 no-subject.patch 2>actual && 1434 cat >expect <<-\EOF && 1435 No '\''Subject:'\'' line in '\''no-subject.patch'\'' 1436 EOF 1437 test_cmp expect actual 1438 ' 1439 1440 test_expect_success $PREREQ 'feed two files' ' 1441 rm -fr outdir && 1442 git format-patch -2 -o outdir && 1443 git send-email \ 1444 --dry-run \ 1445 --from="Example " \ 1446 --to=nobody@example.com \ 1447 outdir/000?-*.patch 2>errors >out && 1448 grep "^Subject: " out >subjects && 1449 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." && 1450 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main" 1451 ' 1452 1453 test_expect_success $PREREQ 'in-reply-to but no threading' ' 1454 git send-email \ 1455 --dry-run \ 1456 --from="Example " \ 1457 --to=nobody@example.com \ 1458 --in-reply-to="" \ 1459 --no-thread \ 1460 $patches >out && 1461 test_grep "In-Reply-To: " out 1462 ' 1463 1464 test_expect_success $PREREQ 'no in-reply-to and no threading' ' 1465 git send-email \ 1466 --dry-run \ 1467 --from="Example " \ 1468 --to=nobody@example.com \ 1469 --no-thread \ 1470 $patches >stdout && 1471 test_grep ! "In-Reply-To: " stdout 1472 ' 1473 1474 test_expect_success $PREREQ 'threading but no chain-reply-to' ' 1475 git send-email \ 1476 --dry-run \ 1477 --from="Example " \ 1478 --to=nobody@example.com \ 1479 --thread \ 1480 --no-chain-reply-to \ 1481 $patches $patches >stdout && 1482 test_grep "In-Reply-To: " stdout 1483 ' 1484 1485 test_expect_success $PREREQ 'override in-reply-to if no threading' ' 1486 git send-email \ 1487 --dry-run \ 1488 --from="Example " \ 1489 --to=nobody@example.com \ 1490 --no-thread \ 1491 --in-reply-to="override" \ 1492 $threaded_patches >stdout && 1493 test_grep "In-Reply-To: " stdout 1494 ' 1495 1496 test_expect_success $PREREQ 'sendemail.to works' ' 1497 git config --replace-all sendemail.to "Somebody " && 1498 git send-email \ 1499 --dry-run \ 1500 --from="Example " \ 1501 $patches >stdout && 1502 test_grep "To: Somebody " stdout 1503 ' 1504 1505 test_expect_success $PREREQ 'setup sendemail.identity' ' 1506 git config --replace-all sendemail.to "default@example.com" && 1507 git config --replace-all sendemail.isp.to "isp@example.com" && 1508 git config --replace-all sendemail.cloud.to "cloud@example.com" 1509 ' 1510 1511 test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' ' 1512 git -c sendemail.identity=cloud send-email \ 1513 --dry-run \ 1514 --from="nobody@example.com" \ 1515 $patches >stdout && 1516 test_grep "To: cloud@example.com" stdout 1517 ' 1518 1519 test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' ' 1520 git -c sendemail.identity=cloud send-email \ 1521 --identity=isp \ 1522 --dry-run \ 1523 --from="nobody@example.com" \ 1524 $patches >stdout && 1525 test_grep "To: isp@example.com" stdout 1526 ' 1527 1528 test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' ' 1529 git -c sendemail.identity=cloud send-email \ 1530 --no-identity \ 1531 --dry-run \ 1532 --from="nobody@example.com" \ 1533 $patches >stdout && 1534 test_grep "To: default@example.com" stdout 1535 ' 1536 1537 test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' ' 1538 git -c sendemail.identity=cloud \ 1539 -c sendemail.xmailer=true \ 1540 -c sendemail.cloud.xmailer=false \ 1541 send-email \ 1542 --dry-run \ 1543 --from="nobody@example.com" \ 1544 $patches >stdout && 1545 test_grep "To: cloud@example.com" stdout && 1546 test_grep ! "X-Mailer" stdout 1547 ' 1548 1549 test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' ' 1550 git -c sendemail.identity=cloud \ 1551 -c sendemail.xmailer=false \ 1552 send-email \ 1553 --dry-run \ 1554 --from="nobody@example.com" \ 1555 $patches >stdout && 1556 test_grep "To: cloud@example.com" stdout && 1557 test_grep ! "X-Mailer" stdout 1558 ' 1559 1560 test_expect_success $PREREQ 'sendemail.identity: bool variable without a value' ' 1561 git -c sendemail.xmailer \ 1562 send-email \ 1563 --dry-run \ 1564 --from="nobody@example.com" \ 1565 $patches >stdout && 1566 test_grep "To: default@example.com" stdout && 1567 test_grep "X-Mailer" stdout 1568 ' 1569 1570 test_expect_success $PREREQ '--no-to overrides sendemail.to' ' 1571 git send-email \ 1572 --dry-run \ 1573 --from="Example " \ 1574 --no-to \ 1575 --to=nobody@example.com \ 1576 $patches >stdout && 1577 test_grep "To: nobody@example.com" stdout && 1578 test_grep ! "To: Somebody " stdout 1579 ' 1580 1581 test_expect_success $PREREQ 'sendemail.cc works' ' 1582 git config --replace-all sendemail.cc "Somebody " && 1583 git send-email \ 1584 --dry-run \ 1585 --from="Example " \ 1586 --to=nobody@example.com \ 1587 $patches >stdout && 1588 test_grep "Cc: Somebody " stdout 1589 ' 1590 1591 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' ' 1592 git send-email \ 1593 --dry-run \ 1594 --from="Example " \ 1595 --no-cc \ 1596 --cc=bodies@example.com \ 1597 --to=nobody@example.com \ 1598 $patches >stdout && 1599 test_grep "Cc: bodies@example.com" stdout && 1600 test_grep ! "Cc: Somebody " stdout 1601 ' 1602 1603 test_expect_success $PREREQ 'sendemail.bcc works' ' 1604 git config --replace-all sendemail.bcc "Other " && 1605 git send-email \ 1606 --dry-run \ 1607 --from="Example " \ 1608 --to=nobody@example.com \ 1609 --smtp-server relay.example.com \ 1610 $patches >stdout && 1611 test_grep "RCPT TO:" stdout 1612 ' 1613 1614 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' ' 1615 git send-email \ 1616 --dry-run \ 1617 --from="Example " \ 1618 --no-bcc \ 1619 --bcc=bodies@example.com \ 1620 --to=nobody@example.com \ 1621 --smtp-server relay.example.com \ 1622 $patches >stdout && 1623 test_grep "RCPT TO:" stdout && 1624 test_grep ! "RCPT TO:" stdout 1625 ' 1626 1627 test_expect_success $PREREQ 'patches To headers are used by default' ' 1628 patch=$(git format-patch -1 --to="bodies@example.com") && 1629 test_when_finished "rm $patch" && 1630 git send-email \ 1631 --dry-run \ 1632 --from="Example " \ 1633 --smtp-server relay.example.com \ 1634 $patch >stdout && 1635 test_grep "RCPT TO:" stdout 1636 ' 1637 1638 test_expect_success $PREREQ 'patches To headers are appended to' ' 1639 patch=$(git format-patch -1 --to="bodies@example.com") && 1640 test_when_finished "rm $patch" && 1641 git send-email \ 1642 --dry-run \ 1643 --from="Example " \ 1644 --to=nobody@example.com \ 1645 --smtp-server relay.example.com \ 1646 $patch >stdout && 1647 test_grep "RCPT TO:" stdout && 1648 test_grep "RCPT TO:" stdout 1649 ' 1650 1651 test_expect_success $PREREQ 'To headers from files reset each patch' ' 1652 patch1=$(git format-patch -1 --to="bodies@example.com") && 1653 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) && 1654 test_when_finished "rm $patch1 && rm $patch2" && 1655 git send-email \ 1656 --dry-run \ 1657 --from="Example " \ 1658 --to="nobody@example.com" \ 1659 --smtp-server relay.example.com \ 1660 $patch1 $patch2 >stdout && 1661 test $(grep -c "RCPT TO:" stdout) = 1 && 1662 test $(grep -c "RCPT TO:" stdout) = 2 && 1663 test $(grep -c "RCPT TO:" stdout) = 1 1664 ' 1665 1666 test_expect_success $PREREQ 'setup expect' ' 1667 # NOTE: do not quote this heredoc, Dash 0.5.13 has a bug with heredocs 1668 # that contain multibyte chars. 1669 cat >email-using-8bit < 1672 From: author@example.com 1673 Date: Sat, 12 Jun 2010 15:53:58 +0200 1674 Subject: subject goes here 1675 1676 Dieser deutsche Text enthält einen Umlaut! 1677 EOF 1678 ' 1679 1680 test_expect_success $PREREQ 'setup expect' ' 1681 echo "Subject: subject goes here" >expected 1682 ' 1683 1684 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' ' 1685 clean_fake_sendmail && 1686 echo bogus | 1687 git send-email --from=author@example.com --to=nobody@example.com \ 1688 --smtp-server="$(pwd)/fake.sendmail" \ 1689 --8bit-encoding=UTF-8 \ 1690 email-using-8bit >stdout && 1691 grep "Subject" msgtxt1 >actual && 1692 test_cmp expected actual 1693 ' 1694 1695 test_expect_success $PREREQ 'setup expect' ' 1696 cat >content-type-decl <<-\EOF 1697 MIME-Version: 1.0 1698 Content-Type: text/plain; charset=UTF-8 1699 Content-Transfer-Encoding: 8bit 1700 EOF 1701 ' 1702 1703 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' ' 1704 clean_fake_sendmail && 1705 echo | 1706 git send-email --from=author@example.com --to=nobody@example.com \ 1707 --smtp-server="$(pwd)/fake.sendmail" \ 1708 email-using-8bit >stdout && 1709 test_grep "do not declare a Content-Transfer-Encoding" stdout && 1710 test_grep email-using-8bit stdout && 1711 test_grep "Declare which 8bit encoding to use" stdout && 1712 grep -E "Content|MIME" msgtxt1 >actual && 1713 test_cmp content-type-decl actual 1714 ' 1715 1716 test_expect_success $PREREQ 'sendemail.8bitEncoding works' ' 1717 clean_fake_sendmail && 1718 git config sendemail.assume8bitEncoding UTF-8 && 1719 echo bogus | 1720 git send-email --from=author@example.com --to=nobody@example.com \ 1721 --smtp-server="$(pwd)/fake.sendmail" \ 1722 email-using-8bit >stdout && 1723 grep -E "Content|MIME" msgtxt1 >actual && 1724 test_cmp content-type-decl actual 1725 ' 1726 1727 test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' ' 1728 clean_fake_sendmail && 1729 git config sendemail.assume8bitEncoding UTF-8 && 1730 test_when_finished "rm -rf home" && 1731 mkdir home && 1732 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" && 1733 echo bogus | 1734 env HOME="$(pwd)/home" DEBUG=1 \ 1735 git send-email --from=author@example.com --to=nobody@example.com \ 1736 --smtp-server="$(pwd)/fake.sendmail" \ 1737 email-using-8bit >stdout && 1738 grep -E "Content|MIME" msgtxt1 >actual && 1739 test_cmp content-type-decl actual 1740 ' 1741 1742 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' ' 1743 clean_fake_sendmail && 1744 git config sendemail.assume8bitEncoding "bogus too" && 1745 echo bogus | 1746 git send-email --from=author@example.com --to=nobody@example.com \ 1747 --smtp-server="$(pwd)/fake.sendmail" \ 1748 --8bit-encoding=UTF-8 \ 1749 email-using-8bit >stdout && 1750 grep -E "Content|MIME" msgtxt1 >actual && 1751 test_cmp content-type-decl actual 1752 ' 1753 1754 test_expect_success $PREREQ 'setup expect' ' 1755 # NOTE: do not quote this heredoc, Dash 0.5.13 has a bug with heredocs 1756 # that contain multibyte chars. 1757 cat >email-using-8bit <<-EOF 1758 From `fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4` Mon Sep 17 00:00:00 2001 1759 Message-ID: 1760 From: author@example.com 1761 Date: Sat, 12 Jun 2010 15:53:58 +0200 1762 Subject: Dieser Betreff enthält auch einen Umlaut! 1763 1764 Nothing to see here. 1765 EOF 1766 ' 1767 1768 test_expect_success $PREREQ 'setup expect' ' 1769 cat >expected <<-\EOF 1770 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?= 1771 EOF 1772 ' 1773 1774 test_expect_success $PREREQ '--8bit-encoding also treats subject' ' 1775 clean_fake_sendmail && 1776 echo bogus | 1777 git send-email --from=author@example.com --to=nobody@example.com \ 1778 --smtp-server="$(pwd)/fake.sendmail" \ 1779 --8bit-encoding=UTF-8 \ 1780 email-using-8bit >stdout && 1781 grep "Subject" msgtxt1 >actual && 1782 test_cmp expected actual 1783 ' 1784 1785 test_expect_success $PREREQ 'setup expect' ' 1786 # NOTE: do not quote this heredoc, Dash 0.5.13 has a bug with heredocs 1787 # that contain multibyte chars. 1788 cat >email-using-8bit <<-EOF 1789 From `fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4` Mon Sep 17 00:00:00 2001 1790 Message-ID: 1791 From: A U Thor 1792 Date: Sat, 12 Jun 2010 15:53:58 +0200 1793 Content-Type: text/plain; charset=UTF-8 1794 Subject: Nothing to see here. 1795 1796 Dieser Betreff enthält auch einen Umlaut! 1797 EOF 1798 ' 1799 1800 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' ' 1801 clean_fake_sendmail && 1802 test_must_fail git -c sendemail.transferEncoding=8bit \ 1803 send-email \ 1804 --transfer-encoding=7bit \ 1805 --smtp-server="$(pwd)/fake.sendmail" \ 1806 email-using-8bit \ 1807 2>errors >out && 1808 test_grep "cannot send message as 7bit" errors && 1809 test -z "$(ls msgtxt*)" 1810 ' 1811 1812 test_expect_success $PREREQ 'sendemail.transferEncoding via config' ' 1813 clean_fake_sendmail && 1814 test_must_fail git -c sendemail.transferEncoding=7bit \ 1815 send-email \ 1816 --smtp-server="$(pwd)/fake.sendmail" \ 1817 email-using-8bit \ 1818 2>errors >out && 1819 test_grep "cannot send message as 7bit" errors && 1820 test -z "$(ls msgtxt*)" 1821 ' 1822 1823 test_expect_success $PREREQ 'sendemail.transferEncoding via cli' ' 1824 clean_fake_sendmail && 1825 test_must_fail git send-email \ 1826 --transfer-encoding=7bit \ 1827 --smtp-server="$(pwd)/fake.sendmail" \ 1828 email-using-8bit \ 1829 2>errors >out && 1830 test_grep "cannot send message as 7bit" errors && 1831 test -z "$(ls msgtxt*)" 1832 ' 1833 1834 test_expect_success $PREREQ 'setup expect' ' 1835 cat >expected <<-\EOF 1836 Dieser Betreff enth=C3=A4lt auch einen Umlaut! 1837 EOF 1838 ' 1839 1840 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' ' 1841 clean_fake_sendmail && 1842 git send-email \ 1843 --transfer-encoding=quoted-printable \ 1844 --smtp-server="$(pwd)/fake.sendmail" \ 1845 email-using-8bit \ 1846 2>errors >out && 1847 sed "1,/^$/d" msgtxt1 >actual && 1848 test_cmp expected actual 1849 ' 1850 1851 test_expect_success $PREREQ 'setup expect' ' 1852 cat >expected <<-\EOF 1853 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg== 1854 EOF 1855 ' 1856 1857 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' ' 1858 clean_fake_sendmail && 1859 git send-email \ 1860 --transfer-encoding=base64 \ 1861 --smtp-server="$(pwd)/fake.sendmail" \ 1862 email-using-8bit \ 1863 2>errors >out && 1864 sed "1,/^$/d" msgtxt1 >actual && 1865 test_cmp expected actual 1866 ' 1867 1868 test_expect_success $PREREQ 'setup expect' ' 1869 cat >email-using-qp <<-\EOF 1870 From `fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4` Mon Sep 17 00:00:00 2001 1871 Message-ID: 1872 From: A U Thor 1873 Date: Sat, 12 Jun 2010 15:53:58 +0200 1874 MIME-Version: 1.0 1875 Content-Transfer-Encoding: quoted-printable 1876 Content-Type: text/plain; charset=UTF-8 1877 Subject: Nothing to see here. 1878 1879 Dieser Betreff enth=C3=A4lt auch einen Umlaut! 1880 EOF 1881 ' 1882 1883 test_expect_success $PREREQ 'convert from quoted-printable to base64' ' 1884 clean_fake_sendmail && 1885 git send-email \ 1886 --transfer-encoding=base64 \ 1887 --smtp-server="$(pwd)/fake.sendmail" \ 1888 email-using-qp \ 1889 2>errors >out && 1890 sed "1,/^$/d" msgtxt1 >actual && 1891 test_cmp expected actual 1892 ' 1893 1894 test_expect_success $PREREQ 'setup expect' " 1895 tr -d '\\015' | tr '%' '\\015' >email-using-crlf < 1898 From: A U Thor 1899 Date: Sat, 12 Jun 2010 15:53:58 +0200 1900 Content-Type: text/plain; charset=UTF-8 1901 Subject: Nothing to see here. 1902 1903 Look, I have a CRLF and an = sign!% 1904 EOF 1905 " 1906 1907 test_expect_success $PREREQ 'setup expect' ' 1908 cat >expected <<-\EOF 1909 Look, I have a CRLF and an =3D sign!=0D 1910 EOF 1911 ' 1912 1913 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' ' 1914 clean_fake_sendmail && 1915 git send-email \ 1916 --transfer-encoding=quoted-printable \ 1917 --smtp-server="$(pwd)/fake.sendmail" \ 1918 email-using-crlf \ 1919 2>errors >out && 1920 sed "1,/^$/d" msgtxt1 >actual && 1921 test_cmp expected actual 1922 ' 1923 1924 test_expect_success $PREREQ 'setup expect' ' 1925 cat >expected <<-\EOF 1926 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K 1927 EOF 1928 ' 1929 1930 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' ' 1931 clean_fake_sendmail && 1932 git send-email \ 1933 --transfer-encoding=base64 \ 1934 --smtp-server="$(pwd)/fake.sendmail" \ 1935 email-using-crlf \ 1936 2>errors >out && 1937 sed "1,/^$/d" msgtxt1 >actual && 1938 test_cmp expected actual 1939 ' 1940 1941 1942 # Note that the patches in this test are deliberately out of order; we 1943 # want to make sure it works even if the cover-letter is not in the 1944 # first mail. 1945 test_expect_success $PREREQ 'refusing to send cover letter template' ' 1946 clean_fake_sendmail && 1947 rm -fr outdir && 1948 git format-patch --cover-letter -2 -o outdir && 1949 test_must_fail git send-email \ 1950 --from="Example " \ 1951 --to=nobody@example.com \ 1952 --smtp-server="$(pwd)/fake.sendmail" \ 1953 outdir/0002-*.patch \ 1954 outdir/0000-*.patch \ 1955 outdir/0001-*.patch \ 1956 2>errors >out && 1957 test_grep "SUBJECT HERE" errors && 1958 test -z "$(ls msgtxt*)" 1959 ' 1960 1961 test_expect_success $PREREQ '--force sends cover letter template anyway' ' 1962 clean_fake_sendmail && 1963 rm -fr outdir && 1964 git format-patch --cover-letter -2 -o outdir && 1965 git send-email \ 1966 --force \ 1967 --from="Example " \ 1968 --to=nobody@example.com \ 1969 --smtp-server="$(pwd)/fake.sendmail" \ 1970 outdir/0002-*.patch \ 1971 outdir/0000-*.patch \ 1972 outdir/0001-*.patch \ 1973 2>errors >out && 1974 test_grep ! "SUBJECT HERE" errors && 1975 test -n "$(ls msgtxt*)" 1976 ' 1977 1978 test_cover_addresses () { 1979 header="$1" 1980 shift 1981 clean_fake_sendmail && 1982 rm -fr outdir && 1983 git format-patch --cover-letter -2 -o outdir && 1984 cover=$(echo outdir/0000-*.patch) && 1985 mv $cover cover-to-edit.patch && 1986 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" && 1987 git send-email \ 1988 --force \ 1989 --from="Example " \ 1990 --no-to --no-cc \ 1991 "$@" \ 1992 --smtp-server="$(pwd)/fake.sendmail" \ 1993 outdir/0000-*.patch \ 1994 outdir/0001-*.patch \ 1995 outdir/0002-*.patch \ 1996 2>errors >out && 1997 grep "^$header: extra@address.com" msgtxt1 >to1 && 1998 grep "^$header: extra@address.com" msgtxt2 >to2 && 1999 grep "^$header: extra@address.com" msgtxt3 >to3 && 2000 test_line_count = 1 to1 && 2001 test_line_count = 1 to2 && 2002 test_line_count = 1 to3 2003 } 2004 2005 test_expect_success $PREREQ 'to-cover adds To to all mail' ' 2006 test_cover_addresses "To" --to-cover 2007 ' 2008 2009 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' ' 2010 test_cover_addresses "Cc" --cc-cover 2011 ' 2012 2013 test_expect_success $PREREQ 'tocover adds To to all mail' ' 2014 test_config sendemail.tocover true && 2015 test_cover_addresses "To" 2016 ' 2017 2018 test_expect_success $PREREQ 'cccover adds Cc to all mail' ' 2019 test_config sendemail.cccover true && 2020 test_cover_addresses "Cc" 2021 ' 2022 2023 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' ' 2024 clean_fake_sendmail && 2025 echo "alias sbd \\\"Dot U. Sir\\\" " >.mutt && 2026 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" && 2027 git config sendemail.aliasfiletype mutt && 2028 git send-email \ 2029 --from="Example " \ 2030 --to=sbd \ 2031 --smtp-server="$(pwd)/fake.sendmail" \ 2032 outdir/0001-*.patch \ 2033 2>errors >out && 2034 test_grep "^!somebody@example\.org!$" commandline1 && 2035 test_grep -F "To: \"Dot U. Sir\" " out 2036 ' 2037 2038 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' ' 2039 clean_fake_sendmail && 2040 echo "alias sbd somebody@example.org" >.mailrc && 2041 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" && 2042 git config sendemail.aliasfiletype mailrc && 2043 git send-email \ 2044 --from="Example " \ 2045 --to=sbd \ 2046 --smtp-server="$(pwd)/fake.sendmail" \ 2047 outdir/0001-*.patch \ 2048 2>errors >out && 2049 test_grep "^!somebody@example\.org!$" commandline1 2050 ' 2051 2052 test_expect_success $PREREQ 'sendemail.aliasesfile=~/.mailrc' ' 2053 clean_fake_sendmail && 2054 echo "alias sbd someone@example.org" >"$HOME/.mailrc" && 2055 git config --replace-all sendemail.aliasesfile "~/.mailrc" && 2056 git config sendemail.aliasfiletype mailrc && 2057 git send-email \ 2058 --from="Example " \ 2059 --to=sbd \ 2060 --smtp-server="$(pwd)/fake.sendmail" \ 2061 outdir/0001-*.patch \ 2062 2>errors >out && 2063 test_grep "^!someone@example\.org!$" commandline1 2064 ' 2065 2066 test_dump_aliases () { 2067 msg="$1" && shift && 2068 filetype="$1" && shift && 2069 printf '%s\n' "$@" >expect && 2070 cat >.tmp-email-aliases && 2071 2072 test_expect_success $PREREQ "$msg" ' 2073 clean_fake_sendmail && rm -fr outdir && 2074 git config --replace-all sendemail.aliasesfile \ 2075 "$(pwd)/.tmp-email-aliases" && 2076 git config sendemail.aliasfiletype "$filetype" && 2077 git send-email --dump-aliases 2>errors >actual && 2078 test_cmp expect actual 2079 ' 2080 } 2081 2082 test_dump_aliases '--dump-aliases sendmail format' \ 2083 'sendmail' \ 2084 'abgroup' \ 2085 'alice' \ 2086 'bcgrp' \ 2087 'bob' \ 2088 'chloe' <<-\EOF 2089 alice: Alice W Land 2090 bob: Robert Bobbyton 2091 chloe: chloe@example.com 2092 abgroup: alice, bob 2093 bcgrp: bob, chloe, Other 2094 EOF 2095 2096 test_dump_aliases '--dump-aliases mutt format' \ 2097 'mutt' \ 2098 'alice' \ 2099 'bob' \ 2100 'chloe' \ 2101 'donald' <<-\EOF 2102 alias alice Alice W Land 2103 alias donald Donald C Carlton 2104 alias bob Robert Bobbyton 2105 alias chloe chloe@example.com 2106 EOF 2107 2108 test_dump_aliases '--dump-aliases mailrc format' \ 2109 'mailrc' \ 2110 'alice' \ 2111 'bob' \ 2112 'chloe' \ 2113 'eve' <<-\EOF 2114 alias alice "Alice W Land " 2115 alias eve "Eve " 2116 alias bob "Robert Bobbyton " 2117 alias chloe chloe@example.com 2118 EOF 2119 2120 test_dump_aliases '--dump-aliases pine format' \ 2121 'pine' \ 2122 'alice' \ 2123 'bcgrp' \ 2124 'bob' \ 2125 'chloe' \ 2126 'eve' <<-\EOF 2127 alice Alice W Land awol@example.com Friend 2128 eve Eve eve@example.com 2129 bob Robert Bobbyton bob@example.com 2130 chloe chloe@example.com 2131 bcgrp (bob, chloe, Other ) 2132 EOF 2133 2134 test_dump_aliases '--dump-aliases gnus format' \ 2135 'gnus' \ 2136 'alice' \ 2137 'bob' \ 2138 'chloe' \ 2139 'eve' <<-\EOF 2140 (define-mail-alias "alice" "awol@example.com") 2141 (define-mail-alias "eve" "eve@example.com") 2142 (define-mail-alias "bob" "bob@example.com") 2143 (define-mail-alias "chloe" "chloe@example.com") 2144 EOF 2145 2146 test_expect_success '--dump-aliases must be used alone' ' 2147 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting 2148 ' 2149 2150 test_translate_aliases () { 2151 msg="$1" && shift && 2152 filetype="$1" && shift && 2153 aliases="$1" && shift && 2154 printf '%s\n' "$@" >expect && 2155 cat >.tmp-email-aliases && 2156 printf '%s\n' "$aliases" >aliases && 2157 2158 test_expect_success $PREREQ "$msg" ' 2159 clean_fake_sendmail && rm -fr outdir && 2160 git config --replace-all sendemail.aliasesfile \ 2161 "$(pwd)/.tmp-email-aliases" && 2162 git config sendemail.aliasfiletype "$filetype" && 2163 git send-email --translate-aliases errors >actual && 2164 test_cmp expect actual 2165 ' 2166 } 2167 2168 test_translate_aliases '--translate-aliases sendmail format' \ 2169 'sendmail' \ 2170 'alice bcgrp' \ 2171 'Alice W Land ' \ 2172 'Robert Bobbyton ' \ 2173 'chloe@example.com' \ 2174 'Other ' <<-\EOF 2175 alice: Alice W Land 2176 bob: Robert Bobbyton 2177 chloe: chloe@example.com 2178 abgroup: alice, bob 2179 bcgrp: bob, chloe, Other 2180 EOF 2181 2182 test_translate_aliases '--translate-aliases mutt format' \ 2183 'mutt' \ 2184 'donald bob' \ 2185 'Donald C Carlton ' \ 2186 'Robert Bobbyton ' <<-\EOF 2187 alias alice Alice W Land 2188 alias donald Donald C Carlton 2189 alias bob Robert Bobbyton 2190 alias chloe chloe@example.com 2191 EOF 2192 2193 test_translate_aliases '--translate-aliases mailrc format' \ 2194 'mailrc' \ 2195 'chloe eve alice' \ 2196 'chloe@example.com' \ 2197 'Eve ' \ 2198 'Alice W Land ' <<-\EOF 2199 alias alice "Alice W Land " 2200 alias eve "Eve " 2201 alias bob "Robert Bobbyton " 2202 alias chloe chloe@example.com 2203 EOF 2204 2205 test_translate_aliases '--translate-aliases pine format' \ 2206 'pine' \ 2207 'eve bob bcgrp' \ 2208 'eve@example.com' \ 2209 'bob@example.com' \ 2210 'bob@example.com' \ 2211 'chloe@example.com' \ 2212 'Other ' <<-\EOF 2213 alice Alice W Land awol@example.com Friend 2214 eve Eve eve@example.com 2215 bob Robert Bobbyton bob@example.com 2216 chloe chloe@example.com 2217 bcgrp (bob, chloe, Other ) 2218 EOF 2219 2220 test_translate_aliases '--translate-aliases gnus format' \ 2221 'gnus' \ 2222 'alice chloe eve' \ 2223 'awol@example.com' \ 2224 'chloe@example.com' \ 2225 'eve@example.com' <<-\EOF 2226 (define-mail-alias "alice" "awol@example.com") 2227 (define-mail-alias "eve" "eve@example.com") 2228 (define-mail-alias "bob" "bob@example.com") 2229 (define-mail-alias "chloe" "chloe@example.com") 2230 EOF 2231 2232 test_expect_success $PREREQ '--translate-aliases passes valid addresses through' ' 2233 cat >expect <<-\EOF && 2234 Other 2235 EOF 2236 cat >aliases <<-\EOF && 2237 Other 2238 EOF 2239 git send-email --translate-aliases actual && 2240 test_cmp expect actual 2241 ' 2242 2243 test_expect_success $PREREQ '--translate-aliases passes unknown aliases through' ' 2244 cat >expect <<-\EOF && 2245 blargh 2246 EOF 2247 cat >aliases <<-\EOF && 2248 blargh 2249 EOF 2250 git send-email --translate-aliases actual && 2251 test_cmp expect actual 2252 ' 2253 2254 test_expect_success $PREREQ 'aliases and sendemail.identity' ' 2255 test_must_fail git \ 2256 -c sendemail.identity=cloud \ 2257 -c sendemail.aliasesfile=default-aliases \ 2258 -c sendemail.cloud.aliasesfile=cloud-aliases \ 2259 send-email -1 2>stderr && 2260 test_grep "cloud-aliases" stderr 2261 ' 2262 2263 test_sendmail_aliases () { 2264 msg="$1" && shift && 2265 expect="$@" && 2266 cat >.tmp-email-aliases && 2267 2268 test_expect_success $PREREQ "$msg" ' 2269 clean_fake_sendmail && rm -fr outdir && 2270 git format-patch -1 -o outdir && 2271 git config --replace-all sendemail.aliasesfile \ 2272 "$(pwd)/.tmp-email-aliases" && 2273 git config sendemail.aliasfiletype sendmail && 2274 git send-email \ 2275 --from="Example " \ 2276 --to=alice --to=bcgrp \ 2277 --smtp-server="$(pwd)/fake.sendmail" \ 2278 outdir/0001-*.patch \ 2279 2>errors >out && 2280 for i in $expect 2281 do 2282 test_grep "^!$i!$" commandline1 || return 1 2283 done 2284 ' 2285 } 2286 2287 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \ 2288 'awol@example\.com' \ 2289 'bob@example\.com' \ 2290 'chloe@example\.com' \ 2291 'o@example\.com' <<-\EOF 2292 alice: Alice W Land 2293 bob: Robert Bobbyton 2294 # this is a comment 2295 # this is also a comment 2296 chloe: chloe@example.com 2297 abgroup: alice, bob 2298 bcgrp: bob, chloe, Other 2299 EOF 2300 2301 test_sendmail_aliases 'sendmail aliases line folding' \ 2302 alice1 \ 2303 bob1 bob2 \ 2304 chuck1 chuck2 \ 2305 darla1 darla2 darla3 \ 2306 elton1 elton2 elton3 \ 2307 fred1 fred2 \ 2308 greg1 <<-\EOF 2309 alice: alice1 2310 bob: bob1,\ 2311 bob2 2312 chuck: chuck1, 2313 chuck2 2314 darla: darla1,\ 2315 darla2, 2316 darla3 2317 elton: elton1, 2318 elton2,\ 2319 elton3 2320 fred: fred1,\ 2321 fred2 2322 greg: greg1 2323 bcgrp: bob, chuck, darla, elton, fred, greg 2324 EOF 2325 2326 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \ 2327 alice1 bob1 <<-\EOF 2328 alice: alice1 2329 bcgrp: bob1\ 2330 EOF 2331 2332 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF 2333 EOF 2334 2335 test_expect_success $PREREQ 'alias support in To header' ' 2336 clean_fake_sendmail && 2337 echo "alias sbd someone@example.org" >.mailrc && 2338 test_config sendemail.aliasesfile ".mailrc" && 2339 test_config sendemail.aliasfiletype mailrc && 2340 git format-patch --stdout -1 --to=sbd >aliased.patch && 2341 git send-email \ 2342 --from="Example " \ 2343 --smtp-server="$(pwd)/fake.sendmail" \ 2344 aliased.patch \ 2345 2>errors >out && 2346 test_grep "^!someone@example\.org!$" commandline1 2347 ' 2348 2349 test_expect_success $PREREQ 'alias support in Cc header' ' 2350 clean_fake_sendmail && 2351 echo "alias sbd someone@example.org" >.mailrc && 2352 test_config sendemail.aliasesfile ".mailrc" && 2353 test_config sendemail.aliasfiletype mailrc && 2354 git format-patch --stdout -1 --cc=sbd >aliased.patch && 2355 git send-email \ 2356 --from="Example " \ 2357 --smtp-server="$(pwd)/fake.sendmail" \ 2358 aliased.patch \ 2359 2>errors >out && 2360 test_grep "^!someone@example\.org!$" commandline1 2361 ' 2362 2363 test_expect_success $PREREQ 'tocmd works with aliases' ' 2364 clean_fake_sendmail && 2365 echo "alias sbd someone@example.org" >.mailrc && 2366 test_config sendemail.aliasesfile ".mailrc" && 2367 test_config sendemail.aliasfiletype mailrc && 2368 git format-patch --stdout -1 >tocmd.patch && 2369 echo tocmd--sbd >>tocmd.patch && 2370 git send-email \ 2371 --from="Example " \ 2372 --to-cmd=./tocmd-sed \ 2373 --smtp-server="$(pwd)/fake.sendmail" \ 2374 tocmd.patch \ 2375 2>errors >out && 2376 test_grep "^!someone@example\.org!$" commandline1 2377 ' 2378 2379 test_expect_success $PREREQ 'cccmd works with aliases' ' 2380 clean_fake_sendmail && 2381 echo "alias sbd someone@example.org" >.mailrc && 2382 test_config sendemail.aliasesfile ".mailrc" && 2383 test_config sendemail.aliasfiletype mailrc && 2384 git format-patch --stdout -1 >cccmd.patch && 2385 echo cccmd--sbd >>cccmd.patch && 2386 git send-email \ 2387 --from="Example " \ 2388 --cc-cmd=./cccmd-sed \ 2389 --smtp-server="$(pwd)/fake.sendmail" \ 2390 cccmd.patch \ 2391 2>errors >out && 2392 test_grep "^!someone@example\.org!$" commandline1 2393 ' 2394 2395 do_xmailer_test () { 2396 expected=$1 params=$2 && 2397 git format-patch -1 && 2398 git send-email \ 2399 --from="Example " \ 2400 --to=someone@example.com \ 2401 --smtp-server="$(pwd)/fake.sendmail" \ 2402 $params \ 2403 0001-*.patch \ 2404 2>errors >out && 2405 { grep '^X-Mailer:' out || :; } >mailer && 2406 test_line_count = $expected mailer 2407 } 2408 2409 test_expect_success $PREREQ '--[no-]xmailer without any configuration' ' 2410 do_xmailer_test 1 "--xmailer" && 2411 do_xmailer_test 0 "--no-xmailer" 2412 ' 2413 2414 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' ' 2415 test_config sendemail.xmailer true && 2416 do_xmailer_test 1 "" && 2417 do_xmailer_test 0 "--no-xmailer" && 2418 do_xmailer_test 1 "--xmailer" 2419 ' 2420 2421 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer' ' 2422 test_when_finished "test_unconfig sendemail.xmailer" && 2423 cat >>.git/config <<-\EOF && 2424 [sendemail] 2425 xmailer 2426 EOF 2427 test_config sendemail.xmailer true && 2428 do_xmailer_test 1 "" && 2429 do_xmailer_test 0 "--no-xmailer" && 2430 do_xmailer_test 1 "--xmailer" 2431 ' 2432 2433 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' ' 2434 test_config sendemail.xmailer false && 2435 do_xmailer_test 0 "" && 2436 do_xmailer_test 0 "--no-xmailer" && 2437 do_xmailer_test 1 "--xmailer" 2438 ' 2439 2440 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' ' 2441 test_config sendemail.xmailer "" && 2442 do_xmailer_test 0 "" && 2443 do_xmailer_test 0 "--no-xmailer" && 2444 do_xmailer_test 1 "--xmailer" 2445 ' 2446 2447 test_expect_success $PREREQ 'setup expected-list' ' 2448 git send-email \ 2449 --dry-run \ 2450 --from="Example " \ 2451 --to="To 1 " \ 2452 --to="to2@example.com" \ 2453 --to="to3@example.com" \ 2454 --cc="Cc 1 " \ 2455 --cc="Cc2 " \ 2456 --bcc="bcc1@example.com" \ 2457 --bcc="bcc2@example.com" \ 2458 0001-add-main.patch | replace_variable_fields \ 2459 >expected-list 2460 ' 2461 2462 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' ' 2463 git send-email \ 2464 --dry-run \ 2465 --from="Example " \ 2466 --to="To 1 , to2@example.com" \ 2467 --to="to3@example.com" \ 2468 --cc="Cc 1 , Cc2 " \ 2469 --bcc="bcc1@example.com, bcc2@example.com" \ 2470 0001-add-main.patch | replace_variable_fields \ 2471 >actual-list && 2472 test_cmp expected-list actual-list 2473 ' 2474 2475 test_expect_success $PREREQ 'aliases work with email list' ' 2476 echo "alias to2 to2@example.com" >.mutt && 2477 echo "alias cc1 Cc 1 " >>.mutt && 2478 test_config sendemail.aliasesfile ".mutt" && 2479 test_config sendemail.aliasfiletype mutt && 2480 git send-email \ 2481 --dry-run \ 2482 --from="Example " \ 2483 --to="To 1 , to2, to3@example.com" \ 2484 --cc="cc1, Cc2 " \ 2485 --bcc="bcc1@example.com, bcc2@example.com" \ 2486 0001-add-main.patch | replace_variable_fields \ 2487 >actual-list && 2488 test_cmp expected-list actual-list 2489 ' 2490 2491 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' ' 2492 echo "alias to2 to2@example.com" >.mutt && 2493 echo "alias cc1 Cc 1 " >>.mutt && 2494 test_config sendemail.aliasesfile ".mutt" && 2495 test_config sendemail.aliasfiletype mutt && 2496 TO1=$(echo "QTo 1 " | q_to_tab) && 2497 TO2=$(echo "QZto2" | qz_to_tab_space) && 2498 CC1=$(echo "cc1" | append_cr) && 2499 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) && 2500 git send-email \ 2501 --dry-run \ 2502 --from=" Example " \ 2503 --to="$TO1" \ 2504 --to="$TO2" \ 2505 --to=" to3@example.com " \ 2506 --cc="$CC1" \ 2507 --cc="Cc2 " \ 2508 --bcc="$BCC1" \ 2509 --bcc="bcc2@example.com" \ 2510 0001-add-main.patch | replace_variable_fields \ 2511 >actual-list && 2512 test_cmp expected-list actual-list 2513 ' 2514 2515 test_expect_success $PREREQ 'mailmap support with --to' ' 2516 clean_fake_sendmail && 2517 test_config mailmap.file "mailmap.test" && 2518 cat >mailmap.test <<-EOF && 2519 Some Body 2520 EOF 2521 git format-patch --stdout -1 >a.patch && 2522 git send-email \ 2523 --from="Example " \ 2524 --smtp-server="$(pwd)/fake.sendmail" \ 2525 --to=someone@example.org \ 2526 --mailmap \ 2527 a.patch \ 2528 2>errors >out && 2529 test_grep "^!someone@example\.com!$" commandline1 2530 ' 2531 2532 test_expect_success $PREREQ 'sendemail.mailmap configuration' ' 2533 clean_fake_sendmail && 2534 test_config mailmap.file "mailmap.test" && 2535 test_config sendemail.mailmap "true" && 2536 cat >mailmap.test <<-EOF && 2537 Some Body 2538 EOF 2539 git format-patch --stdout -1 >a.patch && 2540 git send-email \ 2541 --from="Example " \ 2542 --smtp-server="$(pwd)/fake.sendmail" \ 2543 --to=someone@example.org \ 2544 a.patch \ 2545 2>errors >out && 2546 test_grep "^!someone@example\.com!$" commandline1 2547 ' 2548 2549 test_expect_success $PREREQ 'sendemail.mailmap.file configuration' ' 2550 clean_fake_sendmail && 2551 test_config sendemail.mailmap.file "mailmap.test" && 2552 test_config sendemail.mailmap "true" && 2553 cat >mailmap.test <<-EOF && 2554 Some Body 2555 EOF 2556 git format-patch --stdout -1 >a.patch && 2557 git send-email \ 2558 --from="Example " \ 2559 --smtp-server="$(pwd)/fake.sendmail" \ 2560 --to=someone@example.org \ 2561 a.patch \ 2562 2>errors >out && 2563 test_grep "^!someone@example\.com!$" commandline1 2564 ' 2565 2566 test_expect_success $PREREQ 'sendemail.mailmap identity overrides configuration' ' 2567 clean_fake_sendmail && 2568 test_config sendemail.cloud.mailmap.file "mailmap.test" && 2569 test_config sendemail.mailmap "false" && 2570 test_config sendemail.cloud.mailmap "true" && 2571 cat >mailmap.test <<-EOF && 2572 Some Body 2573 EOF 2574 git format-patch --stdout -1 >a.patch && 2575 git send-email \ 2576 --from="Example " \ 2577 --smtp-server="$(pwd)/fake.sendmail" \ 2578 --identity=cloud \ 2579 --to=someone@example.org \ 2580 a.patch \ 2581 2>errors >out && 2582 test_grep "^!someone@example\.com!$" commandline1 2583 ' 2584 2585 test_expect_success $PREREQ '--no-mailmap overrides configuration' ' 2586 clean_fake_sendmail && 2587 test_config sendemail.cloud.mailmap.file "mailmap.test" && 2588 test_config sendemail.mailmap "false" && 2589 test_config sendemail.cloud.mailmap "true" && 2590 cat >mailmap.test <<-EOF && 2591 Some Body 2592 EOF 2593 git format-patch --stdout -1 >a.patch && 2594 git send-email \ 2595 --from="Example " \ 2596 --smtp-server="$(pwd)/fake.sendmail" \ 2597 --identity=cloud \ 2598 --to=someone@example.org \ 2599 --no-mailmap \ 2600 a.patch \ 2601 2>errors >out && 2602 test_grep "^!someone@example\.org!$" commandline1 2603 ' 2604 2605 test_expect_success $PREREQ 'mailmap support in To header' ' 2606 clean_fake_sendmail && 2607 test_config mailmap.file "mailmap.test" && 2608 cat >mailmap.test <<-EOF && 2609 2610 EOF 2611 git format-patch --stdout -1 --to=someone@example.org >a.patch && 2612 git send-email \ 2613 --from="Example " \ 2614 --smtp-server="$(pwd)/fake.sendmail" \ 2615 --mailmap \ 2616 a.patch \ 2617 2>errors >out && 2618 test_grep "^!someone@example\.com!$" commandline1 2619 ' 2620 2621 test_expect_success $PREREQ 'mailmap support in Cc header' ' 2622 clean_fake_sendmail && 2623 test_config mailmap.file "mailmap.test" && 2624 cat >mailmap.test <<-EOF && 2625 2626 EOF 2627 git format-patch --stdout -1 --cc=someone@example.org >a.patch && 2628 git send-email \ 2629 --from="Example " \ 2630 --smtp-server="$(pwd)/fake.sendmail" \ 2631 --mailmap \ 2632 a.patch \ 2633 2>errors >out && 2634 test_grep "^!someone@example\.com!$" commandline1 2635 ' 2636 2637 test_expect_success $PREREQ 'test using command name with --sendmail-cmd' ' 2638 clean_fake_sendmail && 2639 PATH="$PWD:$PATH" \ 2640 git send-email \ 2641 --from="Example " \ 2642 --to=nobody@example.com \ 2643 --sendmail-cmd="fake.sendmail" \ 2644 HEAD^ && 2645 test_path_is_file commandline1 2646 ' 2647 2648 test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' ' 2649 clean_fake_sendmail && 2650 git send-email \ 2651 --from="Example " \ 2652 --to=nobody@example.com \ 2653 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \ 2654 HEAD^ && 2655 test_path_is_file commandline1 2656 ' 2657 2658 test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' ' 2659 clean_fake_sendmail && 2660 git send-email \ 2661 --from="Example " \ 2662 --to=nobody@example.com \ 2663 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \ 2664 HEAD^ && 2665 test_path_is_file commandline1 2666 ' 2667 2668 test_expect_success $PREREQ 'set up in-reply-to/references patches' ' 2669 cat >has-reply.patch <<-\EOF && 2670 From: A U Thor 2671 Subject: patch with in-reply-to 2672 Message-ID: 2673 In-Reply-To: 2674 References: 2675 2676 This is the body. 2677 EOF 2678 cat >no-reply.patch <<-\EOF 2679 From: A U Thor 2680 Subject: patch without in-reply-to 2681 Message-ID: 2682 2683 This is the body. 2684 EOF 2685 ' 2686 2687 test_expect_success $PREREQ 'patch reply headers correct with --no-thread' ' 2688 clean_fake_sendmail && 2689 git send-email \ 2690 --no-thread \ 2691 --to=nobody@example.com \ 2692 --smtp-server="$(pwd)/fake.sendmail" \ 2693 has-reply.patch no-reply.patch && 2694 test_grep "In-Reply-To: " msgtxt1 && 2695 test_grep "References: " msgtxt1 && 2696 test_grep ! replied.to@example.com msgtxt2 2697 ' 2698 2699 test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' ' 2700 clean_fake_sendmail && 2701 git send-email \ 2702 --no-thread \ 2703 --in-reply-to="" \ 2704 --to=nobody@example.com \ 2705 --smtp-server="$(pwd)/fake.sendmail" \ 2706 has-reply.patch no-reply.patch && 2707 test_grep "In-Reply-To: " msgtxt1 && 2708 test_grep "References: " msgtxt1 && 2709 test_grep "In-Reply-To: " msgtxt2 && 2710 test_grep "References: " msgtxt2 2711 ' 2712 2713 test_expect_success $PREREQ 'invoke hook' ' 2714 test_hook sendemail-validate <<-\EOF && 2715 # test that we have the correct environment variable, pwd, and 2716 # argument 2717 case "$GIT_DIR" in 2718 *.git) 2719 true 2720 ;; 2721 *) 2722 false 2723 ;; 2724 esac && 2725 test -f 0001-add-main.patch && 2726 grep "add main" "$1" 2727 EOF 2728 2729 mkdir subdir && 2730 ( 2731 # Test that it works even if we are not at the root of the 2732 # working tree 2733 cd subdir && 2734 git send-email \ 2735 --from="Example " \ 2736 --to=nobody@example.com \ 2737 --smtp-server="$(pwd)/../fake.sendmail" \ 2738 ../0001-add-main.patch && 2739 2740 # Verify error message when a patch is rejected by the hook 2741 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch && 2742 test_must_fail git send-email \ 2743 --from="Example " \ 2744 --to=nobody@example.com \ 2745 --smtp-server="$(pwd)/../fake.sendmail" \ 2746 ../another.patch 2>err && 2747 test_grep "rejected by sendemail-validate hook" err 2748 ) 2749 ' 2750 2751 expected_file_counter_output () { 2752 total=$1 2753 count=0 2754 while test $count -ne $total 2755 do 2756 count=$((count + 1)) && 2757 echo "$count/$total" || return 2758 done 2759 } 2760 2761 test_expect_success $PREREQ '--validate hook allows counting of messages' ' 2762 test_when_finished "rm -rf my-hooks.log" && 2763 test_config core.hooksPath "my-hooks" && 2764 mkdir -p my-hooks && 2765 2766 write_script my-hooks/sendemail-validate <<-\EOF && 2767 num=$GIT_SENDEMAIL_FILE_COUNTER && 2768 tot=$GIT_SENDEMAIL_FILE_TOTAL && 2769 echo "$num/$tot" >>my-hooks.log || exit 1 2770 EOF 2771 2772 >my-hooks.log && 2773 expected_file_counter_output 4 >expect && 2774 git send-email \ 2775 --from="Example " \ 2776 --to=nobody@example.com \ 2777 --smtp-server="$(pwd)/fake.sendmail" \ 2778 --validate -3 --cover-letter --force && 2779 test_cmp expect my-hooks.log 2780 ' 2781 2782 test_expect_success $PREREQ 'test that send-email works outside a repo' ' 2783 nongit git send-email \ 2784 --from="Example " \ 2785 --to=nobody@example.com \ 2786 --smtp-server="$(pwd)/fake.sendmail" \ 2787 "$(pwd)/0001-add-main.patch" 2788 ' 2789 2790 test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' ' 2791 test_when_finished "rm -f out" && 2792 git send-email --dry-run -v 3 -1 >out && 2793 test_grep "PATCH v3" out 2794 ' 2795 2796 test_expect_success $PREREQ 'test that sendmail config is rejected' ' 2797 test_config sendmail.program sendmail && 2798 test_must_fail git send-email \ 2799 --from="Example " \ 2800 --to=nobody@example.com \ 2801 --smtp-server="$(pwd)/fake.sendmail" \ 2802 HEAD^ 2>err && 2803 test_grep "found configuration options for '"'"sendmail"'"'" err 2804 ' 2805 2806 test_expect_success $PREREQ 'test that sendmail config rejection is specific' ' 2807 test_config resendmail.program sendmail && 2808 git send-email \ 2809 --from="Example " \ 2810 --to=nobody@example.com \ 2811 --smtp-server="$(pwd)/fake.sendmail" \ 2812 HEAD^ 2813 ' 2814 2815 test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' ' 2816 test_config sendmail.program sendmail && 2817 test_config sendemail.forbidSendmailVariables false && 2818 git send-email \ 2819 --from="Example " \ 2820 --to=nobody@example.com \ 2821 --smtp-server="$(pwd)/fake.sendmail" \ 2822 HEAD^ 2823 ' 2824 2825 test_expect_success $PREREQ '--compose handles lowercase headers' ' 2826 write_script fake-editor <<-\EOF && 2827 sed "s/^[Ff][Rr][Oo][Mm]:.*/from: edited-from@example.com/" "$1" >"$1.tmp" && 2828 mv "$1.tmp" "$1" 2829 EOF 2830 clean_fake_sendmail && 2831 git send-email \ 2832 --compose \ 2833 --from="Example " \ 2834 --to=nobody@example.com \ 2835 --smtp-server="$(pwd)/fake.sendmail" \ 2836 HEAD^ && 2837 test_grep "From: edited-from@example.com" msgtxt1 2838 ' 2839 2840 test_expect_success $PREREQ '--compose handles to headers' ' 2841 write_script fake-editor <<-\EOF && 2842 sed "s/^To: .*/&, edited-to@example.com/" <"$1" >"$1.tmp" && 2843 echo this is the body >>"$1.tmp" && 2844 mv "$1.tmp" "$1" 2845 EOF 2846 clean_fake_sendmail && 2847 GIT_SEND_EMAIL_NOTTY=1 \ 2848 git send-email \ 2849 --compose \ 2850 --from="Example " \ 2851 --to=nobody@example.com \ 2852 --smtp-server="$(pwd)/fake.sendmail" \ 2853 HEAD^ && 2854 # Check both that the cover letter used our modified "to" line, 2855 # but also that it was picked up for the patch. 2856 q_to_tab >expect <<-\EOF && 2857 To: nobody@example.com, 2858 Qedited-to@example.com 2859 EOF 2860 grep -A1 "^To:" msgtxt1 >msgtxt1.to && 2861 test_cmp expect msgtxt1.to && 2862 grep -A1 "^To:" msgtxt2 >msgtxt2.to && 2863 test_cmp expect msgtxt2.to 2864 ' 2865 2866 test_done