1 diff -Naur cyrus-imapd-2.2.12/README.autosievefolder cyrus-imapd-2.2.12-autosieve.uncompiled/README.autosievefolder
2 --- cyrus-imapd-2.2.12/README.autosievefolder 1970-01-01 02:00:00 +0200
3 +++ cyrus-imapd-2.2.12-autosieve.uncompiled/README.autosievefolder 2005-02-15 13:59:51 +0200
5 +Cyrus IMAP autosievefolder patch
6 +----------------------------------
8 +NOTE : This patch has been created at the University of Athens. For more info, as well
9 +as more patches on Cyrus IMAPD server, please visit http://email.uoa.gr
12 + When the lmtpd daemon receives an email message prior to delivering it to the
13 +INBOX folder of the user, checks if the user has specified sieve filters. If the
14 +user has specified sieve filters the filters are evaluated. If the message matches
15 +any of the filters the action that is specified in the filter is executed. If the action
16 +is FileInto it is stored in the subfolder specified in the filter. If the
17 +subfolder doesn't exist then the message is sent to the INBOX folder of the user.
19 + With this patch if the folder doesn't exist AND the name of the subfolder is
20 +specified in the autosievefolders option, OR the anysievefolder is set to
21 +yes in the cyrus-imap configuration file then the subfolder is created and the mail
25 +Check the following options of the imapd.conf file
26 +==================================================
28 +* anysievefolder : It must be "yes" in order to permit the autocreation of any
29 +INBOX subfolder requested by a sieve filter, through the "fileinto" action. (default = no)
30 +* autosievefolders : It is a "|" separated list of subfolders of INBOX that will be
31 +automatically created, if requested by a sieve filter, through the "fileinto"
32 +action. (default = null)
33 + i.e. autosievefolders: Junk | Spam
35 +WARNING: anysievefolder, takes precedence over autosievefolders . Which means that if
36 +anysievefolder is set to "yes", cyrus will create any INBOX subfolder requested, no-matter what the value of autosievefolders is.
42 +1. Support cyrus wildcards in the autosievefolders option.
45 +For more information and updates please visit http://email.uoa.gr/projects/cyrus/autosievefolder
47 diff -Naur cyrus-imapd-2.2.12/imap/lmtp_sieve.c cyrus-imapd-2.2.12-autosieve.uncompiled/imap/lmtp_sieve.c
48 --- cyrus-imapd-2.2.12/imap/lmtp_sieve.c 2004-06-01 16:47:16 +0300
49 +++ cyrus-imapd-2.2.12-autosieve.uncompiled/imap/lmtp_sieve.c 2005-02-15 13:59:51 +0200
54 +#include "imap_err.h"
57 static int sieve_usehomedir = 0;
58 static const char *sieve_dir = NULL;
63 +static int autosieve_subfolder(char *userid, struct auth_state *auth_state,
64 + char *subfolder, struct namespace *namespace);
66 static char *make_sieve_db(const char *user)
68 static char buf[MAX_MAILBOX_PATH+1];
74 static int sieve_redirect(void *ac,
75 void *ic __attribute__((unused)),
76 void *sc, void *mc, const char **errmsg)
78 sd->username, mdata->notifyheader,
79 namebuf, quotaoverride, 0);
82 + if (ret == IMAP_MAILBOX_NONEXISTENT) {
83 + /* if "plus" folder under INBOX, then try to create it */
84 + syslog(LOG_DEBUG, "calling autosieve folder for : %s", namebuf);
85 + ret = autosieve_subfolder((char *) sd->username, sd->authstate, namebuf, mdata->namespace);
88 + ret = deliver_mailbox(md->data, mdata->stage, md->size,
89 + fc->imapflags->flag, fc->imapflags->nflags,
90 + (char *) sd->username, sd->authstate, md->id,
91 + sd->username, mdata->notifyheader,
92 + namebuf, quotaoverride, 0);
95 snmp_increment(SIEVE_FILEINTO, 1);
105 +static int autosieve_subfolder(char *userid, struct auth_state *auth_state,
106 + char *subfolder, struct namespace *namespace)
108 + char option_name_external[MAX_MAILBOX_NAME + 1];
109 + char option_name_internal[MAX_MAILBOX_NAME + 1];
111 + char *p, *q, *next_subf;
113 + int createsievefolder = 0;
115 + /* Check if subfolder or userid are NULL */
116 + if(subfolder == NULL || userid == NULL)
117 + return IMAP_MAILBOX_NONEXISTENT;
119 + if (config_getswitch(IMAPOPT_ANYSIEVEFOLDER))
120 + createsievefolder = 1;
121 + else if ((subf = config_getstring(IMAPOPT_AUTOSIEVEFOLDERS)) != NULL) {
122 + /* Roll through subf */
123 + next_subf = (char *) subf;
124 + while (*next_subf) {
125 + for (p = next_subf ; isspace((int) *p) || *p == SEP ; p++);
126 + for (next_subf = p ; *next_subf && *next_subf != SEP ; next_subf++);
127 + for (q = next_subf ; q > p && (isspace((int) *q) || *q == SEP || !*q); q--);
133 + * This is a preliminary length check based on the assumption
134 + * that the *final* internal format will be something
135 + * like user.userid.subfolder(s).
137 + if (len > sizeof(option_name_external) - strlen(userid) - 5)
138 + return IMAP_MAILBOX_BADNAME;
140 + strlcpy(option_name_external, namespace->prefix[NAMESPACE_INBOX], sizeof(option_name_external));
141 + strncat(option_name_external, p, len);
144 + * Transform the option folder name to internal namespace and compare it
145 + * with what must be created.
147 + r = namespace->mboxname_tointernal(namespace, option_name_external, userid, option_name_internal);
150 + if (!strcmp(option_name_internal, subfolder)) {
151 + createsievefolder = 1;
157 + if (createsievefolder) {
158 + /* Folder is already in internal namespace format */
159 + r = mboxlist_createmailbox(subfolder, MAILBOX_FORMAT_NORMAL, NULL,
160 + 1, userid, auth_state, 0, 0, 0);
162 + mboxlist_changesub(subfolder, userid, auth_state, 1, 1);
163 + syslog(LOG_DEBUG, "autosievefolder: User %s, folder %s creation succeeded.",
164 + userid, subfolder);
167 + syslog(LOG_ERR, "autosievefolder: User %s, folder %s creation failed. %s",
168 + userid, subfolder,error_message(r));
172 + return IMAP_MAILBOX_NONEXISTENT;
175 diff -Naur cyrus-imapd-2.2.12/lib/imapoptions cyrus-imapd-2.2.12-autosieve.uncompiled/lib/imapoptions
176 --- cyrus-imapd-2.2.12/lib/imapoptions 2004-07-21 22:07:45 +0300
177 +++ cyrus-imapd-2.2.12-autosieve.uncompiled/lib/imapoptions 2005-02-15 13:59:51 +0200
179 /* If enabled, lmtpd will look for Sieve scripts in user's home
180 directories: ~user/.sieve. */
182 +{ "anysievefolder", 0, SWITCH }
183 +/* It must be "yes" in order to permit the autocreation of any INBOX subfolder
184 + requested by a sieve filter, through the "fileinto" action. (default = no) */
186 +{ "autosievefolders", NULL, STRING }
187 +/* It is a "|" separated list of subfolders of INBOX that will be automatically created,
188 + if requested by a sieve filter, through the "fileinto" action. (default = null)
189 + i.e. autosievefolders: Junk | Spam */
191 { "singleinstancestore", 1, SWITCH }
192 /* If enabled, lmtpd and nntpd attempt to only write one copy of a message per
193 partition and create hard links, resulting in a potentially large