1#!/bin/sh
2######################################################
3#
4# Test mhlist
5#
6######################################################
7
8set -e
9
10if test -z "${MH_OBJ_DIR}"; then
11    srcdir=`dirname $0`/../..
12    MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
13fi
14
15. "$MH_OBJ_DIR/test/common.sh"
16
17setup_test
18
19check_exit '-eq 1' mhlist -
20
21expected=$MH_TEST_DIR/$$.expected
22actual=$MH_TEST_DIR/$$.actual
23
24
25start_test 'with no options and no current message'
26run_test 'mhlist' 'mhlist: no cur message'
27
28start_test 'with no options and current message'
29folder +inbox 5 > /dev/null
30cat > $expected <<EOF
31 msg part  type/subtype              size description
32   5       text/plain                  25
33EOF
34run_prog mhlist > $actual 2>&1
35check $expected $actual 'keep first'
36
37start_test '-noheaders'
38run_test 'mhlist 5 -noheaders' '   5       text/plain                  25'
39
40start_test '-headers'
41run_prog mhlist -noheaders -headers > $actual 2>&1
42check $expected $actual 'keep first'
43
44start_test 'with folder and current message'
45run_prog mhlist +inbox > $actual 2>&1
46check $expected $actual 'keep first'
47
48start_test 'with specified message'
49run_prog mhlist 5 > $actual 2>&1
50check $expected $actual 'keep first'
51
52start_test '-file'
53run_prog mhlist -file "$MH_TEST_DIR/Mail/inbox/5" > $actual 2>&1
54check $expected $actual
55
56start_test '-file -'
57cat > $expected <<EOF
58 msg part  type/subtype              size description
59   0       text/plain                  25
60EOF
61run_prog mhlist -file - < "$MH_TEST_DIR/Mail/inbox/5" > $actual 2>&1
62check $expected $actual
63
64start_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.
68f=$MH_TEST_DIR/$$.blank
69cat >$f-yes <<\E
70foo: bar
71
72body1
73body2
74E
75sed '/^$/d' $f-yes >$f-no
76run_prog mhlist -file $f-yes >$actual-yes
77run_prog mhlist -file $f-no >$actual-no
78check $actual-yes $actual-no
79rm $f-yes $f-no
80
81start_test 'message number greater than highest'
82run_test 'mhlist 11' "mhlist: message 11 doesn't exist"
83
84start_test 'multiple messages'
85cat > $expected <<EOF
86 msg part  type/subtype              size description
87   2       text/plain                  25
88   8       text/plain                  25
89EOF
90run_prog mhlist 2 8 > $actual 2>&1
91check $expected $actual
92
93# Write message with a text/plain subpart.
94msgfile=`mhpath new`
95cat > $msgfile <<EOF
96To: recipient@example.com
97From: sender@example.com
98Subject: mhlist test
99MIME-Version: 1.0
100Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
101
102------- =_aaaaaaaaaa0
103Content-Type: multipart/related;
104    type="multipart/alternative";
105    boundary="subpart__1.1"
106
107--subpart__1.1
108Content-Type: text/plain; charset="iso-8859-1"
109Content-Disposition: attachment; filename="test1"
110
111This is the first text/plain part, in a subpart.
112
113--subpart__1.1--
114
115------- =_aaaaaaaaaa0
116Content-Type: text/plain; charset="iso-8859-1"
117Content-Disposition: attachment; filename="test2"
118Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
119Content-Transfer-Encoding: quoted-printable
120
121This is the second text/plain part.
122
123------- =_aaaaaaaaaa0
124Content-Type: text/plain; charset="iso-8859-1"; name="test3"
125Content-Disposition: attachment; filename="test3"
126
127This is the third text/plain part.
128
129------- =_aaaaaaaaaa0
130Content-Type: text/plain; charset="iso-8859-1"
131Content-Disposition: attachment; filename="test4"
132Content-Transfer-Encoding: base64
133
134VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
135
136------- =_aaaaaaaaaa0--
137EOF
138
139start_test '-part'
140run_test 'mhlist last -part 3 -noheader' \
141'  11       multipart/mixed            936
142     1     multipart/related          180
143     3     text/plain                  35'
144
145start_test '-part of a subpart'
146run_test 'mhlist last -part 1.1 -noheader' \
147'  11       multipart/mixed            936
148     1     multipart/related          180
149     1.1   text/plain                  49'
150
151start_test '-type'
152run_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
160start_test '-norealsize'
161run_test 'mhlist last -part 4 -noheader -norealsize' \
162'  11       multipart/mixed            936
163     1     multipart/related          180
164     4     text/plain                  49'
165
166start_test '-realsize, the default'
167run_test 'mhlist last -part 4 -noheader -norealsize -realsize' \
168'  11       multipart/mixed            936
169     1     multipart/related          180
170     4     text/plain                  36'
171
172start_test '-check'
173run_test 'mhlist last -part 2 -noheader -check' \
174'  11       multipart/mixed            936
175     1     multipart/related          180
176     2     text/plain                  36'
177
178start_test '-check with bad MD5 checksum'
179sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' $msgfile > $MH_TEST_DIR/$$.tmp
180mv -f $MH_TEST_DIR/$$.tmp $msgfile
181run_test 'mhlist last -part 2 -noheader -check' \
182'  11       multipart/mixed            936
183     1     multipart/related          180
184     2     text/plain                  36
185mhlist: content integrity suspect (digest mismatch) -- continuing
186        (content text/plain in message 11, part 2)'
187
188start_test '-nocheck, the default'
189run_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
199mark 1 -sequence cur -add -zero
200
201start_test '-verbose'
202run_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#
219start_test 'default changecur behavior'
220#
221
222run_test 'mark -sequence cur -list' 'cur: 11'
223
224#
225# Now test -nochangecur
226#
227
228mhlist -nochangecur 1 >/dev/null
229
230run_test 'mark -sequence cur -list' 'cur: 11'
231
232start_test 'MIME parser and m_getfld'
233cat > $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
239EOF
240
241msgfile=`mhpath new`
242msgnum=`basename $msgfile`
243cat > $msgfile <<EOF
244To: 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
357From: sender@example.com
358Subject: very long header
359Date: Wed, 4 Dec 2013 21:12:00 -0500
360MIME-Version: 1.0
361Content-Type: multipart/related; boundary="1"
362
363--1
364Content-Type: multipart/alternative; boundary="2"
365
366--2
367Content-Type: text/plain; charset="us-ascii"
368
369This is part 1.
370
371
372--2--
373
374--1
375Content-Type: text/plain; charset="us-ascii"
376
377This is part 2.
378
379
380--1--
381EOF
382
383run_prog mhlist last > $actual 2>&1
384check $expected $actual
385
386##  now check mhlist output
387
388msgfile=`mhpath new`
389msgnum=`basename $msgfile`
390cat > $msgfile <<EOF
391To: example@example.org
392From: someone <someone@example.com>
393Subject: mhlist test
394Date: Thu, 29 Jan 2015 18:12:21 +0000 (GMT)
395Content-Type: multipart/mixed; boundary="BoundaryMixed"
396
397--BoundaryMixed
398Content-type: multipart/alternative;
399 boundary="BoundaryAlternative1"
400
401--BoundaryAlternative1
402Content-type: text/enriched; CHARSET=US-ASCII
403Content-transfer-encoding: 7bit
404
405This is supposedly enriched.
406
407--BoundaryAlternative1
408Content-type: text/plain; charset=ISO-8859-1; format=flowed
409Content-transfer-encoding: 8bit
410
411This is the body text/plain part.
412
413--BoundaryAlternative1
414Content-type: text/html; CHARSET=US-ASCII
415Content-transfer-encoding: 7bit
416
417<html><body><div><span style="line-height: 1.5;">
418This is the text/html body part.
419</span></div></body></html>
420
421--BoundaryAlternative1--
422
423--BoundaryMixed
424Content-type: multipart/alternative;
425 boundary="BoundaryAlternative2"
426
427--BoundaryAlternative2
428Content-type: audio/wav
429Content-transfer-encoding: 8bit
430
431pretend wav audio
432
433--BoundaryAlternative2
434Content-type: audio/mp3
435Content-transfer-encoding: 8bit
436
437pretend mp3 audio
438
439--BoundaryAlternative2
440Content-type: audio/basic
441Content-transfer-encoding: 8bit
442
443pretend basic audio
444
445--BoundaryAlternative2--
446
447--BoundaryMixed--
448EOF
449
450# Write the expected output.
451cat > $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
462EOF
463
464start_test 'vanilla output'
465run_prog mhlist $msgnum > $actual 2>&1
466check "$expected" "$actual"
467
468# Write the expected output.
469cat > $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
477EOF
478
479start_test 'just part 1'
480run_prog mhlist -part 1 $msgnum > $actual 2>&1
481check "$expected" "$actual"
482
483# Write the expected output.
484cat > $expected <<EOF
485 msg part  type/subtype              size description
486  13       multipart/mixed           1038
487     1     multipart/alternative      518
488     2     multipart/alternative      326
489EOF
490
491start_test 'ask for audio/basic in part 1, should get nothing'
492run_prog mhlist -part 1 -type audio/basic $msgnum > $actual 2>&1
493check "$expected" "$actual"
494
495# Write the expected output.
496cat > $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
507EOF
508
509start_test 'bump plain and wav to the top of their parts'
510run_prog mhlist -prefer text/plain -prefer audio/wav $msgnum > $actual 2>&1
511check "$expected" "$actual"
512
513# Write the expected output.
514cat > $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
525EOF
526
527start_test 'bump plain and enriched to the top.  add a bogus type as well.'
528run_prog mhlist -prefer foo/bar -prefer text/plain -prefer text/enriched $msgnum > $actual 2>&1
529check "$expected" "$actual"
530
531
532finish_test
533exit $failed
534