]>
Commit | Line | Data |
---|---|---|
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 -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_success $PREREQ 'setup expect' " | |
205 | cat >expected-show-all-headers <<\EOF | |
206 | 0001-Second.patch | |
207 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
208 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
209 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
210 | Dry-OK. Log says: | |
211 | Server: relay.example.com | |
212 | MAIL FROM:<from@example.com> | |
213 | RCPT TO:<to@example.com> | |
214 | RCPT TO:<cc@example.com> | |
215 | RCPT TO:<author@example.com> | |
216 | RCPT TO:<one@example.com> | |
217 | RCPT TO:<two@example.com> | |
218 | RCPT TO:<bcc@example.com> | |
219 | From: Example <from@example.com> | |
220 | To: to@example.com | |
221 | Cc: cc@example.com, | |
222 | A <author@example.com>, | |
223 | One <one@example.com>, | |
224 | two@example.com | |
225 | Subject: [PATCH 1/1] Second. | |
226 | Date: DATE-STRING | |
227 | Message-Id: MESSAGE-ID-STRING | |
228 | X-Mailer: X-MAILER-STRING | |
229 | In-Reply-To: <unique-message-id@example.com> | |
230 | References: <unique-message-id@example.com> | |
231 | Reply-To: Reply <reply@example.com> | |
232 | MIME-Version: 1.0 | |
233 | Content-Transfer-Encoding: 8bit | |
234 | ||
235 | Result: OK | |
236 | EOF | |
237 | " | |
238 | ||
239 | test_suppress_self () { | |
240 | test_commit $3 && | |
241 | test_when_finished "git reset --hard HEAD^" && | |
242 | ||
243 | write_script cccmd-sed <<-EOF && | |
244 | sed -n -e s/^cccmd--//p "\$1" | |
245 | EOF | |
246 | ||
247 | git commit --amend --author="$1 <$2>" -F - && | |
248 | clean_fake_sendmail && | |
249 | git format-patch --stdout -1 >"suppress-self-$3.patch" && | |
250 | ||
251 | git send-email --from="$1 <$2>" \ | |
252 | --to=nobody@example.com \ | |
253 | --cc-cmd=./cccmd-sed \ | |
254 | --suppress-cc=self \ | |
255 | --smtp-server="$(pwd)/fake.sendmail" \ | |
256 | suppress-self-$3.patch && | |
257 | ||
258 | mv msgtxt1 msgtxt1-$3 && | |
259 | sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" && | |
260 | ||
261 | (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3"; | |
262 | test_must_be_empty actual-no-cc-$3) | |
263 | } | |
264 | ||
265 | test_suppress_self_unquoted () { | |
266 | test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF | |
267 | test suppress-cc.self unquoted-$3 with name $1 email $2 | |
268 | ||
269 | unquoted-$3 | |
270 | ||
271 | cccmd--$1 <$2> | |
272 | ||
273 | Cc: $1 <$2> | |
274 | Signed-off-by: $1 <$2> | |
275 | EOF | |
276 | } | |
277 | ||
278 | test_suppress_self_quoted () { | |
279 | test_suppress_self "$1" "$2" "quoted-$3" <<-EOF | |
280 | test suppress-cc.self quoted-$3 with name $1 email $2 | |
281 | ||
282 | quoted-$3 | |
283 | ||
284 | cccmd--"$1" <$2> | |
285 | ||
286 | Cc: $1 <$2> | |
287 | Cc: "$1" <$2> | |
288 | Signed-off-by: $1 <$2> | |
289 | Signed-off-by: "$1" <$2> | |
290 | EOF | |
291 | } | |
292 | ||
293 | test_expect_success $PREREQ 'self name is suppressed' " | |
294 | test_suppress_self_unquoted 'A U Thor' 'author@example.com' \ | |
295 | 'self_name_suppressed' | |
296 | " | |
297 | ||
298 | test_expect_success $PREREQ 'self name with dot is suppressed' " | |
299 | test_suppress_self_quoted 'A U. Thor' 'author@example.com' \ | |
300 | 'self_name_dot_suppressed' | |
301 | " | |
302 | ||
303 | test_expect_success $PREREQ 'non-ascii self name is suppressed' " | |
304 | test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \ | |
305 | 'non_ascii_self_suppressed' | |
306 | " | |
307 | ||
308 | # This name is long enough to force format-patch to split it into multiple | |
309 | # encoded-words, assuming it uses UTF-8 with the "Q" encoding. | |
310 | test_expect_success $PREREQ 'long non-ascii self name is suppressed' " | |
311 | test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \ | |
312 | 'long_non_ascii_self_suppressed' | |
313 | " | |
314 | ||
315 | test_expect_success $PREREQ 'sanitized self name is suppressed' " | |
316 | test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \ | |
317 | 'self_name_sanitized_suppressed' | |
318 | " | |
319 | ||
320 | test_expect_success $PREREQ 'Show all headers' ' | |
321 | git send-email \ | |
322 | --dry-run \ | |
323 | --suppress-cc=sob \ | |
324 | --from="Example <from@example.com>" \ | |
325 | --reply-to="Reply <reply@example.com>" \ | |
326 | --to=to@example.com \ | |
327 | --cc=cc@example.com \ | |
328 | --bcc=bcc@example.com \ | |
329 | --in-reply-to="<unique-message-id@example.com>" \ | |
330 | --smtp-server relay.example.com \ | |
331 | $patches | replace_variable_fields \ | |
332 | >actual-show-all-headers && | |
333 | test_cmp expected-show-all-headers actual-show-all-headers | |
334 | ' | |
335 | ||
336 | test_expect_success $PREREQ 'Prompting works' ' | |
337 | clean_fake_sendmail && | |
338 | (echo "to@example.com" && | |
339 | echo "" | |
340 | ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \ | |
341 | --smtp-server="$(pwd)/fake.sendmail" \ | |
342 | $patches \ | |
343 | 2>errors && | |
344 | grep "^From: A U Thor <author@example.com>\$" msgtxt1 && | |
345 | grep "^To: to@example.com\$" msgtxt1 | |
346 | ' | |
347 | ||
348 | test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' ' | |
349 | clean_fake_sendmail && | |
350 | (sane_unset GIT_AUTHOR_NAME && | |
351 | sane_unset GIT_AUTHOR_EMAIL && | |
352 | sane_unset GIT_COMMITTER_NAME && | |
353 | sane_unset GIT_COMMITTER_EMAIL && | |
354 | GIT_SEND_EMAIL_NOTTY=1 git send-email \ | |
355 | --smtp-server="$(pwd)/fake.sendmail" \ | |
356 | --to=to@example.com \ | |
357 | $patches </dev/null 2>errors | |
358 | ) | |
359 | ' | |
360 | ||
361 | test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' ' | |
362 | clean_fake_sendmail && | |
363 | (sane_unset GIT_AUTHOR_NAME && | |
364 | sane_unset GIT_AUTHOR_EMAIL && | |
365 | sane_unset GIT_COMMITTER_NAME && | |
366 | sane_unset GIT_COMMITTER_EMAIL && | |
367 | GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY && | |
368 | test_must_fail git send-email \ | |
369 | --smtp-server="$(pwd)/fake.sendmail" \ | |
370 | --to=to@example.com \ | |
371 | $patches </dev/null 2>errors && | |
372 | test_i18ngrep "tell me who you are" errors | |
373 | ) | |
374 | ' | |
375 | ||
376 | test_expect_success $PREREQ 'setup tocmd and cccmd scripts' ' | |
377 | write_script tocmd-sed <<-\EOF && | |
378 | sed -n -e "s/^tocmd--//p" "$1" | |
379 | EOF | |
380 | write_script cccmd-sed <<-\EOF | |
381 | sed -n -e "s/^cccmd--//p" "$1" | |
382 | EOF | |
383 | ' | |
384 | ||
385 | test_expect_success $PREREQ 'tocmd works' ' | |
386 | clean_fake_sendmail && | |
387 | cp $patches tocmd.patch && | |
388 | echo tocmd--tocmd@example.com >>tocmd.patch && | |
389 | git send-email \ | |
390 | --from="Example <nobody@example.com>" \ | |
391 | --to-cmd=./tocmd-sed \ | |
392 | --smtp-server="$(pwd)/fake.sendmail" \ | |
393 | tocmd.patch \ | |
394 | && | |
395 | grep "^To: tocmd@example.com" msgtxt1 | |
396 | ' | |
397 | ||
398 | test_expect_success $PREREQ 'cccmd works' ' | |
399 | clean_fake_sendmail && | |
400 | cp $patches cccmd.patch && | |
401 | echo "cccmd-- cccmd@example.com" >>cccmd.patch && | |
402 | git send-email \ | |
403 | --from="Example <nobody@example.com>" \ | |
404 | --to=nobody@example.com \ | |
405 | --cc-cmd=./cccmd-sed \ | |
406 | --smtp-server="$(pwd)/fake.sendmail" \ | |
407 | cccmd.patch \ | |
408 | && | |
409 | grep "^ cccmd@example.com" msgtxt1 | |
410 | ' | |
411 | ||
412 | test_expect_success $PREREQ 'reject long lines' ' | |
413 | z8=zzzzzzzz && | |
414 | z64=$z8$z8$z8$z8$z8$z8$z8$z8 && | |
415 | z512=$z64$z64$z64$z64$z64$z64$z64$z64 && | |
416 | clean_fake_sendmail && | |
417 | cp $patches longline.patch && | |
418 | echo $z512$z512 >>longline.patch && | |
419 | test_must_fail git send-email \ | |
420 | --from="Example <nobody@example.com>" \ | |
421 | --to=nobody@example.com \ | |
422 | --smtp-server="$(pwd)/fake.sendmail" \ | |
423 | --transfer-encoding=8bit \ | |
424 | $patches longline.patch \ | |
425 | 2>actual && | |
426 | cat >expect <<-\EOF && | |
427 | fatal: longline.patch: 35: patch contains a line longer than 998 characters | |
428 | warning: no patches were sent | |
429 | EOF | |
430 | test_cmp expect actual | |
431 | ' | |
432 | ||
433 | test_expect_success $PREREQ 'no patch was sent' ' | |
434 | ! test -e commandline1 | |
435 | ' | |
436 | ||
437 | test_expect_success $PREREQ 'Author From: in message body' ' | |
438 | clean_fake_sendmail && | |
439 | git send-email \ | |
440 | --from="Example <nobody@example.com>" \ | |
441 | --to=nobody@example.com \ | |
442 | --smtp-server="$(pwd)/fake.sendmail" \ | |
443 | $patches && | |
444 | sed "1,/^\$/d" <msgtxt1 >msgbody1 && | |
445 | grep "From: A <author@example.com>" msgbody1 | |
446 | ' | |
447 | ||
448 | test_expect_success $PREREQ 'Author From: not in message body' ' | |
449 | clean_fake_sendmail && | |
450 | git send-email \ | |
451 | --from="A <author@example.com>" \ | |
452 | --to=nobody@example.com \ | |
453 | --smtp-server="$(pwd)/fake.sendmail" \ | |
454 | $patches && | |
455 | sed "1,/^\$/d" <msgtxt1 >msgbody1 && | |
456 | ! grep "From: A <author@example.com>" msgbody1 | |
457 | ' | |
458 | ||
459 | test_expect_success $PREREQ 'allow long lines with --no-validate' ' | |
460 | git send-email \ | |
461 | --from="Example <nobody@example.com>" \ | |
462 | --to=nobody@example.com \ | |
463 | --smtp-server="$(pwd)/fake.sendmail" \ | |
464 | --no-validate \ | |
465 | $patches longline.patch \ | |
466 | 2>errors | |
467 | ' | |
468 | ||
469 | test_expect_success $PREREQ 'short lines with auto encoding are 8bit' ' | |
470 | clean_fake_sendmail && | |
471 | git send-email \ | |
472 | --from="A <author@example.com>" \ | |
473 | --to=nobody@example.com \ | |
474 | --smtp-server="$(pwd)/fake.sendmail" \ | |
475 | --transfer-encoding=auto \ | |
476 | $patches && | |
477 | grep "Content-Transfer-Encoding: 8bit" msgtxt1 | |
478 | ' | |
479 | ||
480 | test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' ' | |
481 | clean_fake_sendmail && | |
482 | git send-email \ | |
483 | --from="Example <nobody@example.com>" \ | |
484 | --to=nobody@example.com \ | |
485 | --smtp-server="$(pwd)/fake.sendmail" \ | |
486 | --transfer-encoding=auto \ | |
487 | --no-validate \ | |
488 | longline.patch && | |
489 | grep "Content-Transfer-Encoding: quoted-printable" msgtxt1 | |
490 | ' | |
491 | ||
492 | test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' ' | |
493 | clean_fake_sendmail && | |
494 | cp $patches cr.patch && | |
495 | printf "this is a line\r\n" >>cr.patch && | |
496 | git send-email \ | |
497 | --from="Example <nobody@example.com>" \ | |
498 | --to=nobody@example.com \ | |
499 | --smtp-server="$(pwd)/fake.sendmail" \ | |
500 | --transfer-encoding=auto \ | |
501 | --no-validate \ | |
502 | cr.patch && | |
503 | grep "Content-Transfer-Encoding: quoted-printable" msgtxt1 | |
504 | ' | |
505 | ||
506 | for enc in auto quoted-printable base64 | |
507 | do | |
508 | test_expect_success $PREREQ "--validate passes with encoding $enc" ' | |
509 | git send-email \ | |
510 | --from="Example <nobody@example.com>" \ | |
511 | --to=nobody@example.com \ | |
512 | --smtp-server="$(pwd)/fake.sendmail" \ | |
513 | --transfer-encoding=$enc \ | |
514 | --validate \ | |
515 | $patches longline.patch | |
516 | ' | |
517 | ||
518 | done | |
519 | ||
520 | test_expect_success $PREREQ "--validate respects relative core.hooksPath path" ' | |
521 | clean_fake_sendmail && | |
522 | mkdir my-hooks && | |
523 | test_when_finished "rm my-hooks.ran" && | |
524 | write_script my-hooks/sendemail-validate <<-\EOF && | |
525 | >my-hooks.ran | |
526 | exit 1 | |
527 | EOF | |
528 | test_config core.hooksPath "my-hooks" && | |
529 | test_must_fail git send-email \ | |
530 | --from="Example <nobody@example.com>" \ | |
531 | --to=nobody@example.com \ | |
532 | --smtp-server="$(pwd)/fake.sendmail" \ | |
533 | --validate \ | |
534 | longline.patch 2>actual && | |
535 | test_path_is_file my-hooks.ran && | |
536 | cat >expect <<-\EOF && | |
537 | fatal: longline.patch: rejected by sendemail-validate hook | |
538 | warning: no patches were sent | |
539 | EOF | |
540 | test_cmp expect actual | |
541 | ' | |
542 | ||
543 | test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" ' | |
544 | test_config core.hooksPath "$(pwd)/my-hooks" && | |
545 | test_when_finished "rm my-hooks.ran" && | |
546 | test_must_fail git send-email \ | |
547 | --from="Example <nobody@example.com>" \ | |
548 | --to=nobody@example.com \ | |
549 | --smtp-server="$(pwd)/fake.sendmail" \ | |
550 | --validate \ | |
551 | longline.patch 2>actual && | |
552 | test_path_is_file my-hooks.ran && | |
553 | cat >expect <<-\EOF && | |
554 | fatal: longline.patch: rejected by sendemail-validate hook | |
555 | warning: no patches were sent | |
556 | EOF | |
557 | test_cmp expect actual | |
558 | ' | |
559 | ||
560 | for enc in 7bit 8bit quoted-printable base64 | |
561 | do | |
562 | test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" ' | |
563 | clean_fake_sendmail && | |
564 | git send-email \ | |
565 | --from="Example <nobody@example.com>" \ | |
566 | --to=nobody@example.com \ | |
567 | --smtp-server="$(pwd)/fake.sendmail" \ | |
568 | --transfer-encoding=$enc \ | |
569 | $patches && | |
570 | grep "Content-Transfer-Encoding: $enc" msgtxt1 | |
571 | ' | |
572 | done | |
573 | ||
574 | test_expect_success $PREREQ 'Invalid In-Reply-To' ' | |
575 | clean_fake_sendmail && | |
576 | git send-email \ | |
577 | --from="Example <nobody@example.com>" \ | |
578 | --to=nobody@example.com \ | |
579 | --in-reply-to=" " \ | |
580 | --smtp-server="$(pwd)/fake.sendmail" \ | |
581 | $patches \ | |
582 | 2>errors && | |
583 | ! grep "^In-Reply-To: < *>" msgtxt1 | |
584 | ' | |
585 | ||
586 | test_expect_success $PREREQ 'Valid In-Reply-To when prompting' ' | |
587 | clean_fake_sendmail && | |
588 | (echo "From Example <from@example.com>" && | |
589 | echo "To Example <to@example.com>" && | |
590 | echo "" | |
591 | ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \ | |
592 | --smtp-server="$(pwd)/fake.sendmail" \ | |
593 | $patches 2>errors && | |
594 | ! grep "^In-Reply-To: < *>" msgtxt1 | |
595 | ' | |
596 | ||
597 | test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' ' | |
598 | clean_fake_sendmail && | |
599 | echo "<unique-message-id@example.com>" >expect && | |
600 | git send-email \ | |
601 | --from="Example <nobody@example.com>" \ | |
602 | --to=nobody@example.com \ | |
603 | --no-chain-reply-to \ | |
604 | --in-reply-to="$(cat expect)" \ | |
605 | --smtp-server="$(pwd)/fake.sendmail" \ | |
606 | $patches $patches $patches \ | |
607 | 2>errors && | |
608 | # The first message is a reply to --in-reply-to | |
609 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && | |
610 | test_cmp expect actual && | |
611 | # Second and subsequent messages are replies to the first one | |
612 | sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect && | |
613 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual && | |
614 | test_cmp expect actual && | |
615 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual && | |
616 | test_cmp expect actual | |
617 | ' | |
618 | ||
619 | test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' | |
620 | clean_fake_sendmail && | |
621 | echo "<unique-message-id@example.com>" >expect && | |
622 | git send-email \ | |
623 | --from="Example <nobody@example.com>" \ | |
624 | --to=nobody@example.com \ | |
625 | --chain-reply-to \ | |
626 | --in-reply-to="$(cat expect)" \ | |
627 | --smtp-server="$(pwd)/fake.sendmail" \ | |
628 | $patches $patches $patches \ | |
629 | 2>errors && | |
630 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && | |
631 | test_cmp expect actual && | |
632 | sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect && | |
633 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual && | |
634 | test_cmp expect actual && | |
635 | sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect && | |
636 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual && | |
637 | test_cmp expect actual | |
638 | ' | |
639 | ||
640 | test_expect_success $PREREQ 'setup fake editor' ' | |
641 | write_script fake-editor <<-\EOF | |
642 | echo fake edit >>"$1" | |
643 | EOF | |
644 | ' | |
645 | ||
646 | test_set_editor "$(pwd)/fake-editor" | |
647 | ||
648 | test_expect_success $PREREQ '--compose works' ' | |
649 | clean_fake_sendmail && | |
650 | git send-email \ | |
651 | --compose --subject foo \ | |
652 | --from="Example <nobody@example.com>" \ | |
653 | --to=nobody@example.com \ | |
654 | --smtp-server="$(pwd)/fake.sendmail" \ | |
655 | $patches \ | |
656 | 2>errors | |
657 | ' | |
658 | ||
659 | test_expect_success $PREREQ 'first message is compose text' ' | |
660 | grep "^fake edit" msgtxt1 | |
661 | ' | |
662 | ||
663 | test_expect_success $PREREQ 'second message is patch' ' | |
664 | grep "Subject:.*Second" msgtxt2 | |
665 | ' | |
666 | ||
667 | test_expect_success $PREREQ 'setup expect' " | |
668 | cat >expected-suppress-sob <<\EOF | |
669 | 0001-Second.patch | |
670 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
671 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
672 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
673 | Dry-OK. Log says: | |
674 | Server: relay.example.com | |
675 | MAIL FROM:<from@example.com> | |
676 | RCPT TO:<to@example.com> | |
677 | RCPT TO:<cc@example.com> | |
678 | RCPT TO:<author@example.com> | |
679 | RCPT TO:<one@example.com> | |
680 | RCPT TO:<two@example.com> | |
681 | From: Example <from@example.com> | |
682 | To: to@example.com | |
683 | Cc: cc@example.com, | |
684 | A <author@example.com>, | |
685 | One <one@example.com>, | |
686 | two@example.com | |
687 | Subject: [PATCH 1/1] Second. | |
688 | Date: DATE-STRING | |
689 | Message-Id: MESSAGE-ID-STRING | |
690 | X-Mailer: X-MAILER-STRING | |
691 | MIME-Version: 1.0 | |
692 | Content-Transfer-Encoding: 8bit | |
693 | ||
694 | Result: OK | |
695 | EOF | |
696 | " | |
697 | ||
698 | test_suppression () { | |
699 | git send-email \ | |
700 | --dry-run \ | |
701 | --suppress-cc=$1 ${2+"--suppress-cc=$2"} \ | |
702 | --from="Example <from@example.com>" \ | |
703 | --to=to@example.com \ | |
704 | --smtp-server relay.example.com \ | |
705 | $patches | replace_variable_fields \ | |
706 | >actual-suppress-$1${2+"-$2"} && | |
707 | test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"} | |
708 | } | |
709 | ||
710 | test_expect_success $PREREQ 'sendemail.cc set' ' | |
711 | git config sendemail.cc cc@example.com && | |
712 | test_suppression sob | |
713 | ' | |
714 | ||
715 | test_expect_success $PREREQ 'setup expect' " | |
716 | cat >expected-suppress-sob <<\EOF | |
717 | 0001-Second.patch | |
718 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
719 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
720 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
721 | Dry-OK. Log says: | |
722 | Server: relay.example.com | |
723 | MAIL FROM:<from@example.com> | |
724 | RCPT TO:<to@example.com> | |
725 | RCPT TO:<author@example.com> | |
726 | RCPT TO:<one@example.com> | |
727 | RCPT TO:<two@example.com> | |
728 | From: Example <from@example.com> | |
729 | To: to@example.com | |
730 | Cc: A <author@example.com>, | |
731 | One <one@example.com>, | |
732 | two@example.com | |
733 | Subject: [PATCH 1/1] Second. | |
734 | Date: DATE-STRING | |
735 | Message-Id: MESSAGE-ID-STRING | |
736 | X-Mailer: X-MAILER-STRING | |
737 | MIME-Version: 1.0 | |
738 | Content-Transfer-Encoding: 8bit | |
739 | ||
740 | Result: OK | |
741 | EOF | |
742 | " | |
743 | ||
744 | test_expect_success $PREREQ 'sendemail.cc unset' ' | |
745 | git config --unset sendemail.cc && | |
746 | test_suppression sob | |
747 | ' | |
748 | ||
749 | test_expect_success $PREREQ 'setup expect' " | |
750 | cat >expected-suppress-cccmd <<\EOF | |
751 | 0001-Second.patch | |
752 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
753 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
754 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
755 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
756 | Dry-OK. Log says: | |
757 | Server: relay.example.com | |
758 | MAIL FROM:<from@example.com> | |
759 | RCPT TO:<to@example.com> | |
760 | RCPT TO:<author@example.com> | |
761 | RCPT TO:<one@example.com> | |
762 | RCPT TO:<two@example.com> | |
763 | RCPT TO:<committer@example.com> | |
764 | From: Example <from@example.com> | |
765 | To: to@example.com | |
766 | Cc: A <author@example.com>, | |
767 | One <one@example.com>, | |
768 | two@example.com, | |
769 | C O Mitter <committer@example.com> | |
770 | Subject: [PATCH 1/1] Second. | |
771 | Date: DATE-STRING | |
772 | Message-Id: MESSAGE-ID-STRING | |
773 | X-Mailer: X-MAILER-STRING | |
774 | MIME-Version: 1.0 | |
775 | Content-Transfer-Encoding: 8bit | |
776 | ||
777 | Result: OK | |
778 | EOF | |
779 | " | |
780 | ||
781 | test_expect_success $PREREQ 'sendemail.cccmd' ' | |
782 | write_script cccmd <<-\EOF && | |
783 | echo cc-cmd@example.com | |
784 | EOF | |
785 | git config sendemail.cccmd ./cccmd && | |
786 | test_suppression cccmd | |
787 | ' | |
788 | ||
789 | test_expect_success $PREREQ 'setup expect' ' | |
790 | cat >expected-suppress-all <<\EOF | |
791 | 0001-Second.patch | |
792 | Dry-OK. Log says: | |
793 | Server: relay.example.com | |
794 | MAIL FROM:<from@example.com> | |
795 | RCPT TO:<to@example.com> | |
796 | From: Example <from@example.com> | |
797 | To: to@example.com | |
798 | Subject: [PATCH 1/1] Second. | |
799 | Date: DATE-STRING | |
800 | Message-Id: MESSAGE-ID-STRING | |
801 | X-Mailer: X-MAILER-STRING | |
802 | MIME-Version: 1.0 | |
803 | Content-Transfer-Encoding: 8bit | |
804 | ||
805 | Result: OK | |
806 | EOF | |
807 | ' | |
808 | ||
809 | test_expect_success $PREREQ '--suppress-cc=all' ' | |
810 | test_suppression all | |
811 | ' | |
812 | ||
813 | test_expect_success $PREREQ 'setup expect' " | |
814 | cat >expected-suppress-body <<\EOF | |
815 | 0001-Second.patch | |
816 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
817 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
818 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
819 | (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd' | |
820 | Dry-OK. Log says: | |
821 | Server: relay.example.com | |
822 | MAIL FROM:<from@example.com> | |
823 | RCPT TO:<to@example.com> | |
824 | RCPT TO:<author@example.com> | |
825 | RCPT TO:<one@example.com> | |
826 | RCPT TO:<two@example.com> | |
827 | RCPT TO:<cc-cmd@example.com> | |
828 | From: Example <from@example.com> | |
829 | To: to@example.com | |
830 | Cc: A <author@example.com>, | |
831 | One <one@example.com>, | |
832 | two@example.com, | |
833 | cc-cmd@example.com | |
834 | Subject: [PATCH 1/1] Second. | |
835 | Date: DATE-STRING | |
836 | Message-Id: MESSAGE-ID-STRING | |
837 | X-Mailer: X-MAILER-STRING | |
838 | MIME-Version: 1.0 | |
839 | Content-Transfer-Encoding: 8bit | |
840 | ||
841 | Result: OK | |
842 | EOF | |
843 | " | |
844 | ||
845 | test_expect_success $PREREQ '--suppress-cc=body' ' | |
846 | test_suppression body | |
847 | ' | |
848 | ||
849 | test_expect_success $PREREQ 'setup expect' " | |
850 | cat >expected-suppress-body-cccmd <<\EOF | |
851 | 0001-Second.patch | |
852 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
853 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
854 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
855 | Dry-OK. Log says: | |
856 | Server: relay.example.com | |
857 | MAIL FROM:<from@example.com> | |
858 | RCPT TO:<to@example.com> | |
859 | RCPT TO:<author@example.com> | |
860 | RCPT TO:<one@example.com> | |
861 | RCPT TO:<two@example.com> | |
862 | From: Example <from@example.com> | |
863 | To: to@example.com | |
864 | Cc: A <author@example.com>, | |
865 | One <one@example.com>, | |
866 | two@example.com | |
867 | Subject: [PATCH 1/1] Second. | |
868 | Date: DATE-STRING | |
869 | Message-Id: MESSAGE-ID-STRING | |
870 | X-Mailer: X-MAILER-STRING | |
871 | MIME-Version: 1.0 | |
872 | Content-Transfer-Encoding: 8bit | |
873 | ||
874 | Result: OK | |
875 | EOF | |
876 | " | |
877 | ||
878 | test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' ' | |
879 | test_suppression body cccmd | |
880 | ' | |
881 | ||
882 | test_expect_success $PREREQ 'setup expect' " | |
883 | cat >expected-suppress-sob <<\EOF | |
884 | 0001-Second.patch | |
885 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
886 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
887 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
888 | Dry-OK. Log says: | |
889 | Server: relay.example.com | |
890 | MAIL FROM:<from@example.com> | |
891 | RCPT TO:<to@example.com> | |
892 | RCPT TO:<author@example.com> | |
893 | RCPT TO:<one@example.com> | |
894 | RCPT TO:<two@example.com> | |
895 | From: Example <from@example.com> | |
896 | To: to@example.com | |
897 | Cc: A <author@example.com>, | |
898 | One <one@example.com>, | |
899 | two@example.com | |
900 | Subject: [PATCH 1/1] Second. | |
901 | Date: DATE-STRING | |
902 | Message-Id: MESSAGE-ID-STRING | |
903 | X-Mailer: X-MAILER-STRING | |
904 | MIME-Version: 1.0 | |
905 | Content-Transfer-Encoding: 8bit | |
906 | ||
907 | Result: OK | |
908 | EOF | |
909 | " | |
910 | ||
911 | test_expect_success $PREREQ '--suppress-cc=sob' ' | |
912 | test_might_fail git config --unset sendemail.cccmd && | |
913 | test_suppression sob | |
914 | ' | |
915 | ||
916 | test_expect_success $PREREQ 'setup expect' " | |
917 | cat >expected-suppress-bodycc <<\EOF | |
918 | 0001-Second.patch | |
919 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
920 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
921 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
922 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
923 | Dry-OK. Log says: | |
924 | Server: relay.example.com | |
925 | MAIL FROM:<from@example.com> | |
926 | RCPT TO:<to@example.com> | |
927 | RCPT TO:<author@example.com> | |
928 | RCPT TO:<one@example.com> | |
929 | RCPT TO:<two@example.com> | |
930 | RCPT TO:<committer@example.com> | |
931 | From: Example <from@example.com> | |
932 | To: to@example.com | |
933 | Cc: A <author@example.com>, | |
934 | One <one@example.com>, | |
935 | two@example.com, | |
936 | C O Mitter <committer@example.com> | |
937 | Subject: [PATCH 1/1] Second. | |
938 | Date: DATE-STRING | |
939 | Message-Id: MESSAGE-ID-STRING | |
940 | X-Mailer: X-MAILER-STRING | |
941 | MIME-Version: 1.0 | |
942 | Content-Transfer-Encoding: 8bit | |
943 | ||
944 | Result: OK | |
945 | EOF | |
946 | " | |
947 | ||
948 | test_expect_success $PREREQ '--suppress-cc=bodycc' ' | |
949 | test_suppression bodycc | |
950 | ' | |
951 | ||
952 | test_expect_success $PREREQ 'setup expect' " | |
953 | cat >expected-suppress-cc <<\EOF | |
954 | 0001-Second.patch | |
955 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
956 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
957 | Dry-OK. Log says: | |
958 | Server: relay.example.com | |
959 | MAIL FROM:<from@example.com> | |
960 | RCPT TO:<to@example.com> | |
961 | RCPT TO:<author@example.com> | |
962 | RCPT TO:<committer@example.com> | |
963 | From: Example <from@example.com> | |
964 | To: to@example.com | |
965 | Cc: A <author@example.com>, | |
966 | C O Mitter <committer@example.com> | |
967 | Subject: [PATCH 1/1] Second. | |
968 | Date: DATE-STRING | |
969 | Message-Id: MESSAGE-ID-STRING | |
970 | X-Mailer: X-MAILER-STRING | |
971 | MIME-Version: 1.0 | |
972 | Content-Transfer-Encoding: 8bit | |
973 | ||
974 | Result: OK | |
975 | EOF | |
976 | " | |
977 | ||
978 | test_expect_success $PREREQ '--suppress-cc=cc' ' | |
979 | test_suppression cc | |
980 | ' | |
981 | ||
982 | test_confirm () { | |
983 | echo y | \ | |
984 | GIT_SEND_EMAIL_NOTTY=1 \ | |
985 | git send-email \ | |
986 | --from="Example <nobody@example.com>" \ | |
987 | --to=nobody@example.com \ | |
988 | --smtp-server="$(pwd)/fake.sendmail" \ | |
989 | $@ $patches >stdout && | |
990 | grep "Send this email" stdout | |
991 | } | |
992 | ||
993 | test_expect_success $PREREQ '--confirm=always' ' | |
994 | test_confirm --confirm=always --suppress-cc=all | |
995 | ' | |
996 | ||
997 | test_expect_success $PREREQ '--confirm=auto' ' | |
998 | test_confirm --confirm=auto | |
999 | ' | |
1000 | ||
1001 | test_expect_success $PREREQ '--confirm=cc' ' | |
1002 | test_confirm --confirm=cc | |
1003 | ' | |
1004 | ||
1005 | test_expect_success $PREREQ '--confirm=compose' ' | |
1006 | test_confirm --confirm=compose --compose | |
1007 | ' | |
1008 | ||
1009 | test_expect_success $PREREQ 'confirm by default (due to cc)' ' | |
1010 | test_when_finished git config sendemail.confirm never && | |
1011 | git config --unset sendemail.confirm && | |
1012 | test_confirm | |
1013 | ' | |
1014 | ||
1015 | test_expect_success $PREREQ 'confirm by default (due to --compose)' ' | |
1016 | test_when_finished git config sendemail.confirm never && | |
1017 | git config --unset sendemail.confirm && | |
1018 | test_confirm --suppress-cc=all --compose | |
1019 | ' | |
1020 | ||
1021 | test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' ' | |
1022 | test_when_finished git config sendemail.confirm never && | |
1023 | git config --unset sendemail.confirm && | |
1024 | rm -fr outdir && | |
1025 | git format-patch -2 -o outdir && | |
1026 | GIT_SEND_EMAIL_NOTTY=1 \ | |
1027 | git send-email \ | |
1028 | --from="Example <nobody@example.com>" \ | |
1029 | --to=nobody@example.com \ | |
1030 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1031 | outdir/*.patch </dev/null | |
1032 | ' | |
1033 | ||
1034 | test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' ' | |
1035 | test_when_finished git config sendemail.confirm never && | |
1036 | git config sendemail.confirm auto && | |
1037 | GIT_SEND_EMAIL_NOTTY=1 && | |
1038 | export GIT_SEND_EMAIL_NOTTY && | |
1039 | test_must_fail git send-email \ | |
1040 | --from="Example <nobody@example.com>" \ | |
1041 | --to=nobody@example.com \ | |
1042 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1043 | $patches </dev/null | |
1044 | ' | |
1045 | ||
1046 | test_expect_success $PREREQ 'confirm does not loop forever' ' | |
1047 | test_when_finished git config sendemail.confirm never && | |
1048 | git config sendemail.confirm auto && | |
1049 | GIT_SEND_EMAIL_NOTTY=1 && | |
1050 | export GIT_SEND_EMAIL_NOTTY && | |
1051 | yes "bogus" | test_must_fail git send-email \ | |
1052 | --from="Example <nobody@example.com>" \ | |
1053 | --to=nobody@example.com \ | |
1054 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1055 | $patches | |
1056 | ' | |
1057 | ||
1058 | test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' ' | |
1059 | clean_fake_sendmail && | |
1060 | rm -fr outdir && | |
1061 | git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" && | |
1062 | git send-email \ | |
1063 | --from="Example <nobody@example.com>" \ | |
1064 | --to=nobody@example.com \ | |
1065 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1066 | outdir/*.patch && | |
1067 | grep "^ " msgtxt1 | | |
1068 | grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>" | |
1069 | ' | |
1070 | ||
1071 | test_expect_success $PREREQ '--compose adds MIME for utf8 body' ' | |
1072 | clean_fake_sendmail && | |
1073 | write_script fake-editor-utf8 <<-\EOF && | |
1074 | echo "utf8 body: àéìöú" >>"$1" | |
1075 | EOF | |
1076 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ | |
1077 | git send-email \ | |
1078 | --compose --subject foo \ | |
1079 | --from="Example <nobody@example.com>" \ | |
1080 | --to=nobody@example.com \ | |
1081 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1082 | $patches && | |
1083 | grep "^utf8 body" msgtxt1 && | |
1084 | grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 | |
1085 | ' | |
1086 | ||
1087 | test_expect_success $PREREQ '--compose respects user mime type' ' | |
1088 | clean_fake_sendmail && | |
1089 | write_script fake-editor-utf8-mime <<-\EOF && | |
1090 | cat >"$1" <<-\EOM | |
1091 | MIME-Version: 1.0 | |
1092 | Content-Type: text/plain; charset=iso-8859-1 | |
1093 | Content-Transfer-Encoding: 8bit | |
1094 | Subject: foo | |
1095 | ||
1096 | utf8 body: àéìöú | |
1097 | EOM | |
1098 | EOF | |
1099 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \ | |
1100 | git send-email \ | |
1101 | --compose --subject foo \ | |
1102 | --from="Example <nobody@example.com>" \ | |
1103 | --to=nobody@example.com \ | |
1104 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1105 | $patches && | |
1106 | grep "^utf8 body" msgtxt1 && | |
1107 | grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 && | |
1108 | ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 | |
1109 | ' | |
1110 | ||
1111 | test_expect_success $PREREQ '--compose adds MIME for utf8 subject' ' | |
1112 | clean_fake_sendmail && | |
1113 | GIT_EDITOR="\"$(pwd)/fake-editor\"" \ | |
1114 | git send-email \ | |
1115 | --compose --subject utf8-sübjëct \ | |
1116 | --from="Example <nobody@example.com>" \ | |
1117 | --to=nobody@example.com \ | |
1118 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1119 | $patches && | |
1120 | grep "^fake edit" msgtxt1 && | |
1121 | grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1 | |
1122 | ' | |
1123 | ||
1124 | test_expect_success $PREREQ 'utf8 author is correctly passed on' ' | |
1125 | clean_fake_sendmail && | |
1126 | test_commit weird_author && | |
1127 | test_when_finished "git reset --hard HEAD^" && | |
1128 | git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" && | |
1129 | git format-patch --stdout -1 >funny_name.patch && | |
1130 | git send-email --from="Example <nobody@example.com>" \ | |
1131 | --to=nobody@example.com \ | |
1132 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1133 | funny_name.patch && | |
1134 | grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1 | |
1135 | ' | |
1136 | ||
1137 | test_expect_success $PREREQ 'utf8 sender is not duplicated' ' | |
1138 | clean_fake_sendmail && | |
1139 | test_commit weird_sender && | |
1140 | test_when_finished "git reset --hard HEAD^" && | |
1141 | git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" && | |
1142 | git format-patch --stdout -1 >funny_name.patch && | |
1143 | git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \ | |
1144 | --to=nobody@example.com \ | |
1145 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1146 | funny_name.patch && | |
1147 | grep "^From: " msgtxt1 >msgfrom && | |
1148 | test_line_count = 1 msgfrom | |
1149 | ' | |
1150 | ||
1151 | test_expect_success $PREREQ 'sendemail.composeencoding works' ' | |
1152 | clean_fake_sendmail && | |
1153 | git config sendemail.composeencoding iso-8859-1 && | |
1154 | write_script fake-editor-utf8 <<-\EOF && | |
1155 | echo "utf8 body: àéìöú" >>"$1" | |
1156 | EOF | |
1157 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ | |
1158 | git send-email \ | |
1159 | --compose --subject foo \ | |
1160 | --from="Example <nobody@example.com>" \ | |
1161 | --to=nobody@example.com \ | |
1162 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1163 | $patches && | |
1164 | grep "^utf8 body" msgtxt1 && | |
1165 | grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 | |
1166 | ' | |
1167 | ||
1168 | test_expect_success $PREREQ '--compose-encoding works' ' | |
1169 | clean_fake_sendmail && | |
1170 | write_script fake-editor-utf8 <<-\EOF && | |
1171 | echo "utf8 body: àéìöú" >>"$1" | |
1172 | EOF | |
1173 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ | |
1174 | git send-email \ | |
1175 | --compose-encoding iso-8859-1 \ | |
1176 | --compose --subject foo \ | |
1177 | --from="Example <nobody@example.com>" \ | |
1178 | --to=nobody@example.com \ | |
1179 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1180 | $patches && | |
1181 | grep "^utf8 body" msgtxt1 && | |
1182 | grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 | |
1183 | ' | |
1184 | ||
1185 | test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' ' | |
1186 | clean_fake_sendmail && | |
1187 | git config sendemail.composeencoding iso-8859-1 && | |
1188 | write_script fake-editor-utf8 <<-\EOF && | |
1189 | echo "utf8 body: àéìöú" >>"$1" | |
1190 | EOF | |
1191 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ | |
1192 | git send-email \ | |
1193 | --compose-encoding iso-8859-2 \ | |
1194 | --compose --subject foo \ | |
1195 | --from="Example <nobody@example.com>" \ | |
1196 | --to=nobody@example.com \ | |
1197 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1198 | $patches && | |
1199 | grep "^utf8 body" msgtxt1 && | |
1200 | grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1 | |
1201 | ' | |
1202 | ||
1203 | test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' ' | |
1204 | clean_fake_sendmail && | |
1205 | GIT_EDITOR="\"$(pwd)/fake-editor\"" \ | |
1206 | git send-email \ | |
1207 | --compose-encoding iso-8859-2 \ | |
1208 | --compose --subject utf8-sübjëct \ | |
1209 | --from="Example <nobody@example.com>" \ | |
1210 | --to=nobody@example.com \ | |
1211 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1212 | $patches && | |
1213 | grep "^fake edit" msgtxt1 && | |
1214 | grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1 | |
1215 | ' | |
1216 | ||
1217 | test_expect_success $PREREQ 'detects ambiguous reference/file conflict' ' | |
1218 | echo main >main && | |
1219 | git add main && | |
1220 | git commit -m"add main" && | |
1221 | test_must_fail git send-email --dry-run main 2>errors && | |
1222 | grep disambiguate errors | |
1223 | ' | |
1224 | ||
1225 | test_expect_success $PREREQ 'feed two files' ' | |
1226 | rm -fr outdir && | |
1227 | git format-patch -2 -o outdir && | |
1228 | git send-email \ | |
1229 | --dry-run \ | |
1230 | --from="Example <nobody@example.com>" \ | |
1231 | --to=nobody@example.com \ | |
1232 | outdir/000?-*.patch 2>errors >out && | |
1233 | grep "^Subject: " out >subjects && | |
1234 | test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." && | |
1235 | test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main" | |
1236 | ' | |
1237 | ||
1238 | test_expect_success $PREREQ 'in-reply-to but no threading' ' | |
1239 | git send-email \ | |
1240 | --dry-run \ | |
1241 | --from="Example <nobody@example.com>" \ | |
1242 | --to=nobody@example.com \ | |
1243 | --in-reply-to="<in-reply-id@example.com>" \ | |
1244 | --no-thread \ | |
1245 | $patches >out && | |
1246 | grep "In-Reply-To: <in-reply-id@example.com>" out | |
1247 | ' | |
1248 | ||
1249 | test_expect_success $PREREQ 'no in-reply-to and no threading' ' | |
1250 | git send-email \ | |
1251 | --dry-run \ | |
1252 | --from="Example <nobody@example.com>" \ | |
1253 | --to=nobody@example.com \ | |
1254 | --no-thread \ | |
1255 | $patches >stdout && | |
1256 | ! grep "In-Reply-To: " stdout | |
1257 | ' | |
1258 | ||
1259 | test_expect_success $PREREQ 'threading but no chain-reply-to' ' | |
1260 | git send-email \ | |
1261 | --dry-run \ | |
1262 | --from="Example <nobody@example.com>" \ | |
1263 | --to=nobody@example.com \ | |
1264 | --thread \ | |
1265 | --no-chain-reply-to \ | |
1266 | $patches $patches >stdout && | |
1267 | grep "In-Reply-To: " stdout | |
1268 | ' | |
1269 | ||
1270 | test_expect_success $PREREQ 'override in-reply-to if no threading' ' | |
1271 | git send-email \ | |
1272 | --dry-run \ | |
1273 | --from="Example <nobody@example.com>" \ | |
1274 | --to=nobody@example.com \ | |
1275 | --no-thread \ | |
1276 | --in-reply-to="override" \ | |
1277 | $threaded_patches >stdout && | |
1278 | grep "In-Reply-To: <override>" stdout | |
1279 | ' | |
1280 | ||
1281 | test_expect_success $PREREQ 'sendemail.to works' ' | |
1282 | git config --replace-all sendemail.to "Somebody <somebody@ex.com>" && | |
1283 | git send-email \ | |
1284 | --dry-run \ | |
1285 | --from="Example <nobody@example.com>" \ | |
1286 | $patches >stdout && | |
1287 | grep "To: Somebody <somebody@ex.com>" stdout | |
1288 | ' | |
1289 | ||
1290 | test_expect_success $PREREQ 'setup sendemail.identity' ' | |
1291 | git config --replace-all sendemail.to "default@example.com" && | |
1292 | git config --replace-all sendemail.isp.to "isp@example.com" && | |
1293 | git config --replace-all sendemail.cloud.to "cloud@example.com" | |
1294 | ' | |
1295 | ||
1296 | test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' ' | |
1297 | git -c sendemail.identity=cloud send-email \ | |
1298 | --dry-run \ | |
1299 | --from="nobody@example.com" \ | |
1300 | $patches >stdout && | |
1301 | grep "To: cloud@example.com" stdout | |
1302 | ' | |
1303 | ||
1304 | test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' ' | |
1305 | git -c sendemail.identity=cloud send-email \ | |
1306 | --identity=isp \ | |
1307 | --dry-run \ | |
1308 | --from="nobody@example.com" \ | |
1309 | $patches >stdout && | |
1310 | grep "To: isp@example.com" stdout | |
1311 | ' | |
1312 | ||
1313 | test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' ' | |
1314 | git -c sendemail.identity=cloud send-email \ | |
1315 | --no-identity \ | |
1316 | --dry-run \ | |
1317 | --from="nobody@example.com" \ | |
1318 | $patches >stdout && | |
1319 | grep "To: default@example.com" stdout | |
1320 | ' | |
1321 | ||
1322 | test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' ' | |
1323 | git -c sendemail.identity=cloud \ | |
1324 | -c sendemail.xmailer=true \ | |
1325 | -c sendemail.cloud.xmailer=false \ | |
1326 | send-email \ | |
1327 | --dry-run \ | |
1328 | --from="nobody@example.com" \ | |
1329 | $patches >stdout && | |
1330 | grep "To: cloud@example.com" stdout && | |
1331 | ! grep "X-Mailer" stdout | |
1332 | ' | |
1333 | ||
1334 | test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' ' | |
1335 | git -c sendemail.identity=cloud \ | |
1336 | -c sendemail.xmailer=false \ | |
1337 | send-email \ | |
1338 | --dry-run \ | |
1339 | --from="nobody@example.com" \ | |
1340 | $patches >stdout && | |
1341 | grep "To: cloud@example.com" stdout && | |
1342 | ! grep "X-Mailer" stdout | |
1343 | ' | |
1344 | ||
1345 | test_expect_success $PREREQ '--no-to overrides sendemail.to' ' | |
1346 | git send-email \ | |
1347 | --dry-run \ | |
1348 | --from="Example <nobody@example.com>" \ | |
1349 | --no-to \ | |
1350 | --to=nobody@example.com \ | |
1351 | $patches >stdout && | |
1352 | grep "To: nobody@example.com" stdout && | |
1353 | ! grep "To: Somebody <somebody@ex.com>" stdout | |
1354 | ' | |
1355 | ||
1356 | test_expect_success $PREREQ 'sendemail.cc works' ' | |
1357 | git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" && | |
1358 | git send-email \ | |
1359 | --dry-run \ | |
1360 | --from="Example <nobody@example.com>" \ | |
1361 | --to=nobody@example.com \ | |
1362 | $patches >stdout && | |
1363 | grep "Cc: Somebody <somebody@ex.com>" stdout | |
1364 | ' | |
1365 | ||
1366 | test_expect_success $PREREQ '--no-cc overrides sendemail.cc' ' | |
1367 | git send-email \ | |
1368 | --dry-run \ | |
1369 | --from="Example <nobody@example.com>" \ | |
1370 | --no-cc \ | |
1371 | --cc=bodies@example.com \ | |
1372 | --to=nobody@example.com \ | |
1373 | $patches >stdout && | |
1374 | grep "Cc: bodies@example.com" stdout && | |
1375 | ! grep "Cc: Somebody <somebody@ex.com>" stdout | |
1376 | ' | |
1377 | ||
1378 | test_expect_success $PREREQ 'sendemail.bcc works' ' | |
1379 | git config --replace-all sendemail.bcc "Other <other@ex.com>" && | |
1380 | git send-email \ | |
1381 | --dry-run \ | |
1382 | --from="Example <nobody@example.com>" \ | |
1383 | --to=nobody@example.com \ | |
1384 | --smtp-server relay.example.com \ | |
1385 | $patches >stdout && | |
1386 | grep "RCPT TO:<other@ex.com>" stdout | |
1387 | ' | |
1388 | ||
1389 | test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' ' | |
1390 | git send-email \ | |
1391 | --dry-run \ | |
1392 | --from="Example <nobody@example.com>" \ | |
1393 | --no-bcc \ | |
1394 | --bcc=bodies@example.com \ | |
1395 | --to=nobody@example.com \ | |
1396 | --smtp-server relay.example.com \ | |
1397 | $patches >stdout && | |
1398 | grep "RCPT TO:<bodies@example.com>" stdout && | |
1399 | ! grep "RCPT TO:<other@ex.com>" stdout | |
1400 | ' | |
1401 | ||
1402 | test_expect_success $PREREQ 'patches To headers are used by default' ' | |
1403 | patch=$(git format-patch -1 --to="bodies@example.com") && | |
1404 | test_when_finished "rm $patch" && | |
1405 | git send-email \ | |
1406 | --dry-run \ | |
1407 | --from="Example <nobody@example.com>" \ | |
1408 | --smtp-server relay.example.com \ | |
1409 | $patch >stdout && | |
1410 | grep "RCPT TO:<bodies@example.com>" stdout | |
1411 | ' | |
1412 | ||
1413 | test_expect_success $PREREQ 'patches To headers are appended to' ' | |
1414 | patch=$(git format-patch -1 --to="bodies@example.com") && | |
1415 | test_when_finished "rm $patch" && | |
1416 | git send-email \ | |
1417 | --dry-run \ | |
1418 | --from="Example <nobody@example.com>" \ | |
1419 | --to=nobody@example.com \ | |
1420 | --smtp-server relay.example.com \ | |
1421 | $patch >stdout && | |
1422 | grep "RCPT TO:<bodies@example.com>" stdout && | |
1423 | grep "RCPT TO:<nobody@example.com>" stdout | |
1424 | ' | |
1425 | ||
1426 | test_expect_success $PREREQ 'To headers from files reset each patch' ' | |
1427 | patch1=$(git format-patch -1 --to="bodies@example.com") && | |
1428 | patch2=$(git format-patch -1 --to="other@example.com" HEAD~) && | |
1429 | test_when_finished "rm $patch1 && rm $patch2" && | |
1430 | git send-email \ | |
1431 | --dry-run \ | |
1432 | --from="Example <nobody@example.com>" \ | |
1433 | --to="nobody@example.com" \ | |
1434 | --smtp-server relay.example.com \ | |
1435 | $patch1 $patch2 >stdout && | |
1436 | test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 && | |
1437 | test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 && | |
1438 | test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1 | |
1439 | ' | |
1440 | ||
1441 | test_expect_success $PREREQ 'setup expect' ' | |
1442 | cat >email-using-8bit <<\EOF | |
1443 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 | |
1444 | Message-Id: <bogus-message-id@example.com> | |
1445 | From: author@example.com | |
1446 | Date: Sat, 12 Jun 2010 15:53:58 +0200 | |
1447 | Subject: subject goes here | |
1448 | ||
1449 | Dieser deutsche Text enthält einen Umlaut! | |
1450 | EOF | |
1451 | ' | |
1452 | ||
1453 | test_expect_success $PREREQ 'setup expect' ' | |
1454 | echo "Subject: subject goes here" >expected | |
1455 | ' | |
1456 | ||
1457 | test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' ' | |
1458 | clean_fake_sendmail && | |
1459 | echo bogus | | |
1460 | git send-email --from=author@example.com --to=nobody@example.com \ | |
1461 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1462 | --8bit-encoding=UTF-8 \ | |
1463 | email-using-8bit >stdout && | |
1464 | grep "Subject" msgtxt1 >actual && | |
1465 | test_cmp expected actual | |
1466 | ' | |
1467 | ||
1468 | test_expect_success $PREREQ 'setup expect' ' | |
1469 | cat >content-type-decl <<-\EOF | |
1470 | MIME-Version: 1.0 | |
1471 | Content-Type: text/plain; charset=UTF-8 | |
1472 | Content-Transfer-Encoding: 8bit | |
1473 | EOF | |
1474 | ' | |
1475 | ||
1476 | test_expect_success $PREREQ 'asks about and fixes 8bit encodings' ' | |
1477 | clean_fake_sendmail && | |
1478 | echo | | |
1479 | git send-email --from=author@example.com --to=nobody@example.com \ | |
1480 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1481 | email-using-8bit >stdout && | |
1482 | grep "do not declare a Content-Transfer-Encoding" stdout && | |
1483 | grep email-using-8bit stdout && | |
1484 | grep "Which 8bit encoding" stdout && | |
1485 | egrep "Content|MIME" msgtxt1 >actual && | |
1486 | test_cmp content-type-decl actual | |
1487 | ' | |
1488 | ||
1489 | test_expect_success $PREREQ 'sendemail.8bitEncoding works' ' | |
1490 | clean_fake_sendmail && | |
1491 | git config sendemail.assume8bitEncoding UTF-8 && | |
1492 | echo bogus | | |
1493 | git send-email --from=author@example.com --to=nobody@example.com \ | |
1494 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1495 | email-using-8bit >stdout && | |
1496 | egrep "Content|MIME" msgtxt1 >actual && | |
1497 | test_cmp content-type-decl actual | |
1498 | ' | |
1499 | ||
1500 | test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' ' | |
1501 | clean_fake_sendmail && | |
1502 | git config sendemail.assume8bitEncoding "bogus too" && | |
1503 | echo bogus | | |
1504 | git send-email --from=author@example.com --to=nobody@example.com \ | |
1505 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1506 | --8bit-encoding=UTF-8 \ | |
1507 | email-using-8bit >stdout && | |
1508 | egrep "Content|MIME" msgtxt1 >actual && | |
1509 | test_cmp content-type-decl actual | |
1510 | ' | |
1511 | ||
1512 | test_expect_success $PREREQ 'setup expect' ' | |
1513 | cat >email-using-8bit <<-\EOF | |
1514 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 | |
1515 | Message-Id: <bogus-message-id@example.com> | |
1516 | From: author@example.com | |
1517 | Date: Sat, 12 Jun 2010 15:53:58 +0200 | |
1518 | Subject: Dieser Betreff enthält auch einen Umlaut! | |
1519 | ||
1520 | Nothing to see here. | |
1521 | EOF | |
1522 | ' | |
1523 | ||
1524 | test_expect_success $PREREQ 'setup expect' ' | |
1525 | cat >expected <<-\EOF | |
1526 | Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?= | |
1527 | EOF | |
1528 | ' | |
1529 | ||
1530 | test_expect_success $PREREQ '--8bit-encoding also treats subject' ' | |
1531 | clean_fake_sendmail && | |
1532 | echo bogus | | |
1533 | git send-email --from=author@example.com --to=nobody@example.com \ | |
1534 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1535 | --8bit-encoding=UTF-8 \ | |
1536 | email-using-8bit >stdout && | |
1537 | grep "Subject" msgtxt1 >actual && | |
1538 | test_cmp expected actual | |
1539 | ' | |
1540 | ||
1541 | test_expect_success $PREREQ 'setup expect' ' | |
1542 | cat >email-using-8bit <<-\EOF | |
1543 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 | |
1544 | Message-Id: <bogus-message-id@example.com> | |
1545 | From: A U Thor <author@example.com> | |
1546 | Date: Sat, 12 Jun 2010 15:53:58 +0200 | |
1547 | Content-Type: text/plain; charset=UTF-8 | |
1548 | Subject: Nothing to see here. | |
1549 | ||
1550 | Dieser Betreff enthält auch einen Umlaut! | |
1551 | EOF | |
1552 | ' | |
1553 | ||
1554 | test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' ' | |
1555 | clean_fake_sendmail && | |
1556 | test_must_fail git -c sendemail.transferEncoding=8bit \ | |
1557 | send-email \ | |
1558 | --transfer-encoding=7bit \ | |
1559 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1560 | email-using-8bit \ | |
1561 | 2>errors >out && | |
1562 | grep "cannot send message as 7bit" errors && | |
1563 | test -z "$(ls msgtxt*)" | |
1564 | ' | |
1565 | ||
1566 | test_expect_success $PREREQ 'sendemail.transferEncoding via config' ' | |
1567 | clean_fake_sendmail && | |
1568 | test_must_fail git -c sendemail.transferEncoding=7bit \ | |
1569 | send-email \ | |
1570 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1571 | email-using-8bit \ | |
1572 | 2>errors >out && | |
1573 | grep "cannot send message as 7bit" errors && | |
1574 | test -z "$(ls msgtxt*)" | |
1575 | ' | |
1576 | ||
1577 | test_expect_success $PREREQ 'sendemail.transferEncoding via cli' ' | |
1578 | clean_fake_sendmail && | |
1579 | test_must_fail git send-email \ | |
1580 | --transfer-encoding=7bit \ | |
1581 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1582 | email-using-8bit \ | |
1583 | 2>errors >out && | |
1584 | grep "cannot send message as 7bit" errors && | |
1585 | test -z "$(ls msgtxt*)" | |
1586 | ' | |
1587 | ||
1588 | test_expect_success $PREREQ 'setup expect' ' | |
1589 | cat >expected <<-\EOF | |
1590 | Dieser Betreff enth=C3=A4lt auch einen Umlaut! | |
1591 | EOF | |
1592 | ' | |
1593 | ||
1594 | test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' ' | |
1595 | clean_fake_sendmail && | |
1596 | git send-email \ | |
1597 | --transfer-encoding=quoted-printable \ | |
1598 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1599 | email-using-8bit \ | |
1600 | 2>errors >out && | |
1601 | sed "1,/^$/d" msgtxt1 >actual && | |
1602 | test_cmp expected actual | |
1603 | ' | |
1604 | ||
1605 | test_expect_success $PREREQ 'setup expect' ' | |
1606 | cat >expected <<-\EOF | |
1607 | RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg== | |
1608 | EOF | |
1609 | ' | |
1610 | ||
1611 | test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' ' | |
1612 | clean_fake_sendmail && | |
1613 | git send-email \ | |
1614 | --transfer-encoding=base64 \ | |
1615 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1616 | email-using-8bit \ | |
1617 | 2>errors >out && | |
1618 | sed "1,/^$/d" msgtxt1 >actual && | |
1619 | test_cmp expected actual | |
1620 | ' | |
1621 | ||
1622 | test_expect_success $PREREQ 'setup expect' ' | |
1623 | cat >email-using-qp <<-\EOF | |
1624 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 | |
1625 | Message-Id: <bogus-message-id@example.com> | |
1626 | From: A U Thor <author@example.com> | |
1627 | Date: Sat, 12 Jun 2010 15:53:58 +0200 | |
1628 | MIME-Version: 1.0 | |
1629 | Content-Transfer-Encoding: quoted-printable | |
1630 | Content-Type: text/plain; charset=UTF-8 | |
1631 | Subject: Nothing to see here. | |
1632 | ||
1633 | Dieser Betreff enth=C3=A4lt auch einen Umlaut! | |
1634 | EOF | |
1635 | ' | |
1636 | ||
1637 | test_expect_success $PREREQ 'convert from quoted-printable to base64' ' | |
1638 | clean_fake_sendmail && | |
1639 | git send-email \ | |
1640 | --transfer-encoding=base64 \ | |
1641 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1642 | email-using-qp \ | |
1643 | 2>errors >out && | |
1644 | sed "1,/^$/d" msgtxt1 >actual && | |
1645 | test_cmp expected actual | |
1646 | ' | |
1647 | ||
1648 | test_expect_success $PREREQ 'setup expect' " | |
1649 | tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF | |
1650 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 | |
1651 | Message-Id: <bogus-message-id@example.com> | |
1652 | From: A U Thor <author@example.com> | |
1653 | Date: Sat, 12 Jun 2010 15:53:58 +0200 | |
1654 | Content-Type: text/plain; charset=UTF-8 | |
1655 | Subject: Nothing to see here. | |
1656 | ||
1657 | Look, I have a CRLF and an = sign!% | |
1658 | EOF | |
1659 | " | |
1660 | ||
1661 | test_expect_success $PREREQ 'setup expect' ' | |
1662 | cat >expected <<-\EOF | |
1663 | Look, I have a CRLF and an =3D sign!=0D | |
1664 | EOF | |
1665 | ' | |
1666 | ||
1667 | test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' ' | |
1668 | clean_fake_sendmail && | |
1669 | git send-email \ | |
1670 | --transfer-encoding=quoted-printable \ | |
1671 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1672 | email-using-crlf \ | |
1673 | 2>errors >out && | |
1674 | sed "1,/^$/d" msgtxt1 >actual && | |
1675 | test_cmp expected actual | |
1676 | ' | |
1677 | ||
1678 | test_expect_success $PREREQ 'setup expect' ' | |
1679 | cat >expected <<-\EOF | |
1680 | TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K | |
1681 | EOF | |
1682 | ' | |
1683 | ||
1684 | test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' ' | |
1685 | clean_fake_sendmail && | |
1686 | git send-email \ | |
1687 | --transfer-encoding=base64 \ | |
1688 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1689 | email-using-crlf \ | |
1690 | 2>errors >out && | |
1691 | sed "1,/^$/d" msgtxt1 >actual && | |
1692 | test_cmp expected actual | |
1693 | ' | |
1694 | ||
1695 | ||
1696 | # Note that the patches in this test are deliberately out of order; we | |
1697 | # want to make sure it works even if the cover-letter is not in the | |
1698 | # first mail. | |
1699 | test_expect_success $PREREQ 'refusing to send cover letter template' ' | |
1700 | clean_fake_sendmail && | |
1701 | rm -fr outdir && | |
1702 | git format-patch --cover-letter -2 -o outdir && | |
1703 | test_must_fail git send-email \ | |
1704 | --from="Example <nobody@example.com>" \ | |
1705 | --to=nobody@example.com \ | |
1706 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1707 | outdir/0002-*.patch \ | |
1708 | outdir/0000-*.patch \ | |
1709 | outdir/0001-*.patch \ | |
1710 | 2>errors >out && | |
1711 | grep "SUBJECT HERE" errors && | |
1712 | test -z "$(ls msgtxt*)" | |
1713 | ' | |
1714 | ||
1715 | test_expect_success $PREREQ '--force sends cover letter template anyway' ' | |
1716 | clean_fake_sendmail && | |
1717 | rm -fr outdir && | |
1718 | git format-patch --cover-letter -2 -o outdir && | |
1719 | git send-email \ | |
1720 | --force \ | |
1721 | --from="Example <nobody@example.com>" \ | |
1722 | --to=nobody@example.com \ | |
1723 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1724 | outdir/0002-*.patch \ | |
1725 | outdir/0000-*.patch \ | |
1726 | outdir/0001-*.patch \ | |
1727 | 2>errors >out && | |
1728 | ! grep "SUBJECT HERE" errors && | |
1729 | test -n "$(ls msgtxt*)" | |
1730 | ' | |
1731 | ||
1732 | test_cover_addresses () { | |
1733 | header="$1" | |
1734 | shift | |
1735 | clean_fake_sendmail && | |
1736 | rm -fr outdir && | |
1737 | git format-patch --cover-letter -2 -o outdir && | |
1738 | cover=$(echo outdir/0000-*.patch) && | |
1739 | mv $cover cover-to-edit.patch && | |
1740 | perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" && | |
1741 | git send-email \ | |
1742 | --force \ | |
1743 | --from="Example <nobody@example.com>" \ | |
1744 | --no-to --no-cc \ | |
1745 | "$@" \ | |
1746 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1747 | outdir/0000-*.patch \ | |
1748 | outdir/0001-*.patch \ | |
1749 | outdir/0002-*.patch \ | |
1750 | 2>errors >out && | |
1751 | grep "^$header: extra@address.com" msgtxt1 >to1 && | |
1752 | grep "^$header: extra@address.com" msgtxt2 >to2 && | |
1753 | grep "^$header: extra@address.com" msgtxt3 >to3 && | |
1754 | test_line_count = 1 to1 && | |
1755 | test_line_count = 1 to2 && | |
1756 | test_line_count = 1 to3 | |
1757 | } | |
1758 | ||
1759 | test_expect_success $PREREQ 'to-cover adds To to all mail' ' | |
1760 | test_cover_addresses "To" --to-cover | |
1761 | ' | |
1762 | ||
1763 | test_expect_success $PREREQ 'cc-cover adds Cc to all mail' ' | |
1764 | test_cover_addresses "Cc" --cc-cover | |
1765 | ' | |
1766 | ||
1767 | test_expect_success $PREREQ 'tocover adds To to all mail' ' | |
1768 | test_config sendemail.tocover true && | |
1769 | test_cover_addresses "To" | |
1770 | ' | |
1771 | ||
1772 | test_expect_success $PREREQ 'cccover adds Cc to all mail' ' | |
1773 | test_config sendemail.cccover true && | |
1774 | test_cover_addresses "Cc" | |
1775 | ' | |
1776 | ||
1777 | test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' ' | |
1778 | clean_fake_sendmail && | |
1779 | echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt && | |
1780 | git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" && | |
1781 | git config sendemail.aliasfiletype mutt && | |
1782 | git send-email \ | |
1783 | --from="Example <nobody@example.com>" \ | |
1784 | --to=sbd \ | |
1785 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1786 | outdir/0001-*.patch \ | |
1787 | 2>errors >out && | |
1788 | grep "^!somebody@example\.org!$" commandline1 && | |
1789 | grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out | |
1790 | ' | |
1791 | ||
1792 | test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' ' | |
1793 | clean_fake_sendmail && | |
1794 | echo "alias sbd somebody@example.org" >.mailrc && | |
1795 | git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" && | |
1796 | git config sendemail.aliasfiletype mailrc && | |
1797 | git send-email \ | |
1798 | --from="Example <nobody@example.com>" \ | |
1799 | --to=sbd \ | |
1800 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1801 | outdir/0001-*.patch \ | |
1802 | 2>errors >out && | |
1803 | grep "^!somebody@example\.org!$" commandline1 | |
1804 | ' | |
1805 | ||
1806 | test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' ' | |
1807 | clean_fake_sendmail && | |
1808 | echo "alias sbd someone@example.org" >"$HOME/.mailrc" && | |
1809 | git config --replace-all sendemail.aliasesfile "~/.mailrc" && | |
1810 | git config sendemail.aliasfiletype mailrc && | |
1811 | git send-email \ | |
1812 | --from="Example <nobody@example.com>" \ | |
1813 | --to=sbd \ | |
1814 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1815 | outdir/0001-*.patch \ | |
1816 | 2>errors >out && | |
1817 | grep "^!someone@example\.org!$" commandline1 | |
1818 | ' | |
1819 | ||
1820 | test_dump_aliases () { | |
1821 | msg="$1" && shift && | |
1822 | filetype="$1" && shift && | |
1823 | printf '%s\n' "$@" >expect && | |
1824 | cat >.tmp-email-aliases && | |
1825 | ||
1826 | test_expect_success $PREREQ "$msg" ' | |
1827 | clean_fake_sendmail && rm -fr outdir && | |
1828 | git config --replace-all sendemail.aliasesfile \ | |
1829 | "$(pwd)/.tmp-email-aliases" && | |
1830 | git config sendemail.aliasfiletype "$filetype" && | |
1831 | git send-email --dump-aliases 2>errors >actual && | |
1832 | test_cmp expect actual | |
1833 | ' | |
1834 | } | |
1835 | ||
1836 | test_dump_aliases '--dump-aliases sendmail format' \ | |
1837 | 'sendmail' \ | |
1838 | 'abgroup' \ | |
1839 | 'alice' \ | |
1840 | 'bcgrp' \ | |
1841 | 'bob' \ | |
1842 | 'chloe' <<-\EOF | |
1843 | alice: Alice W Land <awol@example.com> | |
1844 | bob: Robert Bobbyton <bob@example.com> | |
1845 | chloe: chloe@example.com | |
1846 | abgroup: alice, bob | |
1847 | bcgrp: bob, chloe, Other <o@example.com> | |
1848 | EOF | |
1849 | ||
1850 | test_dump_aliases '--dump-aliases mutt format' \ | |
1851 | 'mutt' \ | |
1852 | 'alice' \ | |
1853 | 'bob' \ | |
1854 | 'chloe' \ | |
1855 | 'donald' <<-\EOF | |
1856 | alias alice Alice W Land <awol@example.com> | |
1857 | alias donald Donald C Carlton <donc@example.com> | |
1858 | alias bob Robert Bobbyton <bob@example.com> | |
1859 | alias chloe chloe@example.com | |
1860 | EOF | |
1861 | ||
1862 | test_dump_aliases '--dump-aliases mailrc format' \ | |
1863 | 'mailrc' \ | |
1864 | 'alice' \ | |
1865 | 'bob' \ | |
1866 | 'chloe' \ | |
1867 | 'eve' <<-\EOF | |
1868 | alias alice Alice W Land <awol@example.com> | |
1869 | alias eve Eve <eve@example.com> | |
1870 | alias bob Robert Bobbyton <bob@example.com> | |
1871 | alias chloe chloe@example.com | |
1872 | EOF | |
1873 | ||
1874 | test_dump_aliases '--dump-aliases pine format' \ | |
1875 | 'pine' \ | |
1876 | 'alice' \ | |
1877 | 'bob' \ | |
1878 | 'chloe' \ | |
1879 | 'eve' <<-\EOF | |
1880 | alice Alice W Land <awol@example.com> | |
1881 | eve Eve <eve@example.com> | |
1882 | bob Robert Bobbyton <bob@example.com> | |
1883 | chloe chloe@example.com | |
1884 | EOF | |
1885 | ||
1886 | test_dump_aliases '--dump-aliases gnus format' \ | |
1887 | 'gnus' \ | |
1888 | 'alice' \ | |
1889 | 'bob' \ | |
1890 | 'chloe' \ | |
1891 | 'eve' <<-\EOF | |
1892 | (define-mail-alias "alice" "awol@example.com") | |
1893 | (define-mail-alias "eve" "eve@example.com") | |
1894 | (define-mail-alias "bob" "bob@example.com") | |
1895 | (define-mail-alias "chloe" "chloe@example.com") | |
1896 | EOF | |
1897 | ||
1898 | test_expect_success '--dump-aliases must be used alone' ' | |
1899 | test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting | |
1900 | ' | |
1901 | ||
1902 | test_expect_success $PREREQ 'aliases and sendemail.identity' ' | |
1903 | test_must_fail git \ | |
1904 | -c sendemail.identity=cloud \ | |
1905 | -c sendemail.aliasesfile=default-aliases \ | |
1906 | -c sendemail.cloud.aliasesfile=cloud-aliases \ | |
1907 | send-email -1 2>stderr && | |
1908 | test_i18ngrep "cloud-aliases" stderr | |
1909 | ' | |
1910 | ||
1911 | test_sendmail_aliases () { | |
1912 | msg="$1" && shift && | |
1913 | expect="$@" && | |
1914 | cat >.tmp-email-aliases && | |
1915 | ||
1916 | test_expect_success $PREREQ "$msg" ' | |
1917 | clean_fake_sendmail && rm -fr outdir && | |
1918 | git format-patch -1 -o outdir && | |
1919 | git config --replace-all sendemail.aliasesfile \ | |
1920 | "$(pwd)/.tmp-email-aliases" && | |
1921 | git config sendemail.aliasfiletype sendmail && | |
1922 | git send-email \ | |
1923 | --from="Example <nobody@example.com>" \ | |
1924 | --to=alice --to=bcgrp \ | |
1925 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1926 | outdir/0001-*.patch \ | |
1927 | 2>errors >out && | |
1928 | for i in $expect | |
1929 | do | |
1930 | grep "^!$i!$" commandline1 || return 1 | |
1931 | done | |
1932 | ' | |
1933 | } | |
1934 | ||
1935 | test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \ | |
1936 | 'awol@example\.com' \ | |
1937 | 'bob@example\.com' \ | |
1938 | 'chloe@example\.com' \ | |
1939 | 'o@example\.com' <<-\EOF | |
1940 | alice: Alice W Land <awol@example.com> | |
1941 | bob: Robert Bobbyton <bob@example.com> | |
1942 | # this is a comment | |
1943 | # this is also a comment | |
1944 | chloe: chloe@example.com | |
1945 | abgroup: alice, bob | |
1946 | bcgrp: bob, chloe, Other <o@example.com> | |
1947 | EOF | |
1948 | ||
1949 | test_sendmail_aliases 'sendmail aliases line folding' \ | |
1950 | alice1 \ | |
1951 | bob1 bob2 \ | |
1952 | chuck1 chuck2 \ | |
1953 | darla1 darla2 darla3 \ | |
1954 | elton1 elton2 elton3 \ | |
1955 | fred1 fred2 \ | |
1956 | greg1 <<-\EOF | |
1957 | alice: alice1 | |
1958 | bob: bob1,\ | |
1959 | bob2 | |
1960 | chuck: chuck1, | |
1961 | chuck2 | |
1962 | darla: darla1,\ | |
1963 | darla2, | |
1964 | darla3 | |
1965 | elton: elton1, | |
1966 | elton2,\ | |
1967 | elton3 | |
1968 | fred: fred1,\ | |
1969 | fred2 | |
1970 | greg: greg1 | |
1971 | bcgrp: bob, chuck, darla, elton, fred, greg | |
1972 | EOF | |
1973 | ||
1974 | test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \ | |
1975 | alice1 bob1 <<-\EOF | |
1976 | alice: alice1 | |
1977 | bcgrp: bob1\ | |
1978 | EOF | |
1979 | ||
1980 | test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF | |
1981 | EOF | |
1982 | ||
1983 | test_expect_success $PREREQ 'alias support in To header' ' | |
1984 | clean_fake_sendmail && | |
1985 | echo "alias sbd someone@example.org" >.mailrc && | |
1986 | test_config sendemail.aliasesfile ".mailrc" && | |
1987 | test_config sendemail.aliasfiletype mailrc && | |
1988 | git format-patch --stdout -1 --to=sbd >aliased.patch && | |
1989 | git send-email \ | |
1990 | --from="Example <nobody@example.com>" \ | |
1991 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1992 | aliased.patch \ | |
1993 | 2>errors >out && | |
1994 | grep "^!someone@example\.org!$" commandline1 | |
1995 | ' | |
1996 | ||
1997 | test_expect_success $PREREQ 'alias support in Cc header' ' | |
1998 | clean_fake_sendmail && | |
1999 | echo "alias sbd someone@example.org" >.mailrc && | |
2000 | test_config sendemail.aliasesfile ".mailrc" && | |
2001 | test_config sendemail.aliasfiletype mailrc && | |
2002 | git format-patch --stdout -1 --cc=sbd >aliased.patch && | |
2003 | git send-email \ | |
2004 | --from="Example <nobody@example.com>" \ | |
2005 | --smtp-server="$(pwd)/fake.sendmail" \ | |
2006 | aliased.patch \ | |
2007 | 2>errors >out && | |
2008 | grep "^!someone@example\.org!$" commandline1 | |
2009 | ' | |
2010 | ||
2011 | test_expect_success $PREREQ 'tocmd works with aliases' ' | |
2012 | clean_fake_sendmail && | |
2013 | echo "alias sbd someone@example.org" >.mailrc && | |
2014 | test_config sendemail.aliasesfile ".mailrc" && | |
2015 | test_config sendemail.aliasfiletype mailrc && | |
2016 | git format-patch --stdout -1 >tocmd.patch && | |
2017 | echo tocmd--sbd >>tocmd.patch && | |
2018 | git send-email \ | |
2019 | --from="Example <nobody@example.com>" \ | |
2020 | --to-cmd=./tocmd-sed \ | |
2021 | --smtp-server="$(pwd)/fake.sendmail" \ | |
2022 | tocmd.patch \ | |
2023 | 2>errors >out && | |
2024 | grep "^!someone@example\.org!$" commandline1 | |
2025 | ' | |
2026 | ||
2027 | test_expect_success $PREREQ 'cccmd works with aliases' ' | |
2028 | clean_fake_sendmail && | |
2029 | echo "alias sbd someone@example.org" >.mailrc && | |
2030 | test_config sendemail.aliasesfile ".mailrc" && | |
2031 | test_config sendemail.aliasfiletype mailrc && | |
2032 | git format-patch --stdout -1 >cccmd.patch && | |
2033 | echo cccmd--sbd >>cccmd.patch && | |
2034 | git send-email \ | |
2035 | --from="Example <nobody@example.com>" \ | |
2036 | --cc-cmd=./cccmd-sed \ | |
2037 | --smtp-server="$(pwd)/fake.sendmail" \ | |
2038 | cccmd.patch \ | |
2039 | 2>errors >out && | |
2040 | grep "^!someone@example\.org!$" commandline1 | |
2041 | ' | |
2042 | ||
2043 | do_xmailer_test () { | |
2044 | expected=$1 params=$2 && | |
2045 | git format-patch -1 && | |
2046 | git send-email \ | |
2047 | --from="Example <nobody@example.com>" \ | |
2048 | --to=someone@example.com \ | |
2049 | --smtp-server="$(pwd)/fake.sendmail" \ | |
2050 | $params \ | |
2051 | 0001-*.patch \ | |
2052 | 2>errors >out && | |
2053 | { grep '^X-Mailer:' out || :; } >mailer && | |
2054 | test_line_count = $expected mailer | |
2055 | } | |
2056 | ||
2057 | test_expect_success $PREREQ '--[no-]xmailer without any configuration' ' | |
2058 | do_xmailer_test 1 "--xmailer" && | |
2059 | do_xmailer_test 0 "--no-xmailer" | |
2060 | ' | |
2061 | ||
2062 | test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' ' | |
2063 | test_config sendemail.xmailer true && | |
2064 | do_xmailer_test 1 "" && | |
2065 | do_xmailer_test 0 "--no-xmailer" && | |
2066 | do_xmailer_test 1 "--xmailer" | |
2067 | ' | |
2068 | ||
2069 | test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' ' | |
2070 | test_config sendemail.xmailer false && | |
2071 | do_xmailer_test 0 "" && | |
2072 | do_xmailer_test 0 "--no-xmailer" && | |
2073 | do_xmailer_test 1 "--xmailer" | |
2074 | ' | |
2075 | ||
2076 | test_expect_success $PREREQ 'setup expected-list' ' | |
2077 | git send-email \ | |
2078 | --dry-run \ | |
2079 | --from="Example <from@example.com>" \ | |
2080 | --to="To 1 <to1@example.com>" \ | |
2081 | --to="to2@example.com" \ | |
2082 | --to="to3@example.com" \ | |
2083 | --cc="Cc 1 <cc1@example.com>" \ | |
2084 | --cc="Cc2 <cc2@example.com>" \ | |
2085 | --bcc="bcc1@example.com" \ | |
2086 | --bcc="bcc2@example.com" \ | |
2087 | 0001-add-main.patch | replace_variable_fields \ | |
2088 | >expected-list | |
2089 | ' | |
2090 | ||
2091 | test_expect_success $PREREQ 'use email list in --cc --to and --bcc' ' | |
2092 | git send-email \ | |
2093 | --dry-run \ | |
2094 | --from="Example <from@example.com>" \ | |
2095 | --to="To 1 <to1@example.com>, to2@example.com" \ | |
2096 | --to="to3@example.com" \ | |
2097 | --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \ | |
2098 | --bcc="bcc1@example.com, bcc2@example.com" \ | |
2099 | 0001-add-main.patch | replace_variable_fields \ | |
2100 | >actual-list && | |
2101 | test_cmp expected-list actual-list | |
2102 | ' | |
2103 | ||
2104 | test_expect_success $PREREQ 'aliases work with email list' ' | |
2105 | echo "alias to2 to2@example.com" >.mutt && | |
2106 | echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt && | |
2107 | test_config sendemail.aliasesfile ".mutt" && | |
2108 | test_config sendemail.aliasfiletype mutt && | |
2109 | git send-email \ | |
2110 | --dry-run \ | |
2111 | --from="Example <from@example.com>" \ | |
2112 | --to="To 1 <to1@example.com>, to2, to3@example.com" \ | |
2113 | --cc="cc1, Cc2 <cc2@example.com>" \ | |
2114 | --bcc="bcc1@example.com, bcc2@example.com" \ | |
2115 | 0001-add-main.patch | replace_variable_fields \ | |
2116 | >actual-list && | |
2117 | test_cmp expected-list actual-list | |
2118 | ' | |
2119 | ||
2120 | test_expect_success $PREREQ 'leading and trailing whitespaces are removed' ' | |
2121 | echo "alias to2 to2@example.com" >.mutt && | |
2122 | echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt && | |
2123 | test_config sendemail.aliasesfile ".mutt" && | |
2124 | test_config sendemail.aliasfiletype mutt && | |
2125 | TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) && | |
2126 | TO2=$(echo "QZto2" | qz_to_tab_space) && | |
2127 | CC1=$(echo "cc1" | append_cr) && | |
2128 | BCC1=$(echo " bcc1@example.com Q" | q_to_nul) && | |
2129 | git send-email \ | |
2130 | --dry-run \ | |
2131 | --from=" Example <from@example.com>" \ | |
2132 | --to="$TO1" \ | |
2133 | --to="$TO2" \ | |
2134 | --to=" to3@example.com " \ | |
2135 | --cc="$CC1" \ | |
2136 | --cc="Cc2 <cc2@example.com>" \ | |
2137 | --bcc="$BCC1" \ | |
2138 | --bcc="bcc2@example.com" \ | |
2139 | 0001-add-main.patch | replace_variable_fields \ | |
2140 | >actual-list && | |
2141 | test_cmp expected-list actual-list | |
2142 | ' | |
2143 | ||
2144 | test_expect_success $PREREQ 'invoke hook' ' | |
2145 | mkdir -p .git/hooks && | |
2146 | ||
2147 | write_script .git/hooks/sendemail-validate <<-\EOF && | |
2148 | # test that we have the correct environment variable, pwd, and | |
2149 | # argument | |
2150 | case "$GIT_DIR" in | |
2151 | *.git) | |
2152 | true | |
2153 | ;; | |
2154 | *) | |
2155 | false | |
2156 | ;; | |
2157 | esac && | |
2158 | test -f 0001-add-main.patch && | |
2159 | grep "add main" "$1" | |
2160 | EOF | |
2161 | ||
2162 | mkdir subdir && | |
2163 | ( | |
2164 | # Test that it works even if we are not at the root of the | |
2165 | # working tree | |
2166 | cd subdir && | |
2167 | git send-email \ | |
2168 | --from="Example <nobody@example.com>" \ | |
2169 | --to=nobody@example.com \ | |
2170 | --smtp-server="$(pwd)/../fake.sendmail" \ | |
2171 | ../0001-add-main.patch && | |
2172 | ||
2173 | # Verify error message when a patch is rejected by the hook | |
2174 | sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch && | |
2175 | test_must_fail git send-email \ | |
2176 | --from="Example <nobody@example.com>" \ | |
2177 | --to=nobody@example.com \ | |
2178 | --smtp-server="$(pwd)/../fake.sendmail" \ | |
2179 | ../another.patch 2>err && | |
2180 | test_i18ngrep "rejected by sendemail-validate hook" err | |
2181 | ) | |
2182 | ' | |
2183 | ||
2184 | test_expect_success $PREREQ 'test that send-email works outside a repo' ' | |
2185 | nongit git send-email \ | |
2186 | --from="Example <nobody@example.com>" \ | |
2187 | --to=nobody@example.com \ | |
2188 | --smtp-server="$(pwd)/fake.sendmail" \ | |
2189 | "$(pwd)/0001-add-main.patch" | |
2190 | ' | |
2191 | ||
2192 | test_expect_success $PREREQ 'test that sendmail config is rejected' ' | |
2193 | test_config sendmail.program sendmail && | |
2194 | test_must_fail git send-email \ | |
2195 | --from="Example <nobody@example.com>" \ | |
2196 | --to=nobody@example.com \ | |
2197 | --smtp-server="$(pwd)/fake.sendmail" \ | |
2198 | HEAD^ 2>err && | |
2199 | test_i18ngrep "found configuration options for '"'"sendmail"'"'" err | |
2200 | ' | |
2201 | ||
2202 | test_expect_success $PREREQ 'test that sendmail config rejection is specific' ' | |
2203 | test_config resendmail.program sendmail && | |
2204 | git send-email \ | |
2205 | --from="Example <nobody@example.com>" \ | |
2206 | --to=nobody@example.com \ | |
2207 | --smtp-server="$(pwd)/fake.sendmail" \ | |
2208 | HEAD^ | |
2209 | ' | |
2210 | ||
2211 | test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' ' | |
2212 | test_config sendmail.program sendmail && | |
2213 | test_config sendemail.forbidSendmailVariables false && | |
2214 | git send-email \ | |
2215 | --from="Example <nobody@example.com>" \ | |
2216 | --to=nobody@example.com \ | |
2217 | --smtp-server="$(pwd)/fake.sendmail" \ | |
2218 | HEAD^ | |
2219 | ' | |
2220 | ||
2221 | test_done |