NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
reverse.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stddef.h>
31#include "mutt/lib.h"
32#include "address/lib.h"
33#include "core/lib.h"
34#include "reverse.h"
35#include "lib.h"
36#include "alias.h"
37#include "module_data.h"
38
44{
45 /* reverse alias keys need to be strdup'ed because of idna conversions */
47}
48
53void alias_reverse_cleanup(struct HashTable **reverse)
54{
55 mutt_hash_free(reverse);
56}
57
62void alias_reverse_add(struct Alias *alias)
63{
64 if (!alias)
65 return;
66
67 /* Note that the address mailbox should be converted to intl form
68 * before using as a key in the hash. This is currently done
69 * by all callers, but added here mostly as documentation. */
70 mutt_addrlist_to_intl(&alias->addr, NULL);
71
73 ASSERT(mod_data);
74
75 struct Address *addr = NULL;
76 TAILQ_FOREACH(addr, &alias->addr, entries)
77 {
78 if (!addr->group && addr->mailbox)
79 mutt_hash_insert(mod_data->reverse_aliases, buf_string(addr->mailbox), addr);
80 }
81}
82
87void alias_reverse_delete(struct Alias *alias)
88{
89 if (!alias)
90 return;
91
92 /* If the alias addresses were converted to local form, they won't
93 * match the hash entries. */
94 mutt_addrlist_to_intl(&alias->addr, NULL);
95
97 ASSERT(mod_data);
98
99 struct Address *addr = NULL;
100 TAILQ_FOREACH(addr, &alias->addr, entries)
101 {
102 if (!addr->group && addr->mailbox)
103 mutt_hash_delete(mod_data->reverse_aliases, buf_string(addr->mailbox), addr);
104 }
105}
106
112struct Address *alias_reverse_lookup(const struct Address *addr)
113{
114 if (!addr || !addr->mailbox)
115 return NULL;
116
118 ASSERT(mod_data);
119
120 return mutt_hash_find(mod_data->reverse_aliases, buf_string(addr->mailbox));
121}
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition address.c:1302
Email Address Handling.
Email Aliases.
Alias private Module data.
Representation of a single alias to an email address.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
Convenience wrapper for the core headers.
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:337
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
Definition hash.c:429
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_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_ALLOW_DUPS
allow duplicate keys to be inserted
Definition hash.h:114
#define MUTT_HASH_STRCASECMP
use strcasecmp() to compare keys
Definition hash.h:112
@ MODULE_ID_ALIAS
ModuleAlias, Alias
Definition module_api.h:48
Convenience wrapper for the library headers.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:665
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
void alias_reverse_cleanup(struct HashTable **reverse)
Clear up the Reverse Alias Hash Table.
Definition reverse.c:53
struct HashTable * alias_reverse_init(void)
Set up the Reverse Alias Hash Table.
Definition reverse.c:43
void alias_reverse_add(struct Alias *alias)
Add an email address lookup for an Alias.
Definition reverse.c:62
struct Address * alias_reverse_lookup(const struct Address *addr)
Does the user have an alias for the given address.
Definition reverse.c:112
void alias_reverse_delete(struct Alias *alias)
Remove an email address lookup for an Alias.
Definition reverse.c:87
Manage alias reverse lookups.
#define ASSERT(COND)
Definition signal2.h:59
An email address.
Definition address.h:35
bool group
Group mailbox?
Definition address.h:38
struct Buffer * mailbox
Mailbox and host address.
Definition address.h:37
Alias private Module data.
Definition module_data.h:33
struct HashTable * reverse_aliases
Hash Table of aliases (email address -> alias)
Definition module_data.h:36
A shortcut for an email address or addresses.
Definition alias.h:35
struct AddressList addr
List of Addresses the Alias expands to.
Definition alias.h:37
A Hash Table.
Definition hash.h:99
Container for Accounts, Notifications.
Definition neomutt.h:41