mailbox_free(&(*ctx)->mailbox);
FREE(ctx);
}
+
+/**
+ * mutt_mailbox_changed - Notify listeners of a change to a Mailbox
+ * @param m Mailbox
+ * @param action Change to Mailbox
+ */
+void mutt_mailbox_changed(struct Mailbox *m, enum MailboxNotification action)
+{
+ if (!m || !m->notify)
+ return;
+
+ m->notify(m, action);
+}
#define MB_NORMAL 0
#define MB_HIDDEN 1
+/**
+ * enum MailboxNotification - Notifications about changes to a Mailbox
+ */
+enum MailboxNotification
+{
+ MBN_CLOSED = 1, ///< Mailbox was closed
+ MBN_INVALID, ///< Email list was changed
+ MBN_RESORT, ///< Email list needs resorting
+};
+
/**
* enum AclRights - ACL Rights
*
void *mdata; /**< driver specific data */
void (*free_mdata)(void **); /**< driver-specific data free function */
+
+ void (*notify)(struct Mailbox *m, enum MailboxNotification action); ///< Notification callback
+ void *ndata; ///< Notification callback private data
};
/**
bool mutt_mailbox_notify(void);
enum CommandResult mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s, unsigned long data, struct Buffer *err);
enum CommandResult mutt_parse_unmailboxes(struct Buffer *path, struct Buffer *s, unsigned long data, struct Buffer *err);
+void mutt_mailbox_changed(struct Mailbox *m, enum MailboxNotification action);
#endif /* MUTT_MAILBOX_H */
return rc;
}
+/**
+ * mx_mailbox_changed - Act on a Mailbox change notification
+ * @param m Mailbox
+ * @param action Event occurring
+ * @param ndata Private notification data
+ */
+void mx_mailbox_changed(struct Mailbox *m, enum MailboxNotification action)
+{
+ if (!m || !m->ndata)
+ return;
+
+ struct Context *ctx = m->ndata;
+
+ switch (action)
+ {
+ case MBN_CLOSED:
+ mutt_clear_threads(ctx);
+ mx_cleanup_context(ctx);
+ break;
+ case MBN_INVALID:
+ mx_update_context(ctx);
+ break;
+ case MBN_RESORT:
+ mx_update_tables(ctx, false);
+ mutt_sort_headers(ctx, true);
+ break;
+ }
+}
+
/**
* mx_mbox_open - Open a mailbox and parse it
* @param m Mailbox to open
/* int rc = */ mx_path_canon2(m, Folder);
}
+ m->notify = mx_mailbox_changed;
+ m->ndata = ctx;
+
if ((m->magic == MUTT_UNKNOWN) && (flags & MUTT_NEWFOLDER))
{
m->magic = MboxType;