NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
account.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stddef.h>
32#include "mutt/lib.h"
33#include "config/lib.h"
34#include "account.h"
35#include "mailbox.h"
36#include "neomutt.h"
37
44struct Account *account_new(const char *name, struct ConfigSubset *sub)
45{
46 if (!sub)
47 return NULL;
48
49 struct Account *a = mutt_mem_calloc(1, sizeof(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}
60
67bool account_mailbox_add(struct Account *a, struct Mailbox *m)
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 struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
77 np->mailbox = m;
78 STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
81
82 mutt_debug(LL_NOTIFY, "NT_MAILBOX_ADD: %s %p\n",
83 mailbox_get_type_name(m->type), (void *) m);
84 struct EventMailbox ev_m = { m };
86 return true;
87}
88
98bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
99{
100 if (!a || STAILQ_EMPTY(&a->mailboxes))
101 return false;
102
103 if (!m)
104 {
105 mutt_debug(LL_NOTIFY, "NT_MAILBOX_DELETE_ALL\n");
106 struct EventMailbox ev_m = { NULL };
108 }
109
110 bool result = false;
111 struct MailboxNode *np = NULL;
112 struct MailboxNode *tmp = NULL;
113 STAILQ_FOREACH_SAFE(np, &a->mailboxes, entries, tmp)
114 {
115 if (m && (np->mailbox != m))
116 continue;
117
118 STAILQ_REMOVE(&a->mailboxes, np, MailboxNode, entries);
119 if (m)
120 {
121 m->account = NULL;
123 }
124 else
125 {
126 // we make it invisible here to force the deletion of the mailbox
127 np->mailbox->visible = false;
128 mailbox_free(&np->mailbox);
129 }
130 FREE(&np);
131 result = true;
132 if (m)
133 break;
134 }
135
136 return result;
137}
138
143void account_free(struct Account **ptr)
144{
145 if (!ptr || !*ptr)
146 return;
147
148 struct Account *a = *ptr;
149
150 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_DELETE: %s %p\n",
151 mailbox_get_type_name(a->type), (void *) a);
152 struct EventAccount ev_a = { a };
154
155 account_mailbox_remove(a, NULL);
156
157 if (a->adata && a->adata_free)
158 a->adata_free(&a->adata);
159
160 cs_subset_free(&a->sub);
161 FREE(&a->name);
162 notify_free(&a->notify);
163
164 FREE(ptr);
165}
Convenience wrapper for the config headers.
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition: account.c:98
struct Account * account_new(const char *name, struct ConfigSubset *sub)
Create a new Account.
Definition: account.c:44
bool account_mailbox_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account.
Definition: account.c:67
void account_free(struct Account **ptr)
Free an Account.
Definition: account.c:143
@ NT_ACCOUNT_DELETE
Account is about to be deleted.
Definition: account.h:70
bool mailbox_set_subset(struct Mailbox *m, struct ConfigSubset *sub)
Set a Mailbox's Config Subset.
Definition: mailbox.c:270
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:89
const char * mailbox_get_type_name(enum MailboxType type)
Get the type of a Mailbox.
Definition: mailbox.c:326
@ NT_MAILBOX_DELETE_ALL
All Mailboxes are about to be deleted.
Definition: mailbox.h:184
@ NT_MAILBOX_ADD
Mailbox has been added.
Definition: mailbox.h:182
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
Maildir Account.
Maildir Mailbox.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
#define FREE(x)
Definition: memory.h:45
Convenience wrapper for the library headers.
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:62
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
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:75
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
Container for Accounts, Notifications.
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:49
@ NT_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:36
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define STAILQ_INIT(head)
Definition: queue.h:372
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:389
#define STAILQ_EMPTY(head)
Definition: queue.h:348
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
A group of associated Mailboxes.
Definition: account.h:36
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:37
char * name
Name of Account.
Definition: account.h:38
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:41
void(* adata_free)(void **ptr)
Definition: account.h:53
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:39
void * adata
Private data (for Mailbox backends)
Definition: account.h:42
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:40
A set of inherited config items.
Definition: subset.h:47
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
An Event that happened to an Account.
Definition: account.h:79
An Event that happened to a Mailbox.
Definition: mailbox.h:199
List of Mailboxes.
Definition: mailbox.h:166
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:167
A mailbox.
Definition: mailbox.h:79
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
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:130
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct Notify * notify
Notifications handler.
Definition: neomutt.h:43
struct ConfigSubset * cs_subset_new(const char *name, struct ConfigSubset *sub_parent, struct Notify *not_parent)
Create a new Config Subset.
Definition: subset.c:152
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:108
@ SET_SCOPE_ACCOUNT
This Config is Account-specific.
Definition: subset.h:39