bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
12d535f8c44bbcdc1338f49aa93a0d637bd48fd9Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#include "lib.h"
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#include "llist.h"
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#include "mail-storage.h"
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#include "notify-plugin-private.h"
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstruct notify_mail_txn {
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *prev, *next;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mailbox_transaction_context *parent_mailbox_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mail *tmp_mail;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen void *txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen};
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstruct notify_context {
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *prev, *next;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_vfuncs v;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn_list;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen void *mailbox_delete_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen};
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
bd63b5b860658b01b1f46f26d406e1e4a9dc019aTimo Sirainenconst char *notify_plugin_version = DOVECOT_ABI_VERSION;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic struct notify_context *ctx_list = NULL;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic struct notify_mail_txn *
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_context_find_mail_txn(struct notify_context *ctx,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mailbox_transaction_context *t)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn = ctx->mail_txn_list;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (; mail_txn != NULL; mail_txn = mail_txn->next) {
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen if (mail_txn->parent_mailbox_txn == t)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen return mail_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen i_panic("no notify_mail_txn found");
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_contexts_mail_transaction_begin(struct mailbox_transaction_context *t)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen mail_txn = i_new(struct notify_mail_txn, 1);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen mail_txn->parent_mailbox_txn = t;
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen mail_txn->txn = ctx->v.mail_transaction_begin == NULL ? NULL :
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->v.mail_transaction_begin(t);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen DLLIST_PREPEND(&ctx->mail_txn_list, mail_txn);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_contexts_mail_save(struct mail *mail)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mail_save == NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen continue;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen mail_txn = notify_context_find_mail_txn(ctx, mail->transaction);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen ctx->v.mail_save(mail_txn->txn, mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_contexts_mail_copy(struct mail *src, struct mail *dst)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mail_copy == NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen continue;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen mail_txn = notify_context_find_mail_txn(ctx, dst->transaction);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen ctx->v.mail_copy(mail_txn->txn, src, dst);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_contexts_mail_expunge(struct mail *mail)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mail_expunge == NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen continue;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen mail_txn = notify_context_find_mail_txn(ctx, mail->transaction);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen ctx->v.mail_expunge(mail_txn->txn, mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_contexts_mail_update_flags(struct mail *mail,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen enum mail_flags old_flags)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
5441373137620aa8094ceafd9e698d430f5ed0d0Aki Tuomi if (mail->saving)
5441373137620aa8094ceafd9e698d430f5ed0d0Aki Tuomi return;
5441373137620aa8094ceafd9e698d430f5ed0d0Aki Tuomi
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mail_update_flags == NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen continue;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen mail_txn = notify_context_find_mail_txn(ctx, mail->transaction);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen ctx->v.mail_update_flags(mail_txn->txn, mail, old_flags);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_contexts_mail_update_keywords(struct mail *mail,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen const char *const *old_keywords)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
5441373137620aa8094ceafd9e698d430f5ed0d0Aki Tuomi if (mail->saving)
5441373137620aa8094ceafd9e698d430f5ed0d0Aki Tuomi return;
5441373137620aa8094ceafd9e698d430f5ed0d0Aki Tuomi
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mail_update_keywords == NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen continue;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen mail_txn = notify_context_find_mail_txn(ctx, mail->transaction);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen ctx->v.mail_update_keywords(mail_txn->txn, mail, old_keywords);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_contexts_mail_transaction_commit(struct mailbox_transaction_context *t,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mail_transaction_commit_changes *changes)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mail_transaction_commit == NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen continue;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen mail_txn = notify_context_find_mail_txn(ctx, t);
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mail_transaction_commit != NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->v.mail_transaction_commit(mail_txn->txn, changes);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen DLLIST_REMOVE(&ctx->mail_txn_list, mail_txn);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen i_free(mail_txn);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_contexts_mail_transaction_rollback(struct mailbox_transaction_context *t)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen mail_txn = notify_context_find_mail_txn(ctx, t);
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mail_transaction_rollback != NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->v.mail_transaction_rollback(mail_txn->txn);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen DLLIST_REMOVE(&ctx->mail_txn_list, mail_txn);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen i_free(mail_txn);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainenvoid notify_contexts_mailbox_create(struct mailbox *box)
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen{
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen struct notify_context *ctx;
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen if (ctx->v.mailbox_create != NULL)
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen ctx->v.mailbox_create(box);
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen }
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen}
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainenvoid notify_contexts_mailbox_update(struct mailbox *box)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen{
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen struct notify_context *ctx;
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen if (ctx->v.mailbox_update != NULL)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen ctx->v.mailbox_update(box);
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen }
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen}
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainenvoid notify_contexts_mailbox_delete_begin(struct mailbox *box)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->mailbox_delete_txn =
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->v.mailbox_delete_begin == NULL ? NULL :
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->v.mailbox_delete_begin(box);
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainenvoid notify_contexts_mailbox_delete_commit(struct mailbox *box)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mailbox_delete_commit != NULL) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->v.mailbox_delete_commit(ctx->mailbox_delete_txn,
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen box);
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen ctx->mailbox_delete_txn = NULL;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_contexts_mailbox_delete_rollback(void)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mailbox_delete_rollback != NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->v.mailbox_delete_rollback(ctx->mailbox_delete_txn);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen ctx->mailbox_delete_txn = NULL;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
71e88fae3be360e9a93b3398e743f99a6f05d2edTimo Sirainenvoid notify_contexts_mailbox_rename(struct mailbox *src, struct mailbox *dest)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
87346782e83fdb1f316d6cf1d8fa51466c3f0e3aTimo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
87346782e83fdb1f316d6cf1d8fa51466c3f0e3aTimo Sirainen if (ctx->v.mailbox_rename != NULL)
71e88fae3be360e9a93b3398e743f99a6f05d2edTimo Sirainen ctx->v.mailbox_rename(src, dest);
87346782e83fdb1f316d6cf1d8fa51466c3f0e3aTimo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainenvoid notify_contexts_mailbox_set_subscribed(struct mailbox *box,
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen bool subscribed)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen{
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen struct notify_context *ctx;
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen if (ctx->v.mailbox_set_subscribed != NULL)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen ctx->v.mailbox_set_subscribed(box, subscribed);
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen }
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen}
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstruct notify_context *
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_register(const struct notify_vfuncs *v)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_context *ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen ctx = i_new(struct notify_context, 1);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen ctx->v = *v;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen DLLIST_PREPEND(&ctx_list, ctx);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen return ctx;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_unregister(struct notify_context *ctx)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct notify_mail_txn *mail_txn = ctx->mail_txn_list;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen for (; mail_txn != NULL; mail_txn = mail_txn->next) {
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->v.mail_transaction_rollback != NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->v.mail_transaction_rollback(mail_txn->txn);
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen }
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen if (ctx->mailbox_delete_txn != NULL &&
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->v.mailbox_delete_rollback != NULL)
2f779122ee7263be9c8fc7ffd6fa7405e888d755Timo Sirainen ctx->v.mailbox_delete_rollback(ctx->mailbox_delete_txn);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen DLLIST_REMOVE(&ctx_list, ctx);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen i_free(ctx);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainenvoid notify_plugin_init(struct module *module)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainen notify_plugin_init_storage(module);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_plugin_deinit(void)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen notify_plugin_deinit_storage();
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}