]> diplodocus.org Git - nmh/blob - test/mhstore/test-mhstore
One more attempt at getting the buildbot $PATH correct on Solaris.
[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=`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 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 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 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
120
121 ------- =_aaaaaaaaaa0--
122 EOF
123
124 # check -part
125 cat > $expected <<EOF
126 This is the third text/plain part.
127 EOF
128 run_test 'mhstore last -part 3' 'storing message 11 part 3 as file 11.3.txt'
129 check $expected 11.3.txt
130
131 # check -part of a subpart
132 cat > $expected <<EOF
133 This is the first text/plain part, in a subpart.
134 EOF
135 run_test 'mhstore last -part 1.1' \
136 'storing message 11 part 1.1 as file 11.1.1.txt'
137 check $expected 11.1.1.txt 'keep first'
138
139 # check -type
140 run_test 'mhstore last -type text/plain' \
141 'storing message 11 part 1.1 as file 11.1.1.txt
142 storing message 11 part 2 as file 11.2.txt
143 storing message 11 part 3 as file 11.3.txt
144 storing message 11 part 4 as file 11.4.txt'
145 check $expected 11.1.1.txt
146 cat > $expected <<EOF
147 This is the second text/plain part.
148 EOF
149 check $expected 11.2.txt
150 cat > $expected <<EOF
151 This is the third text/plain part.
152 EOF
153 check $expected 11.3.txt
154 cat > $expected <<EOF
155 This is the fourth text/plain part.
156 EOF
157 check $expected 11.4.txt
158
159 # check -auto
160 cat > $expected <<EOF
161 This is the fourth text/plain part.
162 EOF
163 run_test 'mhstore last -part 4 -auto' \
164 'storing message 11 part 4 as file test4.txt'
165 check $expected test4.txt 'keep first'
166
167 # check -noauto, the default
168 run_test 'mhstore last -part 4 -auto -noauto' \
169 'storing message 11 part 4 as file 11.4.txt'
170 check $expected 11.4.txt 'keep first'
171
172 # check -verbose, which doesn't do anything
173 run_test 'mhstore last -part 4 -verbose' \
174 'storing message 11 part 4 as file 11.4.txt'
175 check $expected 11.4.txt 'keep first'
176
177 # check -noverbose, the default
178 run_test 'mhstore last -part 4 -verbose -noverbose' \
179 'storing message 11 part 4 as file 11.4.txt'
180 check $expected 11.4.txt
181
182 # check that -auto obeys Content-Disposition header
183 cat > $expected <<EOF
184 This is the first text/plain part, in a subpart.
185 EOF
186 run_test 'mhstore last -part 1.1 -auto' \
187 'storing message 11 part 1.1 as file test1.txt'
188 check $expected test1.txt
189
190 # check -check
191 cat > $expected <<EOF
192 This is the second text/plain part.
193 EOF
194 run_test 'mhstore last -part 2 -check' \
195 'storing message 11 part 2 as file 11.2.txt'
196 check $expected 11.2.txt 'keep first'
197
198 # check -check with bad MD5 checksum
199 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' $msgfile > $MH_TEST_DIR/$$.tmp
200 mv -f $MH_TEST_DIR/$$.tmp $msgfile
201 run_test 'mhstore last -part 2 -check' \
202 'storing message 11 part 2 as file 11.2.txt
203 mhstore: content integrity suspect (digest mismatch) -- continuing
204 (content text/plain in message 11, part 2)'
205 check $expected 11.2.txt 'keep first'
206
207 # check -nocheck, the default
208 run_test 'mhstore last -part 2 -check -nocheck' \
209 'storing message 11 part 2 as file 11.2.txt'
210 check $expected 11.2.txt
211
212 # check reassembly of message/partial messages (RFC 1521, 7.3.2)
213 msgfile=`mhpath new`
214 cat > $msgfile <<EOF
215 To: recipient@example.com
216 From: sender@example.com
217 Subject: mhlist test
218 MIME-Version: 1.0
219 Content-Type: message/partial; id="test-mhstore message/partial test"; number=1
220
221 Content-Type: text/plain; charset="iso-8859-1"
222
223 This is part one of three.
224 EOF
225
226 msgfile=`mhpath new`
227 cat > $msgfile <<EOF
228 To: recipient@example.com
229 From: sender@example.com
230 Subject: mhlist test
231 MIME-Version: 1.0
232 Content-Type: message/partial; id="test-mhstore message/partial test"; number=2
233
234 This is part two of three.
235 EOF
236
237 msgfile=`mhpath new`
238 cat > $msgfile <<EOF
239 To: recipient@example.com
240 From: sender@example.com
241 Subject: mhlist test
242 MIME-Version: 1.0
243 Content-Type: message/partial; id="test-mhstore message/partial test"; number=3;
244 total=3
245
246 This is part three of three.
247 EOF
248
249 run_test 'mhstore last:3' \
250 'reassembling partials 12,13,14 to folder inbox as message 15'
251
252 cat > $expected <<EOF
253 This is part one of three.
254 This is part two of three.
255 This is part three of three.
256 EOF
257 run_test 'mhstore last' 'storing message 15 as file 15.txt'
258 check $expected 15.txt
259
260 # cd into Mail directory because it gets cleaned up by the exit trap.
261 cd Mail
262
263 # check -clobber always
264 folder +inbox 7 > /dev/null
265 touch 7.txt
266 cat > $expected <<EOF
267 This is message number 7
268 EOF
269 run_test 'mhstore' 'storing message 7 as file 7.txt'
270 check $expected 7.txt 'keep first'
271 run_test 'mhstore -clobber ask -clobber always' \
272 'storing message 7 as file 7.txt'
273 check $expected 7.txt 'keep first'
274
275 # check -clobber auto
276 touch 7.txt
277 run_test 'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
278 check $expected 7-1.txt 'keep first'
279 touch 7-1.txt
280 run_test 'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
281 check $expected 7-2.txt 'keep first'
282
283 # check -clobber suffix
284 run_test 'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
285 check $expected 7.txt.1 'keep first'
286 touch 7.txt.1
287 run_test 'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
288 check $expected 7.txt.2 'keep first'
289
290 # Don't check -clobber ask because it requires connection to a
291 # terminal, and this test won't always be run with one.
292
293 # check -clobber never. Its exit status is the number of files not overwritten.
294 run_test 'mhstore -clobber never' \
295 "mhstore: will not overwrite `pwd`/7.txt with -clobber never"
296 set +e
297 mhstore -clobber never >/dev/null 2>&1
298 run_test "echo $?" 1
299 set -e
300
301 cd ..
302
303 # check with relative nmh-storage profile component
304 storagedir=storagedir
305 dir="$MH_TEST_DIR/Mail/inbox/$storagedir"
306 mkdir "$dir"
307 echo "nmh-storage: $storagedir" >> $MH
308 cat > $expected <<EOF
309 This is the fourth text/plain part.
310 EOF
311 run_test 'mhstore 11 -part 4' \
312 "storing message 11 part 4 as file $storagedir/11.4.txt"
313 check $expected "$dir/11.4.txt" 'keep first'
314
315 # check with relative nmh-storage profile component and -auto
316 run_test 'mhstore 11 -part 4 -auto' \
317 "storing message 11 part 4 as file $storagedir/test4.txt"
318 check $expected "$dir/test4.txt" 'keep first'
319
320 # check with absolute nmh-storage profile component
321 absstoragedir="$MH_TEST_DIR/$storagedir"
322 mkdir "$absstoragedir"
323 sed "s%\(nmh-storage: \)storagedir%\1$absstoragedir%" $MH > $MH.new
324 mv -f $MH.new $MH
325 run_test 'mhstore 11 -part 4' \
326 "storing message 11 part 4 as file $storagedir/11.4.txt"
327 check $expected "$absstoragedir/11.4.txt" 'keep first'
328
329 # check with absolute nmh-storage profile component and -auto
330 run_test 'mhstore 11 -part 4 -auto' \
331 "storing message 11 part 4 as file $storagedir/test4.txt"
332 check $expected "$absstoragedir/test4.txt"
333 rmdir "$absstoragedir"
334
335
336 exit $failed