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