/**
* @file
- * Representation of an account
- *
+ * A group of associated Mailboxes
+
* @authors
* Copyright (C) 2018 Richard Russon <rich@flatcap.org>
*
*/
/**
- * @page account Representation of an account
+ * @page account A group of associated Mailboxes
*
- * Representation of an account
+ * A group of associated Mailboxes
*/
#include "config.h"
#include "mutt/mutt.h"
#include "account.h"
-
-struct AccountList AllAccounts = TAILQ_HEAD_INITIALIZER(AllAccounts);
+#include "neomutt.h"
/**
* account_new - Create a new Account
* account_mailbox_remove - Remove a Mailbox from an Account
* @param a Account
* @param m Mailbox to remove
+ *
+ * @note If m is NULL, all the mailboxes will be removed.
*/
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
{
bool result = false;
struct MailboxNode *np = NULL;
- STAILQ_FOREACH(np, &a->mailboxes, entries)
+ struct MailboxNode *tmp = NULL;
+ STAILQ_FOREACH_SAFE(np, &a->mailboxes, entries, tmp)
{
- if (np->mailbox == m)
+ if (!m || (np->mailbox == m))
{
STAILQ_REMOVE(&a->mailboxes, np, MailboxNode, entries);
+ mailbox_free(&np->mailbox);
+ FREE(&np);
result = true;
- break;
+ if (m)
+ break;
}
}
if (STAILQ_EMPTY(&a->mailboxes))
{
- account_free(&a);
+ neomutt_account_remove(NeoMutt, a);
}
return result;
}
return;
struct Account *a = *ptr;
- if (!TAILQ_EMPTY(&AllAccounts))
- TAILQ_REMOVE(&AllAccounts, a, entries);
+ account_mailbox_remove(a, NULL);
+
if (a->free_adata)
a->free_adata(&a->adata);
/**
* @file
- * Representation of a mailbox
+ * A group of associated Mailboxes
*
* @authors
* Copyright (C) 1996-2000,2010,2013 Michael R. Elkins <me@mutt.org>
#include "mailbox.h"
struct ConnAccount;
+struct Notify;
/**
- * struct Account - XXX
+ * struct Account - A group of associated Mailboxes
*/
struct Account
{
- enum MailboxType magic;
- struct MailboxList mailboxes;
- TAILQ_ENTRY(Account) entries;
- void *adata;
- void (*free_adata)(void **);
+ enum MailboxType magic; ///< Type of Mailboxes this Account contains
+ struct MailboxList mailboxes; ///< List of Mailboxes
+ TAILQ_ENTRY(Account) entries; ///< Linked list of Accounts
+ struct Notify *notify; ///< Notifications handler
+ void *adata; ///< Private data (for Mailbox backends)
+ void (*free_adata)(void **); ///< Callback function to free private data
char *name; ///< Name of Account
const struct ConfigSet *cs; ///< Parent ConfigSet
};
TAILQ_HEAD(AccountList, Account);
-extern struct AccountList AllAccounts; ///< List of all Accounts
-
bool account_add_config(struct Account *a, const struct ConfigSet *cs, const char *name, const char *var_names[]);
void account_free(struct Account **ptr);
void account_free_config(struct Account *a);
#include "mutt_socket.h"
#include "muttlib.h"
#include "mx.h"
+#include "neomutt.h"
#include "pattern.h"
#include "progress.h"
#include "sort.h"
void imap_logout_all(void)
{
struct Account *np = NULL;
- TAILQ_FOREACH(np, &AllAccounts, entries)
+ TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
{
if (np->magic != MUTT_IMAP)
continue;
#include "mailbox.h"
#include "message.h"
#include "mutt_account.h"
+#include "neomutt.h"
#include "options.h"
/* These Config Variables are only used in imap/util.c */
return -1;
struct Account *np = NULL;
- TAILQ_FOREACH(np, &AllAccounts, entries)
+ TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
{
if (np->magic != MUTT_IMAP)
continue;
{
time_t now = time(NULL);
struct Account *np = NULL;
- TAILQ_FOREACH(np, &AllAccounts, entries)
+ TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
{
if (np->magic != MUTT_IMAP)
continue;
#include "mx.h"
#include "myvar.h"
#include "ncrypt/ncrypt.h"
+#include "neomutt.h"
#include "options.h"
#include "protos.h"
#include "sidebar.h"
}
if (new_account)
{
- TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
+ neomutt_account_add(NeoMutt, a);
}
struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
mutt_browser_cleanup();
mutt_free_opts();
mutt_free_keys();
- cs_free(&Config);
neomutt_free(&NeoMutt);
+ cs_free(&Config);
return rc;
}
#include "mutt_thread.h"
#include "muttlib.h"
#include "ncrypt/ncrypt.h"
+#include "neomutt.h"
#include "opcodes.h"
#include "options.h"
#include "pattern.h"
}
if (new_account)
{
- TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
+ neomutt_account_add(NeoMutt, a);
}
}
return NULL;
struct Account *np = NULL;
- TAILQ_FOREACH(np, &AllAccounts, entries)
+ TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
{
if (np->magic != m->magic)
continue;
mx_path_canon(buf, sizeof(buf), C_Folder, NULL);
struct Account *np = NULL;
- TAILQ_FOREACH(np, &AllAccounts, entries)
+ TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
{
struct Mailbox *m = mx_mbox_find(np, buf);
if (m)
#include "config.h"
#include "mutt/mutt.h"
#include "neomutt.h"
+#include "account.h"
struct NeoMutt *NeoMutt; ///< Global NeoMutt object
{
struct NeoMutt *n = mutt_mem_calloc(1, sizeof(*NeoMutt));
+ TAILQ_INIT(&n->accounts);
n->notify = notify_new(n, NT_NEOMUTT);
return n;
struct NeoMutt *n = *ptr;
+ neomutt_account_remove(n, NULL);
notify_free(&n->notify);
FREE(ptr);
}
+
+/**
+ * neomutt_account_add - Add an Account to the global list
+ * @param n NeoMutt
+ * @param a Account to add
+ * @retval true If Account was added
+ */
+bool neomutt_account_add(struct NeoMutt *n, struct Account *a)
+{
+ if (!n || !a)
+ return false;
+
+ TAILQ_INSERT_TAIL(&n->accounts, a, entries);
+ notify_set_parent(a->notify, n->notify);
+
+ return true;
+}
+
+/**
+ * neomutt_account_remove - Remove an Account from the global list
+ * @param n NeoMutt
+ * @param a Account to remove
+ * @retval true If Account was removed
+ *
+ * @note If a is NULL, all the Accounts will be removed
+ */
+bool neomutt_account_remove(struct NeoMutt *n, struct Account *a)
+{
+ if (!n)
+ return false;
+
+ bool result = false;
+ struct Account *np = NULL;
+ struct Account *tmp = NULL;
+ TAILQ_FOREACH_SAFE(np, &n->accounts, entries, tmp)
+ {
+ if (!a || (np == a))
+ {
+ TAILQ_REMOVE(&n->accounts, np, entries);
+ account_free(&np);
+ result = true;
+ if (a)
+ break;
+ }
+ }
+ return result;
+}
#ifndef MUTT_NEOMUTT_H
#define MUTT_NEOMUTT_H
+#include <stdbool.h>
+#include "account.h"
+
struct Notify;
/**
struct NeoMutt
{
struct Notify *notify; ///< Notifications handler
+ struct AccountList accounts; ///< List of all Accounts
};
extern struct NeoMutt *NeoMutt;
NT_GLOBAL_TIMEOUT, ///< A timer has elapsed
};
+bool neomutt_account_add(struct NeoMutt *n, struct Account *a);
+bool neomutt_account_remove(struct NeoMutt *n, struct Account *a);
void neomutt_free(struct NeoMutt **ptr);
struct NeoMutt *neomutt_new(void);