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 "mutt/lib.h"
32#include "address/lib.h"
33#include "expando.h"
34#include "lib.h"
35#include "expando/lib.h"
36#include "alias.h"
37#include "gui.h"
38
42static void alias_address(const struct ExpandoNode *node, void *data,
43 MuttFormatFlags flags, struct Buffer *buf)
44{
45 const struct AliasView *av = data;
46 const struct Alias *alias = av->alias;
47
48 mutt_addrlist_write(&alias->addr, buf, true);
49}
50
54static void alias_alias(const struct ExpandoNode *node, void *data,
55 MuttFormatFlags flags, struct Buffer *buf)
56{
57 const struct AliasView *av = data;
58 const struct Alias *alias = av->alias;
59
60 const char *s = alias->name;
61 buf_strcpy(buf, s);
62}
63
67static void alias_comment(const struct ExpandoNode *node, void *data,
68 MuttFormatFlags flags, struct Buffer *buf)
69{
70 const struct AliasView *av = data;
71 const struct Alias *alias = av->alias;
72
73 const char *s = alias->comment;
74 buf_strcpy(buf, s);
75}
76
80static void alias_email(const struct ExpandoNode *node, void *data,
81 MuttFormatFlags flags, struct Buffer *buf)
82{
83 const struct AliasView *av = data;
84 const struct Alias *alias = av->alias;
85
86 struct Address *a = NULL;
87 TAILQ_FOREACH(a, &alias->addr, entries)
88 {
89 struct Address *next = TAILQ_NEXT(a, entries);
90
91 buf_add_printf(buf, "<%s>", buf_string(a->mailbox));
92 if (next)
93 buf_addstr(buf, ", ");
94 }
95}
96
100static void alias_name(const struct ExpandoNode *node, void *data,
101 MuttFormatFlags flags, struct Buffer *buf)
102{
103 const struct AliasView *av = data;
104 const struct Alias *alias = av->alias;
105
106 struct Address *a = NULL;
107 TAILQ_FOREACH(a, &alias->addr, entries)
108 {
109 struct Address *next = TAILQ_NEXT(a, entries);
110
112 if (next)
113 buf_addstr(buf, ", ");
114 }
115}
116
120static void alias_tags(const struct ExpandoNode *node, void *data,
121 MuttFormatFlags flags, struct Buffer *buf)
122{
123 const struct AliasView *av = data;
124
125 alias_tags_to_buffer(&av->alias->tags, buf);
126}
127
131static void alias_view_flags(const struct ExpandoNode *node, void *data,
132 MuttFormatFlags flags, struct Buffer *buf)
133{
134 const struct AliasView *av = data;
135
136 // NOTE(g0mb4): use $flag_chars?
137 const char *s = av->is_deleted ? "D" : " ";
138 buf_strcpy(buf, s);
139}
140
144static long alias_view_flags_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
145{
146 const struct AliasView *av = data;
147 return av->is_deleted;
148}
149
153static long alias_view_index_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
154{
155 const struct AliasView *av = data;
156
157 return av->num + 1;
158}
159
163static void alias_view_tagged(const struct ExpandoNode *node, void *data,
164 MuttFormatFlags flags, struct Buffer *buf)
165{
166 const struct AliasView *av = data;
167
168 // NOTE(g0mb4): use $flag_chars?
169 const char *s = av->is_tagged ? "*" : " ";
170 buf_strcpy(buf, s);
171}
172
176static long alias_view_tagged_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
177{
178 const struct AliasView *av = data;
179 return av->is_tagged;
180}
181
188 // clang-format off
194 { ED_ALIAS, ED_ALI_NAME, alias_name, NULL },
197 { ED_ALIAS, ED_ALI_TAGS, alias_tags, NULL },
198 { -1, -1, NULL, NULL },
199 // clang-format on
200};
201
208 // clang-format off
212 { ED_ALIAS, ED_ALI_NAME, alias_name, NULL },
215 { ED_ALIAS, ED_ALI_TAGS, alias_tags, NULL },
216 { -1, -1, NULL, NULL },
217 // clang-format on
218};
size_t mutt_addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display)
Write an Address to a buffer.
Definition: address.c:1206
Email Address Handling.
void alias_tags_to_buffer(struct TagList *tl, struct Buffer *buf)
Write a comma-separated list of tags to a Buffer.
Definition: commands.c:49
const struct ExpandoRenderCallback AliasRenderCallbacks[]
Callbacks for Alias Expandos.
Definition: expando.c:187
const struct ExpandoRenderCallback QueryRenderCallbacks[]
Callbacks for Query Expandos.
Definition: expando.c:207
@ ED_ALI_FLAGS
Alias.flags.
Definition: expando.h:39
@ ED_ALI_EMAIL
Alias.addr.mailbox.
Definition: expando.h:38
@ ED_ALI_NUMBER
AliasView.num.
Definition: expando.h:41
@ ED_ALI_NAME
Alias.addr.personal.
Definition: expando.h:40
@ ED_ALI_ALIAS
Alias.name.
Definition: expando.h:36
@ ED_ALI_ADDRESS
Alias.addr.
Definition: expando.h:35
@ ED_ALI_COMMENT
Alias.comment.
Definition: expando.h:37
@ ED_ALI_TAGGED
AliasView.tagged.
Definition: expando.h:42
@ ED_ALI_TAGS
Alias.tags.
Definition: expando.h:43
Representation of a single alias to an email address.
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:204
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
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
@ ED_ALIAS
Alias ED_ALI_ ExpandoDataAlias.
Definition: domain.h:35
Parse Expando string.
static long alias_view_index_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
AliasView: Index number - Implements get_number_t -.
Definition: expando.c:153
static long alias_view_tagged_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
AliasView: Tagged char - Implements get_number_t -.
Definition: expando.c:176
static long alias_view_flags_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
AliasView: Flags - Implements get_number_t -.
Definition: expando.c:144
static void alias_email(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Email Address - Implements get_string_t -.
Definition: expando.c:80
static void alias_comment(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Comment - Implements get_string_t -.
Definition: expando.c:67
static void alias_tags(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Tags - Implements get_string_t -.
Definition: expando.c:120
static void alias_name(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Personal Name - Implements get_string_t -.
Definition: expando.c:100
static void alias_address(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Full Address - Implements get_string_t -.
Definition: expando.c:42
static void alias_alias(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Alias name - Implements get_string_t -.
Definition: expando.c:54
static void alias_view_tagged(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
AliasView: Tagged char - Implements get_string_t -.
Definition: expando.c:163
static void alias_view_flags(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
AliasView: Flags - Implements get_string_t -.
Definition: expando.c:131
Shared code for the Alias and Query Dialogs.
Convenience wrapper for the library headers.
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:743
#define TAILQ_NEXT(elm, field)
Definition: queue.h:850
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
Sidebar Expando definitions.
Key value store.
An email address.
Definition: address.h:36
struct Buffer * personal
Real name of address.
Definition: address.h:37
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
GUI data wrapping an Alias.
Definition: gui.h:38
struct Alias * alias
Alias.
Definition: gui.h:46
bool is_deleted
Is it deleted?
Definition: gui.h:44
bool is_tagged
Is it tagged?
Definition: gui.h:43
int num
Index number in list.
Definition: gui.h:39
A shortcut for an email address or addresses.
Definition: alias.h:35
struct TagList tags
Tags.
Definition: alias.h:39
char * comment
Free-form comment string.
Definition: alias.h:38
char * name
Short name.
Definition: alias.h:36
struct AddressList addr
List of Addresses the Alias expands to.
Definition: alias.h:37
String manipulation buffer.
Definition: buffer.h:36
Basic Expando Node.
Definition: node.h:67