dovecot-2.1-pigeonhole: Added support for retrieving Sieve scrip...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Sun Apr 22 12:30:37 EEST 2012
details: http://hg.rename-it.nl/dovecot-2.1-pigeonhole/rev/f7ea71241032
changeset: 1611:f7ea71241032
user: Stephan Bosch <stephan at rename-it.nl>
date: Sun Apr 22 11:30:28 2012 +0200
description:
Added support for retrieving Sieve scripts from dict lookup.
- Built generic interface for alternative script sources.
- Implemented dict script location.
NOTE: ManageSieve will not work with this yet, nor will sieve_before/sieve_after.
diffstat:
INSTALL | 75 +-
TODO | 16 +-
doc/script-location-dict.txt | 88 +
src/lib-sieve-tool/sieve-tool.c | 15 +-
src/lib-sieve/Makefile.am | 3 +
src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c | 6 +-
src/lib-sieve/plugins/environment/ext-environment-common.c | 12 +-
src/lib-sieve/plugins/environment/sieve-ext-environment.h | 3 +-
src/lib-sieve/plugins/include/cmd-include.c | 19 +-
src/lib-sieve/plugins/include/ext-include-binary.c | 53 +-
src/lib-sieve/plugins/include/ext-include-common.c | 22 +-
src/lib-sieve/plugins/include/ext-include-common.h | 2 +-
src/lib-sieve/plugins/notify/cmd-notify.c | 2 +-
src/lib-sieve/plugins/vacation/cmd-vacation.c | 2 +-
src/lib-sieve/sieve-actions.c | 15 +-
src/lib-sieve/sieve-binary-file.c | 29 +-
src/lib-sieve/sieve-binary.c | 51 +-
src/lib-sieve/sieve-binary.h | 18 +-
src/lib-sieve/sieve-common.h | 13 +-
src/lib-sieve/sieve-message.c | 5 +-
src/lib-sieve/sieve-message.h | 3 +-
src/lib-sieve/sieve-script-dict.c | 283 +++++
src/lib-sieve/sieve-script-file.c | 397 +++++++
src/lib-sieve/sieve-script-file.h | 31 +
src/lib-sieve/sieve-script-private.h | 89 +-
src/lib-sieve/sieve-script.c | 629 +++++++-----
src/lib-sieve/sieve-script.h | 59 +-
src/lib-sieve/sieve-settings.h | 15 +-
src/lib-sieve/sieve-types.h | 37 +-
src/lib-sieve/sieve.c | 91 +-
src/lib-sieve/sieve.h | 37 +-
src/lib-sievestorage/sieve-storage-list.c | 5 +
src/lib-sievestorage/sieve-storage-quota.c | 5 +
src/lib-sievestorage/sieve-storage-save.c | 1 +
src/lib-sievestorage/sieve-storage-script.c | 40 +-
src/lib-sievestorage/sieve-storage.c | 35 +
src/managesieve/cmd-getscript.c | 23 +-
src/managesieve/managesieve-capabilities.c | 16 +-
src/managesieve/managesieve-client.c | 37 +-
src/plugins/lda-sieve/lda-sieve-plugin.c | 673 ++++++------
src/sieve-tools/sieve-filter.c | 7 +-
src/sieve-tools/sieve-test.c | 23 +-
src/sieve-tools/sievec.c | 5 +-
src/testsuite/testsuite-binary.c | 11 +-
src/testsuite/testsuite-script.c | 9 +-
src/testsuite/testsuite-smtp.c | 4 +-
src/testsuite/testsuite-smtp.h | 6 +-
src/testsuite/testsuite.c | 2 -
tests/extensions/environment/basic.svtest | 2 +-
49 files changed, 2086 insertions(+), 938 deletions(-)
diffs (truncated from 4714 to 300 lines):
diff -r a88c63b2d0b0 -r f7ea71241032 INSTALL
--- a/INSTALL Mon Mar 26 21:07:14 2012 +0200
+++ b/INSTALL Sun Apr 22 11:30:28 2012 +0200
@@ -85,23 +85,21 @@
plugin section of the config file (default values are shown if applicable):
sieve = ~/.dovecot.sieve
- The path to the user's main active script.
+ The location of the user's main active script.
sieve_default =
- The path to the default personal sieve script file, which gets executed ONLY
- if user's private Sieve script does no exist, e.g.
- /var/lib/dovecot/default.sieve. This is usually a global script, so sure to
- pre-compile this script manually using the sievec command line tool, as
- explained in the README file.
-
- sieve_global_path =
- This is the DEPRECATED former name of the sieve_default setting.
+ The location of the default personal sieve script file, which gets executed
+ ONLY if user's private Sieve script does no exist, e.g.
+ /var/lib/dovecot/default.sieve. This is usually a global script, so be sure
+ to pre-compile this script manually using the sievec command line tool, as
+ explained in the README file. This setting used to be called
+ `sieve_global_path', but that name is now deprecated.
sieve_global_dir =
- Directory for :global include scripts for the Sieve include extension.
+ Location for :global include scripts for the Sieve include extension.
- sieve_dir = ~/
- Directory for :personal include scripts for the Sieve include extension.
+ sieve_dir = ~/sieve
+ Location for :personal include scripts for the Sieve include extension.
sieve_extensions =
Which Sieve language extensions are available to users. By default, all
@@ -131,6 +129,12 @@
(wiki2.dovecot.org) or the pigeonhole website (http://pigeonhole.dovecot.org)
for available plugins.
+ sieve_user_log =
+ The path to the file where the user log file is written. If not configured, a
+ default location is used. If the main user's personal Sieve (as configured
+ with sieve=) is a file, the logfile is set to <filename>.log by default. If
+ it is not a file, the default user log file is ~/.dovecot.sieve.log.
+
recipient_delimiter = +
The separator that is expected between the :user and :detail address parts
introduced by the subaddress extension. This may also be a sequence of
@@ -176,7 +180,48 @@
The maximum number of redirect actions that can be performed during a single
script execution. If set to 0, no redirect actions are allowed.
-Sieve Interpreter - Per-user Sieve script location
+Sieve Interpreter - Script Locations
+------------------------------------
+
+The location of Sieve scripts is not limited to the file system. The Sieve
+interpreter can be extended to retrieve Sieve scripts from other sources as
+well, such as a database. Currently, all settings that are used to obtain the
+location of a single Sieve script, such as sieve=, sieve_default=, sieve_dir=
+and sieve_global_dir= accept the following extended syntax:
+
+location = [<type>:]path[;<option>[=<value>][;...]]
+
+The following script location types are implemented by default:
+
+ file - The location path is a file system path pointing to the script file
+ or a directory containing script files with names structured as
+ `<script-name>.sieve'.
+ dict - Dovecot dict lookup. The location path is a dict uri. Read
+ doc/scipt-location-dict.txt for more information and examples.
+
+If the type prefix is omitted, the script location type is 'file'.
+
+The following options are defined for all location types:
+
+ name=<script-name>
+ Set the name of the Sieve script that this location points to. If the name
+ of the Sieve script is not contained in the location path, this option is
+ required (e.g. for dict locations that must point to a particular script).
+ If the name of the script is contained in the location, the value of the
+ name option overrides the name retrieved from the location. If the Sieve
+ interpreter explicitly queries for a specific name (e.g. to include a script
+ from the sieve_dir= location), this option has no effect.
+
+ bindir=<dirpath>
+ Points to the directory where the compiled binaries for this script location
+ are stored. If this option is omitted, the behavior depends on the location
+ type. For `file' type locations, the binary is then stored in the same
+ directory as where the script file was found if possible. For `dict' type
+ locations, the binary is not stored at all in that case. Don't specify the
+ same directory for different script locations, as this will result in
+ undefined behavior.
+
+Sieve Interpreter - Per-user Sieve Script Location
--------------------------------------------------
By default, the Pigeonhole LDA Sieve plugin looks for the user's Sieve script
@@ -184,8 +229,8 @@
home directory is set for the user.
If you want to store the script elsewhere, you can override the default using
-the sieve setting, which specifies the path to the user's script file. This can
-be done in two ways:
+the sieve= setting, which specifies the location of the user's script file. This
+can be done in two ways:
1. Define the sieve setting in the plugin section of dovecot.conf.
2. Return sieve extra field from userdb extra fields.
diff -r a88c63b2d0b0 -r f7ea71241032 TODO
--- a/TODO Mon Mar 26 21:07:14 2012 +0200
+++ b/TODO Sun Apr 22 11:30:28 2012 +0200
@@ -1,7 +1,9 @@
Current activities:
-* Update include extension to latest draft (v13 currently):
- - Implement :optional tag.
+* Implement generic Sieve script object that abstracts from its location and
+ add support for retrieving scripts from dict database.
+ - Implement infrastructure for loading a sequence of global scripts from
+ a database (for sieve_before/sieve_after).
Parallel plugin-based efforts:
@@ -14,6 +16,13 @@
Next (mostly in order of descending priority/precedence):
+* Make the sieve storage a base class with (possibly) various implementations,
+ just like mail-storage. This aims to provide support for alternate types
+ of script storage like LDAP or SQL database.
+ - Implement read/write script storages for using ManageSieve with dict
+ database
+* Update include extension to latest draft (v13 currently):
+ - Implement :optional tag.
* Implement index extension
* Add normalize() method to comparators to normalize the string before matching
(for efficiency).
@@ -70,9 +79,6 @@
* Implement extlists extension as a plugin
* Enotify extension: detect use of variable values extracted from the message
that are used in the method argument. RFC reports this as a security issue.
-* Make the sieve storage a base class with (possibly) various implementations,
- just like mail-storage. This aims to provide support for alternate types
- of script storage like LDAP or SQL database.
* Add support for stream matching for handling large values, e.g. from the body
extension.
* Implement message modification and extraction API in order to:
diff -r a88c63b2d0b0 -r f7ea71241032 doc/script-location-dict.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/script-location-dict.txt Sun Apr 22 11:30:28 2012 +0200
@@ -0,0 +1,88 @@
+DICT Sieve Script Location Type
+
+Description
+===========
+
+This location type is used to retrieve Sieve scripts from a Dovecot dict lookup.
+Such dictionaries use a file or an SQL database as backend. Refer to the Dovecot
+dict documentation for more information on dict lookups.
+
+To retrieve a Sieve script from the dict database, two lookups are performed.
+First, the name of the Sieve script is queried from the dict path
+`/priv/sieve/name/<name>'. If the Sieve script exists, this yields a data ID
+which in turn points to the actual script text. The script text is subsequently
+queried from the dict path '/priv/sieve/data/<dict-id>'.
+
+The second query is only necessary when no compiled binary is available or when
+the script has changed and needs to be recompiled. The data ID is used to detect
+changes in the dict's underlying database. Changing a Sieve script in the
+database must be done by first making a new script data item with a new data ID.
+Then, the mapping from name to data ID must be changed to point to the new
+script text, thereby changing the data ID returned from the name lookup, i.e.
+the first query mentioned above. Script binaries compiled from Sieve scripts
+contained in a dict database record the data ID. While the data ID contained in
+the binary is identical to the one returned from the dict lookup, the binary is
+assumed up-to-date. When the returned data ID is different, the new script text
+is retrieved using the second query and compiled into a new binary containing
+the updated data ID.
+
+Note that, by default, compiled binaries are not stored at all for Sieve scripts
+retrieved from a dict database. The bindir= option needs to be specified in the
+location specification. Refer to the INSTALL file for more general information
+about configuration of script locations.
+
+Configuration
+=============
+
+The script location syntax is specialized as follows:
+
+location = dict:<dict-uri>[;<option>[=<value>][;...]]
+
+The following additional options are recognized:
+
+ user=<username>
+ Overrides the user name used for the dict lookup. Normally, the name of the
+ user running the Sieve interpreter is used.
+
+If the name of the Script is left unspecified and not otherwise provided by the
+Sieve interpreter, the name defaults to `default'.
+
+Examples
+========
+
+Example 1
+---------
+
+This example is mainly useful for performing a quick test of the dict location
+configuration without configuring an actual (SQL) database. For this example, a
+very simple file dict is assumed to be contained in the file
+/etc/dovecot/sieve.dict:
+
+priv/sieve/name/keep
+1
+priv/sieve/name/discard
+2
+priv/sieve/name/spam
+3
+priv/sieve/data/1
+keep;
+priv/sieve/data/2
+discard;
+priv/sieve/data/3
+require ["fileinto", "mailbox"]; fileinto :create "spam";
+
+To use this file dict for the main active script, you can change the
+configuration as follows (e.g. in /etc/dovecot/conf.d/90-sieve.conf):
+
+plugin {
+ sieve = dict:file:/etc/dovecot/sieve.dict;name=keep;bindir=~/.sieve-bin
+}
+
+Binaries are stored in the ~/.sieve-bin directory.
+
+Example 2
+---------
+
+This example uses a sqlite database.
+
+FIXME:
diff -r a88c63b2d0b0 -r f7ea71241032 src/lib-sieve-tool/sieve-tool.c
--- a/src/lib-sieve-tool/sieve-tool.c Mon Mar 26 21:07:14 2012 +0200
+++ b/src/lib-sieve-tool/sieve-tool.c Sun Apr 22 11:30:28 2012 +0200
@@ -89,7 +89,7 @@
return sieve_tool_get_homedir(tool);
}
-const struct sieve_environment sieve_tool_sieve_env = {
+const struct sieve_callbacks sieve_tool_callbacks = {
sieve_tool_sieve_get_homedir,
sieve_tool_sieve_get_setting
};
@@ -223,6 +223,7 @@
MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT |
MAIL_STORAGE_SERVICE_FLAG_USE_SYSEXITS;
struct mail_storage_service_input service_input;
+ struct sieve_environment svenv;
const char *username = tool->username;
const char *homedir = tool->homedir;
const char *errstr;
@@ -261,9 +262,15 @@
(master_service, "mail_full_filesystem_access=yes") < 0 )
i_unreached();
+ memset((void *)&svenv, 0, sizeof(svenv));
+ svenv.username = username;
+ (void)mail_user_get_home(tool->mail_user_dovecot, &svenv.home_dir);
+ svenv.hostname = "host.example.com";
+ svenv.base_dir = tool->mail_user_dovecot->set->base_dir;
+
/* Initialize Sieve Engine */
- if ( (tool->svinst=sieve_init(&sieve_tool_sieve_env, tool, tool->debug))
- == NULL )
+ if ( (tool->svinst=sieve_init
+ (&svenv, &sieve_tool_callbacks, tool, tool->debug)) == NULL )
i_fatal("failed to initialize sieve implementation");
/* Load Sieve plugins */
@@ -545,7 +552,7 @@
sieve_error_handler_unref(&ehandler);
- sieve_save(sbin, NULL, FALSE, NULL);
+ sieve_save(sbin, FALSE, NULL);
return sbin;
}
diff -r a88c63b2d0b0 -r f7ea71241032 src/lib-sieve/Makefile.am
--- a/src/lib-sieve/Makefile.am Mon Mar 26 21:07:14 2012 +0200
+++ b/src/lib-sieve/Makefile.am Sun Apr 22 11:30:28 2012 +0200
@@ -80,6 +80,8 @@
sieve-smtp.c \
sieve-lexer.c \
sieve-script.c \
+ sieve-script-file.c \
+ sieve-script-dict.c \
sieve-ast.c \
sieve-binary.c \
More information about the dovecot-cvs
mailing list