What is jSieve?

jSieve is a Java implementation of the Sieve mail filtering language defined by RFC 3028. jSieve is implemented as a language processor that can be plugged into any internet mail application to add Sieve support.

jSieve is a subproject of Apache JAMES. All who are interested in developing jSieve and JAMES will be warmly welcomed on the mailing lists.

What is Sieve?

Sieve is an extensible mail filtering language. It's limited expressiveness (no loops or variables, no tests with side effects) allows user created scripts to be run safely on email servers. Sieve is targeted at the final delivery phase (where an incoming email is transfered to a user's mailbox).

Sieve scripts are composed of commands. Control commands manage the execution of the script. Test commands define side-effect free criteria. Action commands are mail operations to be performed.

Sieve Features Supported By jSieve

jSieve is limited only by the platform on which it runs.

Limits
Maximum Number Of ActionsNo intrinsic limit
Maximum Number Of Nested BlocksNo intrinsic limit
Maximum Number Of Nested Test ListsNo intrinsic limit

jSieve supports the standard control commands specified in RFC 3028.

Control CommandSpecificationSupported
IfRFC 3028 (REQUIRED)yes
RequireRFC 3028 (REQUIRED)yes
StopRFC 3028 (REQUIRED)yes

jSieve supports all action commands (both required and optional) specified in RFC 3028.

Note that jSieve uses a pluggable MailAdapter as an interface to the mail server. Not all implementations may fully support all actions.

Action CommandSpecificationSupported
rejectRFC 3028 (OPTIONAL)yes
fileintoRFC 3028 (OPTIONAL)yes
redirectRFC 3028 (REQUIRED)yes
keepRFC 3028 (REQUIRED)yes
discardRFC 3028 (REQUIRED)yes

jSieve supports all tests commands specified in RFC 3028.

Test CommandSpecificationSupported
addressRFC 3028 (REQUIRED)yes
allofRFC 3028 (REQUIRED)yes
anyofRFC 3028 (REQUIRED)yes
envelopeRFC 3028 (OPTIONAL)yes
existsRFC 3028 (REQUIRED)yes
falseRFC 3028 (REQUIRED)yes
headerRFC 3028 (REQUIRED)yes
notRFC 3028 (REQUIRED)yes
sizeRFC 3028 (REQUIRED)yes
trueRFC 3028 (REQUIRED)yes
bodySIEVE body extensionpartial

jSieve Extension Commands

jSieve allows extension commands to be developed and plugged in at run time. The following extension commands ship with jSieve:

NameFunction
LogLogs messages

Getting Started

Until these pages are fleshed out, the best way to understand jSieve is read the Javadocs and look at the source code. The jUnit tests illustrate many aspects of the implementation.

Using jSieve

Standalone

org.apache.jsieve.SieveFactory is the primary invocation point for all Sieve operations. The API is clean and simple. See the javadocs for more details.

In JAMES

The SieveToMultiMailbox mailet is included in JAMES. It is integrated with the message delivery spool and provides per-user Sieve scripting using jSieve.

Implementing A Mail Adapter

org.apache.jsieve.mail.MailAdapter is the interface API used by jSieve to interact with a mail server.

The mail adapter wraps an email and supplies information (required by the script) about the email. It is responsible for accumulating Actions during the parsing of a script and for executing them once the parsing is complete.

See the javadocs for more details and this sample.

Creating A Custom Extension Command

org.apache.jsieve.commands.extensions.Log is an example of a custom extension command. It is recommended that custom commands extend AbstractCommand. See the javadocs for more details.

Custom commands need to be registered with ConfigurationManager before they can be used. This may be done programmatically but the recommended method is by altering the sieveConfig.xml configuration file.

Building jSieve

jSieve uses Ant. ant -projecthelp describes appropriate targets. ant runs the default target.

Comments, Questions and Issues

jSieve is a sub-project of Apache James. Please direct your comments and questions to the relevant James list.

To report issues, such as bugs, go to the jSieve Issue Tracker. As jSieve comes with a fairly extensive suite of jUnit Tests, it would be most helpful for bug reports to be accompanied by an illustrative jUnit test case.

Frequently Asked Question

Why Do Tests Using Non-ASCII Characters Fail?

SIEVE specifies that UTF-8 encoding is used for scripts. This format is an international standard and has wide support but not all platforms use this encoding by default.

By default, JSieve expects that scripts are encoding using UTF-8. Either set the encoding programmatically or ensure that the script is encoded using UTF-8.