NeoMutt  2020-04-24
Teaching an old dog new tricks
DOXYGEN
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 "core/neomutt.h"
#include "account.h"
#include "mailbox.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. More...
 
bool account_mailbox_add (struct Account *a, struct Mailbox *m)
 Add a Mailbox to an Account. More...
 
bool account_mailbox_remove (struct Account *a, struct Mailbox *m)
 Remove a Mailbox from an Account. More...
 
void account_free (struct Account **ptr)
 Free an Account. More...
 

Detailed Description

A group of associated Mailboxes.

Authors
  • 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 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 43 of file account.c.

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();
54  a->sub = cs_subset_new(name, sub, a->notify);
55  a->sub->cs = sub->cs;
57 
58  return a;
59 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
char * name
Name of Account.
Definition: account.h:39
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
struct Notify * notify
Notifications handler.
Definition: account.h:42
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
A group of associated Mailboxes.
Definition: account.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:35
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
#define STAILQ_INIT(head)
Definition: queue.h:369
const char * name
Definition: pgpmicalg.c:46
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
This Config is Account-specific.
Definition: subset.h:39
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
struct Notify * notify
Notifications handler.
Definition: neomutt.h:37
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
+ 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
trueIf Mailbox 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  struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
77  np->mailbox = m;
78  STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
79  mailbox_set_subset(m, a->sub);
81 
82  struct EventMailbox ev_m = { m };
84  return true;
85 }
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Notify * notify
Notifications handler.
Definition: account.h:42
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:386
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
An Event that happened to a Mailbox.
Definition: mailbox.h:155
A new Mailbox has been created.
Definition: mailbox.h:165
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
bool mailbox_set_subset(struct Mailbox *m, struct ConfigSubset *sub)
Set a Mailbox&#39;s Config Subset.
Definition: mailbox.c:204
Mailbox has changed.
Definition: notify_type.h:38
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
List of Mailboxes.
Definition: mailbox.h:145
struct Notify * notify
Notifications handler.
Definition: mailbox.h:139
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:147
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:137
+ 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.

Parameters
aAccount
mMailbox to remove
Note
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 95 of file account.c.

96 {
97  if (!a)
98  return false;
99 
100  bool result = false;
101  struct MailboxNode *np = NULL;
102  struct MailboxNode *tmp = NULL;
103  STAILQ_FOREACH_SAFE(np, &a->mailboxes, entries, tmp)
104  {
105  if (!m || (np->mailbox == m))
106  {
107  struct EventMailbox ev_m = { m };
109  STAILQ_REMOVE(&a->mailboxes, np, MailboxNode, entries);
110  if (!m)
111  mailbox_free(&np->mailbox);
112  FREE(&np);
113  result = true;
114  if (m)
115  break;
116  }
117  }
118 
119  return result;
120 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
struct Notify * notify
Notifications handler.
Definition: account.h:42
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
An Event that happened to a Mailbox.
Definition: mailbox.h:155
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:60
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
A Mailbox is about to be destroyed.
Definition: mailbox.h:166
#define FREE(x)
Definition: memory.h:40
Mailbox has changed.
Definition: notify_type.h:38
List of Mailboxes.
Definition: mailbox.h:145
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:147
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:137
+ 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 126 of file account.c.

127 {
128  if (!ptr || !*ptr)
129  return;
130 
131  struct Account *a = *ptr;
132 
133  if (a->free_adata)
134  a->free_adata(&a->adata);
135 
136  account_mailbox_remove(a, NULL);
137  cs_subset_free(&a->sub);
138  FREE(&a->name);
139  notify_free(&a->notify);
140 
141  FREE(ptr);
142 }
char * name
Name of Account.
Definition: account.h:39
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
struct Notify * notify
Notifications handler.
Definition: account.h:42
A group of associated Mailboxes.
Definition: account.h:36
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:93
void(* free_adata)(void **ptr)
Callback function to free private data.
Definition: account.h:44
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition: account.c:95
#define FREE(x)
Definition: memory.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function: