dovecot-2.0-pigeonhole: Cleaned up mail storage-related code (mo...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Sat Jun 19 14:07:46 EEST 2010
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/84a0495b9b50
changeset: 1296:84a0495b9b50
user: Stephan Bosch <stephan at rename-it.nl>
date: Sat Jun 19 13:07:10 2010 +0200
description:
Cleaned up mail storage-related code (modified patch by Timo Sirainen).
diffstat:
src/lib-sieve/plugins/mailbox/tag-mailbox-create.c | 68 +++++--------
src/lib-sieve/plugins/mailbox/tst-mailboxexists.c | 4 +-
src/lib-sieve/sieve-actions.c | 115 +++++++++-------------
src/lib-sieve/sieve-actions.h | 8 +-
src/lib-sieve/sieve-types.h | 2 +-
src/plugins/lda-sieve/lda-sieve-plugin.c | 2 +-
src/sieve-tools/sieve-filter.c | 2 +-
src/sieve-tools/sieve-test.c | 2 +-
src/testsuite/testsuite-mailstore.c | 6 +-
src/testsuite/testsuite-mailstore.h | 4 +-
src/testsuite/testsuite-script.c | 5 +-
src/testsuite/testsuite.c | 2 +-
12 files changed, 93 insertions(+), 127 deletions(-)
diffs (truncated from 539 to 300 lines):
diff -r fb437717ff10 -r 84a0495b9b50 src/lib-sieve/plugins/mailbox/tag-mailbox-create.c
--- a/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c Sat Jun 19 11:32:00 2010 +0200
+++ b/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c Sat Jun 19 13:07:10 2010 +0200
@@ -122,54 +122,42 @@
struct act_store_transaction *trans =
(struct act_store_transaction *) tr_context;
struct mail_storage **storage = &(aenv->exec_status->last_storage);
- enum mailbox_flags flags =
- MAILBOX_FLAG_KEEP_RECENT | MAILBOX_FLAG_SAVEONLY |
- MAILBOX_FLAG_POST_SESSION;
- struct mailbox *box = NULL;
+ enum mail_error error;
/* Check whether creation is necessary */
- if ( trans->box != NULL || trans->redundant || trans->disabled )
+ if ( trans->box == NULL || trans->redundant || trans->disabled )
return TRUE;
- /* Check availability of namespace and folder name */
- if ( trans->namespace == NULL || trans->folder == NULL )
+ /* Check whether creation has a chance of working */
+ if ( trans->error_code != MAIL_ERROR_NONE &&
+ trans->error_code != MAIL_ERROR_NOTFOUND )
return FALSE;
- /* Check whether creation has a chance of working */
- if ( trans->error_code != MAIL_ERROR_NONE
- && trans->error_code != MAIL_ERROR_NOTFOUND )
+ *storage = mailbox_get_storage(trans->box);
+
+ /* Create mailbox */
+ if ( mailbox_create(trans->box, NULL, FALSE) < 0 ) {
+ (void)mail_storage_get_last_error(*storage, &error);
+ if ( error != MAIL_ERROR_EXISTS ) {
+ sieve_act_store_get_storage_error(aenv, trans);
+ return FALSE;
+ }
+ }
+ /* Subscribe to it if necessary */
+ if ( aenv->scriptenv->mailbox_autosubscribe ) {
+ (void)mailbox_list_set_subscribed
+ (mailbox_get_namespace(trans->box)->list,
+ mailbox_get_name(trans->box), TRUE);
+ }
+
+ /* Try opening again */
+ if ( mailbox_sync(trans->box, 0) < 0 ) {
+ /* Failed definitively */
+ sieve_act_store_get_storage_error(aenv, trans);
return FALSE;
+ }
- *storage = trans->namespace->storage;
-
- box = mailbox_alloc(trans->namespace->list, trans->folder, flags);
- /* Create mailbox */
- if ( mailbox_create(box, NULL, FALSE) < 0 ) {
- mailbox_free(&box);
- box = NULL;
-
- } else {
- /* Subscribe to it if necessary */
- if ( aenv->scriptenv->mailbox_autosubscribe ) {
- (void)mailbox_list_set_subscribed
- (trans->namespace->list, trans->folder, TRUE);
- }
-
- /* Try opening again */
- if ( mailbox_sync(box, 0) < 0 ) {
- /* Failed definitively */
- mailbox_free(&box);
- box = NULL;
- }
- }
-
- /* Fetch error */
- if ( box == NULL )
- sieve_act_store_get_storage_error(aenv, trans);
-
- trans->box = box;
-
- return ( box != NULL );
+ return TRUE;
}
diff -r fb437717ff10 -r 84a0495b9b50 src/lib-sieve/plugins/mailbox/tst-mailboxexists.c
--- a/src/lib-sieve/plugins/mailbox/tst-mailboxexists.c Sat Jun 19 11:32:00 2010 +0200
+++ b/src/lib-sieve/plugins/mailbox/tst-mailboxexists.c Sat Jun 19 13:07:10 2010 +0200
@@ -124,7 +124,7 @@
sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS, "mailboxexists test");
- if ( renv->scriptenv->namespaces != NULL ) {
+ if ( renv->scriptenv->user != NULL ) {
mailbox_item = NULL;
while ( (result=sieve_coded_stringlist_next_item
(mailbox_names, &mailbox_item))
@@ -134,7 +134,7 @@
struct mailbox *box;
/* Find the namespace */
- ns = mail_namespace_find(renv->scriptenv->namespaces, &mailbox);
+ ns = mail_namespace_find(renv->scriptenv->user->namespaces, &mailbox);
if ( ns == NULL) {
all_exist = FALSE;
break;
diff -r fb437717ff10 -r 84a0495b9b50 src/lib-sieve/sieve-actions.c
--- a/src/lib-sieve/sieve-actions.c Sat Jun 19 11:32:00 2010 +0200
+++ b/src/lib-sieve/sieve-actions.c Sat Jun 19 13:07:10 2010 +0200
@@ -265,11 +265,11 @@
{
pool_t pool = sieve_result_pool(aenv->result);
- trans->error = p_strdup(pool,
- mail_storage_get_last_error(trans->namespace->storage, &trans->error_code));
+ trans->error = p_strdup(pool,
+ mail_storage_get_last_error(mailbox_get_storage(trans->box),
+ &trans->error_code));
}
-
/* Equality */
static bool act_store_equals
@@ -330,18 +330,22 @@
/* Action implementation */
-static struct mailbox *act_store_mailbox_open
+static bool act_store_mailbox_open
(const struct sieve_action_exec_env *aenv, const char **mailbox,
- struct mail_namespace **ns_r, const char **folder_r)
+ struct mailbox **box_r)
{
struct mail_storage **storage = &(aenv->exec_status->last_storage);
enum mailbox_flags flags =
MAILBOX_FLAG_KEEP_RECENT | MAILBOX_FLAG_SAVEONLY |
MAILBOX_FLAG_POST_SESSION;
string_t *mailbox_mutf7;
+ struct mail_namespace *ns;
struct mailbox *box;
+ const char *folder;
enum mail_error error;
+ *box_r = NULL;
+
/* Deliveries to INBOX must always succeed, regardless of ACLs */
if (strcasecmp(*mailbox, "INBOX") == 0) {
flags |= MAILBOX_FLAG_IGNORE_ACLS;
@@ -353,37 +357,32 @@
if ( imap_utf8_to_utf7(*mailbox, mailbox_mutf7) < 0 ) {
/* FIXME: check utf-8 validity at compiletime/runtime */
sieve_result_error(aenv, "mailbox name not utf-8: %s", *mailbox);
- return NULL;
+ return FALSE;
}
- *folder_r = str_c(mailbox_mutf7);
- *ns_r = mail_namespace_find(aenv->scriptenv->namespaces, folder_r);
- if ( *ns_r == NULL) {
- *storage = NULL;
- return NULL;
+ folder = str_c(mailbox_mutf7);
+ ns = mail_namespace_find(aenv->scriptenv->user->namespaces, &folder);
+ if ( ns == NULL) {
+ sieve_result_error
+ (aenv, "failed to find namespace for mailbox '%s'", *mailbox);
+ return FALSE;
}
- if ( **folder_r == '\0' ) {
+ if ( *folder == '\0' ) {
/* delivering to a namespace prefix means we actually want to
* deliver to the INBOX instead
*/
- *folder_r = *mailbox = "INBOX";
+ folder = *mailbox = "INBOX";
flags |= MAILBOX_FLAG_IGNORE_ACLS;
- *ns_r = mail_namespace_find(aenv->scriptenv->namespaces, folder_r);
- if ( *ns_r == NULL) {
- *storage = NULL;
- return NULL;
- }
-
- *storage = (*ns_r)->storage;
+ ns = mail_namespace_find_inbox(aenv->scriptenv->user->namespaces);
}
/* First attempt at opening the box */
- box = mailbox_alloc((*ns_r)->list, *folder_r, flags);
+ *box_r = box = mailbox_alloc(ns->list, folder, flags);
if ( mailbox_open(box) == 0 ) {
/* Success */
- return box;
+ return TRUE;
}
/* Failed */
@@ -394,33 +393,28 @@
/* Only continue when the mailbox is missing and when we are allowed to
* create it.
*/
- if ( !aenv->scriptenv->mailbox_autocreate || error != MAIL_ERROR_NOTFOUND ) {
- mailbox_free(&box);
- return NULL;
- }
+ if ( error != MAIL_ERROR_NOTFOUND || !aenv->scriptenv->mailbox_autocreate )
+ return FALSE;
/* Try creating it. */
if ( mailbox_create(box, NULL, FALSE) < 0 ) {
(void)mail_storage_get_last_error(*storage, &error);
- if (error != MAIL_ERROR_EXISTS) {
- mailbox_free(&box);
- return NULL;
- }
+ if (error != MAIL_ERROR_EXISTS)
+ return FALSE;
}
/* Subscribe to it if required */
if ( aenv->scriptenv->mailbox_autosubscribe ) {
- (void)mailbox_list_set_subscribed((*ns_r)->list, *folder_r, TRUE);
+ (void)mailbox_list_set_subscribed(ns->list, folder, TRUE);
}
/* Try opening again */
if ( mailbox_sync(box, 0) < 0 ) {
/* Failed definitively */
- mailbox_free(&box);
- return NULL;
+ return FALSE;
}
- return box;
+ return TRUE;
}
static bool act_store_start
@@ -431,11 +425,9 @@
const struct sieve_script_env *senv = aenv->scriptenv;
const struct sieve_message_data *msgdata = aenv->msgdata;
struct act_store_transaction *trans;
- struct mail_namespace *ns = NULL;
struct mailbox *box = NULL;
- const char *folder;
pool_t pool = sieve_result_pool(aenv->result);
- bool disabled = FALSE, redundant = FALSE;
+ bool disabled = FALSE, redundant = FALSE, open_failed = FALSE;
/* If context is NULL, the store action is the result of (implicit) keep */
if ( ctx == NULL ) {
@@ -445,19 +437,19 @@
/* Open the requested mailbox */
- /* NOTE: The caller of the sieve library is allowed to leave namespaces set
+ /* NOTE: The caller of the sieve library is allowed to leave user set
* to NULL. This implementation will then skip actually storing the message.
*/
- if ( senv->namespaces != NULL ) {
- box = act_store_mailbox_open(aenv, &ctx->mailbox, &ns, &folder);
+ if ( senv->user != NULL ) {
+ if ( !act_store_mailbox_open(aenv, &ctx->mailbox, &box) ) {
+ open_failed = TRUE;
/* Check whether we are trying to store the message in the folder it
* originates from. In that case we skip actually storing it.
*/
- if ( box != NULL && mailbox_backends_equal(box, msgdata->mail->box) ) {
+ } else if ( mailbox_backends_equal(box, msgdata->mail->box) ) {
mailbox_free(&box);
box = NULL;
- ns = NULL;
redundant = TRUE;
}
} else {
@@ -468,22 +460,19 @@
trans = p_new(pool, struct act_store_transaction, 1);
trans->context = ctx;
- trans->namespace = ns;
- trans->folder = folder;
trans->box = box;
trans->flags = 0;
trans->disabled = disabled;
trans->redundant = redundant;
+ trans->error_code = MAIL_ERROR_NONE;
- if ( ns != NULL && box == NULL )
+ if ( open_failed )
sieve_act_store_get_storage_error(aenv, trans);
-
+
*tr_context = (void *)trans;
- return ( (box != NULL)
More information about the dovecot-cvs
mailing list