bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
12d535f8c44bbcdc1338f49aa93a0d637bd48fd9Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#include "lib.h"
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#include "array.h"
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#include "mail-storage-private.h"
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#include "mailbox-list-private.h"
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#include "notify-plugin-private.h"
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#define NOTIFY_CONTEXT(obj) \
fc7e60de50fca5e86f47f428681518895b6e1d46Aki Tuomi MODULE_CONTEXT_REQUIRE(obj, notify_storage_module)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen#define NOTIFY_MAIL_CONTEXT(obj) \
fc7e60de50fca5e86f47f428681518895b6e1d46Aki Tuomi MODULE_CONTEXT_REQUIRE(obj, notify_mail_module)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(notify_storage_module,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen &mail_storage_module_register);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(notify_mail_module,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen &mail_module_register);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic void
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_mail_expunge(struct mail *_mail)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mail_private *mail = (struct mail_private *)_mail;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mail_module_context *lmail = NOTIFY_MAIL_CONTEXT(mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen notify_contexts_mail_expunge(_mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen lmail->super.expunge(_mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic void
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_mail_update_flags(struct mail *_mail, enum modify_type modify_type,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen enum mail_flags flags)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mail_private *mail = (struct mail_private *)_mail;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mail_module_context *lmail = NOTIFY_MAIL_CONTEXT(mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen enum mail_flags old_flags, new_flags;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen old_flags = mail_get_flags(_mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen lmail->super.update_flags(_mail, modify_type, flags);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen new_flags = mail_get_flags(_mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen if ((old_flags ^ new_flags) == 0)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen return;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen notify_contexts_mail_update_flags(_mail, old_flags);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic void
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_mail_update_keywords(struct mail *_mail, enum modify_type modify_type,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mail_keywords *keywords)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mail_private *mail = (struct mail_private *)_mail;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mail_module_context *lmail = NOTIFY_MAIL_CONTEXT(mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen const char *const *old_keywords, *const *new_keywords;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen unsigned int i;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen old_keywords = mail_get_keywords(_mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen lmail->super.update_keywords(_mail, modify_type, keywords);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen new_keywords = mail_get_keywords(_mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen for (i = 0; old_keywords[i] != NULL && new_keywords[i] != NULL; i++) {
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen if (strcmp(old_keywords[i], new_keywords[i]) != 0)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen break;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen if (old_keywords[i] == NULL && new_keywords[i] == NULL)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen return;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen notify_contexts_mail_update_keywords(_mail, old_keywords);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainenstatic void notify_mail_allocated(struct mail *_mail)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen struct mail_private *mail = (struct mail_private *)_mail;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen struct mail_vfuncs *v = mail->vlast;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mail_module_context *lmail;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen if ((_mail->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) != 0)
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen return;
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen lmail = p_new(mail->pool, union mail_module_context, 1);
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen lmail->super = *v;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen mail->vlast = &lmail->super;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->expunge = notify_mail_expunge;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->update_flags = notify_mail_update_flags;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->update_keywords = notify_mail_update_keywords;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen MODULE_CONTEXT_SET_SELF(mail, notify_mail_module, lmail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic int
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_copy(struct mail_save_context *ctx, struct mail *mail)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mailbox_module_context *lbox =
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen NOTIFY_CONTEXT(ctx->transaction->box);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen int ret;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
2c7cde7c78ccb28dcaa864d262ed6e991a7e8eb7Timo Sirainen if ((ret = lbox->super.copy(ctx, mail)) < 0)
2c7cde7c78ccb28dcaa864d262ed6e991a7e8eb7Timo Sirainen return -1;
2c7cde7c78ccb28dcaa864d262ed6e991a7e8eb7Timo Sirainen
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen if ((ctx->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) != 0) {
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen /* no notifications */
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen } else if (ctx->saving) {
2c7cde7c78ccb28dcaa864d262ed6e991a7e8eb7Timo Sirainen /* we came from mailbox_save_using_mail() */
2c7cde7c78ccb28dcaa864d262ed6e991a7e8eb7Timo Sirainen notify_contexts_mail_save(ctx->dest_mail);
2c7cde7c78ccb28dcaa864d262ed6e991a7e8eb7Timo Sirainen } else {
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen notify_contexts_mail_copy(mail, ctx->dest_mail);
2c7cde7c78ccb28dcaa864d262ed6e991a7e8eb7Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen return ret;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic int
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_save_finish(struct mail_save_context *ctx)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mailbox_module_context *lbox =
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen NOTIFY_CONTEXT(ctx->transaction->box);
abec3f4c5ec486c393e1513950f2d4819dcbc30fTimo Sirainen struct mail *dest_mail = ctx->copying_via_save ? NULL : ctx->dest_mail;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen if (lbox->super.save_finish(ctx) < 0)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen return -1;
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen if (dest_mail != NULL &&
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen (ctx->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0)
263e4b2733768062cb0b8b8917cad78fa2a04ff9Timo Sirainen notify_contexts_mail_save(dest_mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen return 0;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic struct mailbox_transaction_context *
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_transaction_begin(struct mailbox *box,
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi enum mailbox_transaction_flags flags,
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi const char *reason)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(box);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mailbox_transaction_context *t;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi t = lbox->super.transaction_begin(box, flags, reason);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen if ((t->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0)
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen notify_contexts_mail_transaction_begin(t);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen return t;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic int
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_transaction_commit(struct mailbox_transaction_context *t,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mail_transaction_commit_changes *changes_r)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(t->box);
2f564433c979a41ade84b75fa10c7b46fb9781acTimo Sirainen bool no_notify = (t->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) != 0;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen if ((lbox->super.transaction_commit(t, changes_r)) < 0) {
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen notify_contexts_mail_transaction_rollback(t);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen return -1;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen }
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen /* FIXME: note that t is already freed at this stage. it's not actually
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen being dereferenced anymore though. still, a bit unsafe.. */
2f564433c979a41ade84b75fa10c7b46fb9781acTimo Sirainen if (!no_notify)
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen notify_contexts_mail_transaction_commit(t, changes_r);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen return 0;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic void
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_transaction_rollback(struct mailbox_transaction_context *t)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(t->box);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen if ((t->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0)
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen notify_contexts_mail_transaction_rollback(t);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen lbox->super.transaction_rollback(t);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainenstatic int
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainennotify_mailbox_create(struct mailbox *box, const struct mailbox_update *update,
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen bool directory)
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen{
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(box);
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen if (lbox->super.create_box(box, update, directory) < 0)
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen return -1;
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen notify_contexts_mailbox_create(box);
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen return 0;
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen}
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainenstatic int
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainennotify_mailbox_update(struct mailbox *box, const struct mailbox_update *update)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen{
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(box);
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen if (lbox->super.update_box(box, update) < 0)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen return -1;
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen notify_contexts_mailbox_update(box);
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen return 0;
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen}
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainenstatic int
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainennotify_mailbox_delete(struct mailbox *box)
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen{
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(box);
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen notify_contexts_mailbox_delete_begin(box);
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen if (lbox->super.delete_box(box) < 0) {
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen notify_contexts_mailbox_delete_rollback();
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen return -1;
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen }
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen notify_contexts_mailbox_delete_commit(box);
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen return 0;
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen}
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen
206ac4273fa102500fa017f0c21a4fd72e94665aTimo Sirainenstatic int
71e88fae3be360e9a93b3398e743f99a6f05d2edTimo Sirainennotify_mailbox_rename(struct mailbox *src, struct mailbox *dest)
206ac4273fa102500fa017f0c21a4fd72e94665aTimo Sirainen{
206ac4273fa102500fa017f0c21a4fd72e94665aTimo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(src);
206ac4273fa102500fa017f0c21a4fd72e94665aTimo Sirainen
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen if (lbox->super.rename_box(src, dest) < 0)
206ac4273fa102500fa017f0c21a4fd72e94665aTimo Sirainen return -1;
206ac4273fa102500fa017f0c21a4fd72e94665aTimo Sirainen
71e88fae3be360e9a93b3398e743f99a6f05d2edTimo Sirainen notify_contexts_mailbox_rename(src, dest);
206ac4273fa102500fa017f0c21a4fd72e94665aTimo Sirainen return 0;
206ac4273fa102500fa017f0c21a4fd72e94665aTimo Sirainen}
206ac4273fa102500fa017f0c21a4fd72e94665aTimo Sirainen
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainenstatic int
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainennotify_mailbox_set_subscribed(struct mailbox *box, bool set)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen{
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(box);
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen if (lbox->super.set_subscribed(box, set) < 0)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen return -1;
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen notify_contexts_mailbox_set_subscribed(box, set);
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen return 0;
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen}
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen
ea9d9d99948cff5f9b881f79b28fa3b80da0f2a7Timo Sirainenstatic void notify_mailbox_allocated(struct mailbox *box)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen struct mailbox_vfuncs *v = box->vlast;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mailbox_module_context *lbox;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen lbox = p_new(box->pool, union mailbox_module_context, 1);
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen lbox->super = *v;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen box->vlast = &lbox->super;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->copy = notify_copy;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->save_finish = notify_save_finish;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->transaction_begin = notify_transaction_begin;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->transaction_commit = notify_transaction_commit;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->transaction_rollback = notify_transaction_rollback;
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen v->create_box = notify_mailbox_create;
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen v->update_box = notify_mailbox_update;
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen v->delete_box = notify_mailbox_delete;
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen v->rename_box = notify_mailbox_rename;
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen v->set_subscribed = notify_mailbox_set_subscribed;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen MODULE_CONTEXT_SET_SELF(box, notify_storage_module, lbox);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainenstatic struct mail_storage_hooks notify_mail_storage_hooks = {
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen .mailbox_allocated = notify_mailbox_allocated,
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen .mail_allocated = notify_mail_allocated
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainen};
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainenvoid notify_plugin_init_storage(struct module *module)
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainen{
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainen mail_storage_hooks_add(module, &notify_mail_storage_hooks);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenvoid notify_plugin_deinit_storage(void)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen{
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainen mail_storage_hooks_remove(&notify_mail_storage_hooks);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen}