51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen#ifndef IMAP_NOTIFY_H
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen#define IMAP_NOTIFY_H
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenenum imap_notify_type {
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_TYPE_SUBSCRIBED,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_TYPE_SUBTREE,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_TYPE_MAILBOX
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen};
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenenum imap_notify_event {
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_EVENT_MESSAGE_NEW = 0x01,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_EVENT_MESSAGE_EXPUNGE = 0x02,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_EVENT_FLAG_CHANGE = 0x04,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_EVENT_ANNOTATION_CHANGE = 0x08,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_EVENT_MAILBOX_NAME = 0x10,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_EVENT_SUBSCRIPTION_CHANGE = 0x20,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_EVENT_MAILBOX_METADATA_CHANGE = 0x40,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_EVENT_SERVER_METADATA_CHANGE = 0x80
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen};
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen#define UNSUPPORTED_EVENTS \
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen (IMAP_NOTIFY_EVENT_ANNOTATION_CHANGE | \
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_EVENT_MAILBOX_METADATA_CHANGE | \
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen IMAP_NOTIFY_EVENT_SERVER_METADATA_CHANGE)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenstruct imap_notify_mailboxes {
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen enum imap_notify_event events;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen enum imap_notify_type type;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen ARRAY_TYPE(const_string) names;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen};
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenstruct imap_notify_namespace {
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen struct imap_notify_context *ctx;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen struct mail_namespace *ns;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen struct mailbox_list_notify *notify;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct imap_notify_mailboxes) mailboxes;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen};
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenstruct imap_notify_context {
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen pool_t pool;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen struct client *client;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen const char *error;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct imap_notify_namespace) namespaces;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen enum imap_notify_event selected_events;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen enum imap_notify_event global_used_events;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen unsigned int global_max_mailbox_names;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen struct imap_fetch_context *fetch_ctx;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen struct timeout *to_watch;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool have_subscriptions:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool selected_set:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool selected_immediate_expunges:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool send_immediate_status:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool watching_mailbox:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool notifying:1;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen};
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenbool imap_notify_match_mailbox(struct imap_notify_namespace *notify_ns,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen const struct imap_notify_mailboxes *notify_boxes,
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen const char *vname);
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenint imap_client_notify_newmails(struct client *client);
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenvoid imap_client_notify_finished(struct client *client);
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
0081ed0d90d302027ed4a53cb617c0179c246868Timo Sirainenvoid imap_client_notify_command_allocated(struct client *client);
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenvoid imap_client_notify_command_freed(struct client *client);
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenint imap_notify_begin(struct imap_notify_context *ctx);
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenvoid imap_notify_deinit(struct imap_notify_context **ctx);
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
369847496787678ee18608754a97f0c2df80a36fTimo Sirainenvoid imap_notify_flush(struct imap_notify_context *ctx);
369847496787678ee18608754a97f0c2df80a36fTimo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen#endif