Subject: [PATCH] Dovecot-1.0rc2 MANAGESIEVE
From: Stephan Bosch <[email-masked]>
To: [email-masked]
Date: Thu, 13 Jul 2006 13:51:05 +0200

Hi Timo,

Recently my mail setup has developed the need for a MANAGESIEVE daemon. 
Being a draft standard, not many useful implementations exist apart from
the timsieved daemon. So, I decided to write my own.

I've been using dovecot for quite some time now and out of pure 
curiosity I started to browse the source code. I must say I'm impressed 
by the quality of the framework dovecot is implemented with. Recognizing 
the similarities between IMAP and MANAGESIEVE I decided to implement
MANAGESIEVE by adapting de dovecot IMAP daemon to my purposes. Also, 
since dovecot-lda appeared with sieve support recently, I thought 
dovecot itself might benefit from this extension as well.

I have constructed a patch against dovecot-1.0rc2 (it currently also 
applies more or less cleanly to the HEAD cvs branch, but you will get a 
compile error due to a (typo) namechange in lib/buffer.h. This is easy 
to fix in src/managesieve/commands.c). This patch can be downloaded from:

http://sinas.rename-it.nl/~sirius/dovecot-1.0.rc2-MANAGESIEVE.diff

The overall design of the daemon is entirely borrowed from the existing 
imap daemon. I have tried to apply the dovecot framework and programming 
paradigms as often as possible. So, I don't think you will have too much 
trouble understanding my code.

This patch adds the following directories to the src directory:

lib-managesieve:
	parser and quote functions (derived from src/lib-imap)
lib-sievestorage:
	defines a storage for the sieve scripts (a bit crude)
managesieve-login:
	the initial login daemon (derived from src/imap-login)
managesieve:
	the actual managesieve daemon (derived form src/imap)

Furhermore, it adapts the Makefile.am tree and the configure.in file. 
Also, it adapts the dovecot master so that the managesieve daemon can be 
started from the master process.

Currently the managesieve daemon simply plugs in the dovecot-master as 
any other mail protocol (imap,pop3). Since managesieve is not actually a 
mailprotocol, this is probably not a good design practice. However, i 
designed this patch to be most uninvasive to the existing sources. I 
think you know best how to implement this link properly.

The managesieve daemon is currently not very configurable. It uses the
MAIL environment to determine the directory for the sieve storage. It
maintains a symlink called .dovecot.sieve (the active script) in that 
directory. This link points to a script in the sieve subdirectory. 
Scripts are uploaded into that sub-directory. The sieve directory 
structure is automatically created if it does not exist. To enable the 
managesieve daemon, adding 'managesieve' to 'protocols' in the main 
config file is currently enough. It will run on port 2000;

It currently implements all existing MANAGESIEVE commands except the 
HAVESPACE command which always says 'ok'. It also implements the 
required support for UTF-8 strings. I did not yet connect the deamon 
with the libsieve library, so uploaded scripts are not checked. I have 
tested it with Horde-Ingo, but it will need more testing than that.

This managesieve daemon still needs some work (a small TODO list can be 
found in the src/managesieve/README file), but I hope you like it enough 
to incorporate it in the main dovecot package in the future. I would 
greatly appreciate your feedback.

Regards,

--
Stephan Bosch
[email-masked]