NeoMutt  2021-10-29-220-g2b1eec
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 "color/lib.h"
41 #include "command_parse.h"
42 #include "hook.h"
43 #include "keymap.h"
44 #include "mutt_globals.h"
45 #include "score.h"
46 
47 static const struct Command mutt_commands[] = {
48  // clang-format off
49  { "account-hook", mutt_parse_hook, MUTT_ACCOUNT_HOOK },
50  { "alias", parse_alias, 0 },
51  { "alternates", parse_alternates, 0 },
52  { "alternative_order", parse_stailq, IP &AlternativeOrderList },
53  { "attachments", parse_attachments, 0 },
54  { "auto_view", parse_stailq, IP &AutoViewList },
55  { "bind", mutt_parse_bind, 0 },
56  { "cd", parse_cd, 0 },
57  { "charset-hook", mutt_parse_hook, MUTT_CHARSET_HOOK },
58  { "color", mutt_parse_color, 0 },
59  { "crypt-hook", mutt_parse_hook, MUTT_CRYPT_HOOK },
60  { "echo", parse_echo, 0 },
61  { "exec", mutt_parse_exec, 0 },
62  { "fcc-hook", mutt_parse_hook, MUTT_FCC_HOOK },
63  { "fcc-save-hook", mutt_parse_hook, MUTT_FCC_HOOK | MUTT_SAVE_HOOK },
64  { "finish", parse_finish, 0 },
65  { "folder-hook", mutt_parse_hook, MUTT_FOLDER_HOOK },
66  { "group", parse_group, MUTT_GROUP },
67  { "hdr_order", parse_stailq, IP &HeaderOrderList },
68  { "iconv-hook", mutt_parse_hook, MUTT_ICONV_HOOK },
69  { "ifdef", parse_ifdef, 0 },
70  { "ifndef", parse_ifdef, 1 },
71  { "ignore", parse_ignore, 0 },
72  { "index-format-hook", mutt_parse_idxfmt_hook, 0 },
73  { "lists", parse_lists, 0 },
74  { "macro", mutt_parse_macro, 0 },
75  { "mailboxes", parse_mailboxes, 0 },
76  { "mailto_allow", parse_stailq, IP &MailToAllow },
77  { "mbox-hook", mutt_parse_hook, MUTT_MBOX_HOOK },
78  { "message-hook", mutt_parse_hook, MUTT_MESSAGE_HOOK },
79  { "mime_lookup", parse_stailq, IP &MimeLookupList },
80  { "mono", mutt_parse_mono, 0 },
81  { "my_hdr", parse_my_hdr, 0 },
82  { "named-mailboxes", parse_mailboxes, MUTT_NAMED },
83  { "nospam", parse_spam_list, MUTT_NOSPAM },
84  { "pgp-hook", mutt_parse_hook, MUTT_CRYPT_HOOK },
85  { "push", mutt_parse_push, 0 },
86  { "reply-hook", mutt_parse_hook, MUTT_REPLY_HOOK },
87  { "reset", parse_set, MUTT_SET_RESET },
88  { "save-hook", mutt_parse_hook, MUTT_SAVE_HOOK },
89  { "score", mutt_parse_score, 0 },
90  { "send-hook", mutt_parse_hook, MUTT_SEND_HOOK },
91  { "send2-hook", mutt_parse_hook, MUTT_SEND2_HOOK },
92  { "set", parse_set, MUTT_SET_SET },
93  { "setenv", parse_setenv, MUTT_SET_SET },
94  { "shutdown-hook", mutt_parse_hook, MUTT_SHUTDOWN_HOOK | MUTT_GLOBAL_HOOK },
95  { "source", parse_source, 0 },
96  { "spam", parse_spam_list, MUTT_SPAM },
97  { "startup-hook", mutt_parse_hook, MUTT_STARTUP_HOOK | MUTT_GLOBAL_HOOK },
98  { "subjectrx", parse_subjectrx_list, 0 },
99  { "subscribe", parse_subscribe, 0 },
100  { "tag-formats", parse_tag_formats, 0 },
101  { "tag-transforms", parse_tag_transforms, 0 },
102  { "timeout-hook", mutt_parse_hook, MUTT_TIMEOUT_HOOK | MUTT_GLOBAL_HOOK },
103  { "toggle", parse_set, MUTT_SET_INV },
104  { "unalias", parse_unalias, 0 },
105  { "unalternates", parse_unalternates, 0 },
106  { "unalternative_order", parse_unstailq, IP &AlternativeOrderList },
107  { "unattachments", parse_unattachments, 0 },
108  { "unauto_view", parse_unstailq, IP &AutoViewList },
109  { "unbind", mutt_parse_unbind, MUTT_UNBIND },
110  { "uncolor", mutt_parse_uncolor, 0 },
111  { "ungroup", parse_group, MUTT_UNGROUP },
112  { "unhdr_order", parse_unstailq, IP &HeaderOrderList },
113  { "unhook", mutt_parse_unhook, 0 },
114  { "unignore", parse_unignore, 0 },
115  { "unlists", parse_unlists, 0 },
116  { "unmacro", mutt_parse_unbind, MUTT_UNMACRO },
117  { "unmailboxes", parse_unmailboxes, 0 },
118  { "unmailto_allow", parse_unstailq, IP &MailToAllow },
119  { "unmime_lookup", parse_unstailq, IP &MimeLookupList },
120  { "unmono", mutt_parse_unmono, 0 },
121  { "unmy_hdr", parse_unmy_hdr, 0 },
122  { "unscore", mutt_parse_unscore, 0 },
123  { "unset", parse_set, MUTT_SET_UNSET },
124  { "unsetenv", parse_setenv, MUTT_SET_UNSET },
125  { "unsubjectrx", parse_unsubjectrx_list, 0 },
126  { "unsubscribe", parse_unsubscribe, 0 },
127  // clang-format on
128 };
129 
130 ARRAY_HEAD(CommandArray, struct Command);
131 struct CommandArray commands = ARRAY_HEAD_INITIALIZER;
132 
137 {
138  ARRAY_RESERVE(&commands, 100);
140 }
141 
145 int commands_cmp(const void *a, const void *b)
146 {
147  struct Command x = *(const struct Command *) a;
148  struct Command y = *(const struct Command *) b;
149 
150  return strcmp(x.name, y.name);
151 }
152 
158 void commands_register(const struct Command *cmds, const size_t num_cmds)
159 {
160  for (int i = 0; i < num_cmds; i++)
161  {
162  ARRAY_ADD(&commands, cmds[i]);
163  }
165 }
166 
171 {
173 }
174 
180 size_t mutt_commands_array(struct Command **first)
181 {
182  *first = ARRAY_FIRST(&commands);
183  return ARRAY_SIZE(&commands);
184 }
185 
192 struct Command *mutt_command_get(const char *s)
193 {
194  struct Command *cmd = NULL;
195  ARRAY_FOREACH(cmd, &commands)
196  {
197  if (mutt_str_equal(s, cmd->name))
198  return cmd;
199  }
200  return NULL;
201 }
202 
203 #ifdef USE_LUA
211 void mutt_commands_apply(void *data, void (*application)(void *, const struct Command *))
212 {
213  struct Command *cmd = NULL;
214  ARRAY_FOREACH(cmd, &commands)
215  {
216  application(data, cmd);
217  }
218 }
219 #endif
Email Address Handling.
Email Aliases.
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:185
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:274
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:131
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:208
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:200
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:54
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:373
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:201
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:715
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:1351
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:82
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:88
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:743
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:729
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:701
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:1501
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 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:1584
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:531
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:480
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:1188
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:472
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:1659
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:715
Many unsorted constants and some structs.
#define MUTT_NOSPAM
Definition: mutt.h:111
#define MUTT_SPAM
Definition: mutt.h:110
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)
struct Command * mutt_command_get(const char *s)
Get a Command by its name.
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
static const struct Command mutt_commands[]
Definition: mutt_commands.c:47
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:65
struct ListHead AlternativeOrderList
List of preferred mime types to display.
Definition: mutt_globals.h:62
struct ListHead AutoViewList
List of mime types to auto view.
Definition: mutt_globals.h:63
struct ListHead HeaderOrderList
List of header fields in the order they should be displayed.
Definition: mutt_globals.h:64
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:63
const char * name
Name of the command.
Definition: command.h:48