Adjust tests/bad-input/test-header for m_gefld2()
[mmh] / test / tests / bad-input / test-header
1 #!/bin/sh
2 #
3 # Test bogus and strange headers
4
5
6 . "$MH_TEST_COMMON"
7
8 expected=$MH_TEST_DIR/$$.expected
9
10 # Write message with bogus header field (missing blank line, really).
11
12 msgfile="`mhpath b`"
13 msgnum="${msgfile##*/}"
14 cat >"$msgfile" <<!
15 Date: Sun, 18 Dec 2005 00:52:39 +0100
16 From: foo@example.edu
17 To: bar@example.edu
18 Subject: test
19 This is a multi-part message in MIME format.
20
21 I am a stupid spammer.
22 !
23
24 runandcheck "scan $msgnum" <<!
25 ??Format error (message $msgnum) in component 5
26   $msgnum  2005-12-18 00:52  foo@example.edu    test
27 !
28
29 runandcheck "show $msgnum" <<!
30 show: message format error in component #5
31 mhl: format error in message 11
32 part       text/plain                  23
33 I am a stupid spammer.
34 !
35
36
37
38 # check m_getfld() handling of empty header field
39
40 msgfile="`mhpath b`"
41 msgnum="${msgfile##*/}"
42 printf 'Date: Sat, 12 Jan 2013 09:07:01 -0600\nReceived:' >"$msgfile"
43
44 runandcheck "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
53 msgfile="`mhpath b`"
54 msgnum="${msgfile##*/}"
55 cat >"$msgfile" <<!
56 Date: Tue, 15 Jan 2013 21:13:12 -0600
57 ThisHeaderFieldNameIsWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaayTooLong: OK
58 !
59
60 runandcheck "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
69 msgfile="`mhpath b`"
70 msgnum="${msgfile##*/}"
71 cat >"$msgfile" <<!
72 Date: Thu, 17 Jan 2013 19:33:46 -0600
73 A header field name with whitespace: foo
74 Subject: Will this be printed?
75
76 Test
77
78 !
79
80 runandcheck "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
89 msgfile="`mhpath b`"
90 msgnum="${msgfile##*/}"
91 cat >"$msgfile" <<!
92 Date: Thu, 17 Jan 2013 19:34:46 -0600
93 A_header_field_name_without_a_colon_..._or_is_this_the_first_line_of_the_body_question-mark
94 Subject: Will this be printed?
95
96 Test
97
98 !
99
100 runandcheck "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
109 msgfile="`mhpath b`"
110 msgnum="${msgfile##*/}"
111 cat >"$msgfile" <<!
112 Date: Thu, 17 Jan 2013 19:35:46 -0600
113 : foo
114 Subject: Will this be printed?
115
116 Test
117
118 !
119
120 runandcheck "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
130 msgfile="`mhpath b`"
131 msgnum="${msgfile##*/}"
132 cat >"$msgfile" <<!
133 Date: Thu, 17 Jan 2013 19:36:46 -0600
134 ----------
135 Subject: Will this be printed?
136
137 Test
138
139 !
140
141 runandcheck "scan l" <<!
142   $msgnum  2013-01-17 19:36                     
143 !
144
145
146 msgfile="`mhpath b`"
147 msgnum="${msgfile##*/}"
148 cat >"$msgfile" <<!
149 Date: Thu, 17 Jan 2013 19:37:46 -0600
150 -
151 Subject: Will this be printed?
152
153 Test
154
155 !
156
157 runandcheck "scan l" <<!
158   $msgnum  2013-01-17 19:37                     
159 !
160
161
162 msgfile="`mhpath b`"
163 msgnum="${msgfile##*/}"
164 cat >"$msgfile" <<!
165 Date: Thu, 17 Jan 2013 19:39:46 -0600
166 -----foo
167 Subject: Will this be printed?
168
169 Test
170
171 !
172
173 runandcheck "scan l" <<!
174 ??Format error (message $msgnum) in component 2
175   $msgnum  2013-01-17 19:39                     Will this be printed?
176 !
177
178
179 msgfile="`mhpath b`"
180 msgnum="${msgfile##*/}"
181 cat >"$msgfile" <<!
182 Date: Thu, 17 Jan 2013 19:40:46 -0600
183 -foo
184 Subject: Will this be printed?
185
186 Test
187
188 !
189
190 runandcheck "scan l" <<!
191 ??Format error (message $msgnum) in component 2
192   $msgnum  2013-01-17 19:40                     Will this be printed?
193 !
194
195
196 msgfile="`mhpath b`"
197 msgnum="${msgfile##*/}"
198 cat >"$msgfile" <<!
199 Date: Thu, 17 Jan 2013 19:41:46 -0600
200 --- --- ---
201 Subject: Will this be printed?
202
203 Test
204
205 !
206
207 runandcheck "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
215 msgfile="`mhpath b`"
216 msgnum="${msgfile##*/}"
217 cat >"$msgfile" <<!
218 Date: 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 ;-)
224 sort</etc/passwd|lp&&date: ... o ar command lins *eek*
225 Subject: This will be printed!
226
227 Test
228
229 !
230
231 runandcheck "scan l" <<!
232   $msgnum  2013-01-17 19:42                     This will be printed!
233 !