NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
commands.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 "core/lib.h"
34#include "commands/lib.h"
35#include "parse/lib.h"
36#include "group.h"
37#include "ignore.h"
38#include "module_data.h"
39#include "score.h"
40#include "spam.h"
41
51enum CommandResult parse_list(const struct Command *cmd, struct Buffer *line,
52 const struct ParseContext *pc, struct ParseError *pe)
53{
55 ASSERT(md);
56
57 switch (cmd->id)
58 {
60 return parse_stailq(cmd, line, &md->alternative_order, pc, pe);
61
62 case CMD_AUTO_VIEW:
63 return parse_stailq(cmd, line, &md->auto_view, pc, pe);
64
66 return parse_stailq(cmd, line, &md->header_order, pc, pe);
67
69 return parse_stailq(cmd, line, &md->mail_to_allow, pc, pe);
70
71 default:
72 ASSERT(false);
73 }
74
75 return MUTT_CMD_ERROR;
76}
77
87enum CommandResult parse_unlist(const struct Command *cmd, struct Buffer *line,
88 const struct ParseContext *pc, struct ParseError *pe)
89{
91 ASSERT(md);
92
93 switch (cmd->id)
94 {
96 return parse_unstailq(cmd, line, &md->alternative_order, pc, pe);
97
98 case CMD_UNAUTO_VIEW:
99 return parse_unstailq(cmd, line, &md->auto_view, pc, pe);
100
102 return parse_unstailq(cmd, line, &md->header_order, pc, pe);
103
105 return parse_unstailq(cmd, line, &md->mail_to_allow, pc, pe);
106
107 default:
108 ASSERT(false);
109 }
110
111 return MUTT_CMD_ERROR;
112}
113
124enum CommandResult parse_tag_formats(const struct Command *cmd, struct Buffer *line,
125 const struct ParseContext *pc, struct ParseError *pe)
126{
127 struct Buffer *err = pe->message;
128
129 if (!MoreArgs(line))
130 {
131 buf_printf(err, _("%s: too few arguments"), cmd->name);
132 return MUTT_CMD_WARNING;
133 }
134
135 struct Buffer *tag = buf_pool_get();
136 struct Buffer *fmt = buf_pool_get();
137
139 ASSERT(md);
140
141 while (MoreArgs(line))
142 {
144 if (buf_is_empty(tag))
145 continue;
146
148
149 /* avoid duplicates */
150 const char *tmp = mutt_hash_find(md->tag_formats, buf_string(fmt));
151 if (tmp)
152 {
153 mutt_warning(_("tag format '%s' already registered as '%s'"), buf_string(fmt), tmp);
154 continue;
155 }
156
158 }
159
160 buf_pool_release(&tag);
161 buf_pool_release(&fmt);
162 return MUTT_CMD_SUCCESS;
163}
164
175enum CommandResult parse_tag_transforms(const struct Command *cmd, struct Buffer *line,
176 const struct ParseContext *pc,
177 struct ParseError *pe)
178{
179 struct Buffer *err = pe->message;
180
181 if (!MoreArgs(line))
182 {
183 buf_printf(err, _("%s: too few arguments"), cmd->name);
184 return MUTT_CMD_WARNING;
185 }
186
187 struct Buffer *tag = buf_pool_get();
188 struct Buffer *trans = buf_pool_get();
189
191 ASSERT(md);
192
193 while (MoreArgs(line))
194 {
196 if (buf_is_empty(tag))
197 continue;
198
200 const char *trn = buf_string(trans);
201
202 /* avoid duplicates */
203 const char *tmp = mutt_hash_find(md->tag_transforms, buf_string(tag));
204 if (tmp)
205 {
206 mutt_warning(_("tag transform '%s' already registered as '%s'"),
207 buf_string(tag), tmp);
208 continue;
209 }
210
212 }
213
214 buf_pool_release(&tag);
215 buf_pool_release(&trans);
216 return MUTT_CMD_SUCCESS;
217}
218
222const struct Command EmailCommands[] = {
223 // clang-format off
224 { "alternative-order", CMD_ALTERNATIVE_ORDER, parse_list,
225 N_("Set preference order for multipart alternatives"),
226 N_("alternative-order <mime-type>[/<mime-subtype> ] [ ... ]"),
227 "mimesupport.html#alternative-order" },
228 { "auto-view", CMD_AUTO_VIEW, parse_list,
229 N_("Automatically display specified MIME types inline"),
230 N_("auto-view <mime-type>[/<mime-subtype> ] [ ... ]"),
231 "mimesupport.html#auto-view" },
232 { "group", CMD_GROUP, parse_group,
233 N_("Add addresses to an address group"),
234 N_("group [ -group <name> ... ] { -rx <regex> ... | -addr <address> ... }"),
235 "configuration.html#addrgroup" },
236 { "header-order", CMD_HEADER_ORDER, parse_list,
237 N_("Define custom order of headers displayed"),
238 N_("header-order <header> [ <header> ... ]"),
239 "configuration.html#header-order" },
240 { "ignore", CMD_IGNORE, parse_ignore,
241 N_("Hide specified headers when displaying messages"),
242 N_("ignore <string> [ <string> ...]"),
243 "configuration.html#ignore" },
244 { "lists", CMD_LISTS, parse_lists,
245 N_("Add address to the list of mailing lists"),
246 N_("lists [ -group <name> ... ] <regex> [ ... ]"),
247 "configuration.html#lists" },
248 { "mailto-allow", CMD_MAILTO_ALLOW, parse_list,
249 N_("Permit specific header-fields in mailto URL processing"),
250 N_("mailto-allow { * | <header-field> ... }"),
251 "configuration.html#mailto-allow" },
252 { "nospam", CMD_NOSPAM, parse_nospam,
253 N_("Remove a spam detection rule"),
254 N_("nospam { * | <regex> }"),
255 "configuration.html#spam" },
256 { "score", CMD_SCORE, parse_score,
257 N_("Set a score value on emails matching a pattern"),
258 N_("score <pattern> <value>"),
259 "configuration.html#score-command" },
260 { "spam", CMD_SPAM, parse_spam,
261 N_("Define rules to parse spam detection headers"),
262 N_("spam <regex> [ <format> ]"),
263 "configuration.html#spam" },
264 { "tag-formats", CMD_TAG_FORMATS, parse_tag_formats,
265 N_("Define expandos tags"),
266 N_("tag-formats <tag> <format-string> [ ... ] }"),
267 "optionalfeatures.html#custom-tags" },
268 { "tag-transforms", CMD_TAG_TRANSFORMS, parse_tag_transforms,
269 N_("Rules to transform tags into icons"),
270 N_("tag-transforms <tag> <transformed-string> [ ... ]"),
271 "optionalfeatures.html#custom-tags" },
272 { "unalternative-order", CMD_UNALTERNATIVE_ORDER, parse_unlist,
273 N_("Remove MIME types from preference order"),
274 N_("unalternative-order { * | [ <mime-type>[/<mime-subtype> ] ... ] }"),
275 "mimesupport.html#alternative-order" },
276 { "unauto-view", CMD_UNAUTO_VIEW, parse_unlist,
277 N_("Remove MIME types from `auto-view` list"),
278 N_("unauto-view { * | [ <mime-type>[/<mime-subtype> ] ... ] }"),
279 "mimesupport.html#auto-view" },
280 { "ungroup", CMD_UNGROUP, parse_group,
281 N_("Remove addresses from an address `group`"),
282 N_("ungroup [ -group <name> ... ] { * | -rx <regex> ... | -addr <address> ... }"),
283 "configuration.html#addrgroup" },
284 { "unheader-order", CMD_UNHEADER_ORDER, parse_unlist,
285 N_("Remove header from `header-order` list"),
286 N_("unheader-order { * | <header> ... }"),
287 "configuration.html#header-order" },
288 { "unignore", CMD_UNIGNORE, parse_unignore,
289 N_("Remove a header from the `header-order` list"),
290 N_("unignore { * | <string> ... }"),
291 "configuration.html#ignore" },
292 { "unlists", CMD_UNLISTS, parse_unlists,
293 N_("Remove address from the list of mailing lists"),
294 N_("unlists { * | <regex> ... }"),
295 "configuration.html#lists" },
296 { "unmailto-allow", CMD_UNMAILTO_ALLOW, parse_unlist,
297 N_("Disallow header-fields in mailto processing"),
298 N_("unmailto-allow { * | <header-field> ... }"),
299 "configuration.html#mailto-allow" },
300 { "unscore", CMD_UNSCORE, parse_unscore,
301 N_("Remove scoring rules for matching patterns"),
302 N_("unscore { * | <pattern> ... }"),
303 "configuration.html#score-command" },
304
305 // Deprecated
306 { "alternative_order", CMD_NONE, NULL, "alternative-order", NULL, NULL, CF_SYNONYM },
307 { "auto_view", CMD_NONE, NULL, "auto-view", NULL, NULL, CF_SYNONYM },
308 { "hdr_order", CMD_NONE, NULL, "header-order", NULL, NULL, CF_SYNONYM },
309 { "mailto_allow", CMD_NONE, NULL, "mailto-allow", NULL, NULL, CF_SYNONYM },
310 { "unalternative_order", CMD_NONE, NULL, "unalternative-order", NULL, NULL, CF_SYNONYM },
311 { "unauto_view", CMD_NONE, NULL, "unauto-view", NULL, NULL, CF_SYNONYM },
312 { "unhdr_order", CMD_NONE, NULL, "unheader-order", NULL, NULL, CF_SYNONYM },
313 { "unmailto_allow", CMD_NONE, NULL, "unmailto-allow", NULL, NULL, CF_SYNONYM },
314
315 { NULL, CMD_NONE, NULL, NULL, NULL, NULL, CF_NO_FLAGS },
316 // clang-format on
317};
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
#define CF_SYNONYM
Command is a synonym for another command.
Definition command.h:49
#define CF_NO_FLAGS
No flags are set.
Definition command.h:48
@ CMD_SPAM
:spam
Definition command.h:114
@ CMD_IGNORE
:ignore
Definition command.h:85
@ CMD_GROUP
:group
Definition command.h:79
@ CMD_TAG_TRANSFORMS
:tag-transforms
Definition command.h:120
@ CMD_SCORE
:score
Definition command.h:105
@ CMD_MAILTO_ALLOW
:mailto-allow
Definition command.h:92
@ CMD_LISTS
:lists
Definition command.h:87
@ CMD_AUTO_VIEW
:auto-view
Definition command.h:66
@ CMD_UNALTERNATIVE_ORDER
:unalternative-order
Definition command.h:125
@ CMD_UNAUTO_VIEW
:unauto-view
Definition command.h:127
@ CMD_UNHEADER_ORDER
:unheader-order
Definition command.h:131
@ CMD_NOSPAM
:nospam
Definition command.h:99
@ CMD_UNGROUP
:ungroup
Definition command.h:130
@ CMD_NONE
No Command.
Definition command.h:59
@ CMD_TAG_FORMATS
:tag-formats
Definition command.h:119
@ CMD_UNIGNORE
:unignore
Definition command.h:133
@ CMD_UNLISTS
:unlists
Definition command.h:134
@ CMD_ALTERNATIVE_ORDER
:alternative-order
Definition command.h:63
@ CMD_UNSCORE
:unscore
Definition command.h:141
@ CMD_HEADER_ORDER
:header-order
Definition command.h:80
@ CMD_UNMAILTO_ALLOW
:unmailto-allow
Definition command.h:137
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
NeoMutt Commands.
Convenience wrapper for the core headers.
const struct Command EmailCommands[]
Email Commands.
Definition commands.c:222
Parse Group/Lists Commands.
Email private Module data.
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_tag_transforms(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'tag-transforms' command - Implements Command::parse() -.
Definition commands.c:175
enum CommandResult parse_stailq(const struct Command *cmd, struct Buffer *line, struct ListHead *list, const struct ParseContext *pc, struct ParseError *pe)
Parse a list command - Implements Command::parse() -.
Definition stailq.c:52
enum CommandResult parse_unstailq(const struct Command *cmd, struct Buffer *line, struct ListHead *list, const struct ParseContext *pc, struct ParseError *pe)
Parse an unlist command - Implements Command::parse() -.
Definition stailq.c:85
enum CommandResult parse_nospam(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'nospam' command - Implements Command::parse() -.
Definition spam.c:51
enum CommandResult parse_unlist(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse an unlist command - Implements Command::parse() -.
Definition commands.c:87
enum CommandResult parse_tag_formats(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'tag-formats' command - Implements Command::parse() -.
Definition commands.c:124
enum CommandResult parse_unlists(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'unlists' command - Implements Command::parse() -.
Definition group.c:288
enum CommandResult parse_lists(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'lists' command - Implements Command::parse() -.
Definition group.c:188
enum CommandResult parse_group(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'group' and 'ungroup' commands - Implements Command::parse() -.
Definition group.c:90
enum CommandResult parse_unscore(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'unscore' command - Implements Command::parse() -.
Definition score.c:146
enum CommandResult parse_unignore(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'unignore' command - Implements Command::parse() -.
Definition ignore.c:83
enum CommandResult parse_spam(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'spam' command - Implements Command::parse() -.
Definition spam.c:113
enum CommandResult parse_ignore(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'ignore' command - Implements Command::parse() -.
Definition ignore.c:50
enum CommandResult parse_score(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'score' command - Implements Command::parse() -.
Definition score.c:57
enum CommandResult parse_list(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse a list command - Implements Command::parse() -.
Definition commands.c:51
#define mutt_warning(...)
Definition logging2.h:92
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:337
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:364
Parse Ignore Commands.
@ MODULE_ID_EMAIL
ModuleEmail, Email code
Definition module_api.h:64
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
#define _(a)
Definition message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:585
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
Routines for adding user scores to emails.
#define ASSERT(COND)
Definition signal2.h:59
Parse Spam Commands.
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the Command.
Definition command.h:159
enum CommandId id
ID of the Command.
Definition command.h:160
Email private Module data.
Definition module_data.h:32
struct HashTable * tag_formats
Hash Table: "inbox" -> "GI" - Tag format strings.
Definition module_data.h:43
struct ListHead auto_view
List of mime types to auto view.
Definition module_data.h:35
struct ListHead mail_to_allow
Permitted fields in a mailto: url.
Definition module_data.h:39
struct ListHead alternative_order
List of preferred mime types to display.
Definition module_data.h:33
struct HashTable * tag_transforms
Hash Table: "inbox" -> "i" - Alternative tag names.
Definition module_data.h:44
struct ListHead header_order
List of header fields in the order they should be displayed.
Definition module_data.h:36
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