NeoMutt  2023-11-03-107-g582dc1
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
neomutt.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 "neomutt.h"
34#include "account.h"
35#include "mailbox.h"
36
37struct NeoMutt *NeoMutt = NULL;
38
44struct NeoMutt *neomutt_new(struct ConfigSet *cs)
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 n->time_c_locale = duplocale(LC_GLOBAL_LOCALE);
58 if (n->time_c_locale)
59 n->time_c_locale = newlocale(LC_TIME_MASK, "C", n->time_c_locale);
60
61 if (!n->time_c_locale)
62 {
63 mutt_error(_("Out of memory")); // LCOV_EXCL_LINE
64 mutt_exit(1); // LCOV_EXCL_LINE
65 }
66
69
72
73 return n;
74}
75
80void neomutt_free(struct NeoMutt **ptr)
81{
82 if (!ptr || !*ptr)
83 return;
84
85 struct NeoMutt *n = *ptr;
86
92 if (n->time_c_locale)
93 freelocale(n->time_c_locale);
94
95 FREE(ptr);
96}
97
104bool neomutt_account_add(struct NeoMutt *n, struct Account *a)
105{
106 if (!n || !a)
107 return false;
108
109 TAILQ_INSERT_TAIL(&n->accounts, a, entries);
111
112 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_ADD: %s %p\n",
113 mailbox_get_type_name(a->type), (void *) a);
114 struct EventAccount ev_a = { a };
116 return true;
117}
118
127bool neomutt_account_remove(struct NeoMutt *n, const struct Account *a)
128{
129 if (!n || TAILQ_EMPTY(&n->accounts))
130 return false;
131
132 if (!a)
133 {
134 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_DELETE_ALL\n");
135 struct EventAccount ev_a = { NULL };
137 }
138
139 bool result = false;
140 struct Account *np = NULL;
141 struct Account *tmp = NULL;
142 TAILQ_FOREACH_SAFE(np, &n->accounts, entries, tmp)
143 {
144 if (a && (np != a))
145 continue;
146
147 TAILQ_REMOVE(&n->accounts, np, entries);
148 account_free(&np);
149 result = true;
150 if (a)
151 break;
152 }
153 return result;
154}
155
162void neomutt_mailboxlist_clear(struct MailboxList *ml)
163{
164 if (!ml)
165 return;
166
167 struct MailboxNode *mn = NULL;
168 struct MailboxNode *tmp = NULL;
169 STAILQ_FOREACH_SAFE(mn, ml, entries, tmp)
170 {
171 STAILQ_REMOVE(ml, mn, MailboxNode, entries);
172 FREE(&mn);
173 }
174}
175
185size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n,
186 enum MailboxType type)
187{
188 if (!n)
189 return 0;
190
191 size_t count = 0;
192 struct Account *a = NULL;
193 struct MailboxNode *mn = NULL;
194
195 TAILQ_FOREACH(a, &n->accounts, entries)
196 {
197 if ((type > MUTT_UNKNOWN) && (a->type != type))
198 continue;
199
200 STAILQ_FOREACH(mn, &a->mailboxes, entries)
201 {
202 struct MailboxNode *mn2 = mutt_mem_calloc(1, sizeof(*mn2));
203 mn2->mailbox = mn->mailbox;
204 STAILQ_INSERT_TAIL(head, mn2, entries);
205 count++;
206 }
207 }
208
209 return count;
210}
void account_free(struct Account **ptr)
Free an Account.
Definition: account.c:142
A group of associated Mailboxes.
@ NT_ACCOUNT_ADD
Account has been added.
Definition: account.h:70
@ NT_ACCOUNT_DELETE_ALL
All Accounts are about to be deleted.
Definition: account.h:72
Convenience wrapper for the config headers.
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
const char * mailbox_get_type_name(enum MailboxType type)
Get the type of a Mailbox.
Definition: mailbox.c:319
Representation of a mailbox.
MailboxType
Supported mailbox formats.
Definition: mailbox.h:41
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:228
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:45
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
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
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:162
bool neomutt_account_add(struct NeoMutt *n, struct Account *a)
Add an Account to the global list.
Definition: neomutt.c:104
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:185
bool neomutt_account_remove(struct NeoMutt *n, const struct Account *a)
Remove an Account from the global list.
Definition: neomutt.c:127
struct NeoMutt * neomutt_new(struct ConfigSet *cs)
Create the main NeoMutt object.
Definition: neomutt.c:44
void neomutt_free(struct NeoMutt **ptr)
Free a NeoMutt.
Definition: neomutt.c:80
Container for Accounts, Notifications.
@ NT_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:36
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
#define TAILQ_INIT(head)
Definition: queue.h:765
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:389
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
#define TAILQ_EMPTY(head)
Definition: queue.h:721
A group of associated Mailboxes.
Definition: account.h:37
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:42
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:41
Container for lots of config items.
Definition: set.h:252
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:80
List of Mailboxes.
Definition: mailbox.h:153
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:154
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct Notify * notify_timeout
Timeout notifications handler.
Definition: neomutt.h:44
struct Notify * notify_resize
Window resize notifications handler.
Definition: neomutt.h:43
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:46
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
locale_t time_c_locale
Current locale but LC_TIME=C.
Definition: neomutt.h:47
struct ConfigSubset * cs_subset_new(const char *name, struct ConfigSubset *sub_parent, struct Notify *not_parent)
Create a new Config Subset.
Definition: subset.c:143
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:99
@ SET_SCOPE_NEOMUTT
This Config is NeoMutt-specific (global)
Definition: subset.h:38