This file documents the Emacs Sieve package.

Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.

     Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover texts being ``A GNU Manual'', and with the Back-Cover Texts as in (a) below.  A copy of the license is included in the section entitled ``GNU Free Documentation License'' in the Emacs manual.

     (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify this GNU Manual, like GNU software.  Copies published by the Free Software Foundation raise funds for GNU development.''

     This document is part of a collection distributed under the GNU Free Documentation License.  If you want to distribute this document separately from the collection, you can do so by adding a copy of the license to the document, as described in section 6 of the license.

Sieve Support for Emacs
***********************

This manual documents the Emacs Sieve package.

It is intended as a users manual for Sieve Mode and Manage Sieve, and as a reference manual for the sieve-manage protocol Emacs Lisp API.

Sieve is a language for server-side filtering of mail.  The language is documented in RFC 3028.  This manual does not attempt to document the language, so keep RFC 3028 around.

A good online Sieve resources is http://www.cyrusoft.com/sieve/.

Installation
************

The Sieve package should come with your Emacs version, and should be ready for use directly.

However, to manually set up the package you can put the following commands in your ~/.emacs:

     (autoload 'sieve-mode "sieve-mode")

     (setq auto-mode-alist (cons '("\\.s\\(v\\|iv\\|ieve\\)\\'" . sieve-mode)
                                 auto-mode-alist))

Sieve Mode
**********

Sieve mode provides syntax-based indentation, font-locking support and other handy functions to make editing Sieve scripts easier.

Use M-x sieve-mode to switch to this major mode.  This command runs the hook sieve-mode-hook.

Sieve mode is derived from c-mode, and is very similar except for the syntax of comments.  The keymap (sieve-mode-map) is inherited from c-mode, as are the variables for customizing indentation.  Sieve mode has its own abbrev table (sieve-mode-abbrev-table) and syntax table (sieve-mode-syntax-table).

In addition to the editing utility functions, Sieve mode also contains bindings to manage Sieve scripts remotely. See Managing Sieve.

C-c RET
     Open a connection to a remote server using the Managesieve protocol.

C-c C-l
     Upload the Sieve script to the currently open server.

Managing Sieve
**************

Manage Sieve is a special mode used to display Sieve scripts available on a remote server.  It can be invoked with M-x sieve-manage RET, which queries the user for a server and if necessary, user credentials to use.

When a server has been successfully contacted, the Manage Sieve buffer looks something like:

     Server  : mailserver:2000

     2 scripts on server, press RET on a script name edits it, or
     press RET on <new script> to create a new script.
             <new script>
      ACTIVE .sieve
             template.siv

One of the scripts are highlighted, and standard point navigation commands (<up>, <down> etc) can be used to navigate the list.

The following commands are available in the Manage Sieve buffer:

m
     Activates the currently highlighted script.

u
     Deactivates the currently highlighted script.

C-M-?
     Deactivates all scripts.

r
     Remove currently highlighted script.

RET

mouse-2

f
     Bury the server buffer and download the currently highlighted script into a new buffer for editing in Sieve mode (see Sieve Mode).

o
     Create a new buffer in another window containing the currently highlighted script for editing in Sieve mode (see Sieve Mode).

q
     Bury the Manage Sieve buffer without closing the connection.

?

h
     Displays help in the minibuffer.

Examples
********

If you are not familiar with Sieve, this chapter contains a few simple code snippets that you can cut'n'paste and modify at will, until you feel more comfortable with the Sieve language to write the rules from scratch.

The following complete Sieve script places all messages with a matching Sender: header into the given mailbox.  Many mailing lists uses this format.  The first line makes sure your Sieve server understands the fileinto command.

     require "fileinto";

     if address "sender" "owner-w3-beta@xemacs.org" {
     	fileinto "INBOX.w3-beta";
     }

A few mailing lists do not use the Sender: header, but does contain some unique identifier in some other header.  The following is not a complete script, it assumes that fileinto has already been required.

     if header :contains "Delivered-To" "auc-tex@sunsite.dk" {
     	fileinto "INBOX.auc-tex";
     }

At last, we have the hopeless mailing lists that does not have any unique identifier and you are forced to match on the To: and Cc headers.  As before, this snippet assumes that fileinto has been required.

     if address ["to", "cc"] "kerberos@mit.edu" {
     	fileinto "INBOX.kerberos";
     }

Manage Sieve API
****************

The sieve-manage.el library contains low-level functionality for talking to a server with the MANAGESIEVE protocol.

A number of user-visible variables exist, which all can be customized in the sieve group (M-x customize-group RET sieve RET):

sieve-manage-default-user
     Sets the default username.

sieve-manage-default-port
     Sets the default port to use, the suggested port number is 2000.

sieve-manage-log
     If non-nil, should be a string naming a buffer where a protocol trace is dumped (for debugging purposes).

The API functions include:

sieve-manage-open
     Open connection to managesieve server, returning a buffer to be used by all other API functions.

sieve-manage-opened
     Check if a server is open or not.

sieve-manage-close
     Close a server connection.

sieve-manage-authenticate
     Authenticate to the server.

sieve-manage-capability
     Return a list of capabilities the server support.

sieve-manage-listscripts
     List scripts on the server.

sieve-manage-havespace
     Returns non-nil iff server have roam for a script of given size.

sieve-manage-getscript
     Download script from server.

sieve-manage-putscript
     Upload script to server.

sieve-manage-setactive
     Indicate which script on the server should be active.

Standards
*********

The Emacs Sieve package implements all or parts of a small but hopefully growing number of RFCs and drafts documents.  This chapter lists the relevant ones.  They can all be fetched from http://quimby.gnus.org/notes/.

RFC3028
     Sieve: A Mail Filtering Language.

draft-martin-managesieve-03
     A Protocol for Remotely Managing Sieve Scripts