NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
expando.c
Go to the documentation of this file.
1
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 == 0)
98 {
99 buf_strcpy(buf, "");
100 }
101 else if (m->msg_flagged == 1)
102 {
103 buf_strcpy(buf, "!");
104 }
105 else if (m->msg_flagged == 2)
106 {
107 buf_strcpy(buf, "!!");
108 }
109 else
110 {
111 buf_printf(buf, "%d!", m->msg_flagged);
112 }
113}
114
118static long sidebar_flagged_count_num(const struct ExpandoNode *node,
119 void *data, MuttFormatFlags flags)
120{
121 const struct SidebarData *sdata = data;
122 const struct SbEntry *sbe = sdata->entry;
123 const struct Mailbox *m = sbe->mailbox;
124
125 return m->msg_flagged;
126}
127
131static long sidebar_limited_count_num(const struct ExpandoNode *node,
132 void *data, MuttFormatFlags flags)
133{
134 const struct SidebarData *sdata = data;
135 const struct SbEntry *sbe = sdata->entry;
136 const struct IndexSharedData *shared = sdata->shared;
137 const struct Mailbox *m = sbe->mailbox;
138 const struct Mailbox *m_cur = shared->mailbox;
139
140 const bool c = m_cur && mutt_str_equal(m_cur->realpath, m->realpath);
141
142 return c ? m_cur->vcount : m->msg_count;
143}
144
148static long sidebar_message_count_num(const struct ExpandoNode *node,
149 void *data, MuttFormatFlags flags)
150{
151 const struct SidebarData *sdata = data;
152 const struct SbEntry *sbe = sdata->entry;
153 const struct Mailbox *m = sbe->mailbox;
154
155 return m->msg_count;
156}
157
161static void sidebar_name(const struct ExpandoNode *node, void *data,
162 MuttFormatFlags flags, struct Buffer *buf)
163{
164 const struct SidebarData *sdata = data;
165 const struct SbEntry *sbe = sdata->entry;
166
167 add_indent(buf, sbe->depth);
168 buf_addstr(buf, sbe->box);
169}
170
174static void sidebar_new_mail(const struct ExpandoNode *node, void *data,
175 MuttFormatFlags flags, struct Buffer *buf)
176{
177 const struct SidebarData *sdata = data;
178 const struct SbEntry *sbe = sdata->entry;
179 const struct Mailbox *m = sbe->mailbox;
180
181 // NOTE(g0mb4): use $flag_chars?
182 const char *s = m->has_new ? "N" : " ";
183 buf_strcpy(buf, s);
184}
185
189static long sidebar_new_mail_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
190{
191 const struct SidebarData *sdata = data;
192 const struct SbEntry *sbe = sdata->entry;
193 const struct Mailbox *m = sbe->mailbox;
194
195 return m->has_new;
196}
197
201static long sidebar_notify_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
202{
203 const struct SidebarData *sdata = data;
204 const struct SbEntry *sbe = sdata->entry;
205 const struct Mailbox *m = sbe->mailbox;
206
207 return m->notify_user;
208}
209
213static long sidebar_old_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
214{
215 const struct SidebarData *sdata = data;
216 const struct SbEntry *sbe = sdata->entry;
217 const struct Mailbox *m = sbe->mailbox;
218
219 return m->msg_unread - m->msg_new;
220}
221
225static long sidebar_poll_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
226{
227 const struct SidebarData *sdata = data;
228 const struct SbEntry *sbe = sdata->entry;
229 const struct Mailbox *m = sbe->mailbox;
230
231 return m->poll_new_mail;
232}
233
237static long sidebar_read_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
238{
239 const struct SidebarData *sdata = data;
240 const struct SbEntry *sbe = sdata->entry;
241 const struct Mailbox *m = sbe->mailbox;
242
243 return m->msg_count - m->msg_unread;
244}
245
249static long sidebar_tagged_count_num(const struct ExpandoNode *node, void *data,
250 MuttFormatFlags flags)
251{
252 const struct SidebarData *sdata = data;
253 const struct SbEntry *sbe = sdata->entry;
254 const struct IndexSharedData *shared = sdata->shared;
255 const struct Mailbox *m = sbe->mailbox;
256 const struct Mailbox *m_cur = shared->mailbox;
257
258 const bool c = m_cur && mutt_str_equal(m_cur->realpath, m->realpath);
259
260 return c ? m_cur->msg_tagged : 0;
261}
262
266static long sidebar_unread_count_num(const struct ExpandoNode *node, void *data,
267 MuttFormatFlags flags)
268{
269 const struct SidebarData *sdata = data;
270 const struct SbEntry *sbe = sdata->entry;
271 const struct Mailbox *m = sbe->mailbox;
272
273 return m->msg_unread;
274}
275
279static long sidebar_unseen_count_num(const struct ExpandoNode *node, void *data,
280 MuttFormatFlags flags)
281{
282 const struct SidebarData *sdata = data;
283 const struct SbEntry *sbe = sdata->entry;
284 const struct Mailbox *m = sbe->mailbox;
285
286 return m->msg_new;
287}
288
295 // clang-format off
311 { -1, -1, NULL, NULL },
312 // clang-format on
313};
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:54
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:249
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:148
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:266
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:225
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:131
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:189
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:118
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:237
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:279
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:213
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:201
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:161
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:174
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:661
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:294
Sidebar Expando definitions.
GUI display the mailboxes in a side panel.
@ ED_SID_FLAGGED_COUNT
Mailbox.msg_flagged.
Definition: private.h:61
@ ED_SID_READ_COUNT
Mailbox.msg_count, Mailbox.msg_unread.
Definition: private.h:69
@ ED_SID_DESCRIPTION
Mailbox.name.
Definition: private.h:59
@ ED_SID_NEW_MAIL
Mailbox.has_new.
Definition: private.h:65
@ ED_SID_UNSEEN_COUNT
Mailbox.msg_new.
Definition: private.h:72
@ ED_SID_POLL
Mailbox.poll_new_mail.
Definition: private.h:68
@ ED_SID_OLD_COUNT
Mailbox.msg_unread, Mailbox.msg_new.
Definition: private.h:67
@ ED_SID_MESSAGE_COUNT
Mailbox.msg_count.
Definition: private.h:63
@ ED_SID_LIMITED_COUNT
Mailbox.vcount.
Definition: private.h:62
@ ED_SID_UNREAD_COUNT
Mailbox.msg_unread.
Definition: private.h:71
@ ED_SID_TAGGED_COUNT
Mailbox.msg_tagged.
Definition: private.h:70
@ ED_SID_NOTIFY
Mailbox.notify_user.
Definition: private.h:66
@ ED_SID_NAME
SbEntry.box.
Definition: private.h:64
@ ED_SID_DELETED_COUNT
Mailbox.msg_deleted.
Definition: private.h:58
@ ED_SID_FLAGGED
Mailbox.msg_flagged.
Definition: private.h:60
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:79
int vcount
The number of virtual messages.
Definition: mailbox.h:99
bool has_new
Mailbox has new mail.
Definition: mailbox.h:85
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
int msg_new
Number of new messages.
Definition: mailbox.h:92
int msg_count
Total number of messages.
Definition: mailbox.h:88
bool poll_new_mail
Check for new mail.
Definition: mailbox.h:115
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
bool notify_user
Notify the user of new mail.
Definition: mailbox.h:113
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:93
int msg_flagged
Number of flagged messages.
Definition: mailbox.h:90
int msg_tagged
How many messages are tagged?
Definition: mailbox.h:94
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
Container for Accounts, Notifications.
Definition: neomutt.h:43
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:47
Info about folders in the sidebar.
Definition: private.h:41
int depth
Indentation depth.
Definition: private.h:44
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:45
char box[256]
Mailbox path (possibly abbreviated)
Definition: private.h:42
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