]> diplodocus.org Git - nmh/blob - test/mhlist/test-mhlist
content_error(): Don't strlen(invo_name) that might be NULL.
[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 start_test 'with no options and no current message'
26 run_test 'mhlist' 'mhlist: no cur message'
27
28 start_test '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 start_test '-noheaders'
38 run_test 'mhlist 5 -noheaders' ' 5 text/plain 25'
39
40 start_test '-headers'
41 run_prog mhlist -noheaders -headers > $actual 2>&1
42 check $expected $actual 'keep first'
43
44 start_test 'with folder and current message'
45 run_prog mhlist +inbox > $actual 2>&1
46 check $expected $actual 'keep first'
47
48 start_test 'with specified message'
49 run_prog mhlist 5 > $actual 2>&1
50 check $expected $actual 'keep first'
51
52 start_test '-file'
53 run_prog mhlist -file "$MH_TEST_DIR/Mail/inbox/5" > $actual 2>&1
54 check $expected $actual
55
56 start_test '-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 start_test 'message with no blank line separating the headers from the body.'
65 # Shouldn't make a difference to the size of the body part.
66 # Bug meant no-blank-line case was one bigger by including the `\n'
67 # ending the last header.
68 f=$MH_TEST_DIR/$$.blank
69 cat >$f-yes <<\E
70 foo: bar
71
72 body1
73 body2
74 E
75 sed '/^$/d' $f-yes >$f-no
76 run_prog mhlist -file $f-yes >$actual-yes
77 run_prog mhlist -file $f-no >$actual-no
78 check $actual-yes $actual-no
79 rm $f-yes $f-no
80
81 start_test 'message number greater than highest'
82 run_test 'mhlist 11' "mhlist: message 11 doesn't exist"
83
84 start_test 'multiple messages'
85 cat > $expected <<EOF
86 msg part type/subtype size description
87 2 text/plain 25
88 8 text/plain 25
89 EOF
90 run_prog mhlist 2 8 > $actual 2>&1
91 check $expected $actual
92
93 # Write message with a text/plain subpart.
94 msgfile=`mhpath new`
95 cat > $msgfile <<EOF
96 To: recipient@example.com
97 From: sender@example.com
98 Subject: mhlist test
99 MIME-Version: 1.0
100 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
101
102 ------- =_aaaaaaaaaa0
103 Content-Type: multipart/related;
104 type="multipart/alternative";
105 boundary="subpart__1.1"
106
107 --subpart__1.1
108 Content-Type: text/plain; charset="iso-8859-1"
109 Content-Disposition: attachment; filename="test1"
110
111 This is the first text/plain part, in a subpart.
112
113 --subpart__1.1--
114
115 ------- =_aaaaaaaaaa0
116 Content-Type: text/plain; charset="iso-8859-1"
117 Content-Disposition: attachment; filename="test2"
118 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
119 Content-Transfer-Encoding: quoted-printable
120
121 This is the second text/plain part.
122
123 ------- =_aaaaaaaaaa0
124 Content-Type: text/plain; charset="iso-8859-1"; name="test3"
125 Content-Disposition: attachment; filename="test3"
126
127 This is the third text/plain part.
128
129 ------- =_aaaaaaaaaa0
130 Content-Type: text/plain; charset="iso-8859-1"
131 Content-Disposition: attachment; filename="test4"
132 Content-Transfer-Encoding: base64
133
134 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
135
136 ------- =_aaaaaaaaaa0--
137 EOF
138
139 start_test '-part'
140 run_test 'mhlist last -part 3 -noheader' \
141 ' 11 multipart/mixed 936
142 1 multipart/related 180
143 3 text/plain 35'
144
145 start_test '-part of a subpart'
146 run_test 'mhlist last -part 1.1 -noheader' \
147 ' 11 multipart/mixed 936
148 1 multipart/related 180
149 1.1 text/plain 49'
150
151 start_test '-type'
152 run_test 'mhlist last -type text/plain -noheader' \
153 ' 11 multipart/mixed 936
154 1 multipart/related 180
155 1.1 text/plain 49
156 2 text/plain 36
157 3 text/plain 35
158 4 text/plain 36'
159
160 start_test '-norealsize'
161 run_test 'mhlist last -part 4 -noheader -norealsize' \
162 ' 11 multipart/mixed 936
163 1 multipart/related 180
164 4 text/plain 49'
165
166 start_test '-realsize, the default'
167 run_test 'mhlist last -part 4 -noheader -norealsize -realsize' \
168 ' 11 multipart/mixed 936
169 1 multipart/related 180
170 4 text/plain 36'
171
172 start_test '-check'
173 run_test 'mhlist last -part 2 -noheader -check' \
174 ' 11 multipart/mixed 936
175 1 multipart/related 180
176 2 text/plain 36'
177
178 start_test '-check with bad MD5 checksum'
179 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' $msgfile > $MH_TEST_DIR/$$.tmp
180 mv -f $MH_TEST_DIR/$$.tmp $msgfile
181 run_test 'mhlist last -part 2 -noheader -check' \
182 ' 11 multipart/mixed 936
183 1 multipart/related 180
184 2 text/plain 36
185 mhlist: content integrity suspect (digest mismatch) -- continuing
186 (content text/plain in message 11, part 2)'
187
188 start_test '-nocheck, the default'
189 run_test 'mhlist last -part 2 -noheader -check -nocheck' \
190 ' 11 multipart/mixed 936
191 1 multipart/related 180
192 2 text/plain 36'
193
194 #
195 # Set the cur sequence to 1 to test default behavior of changecur after
196 # this test.
197 #
198
199 mark 1 -sequence cur -add -zero
200
201 start_test '-verbose'
202 run_test 'mhlist 11 -verbose -noheader' \
203 ' 11 multipart/mixed 936
204 boundary="----- =_aaaaaaaaaa0"
205 1 multipart/related 180
206 type="multipart/alternative"
207 boundary="subpart__1.1"
208 1.1 text/plain 49
209 charset="iso-8859-1"
210 2 text/plain 36
211 charset="iso-8859-1"
212 3 text/plain 35
213 charset="iso-8859-1"
214 name="test3"
215 4 text/plain 36
216 charset="iso-8859-1"'
217
218 #
219 start_test 'default changecur behavior'
220 #
221
222 run_test 'mark -sequence cur -list' 'cur: 11'
223
224 #
225 # Now test -nochangecur
226 #
227
228 mhlist -nochangecur 1 >/dev/null
229
230 run_test 'mark -sequence cur -list' 'cur: 11'
231
232 start_test 'MIME parser and m_getfld'
233 cat > $expected <<EOF
234 msg part type/subtype size description
235 12 multipart/related 204
236 1 multipart/alternative 74
237 1.1 text/plain 17
238 2 text/plain 17
239 EOF
240
241 msgfile=`mhpath new`
242 msgnum=`basename $msgfile`
243 cat > $msgfile <<EOF
244 To: 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 recipient@example.com, recipient@example.com, recipient@example.com,
340 recipient@example.com, recipient@example.com, recipient@example.com,
341 recipient@example.com, recipient@example.com, recipient@example.com,
342 recipient@example.com, recipient@example.com, recipient@example.com,
343 recipient@example.com, recipient@example.com, recipient@example.com,
344 recipient@example.com, recipient@example.com, recipient@example.com,
345 recipient@example.com, recipient@example.com, recipient@example.com,
346 recipient@example.com, recipient@example.com, recipient@example.com,
347 recipient@example.com, recipient@example.com, recipient@example.com,
348 recipient@example.com, recipient@example.com, recipient@example.com,
349 recipient@example.com, recipient@example.com, recipient@example.com,
350 recipient@example.com, recipient@example.com, recipient@example.com,
351 recipient@example.com, recipient@example.com, recipient@example.com,
352 recipient@example.com, recipient@example.com, recipient@example.com,
353 recipient@example.com, recipient@example.com, recipient@example.com,
354 recipient@example.com, recipient@example.com, recipient@example.com,
355 recipient@example.com, recipient@example.com, recipient@example.com,
356 re@example.com
357 From: sender@example.com
358 Subject: very long header
359 Date: Wed, 4 Dec 2013 21:12:00 -0500
360 MIME-Version: 1.0
361 Content-Type: multipart/related; boundary="1"
362
363 --1
364 Content-Type: multipart/alternative; boundary="2"
365
366 --2
367 Content-Type: text/plain; charset="us-ascii"
368
369 This is part 1.
370
371
372 --2--
373
374 --1
375 Content-Type: text/plain; charset="us-ascii"
376
377 This is part 2.
378
379
380 --1--
381 EOF
382
383 run_prog mhlist last > $actual 2>&1
384 check $expected $actual
385
386 ## now check mhlist output
387
388 msgfile=`mhpath new`
389 msgnum=`basename $msgfile`
390 cat > $msgfile <<EOF
391 To: example@example.org
392 From: someone <someone@example.com>
393 Subject: mhlist test
394 Date: Thu, 29 Jan 2015 18:12:21 +0000 (GMT)
395 Content-Type: multipart/mixed; boundary="BoundaryMixed"
396
397 --BoundaryMixed
398 Content-type: multipart/alternative;
399 boundary="BoundaryAlternative1"
400
401 --BoundaryAlternative1
402 Content-type: text/enriched; CHARSET=US-ASCII
403 Content-transfer-encoding: 7bit
404
405 This is supposedly enriched.
406
407 --BoundaryAlternative1
408 Content-type: text/plain; charset=ISO-8859-1; format=flowed
409 Content-transfer-encoding: 8bit
410
411 This is the body text/plain part.
412
413 --BoundaryAlternative1
414 Content-type: text/html; CHARSET=US-ASCII
415 Content-transfer-encoding: 7bit
416
417 <html><body><div><span style="line-height: 1.5;">
418 This is the text/html body part.
419 </span></div></body></html>
420
421 --BoundaryAlternative1--
422
423 --BoundaryMixed
424 Content-type: multipart/alternative;
425 boundary="BoundaryAlternative2"
426
427 --BoundaryAlternative2
428 Content-type: audio/wav
429 Content-transfer-encoding: 8bit
430
431 pretend wav audio
432
433 --BoundaryAlternative2
434 Content-type: audio/mp3
435 Content-transfer-encoding: 8bit
436
437 pretend mp3 audio
438
439 --BoundaryAlternative2
440 Content-type: audio/basic
441 Content-transfer-encoding: 8bit
442
443 pretend basic audio
444
445 --BoundaryAlternative2--
446
447 --BoundaryMixed--
448 EOF
449
450 # Write the expected output.
451 cat > $expected <<EOF
452 msg part type/subtype size description
453 13 multipart/mixed 1038
454 1 multipart/alternative 518
455 1.1 text/html 111
456 1.2 text/plain 34
457 1.3 text/enriched 29
458 2 multipart/alternative 326
459 2.1 audio/basic 20
460 2.2 audio/mp3 18
461 2.3 audio/wav 18
462 EOF
463
464 start_test 'vanilla output'
465 run_prog mhlist $msgnum > $actual 2>&1
466 check "$expected" "$actual"
467
468 # Write the expected output.
469 cat > $expected <<EOF
470 msg part type/subtype size description
471 13 multipart/mixed 1038
472 1 multipart/alternative 518
473 1.1 text/html 111
474 1.2 text/plain 34
475 1.3 text/enriched 29
476 2 multipart/alternative 326
477 EOF
478
479 start_test 'just part 1'
480 run_prog mhlist -part 1 $msgnum > $actual 2>&1
481 check "$expected" "$actual"
482
483 # Write the expected output.
484 cat > $expected <<EOF
485 msg part type/subtype size description
486 13 multipart/mixed 1038
487 1 multipart/alternative 518
488 2 multipart/alternative 326
489 EOF
490
491 start_test 'ask for audio/basic in part 1, should get nothing'
492 run_prog mhlist -part 1 -type audio/basic $msgnum > $actual 2>&1
493 check "$expected" "$actual"
494
495 # Write the expected output.
496 cat > $expected <<EOF
497 msg part type/subtype size description
498 13 multipart/mixed 1038
499 1 multipart/alternative 518
500 1.1 text/plain 34
501 1.2 text/html 111
502 1.3 text/enriched 29
503 2 multipart/alternative 326
504 2.1 audio/wav 18
505 2.2 audio/basic 20
506 2.3 audio/mp3 18
507 EOF
508
509 start_test 'bump plain and wav to the top of their parts'
510 run_prog mhlist -prefer text/plain -prefer audio/wav $msgnum > $actual 2>&1
511 check "$expected" "$actual"
512
513 # Write the expected output.
514 cat > $expected <<EOF
515 msg part type/subtype size description
516 13 multipart/mixed 1038
517 1 multipart/alternative 518
518 1.1 text/enriched 29
519 1.2 text/plain 34
520 1.3 text/html 111
521 2 multipart/alternative 326
522 2.1 audio/basic 20
523 2.2 audio/mp3 18
524 2.3 audio/wav 18
525 EOF
526
527 start_test 'bump plain and enriched to the top. add a bogus type as well.'
528 run_prog mhlist -prefer foo/bar -prefer text/plain -prefer text/enriched $msgnum > $actual 2>&1
529 check "$expected" "$actual"
530
531
532 finish_test
533 exit $failed