NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
alternates.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include <stdint.h>
32#include <stdio.h>
33#include "mutt/lib.h"
34#include "address/lib.h"
35#include "email/lib.h"
36#include "core/lib.h"
37#include "mutt.h"
38#include "alternates.h"
39#include "command_parse.h"
40#include "init.h"
41
44static struct Notify *AlternatesNotify = NULL;
45
50{
52
55}
56
61{
63 return;
64
67}
68
73{
74 if (!m)
75 return;
76
77 for (int i = 0; i < m->msg_count; i++)
78 {
79 struct Email *e = m->emails[i];
80 if (!e)
81 break;
82 e->recip_valid = false;
83 }
84}
85
89enum CommandResult parse_alternates(struct Buffer *buf, struct Buffer *s,
90 intptr_t data, struct Buffer *err)
91{
92 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
93
94 do
95 {
97
98 if (parse_grouplist(&gl, buf, s, err) == -1)
99 goto bail;
100
102
103 if (mutt_regexlist_add(&Alternates, buf->data, REG_ICASE, err) != 0)
104 goto bail;
105
106 if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
107 goto bail;
108 } while (MoreArgs(s));
109
111
112 mutt_debug(LL_NOTIFY, "NT_ALTERN_ADD: %s\n", buf->data);
114
115 return MUTT_CMD_SUCCESS;
116
117bail:
119 return MUTT_CMD_ERROR;
120}
121
125enum CommandResult parse_unalternates(struct Buffer *buf, struct Buffer *s,
126 intptr_t data, struct Buffer *err)
127{
128 do
129 {
132
133 if (!mutt_str_equal(buf->data, "*") &&
134 (mutt_regexlist_add(&UnAlternates, buf->data, REG_ICASE, err) != 0))
135 {
136 return MUTT_CMD_ERROR;
137 }
138
139 } while (MoreArgs(s));
140
141 mutt_debug(LL_NOTIFY, "NT_ALTERN_DELETE: %s\n", buf->data);
143
144 return MUTT_CMD_SUCCESS;
145}
146
152bool mutt_alternates_match(const char *addr)
153{
154 if (!addr)
155 return false;
156
158 {
159 mutt_debug(LL_DEBUG5, "yes, %s matched by alternates\n", addr);
161 mutt_debug(LL_DEBUG5, "but, %s matched by unalternates\n", addr);
162 else
163 return true;
164 }
165
166 return false;
167}
Email Address Handling.
void alternates_init(void)
Set up the alternates lists.
Definition: alternates.c:60
struct RegexList Alternates
List of regexes to match the user's alternate email addresses.
Definition: alternates.c:42
bool mutt_alternates_match(const char *addr)
Compare an Address to the Un/Alternates lists.
Definition: alternates.c:152
static struct Notify * AlternatesNotify
Definition: alternates.c:44
void mutt_alternates_reset(struct Mailbox *m)
Clear the recipient valid flag of all emails.
Definition: alternates.c:72
void alternates_free(void)
Free the alternates lists.
Definition: alternates.c:49
struct RegexList UnAlternates
List of regexes to blacklist false matches in Alternates.
Definition: alternates.c:43
Alternate address handling.
@ NT_ALTERN_ADD
Alternate address has been added.
Definition: alternates.h:41
@ NT_ALTERN_DELETE
Alternate address has been deleted.
Definition: alternates.h:42
#define MoreArgs(buf)
Definition: buffer.h:40
CommandResult
Error codes for command_t parse functions.
Definition: command.h:34
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:37
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition: command.h:35
int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, struct Buffer *err)
Parse a group context.
Functions to parse commands in a config file.
Convenience wrapper for the core headers.
Structs that make up an email.
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, uint16_t flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:320
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:201
enum CommandResult parse_alternates(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'alternates' command - Implements Command::parse() -.
Definition: alternates.c:89
enum CommandResult parse_unalternates(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unalternates' command - Implements Command::parse() -.
Definition: alternates.c:125
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:273
Config/command parsing.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
@ LL_NOTIFY
Log of notifications.
Definition: logging.h:45
Convenience wrapper for the library headers.
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:60
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:174
int mutt_regexlist_add(struct RegexList *rl, const char *str, uint16_t flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:135
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:230
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition: regex.c:195
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
Many unsorted constants and some structs.
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:67
@ NT_ALTERN
Alternates command changed, NotifyAlternates.
Definition: notify_type.h:38
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
String manipulation buffer.
Definition: buffer.h:34
char * data
Pointer to data.
Definition: buffer.h:35
The envelope/body of an email.
Definition: email.h:37
bool recip_valid
Is_recipient is valid.
Definition: email.h:104
A mailbox.
Definition: mailbox.h:79
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Notification API.
Definition: notify.c:51