NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN
mutt_commands.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stddef.h>
32#include <string.h>
33#include "address/lib.h"
34#include "config/lib.h"
35#include "email/lib.h"
36#include "core/lib.h"
37#include "alias/lib.h"
38#include "mutt.h"
39#include "mutt_commands.h"
40#include "attach/lib.h"
41#include "color/lib.h"
42#include "command_parse.h"
43#include "hook.h"
44#include "keymap.h"
45#include "mutt_globals.h"
46#include "score.h"
47
48static const struct Command mutt_commands[] = {
49 // clang-format off
50 { "account-hook", mutt_parse_hook, MUTT_ACCOUNT_HOOK },
51 { "alias", parse_alias, 0 },
52 { "alternates", parse_alternates, 0 },
53 { "alternative_order", parse_stailq, IP &AlternativeOrderList },
54 { "attachments", parse_attachments, 0 },
55 { "auto_view", parse_stailq, IP &AutoViewList },
56 { "bind", mutt_parse_bind, 0 },
57 { "cd", parse_cd, 0 },
59 { "color", mutt_parse_color, 0 },
60 { "crypt-hook", mutt_parse_hook, MUTT_CRYPT_HOOK },
61 { "echo", parse_echo, 0 },
62 { "exec", mutt_parse_exec, 0 },
63 { "fcc-hook", mutt_parse_hook, MUTT_FCC_HOOK },
64 { "fcc-save-hook", mutt_parse_hook, MUTT_FCC_HOOK | MUTT_SAVE_HOOK },
65 { "finish", parse_finish, 0 },
66 { "folder-hook", mutt_parse_hook, MUTT_FOLDER_HOOK },
67 { "group", parse_group, MUTT_GROUP },
68 { "hdr_order", parse_stailq, IP &HeaderOrderList },
70 { "ifdef", parse_ifdef, 0 },
71 { "ifndef", parse_ifdef, 1 },
72 { "ignore", parse_ignore, 0 },
73 { "index-format-hook", mutt_parse_idxfmt_hook, 0 },
74 { "lists", parse_lists, 0 },
75 { "macro", mutt_parse_macro, 0 },
76 { "mailboxes", parse_mailboxes, 0 },
77 { "mailto_allow", parse_stailq, IP &MailToAllow },
78 { "mbox-hook", mutt_parse_hook, MUTT_MBOX_HOOK },
79 { "message-hook", mutt_parse_hook, MUTT_MESSAGE_HOOK },
80 { "mime_lookup", parse_stailq, IP &MimeLookupList },
81 { "mono", mutt_parse_mono, 0 },
82 { "my_hdr", parse_my_hdr, 0 },
83 { "named-mailboxes", parse_mailboxes, MUTT_NAMED },
84 { "nospam", parse_spam_list, MUTT_NOSPAM },
85 { "pgp-hook", mutt_parse_hook, MUTT_CRYPT_HOOK },
86 { "push", mutt_parse_push, 0 },
87 { "reply-hook", mutt_parse_hook, MUTT_REPLY_HOOK },
88 { "reset", parse_set, MUTT_SET_RESET },
89 { "save-hook", mutt_parse_hook, MUTT_SAVE_HOOK },
90 { "score", mutt_parse_score, 0 },
91 { "send-hook", mutt_parse_hook, MUTT_SEND_HOOK },
92 { "send2-hook", mutt_parse_hook, MUTT_SEND2_HOOK },
93 { "set", parse_set, MUTT_SET_SET },
94 { "setenv", parse_setenv, MUTT_SET_SET },
96 { "source", parse_source, 0 },
97 { "spam", parse_spam_list, MUTT_SPAM },
99 { "subjectrx", parse_subjectrx_list, 0 },
100 { "subscribe", parse_subscribe, 0 },
101 { "tag-formats", parse_tag_formats, 0 },
102 { "tag-transforms", parse_tag_transforms, 0 },
104 { "toggle", parse_set, MUTT_SET_INV },
105 { "unalias", parse_unalias, 0 },
106 { "unalternates", parse_unalternates, 0 },
107 { "unalternative_order", parse_unstailq, IP &AlternativeOrderList },
108 { "unattachments", parse_unattachments, 0 },
109 { "unauto_view", parse_unstailq, IP &AutoViewList },
110 { "unbind", mutt_parse_unbind, MUTT_UNBIND },
111 { "uncolor", mutt_parse_uncolor, 0 },
112 { "ungroup", parse_group, MUTT_UNGROUP },
113 { "unhdr_order", parse_unstailq, IP &HeaderOrderList },
114 { "unhook", mutt_parse_unhook, 0 },
115 { "unignore", parse_unignore, 0 },
116 { "unlists", parse_unlists, 0 },
117 { "unmacro", mutt_parse_unbind, MUTT_UNMACRO },
118 { "unmailboxes", parse_unmailboxes, 0 },
119 { "unmailto_allow", parse_unstailq, IP &MailToAllow },
120 { "unmime_lookup", parse_unstailq, IP &MimeLookupList },
121 { "unmono", mutt_parse_unmono, 0 },
122 { "unmy_hdr", parse_unmy_hdr, 0 },
123 { "unscore", mutt_parse_unscore, 0 },
124 { "unset", parse_set, MUTT_SET_UNSET },
125 { "unsetenv", parse_setenv, MUTT_SET_UNSET },
126 { "unsubjectrx", parse_unsubjectrx_list, 0 },
127 { "unsubscribe", parse_unsubscribe, 0 },
128 // clang-format on
129};
130
131ARRAY_HEAD(CommandArray, struct Command);
132struct CommandArray commands = ARRAY_HEAD_INITIALIZER;
133
138{
139 ARRAY_RESERVE(&commands, 100);
141}
142
146int commands_cmp(const void *a, const void *b)
147{
148 struct Command x = *(const struct Command *) a;
149 struct Command y = *(const struct Command *) b;
150
151 return strcmp(x.name, y.name);
152}
153
159void commands_register(const struct Command *cmds, const size_t num_cmds)
160{
161 for (int i = 0; i < num_cmds; i++)
162 {
163 ARRAY_ADD(&commands, cmds[i]);
164 }
166}
167
172{
174}
175
181size_t mutt_commands_array(struct Command **first)
182{
183 *first = ARRAY_FIRST(&commands);
184 return ARRAY_SIZE(&commands);
185}
186
193struct Command *mutt_command_get(const char *s)
194{
195 struct Command *cmd = NULL;
197 {
198 if (mutt_str_equal(s, cmd->name))
199 return cmd;
200 }
201 return NULL;
202}
203
204#ifdef USE_LUA
212void mutt_commands_apply(void *data, void (*application)(void *, const struct Command *))
213{
214 struct Command *cmd = NULL;
216 {
217 application(data, cmd);
218 }
219}
220#endif
Email Address Handling.
Email Aliases.
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:188
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:277
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:134
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:155
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:203
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:57
GUI display the mailboxes in a side panel.
Color and attribute parsing.
Functions to parse commands in a config file.
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
Structs that make up an email.
struct ListHead MailToAllow
List of permitted fields in a mailto: url.
Definition: globals.c:37
#define MUTT_GROUP
'group' config command
Definition: group.h:33
#define MUTT_UNGROUP
'ungroup' config command
Definition: group.h:34
enum CommandResult mutt_parse_idxfmt_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'index-format-hook' command - Implements Command::parse() -.
Definition: hook.c:411
enum CommandResult parse_unmy_hdr(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unmy_hdr' command - Implements Command::parse() -.
enum CommandResult parse_tag_formats(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'tag-formats' command - Implements Command::parse() -.
enum CommandResult parse_tag_transforms(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'tag-transforms' command - Implements Command::parse() -.
enum CommandResult parse_unsubjectrx_list(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unsubjectrx' command - Implements Command::parse() -.
Definition: subjectrx.c:180
enum CommandResult parse_unstailq(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse an unlist command - Implements Command::parse() -.
enum CommandResult parse_set(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'set' family of commands - Implements Command::parse() -.
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 mutt_parse_unscore(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unscore' command - Implements Command::parse() -.
Definition: score.c:195
enum CommandResult mutt_parse_unmono(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unmono' command - Implements Command::parse() -.
Definition: command.c:681
enum CommandResult mutt_parse_bind(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'bind' command - Implements Command::parse() -.
Definition: keymap.c:1280
enum CommandResult parse_ifdef(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'ifdef' and 'ifndef' commands - Implements Command::parse() -.
enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'hook' family of commands - Implements Command::parse() -.
Definition: hook.c:128
enum CommandResult parse_echo(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'echo' command - Implements Command::parse() -.
enum CommandResult parse_subjectrx_list(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'subjectrx' command - Implements Command::parse() -.
Definition: subjectrx.c:163
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
enum CommandResult mutt_parse_score(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'score' command - Implements Command::parse() -.
Definition: score.c:86
enum CommandResult parse_unmailboxes(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unmailboxes' command - Implements Command::parse() -.
enum CommandResult parse_unsubscribe(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unsubscribe' command - Implements Command::parse() -.
enum CommandResult parse_unignore(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unignore' command - Implements Command::parse() -.
enum CommandResult mutt_parse_mono(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'mono' command - Implements Command::parse() -.
Definition: command.c:706
enum CommandResult mutt_parse_color(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'color' command - Implements Command::parse() -.
Definition: command.c:691
enum CommandResult mutt_parse_uncolor(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'uncolor' command - Implements Command::parse() -.
Definition: command.c:663
enum CommandResult parse_finish(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'finish' command - Implements Command::parse() -.
enum CommandResult parse_unlists(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unlists' command - Implements Command::parse() -.
enum CommandResult mutt_parse_unbind(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unbind' command - Implements Command::parse() -.
Definition: keymap.c:1430
enum CommandResult parse_group(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'group' and 'ungroup' commands - Implements Command::parse() -.
enum CommandResult parse_alias(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'alias' command - Implements Command::parse() -.
Definition: commands.c:48
enum CommandResult parse_source(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'source' command - Implements Command::parse() -.
enum CommandResult parse_unalias(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unalias' command - Implements Command::parse() -.
Definition: commands.c:161
enum CommandResult mutt_parse_charset_iconv_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse 'charset-hook' and 'iconv-hook' commands - Implements Command::parse() -.
Definition: hook.c:83
enum CommandResult parse_mailboxes(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'mailboxes' command - Implements Command::parse() -.
enum CommandResult parse_lists(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'lists' command - Implements Command::parse() -.
enum CommandResult parse_cd(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'cd' command - Implements Command::parse() -.
enum CommandResult parse_spam_list(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'spam' and 'nospam' commands - Implements Command::parse() -.
enum CommandResult mutt_parse_macro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'macro' command - Implements Command::parse() -.
Definition: keymap.c:1513
enum CommandResult parse_setenv(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'setenv' and 'unsetenv' commands - Implements Command::parse() -.
enum CommandResult parse_unattachments(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unattachments' command - Implements Command::parse() -.
Definition: attachments.c:529
enum CommandResult mutt_parse_unhook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unhook' command - Implements Command::parse() -.
Definition: hook.c:538
enum CommandResult parse_my_hdr(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'my_hdr' command - Implements Command::parse() -.
enum CommandResult parse_subscribe(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'subscribe' command - Implements Command::parse() -.
enum CommandResult parse_stailq(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse a list command - Implements Command::parse() -.
enum CommandResult mutt_parse_push(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'push' command - Implements Command::parse() -.
Definition: keymap.c:1117
enum CommandResult parse_attachments(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'attachments' command - Implements Command::parse() -.
Definition: attachments.c:470
enum CommandResult mutt_parse_exec(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'exec' command - Implements Command::parse() -.
Definition: keymap.c:1588
enum CommandResult parse_ignore(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'ignore' command - Implements Command::parse() -.
int commands_cmp(const void *a, const void *b)
Compare two commands by name - Implements sort_t -.
Parse and execute user-defined hooks.
#define MUTT_ICONV_HOOK
iconv-hook: create a system charset alias
Definition: hook.h:44
#define MUTT_FOLDER_HOOK
folder-hook: when entering a mailbox
Definition: hook.h:38
#define MUTT_SAVE_HOOK
save-hook: set a default folder when saving an email
Definition: hook.h:42
#define MUTT_SEND_HOOK
send-hook: when composing a new email
Definition: hook.h:40
#define MUTT_FCC_HOOK
fcc-hook: to save outgoing email
Definition: hook.h:41
#define MUTT_ACCOUNT_HOOK
account-hook: when changing between accounts
Definition: hook.h:47
#define MUTT_GLOBAL_HOOK
Hooks which don't take a regex.
Definition: hook.h:59
#define MUTT_STARTUP_HOOK
startup-hook: run when starting NeoMutt
Definition: hook.h:57
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:49
#define MUTT_CRYPT_HOOK
crypt-hook: automatically select a PGP/SMIME key
Definition: hook.h:46
#define MUTT_MBOX_HOOK
mbox-hook: move messages after reading them
Definition: hook.h:39
#define MUTT_REPLY_HOOK
reply-hook: when replying to an email
Definition: hook.h:48
#define MUTT_TIMEOUT_HOOK
timeout-hook: run a command periodically
Definition: hook.h:56
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:45
#define MUTT_SHUTDOWN_HOOK
shutdown-hook: run when leaving NeoMutt
Definition: hook.h:58
#define MUTT_CHARSET_HOOK
charset-hook: create a charset alias for malformed emails
Definition: hook.h:43
Manage keymappings.
#define MUTT_UNBIND
Definition: keymap.h:33
#define MUTT_UNMACRO
Definition: keymap.h:34
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_NOSPAM
Definition: mutt.h:112
#define MUTT_SPAM
Definition: mutt.h:111
void mutt_commands_free(void)
Free Commands array.
void mutt_commands_apply(void *data, void(*application)(void *, const struct Command *))
Run a callback function on every Command.
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
ARRAY_HEAD(CommandArray, struct Command)
size_t mutt_commands_array(struct Command **first)
Get Commands array.
void mutt_commands_init(void)
Initialize commands array and register default commands.
struct CommandArray commands
struct Command * mutt_command_get(const char *s)
Get a Command by its name.
static const struct Command mutt_commands[]
Definition: mutt_commands.c:48
Definitions of NeoMutt commands.
#define MUTT_NAMED
Definition: mutt_commands.h:44
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:47
@ MUTT_SET_INV
default is to invert all vars
Definition: mutt_commands.h:38
@ MUTT_SET_SET
default is to set all vars
Definition: mutt_commands.h:37
@ MUTT_SET_RESET
default is to reset all vars to default
Definition: mutt_commands.h:40
@ MUTT_SET_UNSET
default is to unset all vars
Definition: mutt_commands.h:39
Hundreds of global variables to back the user variables.
struct ListHead MimeLookupList
List of mime types that that shouldn't use the mailcap entry.
Definition: mutt_globals.h:63
struct ListHead AlternativeOrderList
List of preferred mime types to display.
Definition: mutt_globals.h:60
struct ListHead AutoViewList
List of mime types to auto view.
Definition: mutt_globals.h:61
struct ListHead HeaderOrderList
List of header fields in the order they should be displayed.
Definition: mutt_globals.h:62
Routines for adding user scores to emails.
#define IP
Definition: set.h:54
intptr_t data
Data or flags to pass to the command.
Definition: command.h:65
const char * name
Name of the command.
Definition: command.h:50