NeoMutt  2021-02-05-666-ge300cd
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 "alias/lib.h"
37 #include "gui/lib.h"
38 #include "mutt.h"
39 #include "mutt_commands.h"
40 #include "command_parse.h"
41 #include "hook.h"
42 #include "keymap.h"
43 #include "mutt_globals.h"
44 #include "score.h"
45 
46 static const struct Command mutt_commands[] = {
47  // clang-format off
48  { "account-hook", mutt_parse_hook, MUTT_ACCOUNT_HOOK },
49  { "alias", parse_alias, 0 },
50  { "alternates", parse_alternates, 0 },
51  { "alternative_order", parse_stailq, IP &AlternativeOrderList },
52  { "attachments", parse_attachments, 0 },
53  { "auto_view", parse_stailq, IP &AutoViewList },
54  { "bind", mutt_parse_bind, 0 },
55  { "cd", parse_cd, 0 },
56  { "charset-hook", mutt_parse_hook, MUTT_CHARSET_HOOK },
57 #ifdef HAVE_COLOR
58  { "color", mutt_parse_color, 0 },
59 #endif
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 },
69  { "iconv-hook", mutt_parse_hook, MUTT_ICONV_HOOK },
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 },
95  { "shutdown-hook", mutt_parse_hook, MUTT_SHUTDOWN_HOOK | MUTT_GLOBAL_HOOK },
96  { "source", parse_source, 0 },
97  { "spam", parse_spam_list, MUTT_SPAM },
98  { "startup-hook", mutt_parse_hook, MUTT_STARTUP_HOOK | MUTT_GLOBAL_HOOK },
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 },
103  { "timeout-hook", mutt_parse_hook, MUTT_TIMEOUT_HOOK | MUTT_GLOBAL_HOOK },
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 #ifdef HAVE_COLOR
112  { "uncolor", mutt_parse_uncolor, 0 },
113 #endif
114  { "ungroup", parse_group, MUTT_UNGROUP },
115  { "unhdr_order", parse_unstailq, IP &HeaderOrderList },
116  { "unhook", mutt_parse_unhook, 0 },
117  { "unignore", parse_unignore, 0 },
118  { "unlists", parse_unlists, 0 },
119  { "unmacro", mutt_parse_unbind, MUTT_UNMACRO },
120  { "unmailboxes", parse_unmailboxes, 0 },
121  { "unmailto_allow", parse_unstailq, IP &MailToAllow },
122  { "unmime_lookup", parse_unstailq, IP &MimeLookupList },
123  { "unmono", mutt_parse_unmono, 0 },
124  { "unmy_hdr", parse_unmy_hdr, 0 },
125  { "unscore", mutt_parse_unscore, 0 },
126  { "unset", parse_set, MUTT_SET_UNSET },
127  { "unsetenv", parse_setenv, MUTT_SET_UNSET },
128  { "unsubjectrx", parse_unsubjectrx_list, 0 },
129  { "unsubscribe", parse_unsubscribe, 0 },
130  // clang-format on
131 };
132 
134 
138 void mutt_commands_init(void)
139 {
140  ARRAY_RESERVE(&commands, 100);
141  COMMANDS_REGISTER(mutt_commands);
142 }
143 
147 int commands_cmp(const void *a, const void *b)
148 {
149  struct Command x = *(const struct Command *) a;
150  struct Command y = *(const struct Command *) b;
151 
152  return strcmp(x.name, y.name);
153 }
154 
160 void commands_register(const struct Command *cmds, const size_t num_cmds)
161 {
162  for (int i = 0; i < num_cmds; i++)
163  {
164  ARRAY_ADD(&commands, cmds[i]);
165  }
166  ARRAY_SORT(&commands, commands_cmp);
167 }
168 
173 {
174  ARRAY_FREE(&commands);
175 }
176 
182 size_t mutt_commands_array(struct Command **first)
183 {
184  *first = ARRAY_FIRST(&commands);
185  return ARRAY_SIZE(&commands);
186 }
187 
194 struct Command *mutt_command_get(const char *s)
195 {
196  struct Command *cmd = NULL;
197  ARRAY_FOREACH(cmd, &commands)
198  {
199  if (mutt_str_equal(s, cmd->name))
200  return cmd;
201  }
202  return NULL;
203 }
204 
205 #ifdef USE_LUA
206 
213 void mutt_commands_apply(void *data, void (*application)(void *, const struct Command *))
214 {
215  struct Command *cmd = NULL;
216  ARRAY_FOREACH(cmd, &commands)
217  {
218  application(data, cmd);
219  }
220 }
221 #endif
#define MUTT_SEND_HOOK
send-hook: when composing a new email
Definition: hook.h:41
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
Convenience wrapper for the gui headers.
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:372
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 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:34
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() -.
#define MUTT_SHUTDOWN_HOOK
shutdown-hook: run when leaving NeoMutt
Definition: hook.h:59
Structs that make up an email.
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() -.
#define MUTT_NOSPAM
Definition: mutt.h:111
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() -.
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:955
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_FIRST(head)
Convenience method to get the first element.
Definition: array.h:131
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:198
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
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() -.
Definition: subjectrx.c:164
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() -.
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() -This is used by &#39;account-hook&#39;...
Definition: hook.c:82
void mutt_commands_init(void)
#define MUTT_CHARSET_HOOK
charset-hook: create a charset alias for malformed emails
Definition: hook.h:44
enum CommandResult parse_stailq(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse a list command - Implements Command::parse() -This is used by &#39;alternative_order&#39;, &#39;auto_view&#39; and several others.
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() -bind menu-name <key_sequence> function-name...
Definition: keymap.c:1363
#define MUTT_NAMED
Definition: mutt_commands.h:79
const char * name
Name of the command.
Definition: mutt_commands.h: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:88
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:46
size_t mutt_commands_array(struct Command **first)
Get Commands array.
#define MUTT_UNMACRO
Definition: keymap.h:34
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 parse_source(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;source&#39; command - Implements Command::parse() -.
#define MUTT_CRYPT_HOOK
crypt-hook: automatically select a PGP/SMIME key
Definition: hook.h:47
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:82
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() -macro <menu> <key> <macro> <description> ...
Definition: keymap.c:1595
Convenience wrapper for the config headers.
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() -e.g.
Definition: commands.c:49
Email Address Handling.
default is to reset all vars to default
Definition: mutt_commands.h:75
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() -Command unbinds:
Definition: keymap.c:1512
Parse and execute user-defined hooks.
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() -This is used by &#39;reset&#39;...
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:45
#define MUTT_SPAM
Definition: mutt.h:110
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() -.
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:54
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:40
#define MUTT_GLOBAL_HOOK
Hooks which don&#39;t take a regex.
Definition: hook.h:60
#define MUTT_SAVE_HOOK
save-hook: set a default folder when saving an email
Definition: hook.h:43
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() -.
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:1391
Functions to parse commands in a config file.
struct ListHead MailToAllow
List of permitted fields in a mailto: url.
Definition: globals.c:37
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:162
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:1670
enum CommandResult parse_unstailq(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse an unlist command - Implements Command::parse() -This is used by &#39;unalternative_order&#39;, &#39;unauto_view&#39; and several others.
Definitions of NeoMutt commands.
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:200
struct Command * mutt_command_get(const char *s)
Get a Command by its name.
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() -.
default is to unset all vars
Definition: mutt_commands.h:74
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() -.
Definition: subjectrx.c:181
Routines for adding user scores to emails.
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() -.
Definition: attachments.c:528
#define MUTT_TIMEOUT_HOOK
timeout-hook: run a command periodically
Definition: hook.h:57
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
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() -This is also used by &#39;virtual-mailboxes&#39;...
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:50
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() -.
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:1200
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() -The &#39;ifdef&#39; command allows con...
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() -.
Definition: attachments.c:469
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() -.
Definition: alternates.c:126
#define MUTT_REPLY_HOOK
reply-hook: when replying to an email
Definition: hook.h:49
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() -.
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() -.
Definition: alternates.c:90
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
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() -.
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() -This is also used by &#39;unvirtual-mailbo...
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() -.
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:478
#define ARRAY_SORT(head, fn)
Sort an array.
Definition: array.h:271
#define MUTT_UNBIND
Definition: keymap.h:33
Hundreds of global variables to back the user variables.
default is to set all vars
Definition: mutt_commands.h:72
void mutt_commands_free(void)
Free Commands array.
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() -.
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:970
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:1406
#define MUTT_STARTUP_HOOK
startup-hook: run when starting NeoMutt
Definition: hook.h:58
default is to invert all vars
Definition: mutt_commands.h:73
#define MUTT_FCC_HOOK
fcc-hook: to save outgoing email
Definition: hook.h:42
#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:48
ARRAY_HEAD(struct Command)
Initialize commands array and register default commands.
#define MUTT_GROUP
&#39;group&#39; config command
Definition: group.h:33
#define MUTT_FOLDER_HOOK
folder-hook: when entering a mailbox
Definition: hook.h:39