NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
adata.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include "private.h"
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "core/lib.h"
34#include "conn/lib.h"
35#include "adata.h"
36#include "lib.h"
37
44{
45 if (nc->event_type != NT_TIMEOUT)
46 return 0;
47 if (!nc->global_data)
48 return -1;
49
50 struct ImapAccountData *adata = nc->global_data;
51 mutt_debug(LL_DEBUG5, "imap timeout start\n");
52
53 time_t now = mutt_date_now();
54 const short c_imap_keep_alive = cs_subset_number(NeoMutt->sub, "imap_keep_alive");
55
56 if ((adata->state >= IMAP_AUTHENTICATED) && (now >= (adata->lastread + c_imap_keep_alive)))
57 {
58 if (adata->checking)
59 return 0;
60 adata->checking = true;
61 mutt_debug(LL_DEBUG5, "imap_keep_alive\n");
62 imap_check_mailbox(adata->mailbox, true);
63 adata->checking = false;
64 }
65
66 mutt_debug(LL_DEBUG5, "imap timeout done\n");
67 return 0;
68}
69
77{
78 if (nc->event_type != NT_MAILBOX)
79 return 0;
81 return 0;
82 if (!nc->global_data || !nc->event_data)
83 return -1;
84
85 struct ImapAccountData *adata = nc->global_data;
86 const struct EventMailbox *ev_m = nc->event_data;
87
88 if (adata->mailbox == ev_m->mailbox)
89 {
90 mutt_debug(LL_DEBUG3, "stranding adata->mailbox %p\n", (void *) adata->mailbox);
91 adata->mailbox = NULL;
92 }
93 if (adata->prev_mailbox == ev_m->mailbox)
94 {
95 mutt_debug(LL_DEBUG3, "stranding adata->prev_mailbox %p\n", (void *) adata->prev_mailbox);
96 adata->prev_mailbox = NULL;
97 }
98
99 return 0;
100}
101
105void imap_adata_free(void **ptr)
106{
107 if (!ptr || !*ptr)
108 return;
109
110 struct ImapAccountData *adata = *ptr;
111
113 if (adata->account)
115
116 FREE(&adata->capstr);
117 buf_dealloc(&adata->cmdbuf);
118 FREE(&adata->buf);
119 FREE(&adata->cmds);
120
121 if (adata->conn)
122 {
123 if (adata->conn->close)
124 adata->conn->close(adata->conn);
125 FREE(&adata->conn);
126 }
127
128 FREE(ptr);
129}
130
137{
139 adata->account = a;
140
141 static unsigned char new_seqid = 'a';
142
143 adata->seqid = new_seqid;
144 const short c_imap_pipeline_depth = cs_subset_number(NeoMutt->sub, "imap_pipeline_depth");
145 adata->cmdslots = c_imap_pipeline_depth + 2;
146 adata->cmds = MUTT_MEM_CALLOC(adata->cmdslots, struct ImapCommand);
147
148 if (++new_seqid > 'z')
149 new_seqid = 'a';
150
153
154 return adata;
155}
156
163{
164 if (!m || (m->type != MUTT_IMAP) || !m->account)
165 return NULL;
166 return m->account->adata;
167}
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition buffer.c:377
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition helpers.c:143
Convenience wrapper for the config headers.
Connection Library.
Convenience wrapper for the core headers.
@ NT_MAILBOX_DELETE
Mailbox is about to be deleted.
Definition mailbox.h:176
@ MUTT_IMAP
'IMAP' Mailbox type
Definition mailbox.h:49
void imap_adata_free(void **ptr)
Free the private Account data - Implements Account::adata_free() -.
Definition adata.c:105
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int imap_mailbox_delete_observer(struct NotifyCallback *nc)
Notification that a Mailbox is about to be deleted - Implements observer_t -.
Definition adata.c:76
static int imap_timeout_observer(struct NotifyCallback *nc)
Notification that a timeout has occurred - Implements observer_t -.
Definition adata.c:43
struct ImapAccountData * imap_adata_new(struct Account *a)
Allocate and initialise a new ImapAccountData structure.
Definition adata.c:136
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition adata.c:162
Imap-specific Account data.
IMAP network mailbox.
Shared constants/structs that are private to IMAP.
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition private.h:120
enum MxStatus imap_check_mailbox(struct Mailbox *m, bool force)
Use the NOOP or IDLE command to poll for new mail.
Definition imap.c:1220
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition date.c:457
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition notify.c:230
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition notify.c:191
@ NT_TIMEOUT
Timeout has occurred.
Definition notify_type.h:57
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition notify_type.h:50
A group of associated Mailboxes.
Definition account.h:36
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition account.h:41
void * adata
Private data (for Mailbox backends)
Definition account.h:42
An Event that happened to a Mailbox.
Definition mailbox.h:192
struct Mailbox * mailbox
The Mailbox this Event relates to.
Definition mailbox.h:193
IMAP-specific Account data -.
Definition adata.h:40
struct Mailbox * prev_mailbox
Previously selected mailbox.
Definition adata.h:81
struct Mailbox * mailbox
Current selected mailbox.
Definition adata.h:80
IMAP command structure.
Definition private.h:176
A mailbox.
Definition mailbox.h:81
enum MailboxType type
Mailbox type.
Definition mailbox.h:104
struct Account * account
Account that owns this Mailbox.
Definition mailbox.h:129
Container for Accounts, Notifications.
Definition neomutt.h:41
struct Notify * notify_timeout
Timeout notifications handler.
Definition neomutt.h:47
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
Data passed to a notification function.
Definition observer.h:34
void * event_data
Data from notify_send()
Definition observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition observer.h:37
void * global_data
Data from notify_observer_add()
Definition observer.h:39