NeoMutt  2022-04-29-178-g3b62e6
Teaching an old dog new tricks
DOXYGEN
neomutt.h File Reference

Container for Accounts, Notifications. More...

#include <stddef.h>
#include <stdbool.h>
#include "account.h"
#include "mailbox.h"
+ Include dependency graph for neomutt.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  NeoMutt
 Container for Accounts, Notifications. More...
 

Enumerations

enum  NotifyGlobal { NT_GLOBAL_STARTUP = 1 , NT_GLOBAL_SHUTDOWN , NT_GLOBAL_TIMEOUT , NT_GLOBAL_COMMAND }
 Events not associated with an object. More...
 

Functions

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, const struct Account *a)
 Remove an Account from the global list. More...
 
void neomutt_free (struct NeoMutt **ptr)
 Free a NeoMutt. More...
 
struct NeoMuttneomutt_new (struct ConfigSet *cs)
 Create the main NeoMutt object. 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.h.

Enumeration Type Documentation

◆ NotifyGlobal

Events not associated with an object.

Observers of NT_GLOBAL will not be passed any Event data.

Enumerator
NT_GLOBAL_STARTUP 

NeoMutt is initialised.

NT_GLOBAL_SHUTDOWN 

NeoMutt is about to close.

NT_GLOBAL_TIMEOUT 

A timer has elapsed.

NT_GLOBAL_COMMAND 

A NeoMutt command.

Definition at line 50 of file neomutt.h.

51{
56};
@ NT_GLOBAL_STARTUP
NeoMutt is initialised.
Definition: neomutt.h:52
@ NT_GLOBAL_TIMEOUT
A timer has elapsed.
Definition: neomutt.h:54
@ NT_GLOBAL_COMMAND
A NeoMutt command.
Definition: neomutt.h:55
@ NT_GLOBAL_SHUTDOWN
NeoMutt is about to close.
Definition: neomutt.h:53

Function Documentation

◆ 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
trueAccount 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 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_ADD: %s %p\n", mailbox_get_type_name(a->type), a);
93 struct EventAccount ev_a = { a };
95 return true;
96}
@ NT_ACCOUNT_ADD
Account has been added.
Definition: account.h:69
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_NOTIFY
Log of notifications.
Definition: logging.h:45
const char * mailbox_get_type_name(enum MailboxType type)
Get the type of a Mailbox.
Definition: mailbox.c:310
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
@ NT_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:36
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:42
An Event that happened to an Account.
Definition: account.h:79
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
+ 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,
const struct Account a 
)

Remove an Account from the global list.

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

Definition at line 106 of file neomutt.c.

107{
108 if (!n || TAILQ_EMPTY(&n->accounts))
109 return false;
110
111 if (!a)
112 {
113 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_DELETE_ALL\n");
114 struct EventAccount ev_a = { NULL };
116 }
117
118 bool result = false;
119 struct Account *np = NULL;
120 struct Account *tmp = NULL;
121 TAILQ_FOREACH_SAFE(np, &n->accounts, entries, tmp)
122 {
123 if (a && (np != a))
124 continue;
125
126 TAILQ_REMOVE(&n->accounts, np, entries);
127 account_free(&np);
128 result = true;
129 if (a)
130 break;
131 }
132 return result;
133}
void account_free(struct Account **ptr)
Free an Account.
Definition: account.c:141
@ NT_ACCOUNT_DELETE_ALL
All Accounts are about to be deleted.
Definition: account.h:71
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
#define TAILQ_EMPTY(head)
Definition: queue.h:721
A group of associated Mailboxes.
Definition: account.h:37
+ 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
74
75 FREE(ptr);
76}
#define FREE(x)
Definition: memory.h:43
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
bool neomutt_account_remove(struct NeoMutt *n, const struct Account *a)
Remove an Account from the global list.
Definition: neomutt.c:106
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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
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
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:60
#define TAILQ_INIT(head)
Definition: queue.h:765
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
struct ConfigSubset * cs_subset_new(const char *name, struct ConfigSubset *sub_parent, struct Notify *not_parent)
Create a new Config Subset.
Definition: subset.c:144
@ SET_SCOPE_NEOMUTT
This Config is NeoMutt-specific (global)
Definition: subset.h:38
+ 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 141 of file neomutt.c.

142{
143 if (!ml)
144 return;
145
146 struct MailboxNode *mn = NULL;
147 struct MailboxNode *tmp = NULL;
148 STAILQ_FOREACH_SAFE(mn, ml, entries, tmp)
149 {
150 STAILQ_REMOVE(ml, mn, MailboxNode, entries);
151 FREE(&mn);
152 }
153}
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
List of Mailboxes.
Definition: mailbox.h:154
+ 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 164 of file neomutt.c.

166{
167 if (!n)
168 return 0;
169
170 size_t count = 0;
171 struct Account *a = NULL;
172 struct MailboxNode *mn = NULL;
173
174 TAILQ_FOREACH(a, &n->accounts, entries)
175 {
176 if ((type > MUTT_UNKNOWN) && (a->type != type))
177 continue;
178
179 STAILQ_FOREACH(mn, &a->mailboxes, entries)
180 {
181 struct MailboxNode *mn2 = mutt_mem_calloc(1, sizeof(*mn2));
182 mn2->mailbox = mn->mailbox;
183 STAILQ_INSERT_TAIL(head, mn2, entries);
184 count++;
185 }
186 }
187
188 return count;
189}
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:389
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:155
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ NeoMutt

struct NeoMutt* NeoMutt
extern

Global NeoMutt object.

Definition at line 37 of file neomutt.c.