]> diplodocus.org Git - nmh/blob - test/mhstore/test-mhstore
Added start_test/finish_test.
[nmh] / test / mhstore / test-mhstore
1 #!/bin/sh
2 ######################################################
3 #
4 # Test mhstore
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/test-mhstore$$.expected"
20 expected2="$MH_TEST_DIR/test-mhstore$$.expected2"
21 expected_err="$MH_TEST_DIR/test-mhmail$$.expected_err"
22 actual="$MH_TEST_DIR/test-mhstore$$.actual"
23 actual_err="$MH_TEST_DIR/test-mhmail$$.actual_err"
24
25 cd "$MH_TEST_DIR"
26
27 # check with no options and no current message
28 start_test 'with no options and no current message'
29 run_test 'mhstore' 'mhstore: no cur message'
30
31 # check with no options and current message
32 start_test 'with no options and current message'
33 folder +inbox 5 >/dev/null
34 cat >"$expected" <<'EOF'
35 This is message number 5
36 EOF
37 run_test 'mhstore' 'storing message 5 as file 5.txt'
38 check "$expected" 5.txt 'keep first'
39
40 # check with folder and current message
41 start_test 'with folder and current message'
42 run_test 'mhstore +inbox' 'storing message 5 as file 5.txt'
43 check "$expected" 5.txt 'keep first'
44
45 # check with specified message
46 start_test 'with specified message'
47 run_test 'mhstore 5' 'storing message 5 as file 5.txt'
48 check "$expected" 5.txt 'keep first'
49
50 # check -file
51 start_test '-file'
52 run_test "mhstore -file $MH_TEST_DIR/Mail/inbox/5" \
53 "storing message $MH_TEST_DIR/Mail/inbox/5 as file 5.txt"
54 check "$expected" 5.txt 'keep first'
55
56 # check -file -
57 start_test '-file -'
58 stored_contents=`run_prog mhstore -file - < $MH_TEST_DIR/Mail/inbox/5 2>&1 | \
59 sed 's/.*as file //'`
60 check "$expected" "$stored_contents" 'keep first'
61
62 # check -outfile and -noverbose
63 start_test '-outfile and -noverbose'
64 run_prog mhstore 5 -noverbose -outfile "$actual" >"$actual_err" 2>&1
65 printf '' >"$expected_err"
66 check "$expected" "$actual" 'keep first'
67 check "$expected_err" "$actual_err"
68
69 # check -outfile -
70 start_test '-outfile -'
71 printf '%s\n' 'storing message 5 to stdout' >>"$expected"
72 run_prog mhstore 5 -outfile - >"$actual" 2>&1
73 check "$expected" "$actual"
74
75 # check message number greater than highest
76 start_test 'message number greater than highest'
77 run_test 'mhstore 11' "mhstore: message 11 doesn't exist"
78
79 # check multiple messages
80 start_test 'multiple messages'
81 run_test 'mhstore 4 6' 'storing message 4 as file 4.txt
82 storing message 6 as file 6.txt'
83 cat >"$expected" <<'EOF'
84 This is message number 4
85 EOF
86 check "$expected" 4.txt
87 cat >"$expected" <<'EOF'
88 This is message number 6
89 EOF
90 check "$expected" 6.txt
91
92 # Write message with a text/plain subpart.
93 msgfile=`mhpath new`
94 cat >"$msgfile" <<'EOF'
95 To: recipient@example.com
96 From: sender@example.com
97 Subject: mhlist test
98 MIME-Version: 1.0
99 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
100
101 ------- =_aaaaaaaaaa0
102 Content-Type: multipart/related;
103 type="multipart/alternative";
104 boundary="subpart__1.1"
105
106 --subpart__1.1
107 Content-Type: text/plain; charset="iso-8859-1"
108 Content-Disposition: attachment; filename="test1.txt"
109
110 This is the first text/plain part, in a subpart.
111
112 --subpart__1.1--
113
114 ------- =_aaaaaaaaaa0
115 Content-Type: text/plain; charset="iso-8859-1"
116 Content-Disposition: attachment; filename="test2.txt"
117 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
118 Content-Transfer-Encoding: quoted-printable
119
120 This is the second text/plain part.
121
122 ------- =_aaaaaaaaaa0
123 Content-Type: text/plain; charset="iso-8859-1"
124 Content-Disposition: attachment; filename="test3.txt"
125
126 This is the third text/plain part.
127
128 ------- =_aaaaaaaaaa0
129 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
130 Content-Disposition: attachment; filename="test4.txt"
131 Content-MD5: cMI1lB/LZ4jgVl3EbhdyWA==
132 Content-Transfer-Encoding: base64
133
134 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4NClRoaXMgdGVzdCBoYXMgbXVsdGlw
135 bGUgbGluZXMuDQo=
136
137 ------- =_aaaaaaaaaa0--
138 EOF
139
140 # check -part
141 start_test '-part'
142 cat >"$expected" <<'EOF'
143 This is the third text/plain part.
144 EOF
145 run_test 'mhstore last -part 3' 'storing message 11 part 3 as file 11.3.txt'
146 check "$expected" 11.3.txt
147
148 # check -part of a subpart
149 start_test '-part of a subpart'
150 cat >"$expected" <<'EOF'
151 This is the first text/plain part, in a subpart.
152 EOF
153 run_test 'mhstore last -part 1.1' \
154 'storing message 11 part 1.1 as file 11.1.1.txt'
155 check "$expected" 11.1.1.txt 'keep first'
156
157 # check -type
158 start_test '-type'
159 run_test 'mhstore last -type text/plain' \
160 'storing message 11 part 1.1 as file 11.1.1.txt
161 storing message 11 part 2 as file 11.2.txt
162 storing message 11 part 3 as file 11.3.txt
163 storing message 11 part 4 as file 11.4.txt'
164 check "$expected" 11.1.1.txt
165 cat >"$expected" <<'EOF'
166 This is the second text/plain part.
167 EOF
168 check "$expected" 11.2.txt
169 cat >"$expected" <<'EOF'
170 This is the third text/plain part.
171 EOF
172 check "$expected" 11.3.txt
173 cat >"$expected" <<'EOF'
174 This is the fourth text/plain part.
175 This test has multiple lines.
176 EOF
177 check "$expected" 11.4.txt
178
179 # check -auto
180 start_test '-auto'
181 cat >"$expected" <<'EOF'
182 This is the fourth text/plain part.
183 This test has multiple lines.
184 EOF
185 run_test 'mhstore last -part 4 -auto' \
186 'storing message 11 part 4 as file test4.txt'
187 check "$expected" test4.txt 'keep first'
188
189 # check -noauto, the default
190 start_test '-noauto, the default'
191 run_test 'mhstore last -part 4 -auto -noauto' \
192 'storing message 11 part 4 as file 11.4.txt'
193 check "$expected" 11.4.txt 'keep first'
194
195 # check -verbose, the default
196 start_test '-verbose, the default'
197 run_test 'mhstore last -part 4 -noverbose -verbose' \
198 'storing message 11 part 4 as file 11.4.txt'
199 check "$expected" 11.4.txt 'keep first'
200
201 # check -noverbose
202 start_test '-noverbose'
203 run_test 'mhstore last -part 4 -noverbose' ''
204 check "$expected" 11.4.txt
205
206 # check that -auto obeys Content-Disposition header
207 start_test 'that -auto obeys Content-Disposition header'
208 cat >"$expected" <<'EOF'
209 This is the first text/plain part, in a subpart.
210 EOF
211 run_test 'mhstore last -part 1.1 -auto' \
212 'storing message 11 part 1.1 as file test1.txt'
213 check "$expected" test1.txt
214
215 # check -check
216 start_test '-check'
217 cat >"$expected" <<'EOF'
218 This is the second text/plain part.
219 EOF
220 run_test 'mhstore last -part 2 -check' \
221 'storing message 11 part 2 as file 11.2.txt'
222 check "$expected" 11.2.txt 'keep first'
223
224 # check with -check on base64 encoded part
225 start_test 'with -check on base64 encoded part'
226 cat >"$expected2" <<'EOF'
227 This is the fourth text/plain part.
228 This test has multiple lines.
229 EOF
230 run_test 'mhstore last -part 4 -check' \
231 'storing message 11 part 4 as file 11.4.txt'
232 check "$expected2" 11.4.txt
233
234 # check -check with bad MD5 checksum
235 start_test '-check with bad MD5 checksum'
236 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' "$msgfile" >"$MH_TEST_DIR/$$.tmp"
237 mv -f "$MH_TEST_DIR/$$.tmp" "$msgfile"
238 run_test 'mhstore last -part 2 -check' \
239 'storing message 11 part 2 as file 11.2.txt
240 mhstore: content integrity suspect (digest mismatch) -- continuing
241 (content text/plain in message 11, part 2)'
242 check "$expected" 11.2.txt 'keep first'
243
244 # check -nocheck, the default
245 start_test '-nocheck, the default'
246 run_test 'mhstore last -part 2 -check -nocheck' \
247 'storing message 11 part 2 as file 11.2.txt'
248 check "$expected" 11.2.txt 'keep first'
249
250 # check -outfile - with -file
251 start_test '-outfile - with -file'
252 run_prog mhstore -noverbose -file `mhpath 11` -part 2 -outfile - >"$actual" 2>&1
253 check "$expected" "$actual"
254
255 # check reassembly of message/partial messages (RFC 1521, 7.3.2)
256 start_test 'reassembly of message/partial messages (RFC 1521, 7.3.2)'
257 msgfile=`mhpath new`
258 cat >"$msgfile" <<'EOF'
259 To: recipient@example.com
260 From: sender@example.com
261 Subject: mhlist test
262 MIME-Version: 1.0
263 Content-Type: message/partial; id="test-mhstore message/partial test"; number=1
264
265 Content-Type: text/plain; charset="iso-8859-1"
266
267 This is part one of three.
268 EOF
269
270 msgfile=`mhpath new`
271 cat >"$msgfile" <<'EOF'
272 To: recipient@example.com
273 From: sender@example.com
274 Subject: mhlist test
275 MIME-Version: 1.0
276 Content-Type: message/partial; id="test-mhstore message/partial test"; number=2
277
278 This is part two of three.
279 EOF
280
281 msgfile=`mhpath new`
282 cat >"$msgfile" <<'EOF'
283 To: recipient@example.com
284 From: sender@example.com
285 Subject: mhlist test
286 MIME-Version: 1.0
287 Content-Type: message/partial; id="test-mhstore message/partial test"; number=3;
288 total=3
289
290 This is part three of three.
291 EOF
292
293 run_test 'mhstore last:3' \
294 'reassembling partials 12,13,14 to folder inbox as message 15'
295
296 cat >"$expected" <<'EOF'
297 This is part one of three.
298 This is part two of three.
299 This is part three of three.
300 EOF
301 run_test 'mhstore last' 'storing message 15 as file 15.txt'
302 check "$expected" 15.txt
303
304 # cd into Mail directory because it gets cleaned up by the exit trap.
305 cd Mail
306
307 # check -clobber always
308 start_test '-clobber always'
309 folder +inbox 7 >/dev/null
310 touch 7.txt
311 cat >"$expected" <<'EOF'
312 This is message number 7
313 EOF
314 run_test 'mhstore' 'storing message 7 as file 7.txt'
315 check "$expected" 7.txt 'keep first'
316 run_test 'mhstore -clobber ask -clobber always' \
317 'storing message 7 as file 7.txt'
318 check "$expected" 7.txt 'keep first'
319
320 # check -clobber auto
321 start_test '-clobber auto'
322 touch 7.txt
323 run_test 'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
324 check "$expected" 7-1.txt 'keep first'
325 touch 7-1.txt
326 run_test 'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
327 check "$expected" 7-2.txt 'keep first'
328
329 # check -clobber suffix
330 start_test '-clobber suffix'
331 run_test 'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
332 check "$expected" 7.txt.1 'keep first'
333 touch 7.txt.1
334 run_test 'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
335 check "$expected" 7.txt.2 'keep first'
336
337 # Don't check -clobber ask because it requires connection to a
338 # terminal, and this test won't always be run with one.
339
340 # check -clobber never. Its exit status is the number of files not overwritten.
341 start_test '-clobber never. Its exit status is the number of files not overwritten.'
342 run_test 'mhstore -clobber never' \
343 "mhstore: will not overwrite $MH_TEST_DIR/Mail/7.txt with -clobber never"
344 set +e
345 mhstore -clobber never >/dev/null 2>&1
346 run_test "echo $?" 1
347 set -e
348
349 cd ..
350
351 # check with relative nmh-storage profile component
352 start_test 'with relative nmh-storage profile component'
353 storagedir=storagedir
354 dir="$MH_TEST_DIR/Mail/inbox/$storagedir"
355 mkdir "$dir"
356 printf '%s\n' "nmh-storage: $storagedir" >>"$MH"
357 cat >"$expected" <<'EOF'
358 This is the fourth text/plain part.
359 This test has multiple lines.
360 EOF
361 run_test 'mhstore 11 -part 4' \
362 "storing message 11 part 4 as file $storagedir/11.4.txt"
363 check "$expected" "$dir/11.4.txt" 'keep first'
364
365 # check with relative nmh-storage profile component and -auto
366 start_test 'with relative nmh-storage profile component and -auto'
367 run_test 'mhstore 11 -part 4 -auto' \
368 "storing message 11 part 4 as file $storagedir/test4.txt"
369 check "$expected" "$dir/test4.txt" 'keep first'
370
371 # check with absolute nmh-storage profile component
372 start_test 'with absolute nmh-storage profile component'
373 absstoragedir="$MH_TEST_DIR/$storagedir"
374 mkdir "$absstoragedir"
375 sed "s%\(nmh-storage: \)storagedir%\1$absstoragedir%" "$MH" >"$MH.new"
376 mv -f "$MH.new" "$MH"
377 run_test 'mhstore 11 -part 4' \
378 "storing message 11 part 4 as file $storagedir/11.4.txt"
379 check "$expected" "$absstoragedir/11.4.txt" 'keep first'
380
381 # check with absolute nmh-storage profile component and -auto
382 start_test 'with absolute nmh-storage profile component and -auto'
383 run_test 'mhstore 11 -part 4 -auto' \
384 "storing message 11 part 4 as file $storagedir/test4.txt"
385 check "$expected" "$absstoragedir/test4.txt"
386 rmdir "$absstoragedir"
387
388
389 finish_test
390 exit $failed