1#!/bin/sh
2#
3# Test bogus and strange headers
4
5
6. "$MH_TEST_COMMON"
7
8expected=$MH_TEST_DIR/$$.expected
9
10# Write message with bogus header field (missing blank line, really).
11
12msgfile="`mhpath b`"
13msgnum="${msgfile##*/}"
14cat >"$msgfile" <<!
15Date: Sun, 18 Dec 2005 00:52:39 +0100
16From: foo@example.edu
17To: bar@example.edu
18Subject: test
19This is a multi-part message in MIME format.
20
21I am a stupid spammer.
22!
23
24runandcheck "scan $msgnum" <<!
25??Format error (message $msgnum) in component 5
26  $msgnum  2005-12-18 00:52  foo@example.edu    test
27!
28
29runandcheck "show $msgnum" <<!
30show: message format error in component #5
31mhl: format error in message 11
32part       text/plain                  23
33I am a stupid spammer.
34!
35
36
37
38# check m_getfld() handling of empty header field
39
40msgfile="`mhpath b`"
41msgnum="${msgfile##*/}"
42printf 'Date: Sat, 12 Jan 2013 09:07:01 -0600\nReceived:' >"$msgfile"
43
44runandcheck "scan l" <<!
45??Format error (message $msgnum) in component 2
46  $msgnum  2013-01-12 09:07
47!
48
49
50
51# check m_getfld() handling of excessively long header field name
52
53msgfile="`mhpath b`"
54msgnum="${msgfile##*/}"
55cat >"$msgfile" <<!
56Date: Tue, 15 Jan 2013 21:13:12 -0600
57ThisHeaderFieldNameIsWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaayTooLong: OK
58!
59
60runandcheck "scan l" <<!
61??Format error (message $msgnum) in component 2
62  $msgnum  2013-01-15 21:13
63!
64
65
66
67# check m_getfld() handling of header field name with whitespace
68
69msgfile="`mhpath b`"
70msgnum="${msgfile##*/}"
71cat >"$msgfile" <<!
72Date: Thu, 17 Jan 2013 19:33:46 -0600
73A header field name with whitespace: foo
74Subject: Will this be printed?
75
76Test
77
78!
79
80runandcheck "scan l" <<!
81??Format error (message $msgnum) in component 2
82  $msgnum  2013-01-17 19:33                     Will this be printed?
83!
84
85
86
87# check m_getfld() handling of header field name without a colon
88
89msgfile="`mhpath b`"
90msgnum="${msgfile##*/}"
91cat >"$msgfile" <<!
92Date: Thu, 17 Jan 2013 19:34:46 -0600
93A_header_field_name_without_a_colon_..._or_is_this_the_first_line_of_the_body_question-mark
94Subject: Will this be printed?
95
96Test
97
98!
99
100runandcheck "scan l" <<!
101??Format error (message $msgnum) in component 2
102  $msgnum  2013-01-17 19:34                     Will this be printed?
103!
104
105
106
107# check m_getfld() handling of empty field name
108
109msgfile="`mhpath b`"
110msgnum="${msgfile##*/}"
111cat >"$msgfile" <<!
112Date: Thu, 17 Jan 2013 19:35:46 -0600
113: foo
114Subject: Will this be printed?
115
116Test
117
118!
119
120runandcheck "scan l" <<!
121??Format error (message $msgnum) in component 2
122  $msgnum  2013-01-17 19:35                     Will this be printed?
123!
124
125
126
127
128# check m_getfld() handling of dashed body separator (as in drafts)
129
130msgfile="`mhpath b`"
131msgnum="${msgfile##*/}"
132cat >"$msgfile" <<!
133Date: Thu, 17 Jan 2013 19:36:46 -0600
134----------
135Subject: Will this be printed?
136
137Test
138
139!
140
141runandcheck "scan l" <<!
142  $msgnum  2013-01-17 19:36
143!
144
145
146msgfile="`mhpath b`"
147msgnum="${msgfile##*/}"
148cat >"$msgfile" <<!
149Date: Thu, 17 Jan 2013 19:37:46 -0600
150-
151Subject: Will this be printed?
152
153Test
154
155!
156
157runandcheck "scan l" <<!
158  $msgnum  2013-01-17 19:37
159!
160
161
162msgfile="`mhpath b`"
163msgnum="${msgfile##*/}"
164cat >"$msgfile" <<!
165Date: Thu, 17 Jan 2013 19:39:46 -0600
166-----foo
167Subject: Will this be printed?
168
169Test
170
171!
172
173runandcheck "scan l" <<!
174??Format error (message $msgnum) in component 2
175  $msgnum  2013-01-17 19:39                     Will this be printed?
176!
177
178
179msgfile="`mhpath b`"
180msgnum="${msgfile##*/}"
181cat >"$msgfile" <<!
182Date: Thu, 17 Jan 2013 19:40:46 -0600
183-foo
184Subject: Will this be printed?
185
186Test
187
188!
189
190runandcheck "scan l" <<!
191??Format error (message $msgnum) in component 2
192  $msgnum  2013-01-17 19:40                     Will this be printed?
193!
194
195
196msgfile="`mhpath b`"
197msgnum="${msgfile##*/}"
198cat >"$msgfile" <<!
199Date: Thu, 17 Jan 2013 19:41:46 -0600
200--- --- ---
201Subject: Will this be printed?
202
203Test
204
205!
206
207runandcheck "scan l" <<!
208??Format error (message $msgnum) in component 2
209  $msgnum  2013-01-17 19:41                     Will this be printed?
210!
211
212
213# valid headers that might be treated as body separators but should not
214
215msgfile="`mhpath b`"
216msgnum="${msgfile##*/}"
217cat >"$msgfile" <<!
218Date: Thu, 17 Jan 2013 19:42:46 -0600
219-: strange but valid header name
220-------: also a valid header name
221-dash: nothing special if it start with a dash
222-------dash: or with many dashes
223-..|.-|...|....: could even be morse code ;-)
224sort</etc/passwd|lp&&date: ... o ar command lins *eek*
225Subject: This will be printed!
226
227Test
228
229!
230
231runandcheck "scan l" <<!
232  $msgnum  2013-01-17 19:42                     This will be printed!
233!
234