NeoMutt  2020-09-25
Teaching an old dog new tricks
DOXYGEN
neomutt.c File Reference

Container for Accounts, Notifications. More...

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

Go to the source code of this file.

Functions

struct NeoMuttneomutt_new (struct ConfigSet *cs)
 Create the main NeoMutt object. More...
 
void neomutt_free (struct NeoMutt **ptr)
 Free a NeoMutt. More...
 
bool neomutt_account_add (struct NeoMutt *n, struct Account *a)
 Add an Account to the global list. More...
 
bool neomutt_account_remove (struct NeoMutt *n, struct Account *a)
 Remove an Account from the global list. More...
 
void neomutt_mailboxlist_clear (struct MailboxList *ml)
 Free a Mailbox List. More...
 
size_t neomutt_mailboxlist_get_all (struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
 Get a List of all Mailboxes. More...
 

Variables

struct NeoMuttNeoMutt
 Global NeoMutt object. More...
 

Detailed Description

Container for Accounts, Notifications.

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 neomutt.c.

Function Documentation

◆ neomutt_new()

struct NeoMutt* neomutt_new ( struct ConfigSet cs)

Create the main NeoMutt object.

Parameters
csConfig Set
Return values
ptrNew NeoMutt

Definition at line 44 of file neomutt.c.

45 {
46  if (!cs)
47  return NULL;
48 
49  struct NeoMutt *n = mutt_mem_calloc(1, sizeof(*NeoMutt));
50 
51  TAILQ_INIT(&n->accounts);
52  n->notify = notify_new();
53  n->sub = cs_subset_new(NULL, NULL, n->notify);
54  n->sub->cs = cs;
56 
57  return n;
58 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
This Config is NeoMutt-specific (global)
Definition: subset.h:38
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
#define TAILQ_INIT(head)
Definition: queue.h:758
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
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 ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neomutt_free()

void neomutt_free ( struct NeoMutt **  ptr)

Free a NeoMutt.

Parameters
[out]ptrNeoMutt to free

Definition at line 64 of file neomutt.c.

65 {
66  if (!ptr || !*ptr)
67  return;
68 
69  struct NeoMutt *n = *ptr;
70 
71  neomutt_account_remove(n, NULL);
72  cs_subset_free(&n->sub);
73  notify_free(&n->notify);
74 
75  FREE(ptr);
76 }
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:93
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define FREE(x)
Definition: memory.h:40
bool neomutt_account_remove(struct NeoMutt *n, struct Account *a)
Remove an Account from the global list.
Definition: neomutt.c:105
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neomutt_account_add()

bool neomutt_account_add ( struct NeoMutt n,
struct Account a 
)

Add an Account to the global list.

Parameters
nNeoMutt
aAccount to add
Return values
trueIf Account was added

Definition at line 84 of file neomutt.c.

85 {
86  if (!n || !a)
87  return false;
88 
89  TAILQ_INSERT_TAIL(&n->accounts, a, entries);
91 
92  struct EventAccount ev_a = { a };
94  return true;
95 }
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
struct Notify * notify
Notifications handler.
Definition: account.h:42
An Event that happened to an Account.
Definition: account.h:70
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:34
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:802
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
A new Account has been created.
Definition: account.h:62
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neomutt_account_remove()

bool neomutt_account_remove ( struct NeoMutt n,
struct Account a 
)

Remove an Account from the global list.

Parameters
nNeoMutt
aAccount to remove
Return values
trueIf Account was removed
Note
If a is NULL, all the Accounts will be removed

Definition at line 105 of file neomutt.c.

106 {
107  if (!n)
108  return false;
109 
110  bool result = false;
111  struct Account *np = NULL;
112  struct Account *tmp = NULL;
113  TAILQ_FOREACH_SAFE(np, &n->accounts, entries, tmp)
114  {
115  if (!a || (np == a))
116  {
117  struct EventAccount ev_a = { np };
119 
120  TAILQ_REMOVE(&n->accounts, np, entries);
121  notify_set_parent(n->notify, NULL);
122  account_free(&np);
123  result = true;
124  if (a)
125  break;
126  }
127  }
128  return result;
129 }
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
A group of associated Mailboxes.
Definition: account.h:36
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:728
An Event that happened to an Account.
Definition: account.h:70
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
void account_free(struct Account **ptr)
Free an Account.
Definition: account.c:125
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:34
An Account is about to be destroyed.
Definition: account.h:63
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neomutt_mailboxlist_clear()

void neomutt_mailboxlist_clear ( struct MailboxList *  ml)

Free a Mailbox List.

Parameters
mlMailbox List to free
Note
The Mailboxes aren't freed

Definition at line 137 of file neomutt.c.

138 {
139  if (!ml)
140  return;
141 
142  struct MailboxNode *mn = NULL;
143  struct MailboxNode *tmp = NULL;
144  STAILQ_FOREACH_SAFE(mn, ml, entries, tmp)
145  {
146  STAILQ_REMOVE(ml, mn, MailboxNode, entries);
147  FREE(&mn);
148  }
149 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
#define FREE(x)
Definition: memory.h:40
List of Mailboxes.
Definition: mailbox.h:150
+ Here is the caller graph for this function:

◆ neomutt_mailboxlist_get_all()

size_t neomutt_mailboxlist_get_all ( struct MailboxList *  head,
struct NeoMutt n,
enum MailboxType  type 
)

Get a List of all Mailboxes.

Parameters
headList to store the Mailboxes
nNeoMutt
typeType of Account to match, see MailboxType
Return values
numNumber of Mailboxes in the List
Note
If type is MUTT_MAILBOX_ANY then all Mailbox types will be matched

Definition at line 160 of file neomutt.c.

162 {
163  if (!n)
164  return 0;
165 
166  size_t count = 0;
167  struct Account *a = NULL;
168  struct MailboxNode *mn = NULL;
169 
170  TAILQ_FOREACH(a, &n->accounts, entries)
171  {
172  if ((type > MUTT_UNKNOWN) && (a->type != type))
173  continue;
174 
175  STAILQ_FOREACH(mn, &a->mailboxes, entries)
176  {
177  struct MailboxNode *mn2 = mutt_mem_calloc(1, sizeof(*mn2));
178  mn2->mailbox = mn->mailbox;
179  STAILQ_INSERT_TAIL(head, mn2, entries);
180  count++;
181  }
182  }
183 
184  return count;
185 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
A group of associated Mailboxes.
Definition: account.h:36
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
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
List of Mailboxes.
Definition: mailbox.h:150
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:152
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ NeoMutt

struct NeoMutt* NeoMutt

Global NeoMutt object.

Definition at line 37 of file neomutt.c.