NeoMutt  2022-04-29-70-g0c028c
Teaching an old dog new tricks
DOXYGEN

Function to parse a command. More...

+ Collaboration diagram for parse():

Functions

enum CommandResult parse_alias (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'alias' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unalias (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unalias' command - Implements Command::parse() -. More...
 
enum CommandResult parse_alternates (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'alternates' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unalternates (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unalternates' command - Implements Command::parse() -. More...
 
enum CommandResult parse_attachments (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'attachments' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unattachments (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unattachments' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_uncolor (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'uncolor' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unmono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmono' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_color (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'color' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_mono (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'mono' command - Implements Command::parse() -. More...
 
enum CommandResult parse_cd (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'cd' command - Implements Command::parse() -. More...
 
enum CommandResult parse_echo (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'echo' command - Implements Command::parse() -. More...
 
enum CommandResult parse_finish (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'finish' command - Implements Command::parse() -. More...
 
enum CommandResult parse_group (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'group' and 'ungroup' commands - Implements Command::parse() -. More...
 
enum CommandResult parse_ifdef (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'ifdef' and 'ifndef' commands - Implements Command::parse() -. More...
 
enum CommandResult parse_ignore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'ignore' command - Implements Command::parse() -. More...
 
enum CommandResult parse_lists (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lists' command - Implements Command::parse() -. More...
 
enum CommandResult parse_mailboxes (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'mailboxes' command - Implements Command::parse() -. More...
 
enum CommandResult parse_my_hdr (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'my_hdr' command - Implements Command::parse() -. More...
 
enum CommandResult parse_set (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'set' family of commands - Implements Command::parse() -. More...
 
enum CommandResult parse_setenv (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'setenv' and 'unsetenv' commands - Implements Command::parse() -. More...
 
enum CommandResult parse_source (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'source' command - Implements Command::parse() -. More...
 
enum CommandResult parse_spam_list (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'spam' and 'nospam' commands - Implements Command::parse() -. More...
 
enum CommandResult parse_stailq (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse a list command - Implements Command::parse() -. More...
 
enum CommandResult parse_subscribe (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subscribe' command - Implements Command::parse() -. More...
 
enum CommandResult parse_subscribe_to (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subscribe-to' command - Implements Command::parse() -. More...
 
enum CommandResult parse_tag_formats (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'tag-formats' command - Implements Command::parse() -. More...
 
enum CommandResult parse_tag_transforms (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'tag-transforms' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unignore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unignore' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unlists (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unlists' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unmailboxes (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmailboxes' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unmy_hdr (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmy_hdr' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unstailq (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse an unlist command - Implements Command::parse() -. More...
 
enum CommandResult parse_unsubscribe (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubscribe' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unsubscribe_from (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubscribe-from' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_charset_iconv_hook (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse 'charset-hook' and 'iconv-hook' commands - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_hook (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'hook' family of commands - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_idxfmt_hook (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'index-format-hook' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unhook (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unhook' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_push (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'push' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_bind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'bind' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unbind (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unbind' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_macro (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'macro' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_exec (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'exec' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_lua_parse (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lua' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_lua_source_file (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lua-source' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_score (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'score' command - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_unscore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unscore' command - Implements Command::parse() -. More...
 
enum CommandResult sb_parse_whitelist (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'sidebar_whitelist' command - Implements Command::parse() -. More...
 
enum CommandResult sb_parse_unwhitelist (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsidebar_whitelist' command - Implements Command::parse() -. More...
 
static enum CommandResult parse_unreplace_list (struct Buffer *buf, struct Buffer *s, struct ReplaceList *list, struct Buffer *err)
 Remove a string replacement rule - Implements Command::parse() -. More...
 
static enum CommandResult parse_replace_list (struct Buffer *buf, struct Buffer *s, struct ReplaceList *list, struct Buffer *err)
 Parse a string replacement rule - Implements Command::parse() -. More...
 
enum CommandResult parse_subjectrx_list (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subjectrx' command - Implements Command::parse() -. More...
 
enum CommandResult parse_unsubjectrx_list (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubjectrx' command - Implements Command::parse() -. More...
 

Detailed Description

Function to parse a command.

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

Function Documentation

◆ parse_alias()

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

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

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

Definition at line 1 of file commands.c.

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

◆ parse_unalias()

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

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

Definition at line 1 of file commands.c.

163 {
164  do
165  {
167 
168  struct Alias *np = NULL;
169  if (mutt_str_equal("*", buf->data))
170  {
171  TAILQ_FOREACH(np, &Aliases, entries)
172  {
174  }
175 
177  return MUTT_CMD_SUCCESS;
178  }
179 
180  TAILQ_FOREACH(np, &Aliases, entries)
181  {
182  if (!mutt_istr_equal(buf->data, np->name))
183  continue;
184 
185  TAILQ_REMOVE(&Aliases, np, entries);
187  alias_free(&np);
188  break;
189  }
190  } while (MoreArgs(s));
191  return MUTT_CMD_SUCCESS;
192 }
void alias_free(struct Alias **ptr)
Free an Alias.
Definition: alias.c:640
void aliaslist_free(struct AliasList *al)
Free a List of Aliases.
Definition: alias.c:661
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:784
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841

◆ 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 72 of file alternates.c.

91 {
92  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
93 
94  do
95  {
97 
98  if (parse_grouplist(&gl, buf, s, err) == -1)
99  goto bail;
100 
102 
103  if (mutt_regexlist_add(&Alternates, buf->data, REG_ICASE, err) != 0)
104  goto bail;
105 
106  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
107  goto bail;
108  } while (MoreArgs(s));
109 
111 
112  mutt_debug(LL_NOTIFY, "NT_ALTERN_ADD: %s\n", buf->data);
114 
115  return MUTT_CMD_SUCCESS;
116 
117 bail:
119  return MUTT_CMD_ERROR;
120 }
struct RegexList Alternates
List of regexes to match the user's alternate email addresses.
Definition: alternates.c:42
static struct Notify * AlternatesNotify
Definition: alternates.c:44
struct RegexList UnAlternates
List of regexes to blacklist false matches in Alternates.
Definition: alternates.c:43
@ NT_ALTERN_ADD
Alternate address has been added.
Definition: alternates.h:41
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:320
int mutt_regexlist_add(struct RegexList *rl, const char *str, uint16_t flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:135
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:230
@ NT_ALTERN
Alternates command changed, NotifyAlternates.
Definition: notify_type.h:38

◆ 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 72 of file alternates.c.

127 {
128  do
129  {
132 
133  if (!mutt_str_equal(buf->data, "*") &&
134  (mutt_regexlist_add(&UnAlternates, buf->data, REG_ICASE, err) != 0))
135  {
136  return MUTT_CMD_ERROR;
137  }
138 
139  } while (MoreArgs(s));
140 
141  mutt_debug(LL_NOTIFY, "NT_ALTERN_DELETE: %s\n", buf->data);
143 
144  return MUTT_CMD_SUCCESS;
145 }
@ NT_ALTERN_DELETE
Alternate address has been deleted.
Definition: alternates.h:42

◆ 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 455 of file attachments.c.

473 {
475  if (!buf->data || (*buf->data == '\0'))
476  {
477  mutt_buffer_strcpy(err, _("attachments: no disposition"));
478  return MUTT_CMD_WARNING;
479  }
480 
481  char *category = buf->data;
482  char op = *category++;
483 
484  if (op == '?')
485  {
486  mutt_endwin();
487  fflush(stdout);
488  printf("\n%s\n\n", _("Current attachments settings:"));
489  print_attach_list(&AttachAllow, '+', "A");
490  print_attach_list(&AttachExclude, '-', "A");
491  print_attach_list(&InlineAllow, '+', "I");
492  print_attach_list(&InlineExclude, '-', "I");
494  return MUTT_CMD_SUCCESS;
495  }
496 
497  if ((op != '+') && (op != '-'))
498  {
499  op = '+';
500  category--;
501  }
502 
503  struct ListHead *head = NULL;
504  if (mutt_istr_startswith("attachment", category))
505  {
506  if (op == '+')
507  head = &AttachAllow;
508  else
509  head = &AttachExclude;
510  }
511  else if (mutt_istr_startswith("inline", category))
512  {
513  if (op == '+')
514  head = &InlineAllow;
515  else
516  head = &InlineExclude;
517  }
518  else
519  {
520  mutt_buffer_strcpy(err, _("attachments: invalid disposition"));
521  return MUTT_CMD_ERROR;
522  }
523 
524  return parse_attach_list(buf, s, head, err);
525 }
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: attachments.c:56
static int print_attach_list(struct ListHead *h, const char op, const char *name)
Print a list of attachments.
Definition: attachments.c:455
struct ListHead InlineExclude
List of inline types to ignore.
Definition: attachments.c:59
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: attachments.c:57
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:309
struct ListHead InlineAllow
List of inline types to counted.
Definition: attachments.c:58
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition: curs_lib.c:498
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:465
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:239

◆ 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 455 of file attachments.c.

532 {
533  char op;
534  char *p = NULL;
535  struct ListHead *head = NULL;
536 
538  if (!buf->data || (*buf->data == '\0'))
539  {
540  mutt_buffer_strcpy(err, _("unattachments: no disposition"));
541  return MUTT_CMD_WARNING;
542  }
543 
544  p = buf->data;
545  op = *p++;
546 
547  if (op == '*')
548  {
553 
554  mutt_debug(LL_NOTIFY, "NT_ATTACH_DELETE_ALL\n");
556  return 0;
557  }
558 
559  if ((op != '+') && (op != '-'))
560  {
561  op = '+';
562  p--;
563  }
564  if (mutt_istr_startswith("attachment", p))
565  {
566  if (op == '+')
567  head = &AttachAllow;
568  else
569  head = &AttachExclude;
570  }
571  else if (mutt_istr_startswith("inline", p))
572  {
573  if (op == '+')
574  head = &InlineAllow;
575  else
576  head = &InlineExclude;
577  }
578  else
579  {
580  mutt_buffer_strcpy(err, _("unattachments: invalid disposition"));
581  return MUTT_CMD_ERROR;
582  }
583 
584  return parse_unattach_list(buf, s, head, err);
585 }
static struct Notify * AttachmentsNotify
Definition: attachments.c:60
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:389
@ NT_ATTACH_DELETE_ALL
All Attachment regexes have been deleted.
Definition: attachments.h:42
static void attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t -.
Definition: attachments.c:69
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

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

660 {
661  if (OptNoCurses)
662  {
663  *s->dptr = '\0'; /* fake that we're done parsing */
664  return MUTT_CMD_SUCCESS;
665  }
666  color_debug(LL_DEBUG5, "parse: %s\n", mutt_buffer_string(buf));
667  enum CommandResult rc = parse_uncolor(buf, s, err, true);
668  // simple_colors_dump(false);
670  return rc;
671 }
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, struct Buffer *err, bool uncolor)
Parse an 'uncolor' command.
Definition: command.c:423
CommandResult
Error codes for command_t parse functions.
Definition: command.h:34
int color_debug(enum LogLevel level, const char *format,...)
Write to the log file.
Definition: debug.c:44
void curses_colors_dump(void)
Log all the Curses colours.
Definition: debug.c:265
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:53

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

678 {
679  *s->dptr = '\0'; /* fake that we're done parsing */
680  return MUTT_CMD_SUCCESS;
681 }

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

688 {
689  bool dry_run = OptNoCurses;
690 
691  color_debug(LL_DEBUG5, "parse: %s\n", mutt_buffer_string(buf));
692  enum CommandResult rc = parse_color(buf, s, err, parse_color_pair, dry_run, true);
693  // simple_colors_dump(false);
695  return rc;
696 }
static enum CommandResult parse_color(struct Buffer *buf, struct Buffer *s, struct Buffer *err, parser_callback_t callback, bool dry_run, bool color)
Parse a 'color' command.
Definition: command.c:524
static enum CommandResult parse_color_pair(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attrs, struct Buffer *err)
Parse a pair of colours - Implements parser_callback_t -.
Definition: command.c:252

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

703 {
704  return parse_color(buf, s, err, parse_attr_spec, true, false);
705 }
static enum CommandResult parse_attr_spec(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attrs, struct Buffer *err)
Parse an attribute description - Implements parser_callback_t -.
Definition: command.c:209

◆ parse_cd()

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

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

Definition at line 144 of file command_parse.c.

295 {
298  if (mutt_buffer_len(buf) == 0)
299  {
300  if (HomeDir)
302  else
303  {
304  mutt_buffer_printf(err, _("%s: too few arguments"), "cd");
305  return MUTT_CMD_ERROR;
306  }
307  }
308 
309  if (chdir(mutt_buffer_string(buf)) != 0)
310  {
311  mutt_buffer_printf(err, "cd: %s", strerror(errno));
312  return MUTT_CMD_ERROR;
313  }
314 
315  return MUTT_CMD_SUCCESS;
316 }
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:356
char * HomeDir
User's home directory.
Definition: mutt_globals.h:49
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:321
+ Here is the call graph for this function:

◆ parse_echo()

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

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

Definition at line 144 of file command_parse.c.

323 {
324  if (!MoreArgs(s))
325  {
326  mutt_buffer_printf(err, _("%s: too few arguments"), "echo");
327  return MUTT_CMD_WARNING;
328  }
330  OptForceRefresh = true;
331  mutt_message("%s", buf->data);
332  OptForceRefresh = false;
333  mutt_sleep(0);
334 
335  return MUTT_CMD_SUCCESS;
336 }
#define mutt_message(...)
Definition: logging.h:86
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1454
bool OptForceRefresh
(pseudo) refresh even during macros
Definition: options.h:42

◆ parse_finish()

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

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

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 144 of file command_parse.c.

347 {
348  if (MoreArgs(s))
349  {
350  mutt_buffer_printf(err, _("%s: too many arguments"), "finish");
351  return MUTT_CMD_WARNING;
352  }
353 
354  return MUTT_CMD_FINISH;
355 }
@ MUTT_CMD_FINISH
Finish: Stop processing this file.
Definition: command.h:38

◆ parse_group()

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

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

Definition at line 144 of file command_parse.c.

362 {
363  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
364  enum GroupState state = GS_NONE;
365 
366  do
367  {
369  if (parse_grouplist(&gl, buf, s, err) == -1)
370  goto bail;
371 
372  if ((data == MUTT_UNGROUP) && mutt_istr_equal(buf->data, "*"))
373  {
375  goto out;
376  }
377 
378  if (mutt_istr_equal(buf->data, "-rx"))
379  state = GS_RX;
380  else if (mutt_istr_equal(buf->data, "-addr"))
381  state = GS_ADDR;
382  else
383  {
384  switch (state)
385  {
386  case GS_NONE:
387  mutt_buffer_printf(err, _("%sgroup: missing -rx or -addr"),
388  (data == MUTT_UNGROUP) ? "un" : "");
389  goto warn;
390 
391  case GS_RX:
392  if ((data == MUTT_GROUP) &&
393  (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0))
394  {
395  goto bail;
396  }
397  else if ((data == MUTT_UNGROUP) &&
398  (mutt_grouplist_remove_regex(&gl, buf->data) < 0))
399  {
400  goto bail;
401  }
402  break;
403 
404  case GS_ADDR:
405  {
406  char *estr = NULL;
407  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
408  mutt_addrlist_parse2(&al, buf->data);
409  if (TAILQ_EMPTY(&al))
410  goto bail;
411  if (mutt_addrlist_to_intl(&al, &estr))
412  {
413  mutt_buffer_printf(err, _("%sgroup: warning: bad IDN '%s'"),
414  (data == 1) ? "un" : "", estr);
415  mutt_addrlist_clear(&al);
416  FREE(&estr);
417  goto bail;
418  }
419  if (data == MUTT_GROUP)
420  mutt_grouplist_add_addrlist(&gl, &al);
421  else if (data == MUTT_UNGROUP)
423  mutt_addrlist_clear(&al);
424  break;
425  }
426  }
427  }
428  } while (MoreArgs(s));
429 
430 out:
432  return MUTT_CMD_SUCCESS;
433 
434 bail:
436  return MUTT_CMD_ERROR;
437 
438 warn:
440  return MUTT_CMD_WARNING;
441 }
GroupState
Type of email address group.
Definition: command_parse.c:75
@ GS_RX
Entry is a regular expression.
Definition: command_parse.c:77
@ GS_NONE
Group is missing an argument.
Definition: command_parse.c:76
@ GS_ADDR
Entry is an address.
Definition: command_parse.c:78
int mutt_grouplist_remove_addrlist(struct GroupList *gl, struct AddressList *al)
Remove an AddressList from a GroupList.
Definition: group.c:289
int mutt_grouplist_remove_regex(struct GroupList *gl, const char *s)
Remove matching addresses from a GroupList.
Definition: group.c:345
void mutt_grouplist_clear(struct GroupList *gl)
Clear a GroupList.
Definition: group.c:147
#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

◆ parse_ifdef()

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

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

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 144 of file command_parse.c.

458 {
460 
461  // is the item defined as:
462  bool res = cs_subset_lookup(NeoMutt->sub, buf->data) // a variable?
463  || feature_enabled(buf->data) // a compiled-in feature?
464  || is_function(buf->data) // a function?
465  || mutt_command_get(buf->data) // a command?
466  || myvar_get(buf->data) // a my_ variable?
467  || mutt_str_getenv(buf->data); // an environment variable?
468 
469  if (!MoreArgs(s))
470  {
471  mutt_buffer_printf(err, _("%s: too few arguments"), (data ? "ifndef" : "ifdef"));
472  return MUTT_CMD_WARNING;
473  }
475 
476  /* ifdef KNOWN_SYMBOL or ifndef UNKNOWN_SYMBOL */
477  if ((res && (data == 0)) || (!res && (data == 1)))
478  {
479  enum CommandResult rc = mutt_parse_rc_line(buf->data, err);
480  if (rc == MUTT_CMD_ERROR)
481  {
482  mutt_error(_("Error: %s"), err->data);
483  return MUTT_CMD_ERROR;
484  }
485  return rc;
486  }
487  return MUTT_CMD_SUCCESS;
488 }
static bool is_function(const char *name)
Is the argument a neomutt function?
Definition: command_parse.c:87
#define mutt_error(...)
Definition: logging.h:87
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: init.c:1041
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:904
struct Command * mutt_command_get(const char *s)
Get a Command by its name.
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
Definition: myvar.c:92
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
Definition: subset.c:179
bool feature_enabled(const char *name)
Test if a compile-time feature is enabled.
Definition: version.c:563

◆ parse_ignore()

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

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

Definition at line 144 of file command_parse.c.

495 {
496  do
497  {
500  add_to_stailq(&Ignore, buf->data);
501  } while (MoreArgs(s));
502 
503  return MUTT_CMD_SUCCESS;
504 }
struct ListHead Ignore
List of header patterns to ignore.
Definition: globals.c:35
struct ListHead UnIgnore
List of header patterns to unignore (see)
Definition: globals.c:36
void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: muttlib.c:1743
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: muttlib.c:1718

◆ parse_lists()

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

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

Definition at line 144 of file command_parse.c.

511 {
512  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
513 
514  do
515  {
517 
518  if (parse_grouplist(&gl, buf, s, err) == -1)
519  goto bail;
520 
522 
523  if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
524  goto bail;
525 
526  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
527  goto bail;
528  } while (MoreArgs(s));
529 
531  return MUTT_CMD_SUCCESS;
532 
533 bail:
535  return MUTT_CMD_ERROR;
536 }
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
Definition: globals.c:42
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: globals.c:41

◆ 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 144 of file command_parse.c.

545 {
546  while (MoreArgs(s))
547  {
548  struct Mailbox *m = mailbox_new();
549 
550  if (data & MUTT_NAMED)
551  {
552  // This may be empty, e.g. `named-mailboxes "" +inbox`
554  m->name = mutt_buffer_strdup(buf);
555  }
556 
558  if (mutt_buffer_is_empty(buf))
559  {
560  /* Skip empty tokens. */
561  mailbox_free(&m);
562  continue;
563  }
564 
565  mutt_buffer_strcpy(&m->pathbuf, buf->data);
566  const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
567  /* int rc = */ mx_path_canon2(m, c_folder);
568 
569  if (m->type <= MUTT_UNKNOWN)
570  {
571  mutt_error("Unknown Mailbox: %s", m->realpath);
572  mailbox_free(&m);
573  return MUTT_CMD_ERROR;
574  }
575 
576  bool new_account = false;
577  struct Account *a = mx_ac_find(m);
578  if (!a)
579  {
580  a = account_new(NULL, NeoMutt->sub);
581  a->type = m->type;
582  new_account = true;
583  }
584 
585  if (!new_account)
586  {
587  struct Mailbox *m_old = mx_mbox_find(a, m->realpath);
588  if (m_old)
589  {
590  if (!m_old->visible)
591  {
592  m_old->visible = true;
593  m_old->gen = mailbox_gen();
594  }
595 
596  const bool rename = (data & MUTT_NAMED) && !mutt_str_equal(m_old->name, m->name);
597  if (rename)
598  {
599  mutt_str_replace(&m_old->name, m->name);
600  }
601 
602  mailbox_free(&m);
603  continue;
604  }
605  }
606 
607  if (!mx_ac_add(a, m))
608  {
609  mailbox_free(&m);
610  if (new_account)
611  {
612  cs_subset_free(&a->sub);
613  FREE(&a->name);
614  notify_free(&a->notify);
615  FREE(&a);
616  }
617  continue;
618  }
619  if (new_account)
620  {
622  }
623 
624  // this is finally a visible mailbox in the sidebar and mailboxes list
625  m->visible = true;
626 
627 #ifdef USE_INOTIFY
628  mutt_monitor_add(m);
629 #endif
630  }
631  return MUTT_CMD_SUCCESS;
632 }
struct Account * account_new(const char *name, struct ConfigSubset *sub)
Create a new Account.
Definition: account.c:43
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:432
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
struct Mailbox * mailbox_new(void)
Create a new Mailbox.
Definition: mailbox.c:68
int mailbox_gen(void)
Get the next generation number.
Definition: mailbox.c:58
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:87
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:481
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:326
#define MUTT_NAMED
Definition: mutt_commands.h:44
bool mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add()
Definition: mx.c:1764
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1587
struct Account * mx_ac_find(struct Mailbox *m)
Find the Account owning a Mailbox.
Definition: mx.c:1563
int mx_path_canon2(struct Mailbox *m, const char *folder)
Canonicalise the path to realpath.
Definition: mx.c:1477
bool neomutt_account_add(struct NeoMutt *n, struct Account *a)
Add an Account to the global list.
Definition: neomutt.c:84
A group of associated Mailboxes.
Definition: account.h:37
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
char * name
Name of Account.
Definition: account.h:39
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
A mailbox.
Definition: mailbox.h:79
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
struct Buffer pathbuf
Path of the Mailbox.
Definition: mailbox.h:80
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:131
int gen
Generation number, for sorting.
Definition: mailbox.h:147
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:104

◆ 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 144 of file command_parse.c.

639 {
641  char *p = strpbrk(buf->data, ": \t");
642  if (!p || (*p != ':'))
643  {
644  mutt_buffer_strcpy(err, _("invalid header field"));
645  return MUTT_CMD_WARNING;
646  }
647 
648  struct EventHeader ev_h = { buf->data };
649  struct ListNode *n = header_find(&UserHeader, buf->data);
650 
651  if (n)
652  {
653  header_update(n, buf->data);
654  mutt_debug(LL_NOTIFY, "NT_HEADER_CHANGE: %s\n", buf->data);
656  }
657  else
658  {
659  header_add(&UserHeader, buf->data);
660  mutt_debug(LL_NOTIFY, "NT_HEADER_ADD: %s\n", buf->data);
662  }
663 
664  return MUTT_CMD_SUCCESS;
665 }
struct ListNode * header_add(struct ListHead *hdrlist, const char *header)
Add a header to a list.
Definition: email.c:203
struct ListNode * header_update(struct ListNode *hdr, const char *header)
Update an existing header.
Definition: email.c:217
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:180
@ NT_HEADER_CHANGE
An existing header has been changed.
Definition: email.h:174
@ NT_HEADER_ADD
Header has been added.
Definition: email.h:172
struct ListHead UserHeader
List of custom headers to add to outgoing emails.
Definition: mutt_globals.h:66
@ NT_HEADER
A header has changed, NotifyHeader EventHeader.
Definition: notify_type.h:47
An event that happened to a header.
Definition: email.h:181
A List node for strings.
Definition: list.h:35
+ Here is the caller 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 144 of file command_parse.c.

674 {
675  /* The order must match `enum MuttSetCommand` */
676  static const char *set_commands[] = { "set", "toggle", "unset", "reset" };
677 
678  int rc = 0;
679 
680  while (MoreArgs(s))
681  {
682  bool prefix = false;
683  bool query = false;
684  bool inv = (data == MUTT_SET_INV);
685  bool reset = (data == MUTT_SET_RESET);
686  bool unset = (data == MUTT_SET_UNSET);
687 
688  if (*s->dptr == '?')
689  {
690  prefix = true;
691  query = true;
692  s->dptr++;
693  }
694  else if (mutt_str_startswith(s->dptr, "no"))
695  {
696  prefix = true;
697  unset = !unset;
698  s->dptr += 2;
699  }
700  else if (mutt_str_startswith(s->dptr, "inv"))
701  {
702  prefix = true;
703  inv = !inv;
704  s->dptr += 3;
705  }
706  else if (*s->dptr == '&')
707  {
708  prefix = true;
709  reset = true;
710  s->dptr++;
711  }
712 
713  if (prefix && (data != MUTT_SET_SET))
714  {
715  mutt_buffer_printf(err, _("Can't use 'inv', 'no', '&' or '?' with the '%s' command"),
716  set_commands[data]);
717  return MUTT_CMD_WARNING;
718  }
719 
720  /* get the variable name */
722 
723  bool bq = false;
724  bool equals = false;
725  bool increment = false;
726  bool decrement = false;
727 
728  struct HashElem *he = NULL;
729  bool my = mutt_str_startswith(buf->data, "my_");
730  if (!my)
731  {
732  he = cs_subset_lookup(NeoMutt->sub, buf->data);
733  if (!he)
734  {
735  if (reset && mutt_str_equal(buf->data, "all"))
736  {
737  struct HashElem **list = get_elem_list(NeoMutt->sub->cs);
738  if (!list)
739  return MUTT_CMD_ERROR;
740 
741  for (size_t i = 0; list[i]; i++)
742  cs_subset_he_reset(NeoMutt->sub, list[i], NULL);
743 
744  FREE(&list);
745  break;
746  }
747  else
748  {
749  mutt_buffer_printf(err, _("%s: unknown variable"), buf->data);
750  return MUTT_CMD_ERROR;
751  }
752  }
753 
754  // Use the correct name if a synonym is used
755  mutt_buffer_strcpy(buf, he->key.strkey);
756 
757  bq = ((DTYPE(he->type) == DT_BOOL) || (DTYPE(he->type) == DT_QUAD));
758  }
759 
760  if (*s->dptr == '?')
761  {
762  if (prefix)
763  {
764  mutt_buffer_printf(err, _("Can't use a prefix when querying a variable"));
765  return MUTT_CMD_WARNING;
766  }
767 
768  if (reset || unset || inv)
769  {
770  mutt_buffer_printf(err, _("Can't query a variable with the '%s' command"),
771  set_commands[data]);
772  return MUTT_CMD_WARNING;
773  }
774 
775  query = true;
776  s->dptr++;
777  }
778  else if (*s->dptr == '+' || *s->dptr == '-')
779  {
780  if (prefix)
781  {
782  mutt_buffer_printf(err, _("Can't use prefix when incrementing or decrementing a variable"));
783  return MUTT_CMD_WARNING;
784  }
785 
786  if (reset || unset || inv)
787  {
788  mutt_buffer_printf(err, _("Can't set a variable with the '%s' command"),
789  set_commands[data]);
790  return MUTT_CMD_WARNING;
791  }
792  if (*s->dptr == '+')
793  increment = true;
794  else
795  decrement = true;
796 
797  if (my && decrement)
798  {
799  mutt_buffer_printf(err, _("Can't decrement a my_ variable"), set_commands[data]);
800  return MUTT_CMD_WARNING;
801  }
802  s->dptr++;
803  if (*s->dptr == '=')
804  {
805  equals = true;
806  s->dptr++;
807  }
808  }
809  else if (*s->dptr == '=')
810  {
811  if (prefix)
812  {
813  mutt_buffer_printf(err, _("Can't use prefix when setting a variable"));
814  return MUTT_CMD_WARNING;
815  }
816 
817  if (reset || unset || inv)
818  {
819  mutt_buffer_printf(err, _("Can't set a variable with the '%s' command"),
820  set_commands[data]);
821  return MUTT_CMD_WARNING;
822  }
823 
824  equals = true;
825  s->dptr++;
826  }
827 
828  if (!bq && (inv || (unset && prefix)))
829  {
830  if (data == MUTT_SET_SET)
831  {
832  mutt_buffer_printf(err, _("Prefixes 'no' and 'inv' may only be used with bool/quad variables"));
833  }
834  else
835  {
836  mutt_buffer_printf(err, _("Command '%s' can only be used with bool/quad variables"),
837  set_commands[data]);
838  }
839  return MUTT_CMD_WARNING;
840  }
841 
842  if (reset)
843  {
844  // mutt_buffer_printf(err, "ACT24 reset variable %s", buf->data);
845  if (he)
846  {
847  rc = cs_subset_he_reset(NeoMutt->sub, he, err);
848  if (CSR_RESULT(rc) != CSR_SUCCESS)
849  return MUTT_CMD_ERROR;
850  }
851  else
852  {
853  myvar_del(buf->data);
854  }
855  continue;
856  }
857 
858  if ((data == MUTT_SET_SET) && !inv && !unset)
859  {
860  if (query)
861  {
862  // mutt_buffer_printf(err, "ACT08 query variable %s", buf->data);
863  if (he)
864  {
865  mutt_buffer_addstr(err, buf->data);
866  mutt_buffer_addch(err, '=');
867  mutt_buffer_reset(buf);
868  rc = cs_subset_he_string_get(NeoMutt->sub, he, buf);
869  if (CSR_RESULT(rc) != CSR_SUCCESS)
870  {
871  mutt_buffer_addstr(err, buf->data);
872  return MUTT_CMD_ERROR;
873  }
874  if (DTYPE(he->type) == DT_PATH)
875  mutt_pretty_mailbox(buf->data, buf->dsize);
876  pretty_var(buf->data, err);
877  }
878  else
879  {
880  const char *val = myvar_get(buf->data);
881  if (val)
882  {
883  mutt_buffer_addstr(err, buf->data);
884  mutt_buffer_addch(err, '=');
885  pretty_var(val, err);
886  }
887  else
888  {
889  mutt_buffer_printf(err, _("%s: unknown variable"), buf->data);
890  return MUTT_CMD_ERROR;
891  }
892  }
893  break;
894  }
895  else if (equals)
896  {
897  // mutt_buffer_printf(err, "ACT11 set variable %s to ", buf->data);
898  const char *name = NULL;
899  if (my)
900  {
901  name = mutt_str_dup(buf->data);
902  }
904  if (my)
905  {
906  assert(!decrement);
907  if (increment)
908  {
909  myvar_append(name, buf->data);
910  }
911  else
912  {
913  myvar_set(name, buf->data);
914  }
915  FREE(&name);
916  }
917  else
918  {
919  if (DTYPE(he->type) == DT_PATH)
920  {
921  if (he->type & (DT_PATH_DIR | DT_PATH_FILE))
923  else
924  mutt_path_tilde(buf->data, buf->dsize, HomeDir);
925  }
926  else if (IS_MAILBOX(he))
927  {
929  }
930  else if (IS_COMMAND(he))
931  {
932  struct Buffer scratch = mutt_buffer_make(1024);
933  mutt_buffer_copy(&scratch, buf);
934 
935  if (!mutt_str_equal(buf->data, "builtin"))
936  {
937  mutt_buffer_expand_path(&scratch);
938  }
939  mutt_buffer_reset(buf);
940  mutt_buffer_addstr(buf, mutt_buffer_string(&scratch));
941  mutt_buffer_dealloc(&scratch);
942  }
943  if (increment)
944  {
945  rc = cs_subset_he_string_plus_equals(NeoMutt->sub, he, buf->data, err);
946  }
947  else if (decrement)
948  {
949  rc = cs_subset_he_string_minus_equals(NeoMutt->sub, he, buf->data, err);
950  }
951  else
952  {
953  rc = cs_subset_he_string_set(NeoMutt->sub, he, buf->data, err);
954  }
955  if (CSR_RESULT(rc) != CSR_SUCCESS)
956  return MUTT_CMD_ERROR;
957  }
958  continue;
959  }
960  else
961  {
962  if (bq)
963  {
964  // mutt_buffer_printf(err, "ACT23 set variable %s to 'yes'", buf->data);
965  rc = cs_subset_he_native_set(NeoMutt->sub, he, true, err);
966  if (CSR_RESULT(rc) != CSR_SUCCESS)
967  return MUTT_CMD_ERROR;
968  continue;
969  }
970  else
971  {
972  // mutt_buffer_printf(err, "ACT10 query variable %s", buf->data);
973  if (he)
974  {
975  mutt_buffer_addstr(err, buf->data);
976  mutt_buffer_addch(err, '=');
977  mutt_buffer_reset(buf);
978  rc = cs_subset_he_string_get(NeoMutt->sub, he, buf);
979  if (CSR_RESULT(rc) != CSR_SUCCESS)
980  {
981  mutt_buffer_addstr(err, buf->data);
982  return MUTT_CMD_ERROR;
983  }
984  if (DTYPE(he->type) == DT_PATH)
985  mutt_pretty_mailbox(buf->data, buf->dsize);
986  pretty_var(buf->data, err);
987  }
988  else
989  {
990  const char *val = myvar_get(buf->data);
991  if (val)
992  {
993  mutt_buffer_addstr(err, buf->data);
994  mutt_buffer_addch(err, '=');
995  pretty_var(val, err);
996  }
997  else
998  {
999  mutt_buffer_printf(err, _("%s: unknown variable"), buf->data);
1000  return MUTT_CMD_ERROR;
1001  }
1002  }
1003  break;
1004  }
1005  }
1006  }
1007 
1008  if (my)
1009  {
1010  myvar_del(buf->data);
1011  }
1012  else if (bq)
1013  {
1014  if (inv)
1015  {
1016  // mutt_buffer_printf(err, "ACT25 TOGGLE bool/quad variable %s", buf->data);
1017  if (DTYPE(he->type) == DT_BOOL)
1018  bool_he_toggle(NeoMutt->sub, he, err);
1019  else
1020  quad_he_toggle(NeoMutt->sub, he, err);
1021  }
1022  else
1023  {
1024  // mutt_buffer_printf(err, "ACT26 UNSET bool/quad variable %s", buf->data);
1025  rc = cs_subset_he_native_set(NeoMutt->sub, he, false, err);
1026  if (CSR_RESULT(rc) != CSR_SUCCESS)
1027  return MUTT_CMD_ERROR;
1028  }
1029  continue;
1030  }
1031  else
1032  {
1033  rc = cs_subset_he_string_set(NeoMutt->sub, he, NULL, err);
1034  if (CSR_RESULT(rc) != CSR_SUCCESS)
1035  return MUTT_CMD_ERROR;
1036  }
1037  }
1038 
1039  return MUTT_CMD_SUCCESS;
1040 }
int bool_he_toggle(struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
Toggle the value of a bool.
Definition: bool.c:186
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:447
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
size_t pretty_var(const char *str, struct Buffer *buf)
Escape and stringify a config item value.
Definition: dump.c:83
void mutt_pretty_mailbox(char *buf, size_t buflen)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:521
bool mutt_path_tilde(char *buf, size_t buflen, const char *homedir)
Expand '~' in a path.
Definition: path.c:223
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:227
#define MUTT_TOKEN_BACKTICK_VARS
Expand variables within backticks.
Definition: mutt.h:74
#define MUTT_TOKEN_MINUS
Treat '-' as a special.
Definition: mutt.h:78
#define MUTT_TOKEN_PLUS
Treat '+' as a special.
Definition: mutt.h:77
#define MUTT_TOKEN_EQUAL
Treat '=' as a special.
Definition: mutt.h:67
#define MUTT_TOKEN_QUESTION
Treat '?' as a special.
Definition: mutt.h:76
@ MUTT_SET_INV
default is to invert all vars
Definition: mutt_commands.h:38
@ MUTT_SET_SET
default is to set all vars
Definition: mutt_commands.h:37
@ MUTT_SET_RESET
default is to reset all vars to default
Definition: mutt_commands.h:40
@ MUTT_SET_UNSET
default is to unset all vars
Definition: mutt_commands.h:39
void myvar_del(const char *var)
Unset the value of a "my_" variable.
Definition: myvar.c:146
void myvar_set(const char *var, const char *val)
Set the value of a "my_" variable.
Definition: myvar.c:109
void myvar_append(const char *var, const char *val)
Append to the value of a "my_" variable.
Definition: myvar.c:128
int quad_he_toggle(struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
Toggle the value of a quad.
Definition: quad.c:204
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
String manipulation buffer.
Definition: buffer.h:34
size_t dsize
Length of data.
Definition: buffer.h:37
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
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
int cs_subset_he_string_minus_equals(const struct ConfigSubset *sub, struct HashElem *he, const char *value, struct Buffer *err)
Remove from a config item by string.
Definition: subset.c:462
int cs_subset_he_string_get(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: subset.c:354
int cs_subset_he_native_set(const struct ConfigSubset *sub, struct HashElem *he, intptr_t value, struct Buffer *err)
Natively set the value of a HashElem config item.
Definition: subset.c:283
int cs_subset_he_reset(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
Reset a config item to its initial value.
Definition: subset.c:320
int cs_subset_he_string_set(const struct ConfigSubset *sub, struct HashElem *he, const char *value, struct Buffer *err)
Set a config item by string.
Definition: subset.c:386
struct HashElem ** get_elem_list(struct ConfigSet *cs)
Create a sorted list of all config items.
Definition: subset.c:75
int cs_subset_he_string_plus_equals(const struct ConfigSubset *sub, struct HashElem *he, const char *value, struct Buffer *err)
Add to a config item by string.
Definition: subset.c:424
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:44
#define IS_MAILBOX(x)
Definition: types.h:57
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:37
#define DT_BOOL
boolean option
Definition: types.h:30
#define DT_PATH_DIR
Path is a directory.
Definition: types.h:53
#define DT_PATH_FILE
Path is a file.
Definition: types.h:54
#define DT_PATH
a path to a file/directory
Definition: types.h:36
#define IS_COMMAND(x)
Definition: types.h:58
const char * strkey
String key.
Definition: hash.h:36

◆ parse_setenv()

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

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

Definition at line 144 of file command_parse.c.

1047 {
1048  char **envp = mutt_envlist_getlist();
1049 
1050  bool query = false;
1051  bool prefix = false;
1052  bool unset = (data == MUTT_SET_UNSET);
1053 
1054  if (!MoreArgs(s))
1055  {
1056  mutt_buffer_printf(err, _("%s: too few arguments"), "setenv");
1057  return MUTT_CMD_WARNING;
1058  }
1059 
1060  if (*s->dptr == '?')
1061  {
1062  query = true;
1063  prefix = true;
1064 
1065  if (unset)
1066  {
1067  mutt_buffer_printf(err, _("Can't query a variable with the '%s' command"), "unsetenv");
1068  return MUTT_CMD_WARNING;
1069  }
1070 
1071  s->dptr++;
1072  }
1073 
1074  /* get variable name */
1076 
1077  if (*s->dptr == '?')
1078  {
1079  if (unset)
1080  {
1081  mutt_buffer_printf(err, _("Can't query a variable with the '%s' command"), "unsetenv");
1082  return MUTT_CMD_WARNING;
1083  }
1084 
1085  if (prefix)
1086  {
1087  mutt_buffer_printf(err, _("Can't use a prefix when querying a variable"));
1088  return MUTT_CMD_WARNING;
1089  }
1090 
1091  query = true;
1092  s->dptr++;
1093  }
1094 
1095  if (query)
1096  {
1097  bool found = false;
1098  while (envp && *envp)
1099  {
1100  /* This will display all matches for "^QUERY" */
1101  if (mutt_str_startswith(*envp, buf->data))
1102  {
1103  if (!found)
1104  {
1105  mutt_endwin();
1106  found = true;
1107  }
1108  puts(*envp);
1109  }
1110  envp++;
1111  }
1112 
1113  if (found)
1114  {
1116  return MUTT_CMD_SUCCESS;
1117  }
1118 
1119  mutt_buffer_printf(err, _("%s is unset"), buf->data);
1120  return MUTT_CMD_WARNING;
1121  }
1122 
1123  if (unset)
1124  {
1125  if (!mutt_envlist_unset(buf->data))
1126  {
1127  mutt_buffer_printf(err, _("%s is unset"), buf->data);
1128  return MUTT_CMD_WARNING;
1129  }
1130  return MUTT_CMD_SUCCESS;
1131  }
1132 
1133  /* set variable */
1134 
1135  if (*s->dptr == '=')
1136  {
1137  s->dptr++;
1138  SKIPWS(s->dptr);
1139  }
1140 
1141  if (!MoreArgs(s))
1142  {
1143  mutt_buffer_printf(err, _("%s: too few arguments"), "setenv");
1144  return MUTT_CMD_WARNING;
1145  }
1146 
1147  char *name = mutt_str_dup(buf->data);
1149  mutt_envlist_set(name, buf->data, true);
1150  FREE(&name);
1151 
1152  return MUTT_CMD_SUCCESS;
1153 }
bool mutt_envlist_unset(const char *name)
Unset an environment variable.
Definition: envlist.c:132
bool mutt_envlist_set(const char *name, const char *value, bool overwrite)
Set an environment variable.
Definition: envlist.c:85
char ** mutt_envlist_getlist(void)
Get the private environment.
Definition: envlist.c:169

◆ parse_source()

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

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

Definition at line 144 of file command_parse.c.

1160 {
1161  char path[PATH_MAX];
1162 
1163  do
1164  {
1165  if (mutt_extract_token(buf, s, MUTT_TOKEN_NO_FLAGS) != 0)
1166  {
1167  mutt_buffer_printf(err, _("source: error at %s"), s->dptr);
1168  return MUTT_CMD_ERROR;
1169  }
1170  mutt_str_copy(path, buf->data, sizeof(path));
1171  mutt_expand_path(path, sizeof(path));
1172 
1173  if (source_rc(path, err) < 0)
1174  {
1175  mutt_buffer_printf(err, _("source: file %s could not be sourced"), path);
1176  return MUTT_CMD_ERROR;
1177  }
1178 
1179  } while (MoreArgs(s));
1180 
1181  return MUTT_CMD_SUCCESS;
1182 }
int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
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:629
#define PATH_MAX
Definition: mutt.h:40
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:122

◆ parse_spam_list()

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

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

Definition at line 144 of file command_parse.c.

1189 {
1190  struct Buffer templ;
1191 
1192  mutt_buffer_init(&templ);
1193 
1194  /* Insist on at least one parameter */
1195  if (!MoreArgs(s))
1196  {
1197  if (data == MUTT_SPAM)
1198  mutt_buffer_strcpy(err, _("spam: no matching pattern"));
1199  else
1200  mutt_buffer_strcpy(err, _("nospam: no matching pattern"));
1201  return MUTT_CMD_ERROR;
1202  }
1203 
1204  /* Extract the first token, a regex */
1206 
1207  /* data should be either MUTT_SPAM or MUTT_NOSPAM. MUTT_SPAM is for spam commands. */
1208  if (data == MUTT_SPAM)
1209  {
1210  /* If there's a second parameter, it's a template for the spam tag. */
1211  if (MoreArgs(s))
1212  {
1214 
1215  /* Add to the spam list. */
1216  if (mutt_replacelist_add(&SpamList, buf->data, templ.data, err) != 0)
1217  {
1218  FREE(&templ.data);
1219  return MUTT_CMD_ERROR;
1220  }
1221  FREE(&templ.data);
1222  }
1223  /* If not, try to remove from the nospam list. */
1224  else
1225  {
1227  }
1228 
1229  return MUTT_CMD_SUCCESS;
1230  }
1231  /* MUTT_NOSPAM is for nospam commands. */
1232  else if (data == MUTT_NOSPAM)
1233  {
1234  /* nospam only ever has one parameter. */
1235 
1236  /* "*" is a special case. */
1237  if (mutt_str_equal(buf->data, "*"))
1238  {
1241  return MUTT_CMD_SUCCESS;
1242  }
1243 
1244  /* If it's on the spam list, just remove it. */
1245  if (mutt_replacelist_remove(&SpamList, buf->data) != 0)
1246  return MUTT_CMD_SUCCESS;
1247 
1248  /* Otherwise, add it to the nospam list. */
1249  if (mutt_regexlist_add(&NoSpamList, buf->data, REG_ICASE, err) != 0)
1250  return MUTT_CMD_ERROR;
1251 
1252  return MUTT_CMD_SUCCESS;
1253  }
1254 
1255  /* This should not happen. */
1256  mutt_buffer_strcpy(err, "This is no good at all.");
1257  return MUTT_CMD_ERROR;
1258 }
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
struct ReplaceList SpamList
List of regexes and patterns to match spam emails.
Definition: globals.c:34
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
Definition: globals.c:33
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:583
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:174
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:467
int mutt_replacelist_add(struct ReplaceList *rl, const char *pat, const char *templ, struct Buffer *err)
Add a pattern and a template to a list.
Definition: regex.c:266
#define MUTT_NOSPAM
Definition: mutt.h:111
#define MUTT_SPAM
Definition: mutt.h:110

◆ parse_stailq()

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

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

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

Definition at line 144 of file command_parse.c.

1267 {
1268  do
1269  {
1271  add_to_stailq((struct ListHead *) data, buf->data);
1272  } while (MoreArgs(s));
1273 
1274  return MUTT_CMD_SUCCESS;
1275 }

◆ parse_subscribe()

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

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

Definition at line 144 of file command_parse.c.

1282 {
1283  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1284 
1285  do
1286  {
1288 
1289  if (parse_grouplist(&gl, buf, s, err) == -1)
1290  goto bail;
1291 
1294 
1295  if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
1296  goto bail;
1297  if (mutt_regexlist_add(&SubscribedLists, buf->data, REG_ICASE, err) != 0)
1298  goto bail;
1299  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
1300  goto bail;
1301  } while (MoreArgs(s));
1302 
1304  return MUTT_CMD_SUCCESS;
1305 
1306 bail:
1308  return MUTT_CMD_ERROR;
1309 }
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: globals.c:43
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
Definition: globals.c:40

◆ 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 144 of file command_parse.c.

1321 {
1322  if (!buf || !s || !err)
1323  return MUTT_CMD_ERROR;
1324 
1325  mutt_buffer_reset(err);
1326 
1327  if (MoreArgs(s))
1328  {
1330 
1331  if (MoreArgs(s))
1332  {
1333  mutt_buffer_printf(err, _("%s: too many arguments"), "subscribe-to");
1334  return MUTT_CMD_WARNING;
1335  }
1336 
1337  if (buf->data && (*buf->data != '\0'))
1338  {
1339  /* Expand and subscribe */
1340  if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), true) == 0)
1341  {
1342  mutt_message(_("Subscribed to %s"), buf->data);
1343  return MUTT_CMD_SUCCESS;
1344  }
1345 
1346  mutt_buffer_printf(err, _("Could not subscribe to %s"), buf->data);
1347  return MUTT_CMD_ERROR;
1348  }
1349 
1350  mutt_debug(LL_DEBUG1, "Corrupted buffer");
1351  return MUTT_CMD_ERROR;
1352  }
1353 
1354  mutt_buffer_addstr(err, _("No folder specified"));
1355  return MUTT_CMD_WARNING;
1356 }
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1289
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40

◆ parse_tag_formats()

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

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

Parse config like: tag-formats pgp GP

Note
This maps format -> tag

Definition at line 144 of file command_parse.c.

1368 {
1369  if (!s)
1370  return MUTT_CMD_ERROR;
1371 
1372  struct Buffer *tagbuf = mutt_buffer_pool_get();
1373  struct Buffer *fmtbuf = mutt_buffer_pool_get();
1374 
1375  while (MoreArgs(s))
1376  {
1378  const char *tag = mutt_buffer_string(tagbuf);
1379  if (*tag == '\0')
1380  continue;
1381 
1383  const char *fmt = mutt_buffer_string(fmtbuf);
1384 
1385  /* avoid duplicates */
1386  const char *tmp = mutt_hash_find(TagFormats, fmt);
1387  if (tmp)
1388  {
1389  mutt_warning(_("tag format '%s' already registered as '%s'"), fmt, tmp);
1390  continue;
1391  }
1392 
1394  }
1395 
1396  mutt_buffer_pool_release(&tagbuf);
1397  mutt_buffer_pool_release(&fmtbuf);
1398  return MUTT_CMD_SUCCESS;
1399 }
#define mutt_warning(...)
Definition: logging.h:85
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
Definition: hash.c:335
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:362
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
struct HashTable * TagFormats
Hash Table of tag-formats (tag -> format string)
Definition: tags.c:39

◆ parse_tag_transforms()

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

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

Parse config like: tag-transforms pgp P

Note
This maps tag -> transform

Definition at line 144 of file command_parse.c.

1410 {
1411  if (!s)
1412  return MUTT_CMD_ERROR;
1413 
1414  struct Buffer *tagbuf = mutt_buffer_pool_get();
1415  struct Buffer *trnbuf = mutt_buffer_pool_get();
1416 
1417  while (MoreArgs(s))
1418  {
1420  const char *tag = mutt_buffer_string(tagbuf);
1421  if (*tag == '\0')
1422  continue;
1423 
1425  const char *trn = mutt_buffer_string(trnbuf);
1426 
1427  /* avoid duplicates */
1428  const char *tmp = mutt_hash_find(TagTransforms, tag);
1429  if (tmp)
1430  {
1431  mutt_warning(_("tag transform '%s' already registered as '%s'"), tag, tmp);
1432  continue;
1433  }
1434 
1436  }
1437 
1438  mutt_buffer_pool_release(&tagbuf);
1439  mutt_buffer_pool_release(&trnbuf);
1440  return MUTT_CMD_SUCCESS;
1441 }
struct HashTable * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38

◆ parse_unignore()

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

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

Definition at line 144 of file command_parse.c.

1448 {
1449  do
1450  {
1452 
1453  /* don't add "*" to the unignore list */
1454  if (strcmp(buf->data, "*") != 0)
1455  add_to_stailq(&UnIgnore, buf->data);
1456 
1457  remove_from_stailq(&Ignore, buf->data);
1458  } while (MoreArgs(s));
1459 
1460  return MUTT_CMD_SUCCESS;
1461 }

◆ parse_unlists()

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

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

Definition at line 144 of file command_parse.c.

1468 {
1470  do
1471  {
1475 
1476  if (!mutt_str_equal(buf->data, "*") &&
1477  (mutt_regexlist_add(&UnMailLists, buf->data, REG_ICASE, err) != 0))
1478  {
1479  return MUTT_CMD_ERROR;
1480  }
1481  } while (MoreArgs(s));
1482 
1483  return MUTT_CMD_SUCCESS;
1484 }
struct HashTable * AutoSubscribeCache
Hash Table of auto-subscribed mailing lists.
Definition: globals.c:38
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457

◆ 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 1513 of file command_parse.c.

1533 {
1534  while (MoreArgs(s))
1535  {
1537 
1538  if (mutt_str_equal(buf->data, "*"))
1539  {
1541  return MUTT_CMD_SUCCESS;
1542  }
1543 
1545 
1546  struct Account *a = NULL;
1547  TAILQ_FOREACH(a, &NeoMutt->accounts, entries)
1548  {
1549  struct Mailbox *m = mx_mbox_find(a, mutt_buffer_string(buf));
1550  if (m)
1551  {
1552  do_unmailboxes(m);
1553  break;
1554  }
1555  }
1556  }
1557  return MUTT_CMD_SUCCESS;
1558 }
static void do_unmailboxes_star(void)
Remove all Mailboxes from the Sidebar/notifications.
static void do_unmailboxes(struct Mailbox *m)
Remove a Mailbox from the Sidebar/notifications.
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40

◆ parse_unmy_hdr()

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

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

Definition at line 1513 of file command_parse.c.

1565 {
1566  struct ListNode *np = NULL, *tmp = NULL;
1567  size_t l;
1568 
1569  do
1570  {
1572  if (mutt_str_equal("*", buf->data))
1573  {
1574  /* Clear all headers, send a notification for each header */
1575  STAILQ_FOREACH(np, &UserHeader, entries)
1576  {
1577  mutt_debug(LL_NOTIFY, "NT_HEADER_DELETE: %s\n", np->data);
1578  struct EventHeader ev_h = { np->data };
1580  }
1582  continue;
1583  }
1584 
1585  l = mutt_str_len(buf->data);
1586  if (buf->data[l - 1] == ':')
1587  l--;
1588 
1589  STAILQ_FOREACH_SAFE(np, &UserHeader, entries, tmp)
1590  {
1591  if (mutt_istrn_equal(buf->data, np->data, l) && (np->data[l] == ':'))
1592  {
1593  mutt_debug(LL_NOTIFY, "NT_HEADER_DELETE: %s\n", np->data);
1594  struct EventHeader ev_h = { np->data };
1596 
1597  header_free(&UserHeader, np);
1598  }
1599  }
1600  } while (MoreArgs(s));
1601  return MUTT_CMD_SUCCESS;
1602 }
void header_free(struct ListHead *hdrlist, struct ListNode *target)
Free and remove a header from a header list.
Definition: email.c:245
@ NT_HEADER_DELETE
Header has been removed.
Definition: email.h:173
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:544
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:501
#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

◆ parse_unstailq()

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

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

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

Definition at line 1513 of file command_parse.c.

1611 {
1612  do
1613  {
1615  /* Check for deletion of entire list */
1616  if (mutt_str_equal(buf->data, "*"))
1617  {
1618  mutt_list_free((struct ListHead *) data);
1619  break;
1620  }
1621  remove_from_stailq((struct ListHead *) data, buf->data);
1622  } while (MoreArgs(s));
1623 
1624  return MUTT_CMD_SUCCESS;
1625 }

◆ parse_unsubscribe()

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

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

Definition at line 1513 of file command_parse.c.

1632 {
1634  do
1635  {
1638 
1639  if (!mutt_str_equal(buf->data, "*") &&
1640  (mutt_regexlist_add(&UnSubscribedLists, buf->data, REG_ICASE, err) != 0))
1641  {
1642  return MUTT_CMD_ERROR;
1643  }
1644  } while (MoreArgs(s));
1645 
1646  return MUTT_CMD_SUCCESS;
1647 }

◆ 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 1513 of file command_parse.c.

1659 {
1660  if (!buf || !s || !err)
1661  return MUTT_CMD_ERROR;
1662 
1663  if (MoreArgs(s))
1664  {
1666 
1667  if (MoreArgs(s))
1668  {
1669  mutt_buffer_printf(err, _("%s: too many arguments"), "unsubscribe-from");
1670  return MUTT_CMD_WARNING;
1671  }
1672 
1673  if (buf->data && (*buf->data != '\0'))
1674  {
1675  /* Expand and subscribe */
1676  if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), false) == 0)
1677  {
1678  mutt_message(_("Unsubscribed from %s"), buf->data);
1679  return MUTT_CMD_SUCCESS;
1680  }
1681 
1682  mutt_buffer_printf(err, _("Could not unsubscribe from %s"), buf->data);
1683  return MUTT_CMD_ERROR;
1684  }
1685 
1686  mutt_debug(LL_DEBUG1, "Corrupted buffer");
1687  return MUTT_CMD_ERROR;
1688  }
1689 
1690  mutt_buffer_addstr(err, _("No folder specified"));
1691  return MUTT_CMD_WARNING;
1692 }

◆ 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 75 of file hook.c.

82 {
83  struct Buffer *alias = mutt_buffer_pool_get();
84  struct Buffer *charset = mutt_buffer_pool_get();
85 
86  int rc = MUTT_CMD_ERROR;
87  int retval = 0;
88 
89  retval += mutt_extract_token(alias, s, MUTT_TOKEN_NO_FLAGS);
90  retval += mutt_extract_token(charset, s, MUTT_TOKEN_NO_FLAGS);
91  if (retval != 0)
92  goto done;
93 
95 
96  if (mutt_buffer_is_empty(alias) || mutt_buffer_is_empty(charset))
97  {
98  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
99  rc = MUTT_CMD_WARNING;
100  }
101  else if (MoreArgs(s))
102  {
103  mutt_buffer_printf(err, _("%s: too many arguments"), buf->data);
104  mutt_buffer_reset(s); // clean up buffer to avoid a mess with further rcfile processing
105  rc = MUTT_CMD_WARNING;
106  }
107  else if (mutt_ch_lookup_add(type, mutt_buffer_string(alias),
108  mutt_buffer_string(charset), err))
109  {
110  rc = MUTT_CMD_SUCCESS;
111  }
112 
113 done:
114  mutt_buffer_pool_release(&alias);
115  mutt_buffer_pool_release(&charset);
116 
117  return rc;
118 }
#define MUTT_ICONV_HOOK
iconv-hook: create a system charset alias
Definition: hook.h:44
bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err)
Add a new character set lookup.
Definition: charset.c:484
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

◆ 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 75 of file hook.c.

127 {
128  struct Hook *hook = NULL;
129  int rc = MUTT_CMD_ERROR;
130  bool pat_not = false;
131  bool use_regex = true;
132  regex_t *rx = NULL;
133  struct PatternList *pat = NULL;
134  const bool folder_or_mbox = (data & (MUTT_FOLDER_HOOK | MUTT_MBOX_HOOK));
135 
136  struct Buffer *cmd = mutt_buffer_pool_get();
137  struct Buffer *pattern = mutt_buffer_pool_get();
138 
139  if (~data & MUTT_GLOBAL_HOOK) /* NOT a global hook */
140  {
141  if (*s->dptr == '!')
142  {
143  s->dptr++;
144  SKIPWS(s->dptr);
145  pat_not = true;
146  }
147 
149  if (folder_or_mbox && mutt_str_equal(mutt_buffer_string(pattern), "-noregex"))
150  {
151  use_regex = false;
152  if (!MoreArgs(s))
153  {
154  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
155  rc = MUTT_CMD_WARNING;
156  goto cleanup;
157  }
159  }
160 
161  if (!MoreArgs(s))
162  {
163  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
164  rc = MUTT_CMD_WARNING;
165  goto cleanup;
166  }
167  }
168 
169  mutt_extract_token(cmd, s,
174 
175  if (mutt_buffer_is_empty(cmd))
176  {
177  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
178  rc = MUTT_CMD_WARNING;
179  goto cleanup;
180  }
181 
182  if (MoreArgs(s))
183  {
184  mutt_buffer_printf(err, _("%s: too many arguments"), buf->data);
185  rc = MUTT_CMD_WARNING;
186  goto cleanup;
187  }
188 
189  const char *const c_default_hook = cs_subset_string(NeoMutt->sub, "default_hook");
190  if (folder_or_mbox)
191  {
192  /* Accidentally using the ^ mailbox shortcut in the .neomuttrc is a
193  * common mistake */
194  if ((pattern->data[0] == '^') && !CurrentFolder)
195  {
196  mutt_buffer_strcpy(err, _("current mailbox shortcut '^' is unset"));
197  goto cleanup;
198  }
199 
200  struct Buffer *tmp = mutt_buffer_pool_get();
201  mutt_buffer_copy(tmp, pattern);
202  mutt_buffer_expand_path_regex(tmp, use_regex);
203 
204  /* Check for other mailbox shortcuts that expand to the empty string.
205  * This is likely a mistake too */
206  if (mutt_buffer_is_empty(tmp) && !mutt_buffer_is_empty(pattern))
207  {
208  mutt_buffer_strcpy(err, _("mailbox shortcut expanded to empty regex"));
210  goto cleanup;
211  }
212 
213  if (use_regex)
214  {
215  mutt_buffer_copy(pattern, tmp);
216  }
217  else
218  {
220  }
222  }
223 #ifdef USE_COMP_MBOX
225  {
227  {
228  mutt_buffer_strcpy(err, _("badly formatted command string"));
229  goto cleanup;
230  }
231  }
232 #endif
233  else if (c_default_hook && (~data & MUTT_GLOBAL_HOOK) &&
235  {
236  /* At this stage remain only message-hooks, reply-hooks, send-hooks,
237  * send2-hooks, save-hooks, and fcc-hooks: All those allowing full
238  * patterns. If given a simple regex, we expand $default_hook. */
239  mutt_check_simple(pattern, c_default_hook);
240  }
241 
243  {
245  }
246 
247  /* check to make sure that a matching hook doesn't already exist */
248  TAILQ_FOREACH(hook, &Hooks, entries)
249  {
250  if (data & MUTT_GLOBAL_HOOK)
251  {
252  /* Ignore duplicate global hooks */
253  if (mutt_str_equal(hook->command, mutt_buffer_string(cmd)))
254  {
255  rc = MUTT_CMD_SUCCESS;
256  goto cleanup;
257  }
258  }
259  else if ((hook->type == data) && (hook->regex.pat_not == pat_not) &&
261  {
265  {
266  /* these hooks allow multiple commands with the same
267  * pattern, so if we've already seen this pattern/command pair, just
268  * ignore it instead of creating a duplicate */
269  if (mutt_str_equal(hook->command, mutt_buffer_string(cmd)))
270  {
271  rc = MUTT_CMD_SUCCESS;
272  goto cleanup;
273  }
274  }
275  else
276  {
277  /* other hooks only allow one command per pattern, so update the
278  * entry with the new command. this currently does not change the
279  * order of execution of the hooks, which i think is desirable since
280  * a common action to perform is to change the default (.) entry
281  * based upon some other information. */
282  FREE(&hook->command);
283  hook->command = mutt_buffer_strdup(cmd);
284  rc = MUTT_CMD_SUCCESS;
285  goto cleanup;
286  }
287  }
288  }
289 
292  {
293  PatternCompFlags comp_flags;
294 
295  if (data & (MUTT_SEND2_HOOK))
296  comp_flags = MUTT_PC_SEND_MODE_SEARCH;
297  else if (data & (MUTT_SEND_HOOK | MUTT_FCC_HOOK))
298  comp_flags = MUTT_PC_NO_FLAGS;
299  else
300  comp_flags = MUTT_PC_FULL_MSG;
301 
302  struct Mailbox *m_cur = get_current_mailbox();
303  struct Menu *menu = get_current_menu();
304  pat = mutt_pattern_comp(m_cur, menu, mutt_buffer_string(pattern), comp_flags, err);
305  if (!pat)
306  goto cleanup;
307  }
308  else if (~data & MUTT_GLOBAL_HOOK) /* NOT a global hook */
309  {
310  /* Hooks not allowing full patterns: Check syntax of regex */
311  rx = mutt_mem_calloc(1, sizeof(regex_t));
312  int rc2 = REG_COMP(rx, NONULL(mutt_buffer_string(pattern)),
313  ((data & MUTT_CRYPT_HOOK) ? REG_ICASE : 0));
314  if (rc2 != 0)
315  {
316  regerror(rc2, rx, err->data, err->dsize);
317  FREE(&rx);
318  goto cleanup;
319  }
320  }
321 
322  hook = mutt_mem_calloc(1, sizeof(struct Hook));
323  hook->type = data;
324  hook->command = mutt_buffer_strdup(cmd);
325  hook->pattern = pat;
326  hook->regex.pattern = mutt_buffer_strdup(pattern);
327  hook->regex.regex = rx;
328  hook->regex.pat_not = pat_not;
329  TAILQ_INSERT_TAIL(&Hooks, hook, entries);
330  rc = MUTT_CMD_SUCCESS;
331 
332 cleanup:
334  mutt_buffer_pool_release(&pattern);
335  return rc;
336 }
struct PatternList * mutt_pattern_comp(struct Mailbox *m, struct Menu *menu, const char *s, PatternCompFlags flags, struct Buffer *err)
Create a Pattern.
Definition: compile.c:1160
int mutt_comp_valid_command(const char *cmd)
Is this command string allowed?
Definition: compress.c:411
int mutt_file_sanitize_regex(struct Buffer *dest, const char *src)
Escape any regex-magic characters in a string.
Definition: file.c:666
static struct HookList Hooks
Definition: hook.c:72
#define MUTT_OPEN_HOOK
open-hook: to read a compressed mailbox
Definition: hook.h:51
#define MUTT_FOLDER_HOOK
folder-hook: when entering a mailbox
Definition: hook.h:38
#define MUTT_SAVE_HOOK
save-hook: set a default folder when saving an email
Definition: hook.h:42
#define MUTT_SEND_HOOK
send-hook: when composing a new email
Definition: hook.h:40
#define MUTT_FCC_HOOK
fcc-hook: to save outgoing email
Definition: hook.h:41
#define MUTT_CLOSE_HOOK
close-hook: write to a compressed mailbox
Definition: hook.h:53
#define MUTT_ACCOUNT_HOOK
account-hook: when changing between accounts
Definition: hook.h:47
#define MUTT_APPEND_HOOK
append-hook: append to a compressed mailbox
Definition: hook.h:52
#define MUTT_GLOBAL_HOOK
Hooks which don't take a regex.
Definition: hook.h:59
#define MUTT_STARTUP_HOOK
startup-hook: run when starting NeoMutt
Definition: hook.h:57
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:49
#define MUTT_CRYPT_HOOK
crypt-hook: automatically select a PGP/SMIME key
Definition: hook.h:46
#define MUTT_MBOX_HOOK
mbox-hook: move messages after reading them
Definition: hook.h:39
#define MUTT_REPLY_HOOK
reply-hook: when replying to an email
Definition: hook.h:48
#define MUTT_TIMEOUT_HOOK
timeout-hook: run a command periodically
Definition: hook.h:56
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:45
#define MUTT_SHUTDOWN_HOOK
shutdown-hook: run when leaving NeoMutt
Definition: hook.h:58
struct Menu * get_current_menu(void)
Get the current Menu.
Definition: index.c:629
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition: index.c:603
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
char * CurrentFolder
Currently selected mailbox.
Definition: mutt_globals.h:54
void mutt_buffer_expand_path_regex(struct Buffer *buf, bool regex)
Create the canonical path (with regex char escaping)
Definition: muttlib.c:134
#define WithCrypto
Definition: lib.h:116
#define MUTT_PC_SEND_MODE_SEARCH
Allow send-mode body searching.
Definition: lib.h:64
uint8_t PatternCompFlags
Flags for mutt_pattern_comp(), e.g. MUTT_PC_FULL_MSG.
Definition: lib.h:60
#define MUTT_PC_FULL_MSG
Enable body and header matching.
Definition: lib.h:62
void mutt_check_simple(struct Buffer *s, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:116
#define MUTT_PC_NO_FLAGS
No flags are set.
Definition: lib.h:61
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:53
#define NONULL(x)
Definition: string2.h:37
A list of user hooks.
Definition: hook.c:63
HookFlags type
Hook type.
Definition: hook.c:64
struct PatternList * pattern
Used for fcc,save,send-hook.
Definition: hook.c:67
struct Regex regex
Regular expression.
Definition: hook.c:65
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
Definition: lib.h:69
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 caller graph for this function:

◆ mutt_parse_idxfmt_hook()

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

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

Definition at line 397 of file hook.c.

407 {
408  enum CommandResult rc = MUTT_CMD_ERROR;
409  bool pat_not = false;
410 
411  struct Buffer *name = mutt_buffer_pool_get();
412  struct Buffer *pattern = mutt_buffer_pool_get();
413  struct Buffer *fmtstring = mutt_buffer_pool_get();
414 
415  if (!IdxFmtHooks)
416  {
419  }
420 
421  if (!MoreArgs(s))
422  {
423  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
424  goto out;
425  }
427  struct HookList *hl = mutt_hash_find(IdxFmtHooks, mutt_buffer_string(name));
428 
429  if (*s->dptr == '!')
430  {
431  s->dptr++;
432  SKIPWS(s->dptr);
433  pat_not = true;
434  }
436 
437  if (!MoreArgs(s))
438  {
439  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
440  goto out;
441  }
443 
444  if (MoreArgs(s))
445  {
446  mutt_buffer_printf(err, _("%s: too many arguments"), buf->data);
447  goto out;
448  }
449 
450  const char *const c_default_hook = cs_subset_string(NeoMutt->sub, "default_hook");
451  if (c_default_hook)
452  mutt_check_simple(pattern, c_default_hook);
453 
454  /* check to make sure that a matching hook doesn't already exist */
455  struct Hook *hook = NULL;
456  if (hl)
457  {
458  TAILQ_FOREACH(hook, hl, entries)
459  {
460  if ((hook->regex.pat_not == pat_not) &&
462  {
463  mutt_str_replace(&hook->command, mutt_buffer_string(fmtstring));
464  rc = MUTT_CMD_SUCCESS;
465  goto out;
466  }
467  }
468  }
469 
470  /* MUTT_PC_PATTERN_DYNAMIC sets so that date ranges are regenerated during
471  * matching. This of course is slower, but index-format-hook is commonly
472  * used for date ranges, and they need to be evaluated relative to "now", not
473  * the hook compilation time. */
474  struct Mailbox *m_cur = get_current_mailbox();
475  struct Menu *menu = get_current_menu();
476  struct PatternList *pat = mutt_pattern_comp(m_cur, menu, mutt_buffer_string(pattern),
478  err);
479  if (!pat)
480  goto out;
481 
482  hook = mutt_mem_calloc(1, sizeof(struct Hook));
483  hook->type = MUTT_IDXFMTHOOK;
484  hook->command = mutt_buffer_strdup(fmtstring);
485  hook->pattern = pat;
486  hook->regex.pattern = mutt_buffer_strdup(pattern);
487  hook->regex.regex = NULL;
488  hook->regex.pat_not = pat_not;
489 
490  if (!hl)
491  {
492  hl = mutt_mem_calloc(1, sizeof(*hl));
493  TAILQ_INIT(hl);
495  }
496 
497  TAILQ_INSERT_TAIL(hl, hook, entries);
498  rc = MUTT_CMD_SUCCESS;
499 
500 out:
502  mutt_buffer_pool_release(&pattern);
503  mutt_buffer_pool_release(&fmtstring);
504 
505  return rc;
506 }
static void idxfmt_hashelem_free(int type, void *obj, intptr_t data)
Delete an index-format-hook from the Hash Table - Implements hash_hdata_free_t -.
Definition: hook.c:379
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:111
static struct HashTable * IdxFmtHooks
Definition: hook.c:74
#define MUTT_IDXFMTHOOK
index-format-hook: customise the format of the index
Definition: hook.h:55
#define MUTT_PC_PATTERN_DYNAMIC
Enable runtime date range evaluation.
Definition: lib.h:63
#define TAILQ_INIT(head)
Definition: queue.h:765
+ Here is the caller graph for this function:

◆ mutt_parse_unhook()

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

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

Definition at line 397 of file hook.c.

513 {
514  while (MoreArgs(s))
515  {
517  if (mutt_str_equal("*", buf->data))
518  {
520  {
521  mutt_buffer_printf(err, "%s", _("unhook: Can't do unhook * from within a hook"));
522  return MUTT_CMD_WARNING;
523  }
527  }
528  else
529  {
530  HookFlags type = mutt_get_hook_type(buf->data);
531 
532  if (type == MUTT_HOOK_NO_FLAGS)
533  {
534  mutt_buffer_printf(err, _("unhook: unknown hook type: %s"), buf->data);
535  return MUTT_CMD_ERROR;
536  }
537  if (type & (MUTT_CHARSET_HOOK | MUTT_ICONV_HOOK))
538  {
540  return MUTT_CMD_SUCCESS;
541  }
542  if (current_hook_type == type)
543  {
544  mutt_buffer_printf(err, _("unhook: Can't delete a %s from within a %s"),
545  buf->data, buf->data);
546  return MUTT_CMD_WARNING;
547  }
548  if (type == MUTT_IDXFMTHOOK)
550  else
551  mutt_delete_hooks(type);
552  }
553  }
554  return MUTT_CMD_SUCCESS;
555 }
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
Definition: hook.c:361
static void delete_idxfmt_hooks(void)
Delete all the index-format-hooks.
Definition: hook.c:397
static HookFlags current_hook_type
Definition: hook.c:75
uint32_t HookFlags
Flags for mutt_parse_hook(), e.g. MUTT_FOLDER_HOOK.
Definition: hook.h:34
#define MUTT_CHARSET_HOOK
charset-hook: create a charset alias for malformed emails
Definition: hook.h:43
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:37
HookFlags mutt_get_hook_type(const char *name)
Find a hook by name.
Definition: init.c:698
void mutt_ch_lookup_remove(void)
Remove all the character set lookups.
Definition: charset.c:516

◆ 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 1062 of file keymap.c.

1120 {
1122  if (MoreArgs(s))
1123  {
1124  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1125  return MUTT_CMD_ERROR;
1126  }
1127 
1129  return MUTT_CMD_SUCCESS;
1130 }
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:672
static void generic_tokenize_push_string(char *s, void(*generic_push)(int, int))
Parse and queue a 'push' command.
Definition: keymap.c:538
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:68

◆ 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 1231 of file keymap.c.

1283 {
1284  const struct MenuFuncOp *funcs = NULL;
1285  enum MenuType mtypes[MenuNamesLen];
1286  int num_menus = 0;
1287  enum CommandResult rc = MUTT_CMD_SUCCESS;
1288 
1289  char *key = parse_keymap(mtypes, s, mutt_array_size(mtypes), &num_menus, err, true);
1290  if (!key)
1291  return MUTT_CMD_ERROR;
1292 
1293  /* function to execute */
1295  if (MoreArgs(s))
1296  {
1297  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1298  rc = MUTT_CMD_ERROR;
1299  }
1300  else if (mutt_istr_equal("noop", buf->data))
1301  {
1302  for (int i = 0; i < num_menus; i++)
1303  {
1304  km_bindkey(key, mtypes[i], OP_NULL); /* the 'unbind' command */
1305  funcs = km_get_table(mtypes[i]);
1306  if (funcs)
1307  {
1308  char keystr[32] = { 0 };
1309  km_expand_key_string(key, keystr, sizeof(keystr));
1310  const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1311  mutt_debug(LL_NOTIFY, "NT_BINDING_DELETE: %s %s\n", mname, keystr);
1312 
1313  int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1314  struct EventBinding ev_b = { mtypes[i], key, op };
1316  }
1317  }
1318  }
1319  else
1320  {
1321  for (int i = 0; i < num_menus; i++)
1322  {
1323  /* The pager and editor menus don't use the generic map,
1324  * however for other menus try generic first. */
1325  if ((mtypes[i] != MENU_PAGER) && (mtypes[i] != MENU_EDITOR) && (mtypes[i] != MENU_GENERIC))
1326  {
1327  rc = try_bind(key, mtypes[i], buf->data, OpGeneric, err);
1328  if (rc == MUTT_CMD_SUCCESS)
1329  {
1330  char keystr[32] = { 0 };
1331  km_expand_key_string(key, keystr, sizeof(keystr));
1332  const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1333  mutt_debug(LL_NOTIFY, "NT_BINDING_NEW: %s %s\n", mname, keystr);
1334 
1335  int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1336  struct EventBinding ev_b = { mtypes[i], key, op };
1338  continue;
1339  }
1340  if (rc == MUTT_CMD_WARNING)
1341  break;
1342  }
1343 
1344  /* Clear any error message, we're going to try again */
1345  err->data[0] = '\0';
1346  funcs = km_get_table(mtypes[i]);
1347  if (funcs)
1348  {
1349  rc = try_bind(key, mtypes[i], buf->data, funcs, err);
1350  if (rc == MUTT_CMD_SUCCESS)
1351  {
1352  char keystr[32] = { 0 };
1353  km_expand_key_string(key, keystr, sizeof(keystr));
1354  const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1355  mutt_debug(LL_NOTIFY, "NT_BINDING_NEW: %s %s\n", mname, keystr);
1356 
1357  int op = get_op(funcs, buf->data, mutt_str_len(buf->data));
1358  struct EventBinding ev_b = { mtypes[i], key, op };
1360  continue;
1361  }
1362  }
1363  }
1364  }
1365  FREE(&key);
1366  return rc;
1367 }
const struct MenuFuncOp OpGeneric[]
Functions for the Generic Menu.
Definition: functions.c:287
static int km_expand_key_string(char *str, char *buf, size_t buflen)
Get a human-readable key string.
Definition: keymap.c:904
static enum CommandResult km_bindkey(const char *s, enum MenuType mtype, int op)
Bind a key in a Menu to an operation.
Definition: keymap.c:484
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: keymap.c:1231
static enum CommandResult try_bind(char *key, enum MenuType mtype, char *func, const struct MenuFuncOp *funcs, struct Buffer *err)
Try to make a key binding.
Definition: keymap.c:1208
static char * parse_keymap(enum MenuType *mtypes, struct Buffer *s, int max_menus, int *num_menus, struct Buffer *err, bool bind)
Parse a user-config key binding.
Definition: keymap.c:1146
static int get_op(const struct MenuFuncOp *funcs, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:496
@ NT_BINDING_DELETE
Key binding has been deleted.
Definition: keymap.h:126
@ NT_BINDING_ADD
Key binding has been added.
Definition: keymap.h:125
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
#define mutt_array_size(x)
Definition: memory.h:33
@ NT_BINDING
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:40
A key binding Event.
Definition: keymap.h:110
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:112
int op
Operation the key's bound to (for bind), e.g. OP_DELETE.
Definition: keymap.h:113
Mapping between a function and an operation.
Definition: keymap.h:92
int op
Operation, e.g. OP_DELETE.
Definition: keymap.h:94
const int MenuNamesLen
Definition: type.c:59
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:31
MenuType
Types of GUI selections.
Definition: type.h:36
@ MENU_GENERIC
Generic selection list.
Definition: type.h:45
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:54
@ MENU_EDITOR
Text entry area.
Definition: type.h:43

◆ 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 1407 of file keymap.c.

1433 {
1434  bool menu_matches[MENU_MAX] = { 0 };
1435  bool all_keys = false;
1436  char *key = NULL;
1437 
1439  if (mutt_str_equal(buf->data, "*"))
1440  {
1441  for (enum MenuType i = 0; i < MENU_MAX; i++)
1442  menu_matches[i] = true;
1443  }
1444  else
1445  parse_menu(menu_matches, buf->data, err);
1446 
1447  if (MoreArgs(s))
1448  {
1450  key = buf->data;
1451  }
1452  else
1453  all_keys = true;
1454 
1455  if (MoreArgs(s))
1456  {
1457  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1458 
1459  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1460  return MUTT_CMD_ERROR;
1461  }
1462 
1463  for (enum MenuType i = 0; i < MENU_MAX; i++)
1464  {
1465  if (!menu_matches[i])
1466  continue;
1467  if (all_keys)
1468  {
1469  km_unbind_all(&Keymaps[i], data);
1470  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1471  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1472  km_bindkey("<enter>", MENU_INDEX, OP_DISPLAY_MESSAGE);
1473  km_bindkey("<return>", MENU_INDEX, OP_DISPLAY_MESSAGE);
1474  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1475  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1476  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1477  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1478  if (i != MENU_EDITOR)
1479  {
1480  km_bindkey("?", i, OP_HELP);
1481  km_bindkey("q", i, OP_EXIT);
1482  }
1483 
1484  const char *mname = mutt_map_get_name(i, MenuNames);
1485  mutt_debug(LL_NOTIFY, "NT_MACRO_DELETE_ALL: %s\n", mname);
1486 
1487  struct EventBinding ev_b = { i, NULL, OP_NULL };
1490  &ev_b);
1491  }
1492  else
1493  {
1494  char keystr[32] = { 0 };
1495  km_expand_key_string(key, keystr, sizeof(keystr));
1496  const char *mname = mutt_map_get_name(i, MenuNames);
1497  mutt_debug(LL_NOTIFY, "NT_MACRO_DELETE: %s %s\n", mname, keystr);
1498 
1499  km_bindkey(key, i, OP_NULL);
1500  struct EventBinding ev_b = { i, key, OP_NULL };
1502  (data & MUTT_UNMACRO) ? NT_MACRO_DELETE : NT_BINDING_DELETE, &ev_b);
1503  }
1504  }
1505 
1506  return MUTT_CMD_SUCCESS;
1507 }
static void * parse_menu(bool *menus, char *s, struct Buffer *err)
Parse menu-names into an array.
Definition: keymap.c:1378
static void km_unbind_all(struct KeymapList *km_list, unsigned long mode)
Free all the keys in the supplied Keymap.
Definition: keymap.c:1407
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:126
@ NT_MACRO_DELETE
Key macro has been deleted.
Definition: keymap.h:130
@ NT_MACRO_DELETE_ALL
All key macros have been deleted.
Definition: keymap.h:131
@ NT_BINDING_DELETE_ALL
All key bindings have been deleted.
Definition: keymap.h:127
#define MUTT_UNMACRO
Definition: keymap.h:34
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:50
@ MENU_MAX
Definition: type.h:59

◆ 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 1407 of file keymap.c.

1516 {
1517  enum MenuType mtypes[MenuNamesLen];
1518  int num_menus = 0;
1519  enum CommandResult rc = MUTT_CMD_ERROR;
1520 
1521  char *key = parse_keymap(mtypes, s, mutt_array_size(mtypes), &num_menus, err, false);
1522  if (!key)
1523  return MUTT_CMD_ERROR;
1524 
1526  /* make sure the macro sequence is not an empty string */
1527  if (buf->data[0] == '\0')
1528  {
1529  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1530  }
1531  else
1532  {
1533  if (MoreArgs(s))
1534  {
1535  char *seq = mutt_str_dup(buf->data);
1537 
1538  if (MoreArgs(s))
1539  {
1540  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1541  }
1542  else
1543  {
1544  for (int i = 0; i < num_menus; i++)
1545  {
1546  rc = km_bind(key, mtypes[i], OP_MACRO, seq, buf->data);
1547  if (rc == MUTT_CMD_SUCCESS)
1548  {
1549  char keystr[32] = { 0 };
1550  km_expand_key_string(key, keystr, sizeof(keystr));
1551  const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1552  mutt_debug(LL_NOTIFY, "NT_MACRO_NEW: %s %s\n", mname, keystr);
1553 
1554  struct EventBinding ev_b = { mtypes[i], key, OP_MACRO };
1556  continue;
1557  }
1558  }
1559  }
1560 
1561  FREE(&seq);
1562  }
1563  else
1564  {
1565  for (int i = 0; i < num_menus; i++)
1566  {
1567  rc = km_bind(key, mtypes[i], OP_MACRO, buf->data, NULL);
1568  if (rc == MUTT_CMD_SUCCESS)
1569  {
1570  char keystr[32] = { 0 };
1571  km_expand_key_string(key, keystr, sizeof(keystr));
1572  const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1573  mutt_debug(LL_NOTIFY, "NT_MACRO_NEW: %s %s\n", mname, keystr);
1574 
1575  struct EventBinding ev_b = { mtypes[i], key, OP_MACRO };
1577  continue;
1578  }
1579  }
1580  }
1581  }
1582  FREE(&key);
1583  return rc;
1584 }
enum CommandResult km_bind(char *s, enum MenuType mtype, int op, char *macro, char *desc)
Bind a key to a macro.
Definition: keymap.c:458
@ NT_MACRO_ADD
Key macro has been added.
Definition: keymap.h:129

◆ 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 1407 of file keymap.c.

1591 {
1592  int ops[128];
1593  int nops = 0;
1594  const struct MenuFuncOp *funcs = NULL;
1595  char *function = NULL;
1596 
1597  if (!MoreArgs(s))
1598  {
1599  mutt_buffer_strcpy(err, _("exec: no arguments"));
1600  return MUTT_CMD_ERROR;
1601  }
1602 
1603  do
1604  {
1606  function = buf->data;
1607 
1608  const enum MenuType mtype = menu_get_current_type();
1609  funcs = km_get_table(mtype);
1610  if (!funcs && (mtype != MENU_PAGER))
1611  funcs = OpGeneric;
1612 
1613  ops[nops] = get_op(funcs, function, mutt_str_len(function));
1614  if ((ops[nops] == OP_NULL) && (mtype != MENU_PAGER) && (mtype != MENU_GENERIC))
1615  {
1616  ops[nops] = get_op(OpGeneric, function, mutt_str_len(function));
1617  }
1618 
1619  if (ops[nops] == OP_NULL)
1620  {
1621  mutt_flushinp();
1622  mutt_error(_("%s: no such function"), function);
1623  return MUTT_CMD_ERROR;
1624  }
1625  nops++;
1626  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1627 
1628  while (nops)
1629  mutt_push_macro_event(0, ops[--nops]);
1630 
1631  return MUTT_CMD_SUCCESS;
1632 }
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:703
enum MenuType menu_get_current_type(void)
Get the type of the current Window.
Definition: menu.c:84

◆ 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 469 of file mutt_lua.c.

479 {
480  lua_init(&LuaState);
481  mutt_debug(LL_DEBUG2, " * mutt_lua_parse(%s)\n", buf->data);
482 
483  if (luaL_dostring(LuaState, s->dptr))
484  {
485  mutt_debug(LL_DEBUG2, " * %s -> failure\n", s->dptr);
486  mutt_buffer_printf(err, "%s: %s", s->dptr, lua_tostring(LuaState, -1));
487  /* pop error message from the stack */
488  lua_pop(LuaState, 1);
489  return MUTT_CMD_ERROR;
490  }
491  mutt_debug(LL_DEBUG2, " * %s -> success\n", s->dptr);
492  mutt_buffer_reset(s); // Clear the rest of the line
493  return MUTT_CMD_SUCCESS;
494 }
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
static bool lua_init(lua_State **l)
Initialise a Lua State.
Definition: mutt_lua.c:441
lua_State * LuaState
Global Lua State.
Definition: mutt_lua.c:56

◆ 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 469 of file mutt_lua.c.

501 {
502  mutt_debug(LL_DEBUG2, " * mutt_lua_source()\n");
503 
504  lua_init(&LuaState);
505 
506  char path[PATH_MAX];
507 
508  if (mutt_extract_token(buf, s, MUTT_TOKEN_NO_FLAGS) != 0)
509  {
510  mutt_buffer_printf(err, _("source: error at %s"), s->dptr);
511  return MUTT_CMD_ERROR;
512  }
513  if (MoreArgs(s))
514  {
515  mutt_buffer_printf(err, _("%s: too many arguments"), "source");
516  return MUTT_CMD_WARNING;
517  }
518  mutt_str_copy(path, buf->data, sizeof(path));
519  mutt_expand_path(path, sizeof(path));
520 
521  if (luaL_dofile(LuaState, path))
522  {
523  mutt_error(_("Couldn't source lua source: %s"), lua_tostring(LuaState, -1));
524  lua_pop(LuaState, 1);
525  return MUTT_CMD_ERROR;
526  }
527  return MUTT_CMD_SUCCESS;
528 }

◆ 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 63 of file score.c.

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

◆ 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 159 of file score.c.

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

◆ sb_parse_whitelist()

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

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

Definition at line 1 of file commands.c.

43 {
44  struct Buffer *path = mutt_buffer_pool_get();
45 
46  do
47  {
51  } while (MoreArgs(s));
53 
54  return MUTT_CMD_SUCCESS;
55 }
struct ListHead SidebarWhitelist
List of mailboxes to always display in the sidebar.
Definition: sidebar.c:44
+ Here is the caller graph for this function:

◆ sb_parse_unwhitelist()

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

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

Definition at line 1 of file commands.c.

62 {
63  struct Buffer *path = mutt_buffer_pool_get();
64 
65  do
66  {
68  /* Check for deletion of entire list */
69  if (mutt_str_equal(mutt_buffer_string(path), "*"))
70  {
72  break;
73  }
76  } while (MoreArgs(s));
78 
79  return MUTT_CMD_SUCCESS;
80 }
+ 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 54 of file subjectrx.c.

68 {
69  /* First token is a regex. */
70  if (!MoreArgs(s))
71  {
72  mutt_buffer_printf(err, _("%s: too few arguments"), "unsubjectrx");
73  return MUTT_CMD_WARNING;
74  }
75 
77 
78  /* "*" is a special case. */
79  if (mutt_str_equal(buf->data, "*"))
80  {
82  return MUTT_CMD_SUCCESS;
83  }
84 
85  mutt_replacelist_remove(list, buf->data);
86  return MUTT_CMD_SUCCESS;
87 }

◆ 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 54 of file subjectrx.c.

94 {
95  struct Buffer templ = mutt_buffer_make(0);
96 
97  /* First token is a regex. */
98  if (!MoreArgs(s))
99  {
100  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
101  return MUTT_CMD_WARNING;
102  }
104 
105  /* Second token is a replacement template */
106  if (!MoreArgs(s))
107  {
108  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
109  return MUTT_CMD_WARNING;
110  }
112 
113  if (mutt_replacelist_add(list, buf->data, templ.data, err) != 0)
114  {
115  FREE(&templ.data);
116  return MUTT_CMD_ERROR;
117  }
118  FREE(&templ.data);
119 
120  return MUTT_CMD_SUCCESS;
121 }
+ Here is the call 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 146 of file subjectrx.c.

165 {
166  enum CommandResult rc;
167 
168  rc = parse_replace_list(buf, s, &SubjectRegexList, err);
169  if (rc == MUTT_CMD_SUCCESS)
170  {
171  mutt_debug(LL_NOTIFY, "NT_SUBJRX_ADD: %s\n", buf->data);
173  }
174  return rc;
175 }
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:92
@ NT_SUBJRX
Subject Regex has changed, NotifySubjRx.
Definition: notify_type.h:54
static struct Notify * SubjRxNotify
Definition: subjectrx.c:40
static struct ReplaceList SubjectRegexList
Definition: subjectrx.c:39
@ NT_SUBJRX_ADD
Subject Regex has been added.
Definition: subjectrx.h:42

◆ 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 146 of file subjectrx.c.

182 {
183  enum CommandResult rc;
184 
185  rc = parse_unreplace_list(buf, s, &SubjectRegexList, err);
186  if (rc == MUTT_CMD_SUCCESS)
187  {
188  mutt_debug(LL_NOTIFY, "NT_SUBJRX_DELETE: %s\n", buf->data);
190  }
191  return rc;
192 }
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:66
@ NT_SUBJRX_DELETE
Subject Regex has been deleted.
Definition: subjectrx.h:43