Fixed mhlist -verbose to work with all content types [Bug #35219].
[mmh] / 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 expected=$MH_TEST_DIR/$$.expected
20 actual=$MH_TEST_DIR/$$.actual
21
22
23 # check with no options and no current message
24 run_test 'mhlist' 'mhlist: no cur message'
25
26 # check with no options and current message
27 folder +inbox 5 > /dev/null
28 cat > $expected <<EOF
29  msg part  type/subtype              size description                         
30    5       text/plain                  25
31 EOF
32 mhlist > $actual 2>&1
33 check $expected $actual 'keep first'
34
35 # check -noheaders
36 run_test 'mhlist 5 -noheaders' '   5       text/plain                  25'
37
38 # check -headers
39 mhlist -noheaders -headers > $actual 2>&1
40 check $expected $actual 'keep first'
41
42 # check with folder and current message
43 mhlist +inbox > $actual 2>&1
44 check $expected $actual 'keep first'
45
46 # check with specified message
47 mhlist 5 > $actual 2>&1
48 check $expected $actual 'keep first'
49
50 # check -file
51 mhlist -file "$MH_TEST_DIR/Mail/inbox/5" > $actual 2>&1
52 check $expected $actual
53
54 # check -file -
55 cat > $expected <<EOF
56  msg part  type/subtype              size description                         
57    0       text/plain                  25
58 EOF
59 mhlist -file - < "$MH_TEST_DIR/Mail/inbox/5" > $actual 2>&1
60 check $expected $actual
61
62 # check message number greater than highest
63 run_test 'mhlist 11' "mhlist: message 11 doesn't exist"
64
65 # check multiple messages
66 cat > $expected <<EOF
67  msg part  type/subtype              size description                         
68    2       text/plain                  25
69    8       text/plain                  25
70 EOF
71 mhlist 2 8 > $actual 2>&1
72 check $expected $actual
73
74 # Write message with a text/plain subpart.
75 msgfile=$(mhpath new)
76 cat > $msgfile <<EOF
77 To: recipient@example.com
78 From: sender@example.com
79 Subject: mhlist test
80 MIME-Version: 1.0
81 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
82
83 ------- =_aaaaaaaaaa0
84 Content-Type: multipart/related;
85     type="multipart/alternative";
86     boundary="subpart__1.1"
87
88 --subpart__1.1
89 Content-Type: text/plain; charset="iso-8859-1"
90 Content-Disposition: attachment; filename="test1"
91
92 This is the first text/plain part, in a subpart.
93
94 --subpart__1.1--
95
96 ------- =_aaaaaaaaaa0
97 Content-Type: text/plain; charset="iso-8859-1"
98 Content-Disposition: attachment; filename="test2"
99 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
100 Content-Transfer-Encoding: quoted-printable
101
102 This is the second text/plain part.
103
104 ------- =_aaaaaaaaaa0
105 Content-Type: text/plain; charset="iso-8859-1"; name="test3"
106 Content-Disposition: attachment; filename="test3"
107
108 This is the third text/plain part.
109
110 ------- =_aaaaaaaaaa0
111 Content-Type: text/plain; charset="iso-8859-1"
112 Content-Disposition: attachment; filename="test4"
113 Content-Transfer-Encoding: base64
114
115 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
116
117 ------- =_aaaaaaaaaa0--
118 EOF
119
120 # check -part
121 run_test 'mhlist last -part 3 -noheader' \
122 '  11       multipart/mixed            936
123      1     multipart/related          180
124      3     text/plain                  35'
125
126 # check -part of a subpart
127 run_test 'mhlist last -part 1.1 -noheader' \
128 '  11       multipart/mixed            936
129      1     multipart/related          180
130      1.1   text/plain                  49'
131
132 # check -type
133 run_test 'mhlist last -type text/plain -noheader' \
134 '  11       multipart/mixed            936
135      1     multipart/related          180
136      1.1   text/plain                  49
137      2     text/plain                  36
138      3     text/plain                  35
139      4     text/plain                  36'
140
141 # check -norealsize
142 run_test 'mhlist last -part 4 -noheader -norealsize' \
143 '  11       multipart/mixed            936
144      1     multipart/related          180
145      4     text/plain                  49'
146
147 # check -realsize, the default
148 run_test 'mhlist last -part 4 -noheader -norealsize -realsize' \
149 '  11       multipart/mixed            936
150      1     multipart/related          180
151      4     text/plain                  36'
152
153 # check -check
154 run_test 'mhlist last -part 2 -noheader -check' \
155 '  11       multipart/mixed            936
156      1     multipart/related          180
157      2     text/plain                  36'
158
159 # check -check with bad MD5 checksum
160 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' $msgfile > $MH_TEST_DIR/$$.tmp
161 mv -f $MH_TEST_DIR/$$.tmp $msgfile
162 run_test 'mhlist last -part 2 -noheader -check' \
163 '  11       multipart/mixed            936
164      1     multipart/related          180
165      2     text/plain                  36
166 mhlist: content integrity suspect (digest mismatch) -- continuing
167         (content text/plain in message 11, part 2)'
168
169 # check -nocheck, the default
170 run_test 'mhlist last -part 2 -noheader -check -nocheck' \
171 '  11       multipart/mixed            936
172      1     multipart/related          180
173      2     text/plain                  36'
174
175 # check -verbose
176 run_test 'mhlist 11 -verbose -noheader' \
177 '  11       multipart/mixed            936
178              boundary="----- =_aaaaaaaaaa0"
179      1     multipart/related          180
180              type="multipart/alternative"
181              boundary="subpart__1.1"
182      1.1   text/plain                  49
183              charset="iso-8859-1"
184      2     text/plain                  36
185              charset="iso-8859-1"
186      3     text/plain                  35
187              charset="iso-8859-1"
188              name="test3"
189      4     text/plain                  36
190              charset="iso-8859-1"'
191
192
193 exit $failed