38f2261
Cyrus IMAP autocreate Inbox patch
38f2261
----------------------------------
38f2261
38f2261
NOTE : This patch has been created at the University of Athens. For more info, as well 
38f2261
as more patches on Cyrus IMAPD server, please visit http://email.uoa.gr 
38f2261
38f2261
The design of Cyrus IMAP server does not predict the automatic creation of users'
38f2261
INBOX folders. The creation of a user's INBOX is considered to be an external task,
38f2261
that has to be completed as part of the user e-mail account creation procedure. 
38f2261
Hence, to create a new e-mail account the site administrator has to 
38f2261
a) Include the new account in the user database for the authentication procedure
38f2261
   (e.g. sasldb, shadow, mysql, ldap).
38f2261
b) Create the corresponding INBOX folder. 
38f2261
38f2261
Alternatively, the user, if succesfully authenticated, may create his own INBOX folder,
38f2261
as long as the configuration of the site allows it (see "autocreatequota" in imapd.conf).
38f2261
Unlike what uncareful readers may think, enabling the "autocreatequota" option, doesn't 
38f2261
lead to the automatic INBOX folder creation by Cyrus IMAP server.
38f2261
In fact, "autocreate" means that the IMAP clients are allowed to automatically create 
38f2261
the user INBOX. 
38f2261
38f2261
This patch adds the functionality of automatic creation of the users' INBOX folders into
38f2261
the Cyrus IMAP server. It is implemented as two features, namely the  "create on login"
38f2261
and "create on post".
38f2261
 
38f2261
38f2261
38f2261
Create on login
38f2261
===============
38f2261
This feauture provides automatic creation of a user's INBOX folder when all of the 
38f2261
following requirements are met:
38f2261
38f2261
i)  The user has succesfully passed the authentication procedure.
38f2261
38f2261
ii) The user's authorization ID (typically the same as the user's
38f2261
authentication ID)  doesn't belong to the imap_admins or admins
38f2261
accounts (see imapd.conf).
38f2261
38f2261
iii) The "autocreatequota" option in the imap configuration file 
38f2261
has been set to a non zero value. 
38f2261
38f2261
iv) The corresponding to the user's authorizationID INBOX folder
38f2261
does not exist.
38f2261
38f2261
The user's first login is the most typical case when all four requirements are met. 
38f2261
Note that if the authenticatedID is allowed to proxy to another account for which 
38f2261
all of the above requirements are met, the corresponding INBOX folder for that account 
38f2261
will be created.
38f2261
38f2261
38f2261
38f2261
Create on post
38f2261
==============
38f2261
This feauture provides automatic creation of a user's INBOX folder when all of the 
38f2261
following requirements are met. 
38f2261
38f2261
i) An e-mail message addressed to the user has been received.  
38f2261
38f2261
ii) The recipient is not any of the imap_admins or admins accounts. 
38f2261
Note that passing e-mails to admins or imap_admins accounts from 
38f2261
the MTA to LMTP should be avoided in any case.
38f2261
38f2261
iii) The recipient's INBOX does not exist.
38f2261
38f2261
iv) The "autocreatequota" option in the imap configuration file 
38f2261
has been set to a non zero value. 
38f2261
38f2261
v) The "createonpost" option in the imap configuration file 
38f2261
has been switched on. 
38f2261
38f2261
38f2261
Besides the automatic creation of INBOX folder, additional functionalities are
38f2261
provided:
38f2261
38f2261
A) Automatic creation of INBOX subfolders controlled by "autocreateinboxfolders"
38f2261
configuration option. eg 
38f2261
38f2261
autocreateinboxfolders: sent|drafts|spam|templates
38f2261
38f2261
B) Automatic subscription of INBOX subfolders controlled by "autosubscribeinboxfolders"
38f2261
configuration option. eg
38f2261
38f2261
autosubscribeinboxfolders: sent|spam
38f2261
38f2261
Obviously, only subscription to subfolders included in the "autocreateinboxfolder"
38f2261
list is meaningfull. 
38f2261
38f2261
C) Automatic subscription to shared folders (bulletin boards). The user gets
38f2261
automatically subscribed to the shared folders declared in the "autosubscribesharedfolders"
38f2261
configuration option in imapd.conf.
38f2261
eg autosubscribesharedfolders: public_folder | public_folder.subfolder
38f2261
38f2261
In order the above action to succeed, the shared folder has to pre-exist the INBOX creation
38f2261
and the user must have the apropriate permissions in order to be able to subscribe to the
38f2261
shared folder.
38f2261
38f2261
* A new config option has been added. 'autosubscribe_all_sharedfolders' is a yes/no
38f2261
option. When set to yes, the user is automatically subscribed to all shared folders one 
38f2261
has permission to subscribe to. Please, note that when this option is set to yes, then
38f2261
'autosubscribesharedfolders' option is overriden.
38f2261
38f2261
D) Automatic creation of a predefined default sieve script.
38f2261
38f2261
This is very useful when a default sieve script is used for every user. Usually, a
38f2261
default anti-spam script may me be written in a file and copied to each user
38f2261
sieve scripts upon the INBOX creation. The imapd.conf options that have been added
38f2261
are 'autocreate_sieve_script', 'autocreate_sieve_compiledscript' and 
38f2261
'generate_compiled_sieve_script'. 
38f2261
38f2261
autocreate_sieve_script configuration option refers to the full path of the file 
38f2261
that contains the sieve script. The default value is null and if no file is defined,
38f2261
then no default script is created upon INBOX creation. (The feature is disabled)
38f2261
eg autocreate_sieve_script: /etc/default_sieve_script
38f2261
38f2261
autocreate_sieve_compiledscript configuration option refers to the full path of the
38f2261
file that contains the bytecode compiled sieve script. If this filename is defined
38f2261
in imapd.conf and the file exists, then it is automatically copied in the user's sieve
38f2261
directory. If it is not defined, then a bytecode sieve script gets on the fly compiled
38f2261
by the daemon. 
38f2261
eg autocreate_sieve_compiledscript: /etc/default_sieve_script.bc
38f2261
38f2261
generate_compiled_sieve_script is a boolean option that triggers the compilation of the 
38f2261
source sieve script to bytecode sieve script. The file that the bytecode script will
38f2261
be saved is pointed by autocreate_sieve_compiledscript.
38f2261
38f2261
Ways of compiling a sieve script : 
38f2261
1. Compile a sieve script using the standard sievec utility, distributed by CMU
38f2261
2. Compile a sieve script using the compile_sieve utility, released by UoA. This 
38f2261
   tool is almost identical to the sievec utility, with the difference that it 
38f2261
   reads the input and output file from autocreate_sieve_script and 
38f2261
   autocreate_sieve_compiledscript options in imapd.conf
38f2261
3. Let cyrus create a compiled sieve script using a source script. Cyrus can be
38f2261
   instructed to save the compiled script any time a compiled script does not exist.
38f2261
38f2261
NOTES : 
38f2261
1. In order this functionality to work, the following requirements must have been met:
38f2261
   - 'sieveusehomedir' option must be 'no' in the configuration (default).
38f2261
   - 'sievedir' option must have a valid value.
38f2261
2. Currently, this patch checks the validity of the source script while generating a 
38f2261
   bytecode compiled script, but not the validity of the bytecode sieve script file.
38f2261
   The administrator should make sure that the provided files contain a valid sieve
38f2261
   script as well as the compiled script is updated every time the source script changes.
38f2261
38f2261
38f2261
38f2261
Issues to be considered 
38f2261
=======================
38f2261
38f2261
I) In order to use the create on post feauture one should be absolutely sure that: 
38f2261
a) The MTA checks the validity of the e-mail recipient before sending the e-mail to
38f2261
LMTP. This is an RFC821 requirement. This usually expands to "the mta should be 
38f2261
able to use the account database as user mailbox database". 
38f2261
b) Only authorized accounts/services can talk to LMTP.
38f2261
38f2261
II) Especially in the case of imap logins, the current patch implementation checks
38f2261
for the INBOX folder existence upon login, causing an extra mailbox lookup in most 
38f2261
of the cases. 
38f2261
A better approach would be to chase the "IMAP_MAILBOX_NONEXISTENT" error code and
38f2261
check if the error is associated with an INBOX folder. However, this would mess up
38f2261
Cyrus code. The way it was implemented may not have been the most performance
38f2261
optimized, but it produces a much cleaner and simple patch.
38f2261
38f2261
38f2261
38f2261
Virtual Domains Support
38f2261
=======================
38f2261
38f2261
Virtual domains are supported by all versions of the patch for cyrus-imapd-2.2.1-BETA and 
38f2261
later. However, it is not possible to declare different INBOX subfolders to be created or 
38f2261
shared folders to be subscribed to for every domain.
38f2261
38f2261
38f2261
38f2261
Things to be done
38f2261
=================
38f2261
38f2261
1. Support MURDER architecture. 
38f2261
38f2261
38f2261
For more information and updates please visit http://email.uoa.gr/autocreate
38f2261