NeoMutt  2024-11-14-138-ge5ca67
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
46static size_t add_indent(char *buf, size_t buflen, const struct SbEntry *sbe)
47{
48 size_t res = 0;
49 const char *const c_sidebar_indent_string = cs_subset_string(NeoMutt->sub, "sidebar_indent_string");
50 for (int i = 0; i < sbe->depth; i++)
51 {
52 res += mutt_str_copy(buf + res, c_sidebar_indent_string, buflen - res);
53 }
54 return res;
55}
56
60static long sidebar_deleted_count_num(const struct ExpandoNode *node,
61 void *data, MuttFormatFlags flags)
62{
63 const struct SidebarData *sdata = data;
64 const struct SbEntry *sbe = sdata->entry;
65 const struct IndexSharedData *shared = sdata->shared;
66 const struct Mailbox *m = sbe->mailbox;
67 const struct Mailbox *m_cur = shared->mailbox;
68
69 const bool c = m_cur && mutt_str_equal(m_cur->realpath, m->realpath);
70
71 return c ? m_cur->msg_deleted : 0;
72}
73
77static void sidebar_description(const struct ExpandoNode *node, void *data,
78 MuttFormatFlags flags, struct Buffer *buf)
79{
80 const struct SidebarData *sdata = data;
81 const struct SbEntry *sbe = sdata->entry;
82
83 char tmp[256] = { 0 };
84
85 const size_t ilen = sizeof(tmp);
86 const size_t off = add_indent(tmp, ilen, sbe);
87
88 if (sbe->mailbox->name)
89 {
90 snprintf(tmp + off, ilen - off, "%s", sbe->mailbox->name);
91 }
92 else
93 {
94 snprintf(tmp + off, ilen - off, "%s", sbe->box);
95 }
96
97 buf_strcpy(buf, tmp);
98}
99
103static void sidebar_flagged(const struct ExpandoNode *node, void *data,
104 MuttFormatFlags flags, struct Buffer *buf)
105{
106 const struct SidebarData *sdata = data;
107 const struct SbEntry *sbe = sdata->entry;
108 const struct Mailbox *m = sbe->mailbox;
109
110 if (m->msg_flagged == 0)
111 {
112 buf_strcpy(buf, "");
113 }
114 else if (m->msg_flagged == 1)
115 {
116 buf_strcpy(buf, "!");
117 }
118 else if (m->msg_flagged == 2)
119 {
120 buf_strcpy(buf, "!!");
121 }
122 else
123 {
124 buf_printf(buf, "%d!", m->msg_flagged);
125 }
126}
127
131static long sidebar_flagged_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 Mailbox *m = sbe->mailbox;
137
138 return m->msg_flagged;
139}
140
144static long sidebar_limited_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 IndexSharedData *shared = sdata->shared;
150 const struct Mailbox *m = sbe->mailbox;
151 const struct Mailbox *m_cur = shared->mailbox;
152
153 const bool c = m_cur && mutt_str_equal(m_cur->realpath, m->realpath);
154
155 return c ? m_cur->vcount : m->msg_count;
156}
157
161static long sidebar_message_count_num(const struct ExpandoNode *node,
162 void *data, MuttFormatFlags flags)
163{
164 const struct SidebarData *sdata = data;
165 const struct SbEntry *sbe = sdata->entry;
166 const struct Mailbox *m = sbe->mailbox;
167
168 return m->msg_count;
169}
170
174static void sidebar_name(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
180 char tmp[256] = { 0 };
181
182 const size_t ilen = sizeof(tmp);
183 const size_t off = add_indent(tmp, ilen, sbe);
184 snprintf(tmp + off, ilen - off, "%s", sbe->box);
185
186 buf_strcpy(buf, tmp);
187}
188
192static void sidebar_new_mail(const struct ExpandoNode *node, void *data,
193 MuttFormatFlags flags, struct Buffer *buf)
194{
195 const struct SidebarData *sdata = data;
196 const struct SbEntry *sbe = sdata->entry;
197 const struct Mailbox *m = sbe->mailbox;
198
199 // NOTE(g0mb4): use $flag_chars?
200 const char *s = m->has_new ? "N" : " ";
201 buf_strcpy(buf, s);
202}
203
207static long sidebar_new_mail_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
208{
209 const struct SidebarData *sdata = data;
210 const struct SbEntry *sbe = sdata->entry;
211 const struct Mailbox *m = sbe->mailbox;
212
213 return m->has_new;
214}
215
219static long sidebar_notify_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
220{
221 const struct SidebarData *sdata = data;
222 const struct SbEntry *sbe = sdata->entry;
223 const struct Mailbox *m = sbe->mailbox;
224
225 return m->notify_user;
226}
227
231static long sidebar_old_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
232{
233 const struct SidebarData *sdata = data;
234 const struct SbEntry *sbe = sdata->entry;
235 const struct Mailbox *m = sbe->mailbox;
236
237 return m->msg_unread - m->msg_new;
238}
239
243static long sidebar_poll_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
244{
245 const struct SidebarData *sdata = data;
246 const struct SbEntry *sbe = sdata->entry;
247 const struct Mailbox *m = sbe->mailbox;
248
249 return m->poll_new_mail;
250}
251
255static long sidebar_read_count_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
256{
257 const struct SidebarData *sdata = data;
258 const struct SbEntry *sbe = sdata->entry;
259 const struct Mailbox *m = sbe->mailbox;
260
261 return m->msg_count - m->msg_unread;
262}
263
267static long sidebar_tagged_count_num(const struct ExpandoNode *node, void *data,
268 MuttFormatFlags flags)
269{
270 const struct SidebarData *sdata = data;
271 const struct SbEntry *sbe = sdata->entry;
272 const struct IndexSharedData *shared = sdata->shared;
273 const struct Mailbox *m = sbe->mailbox;
274 const struct Mailbox *m_cur = shared->mailbox;
275
276 const bool c = m_cur && mutt_str_equal(m_cur->realpath, m->realpath);
277
278 return c ? m_cur->msg_tagged : 0;
279}
280
284static long sidebar_unread_count_num(const struct ExpandoNode *node, void *data,
285 MuttFormatFlags flags)
286{
287 const struct SidebarData *sdata = data;
288 const struct SbEntry *sbe = sdata->entry;
289 const struct Mailbox *m = sbe->mailbox;
290
291 return m->msg_unread;
292}
293
297static long sidebar_unseen_count_num(const struct ExpandoNode *node, void *data,
298 MuttFormatFlags flags)
299{
300 const struct SidebarData *sdata = data;
301 const struct SbEntry *sbe = sdata->entry;
302 const struct Mailbox *m = sbe->mailbox;
303
304 return m->msg_new;
305}
306
313 // clang-format off
329 { -1, -1, NULL, NULL },
330 // clang-format on
331};
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
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:267
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:161
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:284
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:243
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:60
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:144
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:207
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:131
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:255
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:297
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:231
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:219
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:174
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:192
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:77
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:103
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:660
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:581
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
static size_t add_indent(char *buf, size_t buflen, const struct SbEntry *sbe)
Generate the needed indentation.
Definition: expando.c:46
const struct ExpandoRenderCallback SidebarRenderCallbacks[]
Callbacks for Sidebar Expandos.
Definition: expando.c:312
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:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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