NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches

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() -.
 
enum CommandResult parse_unalias (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unalias' command - Implements Command::parse() -.
 
enum CommandResult parse_alternates (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'alternates' command - Implements Command::parse() -.
 
enum CommandResult parse_unalternates (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unalternates' command - Implements Command::parse() -.
 
enum CommandResult parse_attachments (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'attachments' command - Implements Command::parse() -.
 
enum CommandResult parse_unattachments (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unattachments' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_uncolor (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'uncolor' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_unmono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmono' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_color (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'color' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_mono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'mono' command - Implements Command::parse() -.
 
static enum CommandResult parse_cd (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'cd' command - Implements Command::parse() -.
 
static enum CommandResult parse_echo (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'echo' command - Implements Command::parse() -.
 
static enum CommandResult parse_finish (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'finish' command - Implements Command::parse() -.
 
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() -.
 
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() -.
 
static enum CommandResult parse_ignore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'ignore' command - Implements Command::parse() -.
 
static enum CommandResult parse_lists (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lists' command - Implements Command::parse() -.
 
enum CommandResult parse_mailboxes (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'mailboxes' command - Implements Command::parse() -.
 
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() -.
 
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() -.
 
static enum CommandResult parse_source (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'source' command - Implements Command::parse() -.
 
static enum CommandResult parse_nospam (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'nospam' command - Implements Command::parse() -.
 
static enum CommandResult parse_spam (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'spam' command - Implements Command::parse() -.
 
static enum CommandResult parse_stailq (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse a list command - Implements Command::parse() -.
 
static enum CommandResult parse_subscribe (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subscribe' command - Implements Command::parse() -.
 
enum CommandResult parse_subscribe_to (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subscribe-to' command - Implements Command::parse() -.
 
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() -.
 
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() -.
 
static enum CommandResult parse_unignore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unignore' command - Implements Command::parse() -.
 
static enum CommandResult parse_unlists (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unlists' command - Implements Command::parse() -.
 
enum CommandResult parse_unmailboxes (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmailboxes' command - Implements Command::parse() -.
 
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() -.
 
static enum CommandResult parse_unstailq (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse an unlist command - Implements Command::parse() -.
 
static enum CommandResult parse_unsubscribe (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubscribe' command - Implements Command::parse() -.
 
enum CommandResult parse_unsubscribe_from (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubscribe-from' command - Implements Command::parse() -.
 
static enum CommandResult parse_version (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'version' command - Implements Command::parse() -.
 
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() -.
 
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() -.
 
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() -.
 
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() -.
 
enum CommandResult dump_bind_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse 'bind' and 'macro' commands - Implements Command::parse() -.
 
enum CommandResult mutt_parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'push' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'bind' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_unbind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unbind' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'macro' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'exec' command - Implements Command::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() -.
 
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() -.
 
enum CommandResult parse_set (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'set' family of commands - Implements Command::parse() -.
 
enum CommandResult mutt_parse_score (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'score' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_unscore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unscore' command - Implements Command::parse() -.
 
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() -.
 
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() -.
 
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() -.
 
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() -.
 
enum CommandResult parse_subjectrx_list (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subjectrx' command - Implements Command::parse() -.
 
enum CommandResult parse_unsubjectrx_list (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubjectrx' command - Implements Command::parse() -.
 

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", buf_string(a->mailbox));
131 else
132 mutt_debug(LL_DEBUG5, " %s\n", buf_string(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:1461
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:641
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1294
struct AliasList Aliases
List of all the user's email aliases.
Definition: alias.c:60
struct Alias * alias_new(void)
Create a new Alias.
Definition: alias.c:630
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:173
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:407
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
@ 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:124
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
int parse_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: extract.c:48
#define TOKEN_SPACE
Don't treat whitespace as a term.
Definition: extract.h:48
#define TOKEN_QUOTE
Don't interpret quotes.
Definition: extract.h:49
#define MoreArgs(buf)
Definition: extract.h:31
#define TOKEN_SEMICOLON
Don't treat ; as special.
Definition: extract.h:52
#define TOKEN_NO_FLAGS
No flags are set.
Definition: extract.h:45
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:89
@ LL_DEBUG4
Log at debug level 4.
Definition: logging2.h:46
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
#define FREE(x)
Definition: memory.h:45
#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:173
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
struct Buffer * 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:41
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ 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:641
void aliaslist_clear(struct AliasList *al)
Empty a List of Aliases.
Definition: alias.c:664
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:136
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:231
@ 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:184
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:150
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 475 of file command.c.

477{
478 if (OptNoCurses) // No GUI, so quietly discard the command
479 {
480 while (MoreArgs(s))
481 {
483 }
484 return MUTT_CMD_SUCCESS;
485 }
486
487 color_debug(LL_DEBUG5, "parse: %s\n", buf_string(buf));
488 enum CommandResult rc = parse_uncolor(buf, s, err, true);
490 return rc;
491}
static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, struct Buffer *err, bool uncolor)
Parse an 'uncolor' command.
Definition: command.c:227
CommandResult
Error codes for command_t parse functions.
Definition: command.h:36
void curses_colors_dump(struct Buffer *buf)
Dump all the Curses colours.
Definition: debug.c:144
static int color_debug(enum LogLevel level, const char *format,...)
Definition: debug.h:53
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:77
+ 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 496 of file command.c.

498{
499 *s->dptr = '\0'; /* fake that we're done parsing */
500 return MUTT_CMD_SUCCESS;
501}

◆ 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 506 of file command.c.

508{
509 // No GUI, or no colours, so quietly discard the command
510 if (OptNoCurses || (COLORS == 0))
511 {
512 while (MoreArgs(s))
513 {
515 }
516 return MUTT_CMD_SUCCESS;
517 }
518
519 color_debug(LL_DEBUG5, "parse: %s\n", buf_string(buf));
520 enum CommandResult rc = parse_color(buf, s, err, parse_color_pair, true);
522 return rc;
523}
static enum CommandResult parse_color(struct Buffer *buf, struct Buffer *s, struct Buffer *err, parser_callback_t callback, bool color)
Parse a 'color' command.
Definition: command.c:319
enum CommandResult parse_color_pair(struct Buffer *buf, struct Buffer *s, struct AttrColor *ac, struct Buffer *err)
Parse a pair of colours - Implements parser_callback_t -.
Definition: parse_color.c:281
+ 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 528 of file command.c.

530{
531 // No GUI, or colours available, so quietly discard the command
532 if (OptNoCurses || (COLORS != 0))
533 {
534 while (MoreArgs(s))
535 {
537 }
538 return MUTT_CMD_SUCCESS;
539 }
540
541 color_debug(LL_DEBUG5, "parse: %s\n", buf_string(buf));
542 enum CommandResult rc = parse_color(buf, s, err, parse_attr_spec, false);
544 return rc;
545}
enum CommandResult parse_attr_spec(struct Buffer *buf, struct Buffer *s, struct AttrColor *ac, struct Buffer *err)
Parse an attribute description - Implements parser_callback_t -.
Definition: parse_color.c:325
+ 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 347 of file commands.c.

349{
351 buf_expand_path(buf);
352 if (buf_len(buf) == 0)
353 {
354 if (HomeDir)
355 {
356 buf_strcpy(buf, HomeDir);
357 }
358 else
359 {
360 buf_printf(err, _("%s: too few arguments"), "cd");
361 return MUTT_CMD_ERROR;
362 }
363 }
364
365 if (chdir(buf_string(buf)) != 0)
366 {
367 buf_printf(err, "cd: %s", strerror(errno));
368 return MUTT_CMD_ERROR;
369 }
370
371 return MUTT_CMD_SUCCESS;
372}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:466
char * HomeDir
User's home directory.
Definition: globals.c:39
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:329
+ 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 377 of file commands.c.

379{
380 if (!MoreArgs(s))
381 {
382 buf_printf(err, _("%s: too few arguments"), "echo");
383 return MUTT_CMD_WARNING;
384 }
386 OptForceRefresh = true;
387 mutt_message("%s", buf->data);
388 OptForceRefresh = false;
389 mutt_sleep(0);
390
391 return MUTT_CMD_SUCCESS;
392}
bool OptForceRefresh
(pseudo) refresh even during macros
Definition: globals.c:70
#define mutt_message(...)
Definition: logging2.h:91
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1418
+ 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 401 of file commands.c.

403{
404 if (MoreArgs(s))
405 {
406 buf_printf(err, _("%s: too many arguments"), "finish");
407 return MUTT_CMD_WARNING;
408 }
409
410 return MUTT_CMD_FINISH;
411}
@ 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 416 of file commands.c.

418{
419 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
420 enum GroupState gstate = GS_NONE;
421
422 do
423 {
425 if (parse_grouplist(&gl, buf, s, err) == -1)
426 goto bail;
427
428 if ((data == MUTT_UNGROUP) && mutt_istr_equal(buf->data, "*"))
429 {
431 goto out;
432 }
433
434 if (mutt_istr_equal(buf->data, "-rx"))
435 {
436 gstate = GS_RX;
437 }
438 else if (mutt_istr_equal(buf->data, "-addr"))
439 {
440 gstate = GS_ADDR;
441 }
442 else
443 {
444 switch (gstate)
445 {
446 case GS_NONE:
447 buf_printf(err, _("%sgroup: missing -rx or -addr"),
448 (data == MUTT_UNGROUP) ? "un" : "");
449 goto warn;
450
451 case GS_RX:
452 if ((data == MUTT_GROUP) &&
453 (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0))
454 {
455 goto bail;
456 }
457 else if ((data == MUTT_UNGROUP) &&
458 (mutt_grouplist_remove_regex(&gl, buf->data) < 0))
459 {
460 goto bail;
461 }
462 break;
463
464 case GS_ADDR:
465 {
466 char *estr = NULL;
467 struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
468 mutt_addrlist_parse2(&al, buf->data);
469 if (TAILQ_EMPTY(&al))
470 goto bail;
471 if (mutt_addrlist_to_intl(&al, &estr))
472 {
473 buf_printf(err, _("%sgroup: warning: bad IDN '%s'"),
474 (data == 1) ? "un" : "", estr);
476 FREE(&estr);
477 goto bail;
478 }
479 if (data == MUTT_GROUP)
481 else if (data == MUTT_UNGROUP)
484 break;
485 }
486 }
487 }
488 } while (MoreArgs(s));
489
490out:
492 return MUTT_CMD_SUCCESS;
493
494bail:
496 return MUTT_CMD_ERROR;
497
498warn:
500 return MUTT_CMD_WARNING;
501}
GroupState
Type of email address group.
Definition: commands.c:88
@ GS_RX
Entry is a regular expression.
Definition: commands.c:90
@ GS_NONE
Group is missing an argument.
Definition: commands.c:89
@ GS_ADDR
Entry is an address.
Definition: commands.c:91
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 516 of file commands.c.

518{
520
521 if (buf_is_empty(buf))
522 {
523 buf_printf(err, _("%s: too few arguments"), (data ? "ifndef" : "ifdef"));
524 return MUTT_CMD_WARNING;
525 }
526
527 // is the item defined as:
528 bool res = cs_subset_lookup(NeoMutt->sub, buf->data) // a variable?
529 || feature_enabled(buf->data) // a compiled-in feature?
530 || is_function(buf->data) // a function?
531 || command_get(buf->data) // a command?
532#ifdef USE_HCACHE
533 || store_is_valid_backend(buf->data) // a store? (database)
534#endif
535 || mutt_str_getenv(buf->data); // an environment variable?
536
537 if (!MoreArgs(s))
538 {
539 buf_printf(err, _("%s: too few arguments"), (data ? "ifndef" : "ifdef"));
540 return MUTT_CMD_WARNING;
541 }
543
544 /* ifdef KNOWN_SYMBOL or ifndef UNKNOWN_SYMBOL */
545 if ((res && (data == 0)) || (!res && (data == 1)))
546 {
547 enum CommandResult rc = parse_rc_line(buf->data, err);
548 if (rc == MUTT_CMD_ERROR)
549 {
550 mutt_error(_("Error: %s"), buf_string(err));
551 return MUTT_CMD_ERROR;
552 }
553 return rc;
554 }
555 return MUTT_CMD_SUCCESS;
556}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:303
static bool is_function(const char *name)
Is the argument a neomutt function?
Definition: commands.c:100
struct Command * command_get(const char *s)
Get a Command by its name.
Definition: command.c:87
#define mutt_error(...)
Definition: logging2.h:92
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:104
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:178
bool feature_enabled(const char *name)
Test if a compile-time feature is enabled.
Definition: version.c:546
+ 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 561 of file commands.c.

563{
564 do
565 {
568 add_to_stailq(&Ignore, buf->data);
569 } while (MoreArgs(s));
570
571 return MUTT_CMD_SUCCESS;
572}
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:1712
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: muttlib.c:1687
+ 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 577 of file commands.c.

579{
580 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
581
582 do
583 {
585
586 if (parse_grouplist(&gl, buf, s, err) == -1)
587 goto bail;
588
590
591 if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
592 goto bail;
593
594 if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
595 goto bail;
596 } while (MoreArgs(s));
597
599 return MUTT_CMD_SUCCESS;
600
601bail:
603 return MUTT_CMD_ERROR;
604}
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 712 of file commands.c.

714{
716
717 struct Buffer *label = buf_pool_get();
718 struct Buffer *mailbox = buf_pool_get();
719
720 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
721 while (MoreArgs(s))
722 {
723 bool label_set = false;
724 enum TriBool notify = TB_UNSET;
725 enum TriBool poll = TB_UNSET;
726
727 do
728 {
729 // Start by handling the options
731
732 if (mutt_str_equal(buf_string(buf), "-label"))
733 {
734 if (!MoreArgs(s))
735 {
736 buf_printf(err, _("%s: too few arguments"), "mailboxes -label");
737 goto done;
738 }
739
741 label_set = true;
742 }
743 else if (mutt_str_equal(buf_string(buf), "-nolabel"))
744 {
745 buf_reset(label);
746 label_set = true;
747 }
748 else if (mutt_str_equal(buf_string(buf), "-notify"))
749 {
750 notify = TB_TRUE;
751 }
752 else if (mutt_str_equal(buf_string(buf), "-nonotify"))
753 {
754 notify = TB_FALSE;
755 }
756 else if (mutt_str_equal(buf_string(buf), "-poll"))
757 {
758 poll = TB_TRUE;
759 }
760 else if (mutt_str_equal(buf_string(buf), "-nopoll"))
761 {
762 poll = TB_FALSE;
763 }
764 else if ((data & MUTT_NAMED) && !label_set)
765 {
766 if (!MoreArgs(s))
767 {
768 buf_printf(err, _("%s: too few arguments"), "named-mailboxes");
769 goto done;
770 }
771
772 buf_copy(label, buf);
773 label_set = true;
774 }
775 else
776 {
777 buf_copy(mailbox, buf);
778 break;
779 }
780 } while (MoreArgs(s));
781
782 if (buf_is_empty(mailbox))
783 {
784 buf_printf(err, _("%s: too few arguments"), "mailboxes");
785 goto done;
786 }
787
788 rc = mailbox_add(c_folder, buf_string(mailbox),
789 label_set ? buf_string(label) : NULL, poll, notify, err);
790 if (rc != MUTT_CMD_SUCCESS)
791 goto done;
792
793 buf_reset(label);
794 buf_reset(mailbox);
795 }
796
797 rc = MUTT_CMD_SUCCESS;
798
799done:
800 buf_pool_release(&label);
801 buf_pool_release(&mailbox);
802 return rc;
803}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:88
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:572
static enum CommandResult mailbox_add(const char *folder, const char *mailbox, const char *label, enum TriBool poll, enum TriBool notify, struct Buffer *err)
Add a new Mailbox.
Definition: commands.c:609
TriBool
Tri-state boolean.
Definition: commands.c:78
@ TB_FALSE
Value is false.
Definition: commands.c:80
@ TB_TRUE
Value is true.
Definition: commands.c:81
@ TB_UNSET
Value hasn't been set.
Definition: commands.c:79
#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:292
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
String manipulation buffer.
Definition: buffer.h:34
+ 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 808 of file commands.c.

810{
812 char *p = strpbrk(buf->data, ": \t");
813 if (!p || (*p != ':'))
814 {
815 buf_strcpy(err, _("invalid header field"));
816 return MUTT_CMD_WARNING;
817 }
818
819 struct EventHeader ev_h = { buf->data };
820 struct ListNode *n = header_find(&UserHeader, buf->data);
821
822 if (n)
823 {
824 header_update(n, buf->data);
825 mutt_debug(LL_NOTIFY, "NT_HEADER_CHANGE: %s\n", buf->data);
827 }
828 else
829 {
830 header_add(&UserHeader, buf->data);
831 mutt_debug(LL_NOTIFY, "NT_HEADER_ADD: %s\n", buf->data);
833 }
834
835 return MUTT_CMD_SUCCESS;
836}
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:176
@ NT_HEADER_ADD
Header has been added.
Definition: email.h:174
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:183
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 891 of file commands.c.

893{
894 char **envp = EnvList;
895
896 bool query = false;
897 bool prefix = false;
898 bool unset = (data == MUTT_SET_UNSET);
899
900 if (!MoreArgs(s))
901 {
902 if (!StartupComplete)
903 {
904 buf_printf(err, _("%s: too few arguments"), "setenv");
905 return MUTT_CMD_WARNING;
906 }
907
908 struct Buffer *tempfile = buf_pool_get();
909 buf_mktemp(tempfile);
910
911 FILE *fp_out = mutt_file_fopen(buf_string(tempfile), "w");
912 if (!fp_out)
913 {
914 // L10N: '%s' is the file name of the temporary file
915 buf_printf(err, _("Could not create temporary file %s"), buf_string(tempfile));
916 buf_pool_release(&tempfile);
917 return MUTT_CMD_ERROR;
918 }
919
920 int count = 0;
921 for (char **env = EnvList; *env; env++)
922 count++;
923
924 mutt_qsort_r(EnvList, count, sizeof(char *), envlist_sort, NULL);
925
926 for (char **env = EnvList; *env; env++)
927 fprintf(fp_out, "%s\n", *env);
928
929 mutt_file_fclose(&fp_out);
930
931 struct PagerData pdata = { 0 };
932 struct PagerView pview = { &pdata };
933
934 pdata.fname = buf_string(tempfile);
935
936 pview.banner = "setenv";
938 pview.mode = PAGER_MODE_OTHER;
939
940 mutt_do_pager(&pview, NULL);
941 buf_pool_release(&tempfile);
942
943 return MUTT_CMD_SUCCESS;
944 }
945
946 if (*s->dptr == '?')
947 {
948 query = true;
949 prefix = true;
950
951 if (unset)
952 {
953 buf_printf(err, _("Can't query a variable with the '%s' command"), "unsetenv");
954 return MUTT_CMD_WARNING;
955 }
956
957 s->dptr++;
958 }
959
960 /* get variable name */
962
963 if (*s->dptr == '?')
964 {
965 if (unset)
966 {
967 buf_printf(err, _("Can't query a variable with the '%s' command"), "unsetenv");
968 return MUTT_CMD_WARNING;
969 }
970
971 if (prefix)
972 {
973 buf_printf(err, _("Can't use a prefix when querying a variable"));
974 return MUTT_CMD_WARNING;
975 }
976
977 query = true;
978 s->dptr++;
979 }
980
981 if (query)
982 {
983 bool found = false;
984 while (envp && *envp)
985 {
986 /* This will display all matches for "^QUERY" */
987 if (mutt_str_startswith(*envp, buf->data))
988 {
989 if (!found)
990 {
991 mutt_endwin();
992 found = true;
993 }
994 puts(*envp);
995 }
996 envp++;
997 }
998
999 if (found)
1000 {
1002 return MUTT_CMD_SUCCESS;
1003 }
1004
1005 buf_printf(err, _("%s is unset"), buf->data);
1006 return MUTT_CMD_WARNING;
1007 }
1008
1009 if (unset)
1010 {
1011 if (!envlist_unset(&EnvList, buf->data))
1012 {
1013 buf_printf(err, _("%s is unset"), buf->data);
1014 return MUTT_CMD_WARNING;
1015 }
1016 return MUTT_CMD_SUCCESS;
1017 }
1018
1019 /* set variable */
1020
1021 if (*s->dptr == '=')
1022 {
1023 s->dptr++;
1024 SKIPWS(s->dptr);
1025 }
1026
1027 if (!MoreArgs(s))
1028 {
1029 buf_printf(err, _("%s: too few arguments"), "setenv");
1030 return MUTT_CMD_WARNING;
1031 }
1032
1033 char *name = mutt_str_dup(buf->data);
1035 envlist_set(&EnvList, name, buf->data, true);
1036 FREE(&name);
1037
1038 return MUTT_CMD_SUCCESS;
1039}
bool StartupComplete
When the config has been read.
Definition: main.c:188
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:46
#define TOKEN_QUESTION
Treat '?' as a special.
Definition: extract.h:55
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:636
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
char ** EnvList
Private copy of the environment variables.
Definition: globals.c:83
static int envlist_sort(const void *a, const void *b, void *sdata)
Compare two environment strings - Implements sort_t -.
Definition: commands.c:883
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:228
#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:141
@ MUTT_SET_UNSET
default is to unset all vars
Definition: set.h:38
void mutt_qsort_r(void *base, size_t nmemb, size_t size, sort_t compar, void *sdata)
Sort an array, where the comparator has access to opaque data rather than requiring global variables.
Definition: qsort_r.c:66
Data to be displayed by PagerView.
Definition: lib.h:160
const char * fname
Name of the file to read.
Definition: lib.h:164
Paged view into some data.
Definition: lib.h:171
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition: lib.h:172
enum PagerMode mode
Pager mode.
Definition: lib.h:173
PagerFlags flags
Additional settings to tweak pager's function.
Definition: lib.h:174
const char * banner
Title to display in status bar.
Definition: lib.h:175
#define buf_mktemp(buf)
Definition: tmp.h:33
+ 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 1044 of file commands.c.

1046{
1047 char path[PATH_MAX] = { 0 };
1048
1049 do
1050 {
1051 if (parse_extract_token(buf, s, TOKEN_NO_FLAGS) != 0)
1052 {
1053 buf_printf(err, _("source: error at %s"), s->dptr);
1054 return MUTT_CMD_ERROR;
1055 }
1056 mutt_str_copy(path, buf->data, sizeof(path));
1057 mutt_expand_path(path, sizeof(path));
1058
1059 if (source_rc(path, err) < 0)
1060 {
1061 buf_printf(err, _("source: file %s could not be sourced"), path);
1062 return MUTT_CMD_ERROR;
1063 }
1064
1065 } while (MoreArgs(s));
1066
1067 return MUTT_CMD_SUCCESS;
1068}
int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
Definition: commands.c:199
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
#define PATH_MAX
Definition: mutt.h:41
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_nospam()

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

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

Definition at line 1073 of file commands.c.

1075{
1076 if (!MoreArgs(s))
1077 {
1078 buf_printf(err, _("%s: too few arguments"), "nospam");
1079 return MUTT_CMD_ERROR;
1080 }
1081
1082 // Extract the first token, a regex or "*"
1084
1085 if (MoreArgs(s))
1086 {
1087 buf_printf(err, _("%s: too many arguments"), "finish");
1088 return MUTT_CMD_ERROR;
1089 }
1090
1091 // "*" is special - clear both spam and nospam lists
1092 if (mutt_str_equal(buf_string(buf), "*"))
1093 {
1096 return MUTT_CMD_SUCCESS;
1097 }
1098
1099 // If it's on the spam list, just remove it
1101 return MUTT_CMD_SUCCESS;
1102
1103 // Otherwise, add it to the nospam list
1104 if (mutt_regexlist_add(&NoSpamList, buf_string(buf), REG_ICASE, err) != 0)
1105 return MUTT_CMD_ERROR;
1106
1107 return MUTT_CMD_SUCCESS;
1108}
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:588
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:175
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:472
+ Here is the call graph for this function:

◆ parse_spam()

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

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

Definition at line 1113 of file commands.c.

1115{
1116 if (!MoreArgs(s))
1117 {
1118 buf_printf(err, _("%s: too few arguments"), "spam");
1119 return MUTT_CMD_ERROR;
1120 }
1121
1122 // Extract the first token, a regex
1124
1125 // If there's a second parameter, it's a template for the spam tag
1126 if (MoreArgs(s))
1127 {
1128 struct Buffer *templ = buf_pool_get();
1130
1131 // Add to the spam list
1132 int rc = mutt_replacelist_add(&SpamList, buf_string(buf), buf_string(templ), err);
1133 buf_pool_release(&templ);
1134 if (rc != 0)
1135 return MUTT_CMD_ERROR;
1136 }
1137 else
1138 {
1139 // If not, try to remove from the nospam list
1141 }
1142
1143 return MUTT_CMD_SUCCESS;
1144}
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:267
+ 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 1151 of file commands.c.

1153{
1154 do
1155 {
1157 add_to_stailq((struct ListHead *) data, buf->data);
1158 } while (MoreArgs(s));
1159
1160 return MUTT_CMD_SUCCESS;
1161}
+ 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 1166 of file commands.c.

1168{
1169 struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1170
1171 do
1172 {
1174
1175 if (parse_grouplist(&gl, buf, s, err) == -1)
1176 goto bail;
1177
1180
1181 if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
1182 goto bail;
1183 if (mutt_regexlist_add(&SubscribedLists, buf->data, REG_ICASE, err) != 0)
1184 goto bail;
1185 if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
1186 goto bail;
1187 } while (MoreArgs(s));
1188
1190 return MUTT_CMD_SUCCESS;
1191
1192bail:
1194 return MUTT_CMD_ERROR;
1195}
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 1204 of file commands.c.

1206{
1207 if (!buf || !s || !err)
1208 return MUTT_CMD_ERROR;
1209
1210 buf_reset(err);
1211
1212 if (MoreArgs(s))
1213 {
1215
1216 if (MoreArgs(s))
1217 {
1218 buf_printf(err, _("%s: too many arguments"), "subscribe-to");
1219 return MUTT_CMD_WARNING;
1220 }
1221
1222 if (!buf_is_empty(buf))
1223 {
1224 /* Expand and subscribe */
1225 if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), true) == 0)
1226 {
1227 mutt_message(_("Subscribed to %s"), buf->data);
1228 return MUTT_CMD_SUCCESS;
1229 }
1230
1231 buf_printf(err, _("Could not subscribe to %s"), buf->data);
1232 return MUTT_CMD_ERROR;
1233 }
1234
1235 mutt_debug(LL_DEBUG1, "Corrupted buffer");
1236 return MUTT_CMD_ERROR;
1237 }
1238
1239 buf_addstr(err, _("No folder specified"));
1240 return MUTT_CMD_WARNING;
1241}
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:238
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1210
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
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 1250 of file commands.c.

1252{
1253 if (!s)
1254 return MUTT_CMD_ERROR;
1255
1256 struct Buffer *tagbuf = buf_pool_get();
1257 struct Buffer *fmtbuf = buf_pool_get();
1258
1259 while (MoreArgs(s))
1260 {
1262 const char *tag = buf_string(tagbuf);
1263 if (*tag == '\0')
1264 continue;
1265
1267 const char *fmt = buf_string(fmtbuf);
1268
1269 /* avoid duplicates */
1270 const char *tmp = mutt_hash_find(TagFormats, fmt);
1271 if (tmp)
1272 {
1273 mutt_warning(_("tag format '%s' already registered as '%s'"), fmt, tmp);
1274 continue;
1275 }
1276
1278 }
1279
1280 buf_pool_release(&tagbuf);
1281 buf_pool_release(&fmtbuf);
1282 return MUTT_CMD_SUCCESS;
1283}
#define mutt_warning(...)
Definition: logging2.h:90
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 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 1292 of file commands.c.

1294{
1295 if (!s)
1296 return MUTT_CMD_ERROR;
1297
1298 struct Buffer *tagbuf = buf_pool_get();
1299 struct Buffer *trnbuf = buf_pool_get();
1300
1301 while (MoreArgs(s))
1302 {
1304 const char *tag = buf_string(tagbuf);
1305 if (*tag == '\0')
1306 continue;
1307
1309 const char *trn = buf_string(trnbuf);
1310
1311 /* avoid duplicates */
1312 const char *tmp = mutt_hash_find(TagTransforms, tag);
1313 if (tmp)
1314 {
1315 mutt_warning(_("tag transform '%s' already registered as '%s'"), tag, tmp);
1316 continue;
1317 }
1318
1320 }
1321
1322 buf_pool_release(&tagbuf);
1323 buf_pool_release(&trnbuf);
1324 return MUTT_CMD_SUCCESS;
1325}
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 1330 of file commands.c.

1332{
1333 do
1334 {
1336
1337 /* don't add "*" to the unignore list */
1338 if (!mutt_str_equal(buf->data, "*"))
1339 add_to_stailq(&UnIgnore, buf->data);
1340
1342 } while (MoreArgs(s));
1343
1344 return MUTT_CMD_SUCCESS;
1345}
+ 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 1350 of file commands.c.

1352{
1354 do
1355 {
1359
1360 if (!mutt_str_equal(buf->data, "*") &&
1361 (mutt_regexlist_add(&UnMailLists, buf->data, REG_ICASE, err) != 0))
1362 {
1363 return MUTT_CMD_ERROR;
1364 }
1365 } while (MoreArgs(s));
1366
1367 return MUTT_CMD_SUCCESS;
1368}
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 1416 of file commands.c.

1418{
1419 while (MoreArgs(s))
1420 {
1422
1423 if (mutt_str_equal(buf->data, "*"))
1424 {
1426 return MUTT_CMD_SUCCESS;
1427 }
1428
1429 buf_expand_path(buf);
1430
1431 struct Account *a = NULL;
1432 TAILQ_FOREACH(a, &NeoMutt->accounts, entries)
1433 {
1434 struct Mailbox *m = mx_mbox_find(a, buf_string(buf));
1435 if (m)
1436 {
1437 do_unmailboxes(m);
1438 break;
1439 }
1440 }
1441 }
1442 return MUTT_CMD_SUCCESS;
1443}
static void do_unmailboxes_star(void)
Remove all Mailboxes from the Sidebar/notifications.
Definition: commands.c:1398
static void do_unmailboxes(struct Mailbox *m)
Remove a Mailbox from the Sidebar/notifications.
Definition: commands.c:1374
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1559
A group of associated Mailboxes.
Definition: account.h:37
A mailbox.
Definition: mailbox.h:79
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:46
+ 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 1448 of file commands.c.

1450{
1451 struct ListNode *np = NULL, *tmp = NULL;
1452 size_t l;
1453
1454 do
1455 {
1457 if (mutt_str_equal("*", buf->data))
1458 {
1459 /* Clear all headers, send a notification for each header */
1460 STAILQ_FOREACH(np, &UserHeader, entries)
1461 {
1462 mutt_debug(LL_NOTIFY, "NT_HEADER_DELETE: %s\n", np->data);
1463 struct EventHeader ev_h = { np->data };
1465 }
1467 continue;
1468 }
1469
1470 l = mutt_str_len(buf->data);
1471 if (buf->data[l - 1] == ':')
1472 l--;
1473
1474 STAILQ_FOREACH_SAFE(np, &UserHeader, entries, tmp)
1475 {
1476 if (mutt_istrn_equal(buf->data, np->data, l) && (np->data[l] == ':'))
1477 {
1478 mutt_debug(LL_NOTIFY, "NT_HEADER_DELETE: %s\n", np->data);
1479 struct EventHeader ev_h = { np->data };
1481
1482 header_free(&UserHeader, np);
1483 }
1484 }
1485 } while (MoreArgs(s));
1486 return MUTT_CMD_SUCCESS;
1487}
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:175
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 1494 of file commands.c.

1496{
1497 do
1498 {
1500 /* Check for deletion of entire list */
1501 if (mutt_str_equal(buf->data, "*"))
1502 {
1503 mutt_list_free((struct ListHead *) data);
1504 break;
1505 }
1506 remove_from_stailq((struct ListHead *) data, buf->data);
1507 } while (MoreArgs(s));
1508
1509 return MUTT_CMD_SUCCESS;
1510}
+ 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 1515 of file commands.c.

1517{
1519 do
1520 {
1523
1524 if (!mutt_str_equal(buf->data, "*") &&
1525 (mutt_regexlist_add(&UnSubscribedLists, buf->data, REG_ICASE, err) != 0))
1526 {
1527 return MUTT_CMD_ERROR;
1528 }
1529 } while (MoreArgs(s));
1530
1531 return MUTT_CMD_SUCCESS;
1532}
+ 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 1541 of file commands.c.

1543{
1544 if (!buf || !s || !err)
1545 return MUTT_CMD_ERROR;
1546
1547 if (MoreArgs(s))
1548 {
1550
1551 if (MoreArgs(s))
1552 {
1553 buf_printf(err, _("%s: too many arguments"), "unsubscribe-from");
1554 return MUTT_CMD_WARNING;
1555 }
1556
1557 if (buf->data && (*buf->data != '\0'))
1558 {
1559 /* Expand and subscribe */
1560 if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), false) == 0)
1561 {
1562 mutt_message(_("Unsubscribed from %s"), buf->data);
1563 return MUTT_CMD_SUCCESS;
1564 }
1565
1566 buf_printf(err, _("Could not unsubscribe from %s"), buf->data);
1567 return MUTT_CMD_ERROR;
1568 }
1569
1570 mutt_debug(LL_DEBUG1, "Corrupted buffer");
1571 return MUTT_CMD_ERROR;
1572 }
1573
1574 buf_addstr(err, _("No folder specified"));
1575 return MUTT_CMD_WARNING;
1576}
+ 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 1581 of file commands.c.

1583{
1584 // silently ignore 'version' if it's in a config file
1585 if (!StartupComplete)
1586 return MUTT_CMD_SUCCESS;
1587
1588 struct Buffer *tempfile = buf_pool_get();
1589 buf_mktemp(tempfile);
1590
1591 FILE *fp_out = mutt_file_fopen(buf_string(tempfile), "w");
1592 if (!fp_out)
1593 {
1594 // L10N: '%s' is the file name of the temporary file
1595 buf_printf(err, _("Could not create temporary file %s"), buf_string(tempfile));
1596 buf_pool_release(&tempfile);
1597 return MUTT_CMD_ERROR;
1598 }
1599
1600 print_version(fp_out);
1601 mutt_file_fclose(&fp_out);
1602
1603 struct PagerData pdata = { 0 };
1604 struct PagerView pview = { &pdata };
1605
1606 pdata.fname = buf_string(tempfile);
1607
1608 pview.banner = "version";
1609 pview.flags = MUTT_PAGER_NO_FLAGS;
1610 pview.mode = PAGER_MODE_OTHER;
1611
1612 mutt_do_pager(&pview, NULL);
1613 buf_pool_release(&tempfile);
1614
1615 return MUTT_CMD_SUCCESS;
1616}
bool print_version(FILE *fp)
Print system and compile info to a file.
Definition: version.c:394
+ 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 114 of file hook.c.

116{
117 struct Buffer *alias = buf_pool_get();
118 struct Buffer *charset = buf_pool_get();
119
120 int rc = MUTT_CMD_ERROR;
121
122 if (parse_extract_token(alias, s, TOKEN_NO_FLAGS) < 0)
123 goto done;
124 if (parse_extract_token(charset, s, TOKEN_NO_FLAGS) < 0)
125 goto done;
126
128
129 if (buf_is_empty(alias) || buf_is_empty(charset))
130 {
131 buf_printf(err, _("%s: too few arguments"), buf->data);
132 rc = MUTT_CMD_WARNING;
133 }
134 else if (MoreArgs(s))
135 {
136 buf_printf(err, _("%s: too many arguments"), buf->data);
137 buf_reset(s); // clean up buffer to avoid a mess with further rcfile processing
138 rc = MUTT_CMD_WARNING;
139 }
140 else if (mutt_ch_lookup_add(type, buf_string(alias), buf_string(charset), err))
141 {
142 rc = MUTT_CMD_SUCCESS;
143 }
144
145done:
146 buf_pool_release(&alias);
147 buf_pool_release(&charset);
148
149 return rc;
150}
#define MUTT_ICONV_HOOK
iconv-hook: create a system charset alias
Definition: hook.h:43
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:504
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 157 of file hook.c.

159{
160 struct Hook *hook = NULL;
161 int rc = MUTT_CMD_ERROR;
162 bool pat_not = false;
163 bool use_regex = true;
164 regex_t *rx = NULL;
165 struct PatternList *pat = NULL;
166 const bool folder_or_mbox = (data & (MUTT_FOLDER_HOOK | MUTT_MBOX_HOOK));
167
168 struct Buffer *cmd = buf_pool_get();
169 struct Buffer *pattern = buf_pool_get();
170
171 if (~data & MUTT_GLOBAL_HOOK) /* NOT a global hook */
172 {
173 if (*s->dptr == '!')
174 {
175 s->dptr++;
176 SKIPWS(s->dptr);
177 pat_not = true;
178 }
179
181 if (folder_or_mbox && mutt_str_equal(buf_string(pattern), "-noregex"))
182 {
183 use_regex = false;
184 if (!MoreArgs(s))
185 {
186 buf_printf(err, _("%s: too few arguments"), buf->data);
187 rc = MUTT_CMD_WARNING;
188 goto cleanup;
189 }
191 }
192
193 if (!MoreArgs(s))
194 {
195 buf_printf(err, _("%s: too few arguments"), buf->data);
196 rc = MUTT_CMD_WARNING;
197 goto cleanup;
198 }
199 }
200
201 parse_extract_token(cmd, s,
206
207 if (buf_is_empty(cmd))
208 {
209 buf_printf(err, _("%s: too few arguments"), buf->data);
210 rc = MUTT_CMD_WARNING;
211 goto cleanup;
212 }
213
214 if (MoreArgs(s))
215 {
216 buf_printf(err, _("%s: too many arguments"), buf->data);
217 rc = MUTT_CMD_WARNING;
218 goto cleanup;
219 }
220
221 const char *const c_default_hook = cs_subset_string(NeoMutt->sub, "default_hook");
222 if (folder_or_mbox)
223 {
224 /* Accidentally using the ^ mailbox shortcut in the .neomuttrc is a
225 * common mistake */
226 if ((pattern->data[0] == '^') && !CurrentFolder)
227 {
228 buf_strcpy(err, _("current mailbox shortcut '^' is unset"));
229 goto cleanup;
230 }
231
232 struct Buffer *tmp = buf_pool_get();
233 buf_copy(tmp, pattern);
234 buf_expand_path_regex(tmp, use_regex);
235
236 /* Check for other mailbox shortcuts that expand to the empty string.
237 * This is likely a mistake too */
238 if (buf_is_empty(tmp) && !buf_is_empty(pattern))
239 {
240 buf_strcpy(err, _("mailbox shortcut expanded to empty regex"));
241 buf_pool_release(&tmp);
242 goto cleanup;
243 }
244
245 if (use_regex)
246 {
247 buf_copy(pattern, tmp);
248 }
249 else
250 {
252 }
253 buf_pool_release(&tmp);
254 }
256 {
257 if (mutt_comp_valid_command(buf_string(cmd)) == 0)
258 {
259 buf_strcpy(err, _("badly formatted command string"));
260 goto cleanup;
261 }
262 }
263 else if (c_default_hook && (~data & MUTT_GLOBAL_HOOK) &&
265 {
266 /* At this stage only these hooks remain:
267 * fcc-, fcc-save-, index-format-, message-, reply-, save-, send- and send2-hook
268 * If given a plain string, or regex, we expand it using $default_hook. */
269 mutt_check_simple(pattern, c_default_hook);
270 }
271
273 {
274 buf_expand_path(cmd);
275 }
276
277 /* check to make sure that a matching hook doesn't already exist */
278 TAILQ_FOREACH(hook, &Hooks, entries)
279 {
281 {
282 /* Ignore duplicate global hooks */
283 if (mutt_str_equal(hook->command, buf_string(cmd)))
284 {
285 rc = MUTT_CMD_SUCCESS;
286 goto cleanup;
287 }
288 }
289 else if ((hook->type == data) && (hook->regex.pat_not == pat_not) &&
290 mutt_str_equal(buf_string(pattern), hook->regex.pattern))
291 {
295 {
296 /* these hooks allow multiple commands with the same
297 * pattern, so if we've already seen this pattern/command pair, just
298 * ignore it instead of creating a duplicate */
299 if (mutt_str_equal(hook->command, buf_string(cmd)))
300 {
301 rc = MUTT_CMD_SUCCESS;
302 goto cleanup;
303 }
304 }
305 else
306 {
307 /* other hooks only allow one command per pattern, so update the
308 * entry with the new command. this currently does not change the
309 * order of execution of the hooks, which i think is desirable since
310 * a common action to perform is to change the default (.) entry
311 * based upon some other information. */
312 FREE(&hook->command);
313 hook->command = buf_strdup(cmd);
315 rc = MUTT_CMD_SUCCESS;
316 goto cleanup;
317 }
318 }
319 }
320
323 {
324 PatternCompFlags comp_flags;
325
326 if (data & (MUTT_SEND2_HOOK))
327 comp_flags = MUTT_PC_SEND_MODE_SEARCH;
328 else if (data & (MUTT_SEND_HOOK | MUTT_FCC_HOOK))
329 comp_flags = MUTT_PC_NO_FLAGS;
330 else
331 comp_flags = MUTT_PC_FULL_MSG;
332
333 struct MailboxView *mv_cur = get_current_mailbox_view();
334 struct Menu *menu = get_current_menu();
335 pat = mutt_pattern_comp(mv_cur, menu, buf_string(pattern), comp_flags, err);
336 if (!pat)
337 goto cleanup;
338 }
339 else if (~data & MUTT_GLOBAL_HOOK) /* NOT a global hook */
340 {
341 /* Hooks not allowing full patterns: Check syntax of regex */
342 rx = mutt_mem_calloc(1, sizeof(regex_t));
343 int rc2 = REG_COMP(rx, buf_string(pattern), ((data & MUTT_CRYPT_HOOK) ? REG_ICASE : 0));
344 if (rc2 != 0)
345 {
346 regerror(rc2, rx, err->data, err->dsize);
347 FREE(&rx);
348 goto cleanup;
349 }
350 }
351
352 hook = hook_new();
353 hook->type = data;
354 hook->command = buf_strdup(cmd);
356 hook->pattern = pat;
357 hook->regex.pattern = buf_strdup(pattern);
358 hook->regex.regex = rx;
359 hook->regex.pat_not = pat_not;
360 TAILQ_INSERT_TAIL(&Hooks, hook, entries);
361 rc = MUTT_CMD_SUCCESS;
362
363cleanup:
364 buf_pool_release(&cmd);
365 buf_pool_release(&pattern);
366 return rc;
367}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:542
char * mutt_get_sourced_cwd(void)
Get the current file path that is being parsed.
Definition: commands.c:178
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:416
int mutt_file_sanitize_regex(struct Buffer *dest, const char *src)
Escape any regex-magic characters in a string.
Definition: file.c:709
char * CurrentFolder
Currently selected mailbox.
Definition: globals.c:44
static struct HookList Hooks
All simple hooks, e.g. MUTT_FOLDER_HOOK.
Definition: hook.c:71
static struct Hook * hook_new(void)
Create a Hook.
Definition: hook.c:106
#define MUTT_OPEN_HOOK
open-hook: to read a compressed mailbox
Definition: hook.h:49
#define MUTT_FOLDER_HOOK
folder-hook: when entering a mailbox
Definition: hook.h:37
#define MUTT_SAVE_HOOK
save-hook: set a default folder when saving an email
Definition: hook.h:41
#define MUTT_SEND_HOOK
send-hook: when composing a new email
Definition: hook.h:39
#define MUTT_FCC_HOOK
fcc-hook: to save outgoing email
Definition: hook.h:40
#define MUTT_CLOSE_HOOK
close-hook: write to a compressed mailbox
Definition: hook.h:51
#define MUTT_ACCOUNT_HOOK
account-hook: when changing between accounts
Definition: hook.h:46
#define MUTT_APPEND_HOOK
append-hook: append to a compressed mailbox
Definition: hook.h:50
#define MUTT_GLOBAL_HOOK
Hooks which don't take a regex.
Definition: hook.h:56
#define MUTT_STARTUP_HOOK
startup-hook: run when starting NeoMutt
Definition: hook.h:54
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:48
#define MUTT_CRYPT_HOOK
crypt-hook: automatically select a PGP/SMIME key
Definition: hook.h:45
#define MUTT_MBOX_HOOK
mbox-hook: move messages after reading them
Definition: hook.h:38
#define MUTT_REPLY_HOOK
reply-hook: when replying to an email
Definition: hook.h:47
#define MUTT_TIMEOUT_HOOK
timeout-hook: run a command periodically
Definition: hook.h:53
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:44
#define MUTT_SHUTDOWN_HOOK
shutdown-hook: run when leaving NeoMutt
Definition: hook.h:55
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:117
#define MUTT_PC_SEND_MODE_SEARCH
Allow send-mode body searching.
Definition: lib.h:71
uint8_t PatternCompFlags
Flags for mutt_pattern_comp(), e.g. MUTT_PC_FULL_MSG.
Definition: lib.h:67
#define MUTT_PC_FULL_MSG
Enable body and header matching.
Definition: lib.h:69
void mutt_check_simple(struct Buffer *s, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:111
#define MUTT_PC_NO_FLAGS
No flags are set.
Definition: lib.h:68
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:53
A list of user hooks.
Definition: hook.c:60
HookFlags type
Hook type.
Definition: hook.c:61
struct PatternList * pattern
Used for fcc,save,send-hook.
Definition: hook.c:65
struct Regex regex
Regular expression.
Definition: hook.c:62
char * command
Filename, command or pattern to execute.
Definition: hook.c:63
char * source_file
Used for relative-directory source.
Definition: hook.c:64
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 419 of file hook.c.

421{
423 bool pat_not = false;
424
425 struct Buffer *name = buf_pool_get();
426 struct Buffer *pattern = buf_pool_get();
427 struct Buffer *fmtstring = buf_pool_get();
428
429 if (!IdxFmtHooks)
430 {
433 }
434
435 if (!MoreArgs(s))
436 {
437 buf_printf(err, _("%s: too few arguments"), buf->data);
438 goto out;
439 }
441 struct HookList *hl = mutt_hash_find(IdxFmtHooks, buf_string(name));
442
443 if (*s->dptr == '!')
444 {
445 s->dptr++;
446 SKIPWS(s->dptr);
447 pat_not = true;
448 }
450
451 if (!MoreArgs(s))
452 {
453 buf_printf(err, _("%s: too few arguments"), buf->data);
454 goto out;
455 }
456 parse_extract_token(fmtstring, s, TOKEN_NO_FLAGS);
457
458 if (MoreArgs(s))
459 {
460 buf_printf(err, _("%s: too many arguments"), buf->data);
461 goto out;
462 }
463
464 const char *const c_default_hook = cs_subset_string(NeoMutt->sub, "default_hook");
465 if (c_default_hook)
466 mutt_check_simple(pattern, c_default_hook);
467
468 /* check to make sure that a matching hook doesn't already exist */
469 struct Hook *hook = NULL;
470 if (hl)
471 {
472 TAILQ_FOREACH(hook, hl, entries)
473 {
474 if ((hook->regex.pat_not == pat_not) &&
476 {
477 mutt_str_replace(&hook->command, buf_string(fmtstring));
478 rc = MUTT_CMD_SUCCESS;
479 goto out;
480 }
481 }
482 }
483
484 /* MUTT_PC_PATTERN_DYNAMIC sets so that date ranges are regenerated during
485 * matching. This of course is slower, but index-format-hook is commonly
486 * used for date ranges, and they need to be evaluated relative to "now", not
487 * the hook compilation time. */
488 struct MailboxView *mv_cur = get_current_mailbox_view();
489 struct Menu *menu = get_current_menu();
490 struct PatternList *pat = mutt_pattern_comp(mv_cur, menu, buf_string(pattern),
492 err);
493 if (!pat)
494 goto out;
495
496 hook = hook_new();
497 hook->type = MUTT_IDXFMTHOOK;
498 hook->command = buf_strdup(fmtstring);
500 hook->pattern = pat;
501 hook->regex.pattern = buf_strdup(pattern);
502 hook->regex.regex = NULL;
503 hook->regex.pat_not = pat_not;
504
505 if (!hl)
506 {
507 hl = mutt_mem_calloc(1, sizeof(*hl));
508 TAILQ_INIT(hl);
510 }
511
512 TAILQ_INSERT_TAIL(hl, hook, entries);
513 rc = MUTT_CMD_SUCCESS;
514
515out:
516 buf_pool_release(&name);
517 buf_pool_release(&pattern);
518 buf_pool_release(&fmtstring);
519
520 return rc;
521}
static void idxfmt_hashelem_free(int type, void *obj, intptr_t data)
Free our hash table data - Implements hash_hdata_free_t -.
Definition: hook.c:393
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:74
#define MUTT_IDXFMTHOOK
index-format-hook: customise the format of the index
Definition: hook.h:52
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:327
#define MUTT_PC_PATTERN_DYNAMIC
Enable runtime date range evaluation.
Definition: lib.h:70
#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 546 of file hook.c.

548{
549 while (MoreArgs(s))
550 {
552 if (mutt_str_equal("*", buf->data))
553 {
555 {
556 buf_addstr(err, _("unhook: Can't do unhook * from within a hook"));
557 return MUTT_CMD_WARNING;
558 }
562 }
563 else
564 {
565 HookFlags type = mutt_get_hook_type(buf->data);
566
567 if (type == MUTT_HOOK_NO_FLAGS)
568 {
569 buf_printf(err, _("unhook: unknown hook type: %s"), buf->data);
570 return MUTT_CMD_ERROR;
571 }
572 if (type & (MUTT_CHARSET_HOOK | MUTT_ICONV_HOOK))
573 {
575 return MUTT_CMD_SUCCESS;
576 }
577 if (CurrentHookType == type)
578 {
579 buf_printf(err, _("unhook: Can't delete a %s from within a %s"),
580 buf->data, buf->data);
581 return MUTT_CMD_WARNING;
582 }
583 if (type == MUTT_IDXFMTHOOK)
585 else
586 mutt_delete_hooks(type);
587 }
588 }
589 return MUTT_CMD_SUCCESS;
590}
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
Definition: hook.c:375
static void delete_idxfmt_hooks(void)
Delete all the index-format-hooks.
Definition: hook.c:411
static HookFlags mutt_get_hook_type(const char *name)
Find a hook by name.
Definition: hook.c:529
static HookFlags CurrentHookType
The type of the hook currently being executed, e.g. MUTT_SAVE_HOOK.
Definition: hook.c:77
uint32_t HookFlags
Flags for mutt_parse_hook(), e.g. MUTT_FOLDER_HOOK.
Definition: hook.h:35
#define MUTT_CHARSET_HOOK
charset-hook: create a charset alias for malformed emails
Definition: hook.h:42
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:36
void mutt_ch_lookup_remove(void)
Remove all the character set lookups.
Definition: charset.c:536
+ Here is the call graph for this function:

◆ dump_bind_macro()

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

Parse 'bind' and 'macro' commands - Implements Command::parse() -.

Definition at line 171 of file dump.c.

173{
174 FILE *fp_out = NULL;
175 bool dump_all = false, bind = (data == 0);
176
177 if (!MoreArgs(s))
178 dump_all = true;
179 else
181
182 if (MoreArgs(s))
183 {
184 /* More arguments potentially means the user is using the
185 * ::command_t :bind command thus we delegate the task. */
186 return MUTT_CMD_ERROR;
187 }
188
189 struct Buffer filebuf = buf_make(4096);
190 if (dump_all || mutt_istr_equal(buf_string(buf), "all"))
191 {
192 if (bind)
193 dump_all_binds(&filebuf);
194 else
195 dump_all_macros(&filebuf);
196 }
197 else
198 {
199 const int menu_index = mutt_map_get_value(buf_string(buf), MenuNames);
200 if (menu_index == -1)
201 {
202 // L10N: '%s' is the (misspelled) name of the menu, e.g. 'index' or 'pager'
203 buf_printf(err, _("%s: no such menu"), buf_string(buf));
204 buf_dealloc(&filebuf);
205 return MUTT_CMD_ERROR;
206 }
207
208 if (bind)
209 dump_bind(&filebuf, menu_index, buf_string(buf));
210 else
211 dump_macro(&filebuf, menu_index, buf_string(buf));
212 }
213
214 if (buf_is_empty(&filebuf))
215 {
216 // L10N: '%s' is the name of the menu, e.g. 'index' or 'pager',
217 // it might also be 'all' when all menus are affected.
218 buf_printf(err, bind ? _("%s: no binds for this menu") : _("%s: no macros for this menu"),
219 dump_all ? "all" : buf_string(buf));
220 buf_dealloc(&filebuf);
221 return MUTT_CMD_ERROR;
222 }
223
224 struct Buffer *tempfile = buf_pool_get();
225 buf_mktemp(tempfile);
226 fp_out = mutt_file_fopen(buf_string(tempfile), "w");
227 if (!fp_out)
228 {
229 // L10N: '%s' is the file name of the temporary file
230 buf_printf(err, _("Could not create temporary file %s"), buf_string(tempfile));
231 buf_dealloc(&filebuf);
232 buf_pool_release(&tempfile);
233 return MUTT_CMD_ERROR;
234 }
235 fputs(filebuf.data, fp_out);
236
237 mutt_file_fclose(&fp_out);
238 buf_dealloc(&filebuf);
239
240 struct PagerData pdata = { 0 };
241 struct PagerView pview = { &pdata };
242
243 pdata.fname = buf_string(tempfile);
244
245 pview.banner = (bind) ? "bind" : "macro";
247 pview.mode = PAGER_MODE_OTHER;
248
249 mutt_do_pager(&pview, NULL);
250 buf_pool_release(&tempfile);
251
252 return MUTT_CMD_SUCCESS;
253}
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:389
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:70
static void dump_all_macros(struct Buffer *buf)
Dumps all the macros inside every menu.
Definition: dump.c:156
static void dump_all_binds(struct Buffer *buf)
Dumps all the binds inside every menu.
Definition: dump.c:99
static bool dump_bind(struct Buffer *buf, enum MenuType menu, const char *name)
Dumps all the binds maps of a menu into a buffer.
Definition: dump.c:50
static bool dump_macro(struct Buffer *buf, enum MenuType menu, const char *name)
Dumps all the macros maps of a menu into a buffer.
Definition: dump.c:119
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:37
+ Here is the call graph for this function:
+ Here is the caller 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 344 of file parse.c.

346{
348 if (MoreArgs(s))
349 {
350 buf_printf(err, _("%s: too many arguments"), "push");
351 return MUTT_CMD_ERROR;
352 }
353
355 return MUTT_CMD_SUCCESS;
356}
#define TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: extract.h:47
void generic_tokenize_push_string(char *s)
Parse and queue a 'push' command.
Definition: lib.c:342
+ 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 363 of file parse.c.

365{
366 if (StartupComplete)
367 {
368 // Save and restore the offset in `s` because dump_bind_macro() might change it
369 char *dptr = s->dptr;
370 if (dump_bind_macro(buf, s, data, err) == MUTT_CMD_SUCCESS)
371 return MUTT_CMD_SUCCESS;
372 if (!buf_is_empty(err))
373 return MUTT_CMD_ERROR;
374 s->dptr = dptr;
375 }
376
377 const struct MenuFuncOp *funcs = NULL;
378 enum MenuType mtypes[MenuNamesLen];
379 int num_menus = 0;
381
382 char *key = parse_keymap(mtypes, s, mutt_array_size(mtypes), &num_menus, err, true);
383 if (!key)
384 return MUTT_CMD_ERROR;
385
386 /* function to execute */
388 if (MoreArgs(s))
389 {
390 buf_printf(err, _("%s: too many arguments"), "bind");
391 rc = MUTT_CMD_ERROR;
392 }
393 else if (mutt_istr_equal("noop", buf->data))
394 {
395 for (int i = 0; i < num_menus; i++)
396 {
397 km_bindkey(key, mtypes[i], OP_NULL); /* the 'unbind' command */
398 funcs = km_get_table(mtypes[i]);
399 if (funcs)
400 {
401 char keystr[32] = { 0 };
402 km_expand_key_string(key, keystr, sizeof(keystr));
403 const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
404 mutt_debug(LL_NOTIFY, "NT_BINDING_DELETE: %s %s\n", mname, keystr);
405
406 int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
407 struct EventBinding ev_b = { mtypes[i], key, op };
409 }
410 }
411 }
412 else
413 {
414 for (int i = 0; i < num_menus; i++)
415 {
416 /* The pager and editor menus don't use the generic map,
417 * however for other menus try generic first. */
418 if ((mtypes[i] != MENU_PAGER) && (mtypes[i] != MENU_EDITOR) && (mtypes[i] != MENU_GENERIC))
419 {
420 rc = try_bind(key, mtypes[i], buf->data, OpGeneric, err);
421 if (rc == MUTT_CMD_SUCCESS)
422 {
423 char keystr[32] = { 0 };
424 km_expand_key_string(key, keystr, sizeof(keystr));
425 const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
426 mutt_debug(LL_NOTIFY, "NT_BINDING_NEW: %s %s\n", mname, keystr);
427
428 int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
429 struct EventBinding ev_b = { mtypes[i], key, op };
431 continue;
432 }
433 if (rc == MUTT_CMD_WARNING)
434 break;
435 }
436
437 /* Clear any error message, we're going to try again */
438 err->data[0] = '\0';
439 funcs = km_get_table(mtypes[i]);
440 if (funcs)
441 {
442 rc = try_bind(key, mtypes[i], buf->data, funcs, err);
443 if (rc == MUTT_CMD_SUCCESS)
444 {
445 char keystr[32] = { 0 };
446 km_expand_key_string(key, keystr, sizeof(keystr));
447 const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
448 mutt_debug(LL_NOTIFY, "NT_BINDING_NEW: %s %s\n", mname, keystr);
449
450 int op = get_op(funcs, buf->data, mutt_str_len(buf->data));
451 struct EventBinding ev_b = { mtypes[i], key, op };
453 continue;
454 }
455 }
456 }
457 }
458 FREE(&key);
459 return rc;
460}
enum CommandResult dump_bind_macro(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse 'bind' and 'macro' commands - Implements Command::parse() -.
Definition: dump.c:171
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition: functions.c:67
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: lib.c:529
int get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition: lib.c:303
int km_expand_key_string(char *str, char *buf, size_t buflen)
Get a human-readable key string.
Definition: lib.c:490
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition: lib.h:136
@ NT_BINDING_ADD
Key binding has been added.
Definition: lib.h:135
enum CommandResult km_bindkey(const char *s, enum MenuType mtype, int op)
Bind a key in a Menu to an operation.
Definition: parse.c:186
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: parse.c:226
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: parse.c:323
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:38
@ NT_BINDING
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:40
A key binding Event.
Definition: lib.h:120
const char * key
Key string being bound (for new bind/macro)
Definition: lib.h:122
int op
Operation the key's bound to (for bind), e.g. OP_DELETE.
Definition: lib.h:123
Mapping between a function and an operation.
Definition: lib.h:102
int op
Operation, e.g. OP_DELETE.
Definition: lib.h:104
const int MenuNamesLen
Number of entries in the MenuNames array.
Definition: type.c:67
MenuType
Types of GUI selections.
Definition: type.h:36
@ MENU_GENERIC
Generic selection list.
Definition: type.h:46
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:55
@ MENU_EDITOR
Text entry area.
Definition: type.h:44
+ 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 472 of file parse.c.

474{
475 bool menu_matches[MENU_MAX] = { 0 };
476 bool all_keys = false;
477 char *key = NULL;
478
480 if (mutt_str_equal(buf->data, "*"))
481 {
482 for (enum MenuType i = 1; i < MENU_MAX; i++)
483 menu_matches[i] = true;
484 }
485 else
486 {
487 parse_menu(menu_matches, buf->data, err);
488 }
489
490 if (MoreArgs(s))
491 {
493 key = buf->data;
494 }
495 else
496 {
497 all_keys = true;
498 }
499
500 if (MoreArgs(s))
501 {
502 const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
503
504 buf_printf(err, _("%s: too many arguments"), cmd);
505 return MUTT_CMD_ERROR;
506 }
507
508 for (enum MenuType i = 1; i < MENU_MAX; i++)
509 {
510 if (!menu_matches[i])
511 continue;
512 if (all_keys)
513 {
514 km_unbind_all(&Keymaps[i], data);
515 km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
516 km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
517 km_bindkey("<enter>", MENU_INDEX, OP_DISPLAY_MESSAGE);
518 km_bindkey("<return>", MENU_INDEX, OP_DISPLAY_MESSAGE);
519 km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
520 km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
521 km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
522 km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
523 if (i != MENU_EDITOR)
524 {
525 km_bindkey("?", i, OP_HELP);
526 km_bindkey("q", i, OP_EXIT);
527 }
528
529 const char *mname = mutt_map_get_name(i, MenuNames);
530 mutt_debug(LL_NOTIFY, "NT_MACRO_DELETE_ALL: %s\n", mname);
531
532 struct EventBinding ev_b = { i, NULL, OP_NULL };
535 &ev_b);
536 }
537 else
538 {
539 char keystr[32] = { 0 };
540 km_expand_key_string(key, keystr, sizeof(keystr));
541 const char *mname = mutt_map_get_name(i, MenuNames);
542 mutt_debug(LL_NOTIFY, "NT_MACRO_DELETE: %s %s\n", mname, keystr);
543
544 km_bindkey(key, i, OP_NULL);
545 struct EventBinding ev_b = { i, key, OP_NULL };
548 }
549 }
550
551 return MUTT_CMD_SUCCESS;
552}
struct KeymapList Keymaps[MENU_MAX]
Array of key mappings, one for each MenuType.
Definition: lib.c:129
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition: lib.h:140
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition: lib.h:141
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition: lib.h:137
#define MUTT_UNMACRO
Parse 'unmacro' command.
Definition: lib.h:49
static void * parse_menu(bool *menus, char *s, struct Buffer *err)
Parse menu-names into an array.
Definition: parse.c:290
static void km_unbind_all(struct KeymapList *km_list, unsigned long mode)
Free all the keys in the supplied Keymap.
Definition: parse.c:198
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:51
@ MENU_MAX
Definition: type.h:60
+ 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 559 of file parse.c.

561{
562 if (StartupComplete)
563 {
564 // Save and restore the offset in `s` because dump_bind_macro() might change it
565 char *dptr = s->dptr;
566 if (dump_bind_macro(buf, s, data, err) == MUTT_CMD_SUCCESS)
567 return MUTT_CMD_SUCCESS;
568 if (!buf_is_empty(err))
569 return MUTT_CMD_ERROR;
570 s->dptr = dptr;
571 }
572
573 enum MenuType mtypes[MenuNamesLen];
574 int num_menus = 0;
576
577 char *key = parse_keymap(mtypes, s, mutt_array_size(mtypes), &num_menus, err, false);
578 if (!key)
579 return MUTT_CMD_ERROR;
580
582 /* make sure the macro sequence is not an empty string */
583 if (buf->data[0] == '\0')
584 {
585 buf_strcpy(err, _("macro: empty key sequence"));
586 }
587 else
588 {
589 if (MoreArgs(s))
590 {
591 char *seq = mutt_str_dup(buf->data);
593
594 if (MoreArgs(s))
595 {
596 buf_printf(err, _("%s: too many arguments"), "macro");
597 }
598 else
599 {
600 for (int i = 0; i < num_menus; i++)
601 {
602 rc = km_bind(key, mtypes[i], OP_MACRO, seq, buf->data);
603 if (rc == MUTT_CMD_SUCCESS)
604 {
605 char keystr[32] = { 0 };
606 km_expand_key_string(key, keystr, sizeof(keystr));
607 const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
608 mutt_debug(LL_NOTIFY, "NT_MACRO_NEW: %s %s\n", mname, keystr);
609
610 struct EventBinding ev_b = { mtypes[i], key, OP_MACRO };
612 continue;
613 }
614 }
615 }
616
617 FREE(&seq);
618 }
619 else
620 {
621 for (int i = 0; i < num_menus; i++)
622 {
623 rc = km_bind(key, mtypes[i], OP_MACRO, buf->data, NULL);
624 if (rc == MUTT_CMD_SUCCESS)
625 {
626 char keystr[32] = { 0 };
627 km_expand_key_string(key, keystr, sizeof(keystr));
628 const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
629 mutt_debug(LL_NOTIFY, "NT_MACRO_NEW: %s %s\n", mname, keystr);
630
631 struct EventBinding ev_b = { mtypes[i], key, OP_MACRO };
633 continue;
634 }
635 }
636 }
637 }
638 FREE(&key);
639 return rc;
640}
@ NT_MACRO_ADD
Key macro has been added.
Definition: lib.h:139
enum CommandResult km_bind(char *s, enum MenuType mtype, int op, char *macro, char *desc)
Bind a key to a macro.
Definition: parse.c:160
+ 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 645 of file parse.c.

647{
648 int ops[128];
649 int nops = 0;
650 const struct MenuFuncOp *funcs = NULL;
651 char *function = NULL;
652
653 if (!MoreArgs(s))
654 {
655 buf_strcpy(err, _("exec: no arguments"));
656 return MUTT_CMD_ERROR;
657 }
658
659 do
660 {
662 function = buf->data;
663
664 const enum MenuType mtype = menu_get_current_type();
665 funcs = km_get_table(mtype);
666 if (!funcs && (mtype != MENU_PAGER))
667 funcs = OpGeneric;
668
669 ops[nops] = get_op(funcs, function, mutt_str_len(function));
670 if ((ops[nops] == OP_NULL) && (mtype != MENU_PAGER) && (mtype != MENU_GENERIC))
671 {
672 ops[nops] = get_op(OpGeneric, function, mutt_str_len(function));
673 }
674
675 if (ops[nops] == OP_NULL)
676 {
678 mutt_error(_("%s: no such function"), function);
679 return MUTT_CMD_ERROR;
680 }
681 nops++;
682 } while (MoreArgs(s) && nops < mutt_array_size(ops));
683
684 while (nops)
685 mutt_push_macro_event(0, ops[--nops]);
686
687 return MUTT_CMD_SUCCESS;
688}
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: get.c:57
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: get.c:154
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:44
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 423 of file set.c.

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