send-email: handle multiple Cc addresses when reading mbox message
[alt-git.git] / t / t9001-send-email.sh
blob63ab88bfc832b91edaf50d829c94385c5b32f2d2
1 #!/bin/sh
3 test_description='git send-email'
4 . ./test-lib.sh
6 PROG='git send-email'
7 test_expect_success \
8 'prepare reference tree' \
9 'echo "1A quick brown fox jumps over the" >file &&
10 echo "lazy dog" >>file &&
11 git add file &&
12 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
14 test_expect_success \
15 'Setup helper tool' \
16 '(echo "#!$SHELL_PATH"
17 echo shift
18 echo output=1
19 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
20 echo for a
21 echo do
22 echo " echo \"!\$a!\""
23 echo "done >commandline\$output"
24 echo "cat > msgtxt\$output"
25 ) >fake.sendmail &&
26 chmod +x ./fake.sendmail &&
27 git add fake.sendmail &&
28 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
30 clean_fake_sendmail() {
31 rm -f commandline* msgtxt*
34 test_expect_success 'Extract patches' '
35 patches=`git format-patch --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
38 test_expect_success 'Send patches' '
39 git send-email --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
42 cat >expected <<\EOF
43 !nobody@example.com!
44 !author@example.com!
45 !one@example.com!
46 !two@example.com!
47 EOF
48 test_expect_success \
49 'Verify commandline' \
50 'diff commandline1 expected'
52 cat >expected-show-all-headers <<\EOF
53 0001-Second.patch
54 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
55 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
56 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
57 Dry-OK. Log says:
58 Server: relay.example.com
59 MAIL FROM:<from@example.com>
60 RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<bcc@example.com>
61 From: Example <from@example.com>
62 To: to@example.com
63 Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com
64 Subject: [PATCH 1/1] Second.
65 Date: DATE-STRING
66 Message-Id: MESSAGE-ID-STRING
67 X-Mailer: X-MAILER-STRING
68 In-Reply-To: <unique-message-id@example.com>
69 References: <unique-message-id@example.com>
71 Result: OK
72 EOF
74 test_expect_success 'Show all headers' '
75 git send-email \
76 --dry-run \
77 --from="Example <from@example.com>" \
78 --to=to@example.com \
79 --cc=cc@example.com \
80 --bcc=bcc@example.com \
81 --in-reply-to="<unique-message-id@example.com>" \
82 --smtp-server relay.example.com \
83 $patches |
84 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
85 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
86 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
87 >actual-show-all-headers &&
88 test_cmp expected-show-all-headers actual-show-all-headers
91 z8=zzzzzzzz
92 z64=$z8$z8$z8$z8$z8$z8$z8$z8
93 z512=$z64$z64$z64$z64$z64$z64$z64$z64
94 test_expect_success 'reject long lines' '
95 clean_fake_sendmail &&
96 cp $patches longline.patch &&
97 echo $z512$z512 >>longline.patch &&
98 test_must_fail git send-email \
99 --from="Example <nobody@example.com>" \
100 --to=nobody@example.com \
101 --smtp-server="$(pwd)/fake.sendmail" \
102 $patches longline.patch \
103 2>errors &&
104 grep longline.patch errors
107 test_expect_success 'no patch was sent' '
108 ! test -e commandline1
111 test_expect_success 'Author From: in message body' '
112 clean_fake_sendmail &&
113 git send-email \
114 --from="Example <nobody@example.com>" \
115 --to=nobody@example.com \
116 --smtp-server="$(pwd)/fake.sendmail" \
117 $patches &&
118 sed "1,/^$/d" < msgtxt1 > msgbody1
119 grep "From: A <author@example.com>" msgbody1
122 test_expect_success 'Author From: not in message body' '
123 clean_fake_sendmail &&
124 git send-email \
125 --from="A <author@example.com>" \
126 --to=nobody@example.com \
127 --smtp-server="$(pwd)/fake.sendmail" \
128 $patches &&
129 sed "1,/^$/d" < msgtxt1 > msgbody1
130 ! grep "From: A <author@example.com>" msgbody1
133 test_expect_success 'allow long lines with --no-validate' '
134 git send-email \
135 --from="Example <nobody@example.com>" \
136 --to=nobody@example.com \
137 --smtp-server="$(pwd)/fake.sendmail" \
138 --novalidate \
139 $patches longline.patch \
140 2>errors
143 test_expect_success 'Invalid In-Reply-To' '
144 clean_fake_sendmail &&
145 git send-email \
146 --from="Example <nobody@example.com>" \
147 --to=nobody@example.com \
148 --in-reply-to=" " \
149 --smtp-server="$(pwd)/fake.sendmail" \
150 $patches
151 2>errors
152 ! grep "^In-Reply-To: < *>" msgtxt1
155 test_expect_success 'Valid In-Reply-To when prompting' '
156 clean_fake_sendmail &&
157 (echo "From Example <from@example.com>"
158 echo "To Example <to@example.com>"
159 echo ""
160 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
161 --smtp-server="$(pwd)/fake.sendmail" \
162 $patches 2>errors &&
163 ! grep "^In-Reply-To: < *>" msgtxt1
166 test_expect_success 'setup fake editor' '
167 (echo "#!$SHELL_PATH" &&
168 echo "echo fake edit >>\"\$1\""
169 ) >fake-editor &&
170 chmod +x fake-editor
173 test_set_editor "$(pwd)/fake-editor"
175 test_expect_success '--compose works' '
176 clean_fake_sendmail &&
177 echo y | \
178 GIT_SEND_EMAIL_NOTTY=1 \
179 git send-email \
180 --compose --subject foo \
181 --from="Example <nobody@example.com>" \
182 --to=nobody@example.com \
183 --smtp-server="$(pwd)/fake.sendmail" \
184 $patches \
185 2>errors
188 test_expect_success 'first message is compose text' '
189 grep "^fake edit" msgtxt1
192 test_expect_success 'second message is patch' '
193 grep "Subject:.*Second" msgtxt2
196 cat >expected-show-all-headers <<\EOF
197 0001-Second.patch
198 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
199 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
200 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
201 Dry-OK. Log says:
202 Server: relay.example.com
203 MAIL FROM:<from@example.com>
204 RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
205 From: Example <from@example.com>
206 To: to@example.com
207 Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com
208 Subject: [PATCH 1/1] Second.
209 Date: DATE-STRING
210 Message-Id: MESSAGE-ID-STRING
211 X-Mailer: X-MAILER-STRING
213 Result: OK
216 test_expect_success 'sendemail.cc set' '
217 git config sendemail.cc cc@example.com &&
218 git send-email \
219 --dry-run \
220 --from="Example <from@example.com>" \
221 --to=to@example.com \
222 --smtp-server relay.example.com \
223 $patches |
224 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
225 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
226 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
227 >actual-show-all-headers &&
228 test_cmp expected-show-all-headers actual-show-all-headers
231 cat >expected-show-all-headers <<\EOF
232 0001-Second.patch
233 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
234 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
235 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
236 Dry-OK. Log says:
237 Server: relay.example.com
238 MAIL FROM:<from@example.com>
239 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
240 From: Example <from@example.com>
241 To: to@example.com
242 Cc: A <author@example.com>, One <one@example.com>, two@example.com
243 Subject: [PATCH 1/1] Second.
244 Date: DATE-STRING
245 Message-Id: MESSAGE-ID-STRING
246 X-Mailer: X-MAILER-STRING
248 Result: OK
251 test_expect_success 'sendemail.cc unset' '
252 git config --unset sendemail.cc &&
253 git send-email \
254 --dry-run \
255 --from="Example <from@example.com>" \
256 --to=to@example.com \
257 --smtp-server relay.example.com \
258 $patches |
259 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
260 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
261 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
262 >actual-show-all-headers &&
263 test_cmp expected-show-all-headers actual-show-all-headers
266 test_expect_success '--compose adds MIME for utf8 body' '
267 clean_fake_sendmail &&
268 (echo "#!$SHELL_PATH" &&
269 echo "echo utf8 body: àéìöú >>\"\$1\""
270 ) >fake-editor-utf8 &&
271 chmod +x fake-editor-utf8 &&
272 echo y | \
273 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
274 GIT_SEND_EMAIL_NOTTY=1 \
275 git send-email \
276 --compose --subject foo \
277 --from="Example <nobody@example.com>" \
278 --to=nobody@example.com \
279 --smtp-server="$(pwd)/fake.sendmail" \
280 $patches &&
281 grep "^utf8 body" msgtxt1 &&
282 grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
285 test_expect_success '--compose respects user mime type' '
286 clean_fake_sendmail &&
287 (echo "#!$SHELL_PATH" &&
288 echo "(echo MIME-Version: 1.0"
289 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
290 echo " echo Content-Transfer-Encoding: 8bit"
291 echo " echo Subject: foo"
292 echo " echo "
293 echo " echo utf8 body: àéìöú) >\"\$1\""
294 ) >fake-editor-utf8-mime &&
295 chmod +x fake-editor-utf8-mime &&
296 echo y | \
297 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
298 GIT_SEND_EMAIL_NOTTY=1 \
299 git send-email \
300 --compose --subject foo \
301 --from="Example <nobody@example.com>" \
302 --to=nobody@example.com \
303 --smtp-server="$(pwd)/fake.sendmail" \
304 $patches &&
305 grep "^utf8 body" msgtxt1 &&
306 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
307 ! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
310 test_expect_success '--compose adds MIME for utf8 subject' '
311 clean_fake_sendmail &&
312 echo y | \
313 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
314 GIT_SEND_EMAIL_NOTTY=1 \
315 git send-email \
316 --compose --subject utf8-sübjëct \
317 --from="Example <nobody@example.com>" \
318 --to=nobody@example.com \
319 --smtp-server="$(pwd)/fake.sendmail" \
320 $patches &&
321 grep "^fake edit" msgtxt1 &&
322 grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
325 test_expect_success 'detects ambiguous reference/file conflict' '
326 echo master > master &&
327 git add master &&
328 git commit -m"add master" &&
329 test_must_fail git send-email --dry-run master 2>errors &&
330 grep disambiguate errors
333 test_expect_success 'feed two files' '
334 rm -fr outdir &&
335 git format-patch -2 -o outdir &&
336 GIT_SEND_EMAIL_NOTTY=1 git send-email \
337 --dry-run \
338 --from="Example <nobody@example.com>" \
339 --to=nobody@example.com \
340 outdir/000?-*.patch 2>errors >out &&
341 grep "^Subject: " out >subjects &&
342 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
343 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
346 test_done