NeoMutt  2025-12-11-435-g4ac674
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_limited_count_num(const struct ExpandoNode *node,
128 void *data, MuttFormatFlags flags)
129{
130 const struct SidebarData *sdata = data;
131 const struct SbEntry *sbe = sdata->entry;
132 const struct IndexSharedData *shared = sdata->shared;
133 const struct Mailbox *m = sbe->mailbox;
134 const struct Mailbox *m_cur = shared->mailbox;
135
136 const bool c = m_cur && mutt_str_equal(m_cur->realpath, m->realpath);
137
138 return c ? m_cur->vcount : m->msg_count;
139}
140
144static long sidebar_message_count_num(const struct ExpandoNode *node,
145 void *data, MuttFormatFlags flags)
146{
147 const struct SidebarData *sdata = data;
148 const struct SbEntry *sbe = sdata->entry;
149 const struct Mailbox *m = sbe->mailbox;
150
151 return m->msg_count;
152}
153
157static void sidebar_name(const struct ExpandoNode *node, void *data,
158 MuttFormatFlags flags, struct Buffer *buf)
159{
160 const struct SidebarData *sdata = data;
161 const struct SbEntry *sbe = sdata->entry;
162
163 add_indent(buf, sbe->depth);
164 buf_addstr(buf, sbe->box);
165}
166
170static void sidebar_new_mail(const struct ExpandoNode *node, void *data,
171 MuttFormatFlags flags, struct Buffer *buf)
172{
173 const struct SidebarData *sdata = data;
174 const struct SbEntry *sbe = sdata->entry;
175 const struct Mailbox *m = sbe->mailbox;
176
177 // NOTE(g0mb4): use $flag_chars?
178 const char *s = m->has_new ? "N" : " ";
179 buf_strcpy(buf, s);
180}
181
185static long sidebar_new_mail_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
186{
187 const struct SidebarData *sdata = data;
188 const struct SbEntry *sbe = sdata->entry;
189 const struct Mailbox *m = sbe->mailbox;
190
191 return m->has_new;
192}
193
197static long sidebar_notify_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->notify_user;
204}
205
209static long sidebar_old_count_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->msg_unread - m->msg_new;
216}
217
221static long sidebar_poll_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->poll_new_mail;
228}
229
233static long sidebar_read_count_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->msg_count - m->msg_unread;
240}
241
245static long sidebar_tagged_count_num(const struct ExpandoNode *node, void *data,
246 MuttFormatFlags flags)
247{
248 const struct SidebarData *sdata = data;
249 const struct SbEntry *sbe = sdata->entry;
250 const struct IndexSharedData *shared = sdata->shared;
251 const struct Mailbox *m = sbe->mailbox;
252 const struct Mailbox *m_cur = shared->mailbox;
253
254 const bool c = m_cur && mutt_str_equal(m_cur->realpath, m->realpath);
255
256 return c ? m_cur->msg_tagged : 0;
257}
258
262static long sidebar_unread_count_num(const struct ExpandoNode *node, void *data,
263 MuttFormatFlags flags)
264{
265 const struct SidebarData *sdata = data;
266 const struct SbEntry *sbe = sdata->entry;
267 const struct Mailbox *m = sbe->mailbox;
268
269 return m->msg_unread;
270}
271
275static long sidebar_unseen_count_num(const struct ExpandoNode *node, void *data,
276 MuttFormatFlags flags)
277{
278 const struct SidebarData *sdata = data;
279 const struct SbEntry *sbe = sdata->entry;
280 const struct Mailbox *m = sbe->mailbox;
281
282 return m->msg_new;
283}
284
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:245
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:144
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:262
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:221
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:127
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:185
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:233
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:275
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:209
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:197
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:157
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:170
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:662
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:290
Sidebar Expando definitions.
GUI display the mailboxes in a side panel.
@ ED_SID_FLAGGED_COUNT
Mailbox.msg_flagged.
Definition private.h:62
@ ED_SID_READ_COUNT
Mailbox.msg_count, Mailbox.msg_unread.
Definition private.h:70
@ ED_SID_DESCRIPTION
Mailbox.name.
Definition private.h:60
@ ED_SID_NEW_MAIL
Mailbox.has_new.
Definition private.h:66
@ ED_SID_UNSEEN_COUNT
Mailbox.msg_new.
Definition private.h:73
@ ED_SID_POLL
Mailbox.poll_new_mail.
Definition private.h:69
@ ED_SID_OLD_COUNT
Mailbox.msg_unread, Mailbox.msg_new.
Definition private.h:68
@ ED_SID_MESSAGE_COUNT
Mailbox.msg_count.
Definition private.h:64
@ ED_SID_LIMITED_COUNT
Mailbox.vcount.
Definition private.h:63
@ ED_SID_UNREAD_COUNT
Mailbox.msg_unread.
Definition private.h:72
@ ED_SID_TAGGED_COUNT
Mailbox.msg_tagged.
Definition private.h:71
@ ED_SID_NOTIFY
Mailbox.notify_user.
Definition private.h:67
@ ED_SID_NAME
SbEntry.box.
Definition private.h:65
@ ED_SID_DELETED_COUNT
Mailbox.msg_deleted.
Definition private.h:59
@ ED_SID_FLAGGED
Mailbox.msg_flagged.
Definition private.h:61
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
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