NeoMutt  2025-12-11-58-g09398d
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 "alternates.h"
37#include "parse/lib.h"
38#include "commands.h"
39#include "mview.h"
40
41static struct RegexList Alternates = STAILQ_HEAD_INITIALIZER(Alternates);
43static struct Notify *AlternatesNotify = NULL;
44
55
67
73{
74 if (!mv || !mv->mailbox)
75 return;
76
77 struct Mailbox *m = mv->mailbox;
78
79 for (int i = 0; i < m->msg_count; i++)
80 {
81 struct Email *e = m->emails[i];
82 if (!e)
83 break;
84 e->recip_valid = false;
85 }
86}
87
94enum CommandResult parse_alternates(const struct Command *cmd,
95 struct Buffer *line, struct Buffer *err)
96{
97 if (!MoreArgs(line))
98 {
99 buf_printf(err, _("%s: too few arguments"), cmd->name);
100 return MUTT_CMD_WARNING;
101 }
102
103 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
104 struct Buffer *token = buf_pool_get();
106
107 do
108 {
110
111 if (parse_grouplist(&gl, token, line, err, NeoMutt->groups) == -1)
112 goto done;
113
115
116 if (mutt_regexlist_add(&Alternates, buf_string(token), REG_ICASE, err) != 0)
117 goto done;
118
119 if (grouplist_add_regex(&gl, buf_string(token), REG_ICASE, err) != 0)
120 goto done;
121 } while (MoreArgs(line));
122
123 mutt_debug(LL_NOTIFY, "NT_ALTERN_ADD: %s\n", buf_string(token));
125
126 rc = MUTT_CMD_SUCCESS;
127
128done:
129 buf_pool_release(&token);
131 return rc;
132}
133
141 struct Buffer *line, struct Buffer *err)
142{
143 if (!MoreArgs(line))
144 {
145 buf_printf(err, _("%s: too few arguments"), cmd->name);
146 return MUTT_CMD_WARNING;
147 }
148
149 struct Buffer *token = buf_pool_get();
151
152 do
153 {
156
157 if (!mutt_str_equal(buf_string(token), "*") &&
158 (mutt_regexlist_add(&UnAlternates, buf_string(token), REG_ICASE, err) != 0))
159 {
160 goto done;
161 }
162
163 } while (MoreArgs(line));
164
165 mutt_debug(LL_NOTIFY, "NT_ALTERN_DELETE: %s\n", buf_string(token));
167
168 rc = MUTT_CMD_SUCCESS;
169
170done:
171 buf_pool_release(&token);
172 return rc;
173}
174
180bool mutt_alternates_match(const char *addr)
181{
182 if (!addr)
183 return false;
184
186 {
187 mutt_debug(LL_DEBUG5, "yes, %s matched by alternates\n", addr);
189 mutt_debug(LL_DEBUG5, "but, %s matched by unalternates\n", addr);
190 else
191 return true;
192 }
193
194 return false;
195}
Email Address Handling.
void alternates_cleanup(void)
Free the alternates lists.
Definition alternates.c:48
void alternates_init(void)
Set up the alternates lists.
Definition alternates.c:59
static struct RegexList Alternates
List of regexes to match the user's alternate email addresses.
Definition alternates.c:41
bool mutt_alternates_match(const char *addr)
Compare an Address to the Un/Alternates lists.
Definition alternates.c:180
static struct Notify * AlternatesNotify
Notifications: NotifyAlternates.
Definition alternates.c:43
void mutt_alternates_reset(struct MailboxView *mv)
Clear the recipient valid flag of all emails.
Definition alternates.c:72
static struct RegexList UnAlternates
List of regexes to exclude false matches in Alternates.
Definition alternates.c:42
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
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:35
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition command.h:38
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:36
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:37
int parse_grouplist(struct GroupList *gl, struct Buffer *token, struct Buffer *line, struct Buffer *err, struct HashTable *groups)
Parse a group context.
Definition commands.c:145
Functions to parse commands in a config file.
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:48
#define MoreArgs(buf)
Definition extract.h:30
#define TOKEN_NO_FLAGS
No flags are set.
Definition extract.h:44
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
enum CommandResult parse_alternates(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'alternates' command - Implements Command::parse() -.
Definition alternates.c:94
enum CommandResult parse_unalternates(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'unalternates' command - Implements Command::parse() -.
Definition alternates.c:140
#define mutt_debug(LEVEL,...)
Definition logging2.h:90
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:48
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:49
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
struct Notify * notify_new(void)
Create a new notifications handler.
Definition notify.c:62
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
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition notify.c:95
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition regex.c:178
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:139
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition regex.c:234
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition regex.c:199
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:660
View of a Mailbox.
@ 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:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:96
#define STAILQ_HEAD_INITIALIZER(head)
Definition queue.h:324
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the command.
Definition command.h:59
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: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:43
struct Notify * notify
Notifications handler.
Definition neomutt.h:44
struct HashTable * groups
Hash Table: "group-name" -> Group.
Definition neomutt.h:52
Notification API.
Definition notify.c:53