NeoMutt  2023-05-17-33-gce4425
Teaching an old dog new tricks
DOXYGEN

Function to parse a command. More...

+ Collaboration diagram for parse():

Functions

enum CommandResult parse_alias (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'alias' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unalias (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unalias' command - Implements Command::parse() -. More...
 
enum CommandResult parse_alternates (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'alternates' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unalternates (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unalternates' command - Implements Command::parse() -. More...
 
enum CommandResult parse_attachments (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'attachments' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unattachments (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unattachments' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_uncolor (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'uncolor' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unmono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmono' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_color (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'color' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_mono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'mono' command - Implements Command::parse() -. More...
 
static enum CommandResult parse_cd (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'cd' command - Implements Command::parse() -. More...
 
static enum CommandResult parse_echo (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'echo' command - Implements Command::parse() -. More...
 
static enum CommandResult parse_finish (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'finish' command - Implements Command::parse() -. More...
 
static 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() -. More...
 
static 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() -. More...
 
static enum CommandResult parse_ignore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'ignore' command - Implements Command::parse() -. More...
 
static enum CommandResult parse_lists (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lists' command - Implements Command::parse() -. More...
 
enum CommandResult parse_mailboxes (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'mailboxes' command - Implements Command::parse() -. More...
 
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() -. More...
 
static 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() -. More...
 
static enum CommandResult parse_source (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'source' command - Implements Command::parse() -. More...
 
static 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() -. More...
 
static enum CommandResult parse_stailq (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse a list command - Implements Command::parse() -. More...
 
static enum CommandResult parse_subscribe (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subscribe' command - Implements Command::parse() -. More...
 
enum CommandResult parse_subscribe_to (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subscribe-to' command - Implements Command::parse() -. More...
 
static 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() -. More...
 
static 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() -. More...
 
static enum CommandResult parse_unignore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unignore' command - Implements Command::parse() -. More...
 
static enum CommandResult parse_unlists (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unlists' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unmailboxes (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmailboxes' command - Implements Command::parse() -. More...
 
static 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() -. More...
 
static enum CommandResult parse_unstailq (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse an unlist command - Implements Command::parse() -. More...
 
static enum CommandResult parse_unsubscribe (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubscribe' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unsubscribe_from (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubscribe-from' command - Implements Command::parse() -. More...
 
static enum CommandResult parse_version (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'version' command - Implements Command::parse() -. More...
 
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() -. More...
 
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() -. More...
 
static 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() -. More...
 
static enum CommandResult mutt_parse_unhook (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unhook' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'push' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'bind' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unbind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unbind' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'macro' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'exec' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_lua_parse (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lua' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_lua_source_file (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lua-source' command - Implements Command::parse() -. More...
 
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() -. More...
 
enum CommandResult mutt_parse_score (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'score' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unscore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unscore' command - Implements Command::parse() -. More...
 
enum CommandResult sb_parse_sidebar_pin (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'sidebar_pin' command - Implements Command::parse() -. More...
 
enum CommandResult sb_parse_sidebar_unpin (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'sidebar_unpin' command - Implements Command::parse() -. More...
 
static enum CommandResult parse_unreplace_list (struct Buffer *buf, struct Buffer *s, struct ReplaceList *list, struct Buffer *err)
 Remove a string replacement rule - Implements Command::parse() -. More...
 
static enum CommandResult parse_replace_list (struct Buffer *buf, struct Buffer *s, struct ReplaceList *list, struct Buffer *err)
 Parse a string replacement rule - Implements Command::parse() -. More...
 
enum CommandResult parse_subjectrx_list (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subjectrx' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unsubjectrx_list (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubjectrx' command - Implements Command::parse() -. More...
 

Detailed Description

Function to parse a command.

Parameters
bufTemporary Buffer space
sBuffer containing string to be parsed
dataFlags associated with the command
errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Function Documentation

◆ 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() -.

e.g. "alias jim James Smith <js@example.com> # Pointy-haired boss"

Definition at line 47 of file commands.c.

49{
50 struct Alias *tmp = NULL;
51 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
52 enum NotifyAlias event;
53
54 if (!MoreArgs(s))
55 {
56 buf_strcpy(err, _("alias: no address"));
57 return MUTT_CMD_WARNING;
58 }
59
60 /* name */
62 mutt_debug(LL_DEBUG5, "First token is '%s'\n", buf->data);
63 if (parse_grouplist(&gl, buf, s, err) == -1)
64 {
65 return MUTT_CMD_ERROR;
66 }
67 char *name = mutt_str_dup(buf->data);
68
69 /* address list */
71 mutt_debug(LL_DEBUG5, "Second token is '%s'\n", buf->data);
72 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
73 int parsed = mutt_addrlist_parse2(&al, buf->data);
74 if (parsed == 0)
75 {
76 buf_printf(err, _("Warning: Bad address '%s' in alias '%s'"), buf->data, name);
77 FREE(&name);
78 goto bail;
79 }
80
81 /* IDN */
82 char *estr = NULL;
83 if (mutt_addrlist_to_intl(&al, &estr))
84 {
85 buf_printf(err, _("Warning: Bad IDN '%s' in alias '%s'"), estr, name);
86 FREE(&name);
87 FREE(&estr);
88 goto bail;
89 }
90
91 /* check to see if an alias with this name already exists */
92 TAILQ_FOREACH(tmp, &Aliases, entries)
93 {
94 if (mutt_istr_equal(tmp->name, name))
95 break;
96 }
97
98 if (tmp)
99 {
100 FREE(&name);
102 /* override the previous value */
104 FREE(&tmp->comment);
105 event = NT_ALIAS_CHANGE;
106 }
107 else
108 {
109 /* create a new alias */
110 tmp = alias_new();
111 tmp->name = name;
112 TAILQ_INSERT_TAIL(&Aliases, tmp, entries);
113 event = NT_ALIAS_ADD;
114 }
115 tmp->addr = al;
116
118
119 const short c_debug_level = cs_subset_number(NeoMutt->sub, "debug_level");
120 if (c_debug_level > LL_DEBUG4)
121 {
122 /* A group is terminated with an empty address, so check a->mailbox */
123 struct Address *a = NULL;
124 TAILQ_FOREACH(a, &tmp->addr, entries)
125 {
126 if (!a->mailbox)
127 break;
128
129 if (a->group)
130 mutt_debug(LL_DEBUG5, " Group %s\n", a->mailbox);
131 else
132 mutt_debug(LL_DEBUG5, " %s\n", a->mailbox);
133 }
134 }
136 if (!MoreArgs(s) && (s->dptr[0] == '#'))
137 {
138 char *comment = s->dptr + 1;
139 SKIPWS(comment);
140 tmp->comment = mutt_str_dup(comment);
141 }
142
144
145 mutt_debug(LL_NOTIFY, "%s: %s\n",
146 (event == NT_ALIAS_ADD) ? "NT_ALIAS_ADD" : "NT_ALIAS_CHANGE", tmp->name);
147 struct EventAlias ev_a = { tmp };
148 notify_send(NeoMutt->notify, NT_ALIAS, event, &ev_a);
149
150 return MUTT_CMD_SUCCESS;
151
152bail:
154 return MUTT_CMD_ERROR;
155}
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1450
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:627
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1285
struct AliasList Aliases
List of all the user's email aliases.
Definition: alias.c:58
struct Alias * alias_new(void)
Create a new Alias.
Definition: alias.c:625
NotifyAlias
Alias notification types.
Definition: alias.h:53
@ NT_ALIAS_ADD
Alias has been added.
Definition: alias.h:54
@ NT_ALIAS_CHANGE
Alias has been changed.
Definition: alias.h:57
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:171
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:370
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:39
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition: command.h:37
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition: command.h:38
int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, struct Buffer *err)
Parse a group context.
Definition: commands.c:116
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
int parse_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: extract.c:47
#define TOKEN_SPACE
Don't treat whitespace as a term.
Definition: extract.h:47
#define TOKEN_QUOTE
Don't interpret quotes.
Definition: extract.h:48
#define MoreArgs(buf)
Definition: extract.h:30
#define TOKEN_SEMICOLON
Don't treat ; as special.
Definition: extract.h:51
#define TOKEN_NO_FLAGS
No flags are set.
Definition: extract.h:44
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:202
void mutt_grouplist_add_addrlist(struct GroupList *gl, struct AddressList *al)
Add Address list to a GroupList.
Definition: group.c:271
#define mutt_debug(LEVEL,...)
Definition: logging2.h:84
@ LL_DEBUG4
Log at debug level 4.
Definition: logging2.h:43
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:44
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:45
#define FREE(x)
Definition: memory.h:43
#define _(a)
Definition: message.h:28
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:810
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
@ NT_ALIAS
Alias has changed, NotifyAlias, EventAlias.
Definition: notify_type.h:37
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
void alias_reverse_add(struct Alias *alias)
Add an email address lookup for an Alias.
Definition: reverse.c:61
void alias_reverse_delete(struct Alias *alias)
Remove an email address lookup for an Alias.
Definition: reverse.c:83
#define SKIPWS(ch)
Definition: string2.h:45
An email address.
Definition: address.h:36
bool group
Group mailbox?
Definition: address.h:39
char * mailbox
Mailbox and host address.
Definition: address.h:38
A shortcut for an email address or addresses.
Definition: alias.h:34
char * comment
Free-form comment string.
Definition: alias.h:37
char * name
Short name.
Definition: alias.h:35
struct AddressList addr
List of Addresses the Alias expands to.
Definition: alias.h:36
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
An alias-change event.
Definition: alias.h:64
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:

◆ 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 at line 160 of file commands.c.

162{
163 do
164 {
166
167 struct Alias *np = NULL;
168 if (mutt_str_equal("*", buf->data))
169 {
170 TAILQ_FOREACH(np, &Aliases, entries)
171 {
173 }
174
176 return MUTT_CMD_SUCCESS;
177 }
178
179 TAILQ_FOREACH(np, &Aliases, entries)
180 {
181 if (!mutt_istr_equal(buf->data, np->name))
182 continue;
183
184 TAILQ_REMOVE(&Aliases, np, entries);
186 alias_free(&np);
187 break;
188 }
189 } while (MoreArgs(s));
190 return MUTT_CMD_SUCCESS;
191}
void alias_free(struct Alias **ptr)
Free an Alias.
Definition: alias.c:636
void aliaslist_free(struct AliasList *al)
Free a List of Aliases.
Definition: alias.c:657
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
+ Here is the call graph for this function:

◆ 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 at line 92 of file alternates.c.

94{
95 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
96
97 do
98 {
100
101 if (parse_grouplist(&gl, buf, s, err) == -1)
102 goto bail;
103
105
106 if (mutt_regexlist_add(&Alternates, buf->data, REG_ICASE, err) != 0)
107 goto bail;
108
109 if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
110 goto bail;
111 } while (MoreArgs(s));
112
114
115 mutt_debug(LL_NOTIFY, "NT_ALTERN_ADD: %s\n", buf->data);
117
118 return MUTT_CMD_SUCCESS;
119
120bail:
122 return MUTT_CMD_ERROR;
123}
static struct RegexList Alternates
List of regexes to match the user's alternate email addresses.
Definition: alternates.c:42
static struct Notify * AlternatesNotify
Notifications: NotifyAlternates.
Definition: alternates.c:44
static struct RegexList UnAlternates
List of regexes to exclude false matches in Alternates.
Definition: alternates.c:43
@ NT_ALTERN_ADD
Alternate address has been added.
Definition: alternates.h:42
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, uint16_t flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:321
int mutt_regexlist_add(struct RegexList *rl, const char *str, uint16_t flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:135
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:230
@ NT_ALTERN
Alternates command changed, NotifyAlternates.
Definition: notify_type.h:38
+ Here is the call graph for this function:

◆ 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 at line 128 of file alternates.c.

130{
131 do
132 {
135
136 if (!mutt_str_equal(buf->data, "*") &&
137 (mutt_regexlist_add(&UnAlternates, buf->data, REG_ICASE, err) != 0))
138 {
139 return MUTT_CMD_ERROR;
140 }
141
142 } while (MoreArgs(s));
143
144 mutt_debug(LL_NOTIFY, "NT_ALTERN_DELETE: %s\n", buf->data);
146
147 return MUTT_CMD_SUCCESS;
148}
@ NT_ALTERN_DELETE
Alternate address has been deleted.
Definition: alternates.h:43
+ Here is the call graph for this function:

◆ 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 at line 475 of file attachments.c.

477{
479 if (!buf->data || (*buf->data == '\0'))
480 {
481 buf_strcpy(err, _("attachments: no disposition"));
482 return MUTT_CMD_WARNING;
483 }
484
485 char *category = buf->data;
486 char op = *category++;
487
488 if (op == '?')
489 {
490 mutt_endwin();
491 fflush(stdout);
492 printf("\n%s\n\n", _("Current attachments settings:"));
493 print_attach_list(&AttachAllow, '+', "A");
495 print_attach_list(&InlineAllow, '+', "I");
498 return MUTT_CMD_SUCCESS;
499 }
500
501 if ((op != '+') && (op != '-'))
502 {
503 op = '+';
504 category--;
505 }
506
507 struct ListHead *head = NULL;
508 if (mutt_istr_startswith("attachment", category))
509 {
510 if (op == '+')
511 head = &AttachAllow;
512 else
513 head = &AttachExclude;
514 }
515 else if (mutt_istr_startswith("inline", category))
516 {
517 if (op == '+')
518 head = &InlineAllow;
519 else
520 head = &InlineExclude;
521 }
522 else
523 {
524 buf_strcpy(err, _("attachments: invalid disposition"));
525 return MUTT_CMD_ERROR;
526 }
527
528 return parse_attach_list(buf, s, head, err);
529}
static struct ListHead AttachAllow
List of attachment types to be counted.
Definition: attachments.c:55
static int print_attach_list(struct ListHead *h, const char op, const char *name)
Print a list of attachments.
Definition: attachments.c:459
static struct ListHead InlineExclude
List of inline types to ignore.
Definition: attachments.c:58
static struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: attachments.c:56
static enum CommandResult parse_attach_list(struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
Parse the "attachments" command.
Definition: attachments.c:313
static struct ListHead InlineAllow
List of inline types to counted.
Definition: attachments.c:57
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition: curs_lib.c:388
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:355
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:240
+ Here is the call graph for this function:

◆ 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 at line 534 of file attachments.c.

536{
537 char op;
538 char *p = NULL;
539 struct ListHead *head = NULL;
540
542 if (!buf->data || (*buf->data == '\0'))
543 {
544 buf_strcpy(err, _("unattachments: no disposition"));
545 return MUTT_CMD_WARNING;
546 }
547
548 p = buf->data;
549 op = *p++;
550
551 if (op == '*')
552 {
557
558 mutt_debug(LL_NOTIFY, "NT_ATTACH_DELETE_ALL\n");
560 return 0;
561 }
562
563 if ((op != '+') && (op != '-'))
564 {
565 op = '+';
566 p--;
567 }
568 if (mutt_istr_startswith("attachment", p))
569 {
570 if (op == '+')
571 head = &AttachAllow;
572 else
573 head = &AttachExclude;
574 }
575 else if (mutt_istr_startswith("inline", p))
576 {
577 if (op == '+')
578 head = &InlineAllow;
579 else
580 head = &InlineExclude;
581 }
582 else
583 {
584 buf_strcpy(err, _("unattachments: invalid disposition"));
585 return MUTT_CMD_ERROR;
586 }
587
588 return parse_unattach_list(buf, s, head, err);
589}
static struct Notify * AttachmentsNotify
Notifications: NotifyAttach.
Definition: attachments.c:59
static enum CommandResult parse_unattach_list(struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
Parse the "unattachments" command.
Definition: attachments.c:393
@ NT_ATTACH_DELETE_ALL
All Attachment regexes have been deleted.
Definition: attachments.h:43
static void attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t -.
Definition: attachments.c:68
void mutt_list_free_type(struct ListHead *h, list_free_t fn)
Free a List of type.
Definition: list.c:144
void(* list_free_t)(void **ptr)
Definition: list.h:48
@ NT_ATTACH
Attachment command changed, NotifyAttach.
Definition: notify_type.h:39
+ Here is the call graph for this function:

◆ 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 at line 1187 of file command.c.

1189{
1190 if (OptNoCurses)
1191 {
1192 *s->dptr = '\0'; /* fake that we're done parsing */
1193 return MUTT_CMD_SUCCESS;
1194 }
1195 color_debug(LL_DEBUG5, "parse: %s\n", buf_string(buf));
1196 enum CommandResult rc = parse_uncolor(buf, s, err, true);
1198 return rc;
1199}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:78
static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, struct Buffer *err, bool uncolor)
Parse an 'uncolor' command.
Definition: command.c:769
CommandResult
Error codes for command_t parse functions.
Definition: command.h:36
int color_debug(enum LogLevel level, const char *format,...)
Write to the log file.
Definition: debug.c:44
void curses_colors_dump(void)
Log all the Curses colours.
Definition: debug.c:267
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:82
+ Here is the call graph for this function:

◆ 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 at line 1204 of file command.c.

1206{
1207 *s->dptr = '\0'; /* fake that we're done parsing */
1208 return MUTT_CMD_SUCCESS;
1209}

◆ 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 at line 1214 of file command.c.

1216{
1217 bool dry_run = OptNoCurses;
1218
1219 color_debug(LL_DEBUG5, "parse: %s\n", buf_string(buf));
1220 enum CommandResult rc = parse_color(buf, s, err, parse_color_pair, dry_run, true);
1222 return rc;
1223}
static enum CommandResult parse_color(struct Buffer *buf, struct Buffer *s, struct Buffer *err, parser_callback_t callback, bool dry_run, bool color)
Parse a 'color' command.
Definition: command.c:1051
static enum CommandResult parse_color_pair(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attrs, struct Buffer *err)
Parse a pair of colours - Implements parser_callback_t -.
Definition: command.c:593
+ Here is the call graph for this function:

◆ 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 at line 1228 of file command.c.

1230{
1231 return parse_color(buf, s, err, parse_attr_spec, true, false);
1232}
static enum CommandResult parse_attr_spec(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attrs, struct Buffer *err)
Parse an attribute description - Implements parser_callback_t -.
Definition: command.c:534
+ Here is the call graph for this function:

◆ parse_cd()

static enum CommandResult parse_cd ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'cd' command - Implements Command::parse() -.

Definition at line 339 of file commands.c.

341{
343 buf_expand_path(buf);
344 if (buf_len(buf) == 0)
345 {
346 if (HomeDir)
347 {
348 buf_strcpy(buf, HomeDir);
349 }
350 else
351 {
352 buf_printf(err, _("%s: too few arguments"), "cd");
353 return MUTT_CMD_ERROR;
354 }
355 }
356
357 if (chdir(buf_string(buf)) != 0)
358 {
359 buf_printf(err, "cd: %s", strerror(errno));
360 return MUTT_CMD_ERROR;
361 }
362
363 return MUTT_CMD_SUCCESS;
364}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:414
char * HomeDir
User's home directory.
Definition: globals.c:39
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:333
+ Here is the call graph for this function:

◆ parse_echo()

static enum CommandResult parse_echo ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'echo' command - Implements Command::parse() -.

Definition at line 369 of file commands.c.

371{
372 if (!MoreArgs(s))
373 {
374 buf_printf(err, _("%s: too few arguments"), "echo");
375 return MUTT_CMD_WARNING;
376 }
378 OptForceRefresh = true;
379 mutt_message("%s", buf->data);
380 OptForceRefresh = false;
381 mutt_sleep(0);
382
383 return MUTT_CMD_SUCCESS;
384}
bool OptForceRefresh
(pseudo) refresh even during macros
Definition: globals.c:71
#define mutt_message(...)
Definition: logging2.h:86
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1424
+ Here is the call graph for this function:

◆ parse_finish()

static enum CommandResult parse_finish ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'finish' command - Implements Command::parse() -.

Return values
MUTT_CMD_FINISHStop processing the current file
MUTT_CMD_WARNINGFailed

If the 'finish' command is found, we should stop reading the current file.

Definition at line 393 of file commands.c.

395{
396 if (MoreArgs(s))
397 {
398 buf_printf(err, _("%s: too many arguments"), "finish");
399 return MUTT_CMD_WARNING;
400 }
401
402 return MUTT_CMD_FINISH;
403}
@ MUTT_CMD_FINISH
Finish: Stop processing this file.
Definition: command.h:40
+ Here is the call graph for this function:

◆ parse_group()

static enum CommandResult parse_group ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'group' and 'ungroup' commands - Implements Command::parse() -.

Definition at line 408 of file commands.c.

410{
411 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
412 enum GroupState gstate = GS_NONE;
413
414 do
415 {
417 if (parse_grouplist(&gl, buf, s, err) == -1)
418 goto bail;
419
420 if ((data == MUTT_UNGROUP) && mutt_istr_equal(buf->data, "*"))
421 {
423 goto out;
424 }
425
426 if (mutt_istr_equal(buf->data, "-rx"))
427 {
428 gstate = GS_RX;
429 }
430 else if (mutt_istr_equal(buf->data, "-addr"))
431 {
432 gstate = GS_ADDR;
433 }
434 else
435 {
436 switch (gstate)
437 {
438 case GS_NONE:
439 buf_printf(err, _("%sgroup: missing -rx or -addr"),
440 (data == MUTT_UNGROUP) ? "un" : "");
441 goto warn;
442
443 case GS_RX:
444 if ((data == MUTT_GROUP) &&
445 (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0))
446 {
447 goto bail;
448 }
449 else if ((data == MUTT_UNGROUP) &&
450 (mutt_grouplist_remove_regex(&gl, buf->data) < 0))
451 {
452 goto bail;
453 }
454 break;
455
456 case GS_ADDR:
457 {
458 char *estr = NULL;
459 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
460 mutt_addrlist_parse2(&al, buf->data);
461 if (TAILQ_EMPTY(&al))
462 goto bail;
463 if (mutt_addrlist_to_intl(&al, &estr))
464 {
465 buf_printf(err, _("%sgroup: warning: bad IDN '%s'"),
466 (data == 1) ? "un" : "", estr);
468 FREE(&estr);
469 goto bail;
470 }
471 if (data == MUTT_GROUP)
473 else if (data == MUTT_UNGROUP)
476 break;
477 }
478 }
479 }
480 } while (MoreArgs(s));
481
482out:
484 return MUTT_CMD_SUCCESS;
485
486bail:
488 return MUTT_CMD_ERROR;
489
490warn:
492 return MUTT_CMD_WARNING;
493}
GroupState
Type of email address group.
Definition: commands.c:80
@ GS_RX
Entry is a regular expression.
Definition: commands.c:82
@ GS_NONE
Group is missing an argument.
Definition: commands.c:81
@ GS_ADDR
Entry is an address.
Definition: commands.c:83
int mutt_grouplist_remove_addrlist(struct GroupList *gl, struct AddressList *al)
Remove an AddressList from a GroupList.
Definition: group.c:290
int mutt_grouplist_remove_regex(struct GroupList *gl, const char *s)
Remove matching addresses from a GroupList.
Definition: group.c:346
void mutt_grouplist_clear(struct GroupList *gl)
Clear a GroupList.
Definition: group.c:148
#define MUTT_GROUP
'group' config command
Definition: group.h:33
#define MUTT_UNGROUP
'ungroup' config command
Definition: group.h:34
#define TAILQ_EMPTY(head)
Definition: queue.h:721
+ Here is the call graph for this function:

◆ parse_ifdef()

static enum CommandResult parse_ifdef ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'ifdef' and 'ifndef' commands - Implements Command::parse() -.

The 'ifdef' command allows conditional elements in the config file. If a given variable, function, command or compile-time symbol exists, then read the rest of the line of config commands. e.g. ifdef sidebar source ~/.neomutt/sidebar.rc

If (data == 1) then it means use the 'ifndef' (if-not-defined) command. e.g. ifndef imap finish

Definition at line 508 of file commands.c.

510{
512
513 if (buf_is_empty(buf))
514 {
515 buf_printf(err, _("%s: too few arguments"), (data ? "ifndef" : "ifdef"));
516 return MUTT_CMD_WARNING;
517 }
518
519 // is the item defined as:
520 bool res = cs_subset_lookup(NeoMutt->sub, buf->data) // a variable?
521 || feature_enabled(buf->data) // a compiled-in feature?
522 || is_function(buf->data) // a function?
523 || command_get(buf->data) // a command?
524#ifdef USE_HCACHE
525 || store_is_valid_backend(buf->data) // a store? (database)
526#endif
527 || mutt_str_getenv(buf->data); // an environment variable?
528
529 if (!MoreArgs(s))
530 {
531 buf_printf(err, _("%s: too few arguments"), (data ? "ifndef" : "ifdef"));
532 return MUTT_CMD_WARNING;
533 }
535
536 /* ifdef KNOWN_SYMBOL or ifndef UNKNOWN_SYMBOL */
537 if ((res && (data == 0)) || (!res && (data == 1)))
538 {
539 enum CommandResult rc = parse_rc_line(buf->data, err);
540 if (rc == MUTT_CMD_ERROR)
541 {
542 mutt_error(_("Error: %s"), err->data);
543 return MUTT_CMD_ERROR;
544 }
545 return rc;
546 }
547 return MUTT_CMD_SUCCESS;
548}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:301
static bool is_function(const char *name)
Is the argument a neomutt function?
Definition: commands.c:92
struct Command * command_get(const char *s)
Get a Command by its name.
Definition: command.c:87
#define mutt_error(...)
Definition: logging2.h:87
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:918
enum CommandResult parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: rc.c:108
bool store_is_valid_backend(const char *str)
Is the string a valid Store backend.
Definition: store.c:128
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
Definition: subset.c:184
bool feature_enabled(const char *name)
Test if a compile-time feature is enabled.
Definition: version.c:575
+ Here is the call graph for this function:

◆ parse_ignore()

static enum CommandResult parse_ignore ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'ignore' command - Implements Command::parse() -.

Definition at line 553 of file commands.c.

555{
556 do
557 {
560 add_to_stailq(&Ignore, buf->data);
561 } while (MoreArgs(s));
562
563 return MUTT_CMD_SUCCESS;
564}
struct ListHead Ignore
List of regexes to match mailing lists.
Definition: globals.c:37
struct ListHead UnIgnore
List of regexes to exclude false matches in MailLists.
Definition: globals.c:49
void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: muttlib.c:1718
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: muttlib.c:1693
+ Here is the call graph for this function:

◆ parse_lists()

static enum CommandResult parse_lists ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'lists' command - Implements Command::parse() -.

Definition at line 569 of file commands.c.

571{
572 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
573
574 do
575 {
577
578 if (parse_grouplist(&gl, buf, s, err) == -1)
579 goto bail;
580
582
583 if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
584 goto bail;
585
586 if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
587 goto bail;
588 } while (MoreArgs(s));
589
591 return MUTT_CMD_SUCCESS;
592
593bail:
595 return MUTT_CMD_ERROR;
596}
struct RegexList UnMailLists
List of regexes to exclude false matches in SubscribedLists.
Definition: globals.c:51
struct RegexList MailLists
List of permitted fields in a mailto: url.
Definition: globals.c:39
+ Here is the call graph for this function:

◆ 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() -.

This is also used by 'virtual-mailboxes'.

Definition at line 603 of file commands.c.

605{
606 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
607 while (MoreArgs(s))
608 {
609 struct Mailbox *m = mailbox_new();
610
611 if (data & MUTT_NAMED)
612 {
613 // This may be empty, e.g. `named-mailboxes "" +inbox`
615 m->name = buf_strdup(buf);
616 }
617
619 if (buf_is_empty(buf))
620 {
621 /* Skip empty tokens. */
622 mailbox_free(&m);
623 continue;
624 }
625
626 buf_strcpy(&m->pathbuf, buf->data);
627 /* int rc = */ mx_path_canon2(m, c_folder);
628
629 if (m->type <= MUTT_UNKNOWN)
630 {
631 mutt_error("Unknown Mailbox: %s", m->realpath);
632 mailbox_free(&m);
633 return MUTT_CMD_ERROR;
634 }
635
636 bool new_account = false;
637 struct Account *a = mx_ac_find(m);
638 if (!a)
639 {
640 a = account_new(NULL, NeoMutt->sub);
641 a->type = m->type;
642 new_account = true;
643 }
644
645 if (!new_account)
646 {
647 struct Mailbox *m_old = mx_mbox_find(a, m->realpath);
648 if (m_old)
649 {
650 if (!m_old->visible)
651 {
652 m_old->visible = true;
653 m_old->gen = mailbox_gen();
654 }
655
656 const bool rename = (data & MUTT_NAMED) && !mutt_str_equal(m_old->name, m->name);
657 if (rename)
658 {
659 mutt_str_replace(&m_old->name, m->name);
660 }
661
662 mailbox_free(&m);
663 continue;
664 }
665 }
666
667 if (!mx_ac_add(a, m))
668 {
669 mailbox_free(&m);
670 if (new_account)
671 {
672 cs_subset_free(&a->sub);
673 FREE(&a->name);
674 notify_free(&a->notify);
675 FREE(&a);
676 }
677 continue;
678 }
679 if (new_account)
680 {
682 }
683
684 // this is finally a visible mailbox in the sidebar and mailboxes list
685 m->visible = true;
686
687#ifdef USE_INOTIFY
689#endif
690 }
691 return MUTT_CMD_SUCCESS;
692}
struct Account * account_new(const char *name, struct ConfigSubset *sub)
Create a new Account.
Definition: account.c:43
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:490
#define MUTT_NAMED
Definition: commands.h:36
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
int mailbox_gen(void)
Get the next generation number.
Definition: mailbox.c:59
struct Mailbox * mailbox_new(void)
Create a new Mailbox.
Definition: mailbox.c:69
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:88
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:489
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:327
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1604
bool mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add()
Definition: mx.c:1781
struct Account * mx_ac_find(struct Mailbox *m)
Find the Account owning a Mailbox.
Definition: mx.c:1580
int mx_path_canon2(struct Mailbox *m, const char *folder)
Canonicalise the path to realpath.
Definition: mx.c:1494
bool neomutt_account_add(struct NeoMutt *n, struct Account *a)
Add an Account to the global list.
Definition: neomutt.c:84
A group of associated Mailboxes.
Definition: account.h:37
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
char * name
Name of Account.
Definition: account.h:39
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
A mailbox.
Definition: mailbox.h:79
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
struct Buffer pathbuf
Path of the Mailbox.
Definition: mailbox.h:80
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:130
int gen
Generation number, for sorting.
Definition: mailbox.h:145
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:105
+ Here is the call graph for this function:

◆ 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 at line 697 of file commands.c.

699{
701 char *p = strpbrk(buf->data, ": \t");
702 if (!p || (*p != ':'))
703 {
704 buf_strcpy(err, _("invalid header field"));
705 return MUTT_CMD_WARNING;
706 }
707
708 struct EventHeader ev_h = { buf->data };
709 struct ListNode *n = header_find(&UserHeader, buf->data);
710
711 if (n)
712 {
713 header_update(n, buf->data);
714 mutt_debug(LL_NOTIFY, "NT_HEADER_CHANGE: %s\n", buf->data);
716 }
717 else
718 {
719 header_add(&UserHeader, buf->data);
720 mutt_debug(LL_NOTIFY, "NT_HEADER_ADD: %s\n", buf->data);
722 }
723
724 return MUTT_CMD_SUCCESS;
725}
struct ListNode * header_add(struct ListHead *hdrlist, const char *header)
Add a header to a list.
Definition: email.c:164
struct ListNode * header_update(struct ListNode *hdr, const char *header)
Update an existing header.
Definition: email.c:178
struct ListNode * header_find(const struct ListHead *hdrlist, const char *header)
Find a header, matching on its field, in a list of headers.
Definition: email.c:141
@ NT_HEADER_CHANGE
An existing header has been changed.
Definition: email.h:174
@ NT_HEADER_ADD
Header has been added.
Definition: email.h:172
struct ListHead UserHeader
List of custom headers to add to outgoing emails.
Definition: globals.c:55
@ NT_HEADER
A header has changed, NotifyHeader EventHeader.
Definition: notify_type.h:47
An event that happened to a header.
Definition: email.h:181
A List node for strings.
Definition: list.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_setenv()

static enum CommandResult parse_setenv ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'setenv' and 'unsetenv' commands - Implements Command::parse() -.

Definition at line 783 of file commands.c.

785{
786 char **envp = EnvList;
787
788 bool query = false;
789 bool prefix = false;
790 bool unset = (data == MUTT_SET_UNSET);
791
792 if (!MoreArgs(s))
793 {
794 if (!StartupComplete)
795 {
796 buf_printf(err, _("%s: too few arguments"), "setenv");
797 return MUTT_CMD_WARNING;
798 }
799
800 char tempfile[PATH_MAX] = { 0 };
801 mutt_mktemp(tempfile, sizeof(tempfile));
802
803 FILE *fp_out = mutt_file_fopen(tempfile, "w");
804 if (!fp_out)
805 {
806 // L10N: '%s' is the file name of the temporary file
807 buf_printf(err, _("Could not create temporary file %s"), tempfile);
808 return MUTT_CMD_ERROR;
809 }
810
811 int count = 0;
812 for (char **env = EnvList; *env; env++)
813 count++;
814
815 qsort(EnvList, count, sizeof(char *), envlist_sort);
816
817 for (char **env = EnvList; *env; env++)
818 fprintf(fp_out, "%s\n", *env);
819
820 mutt_file_fclose(&fp_out);
821
822 struct PagerData pdata = { 0 };
823 struct PagerView pview = { &pdata };
824
825 pdata.fname = tempfile;
826
827 pview.banner = "setenv";
829 pview.mode = PAGER_MODE_OTHER;
830
831 mutt_do_pager(&pview, NULL);
832 return MUTT_CMD_SUCCESS;
833 }
834
835 if (*s->dptr == '?')
836 {
837 query = true;
838 prefix = true;
839
840 if (unset)
841 {
842 buf_printf(err, _("Can't query a variable with the '%s' command"), "unsetenv");
843 return MUTT_CMD_WARNING;
844 }
845
846 s->dptr++;
847 }
848
849 /* get variable name */
851
852 if (*s->dptr == '?')
853 {
854 if (unset)
855 {
856 buf_printf(err, _("Can't query a variable with the '%s' command"), "unsetenv");
857 return MUTT_CMD_WARNING;
858 }
859
860 if (prefix)
861 {
862 buf_printf(err, _("Can't use a prefix when querying a variable"));
863 return MUTT_CMD_WARNING;
864 }
865
866 query = true;
867 s->dptr++;
868 }
869
870 if (query)
871 {
872 bool found = false;
873 while (envp && *envp)
874 {
875 /* This will display all matches for "^QUERY" */
876 if (mutt_str_startswith(*envp, buf->data))
877 {
878 if (!found)
879 {
880 mutt_endwin();
881 found = true;
882 }
883 puts(*envp);
884 }
885 envp++;
886 }
887
888 if (found)
889 {
891 return MUTT_CMD_SUCCESS;
892 }
893
894 buf_printf(err, _("%s is unset"), buf->data);
895 return MUTT_CMD_WARNING;
896 }
897
898 if (unset)
899 {
900 if (!envlist_unset(&EnvList, buf->data))
901 {
902 buf_printf(err, _("%s is unset"), buf->data);
903 return MUTT_CMD_WARNING;
904 }
905 return MUTT_CMD_SUCCESS;
906 }
907
908 /* set variable */
909
910 if (*s->dptr == '=')
911 {
912 s->dptr++;
913 SKIPWS(s->dptr);
914 }
915
916 if (!MoreArgs(s))
917 {
918 buf_printf(err, _("%s: too few arguments"), "setenv");
919 return MUTT_CMD_WARNING;
920 }
921
922 char *name = mutt_str_dup(buf->data);
924 envlist_set(&EnvList, name, buf->data, true);
925 FREE(&name);
926
927 return MUTT_CMD_SUCCESS;
928}
static int envlist_sort(const void *a, const void *b)
Sort two environment strings.
Definition: commands.c:775
int mutt_do_pager(struct PagerView *pview, struct Email *e)
Display some page-able text to the user (help or attachment)
Definition: do_pager.c:123
bool envlist_set(char ***envp, const char *name, const char *value, bool overwrite)
Set an environment variable.
Definition: envlist.c:87
bool envlist_unset(char ***envp, const char *name)
Unset an environment variable.
Definition: envlist.c:135
#define TOKEN_EQUAL
Treat '=' as a special.
Definition: extract.h:45
#define TOKEN_QUESTION
Treat '?' as a special.
Definition: extract.h:54
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:634
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:150
char ** EnvList
Private copy of the environment variables.
Definition: globals.c:91
bool StartupComplete
When the config has been read.
Definition: main.c:199
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:228
#define PATH_MAX
Definition: mutt.h:41
#define MUTT_PAGER_NO_FLAGS
No flags are set.
Definition: lib.h:59
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition: lib.h:140
@ MUTT_SET_UNSET
default is to unset all vars
Definition: set.h:38
Data to be displayed by PagerView.
Definition: lib.h:159
const char * fname
Name of the file to read.
Definition: lib.h:163
Paged view into some data.
Definition: lib.h:170
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition: lib.h:171
enum PagerMode mode
Pager mode.
Definition: lib.h:172
PagerFlags flags
Additional settings to tweak pager's function.
Definition: lib.h:173
const char * banner
Title to display in status bar.
Definition: lib.h:174
#define mutt_mktemp(buf, buflen)
Definition: tmp.h:34
+ Here is the call graph for this function:

◆ parse_source()

static enum CommandResult parse_source ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'source' command - Implements Command::parse() -.

Definition at line 933 of file commands.c.

935{
936 char path[PATH_MAX] = { 0 };
937
938 do
939 {
940 if (parse_extract_token(buf, s, TOKEN_NO_FLAGS) != 0)
941 {
942 buf_printf(err, _("source: error at %s"), s->dptr);
943 return MUTT_CMD_ERROR;
944 }
945 mutt_str_copy(path, buf->data, sizeof(path));
946 mutt_expand_path(path, sizeof(path));
947
948 if (source_rc(path, err) < 0)
949 {
950 buf_printf(err, _("source: file %s could not be sourced"), path);
951 return MUTT_CMD_ERROR;
952 }
953
954 } while (MoreArgs(s));
955
956 return MUTT_CMD_SUCCESS;
957}
int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
Definition: commands.c:191
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:653
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:124
+ Here is the call graph for this function:

◆ parse_spam_list()

static enum CommandResult parse_spam_list ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'spam' and 'nospam' commands - Implements Command::parse() -.

Definition at line 962 of file commands.c.

964{
965 struct Buffer templ;
966
967 buf_init(&templ);
968
969 /* Insist on at least one parameter */
970 if (!MoreArgs(s))
971 {
972 if (data == MUTT_SPAM)
973 buf_strcpy(err, _("spam: no matching pattern"));
974 else
975 buf_strcpy(err, _("nospam: no matching pattern"));
976 return MUTT_CMD_ERROR;
977 }
978
979 /* Extract the first token, a regex */
981
982 /* data should be either MUTT_SPAM or MUTT_NOSPAM. MUTT_SPAM is for spam commands. */
983 if (data == MUTT_SPAM)
984 {
985 /* If there's a second parameter, it's a template for the spam tag. */
986 if (MoreArgs(s))
987 {
989
990 /* Add to the spam list. */
991 if (mutt_replacelist_add(&SpamList, buf->data, templ.data, err) != 0)
992 {
993 FREE(&templ.data);
994 return MUTT_CMD_ERROR;
995 }
996 FREE(&templ.data);
997 }
998 else
999 {
1000 /* If not, try to remove from the nospam list. */
1002 }
1003
1004 return MUTT_CMD_SUCCESS;
1005 }
1006 else if (data == MUTT_NOSPAM)
1007 {
1008 /* MUTT_NOSPAM is for nospam commands. */
1009 /* nospam only ever has one parameter. */
1010
1011 /* "*" is a special case. */
1012 if (mutt_str_equal(buf->data, "*"))
1013 {
1016 return MUTT_CMD_SUCCESS;
1017 }
1018
1019 /* If it's on the spam list, just remove it. */
1020 if (mutt_replacelist_remove(&SpamList, buf->data) != 0)
1021 return MUTT_CMD_SUCCESS;
1022
1023 /* Otherwise, add it to the nospam list. */
1024 if (mutt_regexlist_add(&NoSpamList, buf->data, REG_ICASE, err) != 0)
1025 return MUTT_CMD_ERROR;
1026
1027 return MUTT_CMD_SUCCESS;
1028 }
1029
1030 /* This should not happen. */
1031 buf_strcpy(err, "This is no good at all.");
1032 return MUTT_CMD_ERROR;
1033}
struct Buffer * buf_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:53
struct ReplaceList SpamList
List of regexes to match subscribed mailing lists.
Definition: globals.c:45
struct RegexList NoSpamList
List of regexes and patterns to match spam emails.
Definition: globals.c:43
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:587
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:174
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:471
int mutt_replacelist_add(struct ReplaceList *rl, const char *pat, const char *templ, struct Buffer *err)
Add a pattern and a template to a list.
Definition: regex.c:266
#define MUTT_NOSPAM
Definition: mutt.h:100
#define MUTT_SPAM
Definition: mutt.h:99
String manipulation buffer.
Definition: buffer.h:34
+ Here is the call graph for this function:

◆ parse_stailq()

static enum CommandResult parse_stailq ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse a list command - Implements Command::parse() -.

This is used by 'alternative_order', 'auto_view' and several others.

Definition at line 1040 of file commands.c.

1042{
1043 do
1044 {
1046 add_to_stailq((struct ListHead *) data, buf->data);
1047 } while (MoreArgs(s));
1048
1049 return MUTT_CMD_SUCCESS;
1050}
+ Here is the call graph for this function:

◆ parse_subscribe()

static enum CommandResult parse_subscribe ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'subscribe' command - Implements Command::parse() -.

Definition at line 1055 of file commands.c.

1057{
1058 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1059
1060 do
1061 {
1063
1064 if (parse_grouplist(&gl, buf, s, err) == -1)
1065 goto bail;
1066
1069
1070 if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
1071 goto bail;
1072 if (mutt_regexlist_add(&SubscribedLists, buf->data, REG_ICASE, err) != 0)
1073 goto bail;
1074 if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
1075 goto bail;
1076 } while (MoreArgs(s));
1077
1079 return MUTT_CMD_SUCCESS;
1080
1081bail:
1083 return MUTT_CMD_ERROR;
1084}
struct RegexList SubscribedLists
List of header patterns to unignore (see)
Definition: globals.c:47
struct RegexList UnSubscribedLists
Definition: globals.c:53
+ Here is the call graph for this function:

◆ parse_subscribe_to()

enum CommandResult parse_subscribe_to ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'subscribe-to' command - Implements Command::parse() -.

The 'subscribe-to' command allows to subscribe to an IMAP-Mailbox. Patterns are not supported. Use it as follows: subscribe-to =folder

Definition at line 1094 of file commands.c.

1096{
1097 if (!buf || !s || !err)
1098 return MUTT_CMD_ERROR;
1099
1100 buf_reset(err);
1101
1102 if (MoreArgs(s))
1103 {
1105
1106 if (MoreArgs(s))
1107 {
1108 buf_printf(err, _("%s: too many arguments"), "subscribe-to");
1109 return MUTT_CMD_WARNING;
1110 }
1111
1112 if (buf->data && (*buf->data != '\0'))
1113 {
1114 /* Expand and subscribe */
1115 if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), true) == 0)
1116 {
1117 mutt_message(_("Subscribed to %s"), buf->data);
1118 return MUTT_CMD_SUCCESS;
1119 }
1120
1121 buf_printf(err, _("Could not subscribe to %s"), buf->data);
1122 return MUTT_CMD_ERROR;
1123 }
1124
1125 mutt_debug(LL_DEBUG1, "Corrupted buffer");
1126 return MUTT_CMD_ERROR;
1127 }
1128
1129 buf_addstr(err, _("No folder specified"));
1130 return MUTT_CMD_WARNING;
1131}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:86
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:236
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1124
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:40
size_t dsize
Length of data.
Definition: buffer.h:37
+ Here is the call graph for this function:

◆ parse_tag_formats()

static enum CommandResult parse_tag_formats ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'tag-formats' command - Implements Command::parse() -.

Parse config like: tag-formats pgp GP

Note
This maps format -> tag

Definition at line 1141 of file commands.c.

1143{
1144 if (!s)
1145 return MUTT_CMD_ERROR;
1146
1147 struct Buffer *tagbuf = buf_pool_get();
1148 struct Buffer *fmtbuf = buf_pool_get();
1149
1150 while (MoreArgs(s))
1151 {
1153 const char *tag = buf_string(tagbuf);
1154 if (*tag == '\0')
1155 continue;
1156
1158 const char *fmt = buf_string(fmtbuf);
1159
1160 /* avoid duplicates */
1161 const char *tmp = mutt_hash_find(TagFormats, fmt);
1162 if (tmp)
1163 {
1164 mutt_warning(_("tag format '%s' already registered as '%s'"), fmt, tmp);
1165 continue;
1166 }
1167
1169 }
1170
1171 buf_pool_release(&tagbuf);
1172 buf_pool_release(&fmtbuf);
1173 return MUTT_CMD_SUCCESS;
1174}
#define mutt_warning(...)
Definition: logging2.h:85
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
Definition: hash.c:335
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:362
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:106
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:119
struct HashTable * TagFormats
Hash Table: "inbox" -> "GI" - Tag format strings.
Definition: tags.c:39
+ Here is the call graph for this function:

◆ parse_tag_transforms()

static enum CommandResult parse_tag_transforms ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'tag-transforms' command - Implements Command::parse() -.

Parse config like: tag-transforms pgp P

Note
This maps tag -> transform

Definition at line 1183 of file commands.c.

1185{
1186 if (!s)
1187 return MUTT_CMD_ERROR;
1188
1189 struct Buffer *tagbuf = buf_pool_get();
1190 struct Buffer *trnbuf = buf_pool_get();
1191
1192 while (MoreArgs(s))
1193 {
1195 const char *tag = buf_string(tagbuf);
1196 if (*tag == '\0')
1197 continue;
1198
1200 const char *trn = buf_string(trnbuf);
1201
1202 /* avoid duplicates */
1203 const char *tmp = mutt_hash_find(TagTransforms, tag);
1204 if (tmp)
1205 {
1206 mutt_warning(_("tag transform '%s' already registered as '%s'"), tag, tmp);
1207 continue;
1208 }
1209
1211 }
1212
1213 buf_pool_release(&tagbuf);
1214 buf_pool_release(&trnbuf);
1215 return MUTT_CMD_SUCCESS;
1216}
struct HashTable * TagTransforms
Hash Table: "inbox" -> "i" - Alternative tag names.
Definition: tags.c:38
+ Here is the call graph for this function:

◆ parse_unignore()

static enum CommandResult parse_unignore ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'unignore' command - Implements Command::parse() -.

Definition at line 1221 of file commands.c.

1223{
1224 do
1225 {
1227
1228 /* don't add "*" to the unignore list */
1229 if (!mutt_str_equal(buf->data, "*"))
1230 add_to_stailq(&UnIgnore, buf->data);
1231
1233 } while (MoreArgs(s));
1234
1235 return MUTT_CMD_SUCCESS;
1236}
+ Here is the call graph for this function:

◆ parse_unlists()

static enum CommandResult parse_unlists ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'unlists' command - Implements Command::parse() -.

Definition at line 1241 of file commands.c.

1243{
1245 do
1246 {
1250
1251 if (!mutt_str_equal(buf->data, "*") &&
1252 (mutt_regexlist_add(&UnMailLists, buf->data, REG_ICASE, err) != 0))
1253 {
1254 return MUTT_CMD_ERROR;
1255 }
1256 } while (MoreArgs(s));
1257
1258 return MUTT_CMD_SUCCESS;
1259}
struct HashTable * AutoSubscribeCache
< Hash Table: "mailto:" -> AutoSubscribeCache
Definition: globals.c:35
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
+ Here is the call graph for this function:

◆ 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() -.

This is also used by 'unvirtual-mailboxes'

Definition at line 1306 of file commands.c.

1308{
1309 while (MoreArgs(s))
1310 {
1312
1313 if (mutt_str_equal(buf->data, "*"))
1314 {
1316 return MUTT_CMD_SUCCESS;
1317 }
1318
1319 buf_expand_path(buf);
1320
1321 struct Account *a = NULL;
1322 TAILQ_FOREACH(a, &NeoMutt->accounts, entries)
1323 {
1324 struct Mailbox *m = mx_mbox_find(a, buf_string(buf));
1325 if (m)
1326 {
1327 do_unmailboxes(m);
1328 break;
1329 }
1330 }
1331 }
1332 return MUTT_CMD_SUCCESS;
1333}
static void do_unmailboxes_star(void)
Remove all Mailboxes from the Sidebar/notifications.
Definition: commands.c:1288
static void do_unmailboxes(struct Mailbox *m)
Remove a Mailbox from the Sidebar/notifications.
Definition: commands.c:1265
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
+ Here is the call graph for this function:

◆ parse_unmy_hdr()

static enum CommandResult parse_unmy_hdr ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'unmy_hdr' command - Implements Command::parse() -.

Definition at line 1338 of file commands.c.

1340{
1341 struct ListNode *np = NULL, *tmp = NULL;
1342 size_t l;
1343
1344 do
1345 {
1347 if (mutt_str_equal("*", buf->data))
1348 {
1349 /* Clear all headers, send a notification for each header */
1350 STAILQ_FOREACH(np, &UserHeader, entries)
1351 {
1352 mutt_debug(LL_NOTIFY, "NT_HEADER_DELETE: %s\n", np->data);
1353 struct EventHeader ev_h = { np->data };
1355 }
1357 continue;
1358 }
1359
1360 l = mutt_str_len(buf->data);
1361 if (buf->data[l - 1] == ':')
1362 l--;
1363
1364 STAILQ_FOREACH_SAFE(np, &UserHeader, entries, tmp)
1365 {
1366 if (mutt_istrn_equal(buf->data, np->data, l) && (np->data[l] == ':'))
1367 {
1368 mutt_debug(LL_NOTIFY, "NT_HEADER_DELETE: %s\n", np->data);
1369 struct EventHeader ev_h = { np->data };
1371
1372 header_free(&UserHeader, np);
1373 }
1374 }
1375 } while (MoreArgs(s));
1376 return MUTT_CMD_SUCCESS;
1377}
void header_free(struct ListHead *hdrlist, struct ListNode *target)
Free and remove a header from a header list.
Definition: email.c:206
@ NT_HEADER_DELETE
Header has been removed.
Definition: email.h:173
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:568
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition: string.c:525
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
char * data
String.
Definition: list.h:36
+ Here is the call graph for this function:

◆ parse_unstailq()

static enum CommandResult parse_unstailq ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse an unlist command - Implements Command::parse() -.

This is used by 'unalternative_order', 'unauto_view' and several others.

Definition at line 1384 of file commands.c.

1386{
1387 do
1388 {
1390 /* Check for deletion of entire list */
1391 if (mutt_str_equal(buf->data, "*"))
1392 {
1393 mutt_list_free((struct ListHead *) data);
1394 break;
1395 }
1396 remove_from_stailq((struct ListHead *) data, buf->data);
1397 } while (MoreArgs(s));
1398
1399 return MUTT_CMD_SUCCESS;
1400}
+ Here is the call graph for this function:

◆ parse_unsubscribe()

static enum CommandResult parse_unsubscribe ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'unsubscribe' command - Implements Command::parse() -.

Definition at line 1405 of file commands.c.

1407{
1409 do
1410 {
1413
1414 if (!mutt_str_equal(buf->data, "*") &&
1415 (mutt_regexlist_add(&UnSubscribedLists, buf->data, REG_ICASE, err) != 0))
1416 {
1417 return MUTT_CMD_ERROR;
1418 }
1419 } while (MoreArgs(s));
1420
1421 return MUTT_CMD_SUCCESS;
1422}
+ Here is the call graph for this function:

◆ parse_unsubscribe_from()

enum CommandResult parse_unsubscribe_from ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'unsubscribe-from' command - Implements Command::parse() -.

The 'unsubscribe-from' command allows to unsubscribe from an IMAP-Mailbox. Patterns are not supported. Use it as follows: unsubscribe-from =folder

Definition at line 1432 of file commands.c.

1434{
1435 if (!buf || !s || !err)
1436 return MUTT_CMD_ERROR;
1437
1438 if (MoreArgs(s))
1439 {
1441
1442 if (MoreArgs(s))
1443 {
1444 buf_printf(err, _("%s: too many arguments"), "unsubscribe-from");
1445 return MUTT_CMD_WARNING;
1446 }
1447
1448 if (buf->data && (*buf->data != '\0'))
1449 {
1450 /* Expand and subscribe */
1451 if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), false) == 0)
1452 {
1453 mutt_message(_("Unsubscribed from %s"), buf->data);
1454 return MUTT_CMD_SUCCESS;
1455 }
1456
1457 buf_printf(err, _("Could not unsubscribe from %s"), buf->data);
1458 return MUTT_CMD_ERROR;
1459 }
1460
1461 mutt_debug(LL_DEBUG1, "Corrupted buffer");
1462 return MUTT_CMD_ERROR;
1463 }
1464
1465 buf_addstr(err, _("No folder specified"));
1466 return MUTT_CMD_WARNING;
1467}
+ Here is the call graph for this function:

◆ parse_version()

static enum CommandResult parse_version ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'version' command - Implements Command::parse() -.

Definition at line 1473 of file commands.c.

1475{
1476 // silently ignore 'version' if it's in a config file
1477 if (!StartupComplete)
1478 return MUTT_CMD_SUCCESS;
1479
1480 char tempfile[PATH_MAX] = { 0 };
1481 mutt_mktemp(tempfile, sizeof(tempfile));
1482
1483 FILE *fp_out = mutt_file_fopen(tempfile, "w");
1484 if (!fp_out)
1485 {
1486 // L10N: '%s' is the file name of the temporary file
1487 buf_printf(err, _("Could not create temporary file %s"), tempfile);
1488 return MUTT_CMD_ERROR;
1489 }
1490
1491 print_version(fp_out);
1492 mutt_file_fclose(&fp_out);
1493
1494 struct PagerData pdata = { 0 };
1495 struct PagerView pview = { &pdata };
1496
1497 pdata.fname = tempfile;
1498
1499 pview.banner = "version";
1500 pview.flags = MUTT_PAGER_NO_FLAGS;
1501 pview.mode = PAGER_MODE_OTHER;
1502
1503 mutt_do_pager(&pview, NULL);
1504 return MUTT_CMD_SUCCESS;
1505}
bool print_version(FILE *fp)
Print system and compile info to a file.
Definition: version.c:420
+ Here is the call graph for this function:

◆ mutt_parse_charset_iconv_hook()

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 at line 85 of file hook.c.

87{
88 struct Buffer *alias = buf_pool_get();
89 struct Buffer *charset = buf_pool_get();
90
91 int rc = MUTT_CMD_ERROR;
92 int retval = 0;
93
94 retval += parse_extract_token(alias, s, TOKEN_NO_FLAGS);
95 retval += parse_extract_token(charset, s, TOKEN_NO_FLAGS);
96 if (retval != 0)
97 goto done;
98
100
101 if (buf_is_empty(alias) || buf_is_empty(charset))
102 {
103 buf_printf(err, _("%s: too few arguments"), buf->data);
104 rc = MUTT_CMD_WARNING;
105 }
106 else if (MoreArgs(s))
107 {
108 buf_printf(err, _("%s: too many arguments"), buf->data);
109 buf_reset(s); // clean up buffer to avoid a mess with further rcfile processing
110 rc = MUTT_CMD_WARNING;
111 }
112 else if (mutt_ch_lookup_add(type, buf_string(alias), buf_string(charset), err))
113 {
114 rc = MUTT_CMD_SUCCESS;
115 }
116
117done:
118 buf_pool_release(&alias);
119 buf_pool_release(&charset);
120
121 return rc;
122}
#define MUTT_ICONV_HOOK
iconv-hook: create a system charset alias
Definition: hook.h:44
bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err)
Add a new character set lookup.
Definition: charset.c:500
LookupType
Types of character set lookups.
Definition: charset.h:66
@ MUTT_LOOKUP_ICONV
Character set conversion.
Definition: charset.h:68
@ MUTT_LOOKUP_CHARSET
Alias for another character set.
Definition: charset.h:67
+ Here is the call graph for this function:

◆ 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() -.

This is used by 'account-hook', 'append-hook' and many more.

Definition at line 129 of file hook.c.

131{
132 struct Hook *hook = NULL;
133 int rc = MUTT_CMD_ERROR;
134 bool pat_not = false;
135 bool use_regex = true;
136 regex_t *rx = NULL;
137 struct PatternList *pat = NULL;
138 const bool folder_or_mbox = (data & (MUTT_FOLDER_HOOK | MUTT_MBOX_HOOK));
139
140 struct Buffer *cmd = buf_pool_get();
141 struct Buffer *pattern = buf_pool_get();
142
143 if (~data & MUTT_GLOBAL_HOOK) /* NOT a global hook */
144 {
145 if (*s->dptr == '!')
146 {
147 s->dptr++;
148 SKIPWS(s->dptr);
149 pat_not = true;
150 }
151
153 if (folder_or_mbox && mutt_str_equal(buf_string(pattern), "-noregex"))
154 {
155 use_regex = false;
156 if (!MoreArgs(s))
157 {
158 buf_printf(err, _("%s: too few arguments"), buf->data);
159 rc = MUTT_CMD_WARNING;
160 goto cleanup;
161 }
163 }
164
165 if (!MoreArgs(s))
166 {
167 buf_printf(err, _("%s: too few arguments"), buf->data);
168 rc = MUTT_CMD_WARNING;
169 goto cleanup;
170 }
171 }
172
173 parse_extract_token(cmd, s,
178
179 if (buf_is_empty(cmd))
180 {
181 buf_printf(err, _("%s: too few arguments"), buf->data);
182 rc = MUTT_CMD_WARNING;
183 goto cleanup;
184 }
185
186 if (MoreArgs(s))
187 {
188 buf_printf(err, _("%s: too many arguments"), buf->data);
189 rc = MUTT_CMD_WARNING;
190 goto cleanup;
191 }
192
193 const char *const c_default_hook = cs_subset_string(NeoMutt->sub, "default_hook");
194 if (folder_or_mbox)
195 {
196 /* Accidentally using the ^ mailbox shortcut in the .neomuttrc is a
197 * common mistake */
198 if ((pattern->data[0] == '^') && !CurrentFolder)
199 {
200 buf_strcpy(err, _("current mailbox shortcut '^' is unset"));
201 goto cleanup;
202 }
203
204 struct Buffer *tmp = buf_pool_get();
205 buf_copy(tmp, pattern);
206 buf_expand_path_regex(tmp, use_regex);
207
208 /* Check for other mailbox shortcuts that expand to the empty string.
209 * This is likely a mistake too */
210 if (buf_is_empty(tmp) && !buf_is_empty(pattern))
211 {
212 buf_strcpy(err, _("mailbox shortcut expanded to empty regex"));
213 buf_pool_release(&tmp);
214 goto cleanup;
215 }
216
217 if (use_regex)
218 {
219 buf_copy(pattern, tmp);
220 }
221 else
222 {
224 }
225 buf_pool_release(&tmp);
226 }
227#ifdef USE_COMP_MBOX
229 {
230 if (mutt_comp_valid_command(buf_string(cmd)) == 0)
231 {
232 buf_strcpy(err, _("badly formatted command string"));
233 goto cleanup;
234 }
235 }
236#endif
237 else if (c_default_hook && (~data & MUTT_GLOBAL_HOOK) &&
239 {
240 /* At this stage only these hooks remain:
241 * fcc-, fcc-save-, index-format-, message-, reply-, save-, send- and send2-hook
242 * If given a plain string, or regex, we expand it using $default_hook. */
243 mutt_check_simple(pattern, c_default_hook);
244 }
245
247 {
248 buf_expand_path(cmd);
249 }
250
251 /* check to make sure that a matching hook doesn't already exist */
252 TAILQ_FOREACH(hook, &Hooks, entries)
253 {
255 {
256 /* Ignore duplicate global hooks */
257 if (mutt_str_equal(hook->command, buf_string(cmd)))
258 {
259 rc = MUTT_CMD_SUCCESS;
260 goto cleanup;
261 }
262 }
263 else if ((hook->type == data) && (hook->regex.pat_not == pat_not) &&
264 mutt_str_equal(buf_string(pattern), hook->regex.pattern))
265 {
269 {
270 /* these hooks allow multiple commands with the same
271 * pattern, so if we've already seen this pattern/command pair, just
272 * ignore it instead of creating a duplicate */
273 if (mutt_str_equal(hook->command, buf_string(cmd)))
274 {
275 rc = MUTT_CMD_SUCCESS;
276 goto cleanup;
277 }
278 }
279 else
280 {
281 /* other hooks only allow one command per pattern, so update the
282 * entry with the new command. this currently does not change the
283 * order of execution of the hooks, which i think is desirable since
284 * a common action to perform is to change the default (.) entry
285 * based upon some other information. */
286 FREE(&hook->command);
287 hook->command = buf_strdup(cmd);
289 rc = MUTT_CMD_SUCCESS;
290 goto cleanup;
291 }
292 }
293 }
294
297 {
298 PatternCompFlags comp_flags;
299
300 if (data & (MUTT_SEND2_HOOK))
301 comp_flags = MUTT_PC_SEND_MODE_SEARCH;
302 else if (data & (MUTT_SEND_HOOK | MUTT_FCC_HOOK))
303 comp_flags = MUTT_PC_NO_FLAGS;
304 else
305 comp_flags = MUTT_PC_FULL_MSG;
306
307 struct MailboxView *mv_cur = get_current_mailbox_view();
308 struct Menu *menu = get_current_menu();
309 pat = mutt_pattern_comp(mv_cur, menu, buf_string(pattern), comp_flags, err);
310 if (!pat)
311 goto cleanup;
312 }
313 else if (~data & MUTT_GLOBAL_HOOK) /* NOT a global hook */
314 {
315 /* Hooks not allowing full patterns: Check syntax of regex */
316 rx = mutt_mem_calloc(1, sizeof(regex_t));
317 int rc2 = REG_COMP(rx, buf_string(pattern), ((data & MUTT_CRYPT_HOOK) ? REG_ICASE : 0));
318 if (rc2 != 0)
319 {
320 regerror(rc2, rx, err->data, err->dsize);
321 FREE(&rx);
322 goto cleanup;
323 }
324 }
325
326 hook = mutt_mem_calloc(1, sizeof(struct Hook));
327 hook->type = data;
328 hook->command = buf_strdup(cmd);
330 hook->pattern = pat;
331 hook->regex.pattern = buf_strdup(pattern);
332 hook->regex.regex = rx;
333 hook->regex.pat_not = pat_not;
334 TAILQ_INSERT_TAIL(&Hooks, hook, entries);
335 rc = MUTT_CMD_SUCCESS;
336
337cleanup:
338 buf_pool_release(&cmd);
339 buf_pool_release(&pattern);
340 return rc;
341}
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:505
char * mutt_get_sourced_cwd(void)
Get the current file path that is being parsed.
Definition: commands.c:170
struct PatternList * mutt_pattern_comp(struct MailboxView *mv, struct Menu *menu, const char *s, PatternCompFlags flags, struct Buffer *err)
Create a Pattern.
Definition: compile.c:905
int mutt_comp_valid_command(const char *cmd)
Is this command string allowed?
Definition: compress.c:415
int mutt_file_sanitize_regex(struct Buffer *dest, const char *src)
Escape any regex-magic characters in a string.
Definition: file.c:684
char * CurrentFolder
Currently selected mailbox.
Definition: globals.c:44
static struct HookList Hooks
All simple hooks, e.g. MUTT_FOLDER_HOOK.
Definition: hook.c:74
#define MUTT_OPEN_HOOK
open-hook: to read a compressed mailbox
Definition: hook.h:51
#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_CLOSE_HOOK
close-hook: write to a compressed mailbox
Definition: hook.h:53
#define MUTT_ACCOUNT_HOOK
account-hook: when changing between accounts
Definition: hook.h:47
#define MUTT_APPEND_HOOK
append-hook: append to a compressed mailbox
Definition: hook.h:52
#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
struct MailboxView * get_current_mailbox_view(void)
Get the current Mailbox view.
Definition: index.c:630
struct Menu * get_current_menu(void)
Get the current Menu.
Definition: index.c:678
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
void buf_expand_path_regex(struct Buffer *buf, bool regex)
Create the canonical path (with regex char escaping)
Definition: muttlib.c:136
#define WithCrypto
Definition: lib.h:116
#define MUTT_PC_SEND_MODE_SEARCH
Allow send-mode body searching.
Definition: lib.h:65
uint8_t PatternCompFlags
Flags for mutt_pattern_comp(), e.g. MUTT_PC_FULL_MSG.
Definition: lib.h:61
#define MUTT_PC_FULL_MSG
Enable body and header matching.
Definition: lib.h:63
void mutt_check_simple(struct Buffer *s, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:115
#define MUTT_PC_NO_FLAGS
No flags are set.
Definition: lib.h:62
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:53
A list of user hooks.
Definition: hook.c:63
HookFlags type
Hook type.
Definition: hook.c:64
struct PatternList * pattern
Used for fcc,save,send-hook.
Definition: hook.c:68
struct Regex regex
Regular expression.
Definition: hook.c:65
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
char * source_file
Used for relative-directory source.
Definition: hook.c:67
View of a Mailbox.
Definition: mview.h:39
Definition: lib.h:70
char * pattern
printable version
Definition: regex3.h:90
bool pat_not
do not match
Definition: regex3.h:92
regex_t * regex
compiled expression
Definition: regex3.h:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_idxfmt_hook()

static enum CommandResult mutt_parse_idxfmt_hook ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'index-format-hook' command - Implements Command::parse() -.

Definition at line 411 of file hook.c.

413{
415 bool pat_not = false;
416
417 struct Buffer *name = buf_pool_get();
418 struct Buffer *pattern = buf_pool_get();
419 struct Buffer *fmtstring = buf_pool_get();
420
421 if (!IdxFmtHooks)
422 {
425 }
426
427 if (!MoreArgs(s))
428 {
429 buf_printf(err, _("%s: too few arguments"), buf->data);
430 goto out;
431 }
433 struct HookList *hl = mutt_hash_find(IdxFmtHooks, buf_string(name));
434
435 if (*s->dptr == '!')
436 {
437 s->dptr++;
438 SKIPWS(s->dptr);
439 pat_not = true;
440 }
442
443 if (!MoreArgs(s))
444 {
445 buf_printf(err, _("%s: too few arguments"), buf->data);
446 goto out;
447 }
448 parse_extract_token(fmtstring, s, TOKEN_NO_FLAGS);
449
450 if (MoreArgs(s))
451 {
452 buf_printf(err, _("%s: too many arguments"), buf->data);
453 goto out;
454 }
455
456 const char *const c_default_hook = cs_subset_string(NeoMutt->sub, "default_hook");
457 if (c_default_hook)
458 mutt_check_simple(pattern, c_default_hook);
459
460 /* check to make sure that a matching hook doesn't already exist */
461 struct Hook *hook = NULL;
462 if (hl)
463 {
464 TAILQ_FOREACH(hook, hl, entries)
465 {
466 if ((hook->regex.pat_not == pat_not) &&
468 {
469 mutt_str_replace(&hook->command, buf_string(fmtstring));
470 rc = MUTT_CMD_SUCCESS;
471 goto out;
472 }
473 }
474 }
475
476 /* MUTT_PC_PATTERN_DYNAMIC sets so that date ranges are regenerated during
477 * matching. This of course is slower, but index-format-hook is commonly
478 * used for date ranges, and they need to be evaluated relative to "now", not
479 * the hook compilation time. */
480 struct MailboxView *mv_cur = get_current_mailbox_view();
481 struct Menu *menu = get_current_menu();
482 struct PatternList *pat = mutt_pattern_comp(mv_cur, menu, buf_string(pattern),
484 err);
485 if (!pat)
486 goto out;
487
488 hook = mutt_mem_calloc(1, sizeof(struct Hook));
489 hook->type = MUTT_IDXFMTHOOK;
490 hook->command = buf_strdup(fmtstring);
492 hook->pattern = pat;
493 hook->regex.pattern = buf_strdup(pattern);
494 hook->regex.regex = NULL;
495 hook->regex.pat_not = pat_not;
496
497 if (!hl)
498 {
499 hl = mutt_mem_calloc(1, sizeof(*hl));
500 TAILQ_INIT(hl);
502 }
503
504 TAILQ_INSERT_TAIL(hl, hook, entries);
505 rc = MUTT_CMD_SUCCESS;
506
507out:
508 buf_pool_release(&name);
509 buf_pool_release(&pattern);
510 buf_pool_release(&fmtstring);
511
512 return rc;
513}
static void idxfmt_hashelem_free(int type, void *obj, intptr_t data)
Delete an index-format-hook from the Hash Table - Implements hash_hdata_free_t -.
Definition: hook.c:385
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
Definition: hash.c:259
void mutt_hash_set_destructor(struct HashTable *table, hash_hdata_free_t fn, intptr_t fn_data)
Set the destructor for a Hash Table.
Definition: hash.c:301
#define MUTT_HASH_STRDUP_KEYS
make a copy of the keys
Definition: hash.h:112
static struct HashTable * IdxFmtHooks
All Index Format hooks.
Definition: hook.c:77
#define MUTT_IDXFMTHOOK
index-format-hook: customise the format of the index
Definition: hook.h:55
#define MUTT_PC_PATTERN_DYNAMIC
Enable runtime date range evaluation.
Definition: lib.h:64
#define TAILQ_INIT(head)
Definition: queue.h:765
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_unhook()

static enum CommandResult mutt_parse_unhook ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)
static

Parse the 'unhook' command - Implements Command::parse() -.

Definition at line 538 of file hook.c.

540{
541 while (MoreArgs(s))
542 {
544 if (mutt_str_equal("*", buf->data))
545 {
547 {
548 buf_printf(err, "%s", _("unhook: Can't do unhook * from within a hook"));
549 return MUTT_CMD_WARNING;
550 }
554 }
555 else
556 {
557 HookFlags type = mutt_get_hook_type(buf->data);
558
559 if (type == MUTT_HOOK_NO_FLAGS)
560 {
561 buf_printf(err, _("unhook: unknown hook type: %s"), buf->data);
562 return MUTT_CMD_ERROR;
563 }
564 if (type & (MUTT_CHARSET_HOOK | MUTT_ICONV_HOOK))
565 {
567 return MUTT_CMD_SUCCESS;
568 }
569 if (CurrentHookType == type)
570 {
571 buf_printf(err, _("unhook: Can't delete a %s from within a %s"),
572 buf->data, buf->data);
573 return MUTT_CMD_WARNING;
574 }
575 if (type == MUTT_IDXFMTHOOK)
577 else
578 mutt_delete_hooks(type);
579 }
580 }
581 return MUTT_CMD_SUCCESS;
582}
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
Definition: hook.c:367
static void delete_idxfmt_hooks(void)
Delete all the index-format-hooks.
Definition: hook.c:403
static HookFlags mutt_get_hook_type(const char *name)
Find a hook by name.
Definition: hook.c:521
static HookFlags CurrentHookType
The type of the hook currently being executed, e.g. MUTT_SAVE_HOOK.
Definition: hook.c:80
uint32_t HookFlags
Flags for mutt_parse_hook(), e.g. MUTT_FOLDER_HOOK.
Definition: hook.h:36
#define MUTT_CHARSET_HOOK
charset-hook: create a charset alias for malformed emails
Definition: hook.h:43
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:37
void mutt_ch_lookup_remove(void)
Remove all the character set lookups.
Definition: charset.c:532
+ Here is the call graph for this function:

◆ 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 at line 1133 of file keymap.c.

1135{
1137 if (MoreArgs(s))
1138 {
1139 buf_printf(err, _("%s: too many arguments"), "push");
1140 return MUTT_CMD_ERROR;
1141 }
1142
1144 return MUTT_CMD_SUCCESS;
1145}
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:562
#define TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: extract.h:46
static void generic_tokenize_push_string(char *s, void(*generic_push)(int, int))
Parse and queue a 'push' command.
Definition: keymap.c:544
+ Here is the call graph for this function:

◆ 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() -.

bind menu-name <key_sequence> function-name

Definition at line 1514 of file keymap.c.

1516{
1517 if (StartupComplete)
1518 {
1519 // Save and restore the offset in `s` because dump_bind_macro() might change it
1520 char *dptr = s->dptr;
1521 if (dump_bind_macro(buf, s, data, err) == MUTT_CMD_SUCCESS)
1522 return MUTT_CMD_SUCCESS;
1523 if (!buf_is_empty(err))
1524 return MUTT_CMD_ERROR;
1525 s->dptr = dptr;
1526 }
1527
1528 const struct MenuFuncOp *funcs = NULL;
1529 enum MenuType mtypes[MenuNamesLen];
1530 int num_menus = 0;
1532
1533 char *key = parse_keymap(mtypes, s, mutt_array_size(mtypes), &num_menus, err, true);
1534 if (!key)
1535 return MUTT_CMD_ERROR;
1536
1537 /* function to execute */
1539 if (MoreArgs(s))
1540 {
1541 buf_printf(err, _("%s: too many arguments"), "bind");
1542 rc = MUTT_CMD_ERROR;
1543 }
1544 else if (mutt_istr_equal("noop", buf->data))
1545 {
1546 for (int i = 0; i < num_menus; i++)
1547 {
1548 km_bindkey(key, mtypes[i], OP_NULL); /* the 'unbind' command */
1549 funcs = km_get_table(mtypes[i]);
1550 if (funcs)
1551 {
1552 char keystr[32] = { 0 };
1553 km_expand_key_string(key, keystr, sizeof(keystr));
1554 const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1555 mutt_debug(LL_NOTIFY, "NT_BINDING_DELETE: %s %s\n", mname, keystr);
1556
1557 int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1558 struct EventBinding ev_b = { mtypes[i], key, op };
1560 }
1561 }
1562 }
1563 else
1564 {
1565 for (int i = 0; i < num_menus; i++)
1566 {
1567 /* The pager and editor menus don't use the generic map,
1568 * however for other menus try generic first. */
1569 if ((mtypes[i] != MENU_PAGER) && (mtypes[i] != MENU_EDITOR) && (mtypes[i] != MENU_GENERIC))
1570 {
1571 rc = try_bind(key, mtypes[i], buf->data, OpGeneric, err);
1572 if (rc == MUTT_CMD_SUCCESS)
1573 {
1574 char keystr[32] = { 0 };
1575 km_expand_key_string(key, keystr, sizeof(keystr));
1576 const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1577 mutt_debug(LL_NOTIFY, "NT_BINDING_NEW: %s %s\n", mname, keystr);
1578
1579 int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1580 struct EventBinding ev_b = { mtypes[i], key, op };
1582 continue;
1583 }
1584 if (rc == MUTT_CMD_WARNING)
1585 break;
1586 }
1587
1588 /* Clear any error message, we're going to try again */
1589 err->data[0] = '\0';
1590 funcs = km_get_table(mtypes[i]);
1591 if (funcs)
1592 {
1593 rc = try_bind(key, mtypes[i], buf->data, funcs, err);
1594 if (rc == MUTT_CMD_SUCCESS)
1595 {
1596 char keystr[32] = { 0 };
1597 km_expand_key_string(key, keystr, sizeof(keystr));
1598 const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1599 mutt_debug(LL_NOTIFY, "NT_BINDING_NEW: %s %s\n", mname, keystr);
1600
1601 int op = get_op(funcs, buf->data, mutt_str_len(buf->data));
1602 struct EventBinding ev_b = { mtypes[i], key, op };
1604 continue;
1605 }
1606 }
1607 }
1608 }
1609 FREE(&key);
1610 return rc;
1611}
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition: functions.c:288
static int km_expand_key_string(char *str, char *buf, size_t buflen)
Get a human-readable key string.
Definition: keymap.c:919
static enum CommandResult km_bindkey(const char *s, enum MenuType mtype, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:490
static enum CommandResult dump_bind_macro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse 'bind' and 'macro' commands - Implements ICommand::parse()
Definition: keymap.c:1427
static char * parse_keymap(enum MenuType *mtypes, struct Buffer *s, int max_menus, int *num_menus, struct Buffer *err, bool bind)
Parse a user-config key binding.
Definition: keymap.c:1161
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: keymap.c:1248
static enum CommandResult try_bind(char *key, enum MenuType mtype, char *func, const struct MenuFuncOp *funcs, struct Buffer *err)
Try to make a key binding.
Definition: keymap.c:1225
static int get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:502
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition: keymap.h:126
@ NT_BINDING_ADD
Key binding has been added.
Definition: keymap.h:125
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
#define mutt_array_size(x)
Definition: memory.h:36
@ NT_BINDING
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:40
A key binding Event.
Definition: keymap.h:110
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:112
int op
Operation the key's bound to (for bind), e.g. OP_DELETE.
Definition: keymap.h:113
Mapping between a function and an operation.
Definition: keymap.h:92
int op
Operation, e.g. OP_DELETE.
Definition: keymap.h:94
const int MenuNamesLen
Number of entries in the MenuNames array.
Definition: type.c:66
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:37
MenuType
Types of GUI selections.
Definition: type.h:36
@ MENU_GENERIC
Generic selection list.
Definition: type.h:45
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:54
@ MENU_EDITOR
Text entry area.
Definition: type.h:43
+ Here is the call graph for this function:

◆ 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() -.

Command unbinds:

  • one binding in one menu-name
  • one binding in all menu-names
  • all bindings in all menu-names

unbind <menu-name[,...]|*> [<key_sequence>]

Definition at line 1677 of file keymap.c.

1679{
1680 bool menu_matches[MENU_MAX] = { 0 };
1681 bool all_keys = false;
1682 char *key = NULL;
1683
1685 if (mutt_str_equal(buf->data, "*"))
1686 {
1687 for (enum MenuType i = 0; i < MENU_MAX; i++)
1688 menu_matches[i] = true;
1689 }
1690 else
1691 {
1692 parse_menu(menu_matches, buf->data, err);
1693 }
1694
1695 if (MoreArgs(s))
1696 {
1698 key = buf->data;
1699 }
1700 else
1701 {
1702 all_keys = true;
1703 }
1704
1705 if (MoreArgs(s))
1706 {
1707 const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1708
1709 buf_printf(err, _("%s: too many arguments"), cmd);
1710 return MUTT_CMD_ERROR;
1711 }
1712
1713 for (enum MenuType i = 0; i < MENU_MAX; i++)
1714 {
1715 if (!menu_matches[i])
1716 continue;
1717 if (all_keys)
1718 {
1719 km_unbind_all(&Keymaps[i], data);
1720 km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1721 km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1722 km_bindkey("<enter>", MENU_INDEX, OP_DISPLAY_MESSAGE);
1723 km_bindkey("<return>", MENU_INDEX, OP_DISPLAY_MESSAGE);
1724 km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1725 km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1726 km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1727 km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1728 if (i != MENU_EDITOR)
1729 {
1730 km_bindkey("?", i, OP_HELP);
1731 km_bindkey("q", i, OP_EXIT);
1732 }
1733
1734 const char *mname = mutt_map_get_name(i, MenuNames);
1735 mutt_debug(LL_NOTIFY, "NT_MACRO_DELETE_ALL: %s\n", mname);
1736
1737 struct EventBinding ev_b = { i, NULL, OP_NULL };
1740 &ev_b);
1741 }
1742 else
1743 {
1744 char keystr[32] = { 0 };
1745 km_expand_key_string(key, keystr, sizeof(keystr));
1746 const char *mname = mutt_map_get_name(i, MenuNames);
1747 mutt_debug(LL_NOTIFY, "NT_MACRO_DELETE: %s %s\n", mname, keystr);
1748
1749 km_bindkey(key, i, OP_NULL);
1750 struct EventBinding ev_b = { i, key, OP_NULL };
1752 (data & MUTT_UNMACRO) ? NT_MACRO_DELETE : NT_BINDING_DELETE, &ev_b);
1753 }
1754 }
1755
1756 return MUTT_CMD_SUCCESS;
1757}
static void * parse_menu(bool *menus, char *s, struct Buffer *err)
Parse menu-names into an array.
Definition: keymap.c:1622
static void km_unbind_all(struct KeymapList *km_list, unsigned long mode)
Free all the keys in the supplied Keymap.
Definition: keymap.c:1653
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: keymap.c:127
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition: keymap.h:130
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition: keymap.h:131
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition: keymap.h:127
#define MUTT_UNMACRO
Definition: keymap.h:34
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:50
@ MENU_MAX
Definition: type.h:59
+ Here is the call graph for this function:

◆ 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() -.

macro <menu> <key> <macro> <description>

Definition at line 1764 of file keymap.c.

1766{
1767 if (StartupComplete)
1768 {
1769 // Save and restore the offset in `s` because dump_bind_macro() might change it
1770 char *dptr = s->dptr;
1771 if (dump_bind_macro(buf, s, data, err) == MUTT_CMD_SUCCESS)
1772 return MUTT_CMD_SUCCESS;
1773 if (!buf_is_empty(err))
1774 return MUTT_CMD_ERROR;
1775 s->dptr = dptr;
1776 }
1777
1778 enum MenuType mtypes[MenuNamesLen];
1779 int num_menus = 0;
1780 enum CommandResult rc = MUTT_CMD_ERROR;
1781
1782 char *key = parse_keymap(mtypes, s, mutt_array_size(mtypes), &num_menus, err, false);
1783 if (!key)
1784 return MUTT_CMD_ERROR;
1785
1787 /* make sure the macro sequence is not an empty string */
1788 if (buf->data[0] == '\0')
1789 {
1790 buf_strcpy(err, _("macro: empty key sequence"));
1791 }
1792 else
1793 {
1794 if (MoreArgs(s))
1795 {
1796 char *seq = mutt_str_dup(buf->data);
1798
1799 if (MoreArgs(s))
1800 {
1801 buf_printf(err, _("%s: too many arguments"), "macro");
1802 }
1803 else
1804 {
1805 for (int i = 0; i < num_menus; i++)
1806 {
1807 rc = km_bind(key, mtypes[i], OP_MACRO, seq, buf->data);
1808 if (rc == MUTT_CMD_SUCCESS)
1809 {
1810 char keystr[32] = { 0 };
1811 km_expand_key_string(key, keystr, sizeof(keystr));
1812 const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1813 mutt_debug(LL_NOTIFY, "NT_MACRO_NEW: %s %s\n", mname, keystr);
1814
1815 struct EventBinding ev_b = { mtypes[i], key, OP_MACRO };
1817 continue;
1818 }
1819 }
1820 }
1821
1822 FREE(&seq);
1823 }
1824 else
1825 {
1826 for (int i = 0; i < num_menus; i++)
1827 {
1828 rc = km_bind(key, mtypes[i], OP_MACRO, buf->data, NULL);
1829 if (rc == MUTT_CMD_SUCCESS)
1830 {
1831 char keystr[32] = { 0 };
1832 km_expand_key_string(key, keystr, sizeof(keystr));
1833 const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1834 mutt_debug(LL_NOTIFY, "NT_MACRO_NEW: %s %s\n", mname, keystr);
1835
1836 struct EventBinding ev_b = { mtypes[i], key, OP_MACRO };
1838 continue;
1839 }
1840 }
1841 }
1842 }
1843 FREE(&key);
1844 return rc;
1845}
enum CommandResult km_bind(char *s, enum MenuType mtype, int op, char *macro, char *desc)
Bind a key to a macro.
Definition: keymap.c:464
@ NT_MACRO_ADD
Key macro has been added.
Definition: keymap.h:129
+ Here is the call graph for this function:

◆ 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 at line 1850 of file keymap.c.

1852{
1853 int ops[128];
1854 int nops = 0;
1855 const struct MenuFuncOp *funcs = NULL;
1856 char *function = NULL;
1857
1858 if (!MoreArgs(s))
1859 {
1860 buf_strcpy(err, _("exec: no arguments"));
1861 return MUTT_CMD_ERROR;
1862 }
1863
1864 do
1865 {
1867 function = buf->data;
1868
1869 const enum MenuType mtype = menu_get_current_type();
1870 funcs = km_get_table(mtype);
1871 if (!funcs && (mtype != MENU_PAGER))
1872 funcs = OpGeneric;
1873
1874 ops[nops] = get_op(funcs, function, mutt_str_len(function));
1875 if ((ops[nops] == OP_NULL) && (mtype != MENU_PAGER) && (mtype != MENU_GENERIC))
1876 {
1877 ops[nops] = get_op(OpGeneric, function, mutt_str_len(function));
1878 }
1879
1880 if (ops[nops] == OP_NULL)
1881 {
1882 mutt_flushinp();
1883 mutt_error(_("%s: no such function"), function);
1884 return MUTT_CMD_ERROR;
1885 }
1886 nops++;
1887 } while (MoreArgs(s) && nops < mutt_array_size(ops));
1888
1889 while (nops)
1890 mutt_push_macro_event(0, ops[--nops]);
1891
1892 return MUTT_CMD_SUCCESS;
1893}
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:593
enum MenuType menu_get_current_type(void)
Get the type of the current Window.
Definition: menu.c:85
+ Here is the call graph for this function:

◆ mutt_lua_parse()

enum CommandResult mutt_lua_parse ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'lua' command - Implements Command::parse() -.

Definition at line 473 of file mutt_lua.c.

475{
477 mutt_debug(LL_DEBUG2, " * mutt_lua_parse(%s)\n", buf->data);
478
479 if (luaL_dostring(LuaState, s->dptr))
480 {
481 mutt_debug(LL_DEBUG2, " * %s -> failure\n", s->dptr);
482 buf_printf(err, "%s: %s", s->dptr, lua_tostring(LuaState, -1));
483 /* pop error message from the stack */
484 lua_pop(LuaState, 1);
485 return MUTT_CMD_ERROR;
486 }
487 mutt_debug(LL_DEBUG2, " * %s -> success\n", s->dptr);
488 buf_reset(s); // Clear the rest of the line
489 return MUTT_CMD_SUCCESS;
490}
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:41
static bool lua_init(lua_State **l)
Initialise a Lua State.
Definition: mutt_lua.c:437
static lua_State * LuaState
Global Lua State.
Definition: mutt_lua.c:53
+ Here is the call graph for this function:

◆ mutt_lua_source_file()

enum CommandResult mutt_lua_source_file ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'lua-source' command - Implements Command::parse() -.

Definition at line 495 of file mutt_lua.c.

497{
498 mutt_debug(LL_DEBUG2, " * mutt_lua_source()\n");
499
501
502 char path[PATH_MAX] = { 0 };
503
504 if (parse_extract_token(buf, s, TOKEN_NO_FLAGS) != 0)
505 {
506 buf_printf(err, _("source: error at %s"), s->dptr);
507 return MUTT_CMD_ERROR;
508 }
509 if (MoreArgs(s))
510 {
511 buf_printf(err, _("%s: too many arguments"), "source");
512 return MUTT_CMD_WARNING;
513 }
514 mutt_str_copy(path, buf->data, sizeof(path));
515 mutt_expand_path(path, sizeof(path));
516
517 if (luaL_dofile(LuaState, path))
518 {
519 mutt_error(_("Couldn't source lua source: %s"), lua_tostring(LuaState, -1));
520 lua_pop(LuaState, 1);
521 return MUTT_CMD_ERROR;
522 }
523 return MUTT_CMD_SUCCESS;
524}
+ Here is the call graph for this function:

◆ 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() -.

This is used by 'reset', 'set', 'toggle' and 'unset'.

Definition at line 425 of file set.c.

427{
428 /* The order must match `enum MuttSetCommand` */
429 static const char *set_commands[] = { "set", "toggle", "unset", "reset" };
430
431 if (!buf || !s)
432 return MUTT_CMD_ERROR;
433
434 do
435 {
436 bool prefix = false;
437 bool query = false;
438 bool inv = (data == MUTT_SET_INV);
439 bool reset = (data == MUTT_SET_RESET);
440 bool unset = (data == MUTT_SET_UNSET);
441
442 if (*s->dptr == '?')
443 {
444 prefix = true;
445 query = true;
446 s->dptr++;
447 }
448 else if (mutt_str_startswith(s->dptr, "no"))
449 {
450 prefix = true;
451 unset = !unset;
452 s->dptr += 2;
453 }
454 else if (mutt_str_startswith(s->dptr, "inv"))
455 {
456 prefix = true;
457 inv = !inv;
458 s->dptr += 3;
459 }
460 else if (*s->dptr == '&')
461 {
462 prefix = true;
463 reset = true;
464 s->dptr++;
465 }
466
467 if (prefix && (data != MUTT_SET_SET))
468 {
469 buf_printf(err, _("Can't use 'inv', 'no', '&' or '?' with the '%s' command"),
470 set_commands[data]);
471 return MUTT_CMD_WARNING;
472 }
473
474 // get the variable name. Note that buf might be empty if no additional
475 // argument was given.
477 if (ret == -1)
478 return MUTT_CMD_ERROR;
479
480 bool bool_or_quad = false;
481 bool equals = false;
482 bool increment = false;
483 bool decrement = false;
484
485 struct HashElem *he = cs_subset_lookup(NeoMutt->sub, buf->data);
486 if (he)
487 {
488 // Use the correct name if a synonym is used
489 buf_strcpy(buf, he->key.strkey);
490 bool_or_quad = ((DTYPE(he->type) == DT_BOOL) || (DTYPE(he->type) == DT_QUAD));
491 }
492
493 if (*s->dptr == '?')
494 {
495 if (prefix)
496 {
497 buf_printf(err, _("Can't use a prefix when querying a variable"));
498 return MUTT_CMD_WARNING;
499 }
500
501 if (reset || unset || inv)
502 {
503 buf_printf(err, _("Can't query a variable with the '%s' command"),
504 set_commands[data]);
505 return MUTT_CMD_WARNING;
506 }
507
508 query = true;
509 s->dptr++;
510 }
511 else if ((*s->dptr == '+') || (*s->dptr == '-'))
512 {
513 if (prefix)
514 {
515 buf_printf(err, _("Can't use prefix when incrementing or decrementing a variable"));
516 return MUTT_CMD_WARNING;
517 }
518
519 if (reset || unset || inv)
520 {
521 buf_printf(err, _("Can't set a variable with the '%s' command"),
522 set_commands[data]);
523 return MUTT_CMD_WARNING;
524 }
525 if (*s->dptr == '+')
526 increment = true;
527 else
528 decrement = true;
529
530 s->dptr++;
531 if (*s->dptr == '=')
532 {
533 equals = true;
534 s->dptr++;
535 }
536 else
537 {
538 buf_printf(err, _("'+' and '-' must be followed by '='"), set_commands[data]);
539 return MUTT_CMD_WARNING;
540 }
541 }
542 else if (*s->dptr == '=')
543 {
544 if (prefix)
545 {
546 buf_printf(err, _("Can't use prefix when setting a variable"));
547 return MUTT_CMD_WARNING;
548 }
549
550 if (reset || unset || inv)
551 {
552 buf_printf(err, _("Can't set a variable with the '%s' command"),
553 set_commands[data]);
554 return MUTT_CMD_WARNING;
555 }
556
557 equals = true;
558 s->dptr++;
559 }
560
561 if (!bool_or_quad && (inv || (unset && prefix)))
562 {
563 if (data == MUTT_SET_SET)
564 {
565 buf_printf(err, _("Prefixes 'no' and 'inv' may only be used with bool/quad variables"));
566 }
567 else
568 {
569 buf_printf(err, _("Command '%s' can only be used with bool/quad variables"),
570 set_commands[data]);
571 }
572 return MUTT_CMD_WARNING;
573 }
574
575 // sanity checks for the above
576 // Each of inv, unset reset, query, equals implies that the others are not set.
577 // If none of them are set, then we are dealing with a "set foo" command.
578 // clang-format off
579 assert(!inv || !( unset || reset || query || equals ));
580 assert(!unset || !(inv || reset || query || equals ));
581 assert(!reset || !(inv || unset || query || equals ));
582 assert(!query || !(inv || unset || reset || equals ));
583 assert(!equals || !(inv || unset || reset || query || prefix));
584 // clang-format on
585 assert(!(increment && decrement)); // only one of increment or decrement is set
586 assert(!(increment || decrement) || equals); // increment/decrement implies equals
587 assert(!inv || bool_or_quad); // inv (aka toggle) implies bool or quad
588
590 if (query)
591 {
592 rc = command_set_query(buf, err);
593 return rc; // We can only do one query even if multiple config names are given
594 }
595 else if (reset)
596 {
597 rc = command_set_reset(buf, err);
598 }
599 else if (unset)
600 {
601 rc = command_set_unset(buf, err);
602 }
603 else if (inv)
604 {
605 rc = command_set_toggle(buf, err);
606 }
607 else if (equals)
608 {
609 // These three cases all need a value, since 'increment'/'decrement'
610 // implies 'equals', we can group them in this single case guarded by
611 // 'equals'.
612 struct Buffer *value = buf_pool_get();
614 if (increment)
615 rc = command_set_increment(buf, value, err);
616 else if (decrement)
617 rc = command_set_decrement(buf, value, err);
618 else
619 rc = command_set_set(buf, value, err);
620 buf_pool_release(&value);
621 }
622 else
623 {
624 // This is the "set foo" case which has different meanings depending on
625 // the type of the config variable
626 if (bool_or_quad)
627 {
628 struct Buffer *yes = buf_pool_get();
629 buf_addstr(yes, "yes");
630 rc = command_set_set(buf, yes, err);
631 buf_pool_release(&yes);
632 }
633 else
634 {
635 rc = command_set_query(buf, err);
636 return rc; // We can only do one query even if multiple config names are given
637 }
638 }
639 // Short circuit (i.e. skipping further config variable names) if the action on
640 // the current variable failed.
641 if (rc != MUTT_CMD_SUCCESS)
642 return rc;
643 } while (MoreArgs(s));
644
645 return MUTT_CMD_SUCCESS;
646}
#define TOKEN_BACKTICK_VARS
Expand variables within backticks.
Definition: extract.h:52
#define TOKEN_PLUS
Treat '+' as a special.
Definition: extract.h:55
#define TOKEN_MINUS
Treat '-' as a special.
Definition: extract.h:56
static enum CommandResult command_set_toggle(struct Buffer *name, struct Buffer *err)
Toggle a boolean or quad variable.
Definition: set.c:334
static enum CommandResult command_set_set(struct Buffer *name, struct Buffer *value, struct Buffer *err)
Set a variable to the given value.
Definition: set.c:101
static enum CommandResult command_set_reset(struct Buffer *name, struct Buffer *err)
Reset a variable.
Definition: set.c:280
static enum CommandResult command_set_unset(struct Buffer *name, struct Buffer *err)
Unset a variable.
Definition: set.c:241
static enum CommandResult command_set_query(struct Buffer *name, struct Buffer *err)
Query a variable.
Definition: set.c:370
static enum CommandResult command_set_increment(struct Buffer *name, struct Buffer *value, struct Buffer *err)
Increment a variable by a value.
Definition: set.c:156
static enum CommandResult command_set_decrement(struct Buffer *name, struct Buffer *value, struct Buffer *err)
Decrement a variable by a value.
Definition: set.c:211
@ MUTT_SET_INV
default is to invert all vars
Definition: set.h:37
@ MUTT_SET_SET
default is to set all vars
Definition: set.h:36
@ MUTT_SET_RESET
default is to reset all vars to default
Definition: set.h:39
The item stored in a Hash Table.
Definition: hash.h:44
union HashKey key
Key representing the data.
Definition: hash.h:46
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:45
void * data
User-supplied data.
Definition: hash.h:47
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:45
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:37
#define DT_BOOL
boolean option
Definition: types.h:30
const char * strkey
String key.
Definition: hash.h:36
+ Here is the call graph for this function:

◆ 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 at line 87 of file score.c.

89{
90 struct Score *ptr = NULL, *last = NULL;
91 char *pattern = NULL, *pc = NULL;
92
94 if (!MoreArgs(s))
95 {
96 buf_printf(err, _("%s: too few arguments"), "score");
97 return MUTT_CMD_WARNING;
98 }
99 pattern = buf_strdup(buf);
101 if (MoreArgs(s))
102 {
103 FREE(&pattern);
104 buf_printf(err, _("%s: too many arguments"), "score");
105 return MUTT_CMD_WARNING;
106 }
107
108 /* look for an existing entry and update the value, else add it to the end
109 * of the list */
110 for (ptr = ScoreList, last = NULL; ptr; last = ptr, ptr = ptr->next)
111 if (mutt_str_equal(pattern, ptr->str))
112 break;
113
114 if (ptr)
115 {
116 /* 'buf' arg was cleared and 'pattern' holds the only reference;
117 * as here 'ptr' != NULL -> update the value only in which case
118 * ptr->str already has the string, so pattern should be freed. */
119 FREE(&pattern);
120 }
121 else
122 {
123 struct MailboxView *mv_cur = get_current_mailbox_view();
124 struct Menu *menu = get_current_menu();
125 struct PatternList *pat = mutt_pattern_comp(mv_cur, menu, pattern, MUTT_PC_NO_FLAGS, err);
126 if (!pat)
127 {
128 FREE(&pattern);
129 return MUTT_CMD_ERROR;
130 }
131 ptr = mutt_mem_calloc(1, sizeof(struct Score));
132 if (last)
133 last->next = ptr;
134 else
135 ScoreList = ptr;
136 ptr->pat = pat;
137 ptr->str = pattern;
138 }
139 pc = buf->data;
140 if (*pc == '=')
141 {
142 ptr->exact = true;
143 pc++;
144 }
145 if (!mutt_str_atoi_full(pc, &ptr->val))
146 {
147 FREE(&pattern);
148 buf_strcpy(err, _("Error: score: invalid number"));
149 return MUTT_CMD_ERROR;
150 }
151 OptNeedRescore = true;
152 return MUTT_CMD_SUCCESS;
153}
bool OptNeedRescore
(pseudo) set when the 'score' command is used
Definition: globals.c:76
static struct Score * ScoreList
Linked list of email scoring rules.
Definition: score.c:58
Scoring rule for email.
Definition: score.c:49
struct PatternList * pat
Definition: score.c:51
struct Score * next
Linked list.
Definition: score.c:54
+ Here is the call graph for this function:

◆ 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 at line 197 of file score.c.

199{
200 struct Score *tmp = NULL, *last = NULL;
201
202 while (MoreArgs(s))
203 {
205 if (mutt_str_equal("*", buf->data))
206 {
207 for (tmp = ScoreList; tmp;)
208 {
209 last = tmp;
210 tmp = tmp->next;
211 mutt_pattern_free(&last->pat);
212 FREE(&last);
213 }
214 ScoreList = NULL;
215 }
216 else
217 {
218 for (tmp = ScoreList; tmp; last = tmp, tmp = tmp->next)
219 {
220 if (mutt_str_equal(buf->data, tmp->str))
221 {
222 if (last)
223 last->next = tmp->next;
224 else
225 ScoreList = tmp->next;
226 mutt_pattern_free(&tmp->pat);
227 FREE(&tmp);
228 /* there should only be one score per pattern, so we can stop here */
229 break;
230 }
231 }
232 }
233 }
234 OptNeedRescore = true;
235 return MUTT_CMD_SUCCESS;
236}
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition: compile.c:777
+ Here is the call graph for this function:

◆ sb_parse_sidebar_pin()

enum CommandResult sb_parse_sidebar_pin ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'sidebar_pin' command - Implements Command::parse() -.

Definition at line 40 of file commands.c.

42{
43 struct Buffer *path = buf_pool_get();
44
45 do
46 {
48 buf_expand_path(path);
50 } while (MoreArgs(s));
51 buf_pool_release(&path);
52
53 return MUTT_CMD_SUCCESS;
54}
struct ListHead SidebarPinned
List of mailboxes to always display in the sidebar.
Definition: sidebar.c:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sb_parse_sidebar_unpin()

enum CommandResult sb_parse_sidebar_unpin ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'sidebar_unpin' command - Implements Command::parse() -.

Definition at line 59 of file commands.c.

61{
62 struct Buffer *path = buf_pool_get();
63
64 do
65 {
67 /* Check for deletion of entire list */
68 if (mutt_str_equal(buf_string(path), "*"))
69 {
71 break;
72 }
73 buf_expand_path(path);
75 } while (MoreArgs(s));
76 buf_pool_release(&path);
77
78 return MUTT_CMD_SUCCESS;
79}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_unreplace_list()

static enum CommandResult parse_unreplace_list ( struct Buffer buf,
struct Buffer s,
struct ReplaceList *  list,
struct Buffer err 
)
static

Remove a string replacement rule - Implements Command::parse() -.

Definition at line 67 of file subjectrx.c.

69{
70 /* First token is a regex. */
71 if (!MoreArgs(s))
72 {
73 buf_printf(err, _("%s: too few arguments"), "unsubjectrx");
74 return MUTT_CMD_WARNING;
75 }
76
78
79 /* "*" is a special case. */
80 if (mutt_str_equal(buf->data, "*"))
81 {
83 return MUTT_CMD_SUCCESS;
84 }
85
86 mutt_replacelist_remove(list, buf->data);
87 return MUTT_CMD_SUCCESS;
88}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_replace_list()

static enum CommandResult parse_replace_list ( struct Buffer buf,
struct Buffer s,
struct ReplaceList *  list,
struct Buffer err 
)
static

Parse a string replacement rule - Implements Command::parse() -.

Definition at line 93 of file subjectrx.c.

95{
96 struct Buffer templ = buf_make(0);
97
98 /* First token is a regex. */
99 if (!MoreArgs(s))
100 {
101 buf_printf(err, _("%s: too few arguments"), "subjectrx");
102 return MUTT_CMD_WARNING;
103 }
105
106 /* Second token is a replacement template */
107 if (!MoreArgs(s))
108 {
109 buf_printf(err, _("%s: too few arguments"), "subjectrx");
110 return MUTT_CMD_WARNING;
111 }
113
114 if (mutt_replacelist_add(list, buf->data, templ.data, err) != 0)
115 {
116 FREE(&templ.data);
117 return MUTT_CMD_ERROR;
118 }
119 FREE(&templ.data);
120
121 return MUTT_CMD_SUCCESS;
122}
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 at line 167 of file subjectrx.c.

169{
170 enum CommandResult rc;
171
172 rc = parse_replace_list(buf, s, &SubjectRegexList, err);
173 if (rc == MUTT_CMD_SUCCESS)
174 {
175 mutt_debug(LL_NOTIFY, "NT_SUBJRX_ADD: %s\n", buf->data);
177 }
178 return rc;
179}
static enum CommandResult parse_replace_list(struct Buffer *buf, struct Buffer *s, struct ReplaceList *list, struct Buffer *err)
Parse a string replacement rule - Implements Command::parse() -.
Definition: subjectrx.c:93
@ NT_SUBJRX
Subject Regex has changed, NotifySubjRx.
Definition: notify_type.h:54
static struct Notify * SubjRxNotify
Notifications: NotifySubjRx.
Definition: subjectrx.c:41
static struct ReplaceList SubjectRegexList
List of subjectrx rules for modifying the Subject:
Definition: subjectrx.c:40
@ NT_SUBJRX_ADD
Subject Regex has been added.
Definition: subjectrx.h:43
+ Here is the call graph for this function:

◆ 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 at line 184 of file subjectrx.c.

186{
187 enum CommandResult rc;
188
189 rc = parse_unreplace_list(buf, s, &SubjectRegexList, err);
190 if (rc == MUTT_CMD_SUCCESS)
191 {
192 mutt_debug(LL_NOTIFY, "NT_SUBJRX_DELETE: %s\n", buf->data);
194 }
195 return rc;
196}
static enum CommandResult parse_unreplace_list(struct Buffer *buf, struct Buffer *s, struct ReplaceList *list, struct Buffer *err)
Remove a string replacement rule - Implements Command::parse() -.
Definition: subjectrx.c:67
@ NT_SUBJRX_DELETE
Subject Regex has been deleted.
Definition: subjectrx.h:44
+ Here is the call graph for this function: