NeoMutt  2025-12-11-58-g09398d
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)
 
bool group_match (struct Group *g, const char *str)
 Does a string match an entry in a Group?
 
void grouplist_add_group (struct GroupList *gl, struct Group *g)
 Add a Group to a GroupList.
 
void grouplist_add_addrlist (struct GroupList *gl, struct AddressList *al)
 Add Address list to a GroupList.
 
int grouplist_add_regex (struct GroupList *gl, const char *str, uint16_t flags, struct Buffer *err)
 Add matching Addresses to a GroupList.
 
void grouplist_destroy (struct GroupList *gl)
 Free a GroupList.
 
struct HashTablegroups_new (void)
 Create a HashTable for the Address Groups.
 
void groups_free (struct HashTable **pptr)
 Free Address Groups HashTable.
 
struct Groupgroups_get_group (struct HashTable *groups, const char *name)
 Get a Group by its name.
 
int groups_remove_addrlist (struct HashTable *groups, struct GroupList *gl, struct AddressList *al)
 Remove an AddressList from a GroupList.
 
void groups_remove_grouplist (struct HashTable *groups, struct GroupList *gl)
 Clear a GroupList.
 
int groups_remove_regex (struct HashTable *groups, struct GroupList *gl, const char *str)
 Remove matching addresses from a GroupList.
 

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  )

◆ group_match()

bool group_match ( struct Group * g,
const char * str )

Does a string match an entry in a Group?

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

Definition at line 161 of file group.c.

162{
163 if (!g || !str)
164 return false;
165
166 if (mutt_regexlist_match(&g->rs, str))
167 return true;
168 struct Address *a = NULL;
169 TAILQ_FOREACH(a, &g->al, entries)
170 {
171 if (a->mailbox && mutt_istr_equal(str, buf_string(a->mailbox)))
172 return true;
173 }
174
175 return false;
176}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition regex.c:199
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition string.c:672
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
An email address.
Definition address.h:35
struct Buffer * mailbox
Mailbox and host address.
Definition address.h:37
struct AddressList al
List of Addresses.
Definition group.h:40
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:

◆ grouplist_add_group()

void grouplist_add_group ( struct GroupList * gl,
struct Group * g )

Add a Group to a GroupList.

Parameters
glGroupList to add to
gGroup to add

Definition at line 183 of file group.c.

184{
185 if (!gl || !g)
186 return;
187
188 struct GroupNode *np = NULL;
189 STAILQ_FOREACH(np, gl, entries)
190 {
191 if (np->group == g)
192 return;
193 }
194 np = MUTT_MEM_CALLOC(1, struct GroupNode);
195 np->group = g;
196 STAILQ_INSERT_TAIL(gl, np, entries);
197}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:47
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:427
An element in a GroupList.
Definition group.h:49
struct Group * group
Address Group.
Definition group.h:50
+ Here is the caller graph for this function:

◆ grouplist_add_addrlist()

void 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 224 of file group.c.

225{
226 if (!gl || !al)
227 return;
228
229 struct GroupNode *np = NULL;
230 STAILQ_FOREACH(np, gl, entries)
231 {
232 group_add_addrlist(np->group, al);
233 }
234}
static void group_add_addrlist(struct Group *g, const struct AddressList *al)
Add an Address List to a Group.
Definition group.c:112
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ grouplist_add_regex()

int grouplist_add_regex ( struct GroupList * gl,
const char * str,
uint16_t flags,
struct Buffer * err )

Add matching Addresses to a GroupList.

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

Definition at line 245 of file group.c.

247{
248 if (!gl || !str)
249 return -1;
250
251 int rc = 0;
252
253 struct GroupNode *np = NULL;
254 STAILQ_FOREACH(np, gl, entries)
255 {
256 rc = group_add_regex(np->group, str, flags, err);
257 if (rc)
258 return rc;
259 }
260 return rc;
261}
static int group_add_regex(struct Group *g, const char *str, uint16_t flags, struct Buffer *err)
Add a Regex to a Group.
Definition group.c:138
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ grouplist_destroy()

void 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}
#define FREE(x)
Definition memory.h:62
#define STAILQ_INIT(head)
Definition queue.h:410
#define STAILQ_FIRST(head)
Definition queue.h:388
#define STAILQ_NEXT(elm, field)
Definition queue.h:439
+ Here is the caller graph for this function:

◆ groups_new()

struct HashTable * groups_new ( void )

Create a HashTable for the Address Groups.

Return values
ptrNew Groups HashTable

Definition at line 267 of file group.c.

268{
269 struct HashTable *groups = mutt_hash_new(1031, MUTT_HASH_NO_FLAGS);
270
272
273 return groups;
274}
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:77
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:111
A Hash Table.
Definition hash.h:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ groups_free()

void groups_free ( struct HashTable ** pptr)

Free Address Groups HashTable.

Parameters
pptrGroups HashTable to free

Definition at line 280 of file group.c.

281{
282 mutt_hash_free(pptr);
283}
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:

◆ groups_get_group()

struct Group * groups_get_group ( struct HashTable * groups,
const char * name )

Get a Group by its name.

Parameters
groupsGroups HashTable
nameName to find
Return values
ptrMatching Group, or new Group (if no match)

Definition at line 291 of file group.c.

292{
293 if (!groups || !name)
294 return NULL;
295
296 struct Group *g = mutt_hash_find(groups, name);
297 if (!g)
298 {
299 mutt_debug(LL_DEBUG2, "Creating group %s\n", name);
300 g = group_new(name);
301 mutt_hash_insert(groups, g->name, g);
302 }
303
304 return g;
305}
static struct Group * group_new(const char *name)
Create a new Address Group.
Definition group.c:63
#define mutt_debug(LEVEL,...)
Definition logging2.h:90
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:45
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:

◆ groups_remove_addrlist()

int groups_remove_addrlist ( struct HashTable * groups,
struct GroupList * gl,
struct AddressList * al )

Remove an AddressList from a GroupList.

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

Definition at line 337 of file group.c.

339{
340 if (!groups || !gl || !al)
341 return -1;
342
343 struct GroupNode *gnp = NULL;
344 STAILQ_FOREACH(gnp, gl, entries)
345 {
346 struct Address *a = NULL;
347 TAILQ_FOREACH(a, al, entries)
348 {
350 }
351 if (group_is_empty(gnp->group))
352 {
353 group_remove(groups, gnp->group);
354 }
355 }
356
357 return 0;
358}
int mutt_addrlist_remove(struct AddressList *al, const char *mailbox)
Remove an Address from a list.
Definition address.c:435
static bool group_is_empty(struct Group *g)
Is a Group empty?
Definition group.c:100
static void group_remove(struct HashTable *groups, struct Group *g)
Remove a Group from the Hash Table.
Definition group.c:88
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ groups_remove_grouplist()

void groups_remove_grouplist ( struct HashTable * groups,
struct GroupList * gl )

Clear a GroupList.

Parameters
groupsGroups HashTable
glGroupList to clear

Definition at line 312 of file group.c.

313{
314 if (!groups || !gl)
315 return;
316
317 struct GroupNode *np = STAILQ_FIRST(gl);
318 struct GroupNode *next = NULL;
319 while (np)
320 {
321 group_remove(groups, np->group);
322 next = STAILQ_NEXT(np, entries);
323 FREE(&np);
324 np = next;
325 }
326 STAILQ_INIT(gl);
327}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ groups_remove_regex()

int groups_remove_regex ( struct HashTable * groups,
struct GroupList * gl,
const char * str )

Remove matching addresses from a GroupList.

Parameters
groupsGroups HashTable
glGroupList to remove from
strRegex string to match
Return values
0Success
-1Error

Definition at line 368 of file group.c.

369{
370 if (!groups || !gl || !str)
371 return -1;
372
373 int rc = 0;
374 struct GroupNode *np = NULL;
375 STAILQ_FOREACH(np, gl, entries)
376 {
377 rc = group_remove_regex(np->group, str);
378 if (group_is_empty(np->group))
379 group_remove(groups, np->group);
380 if (rc != 0)
381 return rc;
382 }
383 return rc;
384}
static int group_remove_regex(struct Group *g, const char *str)
Remove a Regex from a Group.
Definition group.c:150
+ Here is the call graph for this function:
+ Here is the caller graph for this function: