This function has dependencies on Context and inotify().
- More sophisticated check for BDB version + support for DB6 (non default)
* Tidy
- drop VirtIncoming
- - split mutt_parse_mailboxes into mutt_parse_unmailboxes
+ - split parse_mailboxes into parse_unmailboxes
- tidy some mailbox code
- tidy the version strings
* Upstream
#include "email/lib.h"
#include "mutt.h"
#include "init.h"
+#include "account.h"
#include "alias.h"
#include "context.h"
#include "filter.h"
#include "hcache/hcache.h"
#include "keymap.h"
+#include "monitor.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
#include "mutt_window.h"
return MUTT_CMD_ERROR;
}
+/**
+ * parse_mailboxes - Parse the 'mailboxes' command - Implements ::command_t
+ *
+ * This is also used by 'virtual-mailboxes'.
+ */
+static enum CommandResult parse_mailboxes(struct Buffer *buf, struct Buffer *s,
+ unsigned long data, struct Buffer *err)
+{
+ while (MoreArgs(s))
+ {
+ struct Mailbox *m = mailbox_new();
+
+ if (data & MUTT_NAMED)
+ {
+ mutt_extract_token(buf, s, 0);
+ if (buf->data && *buf->data)
+ {
+ m->desc = mutt_str_strdup(buf->data);
+ }
+ else
+ {
+ mailbox_free(&m);
+ continue;
+ }
+ }
+
+ mutt_extract_token(buf, s, 0);
+ if (mutt_buffer_is_empty(buf))
+ {
+ /* Skip empty tokens. */
+ mailbox_free(&m);
+ continue;
+ }
+
+ mutt_str_strfcpy(m->path, buf->data, sizeof(m->path));
+ /* int rc = */ mx_path_canon2(m, Folder);
+
+ bool new_account = false;
+ struct Account *a = mx_ac_find(m);
+ if (!a)
+ {
+ a = account_new();
+ a->magic = m->magic;
+ TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
+ new_account = true;
+ }
+
+ if (!new_account)
+ {
+ struct Mailbox *old_m = mx_mbox_find(a, m->realpath);
+ if (old_m)
+ {
+ if (old_m->flags == MB_HIDDEN)
+ {
+ old_m->flags = MB_NORMAL;
+ mutt_sb_notify_mailbox(old_m, true);
+ struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
+ mn->m = old_m;
+ STAILQ_INSERT_TAIL(&AllMailboxes, mn, entries);
+ }
+ mailbox_free(&m);
+ continue;
+ }
+ }
+
+ if (mx_ac_add(a, m) < 0)
+ {
+ //error
+ mailbox_free(&m);
+ continue;
+ }
+
+ struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
+ mn->m = m;
+ STAILQ_INSERT_TAIL(&AllMailboxes, mn, entries);
+
+#ifdef USE_SIDEBAR
+ mutt_sb_notify_mailbox(m, true);
+#endif
+#ifdef USE_INOTIFY
+ mutt_monitor_add(m);
+#endif
+ }
+ return MUTT_CMD_SUCCESS;
+}
+
/**
* parse_my_hdr - Parse the 'my_hdr' command - Implements ::command_t
*/
return MUTT_CMD_SUCCESS;
}
+/**
+ * parse_unmailboxes - Parse the 'unmailboxes' command - Implements ::command_t
+ *
+ * This is also used by 'unvirtual-mailboxes'
+ */
+static enum CommandResult parse_unmailboxes(struct Buffer *buf, struct Buffer *s,
+ unsigned long data, struct Buffer *err)
+{
+ char tmp[PATH_MAX];
+ bool tmp_valid = false;
+ bool clear_all = false;
+
+ while (!clear_all && MoreArgs(s))
+ {
+ mutt_extract_token(buf, s, 0);
+
+ if (mutt_str_strcmp(buf->data, "*") == 0)
+ {
+ clear_all = true;
+ tmp_valid = false;
+ }
+ else
+ {
+ mutt_str_strfcpy(tmp, buf->data, sizeof(tmp));
+ mutt_expand_path(tmp, sizeof(tmp));
+ tmp_valid = true;
+ }
+
+ struct MailboxNode *np = NULL;
+ struct MailboxNode *nptmp = NULL;
+ STAILQ_FOREACH_SAFE(np, &AllMailboxes, entries, nptmp)
+ {
+ /* Decide whether to delete all normal mailboxes or all virtual */
+ bool virt = ((np->m->magic == MUTT_NOTMUCH) && (data & MUTT_VIRTUAL));
+ bool norm = ((np->m->magic != MUTT_NOTMUCH) && !(data & MUTT_VIRTUAL));
+ bool clear_this = clear_all && (virt || norm);
+
+ /* Compare against path or desc? Ensure 'tmp' is valid */
+ if (!clear_this && tmp_valid)
+ {
+ clear_this = (mutt_str_strcasecmp(tmp, np->m->path) == 0) ||
+ (mutt_str_strcasecmp(tmp, np->m->desc) == 0);
+ }
+
+ if (clear_this)
+ {
+#ifdef USE_SIDEBAR
+ mutt_sb_notify_mailbox(np->m, false);
+#endif
+#ifdef USE_INOTIFY
+ mutt_monitor_remove(np->m);
+#endif
+ if (Context && (Context->mailbox == np->m))
+ {
+ np->m->flags |= MB_HIDDEN;
+ }
+ else
+ {
+ mx_ac_remove(np->m);
+ mailbox_free(&np->m);
+ }
+ STAILQ_REMOVE(&AllMailboxes, np, MailboxNode, entries);
+ FREE(&np);
+ continue;
+ }
+ }
+ }
+ return MUTT_CMD_SUCCESS;
+}
+
/**
* parse_unmy_hdr - Parse the 'unmy_hdr' command - Implements ::command_t
*/
MUTT_SET_RESET, ///< default is to reset all vars to default
};
+/* parameter to parse_mailboxes */
+#define MUTT_NAMED (1 << 0)
+#define MUTT_VIRTUAL (1 << 1)
+
#define UL (unsigned long)
#define IP (intptr_t)
#endif /* _MAKEDOC */
static enum CommandResult parse_ifdef (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
static enum CommandResult parse_ignore (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
static enum CommandResult parse_lists (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
+static enum CommandResult parse_mailboxes (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
static enum CommandResult parse_my_hdr (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
#ifdef USE_SIDEBAR
static enum CommandResult parse_path_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
static enum CommandResult parse_unattachments (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
static enum CommandResult parse_unignore (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
static enum CommandResult parse_unlists (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
+static enum CommandResult parse_unmailboxes (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
static enum CommandResult parse_unmy_hdr (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
static enum CommandResult parse_unreplace_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
static enum CommandResult parse_unstailq (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
{ "lua-source", mutt_lua_source_file, 0 },
#endif
{ "macro", mutt_parse_macro, 0 },
- { "mailboxes", mutt_parse_mailboxes, 0 },
+ { "mailboxes", parse_mailboxes, 0 },
{ "mailto_allow", parse_stailq, UL &MailToAllow },
{ "mbox-hook", mutt_parse_hook, MUTT_MBOX_HOOK },
{ "message-hook", mutt_parse_hook, MUTT_MESSAGE_HOOK },
{ "mime_lookup", parse_stailq, UL &MimeLookupList },
{ "mono", mutt_parse_mono, 0 },
{ "my_hdr", parse_my_hdr, 0 },
- { "named-mailboxes", mutt_parse_mailboxes, MUTT_NAMED },
+ { "named-mailboxes", parse_mailboxes, MUTT_NAMED },
{ "nospam", parse_spam_list, MUTT_NOSPAM },
#ifdef USE_COMPRESSED
{ "open-hook", mutt_parse_hook, MUTT_OPEN_HOOK },
{ "unhook", mutt_parse_unhook, 0 },
{ "unignore", parse_unignore, 0 },
{ "unlists", parse_unlists, 0 },
- { "unmailboxes", mutt_parse_unmailboxes, 0 },
+ { "unmailboxes", parse_unmailboxes, 0 },
{ "unmailto_allow", parse_unstailq, UL &MailToAllow },
{ "unmime_lookup", parse_unstailq, UL &MimeLookupList },
{ "unmono", mutt_parse_unmono, 0 },
{ "unsubscribe-from", parse_unsubscribe_from, 0 },
#endif
#ifdef USE_NOTMUCH
- { "unvirtual-mailboxes", mutt_parse_unmailboxes, MUTT_VIRTUAL },
- { "virtual-mailboxes", mutt_parse_mailboxes, MUTT_VIRTUAL | MUTT_NAMED },
+ { "unvirtual-mailboxes", parse_unmailboxes, MUTT_VIRTUAL },
+ { "virtual-mailboxes", parse_mailboxes, MUTT_VIRTUAL | MUTT_NAMED },
#endif
{ NULL, NULL, 0 },
};
m->size = 0;
}
-/**
- * mutt_parse_mailboxes - Parse the 'mailboxes' command - Implements ::command_t
- *
- * This is also used by 'virtual-mailboxes'.
- */
-enum CommandResult mutt_parse_mailboxes(struct Buffer *buf, struct Buffer *s,
- unsigned long data, struct Buffer *err)
-{
- while (MoreArgs(s))
- {
- struct Mailbox *m = mailbox_new();
-
- if (data & MUTT_NAMED)
- {
- mutt_extract_token(buf, s, 0);
- if (buf->data && *buf->data)
- {
- m->desc = mutt_str_strdup(buf->data);
- }
- else
- {
- mailbox_free(&m);
- continue;
- }
- }
-
- mutt_extract_token(buf, s, 0);
- if (mutt_buffer_is_empty(buf))
- {
- /* Skip empty tokens. */
- mailbox_free(&m);
- continue;
- }
-
- mutt_str_strfcpy(m->path, buf->data, sizeof(m->path));
- /* int rc = */ mx_path_canon2(m, Folder);
-
- bool new_account = false;
- struct Account *a = mx_ac_find(m);
- if (!a)
- {
- a = account_new();
- a->magic = m->magic;
- TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
- new_account = true;
- }
-
- if (!new_account)
- {
- struct Mailbox *old_m = mx_mbox_find(a, m->realpath);
- if (old_m)
- {
- if (old_m->flags == MB_HIDDEN)
- {
- old_m->flags = MB_NORMAL;
- mutt_sb_notify_mailbox(old_m, true);
- struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
- mn->m = old_m;
- STAILQ_INSERT_TAIL(&AllMailboxes, mn, entries);
- }
- mailbox_free(&m);
- continue;
- }
- }
-
- if (mx_ac_add(a, m) < 0)
- {
- //error
- mailbox_free(&m);
- continue;
- }
-
- struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
- mn->m = m;
- STAILQ_INSERT_TAIL(&AllMailboxes, mn, entries);
-
-#ifdef USE_SIDEBAR
- mutt_sb_notify_mailbox(m, true);
-#endif
-#ifdef USE_INOTIFY
- mutt_monitor_add(m);
-#endif
- }
- return MUTT_CMD_SUCCESS;
-}
-
-/**
- * mutt_parse_unmailboxes - Parse the 'unmailboxes' command - Implements ::command_t
- *
- * This is also used by 'unvirtual-mailboxes'
- */
-enum CommandResult mutt_parse_unmailboxes(struct Buffer *buf, struct Buffer *s,
- unsigned long data, struct Buffer *err)
-{
- char tmp[PATH_MAX];
- bool tmp_valid = false;
- bool clear_all = false;
-
- while (!clear_all && MoreArgs(s))
- {
- mutt_extract_token(buf, s, 0);
-
- if (mutt_str_strcmp(buf->data, "*") == 0)
- {
- clear_all = true;
- tmp_valid = false;
- }
- else
- {
- mutt_str_strfcpy(tmp, buf->data, sizeof(tmp));
- mutt_expand_path(tmp, sizeof(tmp));
- tmp_valid = true;
- }
-
- struct MailboxNode *np = NULL;
- struct MailboxNode *nptmp = NULL;
- STAILQ_FOREACH_SAFE(np, &AllMailboxes, entries, nptmp)
- {
- /* Decide whether to delete all normal mailboxes or all virtual */
- bool virt = ((np->m->magic == MUTT_NOTMUCH) && (data & MUTT_VIRTUAL));
- bool norm = ((np->m->magic != MUTT_NOTMUCH) && !(data & MUTT_VIRTUAL));
- bool clear_this = clear_all && (virt || norm);
-
- /* Compare against path or desc? Ensure 'tmp' is valid */
- if (!clear_this && tmp_valid)
- {
- clear_this = (mutt_str_strcasecmp(tmp, np->m->path) == 0) ||
- (mutt_str_strcasecmp(tmp, np->m->desc) == 0);
- }
-
- if (clear_this)
- {
-#ifdef USE_SIDEBAR
- mutt_sb_notify_mailbox(np->m, false);
-#endif
-#ifdef USE_INOTIFY
- mutt_monitor_remove(np->m);
-#endif
- if (Context && (Context->mailbox == np->m))
- {
- np->m->flags |= MB_HIDDEN;
- }
- else
- {
- mx_ac_remove(np->m);
- mailbox_free(&np->m);
- }
- STAILQ_REMOVE(&AllMailboxes, np, MailboxNode, entries);
- FREE(&np);
- continue;
- }
- }
- }
- return MUTT_CMD_SUCCESS;
-}
-
/**
* mutt_mailbox_check - Check all AllMailboxes for new mail
* @param m_cur Current Mailbox
extern short MailCheckStatsInterval;
extern bool MaildirCheckCur;
-/* parameter to mutt_parse_mailboxes */
-#define MUTT_NAMED (1 << 0)
-#define MUTT_VIRTUAL (1 << 1)
-
#define MB_NORMAL 0
#define MB_HIDDEN 1
bool mutt_mailbox_list(void);
int mutt_mailbox_check(struct Mailbox *m_cur, int force);
bool mutt_mailbox_notify(struct Mailbox *m_cur);
-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 */