NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
account.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stddef.h>
31 #include "mutt/lib.h"
32 #include "config/lib.h"
33 #include "core/neomutt.h"
34 #include "account.h"
35 #include "mailbox.h"
36 
43 struct Account *account_new(const char *name, struct ConfigSubset *sub)
44 {
45  if (!sub)
46  return NULL;
47 
48  struct Account *a = mutt_mem_calloc(1, sizeof(struct Account));
49 
51  a->notify = notify_new();
52  a->name = mutt_str_dup(name);
53  a->sub = cs_subset_new(name, sub, a->notify);
54  a->sub->cs = sub->cs;
56 
57  return a;
58 }
59 
66 bool account_mailbox_add(struct Account *a, struct Mailbox *m)
67 {
68  if (!a || !m)
69  return false;
70 
71  if (a->type == MUTT_UNKNOWN)
72  a->type = m->type;
73 
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);
78  mailbox_set_subset(m, a->sub);
80 
81  struct EventMailbox ev_m = { m };
83  return true;
84 }
85 
94 bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
95 {
96  if (!a)
97  return false;
98 
99  bool result = false;
100  struct MailboxNode *np = NULL;
101  struct MailboxNode *tmp = NULL;
102  STAILQ_FOREACH_SAFE(np, &a->mailboxes, entries, tmp)
103  {
104  if (!m || (np->mailbox == m))
105  {
106  struct EventMailbox ev_m = { m };
108  STAILQ_REMOVE(&a->mailboxes, np, MailboxNode, entries);
109  if (!m)
110  mailbox_free(&np->mailbox);
111  FREE(&np);
112  result = true;
113  if (m)
114  break;
115  }
116  }
117 
118  return result;
119 }
120 
125 void account_free(struct Account **ptr)
126 {
127  if (!ptr || !*ptr)
128  return;
129 
130  struct Account *a = *ptr;
131 
132  if (a->adata_free)
133  a->adata_free(&a->adata);
134 
135  account_mailbox_remove(a, NULL);
136  cs_subset_free(&a->sub);
137  FREE(&a->name);
138  notify_free(&a->notify);
139 
140  FREE(ptr);
141 }
STAILQ_INIT
#define STAILQ_INIT(head)
Definition: queue.h:369
MailboxNode
List of Mailboxes.
Definition: mailbox.h:152
mutt_mem_calloc
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
NT_MAILBOX_REMOVE
@ NT_MAILBOX_REMOVE
A Mailbox is about to be destroyed.
Definition: mailbox.h:167
Mailbox
A mailbox.
Definition: mailbox.h:81
Account::type
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
account.h
STAILQ_REMOVE
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
Mailbox::notify
struct Notify * notify
Notifications handler.
Definition: mailbox.h:144
Account::name
char * name
Name of Account.
Definition: account.h:39
mutt_str_dup
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
FREE
#define FREE(x)
Definition: memory.h:40
MailboxNode::mailbox
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:154
mailbox.h
mailbox_free
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:71
notify_send
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:152
Account::adata_free
void(* adata_free)(void **ptr)
Free the private data attached to the Account.
Definition: account.h:49
notify_new
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
EventMailbox
An Event that happened to a Mailbox.
Definition: mailbox.h:183
lib.h
cs_subset_free
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:93
NT_MAILBOX
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:42
Mailbox::type
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
account_free
void account_free(struct Account **ptr)
Free an Account.
Definition: account.c:125
lib.h
Account
A group of associated Mailboxes.
Definition: account.h:36
Mailbox::account
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
Account::mailboxes
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
ConfigSubset::cs
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
MUTT_UNKNOWN
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:47
neomutt.h
SET_SCOPE_ACCOUNT
@ SET_SCOPE_ACCOUNT
This Config is Account-specific.
Definition: subset.h:39
cs_subset_new
struct ConfigSubset * cs_subset_new(const char *name, struct ConfigSubset *sub_parent, struct Notify *not_parent)
Create a new Config Subset.
Definition: subset.c:133
STAILQ_FOREACH_SAFE
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
account_new
struct Account * account_new(const char *name, struct ConfigSubset *sub)
Create a new Account.
Definition: account.c:43
NT_MAILBOX_ADD
@ NT_MAILBOX_ADD
A new Mailbox has been created.
Definition: mailbox.h:166
STAILQ_INSERT_TAIL
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:386
account_mailbox_add
bool account_mailbox_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account.
Definition: account.c:66
notify_free
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
Account::adata
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
ConfigSubset::scope
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
notify_set_parent
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
account_mailbox_remove
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition: account.c:94
ConfigSubset
A set of inherited config items.
Definition: subset.h:46
mailbox_set_subset
bool mailbox_set_subset(struct Mailbox *m, struct ConfigSubset *sub)
Set a Mailbox's Config Subset.
Definition: mailbox.c:221
Account::notify
struct Notify * notify
Notifications handler.
Definition: account.h:42
Account::sub
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40