Teaching an old dog new tricks
No Matches
account.c File Reference

A group of associated Mailboxes. More...

#include "config.h"
#include <stddef.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "account.h"
#include "mailbox.h"
#include "neomutt.h"
+ Include dependency graph for account.c:

Go to the source code of this file.


struct Accountaccount_new (const char *name, struct ConfigSubset *sub)
 Create a new Account.
bool account_mailbox_add (struct Account *a, struct Mailbox *m)
 Add a Mailbox to an Account.
bool account_mailbox_remove (struct Account *a, struct Mailbox *m)
 Remove a Mailbox from an Account.
void account_free (struct Account **ptr)
 Free an Account.

Detailed Description

A group of associated Mailboxes.

  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see

Definition in file account.c.

Function Documentation

◆ account_new()

struct Account * account_new ( const char *  name,
struct ConfigSubset sub 

Create a new Account.

nameName for the Account
subParent Config Subset
Return values
ptrNew Account

Definition at line 43 of file account.c.

45 if (!sub)
46 return NULL;
48 struct Account *a = mutt_mem_calloc(1, sizeof(struct Account));
51 a->notify = notify_new();
53 a->sub = cs_subset_new(name, sub, a->notify);
54 a->sub->cs = sub->cs;
57 return a;
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:62
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
#define STAILQ_INIT(head)
Definition: queue.h:372
A group of associated Mailboxes.
Definition: account.h:37
char * name
Name of Account.
Definition: account.h:39
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
struct ConfigSubset * cs_subset_new(const char *name, struct ConfigSubset *sub_parent, struct Notify *not_parent)
Create a new Config Subset.
Definition: subset.c:143
This Config is Account-specific.
Definition: subset.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ account_mailbox_add()

bool account_mailbox_add ( struct Account a,
struct Mailbox m 

Add a Mailbox to an Account.

mMailbox to add
Return values
trueMailbox was added

Definition at line 66 of file account.c.

68 if (!a || !m)
69 return false;
71 if (a->type == MUTT_UNKNOWN)
72 a->type = m->type;
74 m->account = a;
75 struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
76 np->mailbox = m;
77 STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
81 mutt_debug(LL_NOTIFY, "NT_MAILBOX_ADD: %s %p\n",
82 mailbox_get_type_name(m->type), (void *) m);
83 struct EventMailbox ev_m = { m };
85 return true;
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
Log of notifications.
Definition: logging2.h:48
bool mailbox_set_subset(struct Mailbox *m, struct ConfigSubset *sub)
Set a Mailbox's Config Subset.
Definition: mailbox.c:263
const char * mailbox_get_type_name(enum MailboxType type)
Get the type of a Mailbox.
Definition: mailbox.c:319
Mailbox has been added.
Definition: mailbox.h:169
Mailbox wasn't recognised.
Definition: mailbox.h:44
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:95
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:49
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:389
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
An Event that happened to a Mailbox.
Definition: mailbox.h:186
List of Mailboxes.
Definition: mailbox.h:153
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:154
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:144
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:128
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ account_mailbox_remove()

bool account_mailbox_remove ( struct Account a,
struct Mailbox m 

Remove a Mailbox from an Account.

mMailbox to remove
Return values
trueOn success
If m is NULL, all the mailboxes will be removed and FREE'd. Otherwise, the specified mailbox is removed from the Account but not FREE'd.

Definition at line 97 of file account.c.

99 if (!a || STAILQ_EMPTY(&a->mailboxes))
100 return false;
102 if (!m)
103 {
104 mutt_debug(LL_NOTIFY, "NT_MAILBOX_DELETE_ALL\n");
105 struct EventMailbox ev_m = { NULL };
107 }
109 bool result = false;
110 struct MailboxNode *np = NULL;
111 struct MailboxNode *tmp = NULL;
112 STAILQ_FOREACH_SAFE(np, &a->mailboxes, entries, tmp)
113 {
114 if (m && (np->mailbox != m))
115 continue;
117 STAILQ_REMOVE(&a->mailboxes, np, MailboxNode, entries);
118 if (m)
119 {
120 m->account = NULL;
122 }
123 else
124 {
125 // we make it invisible here to force the deletion of the mailbox
126 np->mailbox->visible = false;
127 mailbox_free(&np->mailbox);
128 }
129 FREE(&np);
130 result = true;
131 if (m)
132 break;
133 }
135 return result;
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:90
All Mailboxes are about to be deleted.
Definition: mailbox.h:171
#define FREE(x)
Definition: memory.h:45
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define STAILQ_EMPTY(head)
Definition: queue.h:348
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:131
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ account_free()

void account_free ( struct Account **  ptr)

Free an Account.

[out]ptrAccount to free

Definition at line 142 of file account.c.

144 if (!ptr || !*ptr)
145 return;
147 struct Account *a = *ptr;
149 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_DELETE: %s %p\n",
150 mailbox_get_type_name(a->type), (void *) a);
151 struct EventAccount ev_a = { a };
154 account_mailbox_remove(a, NULL);
156 if (a->adata && a->adata_free)
157 a->adata_free(&a->adata);
159 cs_subset_free(&a->sub);
160 FREE(&a->name);
161 notify_free(&a->notify);
163 FREE(ptr);
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition: account.c:97
Account is about to be deleted.
Definition: account.h:69
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:75
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:36
void(* adata_free)(void **ptr)
Free the private data attached to the Account.
Definition: account.h:52
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
An Event that happened to an Account.
Definition: account.h:78
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function: