#include "mutt_window.h"
#include "muttlib.h"
#include "mx.h"
+#include "neomutt.h"
#include "opcodes.h"
#include "options.h"
#include "sendlib.h"
else if (!S_ISREG(s.st_mode))
continue;
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ STAILQ_FOREACH(np, &ml, entries)
{
if (mutt_str_strcmp(mutt_b2s(buf), mutt_b2s(np->mailbox->pathbuf)) != 0)
break;
}
+ neomutt_mailboxlist_clear(&ml);
if (np && Context && Context->mailbox &&
(mutt_str_strcmp(np->mailbox->realpath, Context->mailbox->realpath) == 0))
{
init_state(state, menu);
- if (STAILQ_EMPTY(&AllMailboxes))
+ if (TAILQ_EMPTY(&NeoMutt->accounts))
return -1;
mailbox = mutt_buffer_pool_get();
md = mutt_buffer_pool_get();
mutt_mailbox_check(Context ? Context->mailbox : NULL, 0);
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ STAILQ_FOREACH(np, &ml, entries)
{
if (Context && (mutt_str_strcmp(np->mailbox->realpath, Context->mailbox->realpath) == 0))
{
add_folder(menu, state, mutt_b2s(mailbox), np->mailbox->desc, &s, np->mailbox, NULL);
}
+ neomutt_mailboxlist_clear(&ml);
}
browser_sort(state);
int nentry = menu->current;
// TODO(sileht): It could be better to select INBOX instead. But I
- // don't want to manipulate Context/AllMailboxes/mailbox->account here for now.
+ // don't want to manipulate Context/Mailboxes/mailbox->account here for now.
// Let's just protect neomutt against crash for now. #1417
if (mutt_str_strcmp(mutt_b2s(Context->mailbox->pathbuf),
state.entry[nentry].name) == 0)
#include "mailbox.h"
#include "mutt_logging.h"
#include "muttlib.h"
+#include "neomutt.h"
/**
* add_folder - Format and add an IMAP folder to the browser
(state->entry)[state->entrylen].selectable = !noselect;
(state->entry)[state->entrylen].inferiors = !noinferiors;
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ STAILQ_FOREACH(np, &ml, entries)
{
if (mutt_str_strcmp(tmp, mutt_b2s(np->mailbox->pathbuf)) == 0)
break;
}
+ neomutt_mailboxlist_clear(&ml);
if (np)
{
C_ImapCheckSubscribed = false;
// Pick first mailbox connected to the same server
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_IMAP);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ STAILQ_FOREACH(np, &ml, entries)
{
- if (np->mailbox->magic != MUTT_IMAP)
- continue;
-
adata = imap_adata_get(np->mailbox);
// Pick first mailbox connected on the same server
if (imap_account_match(&adata->conn_account, &conn_account))
break;
adata = NULL;
}
+ neomutt_mailboxlist_clear(&ml);
if (!adata)
goto fail;
size_t matchlen;
matchlen = mutt_str_strlen(buf);
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ STAILQ_FOREACH(np, &ml, entries)
{
if (!mutt_str_startswith(mutt_b2s(np->mailbox->pathbuf), buf, CASE_MATCH))
continue;
else
longest_common_prefix(buf, mutt_b2s(np->mailbox->pathbuf), matchlen, buflen);
}
+ neomutt_mailboxlist_clear(&ml);
#if 0
TAILQ_FOREACH(conn, mutt_socket_head(), entries)
if (C_VirtualSpoolfile)
{
/* Find the first virtual folder and open it */
- struct MailboxNode *mp = NULL;
- STAILQ_FOREACH(mp, &AllMailboxes, entries)
- {
- if (mp->mailbox->magic == MUTT_NOTMUCH)
- {
- cs_str_string_set(Config, "spoolfile", mutt_b2s(mp->mailbox->pathbuf), NULL);
- break;
- }
- }
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_NOTMUCH);
+ struct MailboxNode *mp = STAILQ_FIRST(&ml);
+ if (mp)
+ cs_str_string_set(Config, "spoolfile", mutt_b2s(mp->mailbox->pathbuf), NULL);
+ neomutt_mailboxlist_clear(&ml);
}
#endif
if (stat(path, &sb) != 0)
return NULL;
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ struct Mailbox *m = NULL;
+ STAILQ_FOREACH(np, &ml, entries)
{
if ((stat(mutt_b2s(np->mailbox->pathbuf), &tmp_sb) == 0) &&
(sb.st_dev == tmp_sb.st_dev) && (sb.st_ino == tmp_sb.st_ino))
{
- return np->mailbox;
+ m = np->mailbox;
+ break;
}
}
+ neomutt_mailboxlist_clear(&ml);
- return NULL;
+ return m;
}
/**
if (!desc)
return NULL;
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ struct Mailbox *m = NULL;
+ STAILQ_FOREACH(np, &ml, entries)
{
if (np->mailbox->desc && (mutt_str_strcmp(np->mailbox->desc, desc) == 0))
- return np->mailbox;
+ {
+ m = np->mailbox;
+ break;
+ }
}
+ neomutt_mailboxlist_clear(&ml);
- return NULL;
+ return m;
}
/**
*/
enum MailboxType
{
- MUTT_MAILBOX_ERROR = -1, ///< Error occurred examining mailbox
+ MUTT_MAILBOX_ANY = -2, ///< Match any Mailbox type
+ MUTT_MAILBOX_ERROR = -1, ///< Error occurred examining Mailbox
MUTT_UNKNOWN = 0, ///< Mailbox wasn't recognised
MUTT_MBOX, ///< 'mbox' Mailbox type
MUTT_MMDF, ///< 'mmdf' Mailbox type
}
else
#endif
- if (STAILQ_EMPTY(&AllMailboxes))
+ if (TAILQ_EMPTY(&NeoMutt->accounts))
{
mutt_error(_("No incoming mailboxes defined"));
goto main_curses; // TEST39: neomutt -n -F /dev/null -y
#include "mutt_window.h"
#include "muttlib.h"
#include "mx.h"
+#include "neomutt.h"
#include "protos.h"
static time_t MailboxTime = 0; /**< last time we started checking for mail */
}
/**
- * mutt_mailbox_check - Check all AllMailboxes for new mail
+ * mutt_mailbox_check - Check all all Mailboxes for new mail
* @param m_cur Current Mailbox
* @param force Force flags, see below
* @retval num Number of mailboxes with new mail
* - MUTT_MAILBOX_CHECK_FORCE ignore MailboxTime and check for new mail
* - MUTT_MAILBOX_CHECK_FORCE_STATS ignore MailboxTime and calculate statistics
*
- * Check all AllMailboxes for new mail and total/new/flagged messages
+ * Check all all Mailboxes for new mail and total/new/flagged messages
*/
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
{
#endif
/* fastest return if there are no mailboxes */
- if (STAILQ_EMPTY(&AllMailboxes))
+ if (TAILQ_EMPTY(&NeoMutt->accounts))
return 0;
t = time(NULL);
contex_sb.st_ino = 0;
}
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ STAILQ_FOREACH(np, &ml, entries)
{
mailbox_check(m_cur, np->mailbox, &contex_sb,
check_stats || (!np->mailbox->first_check_stats_done && C_MailCheckStats));
np->mailbox->first_check_stats_done = true;
}
+ neomutt_mailboxlist_clear(&ml);
return MailboxCount;
}
mailboxlist[0] = '\0';
pos += strlen(strncat(mailboxlist, _("New mail in "), sizeof(mailboxlist) - 1 - pos));
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ STAILQ_FOREACH(np, &ml, entries)
{
/* Is there new mail in this mailbox? */
if (!np->mailbox->has_new || (have_unnotified && np->mailbox->notified))
pos += strlen(strncat(mailboxlist + pos, mutt_b2s(path), sizeof(mailboxlist) - 1 - pos));
first = 0;
}
+ neomutt_mailboxlist_clear(&ml);
if (!first && np)
{
bool found = false;
for (int pass = 0; pass < 2; pass++)
{
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ STAILQ_FOREACH(np, &ml, entries)
{
if (np->mailbox->magic == MUTT_NOTMUCH) /* only match real mailboxes */
continue;
if (mutt_str_strcmp(mutt_b2s(s), mutt_b2s(np->mailbox->pathbuf)) == 0)
found = true;
}
+ neomutt_mailboxlist_clear(&ml);
}
mutt_mailbox_check(m_cur, MUTT_MAILBOX_CHECK_FORCE); /* mailbox was wrong - resync things */
}
return result;
}
+
+/**
+ * neomutt_mailboxlist_clear - Free a Mailbox List
+ * @param ml Mailbox List to free
+ */
+void neomutt_mailboxlist_clear(struct MailboxList *ml)
+{
+ if (!ml)
+ return;
+
+ struct MailboxNode *mn = NULL;
+ struct MailboxNode *tmp = NULL;
+ STAILQ_FOREACH_SAFE(mn, ml, entries, tmp)
+ {
+ STAILQ_REMOVE(ml, mn, MailboxNode, entries);
+ FREE(&mn);
+ }
+}
+
+/**
+ * neomutt_mailboxlist_get_all - Get a List of all Mailboxes
+ * @param n NeoMutt
+ * @param type Type of Account to match, see #MailboxType
+ * @retval obj List of Mailboxes
+ *
+ * @note If type is #MUTT_MAILBOX_ANY then all Mailbox types will be matched
+ */
+struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType magic)
+{
+ struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
+ if (!n)
+ return ml;
+
+ struct Account *a = NULL;
+ struct MailboxNode *mn = NULL;
+
+ TAILQ_FOREACH(a, &n->accounts, entries)
+ {
+ if ((magic > MUTT_UNKNOWN) && (a->magic != magic))
+ continue;
+
+ STAILQ_FOREACH(mn, &a->mailboxes, entries)
+ {
+ struct MailboxNode *mn2 = mutt_mem_calloc(1, sizeof(*mn2));
+ mn2->mailbox = mn->mailbox;
+ STAILQ_INSERT_TAIL(&ml, mn2, entries);
+ }
+ }
+
+ return ml;
+}
void neomutt_free(struct NeoMutt **ptr);
struct NeoMutt *neomutt_new(void);
+void neomutt_mailboxlist_clear(struct MailboxList *ml);
+struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType magic);
+
#endif /* MUTT_NEOMUTT_H */
#include "mutt_window.h"
#include "muttlib.h"
#include "mx.h"
+#include "neomutt.h"
#include "opcodes.h"
#include "sort.h"
{
int i = 0;
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ STAILQ_FOREACH(np, &ml, entries)
{
if (i >= EntryCount)
break;
i++;
}
}
+ neomutt_mailboxlist_clear(&ml);
}
/**
*
* Display a list of mailboxes in a panel on the left. What's displayed will
* depend on our index markers: TopMailbox, OpnMailbox, HilMailbox, BotMailbox.
- * On the first run they'll be NULL, so we display the top of NeoMutt's list
- * (AllMailboxes).
+ * On the first run they'll be NULL, so we display the top of NeoMutt's list.
*
* * TopMailbox - first visible mailbox
* * BotMailbox - last visible mailbox
if (!Entries)
{
+ struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &AllMailboxes, entries)
+ STAILQ_FOREACH(np, &ml, entries)
{
mutt_sb_notify_mailbox(np->mailbox, true);
}
+ neomutt_mailboxlist_clear(&ml);
}
if (!prepare_sidebar(num_rows))