| 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 <one@example.com>" --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 <from@example.com>" \ |
| 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 <nobody@example.com>" --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 <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --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 <nobody@example.com>" --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: <two@example.com> # trailing comments are ignored |
| 174 | Cc: <three@example.com>, <not.four@example.com> one address per line |
| 175 | Cc: "Some # Body" <four@example.com> [ <also.a.comment> ] |
| 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 <one@example.com> (supporter:THIS (FOO/bar))' |
| 188 | echo 'Two Person <two@example.com> (maintainer:THIS THING)' |
| 189 | echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))' |
| 190 | echo '<four@example.com> (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 <author@example.com> from line 'From: A <author@example.com>' |
| 215 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
| 216 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' |
| 217 | Dry-OK. Log says: |
| 218 | Server: relay.example.com |
| 219 | MAIL FROM:<from@example.com> |
| 220 | RCPT TO:<to@example.com> |
| 221 | RCPT TO:<cc@example.com> |
| 222 | RCPT TO:<author@example.com> |
| 223 | RCPT TO:<one@example.com> |
| 224 | RCPT TO:<two@example.com> |
| 225 | RCPT TO:<bcc@example.com> |
| 226 | From: Example <from@example.com> |
| 227 | To: to@example.com |
| 228 | Cc: cc@example.com, |
| 229 | A <author@example.com>, |
| 230 | One <one@example.com>, |
| 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: <unique-message-id@example.com> |
| 237 | References: <unique-message-id@example.com> |
| 238 | Reply-To: Reply <reply@example.com> |
| 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 <from@example.com>" \ |
| 332 | --reply-to="Reply <reply@example.com>" \ |
| 333 | --to=to@example.com \ |
| 334 | --cc=cc@example.com \ |
| 335 | --bcc=bcc@example.com \ |
| 336 | --in-reply-to="<unique-message-id@example.com>" \ |
| 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 | grep "^From: A U Thor <author@example.com>\$" msgtxt1 && |
| 352 | grep "^To: to@example.com\$" msgtxt1 && |
| 353 | grep "^In-Reply-To: <my-message-id@example.com>" 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 </dev/null 2>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 </dev/null 2>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 <nobody@example.com>" \ |
| 402 | --to-cmd=./tocmd-sed \ |
| 403 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 404 | tocmd.patch \ |
| 405 | && |
| 406 | 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 <nobody@example.com>" \ |
| 415 | --to=nobody@example.com \ |
| 416 | --cc-cmd=./cccmd-sed \ |
| 417 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 418 | cccmd.patch \ |
| 419 | && |
| 420 | 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 <nobody@example.com>" \ |
| 429 | --to=nobody@example.com \ |
| 430 | --header-cmd=./headercmd-sed \ |
| 431 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 432 | headercmd.patch \ |
| 433 | && |
| 434 | 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 <nobody@example.com>" \ |
| 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 | ! 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 <nobody@example.com>" \ |
| 463 | --to=nobody@example.com \ |
| 464 | --header-cmd=./headercmd-multiline \ |
| 465 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 466 | headercmd.patch && |
| 467 | 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 <nobody@example.com>" \ |
| 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 <nobody@example.com>" \ |
| 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 <nobody@example.com>" \ |
| 520 | --to=nobody@example.com \ |
| 521 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 522 | $patches && |
| 523 | sed "1,/^\$/d" <msgtxt1 >msgbody1 && |
| 524 | grep "From: A <author@example.com>" 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 <author@example.com>" \ |
| 531 | --to=nobody@example.com \ |
| 532 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 533 | $patches && |
| 534 | sed "1,/^\$/d" <msgtxt1 >msgbody1 && |
| 535 | ! grep "From: A <author@example.com>" msgbody1 |
| 536 | ' |
| 537 | |
| 538 | test_expect_success $PREREQ 'allow long lines with --no-validate' ' |
| 539 | git send-email \ |
| 540 | --from="Example <nobody@example.com>" \ |
| 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 <author@example.com>" \ |
| 552 | --to=nobody@example.com \ |
| 553 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 554 | --transfer-encoding=auto \ |
| 555 | $patches && |
| 556 | 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 <nobody@example.com>" \ |
| 563 | --to=nobody@example.com \ |
| 564 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 565 | --transfer-encoding=auto \ |
| 566 | --no-validate \ |
| 567 | longline.patch && |
| 568 | 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 <nobody@example.com>" \ |
| 577 | --to=nobody@example.com \ |
| 578 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 579 | --transfer-encoding=auto \ |
| 580 | --no-validate \ |
| 581 | cr.patch && |
| 582 | 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 <nobody@example.com>" \ |
| 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 <nobody@example.com>" \ |
| 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 -- <patch> <header>'"'"' 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 <nobody@example.com>" \ |
| 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 -- <patch> <header>'"'"' 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 <nobody@example.com>" \ |
| 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 -- <patch> <header>'"'"' 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 <nobody@example.com>" \ |
| 704 | --to=nobody@example.com \ |
| 705 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 706 | --transfer-encoding=$enc \ |
| 707 | $patches && |
| 708 | 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 <nobody@example.com>" \ |
| 716 | --to=nobody@example.com \ |
| 717 | --in-reply-to=" " \ |
| 718 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 719 | $patches \ |
| 720 | 2>errors && |
| 721 | ! 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 <from@example.com>" && |
| 727 | echo "To Example <to@example.com>" && |
| 728 | echo "" |
| 729 | ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \ |
| 730 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 731 | $patches 2>errors && |
| 732 | ! 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 "<unique-message-id@example.com>" >expect && |
| 738 | git send-email \ |
| 739 | --from="Example <nobody@example.com>" \ |
| 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 "<unique-message-id@example.com>" >expect && |
| 760 | git send-email \ |
| 761 | --from="Example <nobody@example.com>" \ |
| 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 <nobody@example.com>" \ |
| 792 | --to=nobody@example.com \ |
| 793 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 794 | $patches 2>err && |
| 795 | grep "I am about to error" err && |
| 796 | 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 <nobody@example.com>" \ |
| 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 | grep "^fake edit" msgtxt1 |
| 818 | ' |
| 819 | |
| 820 | test_expect_success $PREREQ 'second message is patch' ' |
| 821 | 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 <author@example.com> from line 'From: A <author@example.com>' |
| 828 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
| 829 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' |
| 830 | Dry-OK. Log says: |
| 831 | Server: relay.example.com |
| 832 | MAIL FROM:<from@example.com> |
| 833 | RCPT TO:<to@example.com> |
| 834 | RCPT TO:<cc@example.com> |
| 835 | RCPT TO:<author@example.com> |
| 836 | RCPT TO:<one@example.com> |
| 837 | RCPT TO:<two@example.com> |
| 838 | From: Example <from@example.com> |
| 839 | To: to@example.com |
| 840 | Cc: cc@example.com, |
| 841 | A <author@example.com>, |
| 842 | One <one@example.com>, |
| 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 <from@example.com>" \ |
| 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 <author@example.com> from line 'From: A <author@example.com>' |
| 876 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
| 877 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' |
| 878 | Dry-OK. Log says: |
| 879 | Server: relay.example.com |
| 880 | MAIL FROM:<from@example.com> |
| 881 | RCPT TO:<to@example.com> |
| 882 | RCPT TO:<author@example.com> |
| 883 | RCPT TO:<one@example.com> |
| 884 | RCPT TO:<two@example.com> |
| 885 | From: Example <from@example.com> |
| 886 | To: to@example.com |
| 887 | Cc: A <author@example.com>, |
| 888 | One <one@example.com>, |
| 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 <author@example.com> from line 'From: A <author@example.com>' |
| 910 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
| 911 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' |
| 912 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' |
| 913 | Dry-OK. Log says: |
| 914 | Server: relay.example.com |
| 915 | MAIL FROM:<from@example.com> |
| 916 | RCPT TO:<to@example.com> |
| 917 | RCPT TO:<author@example.com> |
| 918 | RCPT TO:<one@example.com> |
| 919 | RCPT TO:<two@example.com> |
| 920 | RCPT TO:<committer@example.com> |
| 921 | From: Example <from@example.com> |
| 922 | To: to@example.com |
| 923 | Cc: A <author@example.com>, |
| 924 | One <one@example.com>, |
| 925 | two@example.com, |
| 926 | C O Mitter <committer@example.com> |
| 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:<from@example.com> |
| 952 | RCPT TO:<to@example.com> |
| 953 | From: Example <from@example.com> |
| 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 <author@example.com> from line 'From: A <author@example.com>' |
| 974 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
| 975 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, 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:<from@example.com> |
| 980 | RCPT TO:<to@example.com> |
| 981 | RCPT TO:<author@example.com> |
| 982 | RCPT TO:<one@example.com> |
| 983 | RCPT TO:<two@example.com> |
| 984 | RCPT TO:<cc-cmd@example.com> |
| 985 | From: Example <from@example.com> |
| 986 | To: to@example.com |
| 987 | Cc: A <author@example.com>, |
| 988 | One <one@example.com>, |
| 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 <author@example.com> from line 'From: A <author@example.com>' |
| 1010 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
| 1011 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' |
| 1012 | Dry-OK. Log says: |
| 1013 | Server: relay.example.com |
| 1014 | MAIL FROM:<from@example.com> |
| 1015 | RCPT TO:<to@example.com> |
| 1016 | RCPT TO:<author@example.com> |
| 1017 | RCPT TO:<one@example.com> |
| 1018 | RCPT TO:<two@example.com> |
| 1019 | From: Example <from@example.com> |
| 1020 | To: to@example.com |
| 1021 | Cc: A <author@example.com>, |
| 1022 | One <one@example.com>, |
| 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 <author@example.com> from line 'From: A <author@example.com>' |
| 1043 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
| 1044 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' |
| 1045 | Dry-OK. Log says: |
| 1046 | Server: relay.example.com |
| 1047 | MAIL FROM:<from@example.com> |
| 1048 | RCPT TO:<to@example.com> |
| 1049 | RCPT TO:<author@example.com> |
| 1050 | RCPT TO:<one@example.com> |
| 1051 | RCPT TO:<two@example.com> |
| 1052 | From: Example <from@example.com> |
| 1053 | To: to@example.com |
| 1054 | Cc: A <author@example.com>, |
| 1055 | One <one@example.com>, |
| 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 <author@example.com> from line 'From: A <author@example.com>' |
| 1077 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
| 1078 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' |
| 1079 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' |
| 1080 | Dry-OK. Log says: |
| 1081 | Server: relay.example.com |
| 1082 | MAIL FROM:<from@example.com> |
| 1083 | RCPT TO:<to@example.com> |
| 1084 | RCPT TO:<author@example.com> |
| 1085 | RCPT TO:<one@example.com> |
| 1086 | RCPT TO:<two@example.com> |
| 1087 | RCPT TO:<committer@example.com> |
| 1088 | From: Example <from@example.com> |
| 1089 | To: to@example.com |
| 1090 | Cc: A <author@example.com>, |
| 1091 | One <one@example.com>, |
| 1092 | two@example.com, |
| 1093 | C O Mitter <committer@example.com> |
| 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 <author@example.com> from line 'From: A <author@example.com>' |
| 1113 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' |
| 1114 | Dry-OK. Log says: |
| 1115 | Server: relay.example.com |
| 1116 | MAIL FROM:<from@example.com> |
| 1117 | RCPT TO:<to@example.com> |
| 1118 | RCPT TO:<author@example.com> |
| 1119 | RCPT TO:<committer@example.com> |
| 1120 | From: Example <from@example.com> |
| 1121 | To: to@example.com |
| 1122 | Cc: A <author@example.com>, |
| 1123 | C O Mitter <committer@example.com> |
| 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 <nobody@example.com>" \ |
| 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 <nobody@example.com>" \ |
| 1186 | --to=nobody@example.com \ |
| 1187 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1188 | outdir/*.patch </dev/null |
| 1189 | ' |
| 1190 | |
| 1191 | test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' ' |
| 1192 | test_when_finished git config sendemail.confirm never && |
| 1193 | git config sendemail.confirm auto && |
| 1194 | GIT_SEND_EMAIL_NOTTY=1 && |
| 1195 | export GIT_SEND_EMAIL_NOTTY && |
| 1196 | test_must_fail git send-email \ |
| 1197 | --from="Example <nobody@example.com>" \ |
| 1198 | --to=nobody@example.com \ |
| 1199 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1200 | $patches </dev/null |
| 1201 | ' |
| 1202 | |
| 1203 | test_expect_success $PREREQ 'confirm does not loop forever' ' |
| 1204 | test_when_finished git config sendemail.confirm never && |
| 1205 | git config sendemail.confirm auto && |
| 1206 | GIT_SEND_EMAIL_NOTTY=1 && |
| 1207 | export GIT_SEND_EMAIL_NOTTY && |
| 1208 | yes "bogus" | test_must_fail git send-email \ |
| 1209 | --from="Example <nobody@example.com>" \ |
| 1210 | --to=nobody@example.com \ |
| 1211 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1212 | $patches |
| 1213 | ' |
| 1214 | |
| 1215 | test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' ' |
| 1216 | clean_fake_sendmail && |
| 1217 | rm -fr outdir && |
| 1218 | git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" && |
| 1219 | git send-email \ |
| 1220 | --from="Example <nobody@example.com>" \ |
| 1221 | --to=nobody@example.com \ |
| 1222 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1223 | outdir/*.patch && |
| 1224 | grep "^ " msgtxt1 | |
| 1225 | grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>" |
| 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 <nobody@example.com>" \ |
| 1237 | --to=nobody@example.com \ |
| 1238 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1239 | $patches && |
| 1240 | grep "^utf8 body" msgtxt1 && |
| 1241 | 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 <nobody@example.com>" \ |
| 1260 | --to=nobody@example.com \ |
| 1261 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1262 | $patches && |
| 1263 | grep "^utf8 body" msgtxt1 && |
| 1264 | grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 && |
| 1265 | ! 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 <nobody@example.com>" \ |
| 1274 | --to=nobody@example.com \ |
| 1275 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1276 | $patches && |
| 1277 | grep "^fake edit" msgtxt1 && |
| 1278 | 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é <odd_?=mail@example.com>" && |
| 1286 | git format-patch --stdout -1 >funny_name.patch && |
| 1287 | git send-email --from="Example <nobody@example.com>" \ |
| 1288 | --to=nobody@example.com \ |
| 1289 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1290 | funny_name.patch && |
| 1291 | grep "^From: Füñný Nâmé <odd_?=mail@example.com>" 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é <odd_?=mail@example.com>" && |
| 1299 | git format-patch --stdout -1 >funny_name.patch && |
| 1300 | git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \ |
| 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 <one@example.com> |
| 1329 | Cc: Ronnie O${SQ}Sullivan <os@example.com> |
| 1330 | Reviewed-by: Füñný Nâmé <odd_?=mail@example.com> |
| 1331 | Reported-by: bugger on Jira |
| 1332 | Reported-by: Douglas Reporter <doug@example.com> [from Jira profile] |
| 1333 | BugID: 12345should-not-appear |
| 1334 | Co-developed-by: "C. O. Developer" <codev@example.com> |
| 1335 | Signed-off-by: A. U. Thor <thor.au@example.com> |
| 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\" <one@example.com>" actual-show-all-headers && |
| 1341 | test_grep "^(body) Adding cc: Ronnie O${SQ}Sullivan <os@example.com>" 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 | " <odd_?=mail@example.com>" 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 <doug@example.com>" actual-show-all-headers && |
| 1346 | test_grep ! "12345should-not-appear" actual-show-all-headers && |
| 1347 | test_grep "^(body) Adding cc: \"C. O. Developer\" <codev@example.com>" actual-show-all-headers && |
| 1348 | test_grep "^(body) Adding cc: \"A. U. Thor\" <thor.au@example.com>" 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 <nobody@example.com>" \ |
| 1361 | --to=nobody@example.com \ |
| 1362 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1363 | $patches && |
| 1364 | grep "^utf8 body" msgtxt1 && |
| 1365 | 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 <nobody@example.com>" \ |
| 1378 | --to=nobody@example.com \ |
| 1379 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1380 | $patches && |
| 1381 | grep "^utf8 body" msgtxt1 && |
| 1382 | 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 <nobody@example.com>" \ |
| 1396 | --to=nobody@example.com \ |
| 1397 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1398 | $patches && |
| 1399 | grep "^utf8 body" msgtxt1 && |
| 1400 | 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 <nobody@example.com>" \ |
| 1410 | --to=nobody@example.com \ |
| 1411 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1412 | $patches && |
| 1413 | grep "^fake edit" msgtxt1 && |
| 1414 | 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 | grep disambiguate errors |
| 1423 | ' |
| 1424 | |
| 1425 | test_expect_success $PREREQ 'feed two files' ' |
| 1426 | rm -fr outdir && |
| 1427 | git format-patch -2 -o outdir && |
| 1428 | git send-email \ |
| 1429 | --dry-run \ |
| 1430 | --from="Example <nobody@example.com>" \ |
| 1431 | --to=nobody@example.com \ |
| 1432 | outdir/000?-*.patch 2>errors >out && |
| 1433 | grep "^Subject: " out >subjects && |
| 1434 | test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." && |
| 1435 | test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main" |
| 1436 | ' |
| 1437 | |
| 1438 | test_expect_success $PREREQ 'in-reply-to but no threading' ' |
| 1439 | git send-email \ |
| 1440 | --dry-run \ |
| 1441 | --from="Example <nobody@example.com>" \ |
| 1442 | --to=nobody@example.com \ |
| 1443 | --in-reply-to="<in-reply-id@example.com>" \ |
| 1444 | --no-thread \ |
| 1445 | $patches >out && |
| 1446 | grep "In-Reply-To: <in-reply-id@example.com>" out |
| 1447 | ' |
| 1448 | |
| 1449 | test_expect_success $PREREQ 'no in-reply-to and no threading' ' |
| 1450 | git send-email \ |
| 1451 | --dry-run \ |
| 1452 | --from="Example <nobody@example.com>" \ |
| 1453 | --to=nobody@example.com \ |
| 1454 | --no-thread \ |
| 1455 | $patches >stdout && |
| 1456 | ! grep "In-Reply-To: " stdout |
| 1457 | ' |
| 1458 | |
| 1459 | test_expect_success $PREREQ 'threading but no chain-reply-to' ' |
| 1460 | git send-email \ |
| 1461 | --dry-run \ |
| 1462 | --from="Example <nobody@example.com>" \ |
| 1463 | --to=nobody@example.com \ |
| 1464 | --thread \ |
| 1465 | --no-chain-reply-to \ |
| 1466 | $patches $patches >stdout && |
| 1467 | grep "In-Reply-To: " stdout |
| 1468 | ' |
| 1469 | |
| 1470 | test_expect_success $PREREQ 'override in-reply-to if no threading' ' |
| 1471 | git send-email \ |
| 1472 | --dry-run \ |
| 1473 | --from="Example <nobody@example.com>" \ |
| 1474 | --to=nobody@example.com \ |
| 1475 | --no-thread \ |
| 1476 | --in-reply-to="override" \ |
| 1477 | $threaded_patches >stdout && |
| 1478 | grep "In-Reply-To: <override>" stdout |
| 1479 | ' |
| 1480 | |
| 1481 | test_expect_success $PREREQ 'sendemail.to works' ' |
| 1482 | git config --replace-all sendemail.to "Somebody <somebody@ex.com>" && |
| 1483 | git send-email \ |
| 1484 | --dry-run \ |
| 1485 | --from="Example <nobody@example.com>" \ |
| 1486 | $patches >stdout && |
| 1487 | grep "To: Somebody <somebody@ex.com>" stdout |
| 1488 | ' |
| 1489 | |
| 1490 | test_expect_success $PREREQ 'setup sendemail.identity' ' |
| 1491 | git config --replace-all sendemail.to "default@example.com" && |
| 1492 | git config --replace-all sendemail.isp.to "isp@example.com" && |
| 1493 | git config --replace-all sendemail.cloud.to "cloud@example.com" |
| 1494 | ' |
| 1495 | |
| 1496 | test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' ' |
| 1497 | git -c sendemail.identity=cloud send-email \ |
| 1498 | --dry-run \ |
| 1499 | --from="nobody@example.com" \ |
| 1500 | $patches >stdout && |
| 1501 | grep "To: cloud@example.com" stdout |
| 1502 | ' |
| 1503 | |
| 1504 | test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' ' |
| 1505 | git -c sendemail.identity=cloud send-email \ |
| 1506 | --identity=isp \ |
| 1507 | --dry-run \ |
| 1508 | --from="nobody@example.com" \ |
| 1509 | $patches >stdout && |
| 1510 | grep "To: isp@example.com" stdout |
| 1511 | ' |
| 1512 | |
| 1513 | test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' ' |
| 1514 | git -c sendemail.identity=cloud send-email \ |
| 1515 | --no-identity \ |
| 1516 | --dry-run \ |
| 1517 | --from="nobody@example.com" \ |
| 1518 | $patches >stdout && |
| 1519 | grep "To: default@example.com" stdout |
| 1520 | ' |
| 1521 | |
| 1522 | test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' ' |
| 1523 | git -c sendemail.identity=cloud \ |
| 1524 | -c sendemail.xmailer=true \ |
| 1525 | -c sendemail.cloud.xmailer=false \ |
| 1526 | send-email \ |
| 1527 | --dry-run \ |
| 1528 | --from="nobody@example.com" \ |
| 1529 | $patches >stdout && |
| 1530 | grep "To: cloud@example.com" stdout && |
| 1531 | ! grep "X-Mailer" stdout |
| 1532 | ' |
| 1533 | |
| 1534 | test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' ' |
| 1535 | git -c sendemail.identity=cloud \ |
| 1536 | -c sendemail.xmailer=false \ |
| 1537 | send-email \ |
| 1538 | --dry-run \ |
| 1539 | --from="nobody@example.com" \ |
| 1540 | $patches >stdout && |
| 1541 | grep "To: cloud@example.com" stdout && |
| 1542 | ! grep "X-Mailer" stdout |
| 1543 | ' |
| 1544 | |
| 1545 | test_expect_success $PREREQ 'sendemail.identity: bool variable without a value' ' |
| 1546 | git -c sendemail.xmailer \ |
| 1547 | send-email \ |
| 1548 | --dry-run \ |
| 1549 | --from="nobody@example.com" \ |
| 1550 | $patches >stdout && |
| 1551 | grep "To: default@example.com" stdout && |
| 1552 | grep "X-Mailer" stdout |
| 1553 | ' |
| 1554 | |
| 1555 | test_expect_success $PREREQ '--no-to overrides sendemail.to' ' |
| 1556 | git send-email \ |
| 1557 | --dry-run \ |
| 1558 | --from="Example <nobody@example.com>" \ |
| 1559 | --no-to \ |
| 1560 | --to=nobody@example.com \ |
| 1561 | $patches >stdout && |
| 1562 | grep "To: nobody@example.com" stdout && |
| 1563 | ! grep "To: Somebody <somebody@ex.com>" stdout |
| 1564 | ' |
| 1565 | |
| 1566 | test_expect_success $PREREQ 'sendemail.cc works' ' |
| 1567 | git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" && |
| 1568 | git send-email \ |
| 1569 | --dry-run \ |
| 1570 | --from="Example <nobody@example.com>" \ |
| 1571 | --to=nobody@example.com \ |
| 1572 | $patches >stdout && |
| 1573 | grep "Cc: Somebody <somebody@ex.com>" stdout |
| 1574 | ' |
| 1575 | |
| 1576 | test_expect_success $PREREQ '--no-cc overrides sendemail.cc' ' |
| 1577 | git send-email \ |
| 1578 | --dry-run \ |
| 1579 | --from="Example <nobody@example.com>" \ |
| 1580 | --no-cc \ |
| 1581 | --cc=bodies@example.com \ |
| 1582 | --to=nobody@example.com \ |
| 1583 | $patches >stdout && |
| 1584 | grep "Cc: bodies@example.com" stdout && |
| 1585 | ! grep "Cc: Somebody <somebody@ex.com>" stdout |
| 1586 | ' |
| 1587 | |
| 1588 | test_expect_success $PREREQ 'sendemail.bcc works' ' |
| 1589 | git config --replace-all sendemail.bcc "Other <other@ex.com>" && |
| 1590 | git send-email \ |
| 1591 | --dry-run \ |
| 1592 | --from="Example <nobody@example.com>" \ |
| 1593 | --to=nobody@example.com \ |
| 1594 | --smtp-server relay.example.com \ |
| 1595 | $patches >stdout && |
| 1596 | grep "RCPT TO:<other@ex.com>" stdout |
| 1597 | ' |
| 1598 | |
| 1599 | test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' ' |
| 1600 | git send-email \ |
| 1601 | --dry-run \ |
| 1602 | --from="Example <nobody@example.com>" \ |
| 1603 | --no-bcc \ |
| 1604 | --bcc=bodies@example.com \ |
| 1605 | --to=nobody@example.com \ |
| 1606 | --smtp-server relay.example.com \ |
| 1607 | $patches >stdout && |
| 1608 | grep "RCPT TO:<bodies@example.com>" stdout && |
| 1609 | ! grep "RCPT TO:<other@ex.com>" stdout |
| 1610 | ' |
| 1611 | |
| 1612 | test_expect_success $PREREQ 'patches To headers are used by default' ' |
| 1613 | patch=$(git format-patch -1 --to="bodies@example.com") && |
| 1614 | test_when_finished "rm $patch" && |
| 1615 | git send-email \ |
| 1616 | --dry-run \ |
| 1617 | --from="Example <nobody@example.com>" \ |
| 1618 | --smtp-server relay.example.com \ |
| 1619 | $patch >stdout && |
| 1620 | grep "RCPT TO:<bodies@example.com>" stdout |
| 1621 | ' |
| 1622 | |
| 1623 | test_expect_success $PREREQ 'patches To headers are appended to' ' |
| 1624 | patch=$(git format-patch -1 --to="bodies@example.com") && |
| 1625 | test_when_finished "rm $patch" && |
| 1626 | git send-email \ |
| 1627 | --dry-run \ |
| 1628 | --from="Example <nobody@example.com>" \ |
| 1629 | --to=nobody@example.com \ |
| 1630 | --smtp-server relay.example.com \ |
| 1631 | $patch >stdout && |
| 1632 | grep "RCPT TO:<bodies@example.com>" stdout && |
| 1633 | grep "RCPT TO:<nobody@example.com>" stdout |
| 1634 | ' |
| 1635 | |
| 1636 | test_expect_success $PREREQ 'To headers from files reset each patch' ' |
| 1637 | patch1=$(git format-patch -1 --to="bodies@example.com") && |
| 1638 | patch2=$(git format-patch -1 --to="other@example.com" HEAD~) && |
| 1639 | test_when_finished "rm $patch1 && rm $patch2" && |
| 1640 | git send-email \ |
| 1641 | --dry-run \ |
| 1642 | --from="Example <nobody@example.com>" \ |
| 1643 | --to="nobody@example.com" \ |
| 1644 | --smtp-server relay.example.com \ |
| 1645 | $patch1 $patch2 >stdout && |
| 1646 | test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 && |
| 1647 | test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 && |
| 1648 | test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1 |
| 1649 | ' |
| 1650 | |
| 1651 | test_expect_success $PREREQ 'setup expect' ' |
| 1652 | # NOTE: do not quote this heredoc, Dash 0.5.13 has a bug with heredocs |
| 1653 | # that contain multibyte chars. |
| 1654 | cat >email-using-8bit <<EOF |
| 1655 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 |
| 1656 | Message-ID: <bogus-message-id@example.com> |
| 1657 | From: author@example.com |
| 1658 | Date: Sat, 12 Jun 2010 15:53:58 +0200 |
| 1659 | Subject: subject goes here |
| 1660 | |
| 1661 | Dieser deutsche Text enthält einen Umlaut! |
| 1662 | EOF |
| 1663 | ' |
| 1664 | |
| 1665 | test_expect_success $PREREQ 'setup expect' ' |
| 1666 | echo "Subject: subject goes here" >expected |
| 1667 | ' |
| 1668 | |
| 1669 | test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' ' |
| 1670 | clean_fake_sendmail && |
| 1671 | echo bogus | |
| 1672 | git send-email --from=author@example.com --to=nobody@example.com \ |
| 1673 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1674 | --8bit-encoding=UTF-8 \ |
| 1675 | email-using-8bit >stdout && |
| 1676 | grep "Subject" msgtxt1 >actual && |
| 1677 | test_cmp expected actual |
| 1678 | ' |
| 1679 | |
| 1680 | test_expect_success $PREREQ 'setup expect' ' |
| 1681 | cat >content-type-decl <<-\EOF |
| 1682 | MIME-Version: 1.0 |
| 1683 | Content-Type: text/plain; charset=UTF-8 |
| 1684 | Content-Transfer-Encoding: 8bit |
| 1685 | EOF |
| 1686 | ' |
| 1687 | |
| 1688 | test_expect_success $PREREQ 'asks about and fixes 8bit encodings' ' |
| 1689 | clean_fake_sendmail && |
| 1690 | echo | |
| 1691 | git send-email --from=author@example.com --to=nobody@example.com \ |
| 1692 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1693 | email-using-8bit >stdout && |
| 1694 | grep "do not declare a Content-Transfer-Encoding" stdout && |
| 1695 | grep email-using-8bit stdout && |
| 1696 | grep "Declare which 8bit encoding to use" stdout && |
| 1697 | grep -E "Content|MIME" msgtxt1 >actual && |
| 1698 | test_cmp content-type-decl actual |
| 1699 | ' |
| 1700 | |
| 1701 | test_expect_success $PREREQ 'sendemail.8bitEncoding works' ' |
| 1702 | clean_fake_sendmail && |
| 1703 | git config sendemail.assume8bitEncoding UTF-8 && |
| 1704 | echo bogus | |
| 1705 | git send-email --from=author@example.com --to=nobody@example.com \ |
| 1706 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1707 | email-using-8bit >stdout && |
| 1708 | grep -E "Content|MIME" msgtxt1 >actual && |
| 1709 | test_cmp content-type-decl actual |
| 1710 | ' |
| 1711 | |
| 1712 | test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' ' |
| 1713 | clean_fake_sendmail && |
| 1714 | git config sendemail.assume8bitEncoding UTF-8 && |
| 1715 | test_when_finished "rm -rf home" && |
| 1716 | mkdir home && |
| 1717 | git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" && |
| 1718 | echo bogus | |
| 1719 | env HOME="$(pwd)/home" DEBUG=1 \ |
| 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 '--8bit-encoding overrides sendemail.8bitEncoding' ' |
| 1728 | clean_fake_sendmail && |
| 1729 | git config sendemail.assume8bitEncoding "bogus too" && |
| 1730 | echo bogus | |
| 1731 | git send-email --from=author@example.com --to=nobody@example.com \ |
| 1732 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1733 | --8bit-encoding=UTF-8 \ |
| 1734 | email-using-8bit >stdout && |
| 1735 | grep -E "Content|MIME" msgtxt1 >actual && |
| 1736 | test_cmp content-type-decl actual |
| 1737 | ' |
| 1738 | |
| 1739 | test_expect_success $PREREQ 'setup expect' ' |
| 1740 | # NOTE: do not quote this heredoc, Dash 0.5.13 has a bug with heredocs |
| 1741 | # that contain multibyte chars. |
| 1742 | cat >email-using-8bit <<-EOF |
| 1743 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 |
| 1744 | Message-ID: <bogus-message-id@example.com> |
| 1745 | From: author@example.com |
| 1746 | Date: Sat, 12 Jun 2010 15:53:58 +0200 |
| 1747 | Subject: Dieser Betreff enthält auch einen Umlaut! |
| 1748 | |
| 1749 | Nothing to see here. |
| 1750 | EOF |
| 1751 | ' |
| 1752 | |
| 1753 | test_expect_success $PREREQ 'setup expect' ' |
| 1754 | cat >expected <<-\EOF |
| 1755 | Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?= |
| 1756 | EOF |
| 1757 | ' |
| 1758 | |
| 1759 | test_expect_success $PREREQ '--8bit-encoding also treats subject' ' |
| 1760 | clean_fake_sendmail && |
| 1761 | echo bogus | |
| 1762 | git send-email --from=author@example.com --to=nobody@example.com \ |
| 1763 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1764 | --8bit-encoding=UTF-8 \ |
| 1765 | email-using-8bit >stdout && |
| 1766 | grep "Subject" msgtxt1 >actual && |
| 1767 | test_cmp expected actual |
| 1768 | ' |
| 1769 | |
| 1770 | test_expect_success $PREREQ 'setup expect' ' |
| 1771 | # NOTE: do not quote this heredoc, Dash 0.5.13 has a bug with heredocs |
| 1772 | # that contain multibyte chars. |
| 1773 | cat >email-using-8bit <<-EOF |
| 1774 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 |
| 1775 | Message-ID: <bogus-message-id@example.com> |
| 1776 | From: A U Thor <author@example.com> |
| 1777 | Date: Sat, 12 Jun 2010 15:53:58 +0200 |
| 1778 | Content-Type: text/plain; charset=UTF-8 |
| 1779 | Subject: Nothing to see here. |
| 1780 | |
| 1781 | Dieser Betreff enthält auch einen Umlaut! |
| 1782 | EOF |
| 1783 | ' |
| 1784 | |
| 1785 | test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' ' |
| 1786 | clean_fake_sendmail && |
| 1787 | test_must_fail git -c sendemail.transferEncoding=8bit \ |
| 1788 | send-email \ |
| 1789 | --transfer-encoding=7bit \ |
| 1790 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1791 | email-using-8bit \ |
| 1792 | 2>errors >out && |
| 1793 | grep "cannot send message as 7bit" errors && |
| 1794 | test -z "$(ls msgtxt*)" |
| 1795 | ' |
| 1796 | |
| 1797 | test_expect_success $PREREQ 'sendemail.transferEncoding via config' ' |
| 1798 | clean_fake_sendmail && |
| 1799 | test_must_fail git -c sendemail.transferEncoding=7bit \ |
| 1800 | send-email \ |
| 1801 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1802 | email-using-8bit \ |
| 1803 | 2>errors >out && |
| 1804 | grep "cannot send message as 7bit" errors && |
| 1805 | test -z "$(ls msgtxt*)" |
| 1806 | ' |
| 1807 | |
| 1808 | test_expect_success $PREREQ 'sendemail.transferEncoding via cli' ' |
| 1809 | clean_fake_sendmail && |
| 1810 | test_must_fail git send-email \ |
| 1811 | --transfer-encoding=7bit \ |
| 1812 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1813 | email-using-8bit \ |
| 1814 | 2>errors >out && |
| 1815 | grep "cannot send message as 7bit" errors && |
| 1816 | test -z "$(ls msgtxt*)" |
| 1817 | ' |
| 1818 | |
| 1819 | test_expect_success $PREREQ 'setup expect' ' |
| 1820 | cat >expected <<-\EOF |
| 1821 | Dieser Betreff enth=C3=A4lt auch einen Umlaut! |
| 1822 | EOF |
| 1823 | ' |
| 1824 | |
| 1825 | test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' ' |
| 1826 | clean_fake_sendmail && |
| 1827 | git send-email \ |
| 1828 | --transfer-encoding=quoted-printable \ |
| 1829 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1830 | email-using-8bit \ |
| 1831 | 2>errors >out && |
| 1832 | sed "1,/^$/d" msgtxt1 >actual && |
| 1833 | test_cmp expected actual |
| 1834 | ' |
| 1835 | |
| 1836 | test_expect_success $PREREQ 'setup expect' ' |
| 1837 | cat >expected <<-\EOF |
| 1838 | RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg== |
| 1839 | EOF |
| 1840 | ' |
| 1841 | |
| 1842 | test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' ' |
| 1843 | clean_fake_sendmail && |
| 1844 | git send-email \ |
| 1845 | --transfer-encoding=base64 \ |
| 1846 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1847 | email-using-8bit \ |
| 1848 | 2>errors >out && |
| 1849 | sed "1,/^$/d" msgtxt1 >actual && |
| 1850 | test_cmp expected actual |
| 1851 | ' |
| 1852 | |
| 1853 | test_expect_success $PREREQ 'setup expect' ' |
| 1854 | cat >email-using-qp <<-\EOF |
| 1855 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 |
| 1856 | Message-ID: <bogus-message-id@example.com> |
| 1857 | From: A U Thor <author@example.com> |
| 1858 | Date: Sat, 12 Jun 2010 15:53:58 +0200 |
| 1859 | MIME-Version: 1.0 |
| 1860 | Content-Transfer-Encoding: quoted-printable |
| 1861 | Content-Type: text/plain; charset=UTF-8 |
| 1862 | Subject: Nothing to see here. |
| 1863 | |
| 1864 | Dieser Betreff enth=C3=A4lt auch einen Umlaut! |
| 1865 | EOF |
| 1866 | ' |
| 1867 | |
| 1868 | test_expect_success $PREREQ 'convert from quoted-printable to base64' ' |
| 1869 | clean_fake_sendmail && |
| 1870 | git send-email \ |
| 1871 | --transfer-encoding=base64 \ |
| 1872 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1873 | email-using-qp \ |
| 1874 | 2>errors >out && |
| 1875 | sed "1,/^$/d" msgtxt1 >actual && |
| 1876 | test_cmp expected actual |
| 1877 | ' |
| 1878 | |
| 1879 | test_expect_success $PREREQ 'setup expect' " |
| 1880 | tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF |
| 1881 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 |
| 1882 | Message-ID: <bogus-message-id@example.com> |
| 1883 | From: A U Thor <author@example.com> |
| 1884 | Date: Sat, 12 Jun 2010 15:53:58 +0200 |
| 1885 | Content-Type: text/plain; charset=UTF-8 |
| 1886 | Subject: Nothing to see here. |
| 1887 | |
| 1888 | Look, I have a CRLF and an = sign!% |
| 1889 | EOF |
| 1890 | " |
| 1891 | |
| 1892 | test_expect_success $PREREQ 'setup expect' ' |
| 1893 | cat >expected <<-\EOF |
| 1894 | Look, I have a CRLF and an =3D sign!=0D |
| 1895 | EOF |
| 1896 | ' |
| 1897 | |
| 1898 | test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' ' |
| 1899 | clean_fake_sendmail && |
| 1900 | git send-email \ |
| 1901 | --transfer-encoding=quoted-printable \ |
| 1902 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1903 | email-using-crlf \ |
| 1904 | 2>errors >out && |
| 1905 | sed "1,/^$/d" msgtxt1 >actual && |
| 1906 | test_cmp expected actual |
| 1907 | ' |
| 1908 | |
| 1909 | test_expect_success $PREREQ 'setup expect' ' |
| 1910 | cat >expected <<-\EOF |
| 1911 | TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K |
| 1912 | EOF |
| 1913 | ' |
| 1914 | |
| 1915 | test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' ' |
| 1916 | clean_fake_sendmail && |
| 1917 | git send-email \ |
| 1918 | --transfer-encoding=base64 \ |
| 1919 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1920 | email-using-crlf \ |
| 1921 | 2>errors >out && |
| 1922 | sed "1,/^$/d" msgtxt1 >actual && |
| 1923 | test_cmp expected actual |
| 1924 | ' |
| 1925 | |
| 1926 | |
| 1927 | # Note that the patches in this test are deliberately out of order; we |
| 1928 | # want to make sure it works even if the cover-letter is not in the |
| 1929 | # first mail. |
| 1930 | test_expect_success $PREREQ 'refusing to send cover letter template' ' |
| 1931 | clean_fake_sendmail && |
| 1932 | rm -fr outdir && |
| 1933 | git format-patch --cover-letter -2 -o outdir && |
| 1934 | test_must_fail git send-email \ |
| 1935 | --from="Example <nobody@example.com>" \ |
| 1936 | --to=nobody@example.com \ |
| 1937 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1938 | outdir/0002-*.patch \ |
| 1939 | outdir/0000-*.patch \ |
| 1940 | outdir/0001-*.patch \ |
| 1941 | 2>errors >out && |
| 1942 | grep "SUBJECT HERE" errors && |
| 1943 | test -z "$(ls msgtxt*)" |
| 1944 | ' |
| 1945 | |
| 1946 | test_expect_success $PREREQ '--force sends cover letter template anyway' ' |
| 1947 | clean_fake_sendmail && |
| 1948 | rm -fr outdir && |
| 1949 | git format-patch --cover-letter -2 -o outdir && |
| 1950 | git send-email \ |
| 1951 | --force \ |
| 1952 | --from="Example <nobody@example.com>" \ |
| 1953 | --to=nobody@example.com \ |
| 1954 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1955 | outdir/0002-*.patch \ |
| 1956 | outdir/0000-*.patch \ |
| 1957 | outdir/0001-*.patch \ |
| 1958 | 2>errors >out && |
| 1959 | ! grep "SUBJECT HERE" errors && |
| 1960 | test -n "$(ls msgtxt*)" |
| 1961 | ' |
| 1962 | |
| 1963 | test_cover_addresses () { |
| 1964 | header="$1" |
| 1965 | shift |
| 1966 | clean_fake_sendmail && |
| 1967 | rm -fr outdir && |
| 1968 | git format-patch --cover-letter -2 -o outdir && |
| 1969 | cover=$(echo outdir/0000-*.patch) && |
| 1970 | mv $cover cover-to-edit.patch && |
| 1971 | perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" && |
| 1972 | git send-email \ |
| 1973 | --force \ |
| 1974 | --from="Example <nobody@example.com>" \ |
| 1975 | --no-to --no-cc \ |
| 1976 | "$@" \ |
| 1977 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 1978 | outdir/0000-*.patch \ |
| 1979 | outdir/0001-*.patch \ |
| 1980 | outdir/0002-*.patch \ |
| 1981 | 2>errors >out && |
| 1982 | grep "^$header: extra@address.com" msgtxt1 >to1 && |
| 1983 | grep "^$header: extra@address.com" msgtxt2 >to2 && |
| 1984 | grep "^$header: extra@address.com" msgtxt3 >to3 && |
| 1985 | test_line_count = 1 to1 && |
| 1986 | test_line_count = 1 to2 && |
| 1987 | test_line_count = 1 to3 |
| 1988 | } |
| 1989 | |
| 1990 | test_expect_success $PREREQ 'to-cover adds To to all mail' ' |
| 1991 | test_cover_addresses "To" --to-cover |
| 1992 | ' |
| 1993 | |
| 1994 | test_expect_success $PREREQ 'cc-cover adds Cc to all mail' ' |
| 1995 | test_cover_addresses "Cc" --cc-cover |
| 1996 | ' |
| 1997 | |
| 1998 | test_expect_success $PREREQ 'tocover adds To to all mail' ' |
| 1999 | test_config sendemail.tocover true && |
| 2000 | test_cover_addresses "To" |
| 2001 | ' |
| 2002 | |
| 2003 | test_expect_success $PREREQ 'cccover adds Cc to all mail' ' |
| 2004 | test_config sendemail.cccover true && |
| 2005 | test_cover_addresses "Cc" |
| 2006 | ' |
| 2007 | |
| 2008 | test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' ' |
| 2009 | clean_fake_sendmail && |
| 2010 | echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt && |
| 2011 | git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" && |
| 2012 | git config sendemail.aliasfiletype mutt && |
| 2013 | git send-email \ |
| 2014 | --from="Example <nobody@example.com>" \ |
| 2015 | --to=sbd \ |
| 2016 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2017 | outdir/0001-*.patch \ |
| 2018 | 2>errors >out && |
| 2019 | grep "^!somebody@example\.org!$" commandline1 && |
| 2020 | grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out |
| 2021 | ' |
| 2022 | |
| 2023 | test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' ' |
| 2024 | clean_fake_sendmail && |
| 2025 | echo "alias sbd somebody@example.org" >.mailrc && |
| 2026 | git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" && |
| 2027 | git config sendemail.aliasfiletype mailrc && |
| 2028 | git send-email \ |
| 2029 | --from="Example <nobody@example.com>" \ |
| 2030 | --to=sbd \ |
| 2031 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2032 | outdir/0001-*.patch \ |
| 2033 | 2>errors >out && |
| 2034 | grep "^!somebody@example\.org!$" commandline1 |
| 2035 | ' |
| 2036 | |
| 2037 | test_expect_success $PREREQ 'sendemail.aliasesfile=~/.mailrc' ' |
| 2038 | clean_fake_sendmail && |
| 2039 | echo "alias sbd someone@example.org" >"$HOME/.mailrc" && |
| 2040 | git config --replace-all sendemail.aliasesfile "~/.mailrc" && |
| 2041 | git config sendemail.aliasfiletype mailrc && |
| 2042 | git send-email \ |
| 2043 | --from="Example <nobody@example.com>" \ |
| 2044 | --to=sbd \ |
| 2045 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2046 | outdir/0001-*.patch \ |
| 2047 | 2>errors >out && |
| 2048 | grep "^!someone@example\.org!$" commandline1 |
| 2049 | ' |
| 2050 | |
| 2051 | test_dump_aliases () { |
| 2052 | msg="$1" && shift && |
| 2053 | filetype="$1" && shift && |
| 2054 | printf '%s\n' "$@" >expect && |
| 2055 | cat >.tmp-email-aliases && |
| 2056 | |
| 2057 | test_expect_success $PREREQ "$msg" ' |
| 2058 | clean_fake_sendmail && rm -fr outdir && |
| 2059 | git config --replace-all sendemail.aliasesfile \ |
| 2060 | "$(pwd)/.tmp-email-aliases" && |
| 2061 | git config sendemail.aliasfiletype "$filetype" && |
| 2062 | git send-email --dump-aliases 2>errors >actual && |
| 2063 | test_cmp expect actual |
| 2064 | ' |
| 2065 | } |
| 2066 | |
| 2067 | test_dump_aliases '--dump-aliases sendmail format' \ |
| 2068 | 'sendmail' \ |
| 2069 | 'abgroup' \ |
| 2070 | 'alice' \ |
| 2071 | 'bcgrp' \ |
| 2072 | 'bob' \ |
| 2073 | 'chloe' <<-\EOF |
| 2074 | alice: Alice W Land <awol@example.com> |
| 2075 | bob: Robert Bobbyton <bob@example.com> |
| 2076 | chloe: chloe@example.com |
| 2077 | abgroup: alice, bob |
| 2078 | bcgrp: bob, chloe, Other <o@example.com> |
| 2079 | EOF |
| 2080 | |
| 2081 | test_dump_aliases '--dump-aliases mutt format' \ |
| 2082 | 'mutt' \ |
| 2083 | 'alice' \ |
| 2084 | 'bob' \ |
| 2085 | 'chloe' \ |
| 2086 | 'donald' <<-\EOF |
| 2087 | alias alice Alice W Land <awol@example.com> |
| 2088 | alias donald Donald C Carlton <donc@example.com> |
| 2089 | alias bob Robert Bobbyton <bob@example.com> |
| 2090 | alias chloe chloe@example.com |
| 2091 | EOF |
| 2092 | |
| 2093 | test_dump_aliases '--dump-aliases mailrc format' \ |
| 2094 | 'mailrc' \ |
| 2095 | 'alice' \ |
| 2096 | 'bob' \ |
| 2097 | 'chloe' \ |
| 2098 | 'eve' <<-\EOF |
| 2099 | alias alice "Alice W Land <awol@example.com>" |
| 2100 | alias eve "Eve <eve@example.com>" |
| 2101 | alias bob "Robert Bobbyton <bob@example.com>" |
| 2102 | alias chloe chloe@example.com |
| 2103 | EOF |
| 2104 | |
| 2105 | test_dump_aliases '--dump-aliases pine format' \ |
| 2106 | 'pine' \ |
| 2107 | 'alice' \ |
| 2108 | 'bcgrp' \ |
| 2109 | 'bob' \ |
| 2110 | 'chloe' \ |
| 2111 | 'eve' <<-\EOF |
| 2112 | alice Alice W Land awol@example.com Friend |
| 2113 | eve Eve eve@example.com |
| 2114 | bob Robert Bobbyton bob@example.com |
| 2115 | chloe chloe@example.com |
| 2116 | bcgrp (bob, chloe, Other <o@example.com>) |
| 2117 | EOF |
| 2118 | |
| 2119 | test_dump_aliases '--dump-aliases gnus format' \ |
| 2120 | 'gnus' \ |
| 2121 | 'alice' \ |
| 2122 | 'bob' \ |
| 2123 | 'chloe' \ |
| 2124 | 'eve' <<-\EOF |
| 2125 | (define-mail-alias "alice" "awol@example.com") |
| 2126 | (define-mail-alias "eve" "eve@example.com") |
| 2127 | (define-mail-alias "bob" "bob@example.com") |
| 2128 | (define-mail-alias "chloe" "chloe@example.com") |
| 2129 | EOF |
| 2130 | |
| 2131 | test_expect_success '--dump-aliases must be used alone' ' |
| 2132 | test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting |
| 2133 | ' |
| 2134 | |
| 2135 | test_translate_aliases () { |
| 2136 | msg="$1" && shift && |
| 2137 | filetype="$1" && shift && |
| 2138 | aliases="$1" && shift && |
| 2139 | printf '%s\n' "$@" >expect && |
| 2140 | cat >.tmp-email-aliases && |
| 2141 | printf '%s\n' "$aliases" >aliases && |
| 2142 | |
| 2143 | test_expect_success $PREREQ "$msg" ' |
| 2144 | clean_fake_sendmail && rm -fr outdir && |
| 2145 | git config --replace-all sendemail.aliasesfile \ |
| 2146 | "$(pwd)/.tmp-email-aliases" && |
| 2147 | git config sendemail.aliasfiletype "$filetype" && |
| 2148 | git send-email --translate-aliases <aliases 2>errors >actual && |
| 2149 | test_cmp expect actual |
| 2150 | ' |
| 2151 | } |
| 2152 | |
| 2153 | test_translate_aliases '--translate-aliases sendmail format' \ |
| 2154 | 'sendmail' \ |
| 2155 | 'alice bcgrp' \ |
| 2156 | 'Alice W Land <awol@example.com>' \ |
| 2157 | 'Robert Bobbyton <bob@example.com>' \ |
| 2158 | 'chloe@example.com' \ |
| 2159 | 'Other <o@example.com>' <<-\EOF |
| 2160 | alice: Alice W Land <awol@example.com> |
| 2161 | bob: Robert Bobbyton <bob@example.com> |
| 2162 | chloe: chloe@example.com |
| 2163 | abgroup: alice, bob |
| 2164 | bcgrp: bob, chloe, Other <o@example.com> |
| 2165 | EOF |
| 2166 | |
| 2167 | test_translate_aliases '--translate-aliases mutt format' \ |
| 2168 | 'mutt' \ |
| 2169 | 'donald bob' \ |
| 2170 | 'Donald C Carlton <donc@example.com>' \ |
| 2171 | 'Robert Bobbyton <bob@example.com>' <<-\EOF |
| 2172 | alias alice Alice W Land <awol@example.com> |
| 2173 | alias donald Donald C Carlton <donc@example.com> |
| 2174 | alias bob Robert Bobbyton <bob@example.com> |
| 2175 | alias chloe chloe@example.com |
| 2176 | EOF |
| 2177 | |
| 2178 | test_translate_aliases '--translate-aliases mailrc format' \ |
| 2179 | 'mailrc' \ |
| 2180 | 'chloe eve alice' \ |
| 2181 | 'chloe@example.com' \ |
| 2182 | 'Eve <eve@example.com>' \ |
| 2183 | 'Alice W Land <awol@example.com>' <<-\EOF |
| 2184 | alias alice "Alice W Land <awol@example.com>" |
| 2185 | alias eve "Eve <eve@example.com>" |
| 2186 | alias bob "Robert Bobbyton <bob@example.com>" |
| 2187 | alias chloe chloe@example.com |
| 2188 | EOF |
| 2189 | |
| 2190 | test_translate_aliases '--translate-aliases pine format' \ |
| 2191 | 'pine' \ |
| 2192 | 'eve bob bcgrp' \ |
| 2193 | 'eve@example.com' \ |
| 2194 | 'bob@example.com' \ |
| 2195 | 'bob@example.com' \ |
| 2196 | 'chloe@example.com' \ |
| 2197 | 'Other <o@example.com>' <<-\EOF |
| 2198 | alice Alice W Land awol@example.com Friend |
| 2199 | eve Eve eve@example.com |
| 2200 | bob Robert Bobbyton bob@example.com |
| 2201 | chloe chloe@example.com |
| 2202 | bcgrp (bob, chloe, Other <o@example.com>) |
| 2203 | EOF |
| 2204 | |
| 2205 | test_translate_aliases '--translate-aliases gnus format' \ |
| 2206 | 'gnus' \ |
| 2207 | 'alice chloe eve' \ |
| 2208 | 'awol@example.com' \ |
| 2209 | 'chloe@example.com' \ |
| 2210 | 'eve@example.com' <<-\EOF |
| 2211 | (define-mail-alias "alice" "awol@example.com") |
| 2212 | (define-mail-alias "eve" "eve@example.com") |
| 2213 | (define-mail-alias "bob" "bob@example.com") |
| 2214 | (define-mail-alias "chloe" "chloe@example.com") |
| 2215 | EOF |
| 2216 | |
| 2217 | test_expect_success $PREREQ '--translate-aliases passes valid addresses through' ' |
| 2218 | cat >expect <<-\EOF && |
| 2219 | Other <o@example.com> |
| 2220 | EOF |
| 2221 | cat >aliases <<-\EOF && |
| 2222 | Other <o@example.com> |
| 2223 | EOF |
| 2224 | git send-email --translate-aliases <aliases >actual && |
| 2225 | test_cmp expect actual |
| 2226 | ' |
| 2227 | |
| 2228 | test_expect_success $PREREQ '--translate-aliases passes unknown aliases through' ' |
| 2229 | cat >expect <<-\EOF && |
| 2230 | blargh |
| 2231 | EOF |
| 2232 | cat >aliases <<-\EOF && |
| 2233 | blargh |
| 2234 | EOF |
| 2235 | git send-email --translate-aliases <aliases >actual && |
| 2236 | test_cmp expect actual |
| 2237 | ' |
| 2238 | |
| 2239 | test_expect_success $PREREQ 'aliases and sendemail.identity' ' |
| 2240 | test_must_fail git \ |
| 2241 | -c sendemail.identity=cloud \ |
| 2242 | -c sendemail.aliasesfile=default-aliases \ |
| 2243 | -c sendemail.cloud.aliasesfile=cloud-aliases \ |
| 2244 | send-email -1 2>stderr && |
| 2245 | test_grep "cloud-aliases" stderr |
| 2246 | ' |
| 2247 | |
| 2248 | test_sendmail_aliases () { |
| 2249 | msg="$1" && shift && |
| 2250 | expect="$@" && |
| 2251 | cat >.tmp-email-aliases && |
| 2252 | |
| 2253 | test_expect_success $PREREQ "$msg" ' |
| 2254 | clean_fake_sendmail && rm -fr outdir && |
| 2255 | git format-patch -1 -o outdir && |
| 2256 | git config --replace-all sendemail.aliasesfile \ |
| 2257 | "$(pwd)/.tmp-email-aliases" && |
| 2258 | git config sendemail.aliasfiletype sendmail && |
| 2259 | git send-email \ |
| 2260 | --from="Example <nobody@example.com>" \ |
| 2261 | --to=alice --to=bcgrp \ |
| 2262 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2263 | outdir/0001-*.patch \ |
| 2264 | 2>errors >out && |
| 2265 | for i in $expect |
| 2266 | do |
| 2267 | grep "^!$i!$" commandline1 || return 1 |
| 2268 | done |
| 2269 | ' |
| 2270 | } |
| 2271 | |
| 2272 | test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \ |
| 2273 | 'awol@example\.com' \ |
| 2274 | 'bob@example\.com' \ |
| 2275 | 'chloe@example\.com' \ |
| 2276 | 'o@example\.com' <<-\EOF |
| 2277 | alice: Alice W Land <awol@example.com> |
| 2278 | bob: Robert Bobbyton <bob@example.com> |
| 2279 | # this is a comment |
| 2280 | # this is also a comment |
| 2281 | chloe: chloe@example.com |
| 2282 | abgroup: alice, bob |
| 2283 | bcgrp: bob, chloe, Other <o@example.com> |
| 2284 | EOF |
| 2285 | |
| 2286 | test_sendmail_aliases 'sendmail aliases line folding' \ |
| 2287 | alice1 \ |
| 2288 | bob1 bob2 \ |
| 2289 | chuck1 chuck2 \ |
| 2290 | darla1 darla2 darla3 \ |
| 2291 | elton1 elton2 elton3 \ |
| 2292 | fred1 fred2 \ |
| 2293 | greg1 <<-\EOF |
| 2294 | alice: alice1 |
| 2295 | bob: bob1,\ |
| 2296 | bob2 |
| 2297 | chuck: chuck1, |
| 2298 | chuck2 |
| 2299 | darla: darla1,\ |
| 2300 | darla2, |
| 2301 | darla3 |
| 2302 | elton: elton1, |
| 2303 | elton2,\ |
| 2304 | elton3 |
| 2305 | fred: fred1,\ |
| 2306 | fred2 |
| 2307 | greg: greg1 |
| 2308 | bcgrp: bob, chuck, darla, elton, fred, greg |
| 2309 | EOF |
| 2310 | |
| 2311 | test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \ |
| 2312 | alice1 bob1 <<-\EOF |
| 2313 | alice: alice1 |
| 2314 | bcgrp: bob1\ |
| 2315 | EOF |
| 2316 | |
| 2317 | test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF |
| 2318 | EOF |
| 2319 | |
| 2320 | test_expect_success $PREREQ 'alias support in To header' ' |
| 2321 | clean_fake_sendmail && |
| 2322 | echo "alias sbd someone@example.org" >.mailrc && |
| 2323 | test_config sendemail.aliasesfile ".mailrc" && |
| 2324 | test_config sendemail.aliasfiletype mailrc && |
| 2325 | git format-patch --stdout -1 --to=sbd >aliased.patch && |
| 2326 | git send-email \ |
| 2327 | --from="Example <nobody@example.com>" \ |
| 2328 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2329 | aliased.patch \ |
| 2330 | 2>errors >out && |
| 2331 | grep "^!someone@example\.org!$" commandline1 |
| 2332 | ' |
| 2333 | |
| 2334 | test_expect_success $PREREQ 'alias support in Cc header' ' |
| 2335 | clean_fake_sendmail && |
| 2336 | echo "alias sbd someone@example.org" >.mailrc && |
| 2337 | test_config sendemail.aliasesfile ".mailrc" && |
| 2338 | test_config sendemail.aliasfiletype mailrc && |
| 2339 | git format-patch --stdout -1 --cc=sbd >aliased.patch && |
| 2340 | git send-email \ |
| 2341 | --from="Example <nobody@example.com>" \ |
| 2342 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2343 | aliased.patch \ |
| 2344 | 2>errors >out && |
| 2345 | grep "^!someone@example\.org!$" commandline1 |
| 2346 | ' |
| 2347 | |
| 2348 | test_expect_success $PREREQ 'tocmd works with aliases' ' |
| 2349 | clean_fake_sendmail && |
| 2350 | echo "alias sbd someone@example.org" >.mailrc && |
| 2351 | test_config sendemail.aliasesfile ".mailrc" && |
| 2352 | test_config sendemail.aliasfiletype mailrc && |
| 2353 | git format-patch --stdout -1 >tocmd.patch && |
| 2354 | echo tocmd--sbd >>tocmd.patch && |
| 2355 | git send-email \ |
| 2356 | --from="Example <nobody@example.com>" \ |
| 2357 | --to-cmd=./tocmd-sed \ |
| 2358 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2359 | tocmd.patch \ |
| 2360 | 2>errors >out && |
| 2361 | grep "^!someone@example\.org!$" commandline1 |
| 2362 | ' |
| 2363 | |
| 2364 | test_expect_success $PREREQ 'cccmd works with aliases' ' |
| 2365 | clean_fake_sendmail && |
| 2366 | echo "alias sbd someone@example.org" >.mailrc && |
| 2367 | test_config sendemail.aliasesfile ".mailrc" && |
| 2368 | test_config sendemail.aliasfiletype mailrc && |
| 2369 | git format-patch --stdout -1 >cccmd.patch && |
| 2370 | echo cccmd--sbd >>cccmd.patch && |
| 2371 | git send-email \ |
| 2372 | --from="Example <nobody@example.com>" \ |
| 2373 | --cc-cmd=./cccmd-sed \ |
| 2374 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2375 | cccmd.patch \ |
| 2376 | 2>errors >out && |
| 2377 | grep "^!someone@example\.org!$" commandline1 |
| 2378 | ' |
| 2379 | |
| 2380 | do_xmailer_test () { |
| 2381 | expected=$1 params=$2 && |
| 2382 | git format-patch -1 && |
| 2383 | git send-email \ |
| 2384 | --from="Example <nobody@example.com>" \ |
| 2385 | --to=someone@example.com \ |
| 2386 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2387 | $params \ |
| 2388 | 0001-*.patch \ |
| 2389 | 2>errors >out && |
| 2390 | { grep '^X-Mailer:' out || :; } >mailer && |
| 2391 | test_line_count = $expected mailer |
| 2392 | } |
| 2393 | |
| 2394 | test_expect_success $PREREQ '--[no-]xmailer without any configuration' ' |
| 2395 | do_xmailer_test 1 "--xmailer" && |
| 2396 | do_xmailer_test 0 "--no-xmailer" |
| 2397 | ' |
| 2398 | |
| 2399 | test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' ' |
| 2400 | test_config sendemail.xmailer true && |
| 2401 | do_xmailer_test 1 "" && |
| 2402 | do_xmailer_test 0 "--no-xmailer" && |
| 2403 | do_xmailer_test 1 "--xmailer" |
| 2404 | ' |
| 2405 | |
| 2406 | test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer' ' |
| 2407 | test_when_finished "test_unconfig sendemail.xmailer" && |
| 2408 | cat >>.git/config <<-\EOF && |
| 2409 | [sendemail] |
| 2410 | xmailer |
| 2411 | EOF |
| 2412 | test_config sendemail.xmailer true && |
| 2413 | do_xmailer_test 1 "" && |
| 2414 | do_xmailer_test 0 "--no-xmailer" && |
| 2415 | do_xmailer_test 1 "--xmailer" |
| 2416 | ' |
| 2417 | |
| 2418 | test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' ' |
| 2419 | test_config sendemail.xmailer false && |
| 2420 | do_xmailer_test 0 "" && |
| 2421 | do_xmailer_test 0 "--no-xmailer" && |
| 2422 | do_xmailer_test 1 "--xmailer" |
| 2423 | ' |
| 2424 | |
| 2425 | test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' ' |
| 2426 | test_config sendemail.xmailer "" && |
| 2427 | do_xmailer_test 0 "" && |
| 2428 | do_xmailer_test 0 "--no-xmailer" && |
| 2429 | do_xmailer_test 1 "--xmailer" |
| 2430 | ' |
| 2431 | |
| 2432 | test_expect_success $PREREQ 'setup expected-list' ' |
| 2433 | git send-email \ |
| 2434 | --dry-run \ |
| 2435 | --from="Example <from@example.com>" \ |
| 2436 | --to="To 1 <to1@example.com>" \ |
| 2437 | --to="to2@example.com" \ |
| 2438 | --to="to3@example.com" \ |
| 2439 | --cc="Cc 1 <cc1@example.com>" \ |
| 2440 | --cc="Cc2 <cc2@example.com>" \ |
| 2441 | --bcc="bcc1@example.com" \ |
| 2442 | --bcc="bcc2@example.com" \ |
| 2443 | 0001-add-main.patch | replace_variable_fields \ |
| 2444 | >expected-list |
| 2445 | ' |
| 2446 | |
| 2447 | test_expect_success $PREREQ 'use email list in --cc --to and --bcc' ' |
| 2448 | git send-email \ |
| 2449 | --dry-run \ |
| 2450 | --from="Example <from@example.com>" \ |
| 2451 | --to="To 1 <to1@example.com>, to2@example.com" \ |
| 2452 | --to="to3@example.com" \ |
| 2453 | --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \ |
| 2454 | --bcc="bcc1@example.com, bcc2@example.com" \ |
| 2455 | 0001-add-main.patch | replace_variable_fields \ |
| 2456 | >actual-list && |
| 2457 | test_cmp expected-list actual-list |
| 2458 | ' |
| 2459 | |
| 2460 | test_expect_success $PREREQ 'aliases work with email list' ' |
| 2461 | echo "alias to2 to2@example.com" >.mutt && |
| 2462 | echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt && |
| 2463 | test_config sendemail.aliasesfile ".mutt" && |
| 2464 | test_config sendemail.aliasfiletype mutt && |
| 2465 | git send-email \ |
| 2466 | --dry-run \ |
| 2467 | --from="Example <from@example.com>" \ |
| 2468 | --to="To 1 <to1@example.com>, to2, to3@example.com" \ |
| 2469 | --cc="cc1, Cc2 <cc2@example.com>" \ |
| 2470 | --bcc="bcc1@example.com, bcc2@example.com" \ |
| 2471 | 0001-add-main.patch | replace_variable_fields \ |
| 2472 | >actual-list && |
| 2473 | test_cmp expected-list actual-list |
| 2474 | ' |
| 2475 | |
| 2476 | test_expect_success $PREREQ 'leading and trailing whitespaces are removed' ' |
| 2477 | echo "alias to2 to2@example.com" >.mutt && |
| 2478 | echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt && |
| 2479 | test_config sendemail.aliasesfile ".mutt" && |
| 2480 | test_config sendemail.aliasfiletype mutt && |
| 2481 | TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) && |
| 2482 | TO2=$(echo "QZto2" | qz_to_tab_space) && |
| 2483 | CC1=$(echo "cc1" | append_cr) && |
| 2484 | BCC1=$(echo " bcc1@example.com Q" | q_to_nul) && |
| 2485 | git send-email \ |
| 2486 | --dry-run \ |
| 2487 | --from=" Example <from@example.com>" \ |
| 2488 | --to="$TO1" \ |
| 2489 | --to="$TO2" \ |
| 2490 | --to=" to3@example.com " \ |
| 2491 | --cc="$CC1" \ |
| 2492 | --cc="Cc2 <cc2@example.com>" \ |
| 2493 | --bcc="$BCC1" \ |
| 2494 | --bcc="bcc2@example.com" \ |
| 2495 | 0001-add-main.patch | replace_variable_fields \ |
| 2496 | >actual-list && |
| 2497 | test_cmp expected-list actual-list |
| 2498 | ' |
| 2499 | |
| 2500 | test_expect_success $PREREQ 'mailmap support with --to' ' |
| 2501 | clean_fake_sendmail && |
| 2502 | test_config mailmap.file "mailmap.test" && |
| 2503 | cat >mailmap.test <<-EOF && |
| 2504 | Some Body <someone@example.com> <someone@example.org> |
| 2505 | EOF |
| 2506 | git format-patch --stdout -1 >a.patch && |
| 2507 | git send-email \ |
| 2508 | --from="Example <nobody@example.com>" \ |
| 2509 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2510 | --to=someone@example.org \ |
| 2511 | --mailmap \ |
| 2512 | a.patch \ |
| 2513 | 2>errors >out && |
| 2514 | grep "^!someone@example\.com!$" commandline1 |
| 2515 | ' |
| 2516 | |
| 2517 | test_expect_success $PREREQ 'sendemail.mailmap configuration' ' |
| 2518 | clean_fake_sendmail && |
| 2519 | test_config mailmap.file "mailmap.test" && |
| 2520 | test_config sendemail.mailmap "true" && |
| 2521 | cat >mailmap.test <<-EOF && |
| 2522 | Some Body <someone@example.com> <someone@example.org> |
| 2523 | EOF |
| 2524 | git format-patch --stdout -1 >a.patch && |
| 2525 | git send-email \ |
| 2526 | --from="Example <nobody@example.com>" \ |
| 2527 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2528 | --to=someone@example.org \ |
| 2529 | a.patch \ |
| 2530 | 2>errors >out && |
| 2531 | grep "^!someone@example\.com!$" commandline1 |
| 2532 | ' |
| 2533 | |
| 2534 | test_expect_success $PREREQ 'sendemail.mailmap.file configuration' ' |
| 2535 | clean_fake_sendmail && |
| 2536 | test_config sendemail.mailmap.file "mailmap.test" && |
| 2537 | test_config sendemail.mailmap "true" && |
| 2538 | cat >mailmap.test <<-EOF && |
| 2539 | Some Body <someone@example.com> <someone@example.org> |
| 2540 | EOF |
| 2541 | git format-patch --stdout -1 >a.patch && |
| 2542 | git send-email \ |
| 2543 | --from="Example <nobody@example.com>" \ |
| 2544 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2545 | --to=someone@example.org \ |
| 2546 | a.patch \ |
| 2547 | 2>errors >out && |
| 2548 | grep "^!someone@example\.com!$" commandline1 |
| 2549 | ' |
| 2550 | |
| 2551 | test_expect_success $PREREQ 'sendemail.mailmap identity overrides configuration' ' |
| 2552 | clean_fake_sendmail && |
| 2553 | test_config sendemail.cloud.mailmap.file "mailmap.test" && |
| 2554 | test_config sendemail.mailmap "false" && |
| 2555 | test_config sendemail.cloud.mailmap "true" && |
| 2556 | cat >mailmap.test <<-EOF && |
| 2557 | Some Body <someone@example.com> <someone@example.org> |
| 2558 | EOF |
| 2559 | git format-patch --stdout -1 >a.patch && |
| 2560 | git send-email \ |
| 2561 | --from="Example <nobody@example.com>" \ |
| 2562 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2563 | --identity=cloud \ |
| 2564 | --to=someone@example.org \ |
| 2565 | a.patch \ |
| 2566 | 2>errors >out && |
| 2567 | grep "^!someone@example\.com!$" commandline1 |
| 2568 | ' |
| 2569 | |
| 2570 | test_expect_success $PREREQ '--no-mailmap overrides configuration' ' |
| 2571 | clean_fake_sendmail && |
| 2572 | test_config sendemail.cloud.mailmap.file "mailmap.test" && |
| 2573 | test_config sendemail.mailmap "false" && |
| 2574 | test_config sendemail.cloud.mailmap "true" && |
| 2575 | cat >mailmap.test <<-EOF && |
| 2576 | Some Body <someone@example.com> <someone@example.org> |
| 2577 | EOF |
| 2578 | git format-patch --stdout -1 >a.patch && |
| 2579 | git send-email \ |
| 2580 | --from="Example <nobody@example.com>" \ |
| 2581 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2582 | --identity=cloud \ |
| 2583 | --to=someone@example.org \ |
| 2584 | --no-mailmap \ |
| 2585 | a.patch \ |
| 2586 | 2>errors >out && |
| 2587 | grep "^!someone@example\.org!$" commandline1 |
| 2588 | ' |
| 2589 | |
| 2590 | test_expect_success $PREREQ 'mailmap support in To header' ' |
| 2591 | clean_fake_sendmail && |
| 2592 | test_config mailmap.file "mailmap.test" && |
| 2593 | cat >mailmap.test <<-EOF && |
| 2594 | <someone@example.com> <someone@example.org> |
| 2595 | EOF |
| 2596 | git format-patch --stdout -1 --to=someone@example.org >a.patch && |
| 2597 | git send-email \ |
| 2598 | --from="Example <nobody@example.com>" \ |
| 2599 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2600 | --mailmap \ |
| 2601 | a.patch \ |
| 2602 | 2>errors >out && |
| 2603 | grep "^!someone@example\.com!$" commandline1 |
| 2604 | ' |
| 2605 | |
| 2606 | test_expect_success $PREREQ 'mailmap support in Cc header' ' |
| 2607 | clean_fake_sendmail && |
| 2608 | test_config mailmap.file "mailmap.test" && |
| 2609 | cat >mailmap.test <<-EOF && |
| 2610 | <someone@example.com> <someone@example.org> |
| 2611 | EOF |
| 2612 | git format-patch --stdout -1 --cc=someone@example.org >a.patch && |
| 2613 | git send-email \ |
| 2614 | --from="Example <nobody@example.com>" \ |
| 2615 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2616 | --mailmap \ |
| 2617 | a.patch \ |
| 2618 | 2>errors >out && |
| 2619 | grep "^!someone@example\.com!$" commandline1 |
| 2620 | ' |
| 2621 | |
| 2622 | test_expect_success $PREREQ 'test using command name with --sendmail-cmd' ' |
| 2623 | clean_fake_sendmail && |
| 2624 | PATH="$PWD:$PATH" \ |
| 2625 | git send-email \ |
| 2626 | --from="Example <nobody@example.com>" \ |
| 2627 | --to=nobody@example.com \ |
| 2628 | --sendmail-cmd="fake.sendmail" \ |
| 2629 | HEAD^ && |
| 2630 | test_path_is_file commandline1 |
| 2631 | ' |
| 2632 | |
| 2633 | test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' ' |
| 2634 | clean_fake_sendmail && |
| 2635 | git send-email \ |
| 2636 | --from="Example <nobody@example.com>" \ |
| 2637 | --to=nobody@example.com \ |
| 2638 | --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \ |
| 2639 | HEAD^ && |
| 2640 | test_path_is_file commandline1 |
| 2641 | ' |
| 2642 | |
| 2643 | test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' ' |
| 2644 | clean_fake_sendmail && |
| 2645 | git send-email \ |
| 2646 | --from="Example <nobody@example.com>" \ |
| 2647 | --to=nobody@example.com \ |
| 2648 | --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \ |
| 2649 | HEAD^ && |
| 2650 | test_path_is_file commandline1 |
| 2651 | ' |
| 2652 | |
| 2653 | test_expect_success $PREREQ 'set up in-reply-to/references patches' ' |
| 2654 | cat >has-reply.patch <<-\EOF && |
| 2655 | From: A U Thor <author@example.com> |
| 2656 | Subject: patch with in-reply-to |
| 2657 | Message-ID: <patch.with.in.reply.to@example.com> |
| 2658 | In-Reply-To: <replied.to@example.com> |
| 2659 | References: <replied.to@example.com> |
| 2660 | |
| 2661 | This is the body. |
| 2662 | EOF |
| 2663 | cat >no-reply.patch <<-\EOF |
| 2664 | From: A U Thor <author@example.com> |
| 2665 | Subject: patch without in-reply-to |
| 2666 | Message-ID: <patch.without.in.reply.to@example.com> |
| 2667 | |
| 2668 | This is the body. |
| 2669 | EOF |
| 2670 | ' |
| 2671 | |
| 2672 | test_expect_success $PREREQ 'patch reply headers correct with --no-thread' ' |
| 2673 | clean_fake_sendmail && |
| 2674 | git send-email \ |
| 2675 | --no-thread \ |
| 2676 | --to=nobody@example.com \ |
| 2677 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2678 | has-reply.patch no-reply.patch && |
| 2679 | grep "In-Reply-To: <replied.to@example.com>" msgtxt1 && |
| 2680 | grep "References: <replied.to@example.com>" msgtxt1 && |
| 2681 | ! grep replied.to@example.com msgtxt2 |
| 2682 | ' |
| 2683 | |
| 2684 | test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' ' |
| 2685 | clean_fake_sendmail && |
| 2686 | git send-email \ |
| 2687 | --no-thread \ |
| 2688 | --in-reply-to="<cmdline.reply@example.com>" \ |
| 2689 | --to=nobody@example.com \ |
| 2690 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2691 | has-reply.patch no-reply.patch && |
| 2692 | grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 && |
| 2693 | grep "References: <cmdline.reply@example.com>" msgtxt1 && |
| 2694 | grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 && |
| 2695 | grep "References: <cmdline.reply@example.com>" msgtxt2 |
| 2696 | ' |
| 2697 | |
| 2698 | test_expect_success $PREREQ 'invoke hook' ' |
| 2699 | test_hook sendemail-validate <<-\EOF && |
| 2700 | # test that we have the correct environment variable, pwd, and |
| 2701 | # argument |
| 2702 | case "$GIT_DIR" in |
| 2703 | *.git) |
| 2704 | true |
| 2705 | ;; |
| 2706 | *) |
| 2707 | false |
| 2708 | ;; |
| 2709 | esac && |
| 2710 | test -f 0001-add-main.patch && |
| 2711 | grep "add main" "$1" |
| 2712 | EOF |
| 2713 | |
| 2714 | mkdir subdir && |
| 2715 | ( |
| 2716 | # Test that it works even if we are not at the root of the |
| 2717 | # working tree |
| 2718 | cd subdir && |
| 2719 | git send-email \ |
| 2720 | --from="Example <nobody@example.com>" \ |
| 2721 | --to=nobody@example.com \ |
| 2722 | --smtp-server="$(pwd)/../fake.sendmail" \ |
| 2723 | ../0001-add-main.patch && |
| 2724 | |
| 2725 | # Verify error message when a patch is rejected by the hook |
| 2726 | sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch && |
| 2727 | test_must_fail git send-email \ |
| 2728 | --from="Example <nobody@example.com>" \ |
| 2729 | --to=nobody@example.com \ |
| 2730 | --smtp-server="$(pwd)/../fake.sendmail" \ |
| 2731 | ../another.patch 2>err && |
| 2732 | test_grep "rejected by sendemail-validate hook" err |
| 2733 | ) |
| 2734 | ' |
| 2735 | |
| 2736 | expected_file_counter_output () { |
| 2737 | total=$1 |
| 2738 | count=0 |
| 2739 | while test $count -ne $total |
| 2740 | do |
| 2741 | count=$((count + 1)) && |
| 2742 | echo "$count/$total" || return |
| 2743 | done |
| 2744 | } |
| 2745 | |
| 2746 | test_expect_success $PREREQ '--validate hook allows counting of messages' ' |
| 2747 | test_when_finished "rm -rf my-hooks.log" && |
| 2748 | test_config core.hooksPath "my-hooks" && |
| 2749 | mkdir -p my-hooks && |
| 2750 | |
| 2751 | write_script my-hooks/sendemail-validate <<-\EOF && |
| 2752 | num=$GIT_SENDEMAIL_FILE_COUNTER && |
| 2753 | tot=$GIT_SENDEMAIL_FILE_TOTAL && |
| 2754 | echo "$num/$tot" >>my-hooks.log || exit 1 |
| 2755 | EOF |
| 2756 | |
| 2757 | >my-hooks.log && |
| 2758 | expected_file_counter_output 4 >expect && |
| 2759 | git send-email \ |
| 2760 | --from="Example <from@example.com>" \ |
| 2761 | --to=nobody@example.com \ |
| 2762 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2763 | --validate -3 --cover-letter --force && |
| 2764 | test_cmp expect my-hooks.log |
| 2765 | ' |
| 2766 | |
| 2767 | test_expect_success $PREREQ 'test that send-email works outside a repo' ' |
| 2768 | nongit git send-email \ |
| 2769 | --from="Example <nobody@example.com>" \ |
| 2770 | --to=nobody@example.com \ |
| 2771 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2772 | "$(pwd)/0001-add-main.patch" |
| 2773 | ' |
| 2774 | |
| 2775 | test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' ' |
| 2776 | test_when_finished "rm -f out" && |
| 2777 | git send-email --dry-run -v 3 -1 >out && |
| 2778 | grep "PATCH v3" out |
| 2779 | ' |
| 2780 | |
| 2781 | test_expect_success $PREREQ 'test that sendmail config is rejected' ' |
| 2782 | test_config sendmail.program sendmail && |
| 2783 | test_must_fail git send-email \ |
| 2784 | --from="Example <nobody@example.com>" \ |
| 2785 | --to=nobody@example.com \ |
| 2786 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2787 | HEAD^ 2>err && |
| 2788 | test_grep "found configuration options for '"'"sendmail"'"'" err |
| 2789 | ' |
| 2790 | |
| 2791 | test_expect_success $PREREQ 'test that sendmail config rejection is specific' ' |
| 2792 | test_config resendmail.program sendmail && |
| 2793 | git send-email \ |
| 2794 | --from="Example <nobody@example.com>" \ |
| 2795 | --to=nobody@example.com \ |
| 2796 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2797 | HEAD^ |
| 2798 | ' |
| 2799 | |
| 2800 | test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' ' |
| 2801 | test_config sendmail.program sendmail && |
| 2802 | test_config sendemail.forbidSendmailVariables false && |
| 2803 | git send-email \ |
| 2804 | --from="Example <nobody@example.com>" \ |
| 2805 | --to=nobody@example.com \ |
| 2806 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2807 | HEAD^ |
| 2808 | ' |
| 2809 | |
| 2810 | test_expect_success $PREREQ '--compose handles lowercase headers' ' |
| 2811 | write_script fake-editor <<-\EOF && |
| 2812 | sed "s/^[Ff][Rr][Oo][Mm]:.*/from: edited-from@example.com/" "$1" >"$1.tmp" && |
| 2813 | mv "$1.tmp" "$1" |
| 2814 | EOF |
| 2815 | clean_fake_sendmail && |
| 2816 | git send-email \ |
| 2817 | --compose \ |
| 2818 | --from="Example <from@example.com>" \ |
| 2819 | --to=nobody@example.com \ |
| 2820 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2821 | HEAD^ && |
| 2822 | grep "From: edited-from@example.com" msgtxt1 |
| 2823 | ' |
| 2824 | |
| 2825 | test_expect_success $PREREQ '--compose handles to headers' ' |
| 2826 | write_script fake-editor <<-\EOF && |
| 2827 | sed "s/^To: .*/&, edited-to@example.com/" <"$1" >"$1.tmp" && |
| 2828 | echo this is the body >>"$1.tmp" && |
| 2829 | mv "$1.tmp" "$1" |
| 2830 | EOF |
| 2831 | clean_fake_sendmail && |
| 2832 | GIT_SEND_EMAIL_NOTTY=1 \ |
| 2833 | git send-email \ |
| 2834 | --compose \ |
| 2835 | --from="Example <from@example.com>" \ |
| 2836 | --to=nobody@example.com \ |
| 2837 | --smtp-server="$(pwd)/fake.sendmail" \ |
| 2838 | HEAD^ && |
| 2839 | # Check both that the cover letter used our modified "to" line, |
| 2840 | # but also that it was picked up for the patch. |
| 2841 | q_to_tab >expect <<-\EOF && |
| 2842 | To: nobody@example.com, |
| 2843 | Qedited-to@example.com |
| 2844 | EOF |
| 2845 | grep -A1 "^To:" msgtxt1 >msgtxt1.to && |
| 2846 | test_cmp expect msgtxt1.to && |
| 2847 | grep -A1 "^To:" msgtxt2 >msgtxt2.to && |
| 2848 | test_cmp expect msgtxt2.to |
| 2849 | ' |
| 2850 | |
| 2851 | test_done |