NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
tags.h File Reference

Driver based email tags. More...

#include <stdbool.h>
#include "mutt/lib.h"
+ Include dependency graph for tags.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Tag
 LinkedList Tag Element. More...
 

Functions

 STAILQ_HEAD (TagList, Tag)
 
void driver_tags_free (struct TagList *list)
 Free tags from a header. More...
 
char * driver_tags_get (struct TagList *list)
 Get tags. More...
 
char * driver_tags_get_transformed (struct TagList *list)
 Get transformed tags. More...
 
char * driver_tags_get_transformed_for (struct TagList *list, const char *name)
 Get transformed tag for a tag name from a header. More...
 
char * driver_tags_get_with_hidden (struct TagList *list)
 Get tags with hiddens. More...
 
bool driver_tags_replace (struct TagList *list, const char *tags)
 Replace all tags. More...
 
void driver_tags_add (struct TagList *list, char *tag)
 Add a tag to header. More...
 
void driver_tags_init (void)
 Initialize structures used for tags. More...
 
void driver_tags_cleanup (void)
 Deinitialize structures used for tags. More...
 

Variables

struct HashTableTagTransforms
 Hash Table: "inbox" -> "i" - Alternative tag names. More...
 
struct HashTableTagFormats
 Hash Table: "inbox" -> "GI" - Tag format strings. More...
 

Detailed Description

Driver based email tags.

Authors
  • Mehdi Abaakouk

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file tags.h.

Function Documentation

◆ STAILQ_HEAD()

STAILQ_HEAD ( TagList  ,
Tag   
)

◆ driver_tags_free()

void driver_tags_free ( struct TagList *  list)

Free tags from a header.

Parameters
[in]listList of tags

Free the whole tags structure

Definition at line 107 of file tags.c.

108{
109 if (!list)
110 return;
111
112 struct Tag *np = STAILQ_FIRST(list);
113 struct Tag *next = NULL;
114 while (np)
115 {
116 next = STAILQ_NEXT(np, entries);
117 FREE(&np->name);
118 FREE(&np->transformed);
119 FREE(&np);
120 np = next;
121 }
122 STAILQ_INIT(list);
123}
#define FREE(x)
Definition: memory.h:43
#define STAILQ_INIT(head)
Definition: queue.h:372
#define STAILQ_FIRST(head)
Definition: queue.h:350
#define STAILQ_NEXT(elm, field)
Definition: queue.h:400
LinkedList Tag Element.
Definition: tags.h:39
char * transformed
Transformed name.
Definition: tags.h:41
char * name
Tag name.
Definition: tags.h:40
+ Here is the caller graph for this function:

◆ driver_tags_get()

char * driver_tags_get ( struct TagList *  list)

Get tags.

Parameters
[in]listList of tags
Return values
ptrString list of tags

Return a new allocated string containing all tags separated by space

Definition at line 145 of file tags.c.

146{
147 return driver_tags_getter(list, false, false, NULL);
148}
static char * driver_tags_getter(struct TagList *head, bool show_hidden, bool show_transformed, const char *filter)
Get transformed tags.
Definition: tags.c:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_get_transformed()

char * driver_tags_get_transformed ( struct TagList *  list)

Get transformed tags.

Parameters
[in]listList of tags
Return values
ptrString list of tags

Return a new allocated string containing all tags separated by space with transformation

Definition at line 133 of file tags.c.

134{
135 return driver_tags_getter(list, false, true, NULL);
136}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_get_transformed_for()

char * driver_tags_get_transformed_for ( struct TagList *  head,
const char *  name 
)

Get transformed tag for a tag name from a header.

Parameters
[in]headList of tags
[in]nameTag to transform
Return values
ptrString tag

Return a new allocated string containing all tags separated by space even the hiddens.

Definition at line 172 of file tags.c.

173{
174 return driver_tags_getter(head, true, true, name);
175}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_get_with_hidden()

char * driver_tags_get_with_hidden ( struct TagList *  list)

Get tags with hiddens.

Parameters
[in]listList of tags
Return values
ptrString list of tags

Return a new allocated string containing all tags separated by space even the hiddens.

Definition at line 158 of file tags.c.

159{
160 return driver_tags_getter(list, true, false, NULL);
161}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_replace()

bool driver_tags_replace ( struct TagList *  head,
const char *  tags 
)

Replace all tags.

Parameters
[in]headList of tags
[in]tagsstring of all tags separated by space
Return values
falseNo changes are made
trueTags are updated

Free current tags structures and replace it by new tags

Definition at line 186 of file tags.c.

187{
188 if (!head)
189 return false;
190
191 driver_tags_free(head);
192
193 if (tags)
194 {
195 struct ListHead hsplit = STAILQ_HEAD_INITIALIZER(hsplit);
196 mutt_list_str_split(&hsplit, tags, ' ');
197 struct ListNode *np = NULL;
198 STAILQ_FOREACH(np, &hsplit, entries)
199 {
200 driver_tags_add(head, np->data);
201 }
202 mutt_list_clear(&hsplit);
203 }
204 return true;
205}
void mutt_list_clear(struct ListHead *h)
Free a list, but NOT its strings.
Definition: list.c:167
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:247
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
void driver_tags_free(struct TagList *list)
Free tags from a header.
Definition: tags.c:107
void driver_tags_add(struct TagList *list, char *new_tag)
Add a tag to header.
Definition: tags.c:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_add()

void driver_tags_add ( struct TagList *  list,
char *  new_tag 
)

Add a tag to header.

Parameters
[in]listList of tags
[in]new_tagString representing the new tag

Add a tag to the header tags

Note
The ownership of the string is passed to the TagList structure

Definition at line 83 of file tags.c.

84{
85 char *new_tag_transformed = mutt_hash_find(TagTransforms, new_tag);
86
87 struct Tag *tn = mutt_mem_calloc(1, sizeof(struct Tag));
88 tn->name = new_tag;
89 tn->hidden = false;
90 tn->transformed = mutt_str_dup(new_tag_transformed);
91
92 /* filter out hidden tags */
93 const struct Slist *c_hidden_tags = cs_subset_slist(NeoMutt->sub, "hidden_tags");
94 if (c_hidden_tags)
95 if (mutt_list_find(&c_hidden_tags->head, new_tag))
96 tn->hidden = true;
97
98 STAILQ_INSERT_TAIL(list, tn, entries);
99}
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:268
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:362
struct ListNode * mutt_list_find(const struct ListHead *h, const char *data)
Find a string in a List.
Definition: list.c:102
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:389
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
String list.
Definition: slist.h:47
struct ListHead head
List containing values.
Definition: slist.h:48
bool hidden
Tag should be hidden.
Definition: tags.h:42
struct HashTable * TagTransforms
Hash Table: "inbox" -> "i" - Alternative tag names.
Definition: tags.c:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_init()

void driver_tags_init ( void  )

Initialize structures used for tags.

Definition at line 218 of file tags.c.

219{
222
225}
static void tags_deleter(int type, void *obj, intptr_t data)
Delete a tag - Implements hash_hdata_free_t -.
Definition: tags.c:210
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
Definition: hash.c:259
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:301
#define MUTT_HASH_STRDUP_KEYS
make a copy of the keys
Definition: hash.h:112
#define MUTT_HASH_STRCASECMP
use strcasecmp() to compare keys
Definition: hash.h:111
struct HashTable * TagFormats
Hash Table: "inbox" -> "GI" - Tag format strings.
Definition: tags.c:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ driver_tags_cleanup()

void driver_tags_cleanup ( void  )

Deinitialize structures used for tags.

Definition at line 230 of file tags.c.

231{
234}
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ TagTransforms

struct HashTable* TagTransforms
extern

Hash Table: "inbox" -> "i" - Alternative tag names.

Definition at line 38 of file tags.c.

◆ TagFormats

struct HashTable* TagFormats
extern

Hash Table: "inbox" -> "GI" - Tag format strings.

Definition at line 39 of file tags.c.