NeoMutt  2025-12-11-276-g10b23b
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
tags.c
Go to the documentation of this file.
1
25
31
32#include "config.h"
33#include <stdbool.h>
34#include <stddef.h>
35#include <stdint.h>
36#include "mutt/lib.h"
37#include "config/lib.h"
38#include "core/lib.h"
39#include "tags.h"
40#include "module_data.h"
41
46void tag_free(struct Tag **ptr)
47{
48 if (!ptr || !*ptr)
49 return;
50
51 struct Tag *tag = *ptr;
52 FREE(&tag->name);
53 FREE(&tag->transformed);
54
55 FREE(ptr);
56}
57
62struct Tag *tag_new(void)
63{
64 return MUTT_MEM_CALLOC(1, struct Tag);
65}
66
75void driver_tags_getter(struct TagList *tl, bool show_hidden, bool show_transformed,
76 const char *filter, struct Buffer *tags)
77{
78 if (!tl)
79 return;
80
81 struct Tag *tag = NULL;
82 STAILQ_FOREACH(tag, tl, entries)
83 {
84 if (filter && !mutt_str_equal(tag->name, filter))
85 continue;
86 if (show_hidden || !tag->hidden)
87 {
88 if (show_transformed && tag->transformed)
89 buf_join_str(tags, tag->transformed, ' ');
90 else
91 buf_join_str(tags, tag->name, ' ');
92 }
93 }
94}
95
105void driver_tags_add(struct TagList *tl, char *new_tag)
106{
108 ASSERT(md);
109
110 char *new_tag_transformed = mutt_hash_find(md->tag_transforms, new_tag);
111
112 struct Tag *tag = tag_new();
113 tag->name = new_tag;
114 tag->hidden = false;
115 tag->transformed = mutt_str_dup(new_tag_transformed);
116
117 /* filter out hidden tags */
118 const struct Slist *c_hidden_tags = cs_subset_slist(NeoMutt->sub, "hidden_tags");
119 if (c_hidden_tags)
120 if (mutt_list_find(&c_hidden_tags->head, new_tag))
121 tag->hidden = true;
122
123 STAILQ_INSERT_TAIL(tl, tag, entries);
124}
125
132void driver_tags_free(struct TagList *tl)
133{
134 if (!tl)
135 return;
136
137 struct Tag *tag = STAILQ_FIRST(tl);
138 struct Tag *next = NULL;
139 while (tag)
140 {
141 next = STAILQ_NEXT(tag, entries);
142 tag_free(&tag);
143 tag = next;
144 }
145 STAILQ_INIT(tl);
146}
147
153void driver_tags_get_transformed(struct TagList *tl, struct Buffer *tags)
154{
155 driver_tags_getter(tl, false, true, NULL, tags);
156}
157
165void driver_tags_get(struct TagList *tl, struct Buffer *tags)
166{
167 driver_tags_getter(tl, false, false, NULL, tags);
168}
169
175void driver_tags_get_with_hidden(struct TagList *tl, struct Buffer *tags)
176{
177 driver_tags_getter(tl, true, false, NULL, tags);
178}
179
188void driver_tags_get_transformed_for(struct TagList *tl, const char *name, struct Buffer *tags)
189{
190 driver_tags_getter(tl, true, true, name, tags);
191}
192
202bool driver_tags_replace(struct TagList *tl, const char *tags)
203{
204 if (!tl)
205 return false;
206
208
209 if (tags)
210 {
211 struct ListHead hsplit = STAILQ_HEAD_INITIALIZER(hsplit);
212 mutt_list_str_split(&hsplit, tags, ' ');
213 struct ListNode *np = NULL;
214 STAILQ_FOREACH(np, &hsplit, entries)
215 {
216 driver_tags_add(tl, np->data);
217 }
218 mutt_list_clear(&hsplit);
219 }
220 return true;
221}
222
226static void tags_deleter(int type, void *obj, intptr_t data)
227{
228 FREE(&obj);
229}
230
243
void buf_join_str(struct Buffer *buf, const char *str, char sep)
Join a buffer with a string separated by sep.
Definition buffer.c:748
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition helpers.c:242
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
Email private Module data.
static void tags_deleter(int type, void *obj, intptr_t data)
Free our hash table data - Implements hash_hdata_free_t -.
Definition tags.c:226
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition hash.c:364
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
Definition hash.c:261
void mutt_hash_set_destructor(struct HashTable *table, hash_hdata_free_t fn, intptr_t fn_data)
Set the destructor for a Hash Table.
Definition hash.c:303
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition hash.c:459
#define MUTT_HASH_STRDUP_KEYS
make a copy of the keys
Definition hash.h:113
#define MUTT_HASH_STRCASECMP
use strcasecmp() to compare keys
Definition hash.h:112
struct ListNode * mutt_list_find(const struct ListHead *h, const char *data)
Find a string in a List.
Definition list.c:103
void mutt_list_clear(struct ListHead *h)
Free a list, but NOT its strings.
Definition list.c:166
size_t mutt_list_str_split(struct ListHead *head, const char *src, char sep)
Split a string into a list using a separator char.
Definition list.c:246
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
@ MODULE_ID_EMAIL
ModuleEmail, Email code
Definition module_api.h:64
Convenience wrapper for the library headers.
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:662
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:582
#define STAILQ_INIT(head)
Definition queue.h:410
#define STAILQ_HEAD_INITIALIZER(head)
Definition queue.h:324
#define STAILQ_FIRST(head)
Definition queue.h:388
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:427
#define STAILQ_NEXT(elm, field)
Definition queue.h:439
#define ASSERT(COND)
Definition signal2.h:59
String manipulation buffer.
Definition buffer.h:36
Email private Module data.
Definition module_data.h:32
struct HashTable * tag_formats
Hash Table: "inbox" -> "GI" - Tag format strings.
Definition module_data.h:43
struct HashTable * tag_transforms
Hash Table: "inbox" -> "i" - Alternative tag names.
Definition module_data.h:44
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
String list.
Definition slist.h:37
struct ListHead head
List containing values.
Definition slist.h:38
LinkedList Tag Element.
Definition tags.h:41
bool hidden
Tag should be hidden.
Definition tags.h:44
char * transformed
Transformed name.
Definition tags.h:43
char * name
Tag name.
Definition tags.h:42
void driver_tags_getter(struct TagList *tl, bool show_hidden, bool show_transformed, const char *filter, struct Buffer *tags)
Get transformed tags separated by space.
Definition tags.c:75
bool driver_tags_replace(struct TagList *tl, const char *tags)
Replace all tags.
Definition tags.c:202
struct Tag * tag_new(void)
Create a new Tag.
Definition tags.c:62
void driver_tags_init(struct EmailModuleData *md)
Initialize structures used for tags.
Definition tags.c:235
void driver_tags_get(struct TagList *tl, struct Buffer *tags)
Get tags all tags separated by space.
Definition tags.c:165
void driver_tags_add(struct TagList *tl, char *new_tag)
Add a tag to header.
Definition tags.c:105
void driver_tags_get_with_hidden(struct TagList *tl, struct Buffer *tags)
Get all tags, also hidden ones, separated by space.
Definition tags.c:175
void driver_tags_cleanup(struct EmailModuleData *md)
Deinitialize structures used for tags.
Definition tags.c:248
void driver_tags_free(struct TagList *tl)
Free tags from a header.
Definition tags.c:132
void tag_free(struct Tag **ptr)
Free a Tag.
Definition tags.c:46
void driver_tags_get_transformed(struct TagList *tl, struct Buffer *tags)
Get transformed tags separated by space.
Definition tags.c:153
void driver_tags_get_transformed_for(struct TagList *tl, const char *name, struct Buffer *tags)
Get transformed tags for a tag name separated by space.
Definition tags.c:188
Driver based email tags.