Next: Actions, Previous: Comparators, Up: Sieve Language
This section describes the built-in tests supported by gnu libsieve. In the discussion below the following macro-notations are used:
:is
:is
match type describes an absolute match; if the contents of
the first string are absolutely the same as the contents of the
second string, they match. Only the string “frobnitzm” is the string
“frobnitzm”. The null key “:is” and only “:is” the null value.
This is the default match-type.
:contains
:contains
match type describes a substring match. If the value
argument contains the key argument as a substring, the match is true.
For instance, the string “frobnitzm” contains “frob” and “nit”, but
not “fbm”. The null key “” is contained in all values.
:matches
:matches
version specifies a wildcard match using the
characters ‘*’ and ‘?’. ‘*’ matches zero or more
characters, and ‘?’ matches a single character. ‘?’ and
‘*’ may be escaped as ‘\\?’ and ‘\\*’ in strings to match
against themselves. The first backslash escapes the second backslash;
together, they escape the ‘*’.
:regex
:regex
version specifies a match using POSIX Extended Regular
Expressions.
:value
relation:value
match type does a relational comparison between
strings. Valid values for relation are:
:count
relation:comparator "comparator-name"
It instructs sieve to use the given comparator with the test. If comparator-name is not one of ‘i;octet’, ‘i;ascii-casemap’ it must be required prior to using it. For example:
require "comparator-i;ascii-numeric"; if header :comparator "i;ascii-numeric" :is "X-Num" "10" { ...
:all
:localpart
:domain
Notice, that match-type modifiers interact with
comparators. Some comparators are not suitable for matching with
:contains
or :matches
. If this occurs, sieve issues
an appropriate error message. For example, the statement:
if header :matches :comparator "i;ascii-numeric"
would result in the following error message:
comparator `i;ascii-numeric' is incompatible with match type `:matches' in call to `header'
Tagged arguments:
Required arguments:
- address-part
- Selects the address part to compare. Default is the whole email address (
:all
).- comparator
- Specifies the comparator to be used instead of the default
i;ascii-casemap
.- match-type
- Specifies the match type to be used instead of the default
:is
.The
- header-names
- A list of header names.
- key-list
- A list of address values.
address
test matches Internet addresses in structured headers that contain addresses. It returnstrue
if any header contains any key in the specified part of the address, as modified by comparator and match-type optional arguments.This test returns
true
if any combination of the header-names and key-list arguments match.The
address
primitive never acts on the phrase part of an email address, nor on comments within that address. Use theheader
test instead. It also never acts on group names, although it does act on the addresses within the group construct.Example:
if address :is :all "from" "tim@example.com" { discard; }
The
size
test deals with the size of a message. The required argument number represents the size of the message in bytes. It may be suffixed with the following quantifiers:
- ‘k’
- ‘K’
- The number is expressed in kilobytes.
- ‘m’
- ‘M’
- The number is expressed in megabytes.
- ‘g’
- ‘G’
- The number is expressed in gigabytes.
If the tagged argument is ‘:over’, and the size of the message is greater than number, the test is true; otherwise, it is false.
If the argument is ‘:under’, and the size of the message is less than the number, the test is true; otherwise, it is false.
Otherwise, the test is true only if the size of the message equals exactly number. This is a gnu extension.
The size of a message is defined to be the number of octets from the initial header until the last character in the message body.
Tagged arguments:
Required arguments:
- address-part
- Selects the address part to compare. Default is the whole email address (
:all
).- comparator
- Specifies the comparator to be used instead of the default
i;ascii-casemap
.- match-type
- Specifies the match type to be used instead of the default
:is
.The
- envelope-parts
- A list of envelope parts to operate upon.
- key-list
- A list of address values.
envelope
test is true if the specified part of the smtp envelope matches the specified key.If the envelope-part strings is (case insensitive) ‘from’, then matching occurs against the FROM address used in the SMTP MAIL command.
Notice, that due to the limitations imposed by smtp envelope structure the use of any other values in envelope-parts header is meaningless.
Required arguments:
- header-names
- List of message header names.
Theexists
test istrue
if the headers listed in header-names argument exist within the message. All of the headers must exist or the test is false.The following example throws out mail that doesn't have a From header and a Date header:
if not exists ["From","Date"] { discard; }
Tagged arguments:
- comparator
- Specifies the comparator to be used instead of the default
i;ascii-casemap
.- match-type
- Specifies the match type to be used instead of the default
:is
.- :mime
- This tag instructs
header
to search through the mime headers in multipart messages as well.Required arguments:
- header-names
- A list of header names.
- key-list
- A list of header values.
Theheader
test evaluates to true if any header name matches any key. The type of match is specified by the optional match argument, which defaults to ":is" if not explicitly given.The test returns
true
if any combination of the header-names and key-list arguments match.If a header listed in header-names exists, it contains the null key (‘""’). However, if the named header is not present, it does not contain the null key. So if a message contained the header
X-Caffeine: C8H10N4O2these tests on that header evaluate as follows:header :is ["X-Caffeine"] [""] => false header :contains ["X-Caffeine"] [""] => true
This test is provided as an example of loadable extension tests. You must use ‘require "test-numaddr"’ statement before actually using it.
The
numaddr
test counts Internet addresses in structured headers that contain addresses. It returns true if the total number of addresses satisfies the requested relation.If the tagged argument is ‘:over’ and the number of addresses is greater than number, the test is true; otherwise, it is false.
If the tagged argument is ‘:under’ and the number of addresses is less than number, the test is true; otherwise, it is false.
If the tagged argument is not given, ‘:over’ is assumed.