Cyrus IMAP autocreate Inbox patch
----------------------------------

NOTE : This patch has been created at the University of Athens. For more info, as well 
as more patches on Cyrus IMAPD server, please visit http://email.uoa.gr 

The design of Cyrus IMAP server does not predict the automatic creation of users'
INBOX folders. The creation of a user's INBOX is considered to be an external task,
that has to be completed as part of the user e-mail account creation procedure. 
Hence, to create a new e-mail account the site administrator has to 
a) Include the new account in the user database for the authentication procedure
   (e.g. sasldb, shadow, mysql, ldap).
b) Create the corresponding INBOX folder. 

Alternatively, the user, if succesfully authenticated, may create his own INBOX folder,
as long as the configuration of the site allows it (see "autocreatequota" in imapd.conf).
Unlike what uncareful readers may think, enabling the "autocreatequota" option, doesn't 
lead to the automatic INBOX folder creation by Cyrus IMAP server.
In fact, "autocreate" means that the IMAP clients are allowed to automatically create 
the user INBOX. 

This patch adds the functionality of automatic creation of the users' INBOX folders into
the Cyrus IMAP server. It is implemented as two features, namely the  "create on login"
and "create on post".
 


Create on login
===============
This feauture provides automatic creation of a user's INBOX folder when all of the 
following requirements are met:

i)  The user has succesfully passed the authentication procedure.

ii) The user's authorization ID (typically the same as the user's
authentication ID)  doesn't belong to the imap_admins or admins
accounts (see imapd.conf).

iii) The "autocreatequota" option in the imap configuration file 
has been set to a non zero value. 

iv) The corresponding to the user's authorizationID INBOX folder
does not exist.

The user's first login is the most typical case when all four requirements are met. 
Note that if the authenticatedID is allowed to proxy to another account for which 
all of the above requirements are met, the corresponding INBOX folder for that account 
will be created.



Create on post
==============
This feauture provides automatic creation of a user's INBOX folder when all of the 
following requirements are met. 

i) An e-mail message addressed to the user has been received.  

ii) The recipient is not any of the imap_admins or admins accounts. 
Note that passing e-mails to admins or imap_admins accounts from 
the MTA to LMTP should be avoided in any case.

iii) The recipient's INBOX does not exist.

iv) The "autocreatequota" option in the imap configuration file 
has been set to a non zero value. 

v) The "createonpost" option in the imap configuration file 
has been switched on. 


Besides the automatic creation of INBOX folder, additional functionalities are
provided:

A) Automatic creation of INBOX subfolders controlled by "autocreateinboxfolders"
configuration option. e.g 

autocreateinboxfolders: sent|drafts|spam|templates

B) Automatic subscription of INBOX subfolders controlled by "autosubscribeinboxfolders"
configuration option. e.g

autosubscribeinboxfolders: sent|spam

Obviously, only subscription to subfolders included in the "autocreateinboxfolder"
list is meaningfull. 

C) Automatic subscription to shared folders (bulletin boards). The user gets
automatically subscribed to the shared folders declared in the "autosubscribesharedfolders"
configuration option in imapd.conf.
e.g autosubscribesharedfolders: public_folder | public_folder.subfolder

In order the above action to succeed, the shared folder has to pre-exist the INBOX creation
and the user must have the apropriate permissions in order to be able to subscribe to the
shared folder.



Issues to be considered 
=======================

I) In order to use the create on post feauture one should be absolutely sure that: 
a) The MTA checks the validity of the e-mail recipient before sending the e-mail to
LMTP. This is an RFC821 requirement. This usually expands to "the mta should be 
able to use the account database as user mailbox database". 
b) Only authorized accounts/services can talk to LMTP.

II) Especially in the case of imap logins, the current patch implementation checks
for the INBOX folder existence upon login, causing an extra mailbox lookup in most 
of the cases. 
A better approach would be to chase the "IMAP_MAILBOX_NONEXISTENT" error code and
check if the error is associated with an INBOX folder. However, this would mess up
Cyrus code. The way it was implemented may not have been the most performance
optimized, but it produces a much cleaner and simple patch.



Virtual Domains Support
=======================

Virtual domains are supported by all versions of the patch for cyrus-imapd-2.2.1-BETA and 
later. However, it is not possible to declare different INBOX subfolders to be created or 
shared folders to be subscribed to for every domain.



Things to be done
=================

1. Support MURDER architecture. 


For more information and updates please visit http://email.uoa.gr/autocreate

