]> diplodocus.org Git - nmh/blob - test/mhlist/test-mhlist
sbr/oauth.c: Remove const to avoid curl's debug_callback warning.
[nmh] / test / mhlist / test-mhlist
1 #!/bin/sh
2 ######################################################
3 #
4 # Test mhlist
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 check_exit '-eq 1' mhlist -
20
21 expected=$MH_TEST_DIR/$$.expected
22 actual=$MH_TEST_DIR/$$.actual
23
24
25 # check with no options and no current message
26 run_test 'mhlist' 'mhlist: no cur message'
27
28 # check with no options and current message
29 folder +inbox 5 > /dev/null
30 cat > $expected <<EOF
31 msg part type/subtype size description
32 5 text/plain 25
33 EOF
34 run_prog mhlist > $actual 2>&1
35 check $expected $actual 'keep first'
36
37 # check -noheaders
38 run_test 'mhlist 5 -noheaders' ' 5 text/plain 25'
39
40 # check -headers
41 run_prog mhlist -noheaders -headers > $actual 2>&1
42 check $expected $actual 'keep first'
43
44 # check with folder and current message
45 run_prog mhlist +inbox > $actual 2>&1
46 check $expected $actual 'keep first'
47
48 # check with specified message
49 run_prog mhlist 5 > $actual 2>&1
50 check $expected $actual 'keep first'
51
52 # check -file
53 run_prog mhlist -file "$MH_TEST_DIR/Mail/inbox/5" > $actual 2>&1
54 check $expected $actual
55
56 # check -file -
57 cat > $expected <<EOF
58 msg part type/subtype size description
59 0 text/plain 25
60 EOF
61 run_prog mhlist -file - < "$MH_TEST_DIR/Mail/inbox/5" > $actual 2>&1
62 check $expected $actual
63
64 # check message number greater than highest
65 run_test 'mhlist 11' "mhlist: message 11 doesn't exist"
66
67 # check multiple messages
68 cat > $expected <<EOF
69 msg part type/subtype size description
70 2 text/plain 25
71 8 text/plain 25
72 EOF
73 run_prog mhlist 2 8 > $actual 2>&1
74 check $expected $actual
75
76 # Write message with a text/plain subpart.
77 msgfile=`mhpath new`
78 cat > $msgfile <<EOF
79 To: recipient@example.com
80 From: sender@example.com
81 Subject: mhlist test
82 MIME-Version: 1.0
83 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
84
85 ------- =_aaaaaaaaaa0
86 Content-Type: multipart/related;
87 type="multipart/alternative";
88 boundary="subpart__1.1"
89
90 --subpart__1.1
91 Content-Type: text/plain; charset="iso-8859-1"
92 Content-Disposition: attachment; filename="test1"
93
94 This is the first text/plain part, in a subpart.
95
96 --subpart__1.1--
97
98 ------- =_aaaaaaaaaa0
99 Content-Type: text/plain; charset="iso-8859-1"
100 Content-Disposition: attachment; filename="test2"
101 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
102 Content-Transfer-Encoding: quoted-printable
103
104 This is the second text/plain part.
105
106 ------- =_aaaaaaaaaa0
107 Content-Type: text/plain; charset="iso-8859-1"; name="test3"
108 Content-Disposition: attachment; filename="test3"
109
110 This is the third text/plain part.
111
112 ------- =_aaaaaaaaaa0
113 Content-Type: text/plain; charset="iso-8859-1"
114 Content-Disposition: attachment; filename="test4"
115 Content-Transfer-Encoding: base64
116
117 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
118
119 ------- =_aaaaaaaaaa0--
120 EOF
121
122 # check -part
123 run_test 'mhlist last -part 3 -noheader' \
124 ' 11 multipart/mixed 936
125 1 multipart/related 180
126 3 text/plain 35'
127
128 # check -part of a subpart
129 run_test 'mhlist last -part 1.1 -noheader' \
130 ' 11 multipart/mixed 936
131 1 multipart/related 180
132 1.1 text/plain 49'
133
134 # check -type
135 run_test 'mhlist last -type text/plain -noheader' \
136 ' 11 multipart/mixed 936
137 1 multipart/related 180
138 1.1 text/plain 49
139 2 text/plain 36
140 3 text/plain 35
141 4 text/plain 36'
142
143 # check -norealsize
144 run_test 'mhlist last -part 4 -noheader -norealsize' \
145 ' 11 multipart/mixed 936
146 1 multipart/related 180
147 4 text/plain 49'
148
149 # check -realsize, the default
150 run_test 'mhlist last -part 4 -noheader -norealsize -realsize' \
151 ' 11 multipart/mixed 936
152 1 multipart/related 180
153 4 text/plain 36'
154
155 # check -check
156 run_test 'mhlist last -part 2 -noheader -check' \
157 ' 11 multipart/mixed 936
158 1 multipart/related 180
159 2 text/plain 36'
160
161 # check -check with bad MD5 checksum
162 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' $msgfile > $MH_TEST_DIR/$$.tmp
163 mv -f $MH_TEST_DIR/$$.tmp $msgfile
164 run_test 'mhlist last -part 2 -noheader -check' \
165 ' 11 multipart/mixed 936
166 1 multipart/related 180
167 2 text/plain 36
168 mhlist: content integrity suspect (digest mismatch) -- continuing
169 (content text/plain in message 11, part 2)'
170
171 # check -nocheck, the default
172 run_test 'mhlist last -part 2 -noheader -check -nocheck' \
173 ' 11 multipart/mixed 936
174 1 multipart/related 180
175 2 text/plain 36'
176
177 #
178 # Set the cur sequence to 1 to test default behavior of changecur after
179 # this test.
180 #
181
182 mark 1 -sequence cur -add -zero
183
184 # check -verbose
185 run_test 'mhlist 11 -verbose -noheader' \
186 ' 11 multipart/mixed 936
187 boundary="----- =_aaaaaaaaaa0"
188 1 multipart/related 180
189 type="multipart/alternative"
190 boundary="subpart__1.1"
191 1.1 text/plain 49
192 charset="iso-8859-1"
193 2 text/plain 36
194 charset="iso-8859-1"
195 3 text/plain 35
196 charset="iso-8859-1"
197 name="test3"
198 4 text/plain 36
199 charset="iso-8859-1"'
200
201 #
202 # Check default changecur behavior
203 #
204
205 run_test 'mark -sequence cur -list' 'cur: 11'
206
207 #
208 # Now test -nochangecur
209 #
210
211 mhlist -nochangecur 1 >/dev/null
212
213 run_test 'mark -sequence cur -list' 'cur: 11'
214
215 # check MIME parser and m_getfld
216 cat > $expected <<EOF
217 msg part type/subtype size description
218 12 multipart/related 204
219 1 multipart/alternative 74
220 1.1 text/plain 17
221 2 text/plain 17
222 EOF
223
224 msgfile=`mhpath new`
225 msgnum=`basename $msgfile`
226 cat > $msgfile <<EOF
227 To: recipient@example.com, recipient@example.com, recipient@example.com,
228 recipient@example.com, recipient@example.com, recipient@example.com,
229 recipient@example.com, recipient@example.com, recipient@example.com,
230 recipient@example.com, recipient@example.com, recipient@example.com,
231 recipient@example.com, recipient@example.com, recipient@example.com,
232 recipient@example.com, recipient@example.com, recipient@example.com,
233 recipient@example.com, recipient@example.com, recipient@example.com,
234 recipient@example.com, recipient@example.com, recipient@example.com,
235 recipient@example.com, recipient@example.com, recipient@example.com,
236 recipient@example.com, recipient@example.com, recipient@example.com,
237 recipient@example.com, recipient@example.com, recipient@example.com,
238 recipient@example.com, recipient@example.com, recipient@example.com,
239 recipient@example.com, recipient@example.com, recipient@example.com,
240 recipient@example.com, recipient@example.com, recipient@example.com,
241 recipient@example.com, recipient@example.com, recipient@example.com,
242 recipient@example.com, recipient@example.com, recipient@example.com,
243 recipient@example.com, recipient@example.com, recipient@example.com,
244 recipient@example.com, recipient@example.com, recipient@example.com,
245 recipient@example.com, recipient@example.com, recipient@example.com,
246 recipient@example.com, recipient@example.com, recipient@example.com,
247 recipient@example.com, recipient@example.com, recipient@example.com,
248 recipient@example.com, recipient@example.com, recipient@example.com,
249 recipient@example.com, recipient@example.com, recipient@example.com,
250 recipient@example.com, recipient@example.com, recipient@example.com,
251 recipient@example.com, recipient@example.com, recipient@example.com,
252 recipient@example.com, recipient@example.com, recipient@example.com,
253 recipient@example.com, recipient@example.com, recipient@example.com,
254 recipient@example.com, recipient@example.com, recipient@example.com,
255 recipient@example.com, recipient@example.com, recipient@example.com,
256 recipient@example.com, recipient@example.com, recipient@example.com,
257 recipient@example.com, recipient@example.com, recipient@example.com,
258 recipient@example.com, recipient@example.com, recipient@example.com,
259 recipient@example.com, recipient@example.com, recipient@example.com,
260 recipient@example.com, recipient@example.com, recipient@example.com,
261 recipient@example.com, recipient@example.com, recipient@example.com,
262 recipient@example.com, recipient@example.com, recipient@example.com,
263 recipient@example.com, recipient@example.com, recipient@example.com,
264 recipient@example.com, recipient@example.com, recipient@example.com,
265 recipient@example.com, recipient@example.com, recipient@example.com,
266 recipient@example.com, recipient@example.com, recipient@example.com,
267 recipient@example.com, recipient@example.com, recipient@example.com,
268 recipient@example.com, recipient@example.com, recipient@example.com,
269 recipient@example.com, recipient@example.com, recipient@example.com,
270 recipient@example.com, recipient@example.com, recipient@example.com,
271 recipient@example.com, recipient@example.com, recipient@example.com,
272 recipient@example.com, recipient@example.com, recipient@example.com,
273 recipient@example.com, recipient@example.com, recipient@example.com,
274 recipient@example.com, recipient@example.com, recipient@example.com,
275 recipient@example.com, recipient@example.com, recipient@example.com,
276 recipient@example.com, recipient@example.com, recipient@example.com,
277 recipient@example.com, recipient@example.com, recipient@example.com,
278 recipient@example.com, recipient@example.com, recipient@example.com,
279 recipient@example.com, recipient@example.com, recipient@example.com,
280 recipient@example.com, recipient@example.com, recipient@example.com,
281 recipient@example.com, recipient@example.com, recipient@example.com,
282 recipient@example.com, recipient@example.com, recipient@example.com,
283 recipient@example.com, recipient@example.com, recipient@example.com,
284 recipient@example.com, recipient@example.com, recipient@example.com,
285 recipient@example.com, recipient@example.com, recipient@example.com,
286 recipient@example.com, recipient@example.com, recipient@example.com,
287 recipient@example.com, recipient@example.com, recipient@example.com,
288 recipient@example.com, recipient@example.com, recipient@example.com,
289 recipient@example.com, recipient@example.com, recipient@example.com,
290 recipient@example.com, recipient@example.com, recipient@example.com,
291 recipient@example.com, recipient@example.com, recipient@example.com,
292 recipient@example.com, recipient@example.com, recipient@example.com,
293 recipient@example.com, recipient@example.com, recipient@example.com,
294 recipient@example.com, recipient@example.com, recipient@example.com,
295 recipient@example.com, recipient@example.com, recipient@example.com,
296 recipient@example.com, recipient@example.com, recipient@example.com,
297 recipient@example.com, recipient@example.com, recipient@example.com,
298 recipient@example.com, recipient@example.com, recipient@example.com,
299 recipient@example.com, recipient@example.com, recipient@example.com,
300 recipient@example.com, recipient@example.com, recipient@example.com,
301 recipient@example.com, recipient@example.com, recipient@example.com,
302 recipient@example.com, recipient@example.com, recipient@example.com,
303 recipient@example.com, recipient@example.com, recipient@example.com,
304 recipient@example.com, recipient@example.com, recipient@example.com,
305 recipient@example.com, recipient@example.com, recipient@example.com,
306 recipient@example.com, recipient@example.com, recipient@example.com,
307 recipient@example.com, recipient@example.com, recipient@example.com,
308 recipient@example.com, recipient@example.com, recipient@example.com,
309 recipient@example.com, recipient@example.com, recipient@example.com,
310 recipient@example.com, recipient@example.com, recipient@example.com,
311 recipient@example.com, recipient@example.com, recipient@example.com,
312 recipient@example.com, recipient@example.com, recipient@example.com,
313 recipient@example.com, recipient@example.com, recipient@example.com,
314 recipient@example.com, recipient@example.com, recipient@example.com,
315 recipient@example.com, recipient@example.com, recipient@example.com,
316 recipient@example.com, recipient@example.com, recipient@example.com,
317 recipient@example.com, recipient@example.com, recipient@example.com,
318 recipient@example.com, recipient@example.com, recipient@example.com,
319 recipient@example.com, recipient@example.com, recipient@example.com,
320 recipient@example.com, recipient@example.com, recipient@example.com,
321 recipient@example.com, recipient@example.com, recipient@example.com,
322 recipient@example.com, recipient@example.com, recipient@example.com,
323 recipient@example.com, recipient@example.com, recipient@example.com,
324 recipient@example.com, recipient@example.com, recipient@example.com,
325 recipient@example.com, recipient@example.com, recipient@example.com,
326 recipient@example.com, recipient@example.com, recipient@example.com,
327 recipient@example.com, recipient@example.com, recipient@example.com,
328 recipient@example.com, recipient@example.com, recipient@example.com,
329 recipient@example.com, recipient@example.com, recipient@example.com,
330 recipient@example.com, recipient@example.com, recipient@example.com,
331 recipient@example.com, recipient@example.com, recipient@example.com,
332 recipient@example.com, recipient@example.com, recipient@example.com,
333 recipient@example.com, recipient@example.com, recipient@example.com,
334 recipient@example.com, recipient@example.com, recipient@example.com,
335 recipient@example.com, recipient@example.com, recipient@example.com,
336 recipient@example.com, recipient@example.com, recipient@example.com,
337 recipient@example.com, recipient@example.com, recipient@example.com,
338 recipient@example.com, recipient@example.com, recipient@example.com,
339 re@example.com
340 From: sender@example.com
341 Subject: very long header
342 Date: Wed, 4 Dec 2013 21:12:00 -0500
343 MIME-Version: 1.0
344 Content-Type: multipart/related; boundary="1"
345
346 --1
347 Content-Type: multipart/alternative; boundary="2"
348
349 --2
350 Content-Type: text/plain; charset="us-ascii"
351
352 This is part 1.
353
354
355 --2--
356
357 --1
358 Content-Type: text/plain; charset="us-ascii"
359
360 This is part 2.
361
362
363 --1--
364 EOF
365
366 run_prog mhlist last > $actual 2>&1
367 check $expected $actual
368
369 ## now check mhlist output
370
371 msgfile=`mhpath new`
372 msgnum=`basename $msgfile`
373 cat > $msgfile <<EOF
374 To: example@example.org
375 From: someone <someone@example.com>
376 Subject: mhlist test
377 Date: Thu, 29 Jan 2015 18:12:21 +0000 (GMT)
378 Content-Type: multipart/mixed; boundary="BoundaryMixed"
379
380 --BoundaryMixed
381 Content-type: multipart/alternative;
382 boundary="BoundaryAlternative1"
383
384 --BoundaryAlternative1
385 Content-type: text/enriched; CHARSET=US-ASCII
386 Content-transfer-encoding: 7bit
387
388 This is supposedly enriched.
389
390 --BoundaryAlternative1
391 Content-type: text/plain; charset=ISO-8859-1; format=flowed
392 Content-transfer-encoding: 8bit
393
394 This is the body text/plain part.
395
396 --BoundaryAlternative1
397 Content-type: text/html; CHARSET=US-ASCII
398 Content-transfer-encoding: 7bit
399
400 <html><body><div><span style="line-height: 1.5;">
401 This is the text/html body part.
402 </span></div></body></html>
403
404 --BoundaryAlternative1--
405
406 --BoundaryMixed
407 Content-type: multipart/alternative;
408 boundary="BoundaryAlternative2"
409
410 --BoundaryAlternative2
411 Content-type: audio/wav
412 Content-transfer-encoding: 8bit
413
414 pretend wav audio
415
416 --BoundaryAlternative2
417 Content-type: audio/mp3
418 Content-transfer-encoding: 8bit
419
420 pretend mp3 audio
421
422 --BoundaryAlternative2
423 Content-type: audio/basic
424 Content-transfer-encoding: 8bit
425
426 pretend basic audio
427
428 --BoundaryAlternative2--
429
430 --BoundaryMixed--
431 EOF
432
433 # Write the expected output.
434 cat > $expected <<EOF
435 msg part type/subtype size description
436 13 multipart/mixed 1038
437 1 multipart/alternative 518
438 1.1 text/html 111
439 1.2 text/plain 34
440 1.3 text/enriched 29
441 2 multipart/alternative 326
442 2.1 audio/basic 20
443 2.2 audio/mp3 18
444 2.3 audio/wav 18
445 EOF
446
447 # check it -- vanilla output
448 run_prog mhlist $msgnum > $actual 2>&1
449 check "$expected" "$actual"
450
451 # Write the expected output.
452 cat > $expected <<EOF
453 msg part type/subtype size description
454 13 multipart/mixed 1038
455 1 multipart/alternative 518
456 1.1 text/html 111
457 1.2 text/plain 34
458 1.3 text/enriched 29
459 2 multipart/alternative 326
460 EOF
461
462 # check it -- just part 1
463 run_prog mhlist -part 1 $msgnum > $actual 2>&1
464 check "$expected" "$actual"
465
466 # Write the expected output.
467 cat > $expected <<EOF
468 msg part type/subtype size description
469 13 multipart/mixed 1038
470 1 multipart/alternative 518
471 2 multipart/alternative 326
472 EOF
473
474 # check it -- ask for audio/basic in part 1, should get nothing
475 run_prog mhlist -part 1 -type audio/basic $msgnum > $actual 2>&1
476 check "$expected" "$actual"
477
478 # Write the expected output.
479 cat > $expected <<EOF
480 msg part type/subtype size description
481 13 multipart/mixed 1038
482 1 multipart/alternative 518
483 1.1 text/plain 34
484 1.2 text/html 111
485 1.3 text/enriched 29
486 2 multipart/alternative 326
487 2.1 audio/wav 18
488 2.2 audio/basic 20
489 2.3 audio/mp3 18
490 EOF
491
492 # check it -- bump plain and wav to the top of their parts
493 run_prog mhlist -prefer text/plain -prefer audio/wav $msgnum > $actual 2>&1
494 check "$expected" "$actual"
495
496 # Write the expected output.
497 cat > $expected <<EOF
498 msg part type/subtype size description
499 13 multipart/mixed 1038
500 1 multipart/alternative 518
501 1.1 text/plain 34
502 1.2 text/enriched 29
503 1.3 text/html 111
504 2 multipart/alternative 326
505 2.1 audio/basic 20
506 2.2 audio/mp3 18
507 2.3 audio/wav 18
508 EOF
509
510 # check it -- bump plain and enriched to the top. add a bogus type as well.
511 run_prog mhlist -prefer foo/bar -prefer text/plain -prefer text/enriched $msgnum > $actual 2>&1
512 check "$expected" "$actual"
513
514
515 exit $failed