NeoMutt  2025-12-11-596-g7cc1dd
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
expando.c
Go to the documentation of this file.
1
22
28
29#include <stdbool.h>
30#include <stdio.h>
31#include "private.h"
32#include "mutt/lib.h"
33#include "config/lib.h"
34#include "core/lib.h"
35#include "expando.h"
36#include "expando/lib.h"
37#include "index/lib.h"
38
44static void add_indent(struct Buffer *buf, int depth)
45{
46 const char *const c_sidebar_indent_string = cs_subset_string(NeoMutt->sub, "sidebar_indent_string");
47 for (int i = 0; i < depth; i++)
48 {
49 buf_addstr(buf, c_sidebar_indent_string);
50 }
51}
52
56static long sidebar_deleted_count_num(const struct ExpandoNode *node,
57 void *data, MuttFormatFlags flags)
58{
59 const struct SidebarData *sdata = data;
60 const struct SbEntry *sbe = sdata->entry;
61 const struct IndexSharedData *shared = sdata->shared;
62 const struct Mailbox *m = sbe->mailbox;
63 const struct Mailbox *m_cur = shared->mailbox;
64
65 const bool c = m_cur && mutt_str_equal(m_cur->realpath, m->realpath);
66
67 return c ? m_cur->msg_deleted : 0;
68}
69
73static void sidebar_description(const struct ExpandoNode *node, void *data,
74 MuttFormatFlags flags, struct Buffer *buf)
75{
76 const struct SidebarData *sdata = data;
77 const struct SbEntry *sbe = sdata->entry;
78
79 add_indent(buf, sbe->depth);
80
81 if (sbe->mailbox->name)
82 buf_addstr(buf, sbe->mailbox->name);
83 else
84 buf_addstr(buf, sbe->box);
85}
86
90static void sidebar_flagged(const struct ExpandoNode *node, void *data,
91 MuttFormatFlags flags, struct Buffer *buf)
92{
93 const struct SidebarData *sdata = data;
94 const struct SbEntry *sbe = sdata->entry;
95 const struct Mailbox *m = sbe->mailbox;
96
97 if (m->msg_flagged == 1)
98 {
99 buf_strcpy(buf, "!");
100 }
101 else if (m->msg_flagged == 2)
102 {
103 buf_strcpy(buf, "!!");
104 }
105 else if (m->msg_flagged > 2)
106 {
107 buf_printf(buf, "%d!", m->msg_flagged);
108 }
109}
110
114static long sidebar_flagged_count_num(const struct ExpandoNode *node,
115 void *data, MuttFormatFlags flags)
116{
117 const struct SidebarData *sdata = data;
118 const struct SbEntry *sbe = sdata->entry;
119 const struct Mailbox *m = sbe->mailbox;
120
121 return m->msg_flagged;
122}
123
127static long sidebar_fuzzy_score_num(const struct ExpandoNode *node, void *data,
128 MuttFormatFlags flags)
129{
130 const struct SidebarData *sdata = data;
131 const struct SbEntry *sbe = sdata->entry;
132
133 return sbe->score;
134}
135
139static long sidebar_limited_count_num(const struct ExpandoNode *node,
140 void *data, MuttFormatFlags flags)
141{
142 const struct SidebarData *sdata = data;
143 const struct SbEntry *sbe = sdata->entry;
144 const struct IndexSharedData *shared = sdata->shared;
145 const struct Mailbox *m = sbe->mailbox;
146 const struct Mailbox *m_cur = shared->mailbox;
147
148 const bool c = m_cur && mutt_str_equal(m_cur->realpath, m->realpath);
149
150 return c ? m_cur->vcount : m->msg_count;
151}
152
156static long sidebar_message_count_num(const struct ExpandoNode *node,
157 void *data, MuttFormatFlags flags)
158{
159 const struct SidebarData *sdata = data;
160 const struct SbEntry *sbe = sdata->entry;
161 const struct Mailbox *m = sbe->mailbox;
162
163 return m->msg_count;
164}
165
169static void sidebar_name(const struct ExpandoNode *node, void *data,
170 MuttFormatFlags flags, struct Buffer *buf)
171{
172 const struct SidebarData *sdata = data;
173 const struct SbEntry *sbe = sdata->entry;
174
175 add_indent(buf, sbe->depth);
176 buf_addstr(buf, sbe->box);
177}
178
182static void sidebar_new_mail(const struct ExpandoNode *node, void *data,
183 MuttFormatFlags flags, struct Buffer *buf)
184{
185 const struct SidebarData *sdata = data;
186 const struct SbEntry *sbe = sdata->entry;
187 const struct Mailbox *m = sbe->mailbox;
188
189 // NOTE(g0mb4): use $flag_chars?
190 const char *s = m->has_new ? "N" : " ";
191 buf_strcpy(buf, s);
192}
193
197static long sidebar_new_mail_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
198{
199 const struct SidebarData *sdata = data;
200 const struct SbEntry *sbe = sdata->entry;
201 const struct Mailbox *m = sbe->mailbox;
202
203 return m->has_new;
204}
205
209static long sidebar_notify_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
210{
211 const struct SidebarData *sdata = data;
212 const struct SbEntry *sbe = sdata->entry;
213 const struct Mailbox *m = sbe->mailbox;
214
215 return m->notify_user;
216}
217
221static long sidebar_old_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
222{
223 const struct SidebarData *sdata = data;
224 const struct SbEntry *sbe = sdata->entry;
225 const struct Mailbox *m = sbe->mailbox;
226
227 return m->msg_unread - m->msg_new;
228}
229
233static long sidebar_poll_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
234{
235 const struct SidebarData *sdata = data;
236 const struct SbEntry *sbe = sdata->entry;
237 const struct Mailbox *m = sbe->mailbox;
238
239 return m->poll_new_mail;
240}
241
245static long sidebar_read_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
246{
247 const struct SidebarData *sdata = data;
248 const struct SbEntry *sbe = sdata->entry;
249 const struct Mailbox *m = sbe->mailbox;
250
251 return m->msg_count - m->msg_unread;
252}
253
257static long sidebar_tagged_count_num(const struct ExpandoNode *node, void *data,
258 MuttFormatFlags flags)
259{
260 const struct SidebarData *sdata = data;
261 const struct SbEntry *sbe = sdata->entry;
262 const struct IndexSharedData *shared = sdata->shared;
263 const struct Mailbox *m = sbe->mailbox;
264 const struct Mailbox *m_cur = shared->mailbox;
265
266 const bool c = m_cur && mutt_str_equal(m_cur->realpath, m->realpath);
267
268 return c ? m_cur->msg_tagged : 0;
269}
270
274static long sidebar_unread_count_num(const struct ExpandoNode *node, void *data,
275 MuttFormatFlags flags)
276{
277 const struct SidebarData *sdata = data;
278 const struct SbEntry *sbe = sdata->entry;
279 const struct Mailbox *m = sbe->mailbox;
280
281 return m->msg_unread;
282}
283
287static long sidebar_unseen_count_num(const struct ExpandoNode *node, void *data,
288 MuttFormatFlags flags)
289{
290 const struct SidebarData *sdata = data;
291 const struct SbEntry *sbe = sdata->entry;
292 const struct Mailbox *m = sbe->mailbox;
293
294 return m->msg_new;
295}
296
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
@ ED_SIDEBAR
Sidebar ED_SID_ ExpandoDataSidebar.
Definition domain.h:55
Parse Expando string.
static long sidebar_tagged_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Number of tagged messages - Implements get_number_t -.
Definition expando.c:257
static long sidebar_message_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: number of messages - Implements get_number_t -.
Definition expando.c:156
static long sidebar_unread_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Number of unread messages - Implements get_number_t -.
Definition expando.c:274
static long sidebar_poll_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Poll for new mail - Implements get_number_t -.
Definition expando.c:233
static long sidebar_deleted_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Number of deleted messages - Implements get_number_t -.
Definition expando.c:56
static long sidebar_limited_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Number of limited messages - Implements get_number_t -.
Definition expando.c:139
static long sidebar_new_mail_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: New mail flag - Implements get_number_t -.
Definition expando.c:197
static long sidebar_flagged_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Number of flagged messages - Implements get_number_t -.
Definition expando.c:114
static long sidebar_read_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Number of read messages - Implements get_number_t -.
Definition expando.c:245
static long sidebar_unseen_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Number of new messages - Implements get_number_t -.
Definition expando.c:287
static long sidebar_old_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Number of old messages - Implements get_number_t -.
Definition expando.c:221
static long sidebar_notify_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Alert for new mail - Implements get_number_t -.
Definition expando.c:209
static long sidebar_fuzzy_score_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Sidebar: Fuzzy Score - Implements get_number_t -.
Definition expando.c:127
static void sidebar_name(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Sidebar: Name of the mailbox - Implements get_string_t -.
Definition expando.c:169
static void sidebar_new_mail(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Sidebar: New mail flag - Implements get_string_t -.
Definition expando.c:182
static void sidebar_description(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Sidebar: Descriptive name - Implements get_string_t -.
Definition expando.c:73
static void sidebar_flagged(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Sidebar: Flagged flags - Implements get_string_t -.
Definition expando.c:90
GUI manage the main index (list of emails)
Convenience wrapper for the library headers.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition render.h:32
static void add_indent(struct Buffer *buf, int depth)
Generate the needed indentation.
Definition expando.c:44
const struct ExpandoRenderCallback SidebarRenderCallbacks[]
Callbacks for Sidebar Expandos.
Definition expando.c:302
Sidebar Expando definitions.
GUI display the mailboxes in a side panel.
@ ED_SID_FLAGGED_COUNT
Mailbox.msg_flagged.
Definition private.h:63
@ ED_SID_FUZZY_SCORE
SbEntry.score.
Definition private.h:67
@ ED_SID_READ_COUNT
Mailbox.msg_count, Mailbox.msg_unread.
Definition private.h:72
@ ED_SID_DESCRIPTION
Mailbox.name.
Definition private.h:61
@ ED_SID_NEW_MAIL
Mailbox.has_new.
Definition private.h:68
@ ED_SID_UNSEEN_COUNT
Mailbox.msg_new.
Definition private.h:75
@ ED_SID_POLL
Mailbox.poll_new_mail.
Definition private.h:71
@ ED_SID_OLD_COUNT
Mailbox.msg_unread, Mailbox.msg_new.
Definition private.h:70
@ ED_SID_MESSAGE_COUNT
Mailbox.msg_count.
Definition private.h:65
@ ED_SID_LIMITED_COUNT
Mailbox.vcount.
Definition private.h:64
@ ED_SID_UNREAD_COUNT
Mailbox.msg_unread.
Definition private.h:74
@ ED_SID_TAGGED_COUNT
Mailbox.msg_tagged.
Definition private.h:73
@ ED_SID_NOTIFY
Mailbox.notify_user.
Definition private.h:69
@ ED_SID_NAME
SbEntry.box.
Definition private.h:66
@ ED_SID_DELETED_COUNT
Mailbox.msg_deleted.
Definition private.h:60
@ ED_SID_FLAGGED
Mailbox.msg_flagged.
Definition private.h:62
String manipulation buffer.
Definition buffer.h:36
Basic Expando Node.
Definition node.h:67
Data shared between Index, Pager and Sidebar.
Definition shared_data.h:37
struct Mailbox * mailbox
Current Mailbox.
Definition shared_data.h:41
A mailbox.
Definition mailbox.h:78
int vcount
The number of virtual messages.
Definition mailbox.h:98
bool has_new
Mailbox has new mail.
Definition mailbox.h:84
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:80
int msg_new
Number of new messages.
Definition mailbox.h:91
int msg_count
Total number of messages.
Definition mailbox.h:87
bool poll_new_mail
Check for new mail.
Definition mailbox.h:114
char * name
A short name for the Mailbox.
Definition mailbox.h:81
bool notify_user
Notify the user of new mail.
Definition mailbox.h:112
int msg_deleted
Number of deleted messages.
Definition mailbox.h:92
int msg_flagged
Number of flagged messages.
Definition mailbox.h:89
int msg_tagged
How many messages are tagged?
Definition mailbox.h:93
int msg_unread
Number of unread messages.
Definition mailbox.h:88
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
Info about folders in the sidebar.
Definition private.h:42
int depth
Indentation depth.
Definition private.h:45
int score
Fuzzy-match score.
Definition private.h:49
struct Mailbox * mailbox
Mailbox this represents.
Definition private.h:46
char box[256]
Mailbox path (possibly abbreviated)
Definition private.h:43
Data passed to sidebar_format_str()
Definition expando.h:34
struct IndexSharedData * shared
Shared Index Data.
Definition expando.h:36
struct SbEntry * entry
Info about a folder.
Definition expando.h:35