Added :regex tag -- an extension allowing to use posix regexp in address and header tests.
Showing
1 changed file
with
25 additions
and
17 deletions
... | @@ -142,6 +142,8 @@ | ... | @@ -142,6 +142,8 @@ |
142 | #:contains) | 142 | #:contains) |
143 | ((member #:matches opt-args) | 143 | ((member #:matches opt-args) |
144 | #:matches) | 144 | #:matches) |
145 | ((member #:regex opt-args) | ||
146 | #:regex) | ||
145 | (else | 147 | (else |
146 | #:is))) | 148 | #:is))) |
147 | 149 | ||
... | @@ -198,10 +200,25 @@ | ... | @@ -198,10 +200,25 @@ |
198 | (set! cl (append (list ch #\\) cl))) | 200 | (set! cl (append (list ch #\\) cl))) |
199 | (else | 201 | (else |
200 | (set! cl (append (list ch) cl)))))))) | 202 | (set! cl (append (list ch) cl)))))))) |
201 | |||
202 | ;;;; Standard tests: | ||
203 | 203 | ||
204 | 204 | ||
205 | (define (get-regex match key comp) | ||
206 | (case match | ||
207 | ((#:matches) | ||
208 | (make-regexp (sieve-regexp-to-posix key) | ||
209 | (if (eq? comp string-ci=?) | ||
210 | regexp/icase | ||
211 | '()))) | ||
212 | ((#:regex) | ||
213 | (make-regexp key | ||
214 | (if (eq? comp string-ci=?) | ||
215 | regexp/icase | ||
216 | '()))) | ||
217 | (else | ||
218 | #f))) | ||
219 | |||
220 | ;;;; Standard tests: | ||
221 | |||
205 | (define (test-address header-list key-list . opt-args) | 222 | (define (test-address header-list key-list . opt-args) |
206 | (let ((comp (find-comp opt-args)) | 223 | (let ((comp (find-comp opt-args)) |
207 | (match (find-match opt-args)) | 224 | (match (find-match opt-args)) |
... | @@ -219,12 +236,7 @@ | ... | @@ -219,12 +236,7 @@ |
219 | (let ((header-fields (mu-message-get-header-fields | 236 | (let ((header-fields (mu-message-get-header-fields |
220 | sieve-current-message | 237 | sieve-current-message |
221 | header-list)) | 238 | header-list)) |
222 | (rx (if (eq? match #:matches) | 239 | (rx (get-regex match key comp))) |
223 | (make-regexp (sieve-regexp-to-posix key) | ||
224 | (if (eq? comp string-ci=?) | ||
225 | regexp/icase | ||
226 | '())) | ||
227 | #f))) | ||
228 | (for-each | 240 | (for-each |
229 | (lambda (h) | 241 | (lambda (h) |
230 | (let ((hdr (cdr h))) | 242 | (let ((hdr (cdr h))) |
... | @@ -247,7 +259,7 @@ | ... | @@ -247,7 +259,7 @@ |
247 | ((#:contains) | 259 | ((#:contains) |
248 | (if (sieve-str-str addr key comp) | 260 | (if (sieve-str-str addr key comp) |
249 | (exit #t))) | 261 | (exit #t))) |
250 | ((#:matches) | 262 | ((#:matches #:regex) |
251 | (if (regexp-exec rx addr) | 263 | (if (regexp-exec rx addr) |
252 | (exit #t)))) | 264 | (exit #t)))) |
253 | (runtime-message SIEVE-NOTICE | 265 | (runtime-message SIEVE-NOTICE |
... | @@ -311,12 +323,7 @@ | ... | @@ -311,12 +323,7 @@ |
311 | (let ((header-fields (mu-message-get-header-fields | 323 | (let ((header-fields (mu-message-get-header-fields |
312 | sieve-current-message | 324 | sieve-current-message |
313 | header-list)) | 325 | header-list)) |
314 | (rx (if (eq? match #:matches) | 326 | (rx (get-regex match key comp))) |
315 | (make-regexp (sieve-regexp-to-posix key) | ||
316 | (if (eq? comp string-ci=?) | ||
317 | regexp/icase | ||
318 | '())) | ||
319 | #f))) | ||
320 | (for-each | 327 | (for-each |
321 | (lambda (h) | 328 | (lambda (h) |
322 | (let ((hdr (cdr h))) | 329 | (let ((hdr (cdr h))) |
... | @@ -328,7 +335,7 @@ | ... | @@ -328,7 +335,7 @@ |
328 | ((#:contains) | 335 | ((#:contains) |
329 | (if (sieve-str-str hdr key comp) | 336 | (if (sieve-str-str hdr key comp) |
330 | (exit #t))) | 337 | (exit #t))) |
331 | ((#:matches) | 338 | ((#:matches #:regex) |
332 | (if (regexp-exec rx hdr) | 339 | (if (regexp-exec rx hdr) |
333 | (exit #t))))))) | 340 | (exit #t))))))) |
334 | header-fields))) | 341 | header-fields))) |
... | @@ -341,7 +348,8 @@ | ... | @@ -341,7 +348,8 @@ |
341 | (cons "all" #f))) | 348 | (cons "all" #f))) |
342 | (define match-type (list (cons "is" #f) | 349 | (define match-type (list (cons "is" #f) |
343 | (cons "contains" #f) | 350 | (cons "contains" #f) |
344 | (cons "matches" #f))) | 351 | (cons "matches" #f) |
352 | (cons "regex" #f))) | ||
345 | (define size-comp (list (cons "under" #f) | 353 | (define size-comp (list (cons "under" #f) |
346 | (cons "over" #f))) | 354 | (cons "over" #f))) |
347 | (define comparator (list (cons "comparator" 'string))) | 355 | (define comparator (list (cons "comparator" 'string))) | ... | ... |
-
Please register or sign in to post a comment