# Automatically create target mailboxes referenced in user Sieve files # (but only if user has sufficient privilege). # diff -uNrd cyrus-imapd-2.3.8/imap/lmtpd.c cyrus-imapd/imap/lmtpd.c --- cyrus-imapd-2.3.8/imap/lmtpd.c 2007-02-05 18:41:47.000000000 +0000 +++ cyrus-imapd/imap/lmtpd.c 2007-03-26 17:52:35.000000000 +0100 @@ -466,6 +466,7 @@ char *id, const char *user, char *notifyheader, + int autocreate, const char *mailboxname, int quotaoverride, int acloverride) @@ -475,6 +476,7 @@ time_t now = time(NULL); unsigned long uid; const char *notifier; + int created = 0; if (dupelim && id && duplicate_check(id, strlen(id), mailboxname, strlen(mailboxname))) { @@ -488,6 +490,22 @@ quotaoverride ? -1 : config_getswitch(IMAPOPT_LMTP_STRICT_QUOTA) ? size : 0); + /* authuser is defined inside Sieve files, but not in dpc22+foo deliveries. + * dpc22+foo should not autocreate folders, only deliver into mailboxes + * which have already exist and provide anonymous post access. */ + if ((r == IMAP_MAILBOX_NONEXISTENT) && autocreate && authuser) { + r = mboxlist_createmailbox(mailboxname, 0, 0, 1, + authuser, authstate, 0, 0, 0); + if (!r) + r = append_setup(&as, mailboxname, MAILBOX_FORMAT_NORMAL, + authuser, authstate, acloverride ? 0 : ACL_POST, + quotaoverride ? -1 : + config_getswitch(IMAPOPT_LMTP_STRICT_QUOTA) + ? size : 0); + if (!r) + created = 1; + } + if (!r && !content->body) { /* parse the message body if we haven't already, and keep the file mmap'ed */ @@ -515,7 +533,10 @@ append_commit(&as, quotaoverride ? -1 : 0, NULL, &uid, NULL); syslog(LOG_INFO, "Delivered: %s to mailbox: %s", id, mailboxname); - sync_log_append(mailboxname); + if (created) + sync_log_mailbox(mailboxname); + else + sync_log_append(mailboxname); if (user) { /* check if the \Seen flag has been set on this message */ @@ -669,7 +690,7 @@ return deliver_mailbox(md->f, mydata->content, mydata->stage, md->size, flag, nflags, mydata->authuser, mydata->authstate, md->id, - NULL, mydata->notifyheader, + NULL, mydata->notifyheader, 0, namebuf, quotaoverride, 0); } @@ -689,7 +710,7 @@ ret2 = deliver_mailbox(md->f, mydata->content, mydata->stage, md->size, flag, nflags, mydata->authuser, mydata->authstate, md->id, - username, mydata->notifyheader, + username, mydata->notifyheader, 0, namebuf, quotaoverride, 0); } if (ret2 == IMAP_MAILBOX_NONEXISTENT && mailboxname && @@ -699,7 +720,7 @@ ret2 = deliver_mailbox(md->f, mydata->content, mydata->stage, md->size, flag, nflags, mydata->authuser, mydata->authstate, md->id, - username, mydata->notifyheader, + username, mydata->notifyheader, 0, namebuf, quotaoverride, 0); } if (ret2) { @@ -711,7 +732,7 @@ ret = deliver_mailbox(md->f, mydata->content, mydata->stage, md->size, flag, nflags, (char *) username, authstate, md->id, - username, mydata->notifyheader, + username, mydata->notifyheader, 0, namebuf, quotaoverride, 1); if (authstate) auth_freestate(authstate); diff -uNrd cyrus-imapd-2.3.8/imap/lmtpd.h cyrus-imapd/imap/lmtpd.h --- cyrus-imapd-2.3.8/imap/lmtpd.h 2006-11-30 17:11:18.000000000 +0000 +++ cyrus-imapd/imap/lmtpd.h 2007-03-26 17:52:55.000000000 +0100 @@ -88,6 +88,7 @@ char *id, const char *user, char *notifyheader, + int autocreate, const char *mailboxname, int quotaoverride, int acloverride); diff -uNrd cyrus-imapd-2.3.8/imap/lmtp_sieve.c cyrus-imapd/imap/lmtp_sieve.c --- cyrus-imapd-2.3.8/imap/lmtp_sieve.c 2007-02-05 18:41:47.000000000 +0000 +++ cyrus-imapd/imap/lmtp_sieve.c 2007-03-26 17:53:17.000000000 +0100 @@ -481,7 +481,7 @@ ret = deliver_mailbox(md->f, mdata->content, mdata->stage, md->size, fc->imapflags->flag, fc->imapflags->nflags, (char *) sd->username, sd->authstate, md->id, - sd->username, mdata->notifyheader, + sd->username, mdata->notifyheader, 0, namebuf, quotaoverride, 0); }