NeoMutt  2021-10-29-225-gb9986f
Teaching an old dog new tricks
Go to the documentation of this file.
29 #include "config.h"
30 #include <stddef.h>
31 #include "mutt/lib.h"
32 #include "address/lib.h"
33 #include "reverse.h"
34 #include "lib.h"
35 #include "alias.h"
37 static struct HashTable *ReverseAliases;
43 {
44  /* reverse alias keys need to be strdup'ed because of idna conversions */
47 }
53 {
55 }
61 void alias_reverse_add(struct Alias *alias)
62 {
63  if (!alias)
64  return;
66  /* Note that the address mailbox should be converted to intl form
67  * before using as a key in the hash. This is currently done
68  * by all callers, but added here mostly as documentation. */
69  mutt_addrlist_to_intl(&alias->addr, NULL);
71  struct Address *addr = NULL;
72  TAILQ_FOREACH(addr, &alias->addr, entries)
73  {
74  if (!addr->group && addr->mailbox)
76  }
77 }
83 void alias_reverse_delete(struct Alias *alias)
84 {
85  if (!alias)
86  return;
88  /* If the alias addresses were converted to local form, they won't
89  * match the hash entries. */
90  mutt_addrlist_to_intl(&alias->addr, NULL);
92  struct Address *addr = NULL;
93  TAILQ_FOREACH(addr, &alias->addr, entries)
94  {
95  if (!addr->group && addr->mailbox)
97  }
98 }
105 struct Address *alias_reverse_lookup(const struct Address *addr)
106 {
107  if (!addr || !addr->mailbox)
108  return NULL;
110  return mutt_hash_find(ReverseAliases, addr->mailbox);
111 }
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1305
Email Address Handling.
Representation of a single alias to an email address.
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
Definition: hash.c:427
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
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_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
make a copy of the keys
Definition: hash.h:111
allow duplicate keys to be inserted
Definition: hash.h:112
use strcasecmp() to compare keys
Definition: hash.h:110
Convenience wrapper for the library headers.
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
struct Address * alias_reverse_lookup(const struct Address *addr)
Does the user have an alias for the given address.
Definition: reverse.c:105
static struct HashTable * ReverseAliases
Hash Table of aliases (email address -> alias)
Definition: reverse.c:37
void alias_reverse_add(struct Alias *alias)
Add an email address lookup for an Alias.
Definition: reverse.c:61
void alias_reverse_shutdown(void)
Clear up the Reverse Alias Hash Table.
Definition: reverse.c:52
void alias_reverse_delete(struct Alias *alias)
Remove an email address lookup for an Alias.
Definition: reverse.c:83
void alias_reverse_init(void)
Set up the Reverse Alias Hash Table.
Definition: reverse.c:42
Manage alias reverse lookups.
Key value store.
An email address.
Definition: address.h:36
bool group
Group mailbox?
Definition: address.h:39
char * mailbox
Mailbox and host address.
Definition: address.h:38
A shortcut for an email address or addresses.
Definition: alias.h:34
struct AddressList addr
List of Addresses the Alias expands to.
Definition: alias.h:36
A Hash Table.
Definition: hash.h:97