NeoMutt  2025-12-11-435-g4ac674
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 "module_data.h"
40
46{
47 if (!mv || !mv->mailbox)
48 return;
49
50 struct Mailbox *m = mv->mailbox;
51
52 for (int i = 0; i < m->msg_count; i++)
53 {
54 struct Email *e = m->emails[i];
55 if (!e)
56 break;
57 e->recip_valid = false;
58 }
59}
60
67enum CommandResult parse_alternates(const struct Command *cmd, struct Buffer *line,
68 const struct ParseContext *pc, struct ParseError *pe)
69{
70 struct Buffer *err = pe->message;
71
72 if (!MoreArgs(line))
73 {
74 buf_printf(err, _("%s: too few arguments"), cmd->name);
75 return MUTT_CMD_WARNING;
76 }
77
78 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
79 struct Buffer *token = buf_pool_get();
81
83 ASSERT(md);
84
85 do
86 {
88
89 if (parse_grouplist(&gl, token, line, err, NeoMutt->groups) == -1)
90 goto done;
91
93
94 if (mutt_regexlist_add(&md->alternates, buf_string(token), REG_ICASE, err) != 0)
95 goto done;
96
97 if (grouplist_add_regex(&gl, buf_string(token), REG_ICASE, err) != 0)
98 goto done;
99 } while (MoreArgs(line));
100
101 mutt_debug(LL_NOTIFY, "NT_ALTERN_ADD: %s\n", buf_string(token));
103
104 rc = MUTT_CMD_SUCCESS;
105
106done:
107 buf_pool_release(&token);
109 return rc;
110}
111
118enum CommandResult parse_unalternates(const struct Command *cmd, struct Buffer *line,
119 const struct ParseContext *pc, struct ParseError *pe)
120{
121 struct Buffer *err = pe->message;
122
123 if (!MoreArgs(line))
124 {
125 buf_printf(err, _("%s: too few arguments"), cmd->name);
126 return MUTT_CMD_WARNING;
127 }
128
129 struct Buffer *token = buf_pool_get();
131
133 ASSERT(md);
134
135 do
136 {
139
140 if (!mutt_str_equal(buf_string(token), "*") &&
141 (mutt_regexlist_add(&md->unalternates, buf_string(token), REG_ICASE, err) != 0))
142 {
143 goto done;
144 }
145
146 } while (MoreArgs(line));
147
148 mutt_debug(LL_NOTIFY, "NT_ALTERN_DELETE: %s\n", buf_string(token));
150
151 rc = MUTT_CMD_SUCCESS;
152
153done:
154 buf_pool_release(&token);
155 return rc;
156}
157
163bool mutt_alternates_match(const char *addr)
164{
165 if (!addr)
166 return false;
167
169 ASSERT(md);
170
171 if (mutt_regexlist_match(&md->alternates, addr))
172 {
173 mutt_debug(LL_DEBUG5, "yes, %s matched by alternates\n", addr);
174 if (mutt_regexlist_match(&md->unalternates, addr))
175 mutt_debug(LL_DEBUG5, "but, %s matched by unalternates\n", addr);
176 else
177 return true;
178 }
179
180 return false;
181}
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.
Alias private Module data.
bool mutt_alternates_match(const char *addr)
Compare an Address to the un/alternates lists.
Definition alternates.c:163
void mutt_alternates_reset(struct MailboxView *mv)
Clear the recipient valid flag of all emails.
Definition alternates.c:45
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.
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
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:67
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:118
#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:662
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:585
@ 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:38
struct Notify * alternates_notify
Notifications: NotifyAlternates.
Definition module_data.h:39
struct RegexList alternates
Regexes to match the user's alternate email addresses.
Definition module_data.h:37
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
struct HashTable * groups
Hash Table: "group-name" -> Group.
Definition neomutt.h:54
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