NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
neomutt.c File Reference

Container for Accounts, Notifications. More...

#include "config.h"
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "neomutt.h"
#include "account.h"
#include "command.h"
#include "mailbox.h"
#include "module_api.h"
#include "muttlib.h"
+ Include dependency graph for neomutt.c:

Go to the source code of this file.

Macros

#define CONFIG_INIT_TYPE(CS, NAME)
 Register a config type in the config set.
 
#define CONFIG_INIT_VARS(CS, NAME)
 Initialize config variables for a subsystem.
 

Functions

static bool init_env (struct NeoMutt *n, char **envp)
 Initialise the Environment.
 
static bool init_locale (struct NeoMutt *n)
 Initialise the Locale/NLS settings.
 
static void localise_config (struct ConfigSet *cs)
 Localise some config.
 
static void reset_tilde (struct ConfigSet *cs)
 Temporary measure.
 
static bool init_config (struct NeoMutt *n)
 Initialise the config system.
 
static bool init_commands (struct NeoMutt *n)
 Initialise the NeoMutt commands.
 
static bool init_modules (struct NeoMutt *n)
 Initialise the Modules.
 
static bool init_gui_modules (struct NeoMutt *n)
 Initialise the Gui Modules.
 
struct NeoMuttneomutt_new (void)
 Create the main NeoMutt object.
 
bool neomutt_init (struct NeoMutt *n, char **envp, const struct Module **modules)
 Initialise NeoMutt.
 
bool neomutt_gui_init (struct NeoMutt *n)
 Initialise the GUI Modules.
 
static bool cleanup_modules (struct NeoMutt *n)
 Clean up each of the Modules.
 
static void cleanup_gui_modules (struct NeoMutt *n)
 Clean up each of the Gui Modules.
 
void neomutt_cleanup (struct NeoMutt *n)
 Clean up NeoMutt and Modules.
 
void neomutt_gui_cleanup (struct NeoMutt *n)
 Clean up the GUI Modules.
 
void neomutt_free (struct NeoMutt **ptr)
 Free a NeoMutt.
 
bool neomutt_account_add (struct NeoMutt *n, struct Account *a)
 Add an Account to the global list.
 
void neomutt_account_remove (struct NeoMutt *n, struct Account *a)
 Remove an Account from the global list.
 
void neomutt_accounts_free (struct NeoMutt *n)
 
struct MailboxArray neomutt_mailboxes_get (struct NeoMutt *n, enum MailboxType type)
 Get an Array of matching Mailboxes.
 
FILE * mutt_file_fopen_masked_full (const char *path, const char *mode, const char *file, int line, const char *func)
 Wrapper around mutt_file_fopen_full()
 
void * neomutt_get_module_data (struct NeoMutt *n, enum ModuleId id)
 Get the private data for a Module.
 
void neomutt_set_module_data (struct NeoMutt *n, enum ModuleId id, void *data)
 Set the private data for a Module.
 

Variables

struct NeoMutt * NeoMutt = NULL
 Global NeoMutt object.
 

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.

Macro Definition Documentation

◆ CONFIG_INIT_TYPE

#define CONFIG_INIT_TYPE ( CS,
NAME )
Value:
extern const struct ConfigSetType Cst##NAME; \
cs_register_type(CS, &Cst##NAME)

Register a config type in the config set.

Definition at line 49 of file neomutt.c.

49#define CONFIG_INIT_TYPE(CS, NAME) \
50 extern const struct ConfigSetType Cst##NAME; \
51 cs_register_type(CS, &Cst##NAME)

◆ CONFIG_INIT_VARS

#define CONFIG_INIT_VARS ( CS,
NAME )
Value:
bool config_init_##NAME(struct ConfigSet *cs); \
config_init_##NAME(CS)
Container for lots of config items.
Definition set.h:251

Initialize config variables for a subsystem.

Definition at line 54 of file neomutt.c.

54#define CONFIG_INIT_VARS(CS, NAME) \
55 bool config_init_##NAME(struct ConfigSet *cs); \
56 config_init_##NAME(CS)

Function Documentation

◆ init_env()

static bool init_env ( struct NeoMutt * n,
char ** envp )
static

Initialise the Environment.

Parameters
nNeoMutt
envpExternal environment
Return values
trueSuccess

Definition at line 64 of file neomutt.c.

65{
66 if (!n)
67 return false;
68
71
72 envlist_free(&n->env);
73 n->env = envlist_init(envp);
74
75 return true;
76}
void envlist_free(char ***envp)
Free the private copy of the environment.
Definition envlist.c:42
char ** envlist_init(char **envp)
Create a copy of the environment.
Definition envlist.c:58
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition string.c:731
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:284
char ** env
Private copy of the environment variables.
Definition neomutt.h:57
char * username
User's login name.
Definition neomutt.h:56
char * home_dir
User's home directory.
Definition neomutt.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_locale()

static bool init_locale ( struct NeoMutt * n)
static

Initialise the Locale/NLS settings.

Parameters
nNeoMutt
Return values
trueSuccess

Definition at line 83 of file neomutt.c.

84{
85 if (!n)
86 return false;
87
88 setlocale(LC_ALL, "");
89
90#ifdef ENABLE_NLS
91 const char *domdir = mutt_str_getenv("TEXTDOMAINDIR");
92 if (domdir)
93 bindtextdomain(PACKAGE, domdir);
94 else
95 bindtextdomain(PACKAGE, MUTTLOCALEDIR);
96 textdomain(PACKAGE);
97#endif
98
99 n->time_c_locale = duplocale(LC_GLOBAL_LOCALE);
100 if (n->time_c_locale)
101 n->time_c_locale = newlocale(LC_TIME_MASK, "C", n->time_c_locale);
102
103 if (!n->time_c_locale)
104 {
105 mutt_error("%s", strerror(errno)); // LCOV_EXCL_LINE
106 return false; // LCOV_EXCL_LINE
107 }
108
109#ifndef LOCALES_HACK
110 /* Do we have a locale definition? */
111 if (mutt_str_getenv("LC_ALL") || mutt_str_getenv("LANG") || mutt_str_getenv("LC_CTYPE"))
112 {
113 OptLocales = true;
114 }
115#endif
116
117 return true;
118}
#define mutt_error(...)
Definition logging2.h:94
bool OptLocales
(pseudo) set if user has valid locale definition
Definition mbyte.c:45
locale_t time_c_locale
Current locale but LC_TIME=C.
Definition neomutt.h:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ localise_config()

static void localise_config ( struct ConfigSet * cs)
static

Localise some config.

Parameters
csConfig Set

Definition at line 125 of file neomutt.c.

126{
127 struct Buffer *value = buf_pool_get();
128 struct HashElemArray hea = get_elem_list(cs, GEL_ALL_CONFIG);
129 struct HashElem **hep = NULL;
130
131 ARRAY_FOREACH(hep, &hea)
132 {
133 struct HashElem *he = *hep;
134 if (!(he->type & D_L10N_STRING))
135 continue;
136
137 buf_reset(value);
138 cs_he_initial_get(cs, he, value);
139
140 // Lookup the translation
141 const char *l10n = gettext(buf_string(value));
142 config_he_set_initial(cs, he, l10n);
143 }
144
145 ARRAY_FREE(&hea);
146 buf_pool_release(&value);
147}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
bool config_he_set_initial(struct ConfigSet *cs, struct HashElem *he, const char *value)
Set the initial value of a Config Option.
Definition helpers.c:312
int cs_he_initial_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get the initial, or parent, value of a config item.
Definition set.c:558
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
String manipulation buffer.
Definition buffer.h:36
The item stored in a Hash Table.
Definition hash.h:44
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition hash.h:45
struct HashElemArray get_elem_list(struct ConfigSet *cs, enum GetElemListFlags flags)
Create a sorted list of all config items.
Definition subset.c:81
@ GEL_ALL_CONFIG
All the normal config (no synonyms or deprecated)
Definition subset.h:81
#define D_L10N_STRING
String can be localised.
Definition types.h:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_tilde()

static void reset_tilde ( struct ConfigSet * cs)
static

Temporary measure.

Parameters
csConfig Set

Definition at line 154 of file neomutt.c.

155{
156 static const char *names[] = { "folder", "mbox", "postponed", "record" };
157
158 struct Buffer *value = buf_pool_get();
159 for (size_t i = 0; i < countof(names); i++)
160 {
161 struct HashElem *he = cs_get_elem(cs, names[i]);
162 if (!he)
163 continue;
164 buf_reset(value);
165 cs_he_initial_get(cs, he, value);
166 expand_path(value, false);
167 config_he_set_initial(cs, he, value->data);
168 }
169 buf_pool_release(&value);
170}
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition set.c:176
#define countof(x)
Definition memory.h:49
void expand_path(struct Buffer *buf, bool regex)
Create the canonical path.
Definition muttlib.c:122
char * data
Pointer to data.
Definition buffer.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_config()

static bool init_config ( struct NeoMutt * n)
static

Initialise the config system.

Parameters
nNeomutt
Return values
trueSuccess

Set up the config variables in three stages:

  • Create the config types
  • Create the config variables
  • Set some run-time defaults

Definition at line 182 of file neomutt.c.

183{
184 if (!n)
185 return false;
186
187 n->cs = cs_new(500);
188
189 n->sub = cs_subset_new(NULL, NULL, n->notify);
191 n->sub->cs = n->cs;
192
193 bool rc = true;
194
195 // Set up the Config Types
196 for (enum ModuleId id = MODULE_ID_MAIN; id < MODULE_ID_MAX; id++)
197 {
198 const struct Module *mod = n->modules[id];
199 if (!mod)
200 continue;
201
202 if (mod->config_define_types)
203 {
204 mutt_debug(LL_DEBUG3, "%s:config_define_types()\n", mod->name);
205 rc &= mod->config_define_types(n, n->sub->cs);
206 }
207 }
208
209 if (!rc)
210 return false;
211
212 // Define the Config Variables
213 for (enum ModuleId id = MODULE_ID_MAIN; id < MODULE_ID_MAX; id++)
214 {
215 const struct Module *mod = n->modules[id];
216 if (!mod)
217 continue;
218
220 {
221 mutt_debug(LL_DEBUG3, "%s:config_define_variables()\n", mod->name);
222 rc &= mod->config_define_variables(n, n->sub->cs);
223 }
224 }
225
226 if (!rc)
227 return false;
228
229 // Post-processing
230#ifdef ENABLE_NLS
232#endif
233 reset_tilde(n->sub->cs);
234
235 /* Unset suspend by default if we're the session leader */
236 if (getsid(0) == getpid())
237 config_str_set_initial(n->sub->cs, "suspend", "no");
238
239 return rc;
240}
bool config_str_set_initial(struct ConfigSet *cs, const char *name, const char *value)
Set the initial value of a Config Option.
Definition helpers.c:332
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition set.c:128
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
ModuleId
Unique Module Ids.
Definition module_api.h:42
@ MODULE_ID_MAX
Definition module_api.h:93
@ MODULE_ID_MAIN
ModuleMain, NeoMutt Email Client
Definition module_api.h:44
static void localise_config(struct ConfigSet *cs)
Localise some config.
Definition neomutt.c:125
static void reset_tilde(struct ConfigSet *cs)
Temporary measure.
Definition neomutt.c:154
struct ConfigSet * cs
Parent ConfigSet.
Definition subset.h:50
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition subset.h:48
const char * name
Name of the library module.
Definition module_api.h:104
bool(* config_define_types)(struct NeoMutt *n, struct ConfigSet *cs)
Definition module_api.h:125
bool(* config_define_variables)(struct NeoMutt *n, struct ConfigSet *cs)
Definition module_api.h:137
const struct Module * modules[MODULE_ID_MAX]
Library modules.
Definition neomutt.h:42
struct ConfigSet * cs
Config set.
Definition neomutt.h:48
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.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:158
@ SET_SCOPE_NEOMUTT
This Config is NeoMutt-specific (global)
Definition subset.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_commands()

static bool init_commands ( struct NeoMutt * n)
static

Initialise the NeoMutt commands.

Parameters
nNeomutt
Return values
trueSuccess

Definition at line 247 of file neomutt.c.

248{
249 if (!n)
250 return false;
251
252 struct CommandArray *ca = &n->commands;
253
254 bool rc = true;
255
256 // Set up the Config Types
257 for (enum ModuleId id = MODULE_ID_MAIN; id < MODULE_ID_MAX; id++)
258 {
259 const struct Module *mod = n->modules[id];
260 if (!mod)
261 continue;
262
263 if (mod->commands_register)
264 {
265 mutt_debug(LL_DEBUG3, "%s:commands_register()\n", mod->name);
266 rc &= mod->commands_register(n, ca);
267 }
268 }
269
270 return rc;
271}
bool(* commands_register)(struct NeoMutt *n, struct CommandArray *ca)
Definition module_api.h:149
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:53
+ Here is the caller graph for this function:

◆ init_modules()

static bool init_modules ( struct NeoMutt * n)
static

Initialise the Modules.

Parameters
nNeomutt
Return values
trueSuccess

Definition at line 278 of file neomutt.c.

279{
280 if (!n)
281 return false;
282
283 bool rc = true;
284
285 // Initialise the Modules
286 for (enum ModuleId id = MODULE_ID_MAIN; id < MODULE_ID_MAX; id++)
287 {
288 const struct Module *mod = n->modules[id];
289 if (!mod)
290 continue;
291
292 if (mod->init)
293 {
294 mutt_debug(LL_DEBUG3, "%s:init()\n", mod->name);
295 rc &= mod->init(n);
296 }
297 }
298
299 return rc;
300}
bool(* init)(struct NeoMutt *n)
Definition module_api.h:113
+ Here is the caller graph for this function:

◆ init_gui_modules()

static bool init_gui_modules ( struct NeoMutt * n)
static

Initialise the Gui Modules.

Parameters
nNeomutt
Return values
trueSuccess

Definition at line 307 of file neomutt.c.

308{
309 if (!n)
310 return false;
311
312 bool rc = true;
313
314 // Initialise the Gui Modules
315 for (enum ModuleId id = MODULE_ID_MAIN; id < MODULE_ID_MAX; id++)
316 {
317 const struct Module *mod = n->modules[id];
318 if (!mod)
319 continue;
320
321 if (mod->gui_init)
322 {
323 mutt_debug(LL_DEBUG3, "%s:gui_init()\n", mod->name);
324 rc &= mod->gui_init(n);
325 }
326 }
327
328 return rc;
329}
bool(* gui_init)(struct NeoMutt *n)
Definition module_api.h:158
+ Here is the caller graph for this function:

◆ neomutt_new()

struct NeoMutt * neomutt_new ( void )

Create the main NeoMutt object.

Return values
ptrNew NeoMutt

Definition at line 335 of file neomutt.c.

336{
337 return MUTT_MEM_CALLOC(1, struct NeoMutt);
338}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
Container for Accounts, Notifications.
Definition neomutt.h:41
+ Here is the caller graph for this function:

◆ neomutt_init()

bool neomutt_init ( struct NeoMutt * n,
char ** envp,
const struct Module ** modules )

Initialise NeoMutt.

Parameters
nNeoMutt
envpExternal environment
modulesLibrary modules to initialise
Return values
trueSuccess

Definition at line 347 of file neomutt.c.

348{
349 if (!n || !modules)
350 return false;
351
352 for (int i = 0; modules[i]; i++)
353 {
354 const struct Module *mod = modules[i];
355
356 n->modules[mod->mid] = mod;
357 }
358
359 if (!init_env(n, envp))
360 return false;
361
362 if (!init_locale(n))
363 return false;
364
365 if (!init_config(n))
366 return false;
367
368 if (!init_commands(n))
369 return false;
370
371 if (!init_modules(n))
372 return false;
373
374 ARRAY_INIT(&n->accounts);
375 n->notify = notify_new();
377
380
383
384 // Change the current umask, and save the original one
385 n->user_default_umask = umask(077);
386 mutt_debug(LL_DEBUG1, "user's umask %03o\n", n->user_default_umask);
387 mutt_debug(LL_DEBUG3, "umask set to 077\n");
388
389 return true;
390}
#define ARRAY_INIT(head)
Initialize an array.
Definition array.h:65
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
struct Notify * notify_new(void)
Create a new notifications handler.
Definition notify.c:62
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition notify.c:95
static bool init_modules(struct NeoMutt *n)
Initialise the Modules.
Definition neomutt.c:278
static bool init_locale(struct NeoMutt *n)
Initialise the Locale/NLS settings.
Definition neomutt.c:83
static bool init_config(struct NeoMutt *n)
Initialise the config system.
Definition neomutt.c:182
static bool init_env(struct NeoMutt *n, char **envp)
Initialise the Environment.
Definition neomutt.c:64
static bool init_commands(struct NeoMutt *n)
Initialise the NeoMutt commands.
Definition neomutt.c:247
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
enum ModuleId mid
Module Id.
Definition module_api.h:103
struct Notify * notify_timeout
Timeout notifications handler.
Definition neomutt.h:47
struct AccountArray accounts
All Accounts.
Definition neomutt.h:50
struct Notify * notify_resize
Window resize notifications handler.
Definition neomutt.h:46
mode_t user_default_umask
User's default file writing permissions (inferred from umask)
Definition neomutt.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neomutt_gui_init()

bool neomutt_gui_init ( struct NeoMutt * n)

Initialise the GUI Modules.

Parameters
nNeoMutt
Return values
trueSuccess

Definition at line 397 of file neomutt.c.

398{
399 if (!n)
400 return false;
401
402 return init_gui_modules(n);
403}
static bool init_gui_modules(struct NeoMutt *n)
Initialise the Gui Modules.
Definition neomutt.c:307
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cleanup_modules()

static bool cleanup_modules ( struct NeoMutt * n)
static

Clean up each of the Modules.

Parameters
nNeoMutt
Return values
trueSuccess

Definition at line 410 of file neomutt.c.

411{
412 if (!n)
413 return false;
414
415 bool rc = true;
416
417 // Cleanup the Modules
418 for (enum ModuleId id = MODULE_ID_MAIN; id < MODULE_ID_MAX; id++)
419 {
420 const struct Module *mod = n->modules[id];
421 if (!mod)
422 continue;
423
424 if (mod->cleanup)
425 {
426 mutt_debug(LL_DEBUG3, "%s:cleanup()\n", mod->name);
427 rc &= mod->cleanup(n);
428 }
429
430 if (n->module_data[mod->mid])
431 {
432 mutt_debug(LL_DEBUG1, "Module %s didn't clean up its data\n", mod->name);
433 rc = false;
434 }
435 }
436
437 return rc;
438}
bool(* cleanup)(struct NeoMutt *n)
Definition module_api.h:177
void * module_data[MODULE_ID_MAX]
Private library module data.
Definition neomutt.h:43
+ Here is the caller graph for this function:

◆ cleanup_gui_modules()

static void cleanup_gui_modules ( struct NeoMutt * n)
static

Clean up each of the Gui Modules.

Parameters
nNeoMutt

Definition at line 444 of file neomutt.c.

445{
446 if (!n)
447 return;
448
449 // Cleanup the Gui Modules
450 for (enum ModuleId id = MODULE_ID_MAIN; id < MODULE_ID_MAX; id++)
451 {
452 const struct Module *mod = n->modules[id];
453 if (!mod)
454 continue;
455
456 if (mod->gui_cleanup)
457 {
458 mutt_debug(LL_DEBUG3, "%s:gui_cleanup()\n", mod->name);
459 mod->gui_cleanup(n);
460 }
461
462 if (n->module_data[mod->mid])
463 {
464 mutt_debug(LL_DEBUG1, "Module %s didn't clean up its data\n", mod->name);
465 }
466 }
467}
void(* gui_cleanup)(struct NeoMutt *n)
Definition module_api.h:168
+ Here is the caller graph for this function:

◆ neomutt_cleanup()

void neomutt_cleanup ( struct NeoMutt * n)

Clean up NeoMutt and Modules.

Parameters
nNeoMutt

Definition at line 473 of file neomutt.c.

474{
475 if (!n)
476 return;
477
479
482}
void commands_clear(struct CommandArray *ca)
Clear an Array of Commands.
Definition command.c:70
static void cleanup_gui_modules(struct NeoMutt *n)
Clean up each of the Gui Modules.
Definition neomutt.c:444
static bool cleanup_modules(struct NeoMutt *n)
Clean up each of the Modules.
Definition neomutt.c:410
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neomutt_gui_cleanup()

void neomutt_gui_cleanup ( struct NeoMutt * n)

Clean up the GUI Modules.

Parameters
nNeoMutt

Definition at line 488 of file neomutt.c.

489{
490 if (!n)
491 return;
492
494}
+ 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 500 of file neomutt.c.

501{
502 if (!ptr || !*ptr)
503 return;
504
505 struct NeoMutt *n = *ptr;
506
508
509 if (n->sub)
510 {
511 struct ConfigSet *cs = n->sub->cs;
512 cs_subset_free(&n->sub);
513 cs_free(&cs);
514 }
515
518 notify_free(&n->notify);
519 if (n->time_c_locale)
520 freelocale(n->time_c_locale);
521
522 FREE(&n->home_dir);
523 FREE(&n->username);
524
525 envlist_free(&n->env);
526
527 FREE(ptr);
528}
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition set.c:142
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
void neomutt_accounts_free(struct NeoMutt *n)
Definition neomutt.c:577
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition subset.c:112
+ 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
trueAccount was added

Definition at line 536 of file neomutt.c.

537{
538 if (!n || !a)
539 return false;
540
541 ARRAY_ADD(&n->accounts, a);
543
544 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_ADD: %s %p\n",
545 mailbox_get_type_name(a->type), (void *) a);
546 struct EventAccount ev_a = { a };
548 return true;
549}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
@ NT_ACCOUNT_ADD
Account has been added.
Definition account.h:67
const char * mailbox_get_type_name(enum MailboxType type)
Get the type of a Mailbox.
Definition mailbox.c:325
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:50
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
@ NT_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition notify_type.h:36
enum MailboxType type
Type of Mailboxes this Account contains.
Definition account.h:37
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition account.h:41
An Event that happened to an Account.
Definition account.h:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neomutt_account_remove()

void neomutt_account_remove ( struct NeoMutt * n,
struct Account * a )

Remove an Account from the global list.

Parameters
nNeoMutt
aAccount to remove

Definition at line 556 of file neomutt.c.

557{
558 if (!n || !a || ARRAY_EMPTY(&n->accounts))
559 return;
560
561 struct Account **ap = NULL;
562 ARRAY_FOREACH(ap, &n->accounts)
563 {
564 if ((*ap) != a)
565 continue;
566
567 ARRAY_REMOVE(&n->accounts, ap);
568 account_free(&a);
569 break;
570 }
571}
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:355
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
void account_free(struct Account **ptr)
Free an Account.
Definition account.c:148
A group of associated Mailboxes.
Definition account.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neomutt_accounts_free()

void neomutt_accounts_free ( struct NeoMutt * n)
  • Free all the Accounts
    Parameters
    nNeoMutt

Definition at line 577 of file neomutt.c.

578{
579 if (!n)
580 return;
581
582 if (!ARRAY_EMPTY(&n->accounts))
583 {
584 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_DELETE_ALL\n");
585 struct EventAccount ev_a = { NULL };
587
588 struct Account **ap = NULL;
589 ARRAY_FOREACH(ap, &n->accounts)
590 {
591 account_free(ap);
592 }
593 }
594
595 ARRAY_FREE(&n->accounts);
596}
@ NT_ACCOUNT_DELETE_ALL
All Accounts are about to be deleted.
Definition account.h:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neomutt_mailboxes_get()

struct MailboxArray neomutt_mailboxes_get ( struct NeoMutt * n,
enum MailboxType type )

Get an Array of matching Mailboxes.

Parameters
nNeoMutt
typeType of Account to match, see MailboxType
Return values
objArray of Mailboxes
Note
If type is MUTT_MAILBOX_ANY then all Mailbox types will be matched

Definition at line 606 of file neomutt.c.

607{
608 struct MailboxArray ma = ARRAY_HEAD_INITIALIZER;
609
610 if (!n)
611 return ma;
612
613 struct Account **ap = NULL;
614 struct Mailbox **mp = NULL;
615
616 ARRAY_FOREACH(ap, &n->accounts)
617 {
618 struct Account *a = *ap;
619 if ((type > MUTT_UNKNOWN) && (a->type != type))
620 continue;
621
622 ARRAY_FOREACH(mp, &a->mailboxes)
623 {
624 ARRAY_ADD(&ma, *mp);
625 }
626 }
627
628 return ma;
629}
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition mailbox.h:43
struct MailboxArray mailboxes
All Mailboxes.
Definition account.h:40
A mailbox.
Definition mailbox.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_file_fopen_masked_full()

FILE * mutt_file_fopen_masked_full ( const char * path,
const char * mode,
const char * file,
int line,
const char * func )

Wrapper around mutt_file_fopen_full()

Parameters
pathFilename
modeMode e.g. "r" readonly; "w" read-write
fileSource file
lineSource line number
funcSource function
Return values
ptrFILE handle
NULLError, see errno

Apply the user's umask, then call mutt_file_fopen_full().

Definition at line 643 of file neomutt.c.

645{
646 // Set the user's umask (saved on startup)
647 mode_t old_umask = umask(NeoMutt->user_default_umask);
648 mutt_debug(LL_DEBUG3, "umask set to %03o\n", NeoMutt->user_default_umask);
649
650 // The permissions will be limited by the umask
651 FILE *fp = mutt_file_fopen_full(path, mode, 0666, file, line, func);
652
653 umask(old_umask); // Immediately restore the umask
654 mutt_debug(LL_DEBUG3, "umask set to %03o\n", old_umask);
655
656 return fp;
657}
FILE * mutt_file_fopen_full(const char *path, const char *mode, const mode_t perms, const char *file, int line, const char *func)
Call fopen() safely.
Definition file.c:556
+ Here is the call graph for this function:

◆ neomutt_get_module_data()

void * neomutt_get_module_data ( struct NeoMutt * n,
enum ModuleId id )

Get the private data for a Module.

Parameters
nNeoMutt
idModule Id
Return values
ptrPrivate Module data

Definition at line 665 of file neomutt.c.

666{
667 if (!n)
668 return NULL;
669
670 return n->module_data[id];
671}

◆ neomutt_set_module_data()

void neomutt_set_module_data ( struct NeoMutt * n,
enum ModuleId id,
void * data )

Set the private data for a Module.

Parameters
nNeoMutt
idModule Id
dataPrivate Module data

Definition at line 679 of file neomutt.c.

680{
681 if (!n)
682 return;
683
684 n->module_data[id] = data;
685}
+ Here is the caller graph for this function:

Variable Documentation

◆ NeoMutt

struct NeoMutt* NeoMutt = NULL

Global NeoMutt object.

Definition at line 46 of file neomutt.c.