NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN
notify.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "email/lib.h"
34#include "core/lib.h"
35#include "gui/lib.h"
36#include "lib.h"
37#include "color/lib.h"
38#include "mview.h"
39
40extern const struct Mapping ColorFields[];
41extern const struct Mapping ComposeColorFields[];
42
43static const char *get_event_type(enum NotifyType type)
44{
45 switch (type)
46 {
47 case NT_ACCOUNT:
48 return "account";
49 case NT_ALIAS:
50 return "alias";
51 case NT_ALTERN:
52 return "altern";
53 case NT_ATTACH:
54 return "attach";
55 case NT_BINDING:
56 return "binding";
57 case NT_COLOR:
58 return "color";
59 case NT_COMMAND:
60 return "command";
61 case NT_CONFIG:
62 return "config";
63 case NT_MVIEW:
64 return "mailboxview";
65 case NT_EMAIL:
66 return "email";
67 case NT_ENVELOPE:
68 return "envelope";
69 case NT_GLOBAL:
70 return "global";
71 case NT_HEADER:
72 return "header";
73 case NT_INDEX:
74 return "index";
75 case NT_MAILBOX:
76 return "mailbox";
77 case NT_MENU:
78 return "menu";
79 case NT_PAGER:
80 return "pager";
81 case NT_SCORE:
82 return "score";
83 case NT_SUBJRX:
84 return "subjrx";
85 case NT_WINDOW:
86 return "window";
87 default:
88 return "UNKNOWN";
89 }
90}
91
92const char *get_mailbox_type(enum MailboxType type)
93{
94 switch (type)
95 {
96 case MUTT_COMPRESSED:
97 return "compressed";
98 case MUTT_IMAP:
99 return "imap";
100 case MUTT_MAILDIR:
101 return "maildir";
102 case MUTT_MBOX:
103 return "mbox";
104 case MUTT_MH:
105 return "mh";
106 case MUTT_MMDF:
107 return "mmdf";
108 case MUTT_NNTP:
109 return "nntp";
110 case MUTT_NOTMUCH:
111 return "notmuch";
112 case MUTT_POP:
113 return "pop";
114 default:
115 return "UNKNOWN";
116 }
117}
118
119static const char *get_global_event(int id)
120{
121 switch (id)
122 {
124 return "shutdown";
126 return "startup";
128 return "timeout";
129 default:
130 return "UNKNOWN";
131 }
132}
133
134static const char *get_config_type(int id)
135{
136 switch (id)
137 {
138 case NT_CONFIG_SET:
139 return "set";
140 case NT_CONFIG_RESET:
141 return "reset";
142 default:
143 return "UNKNOWN";
144 }
145}
146
147static const char *get_mailbox_event(int id)
148{
149 switch (id)
150 {
151 case NT_MAILBOX_ADD:
152 return "add";
154 return "delete";
156 return "invalid";
158 return "resort";
160 return "update";
161 case NT_MAILBOX_UNTAG:
162 return "untag";
163 default:
164 return "UNKNOWN";
165 }
166}
167
168static const char *get_mview(int id)
169{
170 switch (id)
171 {
172 case NT_MVIEW_DELETE:
173 return "delete";
174 case NT_MVIEW_ADD:
175 return "add";
176 default:
177 return "UNKNOWN";
178 }
179}
180
181static void notify_dump_account(struct NotifyCallback *nc)
182{
183 struct EventAccount *ev_a = nc->event_data;
184 struct Account *a = ev_a->account;
185 if (!a)
186 return;
187
188 mutt_debug(LL_DEBUG1, " Account: %p (%s) %s\n", a,
190}
191
192static void notify_dump_color(struct NotifyCallback *nc)
193{
194 struct EventColor *ev_c = nc->event_data;
195
196 const char *color = NULL;
197 const char *scope = "";
198
199 if (ev_c->cid == MT_COLOR_MAX)
200 color = "ALL";
201
202 if (!color)
203 color = mutt_map_get_name(ev_c->cid, ColorFields);
204
205 if (!color)
206 {
208 scope = "compose ";
209 }
210
211 if (!color)
212 color = "UNKNOWN";
213
214 mutt_debug(LL_DEBUG1, " Color: %s %s%s (%d)\n",
215 (nc->event_subtype == NT_COLOR_SET) ? "set" : "reset", scope,
216 color, ev_c->cid);
217}
218
219static void notify_dump_command(struct NotifyCallback *nc)
220{
221 struct Command *cmd = nc->event_data;
222
223 if (cmd->data < 4096)
224 mutt_debug(LL_DEBUG1, " Command: %s, data: %ld\n", cmd->name, cmd->data);
225 else
226 mutt_debug(LL_DEBUG1, " Command: %s, data: %p\n", cmd->name, (void *) cmd->data);
227}
228
229static void notify_dump_config(struct NotifyCallback *nc)
230{
231 struct EventConfig *ev_c = nc->event_data;
232
233 struct Buffer value = mutt_buffer_make(128);
234 cs_he_string_get(ev_c->sub->cs, ev_c->he, &value);
235 mutt_debug(LL_DEBUG1, " Config: %s %s = %s\n", get_config_type(nc->event_subtype),
236 ev_c->name, mutt_buffer_string(&value));
237 mutt_buffer_dealloc(&value);
238}
239
240static void notify_dump_mview(struct NotifyCallback *nc)
241{
242 struct EventMview *ev_m = nc->event_data;
243
244 const char *path = "NONE";
245 if (ev_m->mv && ev_m->mv->mailbox)
246 path = mailbox_path(ev_m->mv->mailbox);
247
248 mutt_debug(LL_DEBUG1, " MailboxView: %s %s\n", get_mview(nc->event_subtype), path);
249}
250
251static void notify_dump_email(struct NotifyCallback *nc)
252{
253 struct EventEmail *ev_e = nc->event_data;
254
255 mutt_debug(LL_DEBUG1, " Email: %d\n", ev_e->num_emails);
256 for (size_t i = 0; i < ev_e->num_emails; i++)
257 {
258 mutt_debug(LL_DEBUG1, " : %p\n", ev_e->emails[i]);
259 }
260}
261
262static void notify_dump_global(struct NotifyCallback *nc)
263{
264 mutt_debug(LL_DEBUG1, " Global: %s\n", get_global_event(nc->event_subtype));
265}
266
267static void notify_dump_mailbox(struct NotifyCallback *nc)
268{
269 struct EventMailbox *ev_m = nc->event_data;
270
271 struct Mailbox *m = ev_m->mailbox;
272 const char *path = m ? mailbox_path(m) : "";
273 mutt_debug(LL_DEBUG1, " Mailbox: %s %s\n", get_mailbox_event(nc->event_subtype), path);
274}
275
277{
278 struct EventWindow *ev_w = nc->event_data;
279 const struct MuttWindow *win = ev_w->win;
280 WindowNotifyFlags flags = ev_w->flags;
281
282 struct Buffer buf = mutt_buffer_make(128);
283
284 mutt_buffer_add_printf(&buf, "[%s] ", mutt_window_win_name(win));
285
286 if (flags & WN_VISIBLE)
287 mutt_buffer_addstr(&buf, "visible ");
288 if (flags & WN_HIDDEN)
289 mutt_buffer_addstr(&buf, "hidden ");
290
291 if (flags & WN_MOVED)
292 {
293 mutt_buffer_add_printf(&buf, "moved (C%d,R%d)->(C%d,R%d) ",
294 win->old.col_offset, win->old.row_offset,
295 win->state.col_offset, win->state.row_offset);
296 }
297
298 if (flags & WN_TALLER)
299 mutt_buffer_add_printf(&buf, "taller [%d->%d] ", win->old.rows, win->state.rows);
300 if (flags & WN_SHORTER)
301 mutt_buffer_add_printf(&buf, "shorter [%d->%d] ", win->old.rows, win->state.rows);
302 if (flags & WN_WIDER)
303 mutt_buffer_add_printf(&buf, "wider [%d->%d] ", win->old.cols, win->state.cols);
304 if (flags & WN_NARROWER)
305 mutt_buffer_add_printf(&buf, "narrower [%d->%d] ", win->old.cols, win->state.cols);
306
307 mutt_debug(LL_DEBUG1, " Window: %s\n", mutt_buffer_string(&buf));
308
310}
311
313{
314 struct EventWindow *ev_w = nc->event_data;
315 struct MuttWindow *win = ev_w->win;
316
317 struct Buffer buf = mutt_buffer_make(128);
318
319 mutt_buffer_addstr(&buf, "Focus: ");
320
321 if (win)
322 {
323 struct MuttWindow *dlg = dialog_find(win);
324 if (dlg && (dlg != win))
326
328
329 mutt_buffer_add_printf(&buf, "(C%d,R%d) [%dx%d]", win->state.col_offset,
330 win->state.row_offset, win->state.cols, win->state.rows);
331 }
332 else
333 {
334 mutt_buffer_addstr(&buf, "NONE");
335 }
336
337 mutt_debug(LL_DEBUG1, " Window: %s\n", mutt_buffer_string(&buf));
338
340}
341
343{
344 mutt_debug(LL_DEBUG1, "\033[1;31mNotification:\033[0m %s\n", get_event_type(nc->event_type));
345
346 switch (nc->event_type)
347 {
348 case NT_ACCOUNT:
350 break;
351 case NT_COLOR:
353 break;
354 case NT_COMMAND:
356 break;
357 case NT_CONFIG:
359 break;
360 case NT_MVIEW:
362 break;
363 case NT_EMAIL:
365 break;
366 case NT_GLOBAL:
368 break;
369 case NT_MAILBOX:
371 break;
372 case NT_WINDOW:
375 else if (nc->event_subtype == NT_WINDOW_FOCUS)
377 break;
378 default:
379 mutt_debug(LL_DEBUG1, " Event Type: %d\n", nc->event_type);
380 mutt_debug(LL_DEBUG1, " Event Sub-type: %d\n", nc->event_subtype);
381 mutt_debug(LL_DEBUG1, " Event Data: %p\n", nc->event_data);
382 break;
383 }
384
385 mutt_debug(LL_DEBUG1, " Global Data: %p\n", nc->global_data);
386
387 mutt_debug(LL_DEBUG5, "debug done\n");
388 return 0;
389}
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:67
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:309
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:233
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:211
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
Color and attribute parsing.
@ MT_COLOR_MAX
Definition: color.h:88
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
const char * get_mailbox_type(enum MailboxType type)
Definition: notify.c:92
static void notify_dump_global(struct NotifyCallback *nc)
Definition: notify.c:262
const struct Mapping ComposeColorFields[]
Mapping of compose colour names to their IDs.
Definition: command.c:99
const struct Mapping ColorFields[]
Mapping of colour names to their IDs.
Definition: command.c:45
static void notify_dump_config(struct NotifyCallback *nc)
Definition: notify.c:229
static void notify_dump_mview(struct NotifyCallback *nc)
Definition: notify.c:240
static void notify_dump_command(struct NotifyCallback *nc)
Definition: notify.c:219
static const char * get_event_type(enum NotifyType type)
Definition: notify.c:43
static void notify_dump_color(struct NotifyCallback *nc)
Definition: notify.c:192
int debug_all_observer(struct NotifyCallback *nc)
Definition: notify.c:342
static const char * get_global_event(int id)
Definition: notify.c:119
static const char * get_mview(int id)
Definition: notify.c:168
static void notify_dump_mailbox(struct NotifyCallback *nc)
Definition: notify.c:267
static const char * get_config_type(int id)
Definition: notify.c:134
static void notify_dump_window_focus(struct NotifyCallback *nc)
Definition: notify.c:312
static const char * get_mailbox_event(int id)
Definition: notify.c:147
static void notify_dump_account(struct NotifyCallback *nc)
Definition: notify.c:181
static void notify_dump_email(struct NotifyCallback *nc)
Definition: notify.c:251
static void notify_dump_window_state(struct NotifyCallback *nc)
Definition: notify.c:276
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition: dialog.c:83
Structs that make up an email.
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
Convenience wrapper for the gui headers.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
@ NT_MAILBOX_UNTAG
Clear the 'last-tagged' pointer.
Definition: mailbox.h:179
@ NT_MAILBOX_RESORT
Email list needs resorting.
Definition: mailbox.h:177
@ NT_MAILBOX_DELETE
Mailbox is about to be deleted.
Definition: mailbox.h:170
@ NT_MAILBOX_INVALID
Email list was changed.
Definition: mailbox.h:176
@ NT_MAILBOX_UPDATE
Update internal tables.
Definition: mailbox.h:178
@ NT_MAILBOX_ADD
Mailbox has been added.
Definition: mailbox.h:169
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:210
MailboxType
Supported mailbox formats.
Definition: mailbox.h:41
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
@ MUTT_MMDF
'mmdf' Mailbox type
Definition: mailbox.h:46
@ MUTT_POP
'POP3' Mailbox type
Definition: mailbox.h:52
@ MUTT_MH
'MH' Mailbox type
Definition: mailbox.h:47
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
@ MUTT_MBOX
'mbox' Mailbox type
Definition: mailbox.h:45
@ MUTT_COMPRESSED
Compressed file Mailbox type.
Definition: mailbox.h:53
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition: mailbox.h:48
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
Convenience wrapper for the library headers.
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:710
#define WN_MOVED
Window moved.
Definition: mutt_window.h:191
uint8_t WindowNotifyFlags
Flags for Changes to a MuttWindow, e.g. WN_TALLER.
Definition: mutt_window.h:185
#define WN_WIDER
Window became wider.
Definition: mutt_window.h:189
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
@ NT_WINDOW_FOCUS
Window focus has changed.
Definition: mutt_window.h:209
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:192
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:193
#define WN_TALLER
Window became taller.
Definition: mutt_window.h:187
#define WN_NARROWER
Window became narrower.
Definition: mutt_window.h:190
#define WN_SHORTER
Window became shorter.
Definition: mutt_window.h:188
The "currently-open" mailbox.
@ NT_MVIEW_DELETE
The Mview is about to be destroyed.
Definition: mview.h:61
@ NT_MVIEW_ADD
The Mview has been opened.
Definition: mview.h:60
@ NT_GLOBAL_STARTUP
NeoMutt is initialised.
Definition: neomutt.h:52
@ NT_GLOBAL_TIMEOUT
A timer has elapsed.
Definition: neomutt.h:54
@ NT_GLOBAL_SHUTDOWN
NeoMutt is about to close.
Definition: neomutt.h:53
@ NT_COLOR_SET
Color has been set.
Definition: notify2.h:41
NotifyType
Notification Types.
Definition: notify_type.h:34
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
@ NT_MENU
Menu has changed, MenuRedrawFlags.
Definition: notify_type.h:51
@ NT_ATTACH
Attachment command changed, NotifyAttach.
Definition: notify_type.h:39
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:41
@ NT_EMAIL
Email has changed, NotifyEmail, EventEmail.
Definition: notify_type.h:44
@ NT_BINDING
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:40
@ NT_ENVELOPE
Envelope has changed, NotifyEnvelope.
Definition: notify_type.h:45
@ NT_SCORE
Email scoring has changed.
Definition: notify_type.h:53
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:49
@ NT_PAGER
Pager data has changed, NotifyPager, PagerPrivateData.
Definition: notify_type.h:52
@ NT_COMMAND
A Command has been executed, Command.
Definition: notify_type.h:42
@ NT_HEADER
A header has changed, NotifyHeader EventHeader.
Definition: notify_type.h:47
@ NT_ACCOUNT
Account has changed, NotifyAccount, EventAccount.
Definition: notify_type.h:36
@ NT_INDEX
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:48
@ NT_MVIEW
MailboxView has changed, NotifyMview, EventMview.
Definition: notify_type.h:50
@ NT_GLOBAL
Not object-related, NotifyGlobal.
Definition: notify_type.h:46
@ NT_ALTERN
Alternates command changed, NotifyAlternates.
Definition: notify_type.h:38
@ NT_SUBJRX
Subject Regex has changed, NotifySubjRx.
Definition: notify_type.h:54
@ NT_ALIAS
Alias has changed, NotifyAlias, EventAlias.
Definition: notify_type.h:37
int cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: set.c:618
Key value store.
#define NONULL(x)
Definition: string2.h:37
A group of associated Mailboxes.
Definition: account.h:37
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
char * name
Name of Account.
Definition: account.h:39
String manipulation buffer.
Definition: buffer.h:34
intptr_t data
Data or flags to pass to the command.
Definition: command.h:65
const char * name
Name of the command.
Definition: command.h:50
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
An Event that happened to an Account.
Definition: account.h:79
struct Account * account
The Account this Event relates to.
Definition: account.h:80
An Event that happened to a Colour.
Definition: notify2.h:53
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:54
A config-change event.
Definition: subset.h:70
const struct ConfigSubset * sub
Config Subset.
Definition: subset.h:71
const char * name
Name of config item that changed.
Definition: subset.h:72
struct HashElem * he
Config item that changed.
Definition: subset.h:73
An Event that happened to an Email.
Definition: email.h:161
int num_emails
Number of Emails the event applies to.
Definition: email.h:162
struct Email ** emails
Emails affected by the event.
Definition: email.h:163
An Event that happened to a Mailbox.
Definition: mailbox.h:186
struct Mailbox * mailbox
The Mailbox this Event relates to.
Definition: mailbox.h:187
An Event that happened to an MailboxView.
Definition: mview.h:69
struct MailboxView * mv
The MailboxView this Event relates to.
Definition: mview.h:70
An Event that happened to a Window.
Definition: mutt_window.h:216
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
WindowNotifyFlags flags
Attributes of Window that changed.
Definition: mutt_window.h:218
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:49
A mailbox.
Definition: mailbox.h:79
Mapping between user-readable string and a constant.
Definition: mapping.h:32
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:128
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
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
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:63
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:62
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
@ NT_CONFIG_RESET
Config item has been reset to initial, or parent, value.
Definition: subset.h:63
@ NT_CONFIG_SET
Config item has been set.
Definition: subset.h:62