NeoMutt  2022-04-29-323-g5fcc6c
Teaching an old dog new tricks
DOXYGEN
group.h File Reference

Handling for email address groups. More...

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

Go to the source code of this file.

Data Structures

struct  Group
 A set of email addresses. More...
 
struct  GroupNode
 An element in a GroupList. More...
 

Macros

#define MUTT_GROUP   0
 'group' config command More...
 
#define MUTT_UNGROUP   1
 'ungroup' config command More...
 

Functions

 STAILQ_HEAD (GroupList, GroupNode)
 
void mutt_grouplist_add (struct GroupList *gl, struct Group *group)
 Add a Group to a GroupList. More...
 
void mutt_grouplist_add_addrlist (struct GroupList *gl, struct AddressList *a)
 Add Address list to a GroupList. More...
 
int mutt_grouplist_add_regex (struct GroupList *gl, const char *s, uint16_t flags, struct Buffer *err)
 Add matching Addresses to a GroupList. More...
 
void mutt_grouplist_clear (struct GroupList *gl)
 Clear a GroupList. More...
 
void mutt_grouplist_destroy (struct GroupList *gl)
 Free a GroupList. More...
 
void mutt_grouplist_free (void)
 Free GroupList singleton resource. More...
 
void mutt_grouplist_init (void)
 Initialize the GroupList singleton. More...
 
int mutt_grouplist_remove_addrlist (struct GroupList *gl, struct AddressList *a)
 Remove an AddressList from a GroupList. More...
 
int mutt_grouplist_remove_regex (struct GroupList *gl, const char *s)
 Remove matching addresses from a GroupList. More...
 
bool mutt_group_match (struct Group *g, const char *s)
 Does a string match an entry in a Group? More...
 
struct Groupmutt_pattern_group (const char *pat)
 Match a pattern to a Group. More...
 

Detailed Description

Handling for email address groups.

Authors
  • Thomas Roessler
  • Rocco Rutte
  • Pietro Cerutti

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 group.h.

Macro Definition Documentation

◆ MUTT_GROUP

#define MUTT_GROUP   0

'group' config command

Definition at line 33 of file group.h.

◆ MUTT_UNGROUP

#define MUTT_UNGROUP   1

'ungroup' config command

Definition at line 34 of file group.h.

Function Documentation

◆ STAILQ_HEAD()

STAILQ_HEAD ( GroupList  ,
GroupNode   
)

◆ mutt_grouplist_add()

void mutt_grouplist_add ( struct GroupList *  gl,
struct Group group 
)

Add a Group to a GroupList.

Parameters
glGroupList to add to
groupGroup to add

Definition at line 177 of file group.c.

178{
179 if (!gl || !group)
180 return;
181
182 struct GroupNode *np = NULL;
183 STAILQ_FOREACH(np, gl, entries)
184 {
185 if (np->group == group)
186 return;
187 }
188 np = mutt_mem_calloc(1, sizeof(struct GroupNode));
189 np->group = group;
190 STAILQ_INSERT_TAIL(gl, np, entries);
191}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:389
An element in a GroupList.
Definition: group.h:50
struct Group * group
Address Group.
Definition: group.h:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_grouplist_add_addrlist()

void mutt_grouplist_add_addrlist ( struct GroupList *  gl,
struct AddressList *  al 
)

Add Address list to a GroupList.

Parameters
glGroupList to add to
alAddress list to add

Definition at line 266 of file group.c.

267{
268 if (!gl || !al)
269 return;
270
271 struct GroupNode *np = NULL;
272 STAILQ_FOREACH(np, gl, entries)
273 {
274 group_add_addrlist(np->group, al);
275 }
276}
static void group_add_addrlist(struct Group *g, const struct AddressList *al)
Add an Address List to a Group.
Definition: group.c:218
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_grouplist_add_regex()

int mutt_grouplist_add_regex ( struct GroupList *  gl,
const char *  s,
uint16_t  flags,
struct Buffer err 
)

Add matching Addresses to a GroupList.

Parameters
glGroupList to add to
sAddress to match
flagsFlags, e.g. REG_ICASE
errBuffer for error message
Return values
0Success
-1Error

Definition at line 316 of file group.c.

318{
319 if (!gl || !s)
320 return -1;
321
322 int rc = 0;
323
324 struct GroupNode *np = NULL;
325 STAILQ_FOREACH(np, gl, entries)
326 {
327 rc = group_add_regex(np->group, s, flags, err);
328 if (rc)
329 return rc;
330 }
331 return rc;
332}
static int group_add_regex(struct Group *g, const char *s, uint16_t flags, struct Buffer *err)
Add a Regex to a Group.
Definition: group.c:244
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_grouplist_clear()

void mutt_grouplist_clear ( struct GroupList *  gl)

Clear a GroupList.

Parameters
glGroupList to clear

Definition at line 143 of file group.c.

144{
145 if (!gl)
146 return;
147
148 struct GroupNode *np = STAILQ_FIRST(gl);
149 struct GroupNode *next = NULL;
150 while (np)
151 {
152 group_remove(np->group);
153 next = STAILQ_NEXT(np, entries);
154 FREE(&np);
155 np = next;
156 }
157 STAILQ_INIT(gl);
158}
static void group_remove(struct Group *g)
Remove a Group from the Hash Table.
Definition: group.c:132
#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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_grouplist_destroy()

void mutt_grouplist_destroy ( struct GroupList *  gl)

Free a GroupList.

Parameters
glGroupList to free

Definition at line 197 of file group.c.

198{
199 if (!gl)
200 return;
201
202 struct GroupNode *np = STAILQ_FIRST(gl);
203 struct GroupNode *next = NULL;
204 while (np)
205 {
206 next = STAILQ_NEXT(np, entries);
207 FREE(&np);
208 np = next;
209 }
210 STAILQ_INIT(gl);
211}
+ Here is the caller graph for this function:

◆ mutt_grouplist_free()

void mutt_grouplist_free ( void  )

Free GroupList singleton resource.

This is called once from init.c when deinitializing the global resources.

Definition at line 102 of file group.c.

103{
105}
static struct HashTable * Groups
Definition: group.c:38
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:

◆ mutt_grouplist_init()

void mutt_grouplist_init ( void  )

Initialize the GroupList singleton.

This is called once from init.c when initializing the global structures.

Definition at line 90 of file group.c.

91{
93
95}
void group_hash_free(int type, void *obj, intptr_t data)
Free our hash table data - Implements hash_hdata_free_t -.
Definition: group.c:79
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_NO_FLAGS
No flags are set.
Definition: hash.h:109
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_grouplist_remove_addrlist()

int mutt_grouplist_remove_addrlist ( struct GroupList *  gl,
struct AddressList *  al 
)

Remove an AddressList from a GroupList.

Parameters
glGroupList to remove from
alAddressList to remove
Return values
0Success
-1Error

Definition at line 285 of file group.c.

286{
287 if (!gl || !al)
288 return -1;
289
290 struct GroupNode *gnp = NULL;
291 STAILQ_FOREACH(gnp, gl, entries)
292 {
293 struct Address *a = NULL;
294 TAILQ_FOREACH(a, al, entries)
295 {
297 }
298 if (empty_group(gnp->group))
299 {
300 group_remove(gnp->group);
301 }
302 }
303
304 return 0;
305}
int mutt_addrlist_remove(struct AddressList *al, const char *mailbox)
Remove an Address from a list.
Definition: address.c:413
static bool empty_group(struct Group *g)
Is a Group empty?
Definition: group.c:165
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
An email address.
Definition: address.h:36
char * mailbox
Mailbox and host address.
Definition: address.h:38
struct AddressList al
List of Addresses.
Definition: group.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_grouplist_remove_regex()

int mutt_grouplist_remove_regex ( struct GroupList *  gl,
const char *  s 
)

Remove matching addresses from a GroupList.

Parameters
glGroupList to remove from
sAddress to match
Return values
0Success
-1Error

Definition at line 341 of file group.c.

342{
343 if (!gl || !s)
344 return -1;
345
346 int rc = 0;
347 struct GroupNode *np = NULL;
348 STAILQ_FOREACH(np, gl, entries)
349 {
350 rc = group_remove_regex(np->group, s);
351 if (empty_group(np->group))
352 group_remove(np->group);
353 if (rc)
354 return rc;
355 }
356 return rc;
357}
static int group_remove_regex(struct Group *g, const char *s)
Remove a Regex from a Group.
Definition: group.c:256
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_group_match()

bool mutt_group_match ( struct Group g,
const char *  s 
)

Does a string match an entry in a Group?

Parameters
gGroup to match against
sString to match
Return values
trueThere's a match

Definition at line 365 of file group.c.

366{
367 if (!g || !s)
368 return false;
369
370 if (mutt_regexlist_match(&g->rs, s))
371 return true;
372 struct Address *a = NULL;
373 TAILQ_FOREACH(a, &g->al, entries)
374 {
375 if (a->mailbox && mutt_istr_equal(s, a->mailbox))
376 return true;
377 }
378
379 return false;
380}
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition: regex.c:195
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:819
struct RegexList rs
Group Regex patterns.
Definition: group.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_pattern_group()

struct Group * mutt_pattern_group ( const char *  pat)

Match a pattern to a Group.

Parameters
patPattern to match
Return values
ptrMatching Group, or new Group (if no match)

Definition at line 112 of file group.c.

113{
114 if (!pat)
115 return NULL;
116
117 struct Group *g = mutt_hash_find(Groups, pat);
118 if (!g)
119 {
120 mutt_debug(LL_DEBUG2, "Creating group %s\n", pat);
121 g = group_new(pat);
123 }
124
125 return g;
126}
struct Group * group_new(const char *pat)
Create a new Address Group.
Definition: group.c:65
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
Definition: hash.c:335
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
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
A set of email addresses.
Definition: group.h:40
char * name
Name of Group.
Definition: group.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function: