NeoMutt  2025-12-11-58-g09398d
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 "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "neomutt.h"
#include "account.h"
#include "mailbox.h"
+ Include dependency graph for neomutt.c:

Go to the source code of this file.

Functions

struct NeoMuttneomutt_new (struct ConfigSet *cs)
 Create the main NeoMutt object.
 
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()
 

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.

Function Documentation

◆ neomutt_new()

struct NeoMutt * neomutt_new ( struct ConfigSet * cs)

Create the main NeoMutt object.

Parameters
csConfig Set
Return values
ptrNew NeoMutt

Definition at line 50 of file neomutt.c.

51{
52 if (!cs)
53 return NULL;
54
55 struct NeoMutt *n = MUTT_MEM_CALLOC(1, struct NeoMutt);
56
58 n->notify = notify_new();
59 n->sub = cs_subset_new(NULL, NULL, n->notify);
60 n->sub->cs = cs;
62
63 n->time_c_locale = duplocale(LC_GLOBAL_LOCALE);
64 if (n->time_c_locale)
65 n->time_c_locale = newlocale(LC_TIME_MASK, "C", n->time_c_locale);
66
67 if (!n->time_c_locale)
68 {
69 mutt_error("%s", strerror(errno)); // LCOV_EXCL_LINE
70 mutt_exit(1); // LCOV_EXCL_LINE
71 }
72
75
78
79 n->groups = groups_new();
80
81 return n;
82}
#define ARRAY_INIT(head)
Initialize an array.
Definition array.h:65
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition exit.c:41
struct HashTable * groups_new(void)
Create a HashTable for the Address Groups.
Definition group.c:267
#define mutt_error(...)
Definition logging2.h:93
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:47
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
struct ConfigSet * cs
Parent ConfigSet.
Definition subset.h:50
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition subset.h:48
Container for Accounts, Notifications.
Definition neomutt.h:43
struct Notify * notify_timeout
Timeout notifications handler.
Definition neomutt.h:46
struct AccountArray accounts
All Accounts.
Definition neomutt.h:48
struct Notify * notify_resize
Window resize notifications handler.
Definition neomutt.h:45
struct Notify * notify
Notifications handler.
Definition neomutt.h:44
struct HashTable * groups
Hash Table: "group-name" -> Group.
Definition neomutt.h:52
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:47
locale_t time_c_locale
Current locale but LC_TIME=C.
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:

◆ neomutt_free()

void neomutt_free ( struct NeoMutt ** ptr)

Free a NeoMutt.

Parameters
[out]ptrNeoMutt to free

Definition at line 88 of file neomutt.c.

89{
90 if (!ptr || !*ptr)
91 return;
92
93 struct NeoMutt *n = *ptr;
94
100 if (n->time_c_locale)
101 freelocale(n->time_c_locale);
102
103 groups_free(&n->groups);
104
105 FREE(&n->home_dir);
106 FREE(&n->username);
107
108 envlist_free(&n->env);
109
110 FREE(ptr);
111}
void envlist_free(char ***envp)
Free the private copy of the environment.
Definition envlist.c:42
void groups_free(struct HashTable **pptr)
Free Address Groups HashTable.
Definition group.c:280
#define FREE(x)
Definition memory.h:62
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
void neomutt_accounts_free(struct NeoMutt *n)
Definition neomutt.c:160
char ** env
Private copy of the environment variables.
Definition neomutt.h:56
char * username
User's login name.
Definition neomutt.h:55
char * home_dir
User's home directory.
Definition neomutt.h:54
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 119 of file neomutt.c.

120{
121 if (!n || !a)
122 return false;
123
124 ARRAY_ADD(&n->accounts, a);
126
127 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_ADD: %s %p\n",
128 mailbox_get_type_name(a->type), (void *) a);
129 struct EventAccount ev_a = { a };
131 return true;
132}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:156
@ 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:324
#define mutt_debug(LEVEL,...)
Definition logging2.h:90
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:49
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 139 of file neomutt.c.

140{
141 if (!n || !a || ARRAY_EMPTY(&n->accounts))
142 return;
143
144 struct Account **ap = NULL;
145 ARRAY_FOREACH(ap, &n->accounts)
146 {
147 if ((*ap) != a)
148 continue;
149
150 ARRAY_REMOVE(&n->accounts, ap);
151 account_free(&a);
152 break;
153 }
154}
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:323
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:214
#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 160 of file neomutt.c.

161{
162 if (!n)
163 return;
164
165 if (!ARRAY_EMPTY(&n->accounts))
166 {
167 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_DELETE_ALL\n");
168 struct EventAccount ev_a = { NULL };
170
171 struct Account **ap = NULL;
172 ARRAY_FOREACH(ap, &n->accounts)
173 {
174 account_free(ap);
175 }
176 }
177
178 ARRAY_FREE(&n->accounts);
179}
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:204
@ 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 189 of file neomutt.c.

190{
191 struct MailboxArray ma = ARRAY_HEAD_INITIALIZER;
192
193 if (!n)
194 return ma;
195
196 struct Account **ap = NULL;
197 struct Mailbox **mp = NULL;
198
199 ARRAY_FOREACH(ap, &n->accounts)
200 {
201 struct Account *a = *ap;
202 if ((type > MUTT_UNKNOWN) && (a->type != type))
203 continue;
204
205 ARRAY_FOREACH(mp, &a->mailboxes)
206 {
207 ARRAY_ADD(&ma, *mp);
208 }
209 }
210
211 return ma;
212}
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition mailbox.h:44
struct MailboxArray mailboxes
All Mailboxes.
Definition account.h:40
A mailbox.
Definition mailbox.h:79
+ 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 226 of file neomutt.c.

228{
229 // Set the user's umask (saved on startup)
230 mode_t old_umask = umask(NeoMutt->user_default_umask);
231 mutt_debug(LL_DEBUG3, "umask set to %03o\n", NeoMutt->user_default_umask);
232
233 // The permissions will be limited by the umask
234 FILE *fp = mutt_file_fopen_full(path, mode, 0666, file, line, func);
235
236 umask(old_umask); // Immediately restore the umask
237 mutt_debug(LL_DEBUG3, "umask set to %03o\n", old_umask);
238
239 return fp;
240}
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:563
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:46
mode_t user_default_umask
User's default file writing permissions (inferred from umask)
Definition neomutt.h:50
+ Here is the call graph for this function:

Variable Documentation

◆ NeoMutt

struct NeoMutt* NeoMutt = NULL

Global NeoMutt object.

Definition at line 43 of file neomutt.c.