Mercurial > dovecot > core-2.2
changeset 19317:16ff395c156e
lib-storage/notify: Added MAILBOX_TRANSACTION_FLAG_NO_NOTIFY
This flag could potentially apply for other things as well, not just notify
plugin. In general anything that could do external notifications shouldn't
do anything for transactions with this flag.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 20 Oct 2015 15:27:42 +0300 |
parents | 467695fee373 |
children | f9a143c630a5 |
files | src/lib-storage/mail-storage.h src/plugins/notify/notify-storage.c |
diffstat | 2 files changed, 25 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/mail-storage.h Tue Oct 20 13:12:24 2015 +0300 +++ b/src/lib-storage/mail-storage.h Tue Oct 20 15:27:42 2015 +0300 @@ -177,7 +177,11 @@ MAILBOX_TRANSACTION_FLAG_NO_CACHE_DEC = 0x10, /* Sync transaction describes changes to mailbox that already happened to another mailbox with whom we're syncing with (dsync) */ - MAILBOX_TRANSACTION_FLAG_SYNC = 0x20 + MAILBOX_TRANSACTION_FLAG_SYNC = 0x20, + /* Don't trigger any notifications for this transaction. This + especially means the notify plugin. This would normally be used only + with _FLAG_SYNC. */ + MAILBOX_TRANSACTION_FLAG_NO_NOTIFY = 0x40 }; enum mailbox_sync_flags {
--- a/src/plugins/notify/notify-storage.c Tue Oct 20 13:12:24 2015 +0300 +++ b/src/plugins/notify/notify-storage.c Tue Oct 20 15:27:42 2015 +0300 @@ -79,6 +79,9 @@ struct mail_vfuncs *v = mail->vlast; union mail_module_context *lmail; + if ((_mail->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) != 0) + return; + lmail = p_new(mail->pool, union mail_module_context, 1); lmail->super = *v; mail->vlast = &lmail->super; @@ -98,7 +101,8 @@ NOTIFY_CONTEXT(ctx->transaction->box); int ret; - if (ctx->dest_mail == NULL) { + if (ctx->dest_mail == NULL && + (ctx->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0) { if (lt->tmp_mail == NULL) lt->tmp_mail = mail_alloc(ctx->transaction, 0, NULL); ctx->dest_mail = lt->tmp_mail; @@ -107,7 +111,9 @@ if ((ret = lbox->super.copy(ctx, mail)) < 0) return -1; - if (ctx->saving) { + if ((ctx->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) != 0) { + /* no notifications */ + } else if (ctx->saving) { /* we came from mailbox_save_using_mail() */ notify_contexts_mail_save(ctx->dest_mail); } else { @@ -124,7 +130,8 @@ union mailbox_module_context *lbox = NOTIFY_CONTEXT(ctx->transaction->box); - if (ctx->dest_mail == NULL) { + if (ctx->dest_mail == NULL && + (ctx->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0) { if (lt->tmp_mail == NULL) lt->tmp_mail = mail_alloc(ctx->transaction, 0, NULL); ctx->dest_mail = lt->tmp_mail; @@ -141,7 +148,8 @@ if (lbox->super.save_finish(ctx) < 0) return -1; - if (dest_mail != NULL) + if (dest_mail != NULL && + (ctx->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0) notify_contexts_mail_save(dest_mail); return 0; } @@ -159,7 +167,8 @@ lt = i_new(struct notify_transaction_context, 1); MODULE_CONTEXT_SET(t, notify_storage_module, lt); - notify_contexts_mail_transaction_begin(t); + if ((t->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0) + notify_contexts_mail_transaction_begin(t); return t; } @@ -179,7 +188,10 @@ return -1; } - notify_contexts_mail_transaction_commit(t, changes_r); + /* FIXME: note that t is already freed at this stage. it's not actually + being dereferenced anymore though. still, a bit unsafe.. */ + if ((t->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0) + notify_contexts_mail_transaction_commit(t, changes_r); return 0; } @@ -193,7 +205,8 @@ mail_free(<->tmp_mail); i_free(lt); - notify_contexts_mail_transaction_rollback(t); + if ((t->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0) + notify_contexts_mail_transaction_rollback(t); lbox->super.transaction_rollback(t); }