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