NeoMutt  2025-09-05-70-gcfdde0
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
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.

Functions

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.
 
void account_mailbox_remove (struct Account *a, struct Mailbox *m)
 Remove a Mailbox from an Account.
 
void account_mailboxes_free (struct Account *a)
 Free all the Mailboxes on an Account.
 
void account_free (struct Account **ptr)
 Free an Account.
 

Detailed Description

A group of associated Mailboxes.

Authors
  • Richard Russon
  • Pietro Cerutti

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 http://www.gnu.org/licenses/.

Definition in file account.c.

Function Documentation

◆ account_new()

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

Create a new Account.

Parameters
nameName for the Account
subParent Config Subset
Return values
ptrNew Account

Definition at line 44 of file account.c.

45{
46 if (!sub)
47 return NULL;
48
49 struct Account *a = MUTT_MEM_CALLOC(1, struct Account);
50
52 a->notify = notify_new();
54 a->sub = cs_subset_new(name, sub, a->notify);
55 a->sub->cs = sub->cs;
57
58 return a;
59}
#define ARRAY_INIT(head)
Initialize an array.
Definition array.h:65
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:47
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:255
A group of associated Mailboxes.
Definition account.h:36
char * name
Name of Account.
Definition account.h:38
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition account.h:41
struct MailboxArray mailboxes
All Mailboxes.
Definition account.h:40
struct ConfigSubset * sub
Inherited config items.
Definition account.h:39
struct ConfigSet * cs
Parent ConfigSet.
Definition subset.h:50
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition subset.h:48
struct ConfigSubset * cs_subset_new(const char *name, struct ConfigSubset *sub_parent, struct Notify *not_parent)
Create a new Config Subset.
Definition subset.c:158
@ SET_SCOPE_ACCOUNT
This Config is Account-specific.
Definition subset.h:38
+ 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.

Parameters
aAccount
mMailbox to add
Return values
trueMailbox was added

Definition at line 67 of file account.c.

68{
69 if (!a || !m)
70 return false;
71
72 if (a->type == MUTT_UNKNOWN)
73 a->type = m->type;
74
75 m->account = a;
76 ARRAY_ADD(&a->mailboxes, m);
79
80 mutt_debug(LL_NOTIFY, "NT_MAILBOX_ADD: %s %p\n",
81 mailbox_get_type_name(m->type), (void *) m);
82 struct EventMailbox ev_m = { m };
84 return true;
85}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:156
bool mailbox_set_subset(struct Mailbox *m, struct ConfigSubset *sub)
Set a Mailbox's Config Subset.
Definition mailbox.c:268
const char * mailbox_get_type_name(enum MailboxType type)
Get the type of a Mailbox.
Definition mailbox.c:324
@ NT_MAILBOX_ADD
Mailbox has been added.
Definition mailbox.h:173
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition mailbox.h:44
#define mutt_debug(LEVEL,...)
Definition logging2.h:90
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:49
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
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition notify_type.h:49
enum MailboxType type
Type of Mailboxes this Account contains.
Definition account.h:37
An Event that happened to a Mailbox.
Definition mailbox.h:190
enum MailboxType type
Mailbox type.
Definition mailbox.h:102
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition mailbox.h:145
struct Account * account
Account that owns this Mailbox.
Definition mailbox.h:127
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ account_mailbox_remove()

void account_mailbox_remove ( struct Account * a,
struct Mailbox * m )

Remove a Mailbox from an Account.

Parameters
aAccount
mMailbox to remove
Note
The mailbox is removed from the Account but not FREE'd

Definition at line 94 of file account.c.

95{
96 if (!a || !m || ARRAY_EMPTY(&a->mailboxes))
97 return;
98
99 struct Mailbox **mp = NULL;
100 ARRAY_FOREACH(mp, &a->mailboxes)
101 {
102 if (*mp != m)
103 continue;
104
105 ARRAY_REMOVE(&a->mailboxes, mp);
106
107 m->account = NULL;
109 break;
110 }
111}
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:323
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:214
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
A mailbox.
Definition mailbox.h:79
Container for Accounts, Notifications.
Definition neomutt.h:42
struct Notify * notify
Notifications handler.
Definition neomutt.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ account_mailboxes_free()

void account_mailboxes_free ( struct Account * a)

Free all the Mailboxes on an Account.

Parameters
aAccount

All the Mailboxes will be removed and FREE'd.

Definition at line 119 of file account.c.

120{
121 if (!a)
122 return;
123
124 if (!ARRAY_EMPTY(&a->mailboxes))
125 {
126 mutt_debug(LL_NOTIFY, "NT_MAILBOX_DELETE_ALL\n");
127 struct EventMailbox ev_m = { NULL };
129
130 struct Mailbox **mp = NULL;
131 ARRAY_FOREACH(mp, &a->mailboxes)
132 {
133 struct Mailbox *m = *mp;
134
135 // we make it invisible here to force the deletion of the mailbox
136 m->visible = false;
137 mailbox_free(&m);
138 }
139 }
140
142}
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:204
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition mailbox.c:89
@ NT_MAILBOX_DELETE_ALL
All Mailboxes are about to be deleted.
Definition mailbox.h:175
bool visible
True if a result of "mailboxes".
Definition mailbox.h:130
+ 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.

Parameters
[out]ptrAccount to free

Definition at line 148 of file account.c.

149{
150 if (!ptr || !*ptr)
151 return;
152
153 struct Account *a = *ptr;
154
155 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_DELETE: %s %p\n",
156 mailbox_get_type_name(a->type), (void *) a);
157 struct EventAccount ev_a = { a };
159
161
162 if (a->adata && a->adata_free)
163 a->adata_free(&a->adata);
164
165 cs_subset_free(&a->sub);
166 FREE(&a->name);
167 notify_free(&a->notify);
168
169 FREE(ptr);
170}
void account_mailboxes_free(struct Account *a)
Free all the Mailboxes on an Account.
Definition account.c:119
@ NT_ACCOUNT_DELETE
Account is about to be deleted.
Definition account.h:68
#define FREE(x)
Definition memory.h:62
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
@ NT_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition notify_type.h:36
void(* adata_free)(void **ptr)
Definition account.h:53
void * adata
Private data (for Mailbox backends)
Definition account.h:42
An Event that happened to an Account.
Definition account.h:77
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition subset.c:112
+ Here is the call graph for this function:
+ Here is the caller graph for this function: