NeoMutt  2024-12-12-14-g7b49f7
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 <stddef.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include "mutt/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.
 
bool neomutt_account_remove (struct NeoMutt *n, const struct Account *a)
 Remove an Account from the global list.
 
void neomutt_mailboxlist_clear (struct MailboxList *ml)
 Free a Mailbox List.
 
size_t neomutt_mailboxlist_get_all (struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
 Get a List of all 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 NeoMuttNeoMutt = 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 return n;
80}
#define mutt_error(...)
Definition: logging2.h:92
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:266
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
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
#define TAILQ_INIT(head)
Definition: queue.h:783
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct Notify * notify_timeout
Timeout notifications handler.
Definition: neomutt.h:45
struct Notify * notify_resize
Window resize notifications handler.
Definition: neomutt.h:44
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:47
struct Notify * notify
Notifications handler.
Definition: neomutt.h:43
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
locale_t time_c_locale
Current locale but LC_TIME=C.
Definition: neomutt.h:48
struct ConfigSubset * cs_subset_new(const char *name, struct ConfigSubset *sub_parent, struct Notify *not_parent)
Create a new Config Subset.
Definition: subset.c:152
@ SET_SCOPE_NEOMUTT
This Config is NeoMutt-specific (global)
Definition: subset.h:38
+ 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 86 of file neomutt.c.

87{
88 if (!ptr || !*ptr)
89 return;
90
91 struct NeoMutt *n = *ptr;
92
98 if (n->time_c_locale)
99 freelocale(n->time_c_locale);
100
101 FREE(ptr);
102}
#define FREE(x)
Definition: memory.h:55
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:75
bool neomutt_account_remove(struct NeoMutt *n, const struct Account *a)
Remove an Account from the global list.
Definition: neomutt.c:133
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:108
+ 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 110 of file neomutt.c.

111{
112 if (!n || !a)
113 return false;
114
115 TAILQ_INSERT_TAIL(&n->accounts, a, entries);
117
118 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_ADD: %s %p\n",
119 mailbox_get_type_name(a->type), (void *) a);
120 struct EventAccount ev_a = { a };
122 return true;
123}
@ NT_ACCOUNT_ADD
Account has been added.
Definition: account.h:69
const char * mailbox_get_type_name(enum MailboxType type)
Get the type of a Mailbox.
Definition: mailbox.c:326
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
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
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:827
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:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ neomutt_account_remove()

bool neomutt_account_remove ( struct NeoMutt n,
const struct Account a 
)

Remove an Account from the global list.

Parameters
nNeoMutt
aAccount to remove
Return values
trueAccount was removed
Note
If a is NULL, all the Accounts will be removed

Definition at line 133 of file neomutt.c.

134{
135 if (!n || TAILQ_EMPTY(&n->accounts))
136 return false;
137
138 if (!a)
139 {
140 mutt_debug(LL_NOTIFY, "NT_ACCOUNT_DELETE_ALL\n");
141 struct EventAccount ev_a = { NULL };
143 }
144
145 bool result = false;
146 struct Account *np = NULL;
147 struct Account *tmp = NULL;
148 TAILQ_FOREACH_SAFE(np, &n->accounts, entries, tmp)
149 {
150 if (a && (np != a))
151 continue;
152
153 TAILQ_REMOVE(&n->accounts, np, entries);
154 account_free(&np);
155 result = true;
156 if (a)
157 break;
158 }
159 return result;
160}
void account_free(struct Account **ptr)
Free an Account.
Definition: account.c:143
@ NT_ACCOUNT_DELETE_ALL
All Accounts are about to be deleted.
Definition: account.h:71
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:753
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:862
#define TAILQ_EMPTY(head)
Definition: queue.h:739
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_mailboxlist_clear()

void neomutt_mailboxlist_clear ( struct MailboxList *  ml)

Free a Mailbox List.

Parameters
mlMailbox List to free
Note
The Mailboxes aren't freed

Definition at line 168 of file neomutt.c.

169{
170 if (!ml)
171 return;
172
173 struct MailboxNode *mn = NULL;
174 struct MailboxNode *tmp = NULL;
175 STAILQ_FOREACH_SAFE(mn, ml, entries, tmp)
176 {
177 STAILQ_REMOVE(ml, mn, MailboxNode, entries);
178 FREE(&mn);
179 }
180}
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
List of Mailboxes.
Definition: mailbox.h:166
+ Here is the caller graph for this function:

◆ neomutt_mailboxlist_get_all()

size_t neomutt_mailboxlist_get_all ( struct MailboxList *  head,
struct NeoMutt n,
enum MailboxType  type 
)

Get a List of all Mailboxes.

Parameters
headList to store the Mailboxes
nNeoMutt
typeType of Account to match, see MailboxType
Return values
numNumber of Mailboxes in the List
Note
If type is MUTT_MAILBOX_ANY then all Mailbox types will be matched

Definition at line 191 of file neomutt.c.

193{
194 if (!n)
195 return 0;
196
197 size_t count = 0;
198 struct Account *a = NULL;
199 struct MailboxNode *mn = NULL;
200
201 TAILQ_FOREACH(a, &n->accounts, entries)
202 {
203 if ((type > MUTT_UNKNOWN) && (a->type != type))
204 continue;
205
206 STAILQ_FOREACH(mn, &a->mailboxes, entries)
207 {
208 struct MailboxNode *mn2 = MUTT_MEM_CALLOC(1, struct MailboxNode);
209 mn2->mailbox = mn->mailbox;
210 STAILQ_INSERT_TAIL(head, mn2, entries);
211 count++;
212 }
213 }
214
215 return count;
216}
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:743
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:389
struct MailboxList mailboxes
List of Mailboxes.
Definition: account.h:40
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:167
+ 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 230 of file neomutt.c.

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