Added Message-Id to messages in test suite.
[mmh] / test / dist / test-dist
1 #!/bin/sh
2 ######################################################
3 #
4 # Test dist
5 #
6 ######################################################
7
8 set -e
9
10 if test -z "${MH_OBJ_DIR}"; then
11     srcdir=`dirname $0`/../..
12     MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
13 fi
14
15 . "$MH_OBJ_DIR/test/common.sh"
16
17 setup_test
18
19 expected=$MH_TEST_DIR/$$.expected
20 expected_err=$MH_TEST_DIR/$$.expected_err
21 actual=$MH_TEST_DIR/$$.actual
22 actual_err=$MH_TEST_DIR/$$.actual_err
23 localmbox=`${MH_LIB_DIR}/ap -format "%(localmbox)" 0`
24
25 #### Use sendmail/pipe below to override default mts.
26 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
27 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
28 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
29 MHMTSCONF="$mts_fakesendmail"
30
31 # arguments: dist switches
32 test_dist ()
33 {
34   printf 'send\n' | dist "$@" >/dev/null
35
36   # fakesendmail drops the message and any cc's into this mbox.
37   mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
38   inc -silent -file "$mbox"
39   rm -f "$mbox" "$mbox.map"
40
41   # It's hard to calculate the exact Date: header post is going to
42   # use, so we'll just use sed to remove the actual date so we can
43   # easily compare it against our "correct" output.
44   sed -e 's/^Resent-Date:.*/Resent-Date:/' `mhpath last` > "$actual"
45
46   check "$expected" "$actual"
47 }
48
49
50 # check -help
51 cat >"$expected" <<EOF
52 Usage: dist [+folder] [msg] [switches]
53   switches are:
54   -[no]annotate
55   -draftfolder +folder
56   -draftmessage msg
57   -nodraftfolder
58   -editor editor
59   -noedit
60   -form formfile
61   -[no]inplace
62   -whatnowproc program
63   -nowhatnowproc
64   -version
65   -help
66   -from address
67   -to address
68   -cc address
69   -fcc mailbox
70   -width columns
71   -[no]atfile
72 EOF
73
74 dist -help >"$actual" 2>&1
75 check "$expected" "$actual"
76
77 # check -version
78 case `dist -v` in
79   dist\ --*) ;;
80   *        ) printf '%s: dist -v generated unexpected output\n' "$0" >&2
81              failed=`expr ${failed:-0} + 1`;;
82 esac
83
84 # check unknown switch
85 run_test "dist -nonexistent" 'dist: -nonexistent unknown'
86
87 folder +outbox -create -fast >/dev/null
88 folder +inbox -fast 1 >/dev/null
89
90 # For most tests, use -nowhatnow and just check that the draft
91 # looks correct.
92
93 # check basic dist operation, including -noedit and -to
94 cat >"$expected" <<EOF
95 From: Test1 <test1@example.com>
96 To: Some User <user@example.com>
97 Date: Fri, 29 Sep 2006 00:00:00
98 Message-Id: 1@test.nmh
99 Subject: Testing message 1
100 Resent-From: ${localmbox}
101 Resent-To: somebody@example.com
102 Resent-Date:
103
104 This is message number 1
105 EOF
106
107 test_dist -noedit -to somebody@example.com
108
109 # check +folder and msg
110 folder +outbox -fast >/dev/null
111
112 cat >"$expected" <<EOF
113 From: Test1 <test1@example.com>
114 To: Some User <user@example.com>
115 Date: Fri, 29 Sep 2006 00:00:00
116 Message-Id: 1@test.nmh
117 Subject: Testing message 1
118 Resent-From: ${localmbox}
119 Resent-To: somebody@example.com
120 Resent-Date:
121
122 This is message number 1
123 EOF
124
125 test_dist +inbox 1 -noedit -to somebody@example.com
126
127 # check -form
128 cat >"${MH_TEST_DIR}/Mail/distform" <<'EOF'
129 Resent-From: me@example.com
130 Resent-To: you@example.com
131 EOF
132
133 cat >"$expected" <<EOF
134 From: Test1 <test1@example.com>
135 To: Some User <user@example.com>
136 Date: Fri, 29 Sep 2006 00:00:00
137 Message-Id: 1@test.nmh
138 Subject: Testing message 1
139 Resent-From: me@example.com
140 Resent-To: you@example.com
141 Resent-Date:
142
143 This is message number 1
144 EOF
145
146 test_dist 1 -noedit -form "${MH_TEST_DIR}"/Mail/distform
147
148 rm "${MH_TEST_DIR}"/Mail/distform
149
150 # check -annotate
151 cat >"$expected" <<EOF
152 From: Test2 <test2@example.com>
153 To: Some User <user@example.com>
154 Date: Fri, 29 Sep 2006 00:00:00
155 Message-Id: 2@test.nmh
156 Subject: Testing message 2
157 Resent-From: ${localmbox}
158 Resent-To: somebody@example.com
159 Resent-Date:
160
161 This is message number 2
162 EOF
163
164 test_dist 2 -noedit -to somebody@example.com -annotate
165
166 cat >"$expected" <<EOF
167 Resent:
168 Resent: somebody@example.com
169 From: Test2 <test2@example.com>
170 To: Some User <user@example.com>
171 Date: Fri, 29 Sep 2006 00:00:00
172 Message-Id: 2@test.nmh
173 Subject: Testing message 2
174
175 This is message number 2
176 EOF
177
178 # The annotation is done by a separate process, so we need to wait for
179 # it to complete.
180 i=1
181 until grep '^Resent:' "${MH_TEST_DIR}"/Mail/inbox/2 >/dev/null; do
182   sleep 2
183   arith_eval $i + 1
184   i=$arith_val
185   if [ $i -gt 60 ]; then
186     printf '%s: -annotate failed, will not wait any longer\n' "$0"
187     break
188   fi
189 done
190
191 # Strip date from line of this form:
192 # Resent: Sat, 06 Oct 2012 08:24:08 -0500
193 sed -e 's/^Resent:.*:.*/Resent:/' "${MH_TEST_DIR}"/Mail/inbox/2 >"$actual"
194
195 check "$expected" "$actual"
196
197 # check -noannotate
198 cat >"$expected" <<EOF
199 From: Test1 <test1@example.com>
200 To: Some User <user@example.com>
201 Date: Fri, 29 Sep 2006 00:00:00
202 Message-Id: 1@test.nmh
203 Subject: Testing message 1
204 Resent-From: ${localmbox}
205 Resent-To: somebody@example.com
206 Resent-Date:
207
208 This is message number 1
209 EOF
210
211 test_dist 1 -noedit -to somebody@example.com -annotate -noannotate
212
213 cat >"$expected" <<EOF
214 From: Test1 <test1@example.com>
215 To: Some User <user@example.com>
216 Date: Fri, 29 Sep 2006 00:00:00
217 Message-Id: 1@test.nmh
218 Subject: Testing message 1
219
220 This is message number 1
221 EOF
222
223 check "${MH_TEST_DIR}"/Mail/inbox/1 "$expected" 'keep first'
224
225 check_for_hard_links
226 if [ $hard_links_supported -eq 1 ]; then
227   # check -noinplace
228   # Hard link the message and verify that the new one doesn't get annotated.
229   cp "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.copy"
230   ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
231   cat >"$expected" <<EOF
232 From: Test8 <test8@example.com>
233 To: Some User <user@example.com>
234 Date: Fri, 29 Sep 2006 00:00:00
235 Message-Id: 8@test.nmh
236 Subject: Testing message 8
237 Resent-From: ${localmbox}
238 Resent-To: somebody@example.com
239 Resent-Date:
240
241 This is message number 8
242 EOF
243   test_dist 8 -noedit -to somebody@example.com -annotate -noinplace
244   mv -f "${MH_TEST_DIR}/Mail/inbox/8.copy" "${MH_TEST_DIR}/Mail/inbox/8"
245   check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link" \
246     'keep first'
247
248   # check -inplace
249   # Hard link the message and verify that the new one does get annotated.
250   ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
251   cat >"$expected" <<EOF
252 From: Test8 <test8@example.com>
253 To: Some User <user@example.com>
254 Date: Fri, 29 Sep 2006 00:00:00
255 Message-Id: 8@test.nmh
256 Subject: Testing message 8
257 Resent-From: ${localmbox}
258 Resent-To: somebody@example.com
259 Resent-Date:
260
261 This is message number 8
262 EOF
263   test_dist 8 -noedit -to somebody@example.com -annotate -noinplace -inplace
264   check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
265 fi
266
267 # check -draftfolder
268 cat >"$expected" <<EOF
269 From: Test3 <test3@example.com>
270 To: Some User <user@example.com>
271 Date: Fri, 29 Sep 2006 00:00:00
272 Message-Id: 3@test.nmh
273 Subject: Testing message 3
274 Resent-From: ${localmbox}
275 Resent-To: somebody@example.com
276 Resent-Date:
277
278 This is message number 3
279 EOF
280
281 test_dist 3 -noedit -to somebody@example.com -draftfolder drafts
282
283 # check -draftmsg
284 cat >"$expected" <<EOF
285 From: Test3 <test3@example.com>
286 To: Some User <user@example.com>
287 Date: Fri, 29 Sep 2006 00:00:00
288 Message-Id: 3@test.nmh
289 Subject: Testing message 3
290 Resent-From: ${localmbox}
291 Resent-To: somebody@example.com
292 Resent-Date:
293
294 This is message number 3
295 EOF
296
297 touch $MH_TEST_DIR/Mail/drafts/3
298 test_dist 3 -noedit -to somebody@example.com -draftfolder drafts -draftmessage 2
299
300 # check -nodraftfolder
301 cat >"$expected" <<EOF
302 From: Test3 <test3@example.com>
303 To: Some User <user@example.com>
304 Date: Fri, 29 Sep 2006 00:00:00
305 Message-Id: 3@test.nmh
306 Subject: Testing message 3
307 Resent-From: ${localmbox}
308 Resent-To: somebody@example.com
309 Resent-Date:
310
311 This is message number 3
312 EOF
313
314 test_dist 3 -noedit -to somebody@example.com -draftfolder nonexistent \
315   -nodraftfolder
316 if test -d "${MH_TEST_DIR}/Mail/nonexistent"; then
317   echo "$0: -nodraftfolder test failed."
318   failed=`expr ${failed:-0} + 1`
319 fi
320
321 # check -from
322 cat >"$expected" <<EOF
323 From: Test1 <test1@example.com>
324 To: Some User <user@example.com>
325 Date: Fri, 29 Sep 2006 00:00:00
326 Message-Id: 1@test.nmh
327 Subject: Testing message 1
328 Resent-From: me@example.com
329 Resent-To: somebody@example.com
330 Resent-Date:
331
332 This is message number 1
333 EOF
334
335 test_dist 1 -noedit -to somebody@example.com -from me@example.com
336
337 # check -cc
338 cat >"$expected" <<EOF
339 From: Test1 <test1@example.com>
340 To: Some User <user@example.com>
341 Date: Fri, 29 Sep 2006 00:00:00
342 Message-Id: 1@test.nmh
343 Subject: Testing message 1
344 Resent-From: ${localmbox}
345 Resent-To: somebody@example.com
346 Resent-cc: cc@example.com
347 Resent-Date:
348
349 This is message number 1
350 EOF
351
352 test_dist 1 -noedit -to somebody@example.com -cc cc@example.com
353
354 # check -fcc
355 cat >"$expected" <<EOF
356 From: Test1 <test1@example.com>
357 To: Some User <user@example.com>
358 Date: Fri, 29 Sep 2006 00:00:00
359 Message-Id: 1@test.nmh
360 Subject: Testing message 1
361 Resent-From: ${localmbox}
362 Resent-To: somebody@example.com
363 Resent-Date:
364
365 This is message number 1
366 EOF
367
368 test_dist 1 -noedit -to somebody@example.com -fcc outbox
369 run_test 'scan +outbox -width 6' '   1 '
370
371 cat >"$expected" <<EOF
372 From: Test1 <test1@example.com>
373 To: Some User <user@example.com>
374 Date: Fri, 29 Sep 2006 00:00:00
375 Message-Id: 1@test.nmh
376 Subject: Testing message 1
377 Resent-From: ${localmbox}
378 Resent-To: somebody@example.com
379 Resent-Date:
380
381 This is message number 1
382 EOF
383
384 test_dist +inbox 1 -noedit -to somebody@example.com -fcc +outbox
385 run_test 'scan +outbox -width 6 2' '   2 '
386
387
388 exit ${failed:-0}