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