NeoMutt  2024-03-23-23-gec7045
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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
 
#define MUTT_UNGROUP   1
 'ungroup' config command
 

Functions

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

Detailed Description

Handling for email address groups.

Authors
  • Richard Russon
  • 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 32 of file group.h.

◆ MUTT_UNGROUP

#define MUTT_UNGROUP   1

'ungroup' config command

Definition at line 33 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 183 of file group.c.

184{
185 if (!gl || !group)
186 return;
187
188 struct GroupNode *np = NULL;
189 STAILQ_FOREACH(np, gl, entries)
190 {
191 if (np->group == group)
192 return;
193 }
194 np = mutt_mem_calloc(1, sizeof(struct GroupNode));
195 np->group = group;
196 STAILQ_INSERT_TAIL(gl, np, entries);
197}
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:49
struct Group * group
Address Group.
Definition: group.h:50
+ 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 272 of file group.c.

273{
274 if (!gl || !al)
275 return;
276
277 struct GroupNode *np = NULL;
278 STAILQ_FOREACH(np, gl, entries)
279 {
280 group_add_addrlist(np->group, al);
281 }
282}
static void group_add_addrlist(struct Group *g, const struct AddressList *al)
Add an Address List to a Group.
Definition: group.c:224
+ 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 322 of file group.c.

324{
325 if (!gl || !s)
326 return -1;
327
328 int rc = 0;
329
330 struct GroupNode *np = NULL;
331 STAILQ_FOREACH(np, gl, entries)
332 {
333 rc = group_add_regex(np->group, s, flags, err);
334 if (rc)
335 return rc;
336 }
337 return rc;
338}
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:250
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_grouplist_cleanup()

void mutt_grouplist_cleanup ( void  )

Free GroupList singleton resource.

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

Definition at line 108 of file group.c.

109{
111}
static struct HashTable * Groups
Hash Table: "group-name" -> Group.
Definition: group.c:44
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_clear()

void mutt_grouplist_clear ( struct GroupList *  gl)

Clear a GroupList.

Parameters
glGroupList to clear

Definition at line 149 of file group.c.

150{
151 if (!gl)
152 return;
153
154 struct GroupNode *np = STAILQ_FIRST(gl);
155 struct GroupNode *next = NULL;
156 while (np)
157 {
158 group_remove(np->group);
159 next = STAILQ_NEXT(np, entries);
160 FREE(&np);
161 np = next;
162 }
163 STAILQ_INIT(gl);
164}
static void group_remove(struct Group *g)
Remove a Group from the Hash Table.
Definition: group.c:138
#define FREE(x)
Definition: memory.h:45
#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 203 of file group.c.

204{
205 if (!gl)
206 return;
207
208 struct GroupNode *np = STAILQ_FIRST(gl);
209 struct GroupNode *next = NULL;
210 while (np)
211 {
212 next = STAILQ_NEXT(np, entries);
213 FREE(&np);
214 np = next;
215 }
216 STAILQ_INIT(gl);
217}
+ 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 96 of file group.c.

97{
99
101}
static void group_hash_free(int type, void *obj, intptr_t data)
Free our hash table data - Implements hash_hdata_free_t -.
Definition: group.c:85
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 291 of file group.c.

292{
293 if (!gl || !al)
294 return -1;
295
296 struct GroupNode *gnp = NULL;
297 STAILQ_FOREACH(gnp, gl, entries)
298 {
299 struct Address *a = NULL;
300 TAILQ_FOREACH(a, al, entries)
301 {
303 }
304 if (empty_group(gnp->group))
305 {
306 group_remove(gnp->group);
307 }
308 }
309
310 return 0;
311}
int mutt_addrlist_remove(struct AddressList *al, const char *mailbox)
Remove an Address from a list.
Definition: address.c:435
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:97
static bool empty_group(struct Group *g)
Is a Group empty?
Definition: group.c:171
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
An email address.
Definition: address.h:36
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
struct AddressList al
List of Addresses.
Definition: group.h:40
+ 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 347 of file group.c.

348{
349 if (!gl || !s)
350 return -1;
351
352 int rc = 0;
353 struct GroupNode *np = NULL;
354 STAILQ_FOREACH(np, gl, entries)
355 {
356 rc = group_remove_regex(np->group, s);
357 if (empty_group(np->group))
358 group_remove(np->group);
359 if (rc)
360 return rc;
361 }
362 return rc;
363}
static int group_remove_regex(struct Group *g, const char *s)
Remove a Regex from a Group.
Definition: group.c:262
+ 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 371 of file group.c.

372{
373 if (!g || !s)
374 return false;
375
376 if (mutt_regexlist_match(&g->rs, s))
377 return true;
378 struct Address *a = NULL;
379 TAILQ_FOREACH(a, &g->al, entries)
380 {
381 if (a->mailbox && mutt_istr_equal(s, buf_string(a->mailbox)))
382 return true;
383 }
384
385 return false;
386}
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition: regex.c:200
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:721
struct RegexList rs
Group Regex patterns.
Definition: group.h:41
+ 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 118 of file group.c.

119{
120 if (!pat)
121 return NULL;
122
123 struct Group *g = mutt_hash_find(Groups, pat);
124 if (!g)
125 {
126 mutt_debug(LL_DEBUG2, "Creating group %s\n", pat);
127 g = group_new(pat);
129 }
130
131 return g;
132}
static struct Group * group_new(const char *pat)
Create a new Address Group.
Definition: group.c:71
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
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: logging2.h:44
A set of email addresses.
Definition: group.h:39
char * name
Name of Group.
Definition: group.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function: