]> diplodocus.org Git - nmh/blob - test/mhstore/test-mhstore
Fixed memory management in mhstore. The main problem was a double
[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 'keep first'
216
217 # check -outfile - with -file
218 run_prog mhstore -noverbose -file `mhpath 11` -part 2 -outfile - >"$actual" 2>&1
219 check "$expected" "$actual"
220
221 # check reassembly of message/partial messages (RFC 1521, 7.3.2)
222 msgfile=`mhpath new`
223 cat >"$msgfile" <<'EOF'
224 To: recipient@example.com
225 From: sender@example.com
226 Subject: mhlist test
227 MIME-Version: 1.0
228 Content-Type: message/partial; id="test-mhstore message/partial test"; number=1
229
230 Content-Type: text/plain; charset="iso-8859-1"
231
232 This is part one of three.
233 EOF
234
235 msgfile=`mhpath new`
236 cat >"$msgfile" <<'EOF'
237 To: recipient@example.com
238 From: sender@example.com
239 Subject: mhlist test
240 MIME-Version: 1.0
241 Content-Type: message/partial; id="test-mhstore message/partial test"; number=2
242
243 This is part two 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=3;
253 total=3
254
255 This is part three of three.
256 EOF
257
258 run_test 'mhstore last:3' \
259 'reassembling partials 12,13,14 to folder inbox as message 15'
260
261 cat >"$expected" <<'EOF'
262 This is part one of three.
263 This is part two of three.
264 This is part three of three.
265 EOF
266 run_test 'mhstore last' 'storing message 15 as file 15.txt'
267 check "$expected" 15.txt
268
269 # cd into Mail directory because it gets cleaned up by the exit trap.
270 cd Mail
271
272 # check -clobber always
273 folder +inbox 7 >/dev/null
274 touch 7.txt
275 cat >"$expected" <<'EOF'
276 This is message number 7
277 EOF
278 run_test 'mhstore' 'storing message 7 as file 7.txt'
279 check "$expected" 7.txt 'keep first'
280 run_test 'mhstore -clobber ask -clobber always' \
281 'storing message 7 as file 7.txt'
282 check "$expected" 7.txt 'keep first'
283
284 # check -clobber auto
285 touch 7.txt
286 run_test 'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
287 check "$expected" 7-1.txt 'keep first'
288 touch 7-1.txt
289 run_test 'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
290 check "$expected" 7-2.txt 'keep first'
291
292 # check -clobber suffix
293 run_test 'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
294 check "$expected" 7.txt.1 'keep first'
295 touch 7.txt.1
296 run_test 'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
297 check "$expected" 7.txt.2 'keep first'
298
299 # Don't check -clobber ask because it requires connection to a
300 # terminal, and this test won't always be run with one.
301
302 # check -clobber never. Its exit status is the number of files not overwritten.
303 run_test 'mhstore -clobber never' \
304 "mhstore: will not overwrite `pwd`/7.txt with -clobber never"
305 set +e
306 mhstore -clobber never >/dev/null 2>&1
307 run_test "echo $?" 1
308 set -e
309
310 cd ..
311
312 # check with relative nmh-storage profile component
313 storagedir=storagedir
314 dir="$MH_TEST_DIR/Mail/inbox/$storagedir"
315 mkdir "$dir"
316 printf '%s\n' "nmh-storage: $storagedir" >>"$MH"
317 cat >"$expected" <<'EOF'
318 This is the fourth text/plain part.
319 This test has multiple lines.
320 EOF
321 run_test 'mhstore 11 -part 4' \
322 "storing message 11 part 4 as file $storagedir/11.4.txt"
323 check "$expected" "$dir/11.4.txt" 'keep first'
324
325 # check with relative nmh-storage profile component and -auto
326 run_test 'mhstore 11 -part 4 -auto' \
327 "storing message 11 part 4 as file $storagedir/test4.txt"
328 check "$expected" "$dir/test4.txt" 'keep first'
329
330 # check with absolute nmh-storage profile component
331 absstoragedir="$MH_TEST_DIR/$storagedir"
332 mkdir "$absstoragedir"
333 sed "s%\(nmh-storage: \)storagedir%\1$absstoragedir%" "$MH" >"$MH.new"
334 mv -f "$MH.new" "$MH"
335 run_test 'mhstore 11 -part 4' \
336 "storing message 11 part 4 as file $storagedir/11.4.txt"
337 check "$expected" "$absstoragedir/11.4.txt" 'keep first'
338
339 # check with absolute nmh-storage profile component and -auto
340 run_test 'mhstore 11 -part 4 -auto' \
341 "storing message 11 part 4 as file $storagedir/test4.txt"
342 check "$expected" "$absstoragedir/test4.txt"
343 rmdir "$absstoragedir"
344
345
346 exit $failed