NeoMutt  2025-12-11-980-ge38c27
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
neomutt.h File Reference

Container for Accounts, Notifications. More...

#include <locale.h>
#include <stdbool.h>
#include <sys/types.h>
#include "account.h"
#include "command.h"
#include "mailbox.h"
#include "module_api.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...
 

Macros

#define mutt_file_fopen_masked(PATH, MODE)
 Open a file with proper permissions, tracked for debugging.
 

Enumerations

enum  NotifyGlobal { NT_GLOBAL_STARTUP = 1 , NT_GLOBAL_SHUTDOWN , 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.
 
void neomutt_account_remove (struct NeoMutt *n, struct Account *a)
 Remove an Account from the global list.
 
void neomutt_accounts_free (struct NeoMutt *n)
 
void neomutt_free (struct NeoMutt **ptr)
 Free a NeoMutt.
 
struct NeoMuttneomutt_new (void)
 Create the main NeoMutt object.
 
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.
 
bool neomutt_init (struct NeoMutt *n, char **envp, const struct Module **modules)
 Initialise NeoMutt.
 
void neomutt_cleanup (struct NeoMutt *n)
 Clean up NeoMutt and Modules.
 
bool neomutt_gui_init (struct NeoMutt *n)
 Initialise the GUI Modules.
 
void neomutt_gui_cleanup (struct NeoMutt *n)
 Clean up the GUI Modules.
 
struct MailboxArray neomutt_mailboxes_get (struct NeoMutt *n, enum MailboxType type)
 Get an Array of matching Mailboxes.
 

Variables

struct NeoMutt * NeoMutt
 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.h.

Macro Definition Documentation

◆ mutt_file_fopen_masked

#define mutt_file_fopen_masked ( PATH,
MODE )
Value:
mutt_file_fopen_masked_full(PATH, MODE, __FILE__, __LINE__, __func__)
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()
Definition neomutt.c:644
#define PATH

Open a file with proper permissions, tracked for debugging.

Definition at line 92 of 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_COMMAND 

A NeoMutt command.

Definition at line 67 of file neomutt.h.

68{
72};
@ NT_GLOBAL_STARTUP
NeoMutt is initialised.
Definition neomutt.h:69
@ NT_GLOBAL_COMMAND
A NeoMutt command.
Definition neomutt.h:71
@ NT_GLOBAL_SHUTDOWN
NeoMutt is about to close.
Definition neomutt.h:70

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 537 of file neomutt.c.

538{
539 if (!n || !a)
540 return false;
541
542 ARRAY_ADD(&n->accounts, a);
544
545 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_ADD: %s %p\n",
546 mailbox_get_type_name(a->type), (void *) a);
547 struct EventAccount ev_a = { a };
549 return true;
550}
#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
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ 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
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition notify.c:95
@ 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
struct AccountArray accounts
All Accounts.
Definition neomutt.h:50
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
+ 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 557 of file neomutt.c.

558{
559 if (!n || !a || ARRAY_EMPTY(&n->accounts))
560 return;
561
562 struct Account **ap = NULL;
563 ARRAY_FOREACH(ap, &n->accounts)
564 {
565 if ((*ap) != a)
566 continue;
567
568 ARRAY_REMOVE(&n->accounts, ap);
569 account_free(&a);
570 break;
571 }
572}
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:355
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#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 578 of file neomutt.c.

579{
580 if (!n)
581 return;
582
583 if (!ARRAY_EMPTY(&n->accounts))
584 {
585 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_DELETE_ALL\n");
586 struct EventAccount ev_a = { NULL };
588
589 struct Account **ap = NULL;
590 ARRAY_FOREACH(ap, &n->accounts)
591 {
592 account_free(ap);
593 }
594 }
595
596 ARRAY_FREE(&n->accounts);
597}
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
@ 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_free()

void neomutt_free ( struct NeoMutt ** ptr)

Free a NeoMutt.

Parameters
[out]ptrNeoMutt to free

Definition at line 501 of file neomutt.c.

502{
503 if (!ptr || !*ptr)
504 return;
505
506 struct NeoMutt *n = *ptr;
507
509
510 if (n->sub)
511 {
512 struct ConfigSet *cs = n->sub->cs;
513 cs_subset_free(&n->sub);
514 cs_free(&cs);
515 }
516
519 notify_free(&n->notify);
520 if (n->time_c_locale)
521 freelocale(n->time_c_locale);
522
523 FREE(&n->home_dir);
524 FREE(&n->username);
525
526 envlist_free(&n->env);
527
528 FREE(ptr);
529}
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition set.c:142
void envlist_free(char ***envp)
Free the private copy of the environment.
Definition envlist.c:42
#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:578
Container for lots of config items.
Definition set.h:251
struct ConfigSet * cs
Parent ConfigSet.
Definition subset.h:50
Container for Accounts, Notifications.
Definition neomutt.h:41
struct Notify * notify_timeout
Timeout notifications handler.
Definition neomutt.h:47
struct Notify * notify_resize
Window resize notifications handler.
Definition neomutt.h:46
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
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
locale_t time_c_locale
Current locale but LC_TIME=C.
Definition neomutt.h:51
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_new()

struct NeoMutt * neomutt_new ( void )

Create the main NeoMutt object.

Return values
ptrNew NeoMutt

Definition at line 338 of file neomutt.c.

339{
340 return MUTT_MEM_CALLOC(1, struct NeoMutt);
341}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
+ Here is the caller 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 666 of file neomutt.c.

667{
668 if (!n)
669 return NULL;
670
671 return n->module_data[id];
672}
void * module_data[MODULE_ID_MAX]
Private library module data.
Definition neomutt.h:43

◆ 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 680 of file neomutt.c.

681{
682 if (!n)
683 return;
684
685 n->module_data[id] = data;
686}
+ 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 350 of file neomutt.c.

351{
352 if (!n || !modules)
353 return false;
354
355 for (int i = 0; modules[i]; i++)
356 {
357 const struct Module *mod = modules[i];
358
359 n->modules[mod->mid] = mod;
360 }
361
362 if (!init_env(n, envp))
363 return false;
364
365 if (!init_locale(n))
366 return false;
367
368 if (!init_config(n))
369 return false;
370
371 if (!init_commands(n))
372 return false;
373
374 if (!init_modules(n))
375 return false;
376
377 ARRAY_INIT(&n->accounts);
378 n->notify = notify_new();
380
383
386
387 // Change the current umask, and save the original one
388 n->user_default_umask = umask(077);
389 mutt_debug(LL_DEBUG1, "user's umask %03o\n", n->user_default_umask);
390 mutt_debug(LL_DEBUG3, "umask set to 077\n");
391
392 return true;
393}
#define ARRAY_INIT(head)
Initialize an array.
Definition array.h:65
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
@ 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
static bool init_modules(struct NeoMutt *n)
Initialise the Modules.
Definition neomutt.c:281
static bool init_locale(struct NeoMutt *n)
Initialise the Locale/NLS settings.
Definition neomutt.c:86
static bool init_config(struct NeoMutt *n)
Initialise the config system.
Definition neomutt.c:185
static bool init_env(struct NeoMutt *n, char **envp)
Initialise the Environment.
Definition neomutt.c:67
static bool init_commands(struct NeoMutt *n)
Initialise the NeoMutt commands.
Definition neomutt.c:250
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
enum ModuleId mid
Module Id.
Definition module_api.h:105
const struct Module * modules[MODULE_ID_MAX]
Library modules.
Definition neomutt.h:42
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_cleanup()

void neomutt_cleanup ( struct NeoMutt * n)

Clean up NeoMutt and Modules.

Parameters
nNeoMutt

Definition at line 474 of file neomutt.c.

475{
476 if (!n)
477 return;
478
480
483}
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:450
static bool cleanup_modules(struct NeoMutt *n)
Clean up each of the Modules.
Definition neomutt.c:413
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:53
+ 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 400 of file neomutt.c.

401{
402 if (!n)
403 return false;
404
405 return init_gui_modules(n);
406}
static bool init_gui_modules(struct NeoMutt *n)
Initialise the Gui Modules.
Definition neomutt.c:310
+ 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 489 of file neomutt.c.

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

608{
609 struct MailboxArray ma = ARRAY_HEAD_INITIALIZER;
610
611 if (!n)
612 return ma;
613
614 struct Account **ap = NULL;
615 struct Mailbox **mp = NULL;
616
617 ARRAY_FOREACH(ap, &n->accounts)
618 {
619 struct Account *a = *ap;
620 if ((type > MUTT_UNKNOWN) && (a->type != type))
621 continue;
622
623 ARRAY_FOREACH(mp, &a->mailboxes)
624 {
625 ARRAY_ADD(&ma, *mp);
626 }
627 }
628
629 return ma;
630}
#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:81
+ 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 49 of file neomutt.c.