NeoMutt  2025-12-11-694-ga89709
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.
 
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:563
#define PATH

Open a file with proper permissions, tracked for debugging.

Definition at line 90 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 68 of file neomutt.h.

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

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

457{
458 if (!n || !a)
459 return false;
460
461 ARRAY_ADD(&n->accounts, a);
463
464 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_ADD: %s %p\n",
465 mailbox_get_type_name(a->type), (void *) a);
466 struct EventAccount ev_a = { a };
468 return true;
469}
#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 476 of file neomutt.c.

477{
478 if (!n || !a || ARRAY_EMPTY(&n->accounts))
479 return;
480
481 struct Account **ap = NULL;
482 ARRAY_FOREACH(ap, &n->accounts)
483 {
484 if ((*ap) != a)
485 continue;
486
487 ARRAY_REMOVE(&n->accounts, ap);
488 account_free(&a);
489 break;
490 }
491}
#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 497 of file neomutt.c.

498{
499 if (!n)
500 return;
501
502 if (!ARRAY_EMPTY(&n->accounts))
503 {
504 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_DELETE_ALL\n");
505 struct EventAccount ev_a = { NULL };
507
508 struct Account **ap = NULL;
509 ARRAY_FOREACH(ap, &n->accounts)
510 {
511 account_free(ap);
512 }
513 }
514
515 ARRAY_FREE(&n->accounts);
516}
#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 418 of file neomutt.c.

419{
420 if (!ptr || !*ptr)
421 return;
422
423 struct NeoMutt *n = *ptr;
424
426
427 if (n->sub)
428 {
429 struct ConfigSet *cs = n->sub->cs;
430 cs_subset_free(&n->sub);
431 cs_free(&cs);
432 }
433
436 notify_free(&n->notify);
437 if (n->time_c_locale)
438 freelocale(n->time_c_locale);
439
440 groups_free(&n->groups);
441
442 FREE(&n->home_dir);
443 FREE(&n->username);
444
445 envlist_free(&n->env);
446
447 FREE(ptr);
448}
void groups_free(struct HashTable **pptr)
Free Address Groups HashTable.
Definition group.c:280
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:497
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:58
char * username
User's login name.
Definition neomutt.h:57
char * home_dir
User's home directory.
Definition neomutt.h:56
struct HashTable * groups
Hash Table: "group-name" -> Group.
Definition neomutt.h:54
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 307 of file neomutt.c.

308{
309 return MUTT_MEM_CALLOC(1, struct NeoMutt);
310}
#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 585 of file neomutt.c.

586{
587 if (!n)
588 return NULL;
589
590 return n->module_data[id];
591}
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 599 of file neomutt.c.

600{
601 if (!n)
602 return;
603
604 n->module_data[id] = data;
605}
+ 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 319 of file neomutt.c.

320{
321 if (!n || !modules)
322 return false;
323
324 for (int i = 0; modules[i]; i++)
325 {
326 const struct Module *mod = modules[i];
327
328 n->modules[mod->mid] = mod;
329 }
330
331 if (!init_env(n, envp))
332 return false;
333
334 if (!init_locale(n))
335 return false;
336
337 if (!init_config(n))
338 return false;
339
340 if (!init_commands(n))
341 return false;
342
343 if (!init_modules(n))
344 return false;
345
346 ARRAY_INIT(&n->accounts);
347 n->notify = notify_new();
349
352
355
356 n->groups = groups_new();
357
358 // Change the current umask, and save the original one
359 n->user_default_umask = umask(077);
360 mutt_debug(LL_DEBUG1, "user's umask %03o\n", n->user_default_umask);
361 mutt_debug(LL_DEBUG3, "umask set to 077\n");
362
363 return true;
364}
struct HashTable * groups_new(void)
Create a HashTable for the Address Groups.
Definition group.c:267
#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:279
static bool init_locale(struct NeoMutt *n)
Initialise the Locale/NLS settings.
Definition neomutt.c:84
static bool init_config(struct NeoMutt *n)
Initialise the config system.
Definition neomutt.c:183
static bool init_env(struct NeoMutt *n, char **envp)
Initialise the Environment.
Definition neomutt.c:65
static bool init_commands(struct NeoMutt *n)
Initialise the NeoMutt commands.
Definition neomutt.c:248
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
enum ModuleId mid
Module Id.
Definition module_api.h:103
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 405 of file neomutt.c.

406{
407 if (!n)
408 return;
409
412}
void commands_clear(struct CommandArray *ca)
Clear an Array of Commands.
Definition command.c:70
static bool cleanup_modules(struct NeoMutt *n)
Clean up each of the Modules.
Definition neomutt.c:371
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_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 526 of file neomutt.c.

527{
528 struct MailboxArray ma = ARRAY_HEAD_INITIALIZER;
529
530 if (!n)
531 return ma;
532
533 struct Account **ap = NULL;
534 struct Mailbox **mp = NULL;
535
536 ARRAY_FOREACH(ap, &n->accounts)
537 {
538 struct Account *a = *ap;
539 if ((type > MUTT_UNKNOWN) && (a->type != type))
540 continue;
541
542 ARRAY_FOREACH(mp, &a->mailboxes)
543 {
544 ARRAY_ADD(&ma, *mp);
545 }
546 }
547
548 return ma;
549}
#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:

Variable Documentation

◆ NeoMutt

struct NeoMutt* NeoMutt
extern

Global NeoMutt object.

Definition at line 47 of file neomutt.c.