1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
require "vnd.dovecot.testsuite";
/*
* ## RFC 5228, Section 5.1. Test address (page 26) ##
*/
/*
* TEST: Basic functionionality
*/
/* "The "address" test matches Internet addresses in structured headers
* that contain addresses. It returns true if any header contains any
* key in the specified part of the address, as modified by the
* comparator and the match keyword. Whether there are other addresses
* present in the header doesn't affect this test; this test does not
* provide any way to determine whether an address is the only address
* in a header.
*
* Like envelope and header, this test returns true if any combination
* of the header-list and key-list arguments match and returns false
* otherwise.
* "
*/
test_set "message" text:
From: stephan@example.com
To: nico@nl.example.com, harry@de.example.com
cc: Timo <tss(no spam)@fi.iki>
Subject: Frobnitzm
Test.
.
;
test "Basic functionality" {
/* Must match */
if not address :contains ["to", "from"] "harry" {
test_fail "failed to match address (1)";
}
if not address :contains ["to", "from"] "de.example" {
test_fail "failed to match address (2)";
}
if not address :matches "to" "*@*.example.com" {
test_fail "failed to match address (3)";
}
if not address :is "to" "harry@de.example.com" {
test_fail "failed to match address (4)";
}
/* Must not match */
if address :is ["to", "from"] "nonsense@example.com" {
test_fail "matches erroneous address";
}
/* Match first key */
if not address :contains ["to"] ["nico", "fred", "henk"] {
test_fail "failed to match first key";
}
/* Match second key */
if not address :contains ["to"] ["fred", "nico", "henk"] {
test_fail "failed to match second key";
}
/* Match last key */
if not address :contains ["to"] ["fred", "henk", "nico"] {
test_fail "failed to match last key";
}
/* First header */
if not address :contains ["to", "from"] ["fred", "nico", "henk"] {
test_fail "failed to match first header";
}
/* Second header */
if not address :contains ["from", "to"] ["fred", "nico", "henk"] {
test_fail "failed to match second header";
}
/* Comment */
if not address :is "cc" "tss@fi.iki" {
test_fail "failed to ignore comment in address";
}
}
/*
* TEST: Case-sensitivity
*/
/* "Internet email addresses [RFC 2822] have the somewhat awkward characteristic
* that the local-part to the left of the at-sign is considered case sensitive,
* and the domain-part to the right of the at-sign is case insensitive. The
* "address" command does not deal with this itself, but provides the
* ADDRESS-PART argument for allowing users to deal with it.
* "
*/
test_set "message" text:
From: stephan@example.com
To: Nico@nl.example.com, harry@DE.EXAMPLE.COM
Subject: Case-sensitivity
Test.
.
;
test "Case-sensitivity" {
/* Default: i;ascii-casemap */
if not address :is ["to", "from"] "nico@nl.example.com" {
test_fail "address comparator is i;octet by default (1)";
}
if not address :is ["to", "from"] "harry@de.example.com" {
test_fail "address comparator is i;octet by default (2)";
}
if not address :is ["to", "from"] "STEPHAN@example.com" {
test_fail "address comparator is i;octet by default (3)";
}
if not address :is :localpart ["to"] "nico" {
test_fail "address comparator is i;octet by default (4)";
}
/* Match case-sensitively */
if not address :is :comparator "i;octet" ["to"] "Nico@nl.example.com" {
test_fail "failed to match case-sensitive address (1)";
}
if not address :is :comparator "i;octet" ["to"] "harry@DE.EXAMPLE.COM" {
test_fail "failed to match case-sensitive address (2)";
}
if address :is :comparator "i;octet" ["to"] "harry@de.example.com" {
test_fail "failed to notice case difference in address with i;octet (1)";
}
if address :is :comparator "i;octet" ["from"] "STEPHAN@example.com" {
test_fail "failed to notice case difference in address with i;octet (2)";
}
if not address :is :localpart :comparator "i;octet" ["to"] "Nico" {
test_fail "failed to match case-sensitive localpart";
}
if address :is :localpart :comparator "i;octet" ["to"] "nico" {
test_fail "failed to notice case difference in local_part with i;octet";
}
if not address :is :domain :comparator "i;octet" ["to"] "DE.EXAMPLE.COM" {
test_fail "failed to match case-sensitive localpart";
}
if address :is :domain :comparator "i;octet" ["to"] "de.example.com" {
test_fail "failed to notice case difference in domain with i;octet";
}
}
/*
* TEST: Phrase part, comments and group names
*/
/* "The address primitive never acts on the phrase part of an email
* address or on comments within that address. It also never acts on
* group names, ...
* "
*/
test_set "message" text:
From: Stephan Bosch <stephan(the author)@example.com>
To: Nico Thalens <nico@nl.example.com>, Harry Becker <harry@de.example.com>
cc: tukkers: henk@tukkerland.ex, theo@tukkerland.ex, frits@tukkerland.ex;
Subject: Frobnitzm
Test.
.
;
test "Phrase part, comments and group names" {
if address :contains :all :comparator "i;ascii-casemap"
["to","from"] ["Bosch", "Thalens", "Becker"] {
test_fail "matched phrase part";
}
if address :contains :all :comparator "i;ascii-casemap" "from" "author" {
test_fail "matched comment";
}
if address :contains :all :comparator "i;ascii-casemap" ["cc"] ["tukkers"] {
test_fail "matched group name";
}
}
/*
* TEST: Group addresses
*/
/* "... although it does act on the addresses within the group
* construct.
* "
*/
test_set "message" text:
From: stephan@friep.frop
To: undisclosed-recipients:;
cc: tukkers: henk@tukkerland.ex, theo@tukkerland.ex, frits@tukkerland.ex;
Subject: Invalid addresses
Test.
.
;
test "Group addresses" {
if not address :is :domain ["cc"] ["tukkerland.ex"] {
test_fail "failed to match group address (1)";
}
if not address :is :localpart ["cc"] ["henk"] {
test_fail "failed to match group address (2)";
}
if not address :is :localpart ["cc"] ["theo"] {
test_fail "failed to match group address (3)";
}
if not address :is :localpart ["cc"] ["frits"] {
test_fail "failed to match group address (4)";
}
}
/*
* TEST: Address headers
*/
/* "Implementations MUST restrict the address test to headers that
* contain addresses, but MUST include at least From, To, Cc, Bcc,
* Sender, Resent-From, and Resent-To, and it SHOULD include any other
* header that utilizes an "address-list" structured header body.
* "
*/
test_set "message" text:
From: stephan@friep.frop
To: henk@tukkerland.ex
CC: ivo@boer.ex
Bcc: joop@hooibaal.ex
Sender: s.bosch@friep.frop
Resent-From: ivo@boer.ex
Resent-To: idioot@dombo.ex
Subject: Berichtje
Test.
.
;
test "Address headers" {
if not address "from" "stephan@friep.frop" {
test_fail "from header not recognized";
}
if not address "to" "henk@tukkerland.ex" {
test_fail "to header not recognized";
}
if not address "cc" "ivo@boer.ex" {
test_fail "cc header not recognized";
}
if not address "bcc" "joop@hooibaal.ex" {
test_fail "bcc header not recognized";
}
if not address "sender" "s.bosch@friep.frop" {
test_fail "sender header not recognized";
}
if not address "resent-from" "ivo@boer.ex" {
test_fail "resent-from header not recognized";
}
if not address "resent-to" "idioot@dombo.ex" {
test_fail "resent-to header not recognized";
}
}
/* ## RFC 5228, Section 2.7.4. Comparisons against Addresses (page 16) ## */
/*
* TEST: Invalid addresses
*/
/*
* "If an address is not syntactically valid, then it will not be matched
* by tests specifying ":localpart" or ":domain".
* "
*/
test_set "message" text:
From: stephan@
To: @example.org
Cc: nonsense
Resent-To:
Bcc: nico@frop.example.com, @example.org
Resent-Cc:<jürgen@example.com>
Subject: Invalid addresses
Test.
.
;
test "Invalid addresses" {
if address :localpart "from" "stephan" {
test_fail ":localpart matched invalid address";
}
if address :localpart "resent-cc" "jürgen" {
test_fail ":localpart matched invalid UTF-8 address";
}
if address :domain "to" "example.org" {
test_fail ":domain matched invalid address";
}
if address :domain "resent-cc" "example.com" {
test_fail ":domain matched invalid UTF-8 address";
}
if not address :is :all "resent-to" "" {
test_fail ":all failed to match empty address";
}
if not address :is :all "cc" "nonsense" {
test_fail ":all failed to match invalid address";
}
if not address :is :all "resent-cc" "<jürgen@example.com>" {
test_fail ":all failed to match invalid UTF-8 address";
}
if address :is :localpart "bcc" "" {
test_fail ":localpart matched invalid address";
}
if address :is :domain "cc" "example.org" {
test_fail ":domain matched invalid address";
}
}
/*
* TEST: Default address part
*/
/* "If an optional address-part is omitted, the default is ":all".
* "
*/
test_set "message" text:
From: stephan@example.com
To: nico@nl.example.com, harry@de.example.com
Subject: Frobnitzm
Test.
.
;
test "Default address part" {
if not address :is :comparator "i;ascii-casemap" "from" "stephan@example.com"
{
test_fail "invalid default address part (1)";
}
if not address :is :comparator "i;ascii-casemap" "to"
["harry@de.example.com"] {
test_fail "invalid default address part (2)";
}
}
/*
* TEST: Mime encoding of '@' in display name
*/
test_set "message" text:
From: "Frop <frop@example.org>"
To: =?UTF-8?B?RnJpZXBAZnJvcA0K?=
<friep@example.com>
Subject: Test
Frop!
.
;
test "Mime encoding of '@' in display name" {
# Relevant sieve rule:
if not address :is "To"
["friep@example.com"] {
test_fail "Invalid address extracted";
}
}
/*
* TEST: Erroneous mime encoding
*/
test_set "message" text:
From: "William Wallace <william@scotsmen.ex>"
To: "=?UTF-8?B?IkR1bWIgTWFpbGVyIg==?="
<horde@lists.scotsmen.ex>
Subject: Test
Frop!
.
;
test "Erroneous mime encoding" {
# Relevant sieve rule:
if not address :is ["To","CC"] ["horde@lists.scotsmen.ex","archers@lists.scotsmen.ex"] {
test_fail "Failed to match improperly encoded address headers";
}
}
|