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