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