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