1
require "vnd.dovecot.testsuite";
3
require "comparator-i;ascii-numeric";
11
test_set "message" text:
12
From: justin@example.com
15
Content-Type: multipart/mixed; boundary=donkey
17
This is a multi-part message in MIME format.
20
Content-Type: text/plain
25
Content-Type: text/stupid
30
Content-Type: text/plain/stupid
39
* RFC5173, Section 5.2:
40
* If an individual content type begins or ends with a '/' (slash) or
41
* contains multiple slashes, then it matches no content types.
46
if not body :content "text/plain" :matches "Plain Text*" {
47
test_fail "failed to match (1)";
50
if not body :content "text/plain" :contains "" {
51
test_fail "failed to match (2)";
54
if not body :content "text/stupid" :contains "" {
55
test_fail "failed to match (3)";
60
if body :content "/plain" :contains "" {
61
test_fail "matched :content \"/plain\"";
66
if body :content "text/" :contains "" {
67
test_fail "matched :content \"text/\"";
72
if body :content "text/plain/stupid" :contains "" {
73
test_fail "matched :content \"text/plain/stupid\"";
81
test_set "message" text:
82
From: justin@example.com
85
Content-Type: multipart/mixed; boundary=limit
87
This is a multi-part message in MIME format.
90
Content-Type: text/plain
92
This is a text message.
95
Content-Type: text/html
97
<html><body>This is HTML</body></html>
100
Content-Type: application/sieve
108
/* RFC5173, Section 5.2:
110
* Otherwise, if it contains a slash, then it specifies a full
111
* <type>/<subtype> pair, and matches only that specific content type.
112
* If it is the empty string, all MIME content types are matched.
113
* Otherwise, it specifies a <type> only, and any subtype of that type
117
test "Full Content Type" {
118
if not body :content "text/plain" :matches "This is a text message.*" {
119
test_fail "failed to match text/plain content";
122
if body :content "text/plain" :matches "<html><body>This is HTML</body></html>*" {
123
test_fail "erroneously matched text/html content";
126
if not body :content "text/html" :matches "<html><body>This is HTML</body></html>*" {
127
test_fail "failed to match text/html content";
130
if body :content "text/html" :matches "This is a text message.*" {
131
test_fail "erroneously matched text/plain content";
134
if body :content "text/html" :matches "This is HTML*" {
135
test_fail "body :content test matched plain text";
139
test "Empty Content Type" {
140
if not body :content "" :matches "This is a text message.*" {
141
test_fail "failed to match text/plain content";
144
if not body :content "" :matches "<html><body>This is HTML</body></html>*" {
145
test_fail "failed to match text/html content";
148
if not body :content "" :matches "keep;*" {
149
test_fail "failed to match application/sieve content";
152
if body :content "" :matches "*blurdybloop*" {
153
test_fail "body :content \"\" test matches nonsense";
157
test "Main Content Type" {
158
if not body :content "text" :matches "This is a text message.*" {
159
test_fail "failed to match text/plain content";
162
if not body :content "text" :matches "<html><body>This is HTML</body></html>*" {
163
test_fail "failed to match text/html content";
166
if body :content "text" :matches "keep;*" {
167
test_fail "erroneously matched application/sieve content";
175
test_set "message" text:
176
From: Whomever <whoever@example.com>
177
To: Someone <someone@example.com>
178
Date: Sat, 10 Oct 2009 00:30:04 +0200
180
Content-Type: multipart/mixed; boundary=outer
182
This is a multi-part message in MIME format.
185
Content-Type: multipart/alternative; boundary=inner
187
This is a nested multi-part message in MIME format.
190
Content-Type: text/plain; charset="us-ascii"
195
Content-Type: text/html; charset="us-ascii"
197
<html><body>Hello</body></html>
201
This is the end of the inner MIME multipart.
204
Content-Type: message/rfc822
207
Subject: hello request
213
This is the end of the outer MIME multipart.
217
/* RFC5173, Section 5.2:
219
* The search for MIME parts matching the :content specification is
220
* recursive and automatically descends into multipart and
221
* message/rfc822 MIME parts. All MIME parts with matching types are
222
* searched for the key strings. The test returns true if any
223
* combination of a searched MIME part and key-list argument match.
226
test "Nested Search" {
227
if not body :content "text/plain" :matches "Hello*" {
228
test_fail "failed to match text/plain content";
231
if body :content "text/plain" :matches "<html><body>Hello</body></html>*" {
232
test_fail "erroneously matched text/html content";
235
if not body :content "text/html" :matches "<html><body>Hello</body></html>*" {
236
test_fail "failed to match text/html content";
239
if body :content "text/html" :matches "Hello*" {
240
test_fail "erroneously matched text/plain content";
243
if not body :content "text" :contains "html" {
244
test_fail "failed match text content (1)";
247
if not body :content "text" :contains "hello" {
248
test_fail "failed match text content (2)";
251
if not body :content "text/plain" :contains "please say hello" {
252
test_fail "failed match nested message content as text/plain";
255
if not body :content "text" :contains "please say hello" {
256
test_fail "failed match nested message content as text/*";
259
if not body :content "text" :count "eq" :comparator "i;ascii-numeric" "3" {
260
test_fail "matched wrong number of \"text/*\" body parts";
264
/* RFC5173, Section 5.2:
266
* If the :content specification matches a multipart MIME part, only the
267
* prologue and epilogue sections of the part will be searched for the
268
* key strings, treating the entire prologue and the entire epilogue as
269
* separate strings; the contents of nested parts are only searched if
270
* their respective types match the :content specification.
274
test "Multipart Content" {
275
if not body :content "multipart" :contains
276
"This is a multi-part message in MIME format" {
277
test_fail "missed first multipart body part";
280
if not body :content "multipart" :contains
281
"This is a nested multi-part message in MIME format" {
282
test_fail "missed second multipart body part";
287
if not body :content "multipart" :contains
288
"This is the end of the inner MIME multipart" {
289
test_fail "missed third multipart body part";
292
if not body :content "multipart" :contains
293
"This is the end of the outer MIME multipart." {
294
test_fail "missed fourth multipart body part";
297
if body :content "multipart" :contains "--inner" {
298
test_fail "inner boundary is part of match";
301
if body :content "multipart" :contains "--outer" {
302
test_fail "outer boundary is part of match";
307
/* RFC5173, Section 5.2:
309
* If the :content specification matches a message/rfc822 MIME part,
310
* only the header of the nested message will be searched for the key
311
* strings, treating the header as a single string; the contents of the
312
* nested message body parts are only searched if their content type
313
* matches the :content specification.