NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
alternates.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdbool.h>
31#include <stdio.h>
32#include "mutt/lib.h"
33#include "address/lib.h"
34#include "email/lib.h"
35#include "core/lib.h"
36#include "gui/lib.h"
37#include "alternates.h"
38#include "parse/lib.h"
39#include "group.h"
40#include "module_data.h"
41
47{
48 if (!mv || !mv->mailbox)
49 return;
50
51 struct Mailbox *m = mv->mailbox;
52
53 for (int i = 0; i < m->msg_count; i++)
54 {
55 struct Email *e = m->emails[i];
56 if (!e)
57 break;
58 e->recip_valid = false;
59 }
60}
61
68enum CommandResult parse_alternates(const struct Command *cmd, struct Buffer *line,
69 const struct ParseContext *pc, struct ParseError *pe)
70{
71 struct Buffer *err = pe->message;
72
73 if (!MoreArgs(line))
74 {
75 buf_printf(err, _("%s: too few arguments"), cmd->name);
76 return MUTT_CMD_WARNING;
77 }
78
79 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
80 struct Buffer *token = buf_pool_get();
82
84 ASSERT(mod_data);
85
86 do
87 {
89
90 if (parse_grouplist(&gl, token, line, err, mod_data->groups) == -1)
91 goto done;
92
94
95 if (mutt_regexlist_add(&mod_data->alternates, buf_string(token), REG_ICASE, err) != 0)
96 goto done;
97
98 if (grouplist_add_regex(&gl, buf_string(token), REG_ICASE, err) != 0)
99 goto done;
100 } while (MoreArgs(line));
101
102 mutt_debug(LL_NOTIFY, "NT_ALTERN_ADD: %s\n", buf_string(token));
104
105 rc = MUTT_CMD_SUCCESS;
106
107done:
108 buf_pool_release(&token);
110 return rc;
111}
112
119enum CommandResult parse_unalternates(const struct Command *cmd, struct Buffer *line,
120 const struct ParseContext *pc, struct ParseError *pe)
121{
122 struct Buffer *err = pe->message;
123
124 if (!MoreArgs(line))
125 {
126 buf_printf(err, _("%s: too few arguments"), cmd->name);
127 return MUTT_CMD_WARNING;
128 }
129
130 struct Buffer *token = buf_pool_get();
132
134 ASSERT(mod_data);
135
136 do
137 {
139 mutt_regexlist_remove(&mod_data->alternates, buf_string(token));
140
141 if (!mutt_str_equal(buf_string(token), "*") &&
142 (mutt_regexlist_add(&mod_data->unalternates, buf_string(token), REG_ICASE, err) != 0))
143 {
144 goto done;
145 }
146
147 } while (MoreArgs(line));
148
149 mutt_debug(LL_NOTIFY, "NT_ALTERN_DELETE: %s\n", buf_string(token));
151
152 rc = MUTT_CMD_SUCCESS;
153
154done:
155 buf_pool_release(&token);
156 return rc;
157}
158
164bool mutt_alternates_match(const char *addr)
165{
166 if (!addr)
167 return false;
168
170 ASSERT(mod_data);
171
172 if (mutt_regexlist_match(&mod_data->alternates, addr))
173 {
174 mutt_debug(LL_DEBUG5, "yes, %s matched by alternates\n", addr);
175 if (mutt_regexlist_match(&mod_data->unalternates, addr))
176 mutt_debug(LL_DEBUG5, "but, %s matched by unalternates\n", addr);
177 else
178 return true;
179 }
180
181 return false;
182}
int grouplist_add_regex(struct GroupList *gl, const char *str, uint16_t flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition group.c:245
void grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition group.c:203
Email Address Handling.
int parse_grouplist(struct GroupList *gl, struct Buffer *token, struct Buffer *line, struct Buffer *err, struct HashTable *groups)
Parse a group context.
Definition group.c:56
Parse Group/Lists Commands.
Alias private Module data.
bool mutt_alternates_match(const char *addr)
Compare an Address to the un/alternates lists.
Definition alternates.c:164
void mutt_alternates_reset(struct MailboxView *mv)
Clear the recipient valid flag of all emails.
Definition alternates.c:46
Parse Alternate Commands.
@ NT_ALTERN_ADD
Alternate address has been added.
Definition alternates.h:43
@ NT_ALTERN_DELETE
Alternate address has been deleted.
Definition alternates.h:44
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
CommandResult
Error codes for command_t parse functions.
Definition command.h:37
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition command.h:40
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:38
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:39
Convenience wrapper for the core headers.
Structs that make up an email.
int parse_extract_token(struct Buffer *dest, struct Buffer *line, TokenFlags flags)
Extract one token from a string.
Definition extract.c:49
#define MoreArgs(buf)
Definition extract.h:31
#define TOKEN_NO_FLAGS
No flags are set.
Definition extract.h:45
enum CommandResult parse_alternates(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'alternates' command - Implements Command::parse() -.
Definition alternates.c:68
enum CommandResult parse_unalternates(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'unalternates' command - Implements Command::parse() -.
Definition alternates.c:119
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
Convenience wrapper for the gui headers.
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:50
@ MODULE_ID_ALIAS
ModuleAlias, Alias
Definition module_api.h:48
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition notify.c:173
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:140
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition regex.c:235
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition regex.c:200
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:665
@ NT_ALTERN
Alternates command changed, NotifyAlternates.
Definition notify_type.h:38
Text parsing functions.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define STAILQ_HEAD_INITIALIZER(head)
Definition queue.h:324
#define ASSERT(COND)
Definition signal2.h:59
Alias private Module data.
Definition module_data.h:33
struct RegexList unalternates
Regexes to exclude false matches in alternates.
Definition module_data.h:39
struct Notify * alternates_notify
Notifications: NotifyAlternates.
Definition module_data.h:40
struct HashTable * groups
Hash Table: "group-name" -> Group.
Definition module_data.h:45
struct RegexList alternates
Regexes to match the user's alternate email addresses.
Definition module_data.h:38
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the Command.
Definition command.h:159
The envelope/body of an email.
Definition email.h:39
bool recip_valid
Is_recipient is valid.
Definition email.h:104
View of a Mailbox.
Definition mview.h:40
struct Mailbox * mailbox
Current Mailbox.
Definition mview.h:51
A mailbox.
Definition mailbox.h:78
int msg_count
Total number of messages.
Definition mailbox.h:87
struct Email ** emails
Array of Emails.
Definition mailbox.h:95
Container for Accounts, Notifications.
Definition neomutt.h:41
Context for config parsing (history/backtrace)
Definition pcontext.h:34
Detailed error information from config parsing.
Definition perror.h:34
struct Buffer * message
Error message.
Definition perror.h:35