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