NeoMutt  2021-02-05-89-gabe350
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 "address/lib.h"
33 #include "config/lib.h"
34 #include "email/lib.h"
35 #include "alias/lib.h"
36 #include "gui/lib.h"
37 #include "mutt.h"
38 #include "mutt_commands.h"
39 #include "command_parse.h"
40 #include "hook.h"
41 #include "keymap.h"
42 #include "mutt_globals.h"
43 #include "mutt_lua.h"
44 #include "score.h"
45 #ifdef USE_SIDEBAR
46 #include "sidebar/lib.h"
47 #endif
48 
49 static const struct Command mutt_commands[] = {
50  // clang-format off
51  { "account-hook", mutt_parse_hook, MUTT_ACCOUNT_HOOK },
52  { "alias", parse_alias, 0 },
53  { "alternates", parse_alternates, 0 },
54  { "alternative_order", parse_stailq, IP &AlternativeOrderList },
55  { "attachments", parse_attachments, 0 },
56  { "auto_view", parse_stailq, IP &AutoViewList },
57  { "bind", mutt_parse_bind, 0 },
58  { "cd", parse_cd, 0 },
59  { "charset-hook", mutt_parse_hook, MUTT_CHARSET_HOOK },
60 #ifdef HAVE_COLOR
61  { "color", mutt_parse_color, 0 },
62 #endif
63  { "crypt-hook", mutt_parse_hook, MUTT_CRYPT_HOOK },
64  { "echo", parse_echo, 0 },
65  { "exec", mutt_parse_exec, 0 },
66  { "fcc-hook", mutt_parse_hook, MUTT_FCC_HOOK },
67  { "fcc-save-hook", mutt_parse_hook, MUTT_FCC_HOOK | MUTT_SAVE_HOOK },
68  { "finish", parse_finish, 0 },
69  { "folder-hook", mutt_parse_hook, MUTT_FOLDER_HOOK },
70  { "group", parse_group, MUTT_GROUP },
71  { "hdr_order", parse_stailq, IP &HeaderOrderList },
72  { "iconv-hook", mutt_parse_hook, MUTT_ICONV_HOOK },
73  { "ifdef", parse_ifdef, 0 },
74  { "ifndef", parse_ifdef, 1 },
75  { "ignore", parse_ignore, 0 },
76  { "index-format-hook", mutt_parse_idxfmt_hook, 0 },
77  { "lists", parse_lists, 0 },
78  { "macro", mutt_parse_macro, 0 },
79  { "mailboxes", parse_mailboxes, 0 },
80  { "mailto_allow", parse_stailq, IP &MailToAllow },
81  { "mbox-hook", mutt_parse_hook, MUTT_MBOX_HOOK },
82  { "message-hook", mutt_parse_hook, MUTT_MESSAGE_HOOK },
83  { "mime_lookup", parse_stailq, IP &MimeLookupList },
84  { "mono", mutt_parse_mono, 0 },
85  { "my_hdr", parse_my_hdr, 0 },
86  { "named-mailboxes", parse_mailboxes, MUTT_NAMED },
87  { "nospam", parse_spam_list, MUTT_NOSPAM },
88  { "pgp-hook", mutt_parse_hook, MUTT_CRYPT_HOOK },
89  { "push", mutt_parse_push, 0 },
90  { "reply-hook", mutt_parse_hook, MUTT_REPLY_HOOK },
91  { "reset", parse_set, MUTT_SET_RESET },
92  { "save-hook", mutt_parse_hook, MUTT_SAVE_HOOK },
93  { "score", mutt_parse_score, 0 },
94  { "send-hook", mutt_parse_hook, MUTT_SEND_HOOK },
95  { "send2-hook", mutt_parse_hook, MUTT_SEND2_HOOK },
96  { "set", parse_set, MUTT_SET_SET },
97  { "setenv", parse_setenv, MUTT_SET_SET },
98  { "shutdown-hook", mutt_parse_hook, MUTT_SHUTDOWN_HOOK | MUTT_GLOBAL_HOOK },
99  { "source", parse_source, 0 },
100  { "spam", parse_spam_list, MUTT_SPAM },
101  { "startup-hook", mutt_parse_hook, MUTT_STARTUP_HOOK | MUTT_GLOBAL_HOOK },
102  { "subjectrx", parse_subjectrx_list, 0 },
103  { "subscribe", parse_subscribe, 0 },
104  { "tag-formats", parse_tag_formats, 0 },
105  { "tag-transforms", parse_tag_transforms, 0 },
106  { "timeout-hook", mutt_parse_hook, MUTT_TIMEOUT_HOOK | MUTT_GLOBAL_HOOK },
107  { "toggle", parse_set, MUTT_SET_INV },
108  { "unalias", parse_unalias, 0 },
109  { "unalternates", parse_unalternates, 0 },
110  { "unalternative_order", parse_unstailq, IP &AlternativeOrderList },
111  { "unattachments", parse_unattachments, 0 },
112  { "unauto_view", parse_unstailq, IP &AutoViewList },
113  { "unbind", mutt_parse_unbind, MUTT_UNBIND },
114 #ifdef HAVE_COLOR
115  { "uncolor", mutt_parse_uncolor, 0 },
116 #endif
117  { "ungroup", parse_group, MUTT_UNGROUP },
118  { "unhdr_order", parse_unstailq, IP &HeaderOrderList },
119  { "unhook", mutt_parse_unhook, 0 },
120  { "unignore", parse_unignore, 0 },
121  { "unlists", parse_unlists, 0 },
122  { "unmacro", mutt_parse_unbind, MUTT_UNMACRO },
123  { "unmailboxes", parse_unmailboxes, 0 },
124  { "unmailto_allow", parse_unstailq, IP &MailToAllow },
125  { "unmime_lookup", parse_unstailq, IP &MimeLookupList },
126  { "unmono", mutt_parse_unmono, 0 },
127  { "unmy_hdr", parse_unmy_hdr, 0 },
128  { "unscore", mutt_parse_unscore, 0 },
129  { "unset", parse_set, MUTT_SET_UNSET },
130  { "unsetenv", parse_setenv, MUTT_SET_UNSET },
131  { "unsubjectrx", parse_unsubjectrx_list, 0 },
132  { "unsubscribe", parse_unsubscribe, 0 },
133  // clang-format on
134 };
135 
137 
141 void mutt_commands_init(void)
142 {
143  ARRAY_RESERVE(&commands, 100);
145 }
146 
150 int commands_cmp(const void *a, const void *b)
151 {
152  struct Command x = *(const struct Command *) a;
153  struct Command y = *(const struct Command *) b;
154 
155  return strcmp(x.name, y.name);
156 }
157 
163 void commands_register(const struct Command *cmds, const size_t num_cmds)
164 {
165  for (int i = 0; i < num_cmds; i++)
166  {
167  ARRAY_ADD(&commands, cmds[i]);
168  }
169  ARRAY_SORT(&commands, commands_cmp);
170 }
171 
176 {
177  ARRAY_FREE(&commands);
178 }
179 
185 size_t mutt_commands_array(struct Command **first)
186 {
187  *first = ARRAY_FIRST(&commands);
188  return ARRAY_SIZE(&commands);
189 }
190 
197 struct Command *mutt_command_get(const char *s)
198 {
199  struct Command *cmd = NULL;
200  ARRAY_FOREACH(cmd, &commands)
201  {
202  if (mutt_str_equal(s, cmd->name))
203  return cmd;
204  }
205  return NULL;
206 }
207 
208 #ifdef USE_LUA
209 
216 void mutt_commands_apply(void *data, void (*application)(void *, const struct Command *))
217 {
218  struct Command *cmd = NULL;
219  ARRAY_FOREACH(cmd, &commands)
220  {
221  application(data, cmd);
222  }
223 }
224 #endif
parse_ignore
enum CommandResult parse_ignore(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'ignore' command - Implements Command::parse()
Definition: command_parse.c:863
lib.h
IP
#define IP
Definition: set.h:54
MUTT_SPAM
#define MUTT_SPAM
Definition: mutt.h:114
mutt_parse_macro
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:1564
mutt_parse_unscore
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:205
MUTT_SET_UNSET
@ MUTT_SET_UNSET
default is to unset all vars
Definition: mutt_commands.h:69
parse_setenv
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()
Definition: command_parse.c:1399
parse_unattachments
enum CommandResult parse_unattachments(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unattachments' command - Implements Command::parse()
Definition: command_parse.c:1828
parse_unalias
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:159
MUTT_ICONV_HOOK
#define MUTT_ICONV_HOOK
iconv-hook: create a system charset alias
Definition: hook.h:51
MUTT_SEND2_HOOK
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:56
ARRAY_ADD
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
mutt_commands_array
size_t mutt_commands_array(struct Command **first)
Get Commands array.
Definition: mutt_commands.c:185
MUTT_MBOX_HOOK
#define MUTT_MBOX_HOOK
mbox-hook: move messages after reading them
Definition: hook.h:46
MUTT_SAVE_HOOK
#define MUTT_SAVE_HOOK
save-hook: set a default folder when saving an email
Definition: hook.h:49
parse_alias
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:49
mutt_parse_unmono
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: color.c:931
parse_unignore
enum CommandResult parse_unignore(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unignore' command - Implements Command::parse()
Definition: command_parse.c:1886
MUTT_SEND_HOOK
#define MUTT_SEND_HOOK
send-hook: when composing a new email
Definition: hook.h:47
mutt_parse_exec
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:1629
MUTT_UNGROUP
#define MUTT_UNGROUP
'ungroup' config command
Definition: group.h:34
mutt_globals.h
ARRAY_SORT
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:271
MUTT_SET_RESET
@ MUTT_SET_RESET
default is to reset all vars to default
Definition: mutt_commands.h:70
mutt_parse_mono
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: color.c:1361
parse_subjectrx_list
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: command_parse.c:1631
mutt_parse_score
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:102
ARRAY_SIZE
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
parse_subscribe
enum CommandResult parse_subscribe(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'subscribe' command - Implements Command::parse()
Definition: command_parse.c:1645
mutt_parse_uncolor
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: color.c:921
parse_tag_transforms
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()
Definition: command_parse.c:1766
MUTT_STARTUP_HOOK
#define MUTT_STARTUP_HOOK
startup-hook: run when starting NeoMutt
Definition: hook.h:64
MUTT_UNMACRO
#define MUTT_UNMACRO
Definition: keymap.h:33
MUTT_NAMED
#define MUTT_NAMED
Definition: mutt_commands.h:74
parse_mailboxes
enum CommandResult parse_mailboxes(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'mailboxes' command - Implements Command::parse()
Definition: command_parse.c:913
mutt_parse_bind
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:1356
parse_unmailboxes
enum CommandResult parse_unmailboxes(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unmailboxes' command - Implements Command::parse()
Definition: command_parse.c:1970
mutt_str_equal
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
lib.h
parse_unsubjectrx_list
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: command_parse.c:2067
command_parse.h
Command
A user-callable command.
Definition: mutt_commands.h:45
MUTT_CHARSET_HOOK
#define MUTT_CHARSET_HOOK
charset-hook: create a charset alias for malformed emails
Definition: hook.h:50
parse_set
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()
Definition: command_parse.c:1038
parse_source
enum CommandResult parse_source(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'source' command - Implements Command::parse()
Definition: command_parse.c:1509
parse_attachments
enum CommandResult parse_attachments(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'attachments' command - Implements Command::parse()
Definition: command_parse.c:602
parse_unalternates
enum CommandResult parse_unalternates(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unalternates' command - Implements Command::parse()
Definition: command_parse.c:1805
ARRAY_FOREACH
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
keymap.h
parse_stailq
enum CommandResult parse_stailq(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse a list command - Implements Command::parse()
Definition: command_parse.c:1616
ARRAY_HEAD_INITIALIZER
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:54
lib.h
MUTT_NOSPAM
#define MUTT_NOSPAM
Definition: mutt.h:115
MUTT_SET_SET
@ MUTT_SET_SET
default is to set all vars
Definition: mutt_commands.h:67
ARRAY_FREE
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:198
parse_echo
enum CommandResult parse_echo(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'echo' command - Implements Command::parse()
Definition: command_parse.c:691
MUTT_FCC_HOOK
#define MUTT_FCC_HOOK
fcc-hook: to save outgoing email
Definition: hook.h:48
commands_register
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
Definition: mutt_commands.c:163
MUTT_SET_INV
@ MUTT_SET_INV
default is to invert all vars
Definition: mutt_commands.h:68
parse_alternates
enum CommandResult parse_alternates(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'alternates' command - Implements Command::parse()
Definition: command_parse.c:568
MUTT_UNBIND
#define MUTT_UNBIND
Definition: keymap.h:32
MUTT_GROUP
#define MUTT_GROUP
'group' config command
Definition: group.h:33
parse_unstailq
enum CommandResult parse_unstailq(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse an unlist command - Implements Command::parse()
Definition: command_parse.c:2046
mutt_commands
static const struct Command mutt_commands[]
Definition: mutt_commands.c:49
Command::data
intptr_t data
Data or flags to pass to the command.
Definition: mutt_commands.h:59
commands_cmp
int commands_cmp(const void *a, const void *b)
Compare two commands by name - Implements sort_t.
Definition: mutt_commands.c:150
lib.h
mutt_commands_init
void mutt_commands_init(void)
mutt_commands_free
void mutt_commands_free(void)
Free Commands array.
Definition: mutt_commands.c:175
parse_lists
enum CommandResult parse_lists(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'lists' command - Implements Command::parse()
Definition: command_parse.c:879
mutt_parse_unbind
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:1490
parse_unsubscribe
enum CommandResult parse_unsubscribe(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unsubscribe' command - Implements Command::parse()
Definition: command_parse.c:2081
parse_finish
enum CommandResult parse_finish(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'finish' command - Implements Command::parse()
Definition: command_parse.c:715
MUTT_SHUTDOWN_HOOK
#define MUTT_SHUTDOWN_HOOK
shutdown-hook: run when leaving NeoMutt
Definition: hook.h:65
parse_my_hdr
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()
Definition: command_parse.c:1005
parse_tag_formats
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()
Definition: command_parse.c:1727
MUTT_GLOBAL_HOOK
#define MUTT_GLOBAL_HOOK
Hooks which don't take a regex.
Definition: hook.h:66
MailToAllow
struct ListHead MailToAllow
List of permitted fields in a mailto: url.
Definition: globals.c:47
MUTT_MESSAGE_HOOK
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:52
mutt_command_get
struct Command * mutt_command_get(const char *s)
Get a Command by its name.
Definition: mutt_commands.c:197
ARRAY_RESERVE
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:185
mutt.h
mutt_parse_hook
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:85
parse_unmy_hdr
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()
Definition: command_parse.c:2002
mutt_lua.h
mutt_parse_color
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: color.c:1346
MUTT_ACCOUNT_HOOK
#define MUTT_ACCOUNT_HOOK
account-hook: when changing between accounts
Definition: hook.h:54
Command::name
const char * name
Name of the command.
Definition: mutt_commands.h:47
lib.h
parse_ifdef
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()
Definition: command_parse.c:826
parse_spam_list
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()
Definition: command_parse.c:1538
score.h
mutt_commands.h
parse_unlists
enum CommandResult parse_unlists(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'unlists' command - Implements Command::parse()
Definition: command_parse.c:1906
parse_group
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()
Definition: command_parse.c:730
lib.h
ARRAY_HEAD
ARRAY_HEAD(struct Command)
Initialize commands array and register default commands.
Definition: mutt_commands.c:136
mutt_commands_apply
void mutt_commands_apply(void *data, void(*application)(void *, const struct Command *))
Run a callback function on every Command.
Definition: mutt_commands.c:216
MUTT_FOLDER_HOOK
#define MUTT_FOLDER_HOOK
folder-hook: when entering a mailbox
Definition: hook.h:45
mutt_parse_push
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:1193
hook.h
COMMANDS_REGISTER
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:77
mutt_parse_unhook
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:454
MUTT_CRYPT_HOOK
#define MUTT_CRYPT_HOOK
crypt-hook: automatically select a PGP/SMIME key
Definition: hook.h:53
MUTT_REPLY_HOOK
#define MUTT_REPLY_HOOK
reply-hook: when replying to an email
Definition: hook.h:55
parse_cd
enum CommandResult parse_cd(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'cd' command - Implements Command::parse()
Definition: command_parse.c:663
MUTT_TIMEOUT_HOOK
#define MUTT_TIMEOUT_HOOK
timeout-hook: run a command periodically
Definition: hook.h:63
mutt_parse_idxfmt_hook
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:351
ARRAY_FIRST
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:131