NeoMutt  2020-09-25
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 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);
144  COMMANDS_REGISTER(mutt_commands);
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
#define MUTT_SEND_HOOK
send-hook: when composing a new email
Definition: hook.h:47
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
Convenience wrapper for the gui headers.
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:185
#define IP
Definition: set.h:54
Manage keymappings.
#define MUTT_UNGROUP
&#39;ungroup&#39; config command
Definition: group.h:33
#define MUTT_SHUTDOWN_HOOK
shutdown-hook: run when leaving NeoMutt
Definition: hook.h:65
Structs that make up an email.
enum CommandResult parse_alternates(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;alternates&#39; command - Implements Command::parse()
enum CommandResult parse_lists(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;lists&#39; command - Implements Command::parse()
#define MUTT_NOSPAM
Definition: mutt.h:115
enum CommandResult parse_finish(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;finish&#39; command - Implements Command::parse()
enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;hook&#39; family of commands - Implements Command::parse()
Definition: hook.c:85
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:131
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:198
enum CommandResult parse_unsubscribe(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unsubscribe&#39; command - Implements Command::parse()
enum CommandResult parse_subjectrx_list(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;subjectrx&#39; command - Implements Command::parse()
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
enum CommandResult parse_unattachments(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unattachments&#39; command - Implements Command::parse()
enum CommandResult mutt_parse_exec(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;exec&#39; command - Implements Command::parse()
Definition: keymap.c:1629
void mutt_commands_init(void)
enum CommandResult mutt_parse_mono(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;mono&#39; command - Implements Command::parse()
Definition: color.c:1360
#define MUTT_CHARSET_HOOK
charset-hook: create a charset alias for malformed emails
Definition: hook.h:50
#define MUTT_NAMED
Definition: mutt_commands.h:74
A user-callable command.
Definition: mutt_commands.h:45
const char * name
Name of the command.
Definition: mutt_commands.h:47
enum CommandResult mutt_parse_unhook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unhook&#39; command - Implements Command::parse()
Definition: hook.c:453
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:52
enum CommandResult parse_unignore(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unignore&#39; command - Implements Command::parse()
size_t mutt_commands_array(struct Command **first)
Get Commands array.
#define MUTT_UNMACRO
Definition: keymap.h:33
enum CommandResult parse_unmy_hdr(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unmy_hdr&#39; command - Implements Command::parse()
enum CommandResult mutt_parse_push(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;push&#39; command - Implements Command::parse()
Definition: keymap.c:1193
#define MUTT_CRYPT_HOOK
crypt-hook: automatically select a PGP/SMIME key
Definition: hook.h:53
enum CommandResult parse_set(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;set&#39; family of commands - Implements Command::parse()
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:77
enum CommandResult parse_source(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;source&#39; command - Implements Command::parse()
Integrated Lua scripting.
enum CommandResult parse_ifdef(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;ifdef&#39; and &#39;ifndef&#39; commands - Implements Command::parse()
Convenience wrapper for the config headers.
enum CommandResult mutt_parse_bind(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;bind&#39; command - Implements Command::parse()
Definition: keymap.c:1356
Email Address Handling.
default is to reset all vars to default
Definition: mutt_commands.h:70
enum CommandResult mutt_parse_unscore(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unscore&#39; command - Implements Command::parse()
Definition: score.c:205
enum CommandResult parse_unlists(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unlists&#39; command - Implements Command::parse()
enum CommandResult parse_group(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;group&#39; and &#39;ungroup&#39; commands - Implements Command::parse()
Parse and execute user-defined hooks.
Many unsorted constants and some structs.
int commands_cmp(const void *a, const void *b)
Compare two commands by name - Implements sort_t.
#define MUTT_ICONV_HOOK
iconv-hook: create a system charset alias
Definition: hook.h:51
enum CommandResult parse_spam_list(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;spam&#39; and &#39;nospam&#39; commands - Implements Command::parse()
#define MUTT_SPAM
Definition: mutt.h:114
enum CommandResult parse_mailboxes(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;mailboxes&#39; command - Implements Command::parse()
enum CommandResult parse_echo(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;echo&#39; command - Implements Command::parse()
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:54
enum CommandResult parse_ignore(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;ignore&#39; command - Implements Command::parse()
void mutt_commands_apply(void *data, void(*application)(void *, const struct Command *))
Run a callback function on every Command.
Email Aliases.
#define MUTT_MBOX_HOOK
mbox-hook: move messages after reading them
Definition: hook.h:46
#define MUTT_GLOBAL_HOOK
Hooks which don&#39;t take a regex.
Definition: hook.h:66
enum CommandResult parse_alias(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;alias&#39; command - Implements Command::parse()
Definition: commands.c:49
enum CommandResult mutt_parse_score(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;score&#39; command - Implements Command::parse()
Definition: score.c:102
#define MUTT_SAVE_HOOK
save-hook: set a default folder when saving an email
Definition: hook.h:49
enum CommandResult parse_cd(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;cd&#39; command - Implements Command::parse()
enum CommandResult mutt_parse_unbind(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unbind&#39; command - Implements Command::parse()
Definition: keymap.c:1490
Functions to parse commands in a config file.
enum CommandResult parse_unstailq(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse an unlist command - Implements Command::parse()
struct ListHead MailToAllow
List of permitted fields in a mailto: url.
Definition: globals.c:47
enum CommandResult parse_tag_formats(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;tag-formats&#39; command - Implements Command::parse()
Definitions of NeoMutt commands.
struct Command * mutt_command_get(const char *s)
Get a Command by its name.
default is to unset all vars
Definition: mutt_commands.h:69
enum CommandResult mutt_parse_uncolor(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;uncolor&#39; command - Implements Command::parse()
Definition: color.c:920
Routines for adding user scores to emails.
enum CommandResult mutt_parse_unmono(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unmono&#39; command - Implements Command::parse()
Definition: color.c:930
#define MUTT_TIMEOUT_HOOK
timeout-hook: run a command periodically
Definition: hook.h:63
enum CommandResult mutt_parse_color(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;color&#39; command - Implements Command::parse()
Definition: color.c:1345
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
enum CommandResult parse_tag_transforms(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;tag-transforms&#39; command - Implements Command::parse()
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:56
enum CommandResult parse_unalias(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unalias&#39; command - Implements Command::parse()
Definition: commands.c:159
enum CommandResult parse_subscribe(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;subscribe&#39; command - Implements Command::parse()
#define MUTT_REPLY_HOOK
reply-hook: when replying to an email
Definition: hook.h:55
enum CommandResult parse_my_hdr(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;my_hdr&#39; command - Implements Command::parse()
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
enum CommandResult parse_unsubjectrx_list(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unsubjectrx&#39; command - Implements Command::parse()
enum CommandResult mutt_parse_idxfmt_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;index-format-hook&#39; command - Implements Command::parse()
Definition: hook.c:351
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:271
#define MUTT_UNBIND
Definition: keymap.h:32
Hundreds of global variables to back the user variables.
default is to set all vars
Definition: mutt_commands.h:67
void mutt_commands_free(void)
Free Commands array.
enum CommandResult parse_unmailboxes(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unmailboxes&#39; command - Implements Command::parse()
enum CommandResult parse_attachments(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;attachments&#39; command - Implements Command::parse()
enum CommandResult parse_unalternates(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unalternates&#39; command - Implements Command::parse()
enum CommandResult mutt_parse_macro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;macro&#39; command - Implements Command::parse()
Definition: keymap.c:1564
enum CommandResult parse_setenv(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;setenv&#39; and &#39;unsetenv&#39; commands - Implements Command::parse()
#define MUTT_STARTUP_HOOK
startup-hook: run when starting NeoMutt
Definition: hook.h:64
enum CommandResult parse_stailq(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse a list command - Implements Command::parse()
default is to invert all vars
Definition: mutt_commands.h:68
#define MUTT_FCC_HOOK
fcc-hook: to save outgoing email
Definition: hook.h:48
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
#define MUTT_ACCOUNT_HOOK
account-hook: when changing between accounts
Definition: hook.h:54
ARRAY_HEAD(struct Command)
Initialize commands array and register default commands.
#define MUTT_GROUP
&#39;group&#39; config command
Definition: group.h:32
#define MUTT_FOLDER_HOOK
folder-hook: when entering a mailbox
Definition: hook.h:45