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