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