NeoMutt  2021-02-05-329-g9e03b7
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 {
54  mutt_hash_free(&ReverseAliases);
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)
75  mutt_hash_insert(ReverseAliases, addr->mailbox, addr);
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)
96  mutt_hash_delete(ReverseAliases, addr->mailbox, addr);
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 }
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:354
A shortcut for an email address or addresses.
Definition: alias.h:33
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:327
A Hash Table.
Definition: hash.h:84
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:447
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
void alias_reverse_shutdown(void)
Clear up the Reverse Alias Hash Table.
Definition: reverse.c:52
Representation of a single alias to an email address.
void alias_reverse_init(void)
Set up the Reverse Alias Hash Table.
Definition: reverse.c:42
Email Address Handling.
use strcasecmp() to compare keys
Definition: hash.h:98
void alias_reverse_add(struct Alias *alias)
Add an email address lookup for an Alias.
Definition: reverse.c:61
allow duplicate keys to be inserted
Definition: hash.h:100
struct Address * alias_reverse_lookup(const struct Address *addr)
Does the user have an alias for the given address.
Definition: reverse.c:105
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1305
bool group
Group mailbox?
Definition: address.h:39
static struct HashTable * ReverseAliases
Hash Table of aliases (email address -> alias)
Definition: reverse.c:37
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from a Hash Table.
Definition: hash.c:419
make a copy of the keys
Definition: hash.h:99
struct AddressList addr
List of Addresses the Alias expands to.
Definition: alias.h:36
Convenience wrapper for the library headers.
void alias_reverse_delete(struct Alias *alias)
Remove an email address lookup for an Alias.
Definition: reverse.c:83
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
Definition: hash.c:251
Manage alias reverse lookups.