bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
fc7e60de50fca5e86f47f428681518895b6e1d46Aki Tuomi MODULE_CONTEXT_REQUIRE(obj, notify_storage_module)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(notify_storage_module,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(notify_mail_module,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mail_private *mail = (struct mail_private *)_mail;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mail_module_context *lmail = NOTIFY_MAIL_CONTEXT(mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_mail_update_flags(struct mail *_mail, enum modify_type modify_type,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mail_private *mail = (struct mail_private *)_mail;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mail_module_context *lmail = NOTIFY_MAIL_CONTEXT(mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen lmail->super.update_flags(_mail, modify_type, flags);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen notify_contexts_mail_update_flags(_mail, old_flags);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_mail_update_keywords(struct mail *_mail, enum modify_type modify_type,
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 lmail->super.update_keywords(_mail, modify_type, keywords);
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 if (old_keywords[i] == NULL && new_keywords[i] == NULL)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen notify_contexts_mail_update_keywords(_mail, old_keywords);
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainenstatic void notify_mail_allocated(struct mail *_mail)
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen struct mail_private *mail = (struct mail_private *)_mail;
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen if ((_mail->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) != 0)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen lmail = p_new(mail->pool, union mail_module_context, 1);
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->update_keywords = notify_mail_update_keywords;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen MODULE_CONTEXT_SET_SELF(mail, notify_mail_module, lmail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_copy(struct mail_save_context *ctx, struct mail *mail)
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen if ((ctx->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) != 0) {
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen /* no notifications */
2c7cde7c78ccb28dcaa864d262ed6e991a7e8eb7Timo Sirainen /* we came from mailbox_save_using_mail() */
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen notify_contexts_mail_copy(mail, ctx->dest_mail);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_save_finish(struct mail_save_context *ctx)
abec3f4c5ec486c393e1513950f2d4819dcbc30fTimo Sirainen struct mail *dest_mail = ctx->copying_via_save ? NULL : ctx->dest_mail;
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen (ctx->transaction->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(box);
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi t = lbox->super.transaction_begin(box, flags, reason);
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen if ((t->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_transaction_commit(struct mailbox_transaction_context *t,
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen struct mail_transaction_commit_changes *changes_r)
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 if ((lbox->super.transaction_commit(t, changes_r)) < 0) {
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.. */
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen notify_contexts_mail_transaction_commit(t, changes_r);
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainennotify_transaction_rollback(struct mailbox_transaction_context *t)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(t->box);
8ccb1a013b07e7ca37b7281732b78c042f128388Timo Sirainen if ((t->flags & MAILBOX_TRANSACTION_FLAG_NO_NOTIFY) == 0)
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainennotify_mailbox_create(struct mailbox *box, const struct mailbox_update *update,
132bfe8fcb7a1be790dc8b5bf9d155c9f060808dTimo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(box);
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen if (lbox->super.create_box(box, update, directory) < 0)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainennotify_mailbox_update(struct mailbox *box, const struct mailbox_update *update)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(box);
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(box);
71e88fae3be360e9a93b3398e743f99a6f05d2edTimo Sirainennotify_mailbox_rename(struct mailbox *src, struct mailbox *dest)
206ac4273fa102500fa017f0c21a4fd72e94665aTimo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(src);
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainennotify_mailbox_set_subscribed(struct mailbox *box, bool set)
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen union mailbox_module_context *lbox = NOTIFY_CONTEXT(box);
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen notify_contexts_mailbox_set_subscribed(box, set);
ea9d9d99948cff5f9b881f79b28fa3b80da0f2a7Timo Sirainenstatic void notify_mailbox_allocated(struct mailbox *box)
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen lbox = p_new(box->pool, union mailbox_module_context, 1);
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->transaction_begin = notify_transaction_begin;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->transaction_commit = notify_transaction_commit;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen v->transaction_rollback = notify_transaction_rollback;
95c4f06cba717df14358ec883b1bd1aec6cbf0a1Timo Sirainen v->set_subscribed = notify_mailbox_set_subscribed;
56c35c844320b0a157d1aaa6b3e62b7f3851b235Timo Sirainen MODULE_CONTEXT_SET_SELF(box, notify_storage_module, lbox);
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainenstatic struct mail_storage_hooks notify_mail_storage_hooks = {
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen .mailbox_allocated = notify_mailbox_allocated,
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainenvoid notify_plugin_init_storage(struct module *module)
5666a3d6a7ea89362b8d9e8b39b15424cd9d6388Timo Sirainen mail_storage_hooks_add(module, ¬ify_mail_storage_hooks);