NeoMutt  2021-02-05-666-ge300cd
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() -e.g. 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 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() -The 'ifdef' command allows conditional elements in the config file. 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() -This is also used by 'virtual-mailboxes'. 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() -This is used by 'reset', 'set', 'toggle' and 'unset'. 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() -This is used by 'alternative_order', 'auto_view' and several others. 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() -The 'subscribe-to' command allows to subscribe to an IMAP-Mailbox. 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() -This is also used by 'unvirtual-mailboxes'. 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() -This is used by 'unalternative_order', 'unauto_view' and several others. 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() -The 'unsubscribe-from' command allows to unsubscribe from an IMAP-Mailbox. 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 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. 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() -bind menu-name <key_sequence> function-name. 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() -Command unbinds: 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() -macro <menu> <key> <macro> <description> 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 49 of file commands.c.

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

164 {
165  do
166  {
168 
169  struct Alias *np = NULL;
170  if (mutt_str_equal("*", buf->data))
171  {
172  TAILQ_FOREACH(np, &Aliases, entries)
173  {
175  }
176 
178  return MUTT_CMD_SUCCESS;
179  }
180 
181  TAILQ_FOREACH(np, &Aliases, entries)
182  {
183  if (!mutt_istr_equal(buf->data, np->name))
184  continue;
185 
186  TAILQ_REMOVE(&Aliases, np, entries);
188  alias_free(&np);
189  break;
190  }
191  } while (MoreArgs(s));
192  return MUTT_CMD_SUCCESS;
193 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
A shortcut for an email address or addresses.
Definition: alias.h:33
char * name
Short name.
Definition: alias.h:35
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define MoreArgs(buf)
Definition: buffer.h:40
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
struct AliasList Aliases
List of all the user&#39;s email aliases.
Definition: alias.c:57
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
void alias_free(struct Alias **ptr)
Free an Alias.
Definition: alias.c:629
void aliaslist_free(struct AliasList *al)
Free a List of Aliases.
Definition: alias.c:650
Success: Command worked.
Definition: mutt_commands.h:38
void alias_reverse_delete(struct Alias *alias)
Remove an email address lookup for an Alias.
Definition: reverse.c:83
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ parse_alternates()

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

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

Definition at line 90 of file alternates.c.

92 {
93  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
94 
95  do
96  {
98 
99  if (parse_grouplist(&gl, buf, s, err) == -1)
100  goto bail;
101 
103 
104  if (mutt_regexlist_add(&Alternates, buf->data, REG_ICASE, err) != 0)
105  goto bail;
106 
107  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
108  goto bail;
109  } while (MoreArgs(s));
110 
112 
113  mutt_debug(LL_NOTIFY, "NT_ALTERN_ADD: %s\n", buf->data);
115 
116  return MUTT_CMD_SUCCESS;
117 
118 bail:
120  return MUTT_CMD_ERROR;
121 }
int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, struct Buffer *err)
Parse a group context.
struct RegexList UnAlternates
List of regexes to blacklist false matches in Alternates.
Definition: alternates.c:44
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:227
Alternate address has been added.
Definition: alternates.h:40
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
Log of notifications.
Definition: logging.h:45
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:132
Alternates command changed, NotifyAlternates.
Definition: notify_type.h:36
#define MoreArgs(buf)
Definition: buffer.h:40
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:276
static struct Notify * AlternatesNotify
Definition: alternates.c:45
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
struct RegexList Alternates
List of regexes to match the user&#39;s alternate email addresses.
Definition: alternates.c:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Success: Command worked.
Definition: mutt_commands.h:38
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:157
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
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
+ Here is the call graph for this function:

◆ parse_unalternates()

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

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

Definition at line 126 of file alternates.c.

128 {
129  do
130  {
133 
134  if (!mutt_str_equal(buf->data, "*") &&
135  (mutt_regexlist_add(&UnAlternates, buf->data, REG_ICASE, err) != 0))
136  {
137  return MUTT_CMD_ERROR;
138  }
139 
140  } while (MoreArgs(s));
141 
142  mutt_debug(LL_NOTIFY, "NT_ALTERN_DELETE: %s\n", buf->data);
144 
145  return MUTT_CMD_SUCCESS;
146 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
struct RegexList UnAlternates
List of regexes to blacklist false matches in Alternates.
Definition: alternates.c:44
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:227
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
Log of notifications.
Definition: logging.h:45
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:132
Alternates command changed, NotifyAlternates.
Definition: notify_type.h:36
Alternate address has been deleted.
Definition: alternates.h:41
#define MoreArgs(buf)
Definition: buffer.h:40
static struct Notify * AlternatesNotify
Definition: alternates.c:45
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
struct RegexList Alternates
List of regexes to match the user&#39;s alternate email addresses.
Definition: alternates.c:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Success: Command worked.
Definition: mutt_commands.h:38
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
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
+ Here is the call graph for this function:

◆ parse_attachments()

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

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

Definition at line 469 of file attachments.c.

471 {
473  if (!buf->data || (*buf->data == '\0'))
474  {
475  mutt_buffer_strcpy(err, _("attachments: no disposition"));
476  return MUTT_CMD_WARNING;
477  }
478 
479  char *category = buf->data;
480  char op = *category++;
481 
482  if (op == '?')
483  {
484  mutt_endwin();
485  fflush(stdout);
486  printf("\n%s\n\n", _("Current attachments settings:"));
487  print_attach_list(&AttachAllow, '+', "A");
488  print_attach_list(&AttachExclude, '-', "A");
489  print_attach_list(&InlineAllow, '+', "I");
490  print_attach_list(&InlineExclude, '-', "I");
492  return MUTT_CMD_SUCCESS;
493  }
494 
495  if ((op != '+') && (op != '-'))
496  {
497  op = '+';
498  category--;
499  }
500 
501  struct ListHead *head = NULL;
502  if (mutt_istr_startswith("attachment", category))
503  {
504  if (op == '+')
505  head = &AttachAllow;
506  else
507  head = &AttachExclude;
508  }
509  else if (mutt_istr_startswith("inline", category))
510  {
511  if (op == '+')
512  head = &InlineAllow;
513  else
514  head = &InlineExclude;
515  }
516  else
517  {
518  mutt_buffer_strcpy(err, _("attachments: invalid disposition"));
519  return MUTT_CMD_ERROR;
520  }
521 
522  return parse_attach_list(buf, s, head, err);
523 }
struct ListHead InlineAllow
List of inline types to counted.
Definition: attachments.c:58
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define _(a)
Definition: message.h:28
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:422
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
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:310
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:455
static int print_attach_list(struct ListHead *h, const char op, const char *name)
Print a list of attachments.
Definition: attachments.c:453
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
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
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: attachments.c:56
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ parse_unattachments()

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

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

Definition at line 528 of file attachments.c.

530 {
531  char op;
532  char *p = NULL;
533  struct ListHead *head = NULL;
534 
536  if (!buf->data || (*buf->data == '\0'))
537  {
538  mutt_buffer_strcpy(err, _("unattachments: no disposition"));
539  return MUTT_CMD_WARNING;
540  }
541 
542  p = buf->data;
543  op = *p++;
544 
545  if (op == '*')
546  {
551 
552  mutt_debug(LL_NOTIFY, "NT_ATTACH_DELETE_ALL\n");
554  return 0;
555  }
556 
557  if ((op != '+') && (op != '-'))
558  {
559  op = '+';
560  p--;
561  }
562  if (mutt_istr_startswith("attachment", p))
563  {
564  if (op == '+')
565  head = &AttachAllow;
566  else
567  head = &AttachExclude;
568  }
569  else if (mutt_istr_startswith("inline", p))
570  {
571  if (op == '+')
572  head = &InlineAllow;
573  else
574  head = &InlineExclude;
575  }
576  else
577  {
578  mutt_buffer_strcpy(err, _("unattachments: invalid disposition"));
579  return MUTT_CMD_ERROR;
580  }
581 
582  return parse_unattach_list(buf, s, head, err);
583 }
struct ListHead InlineAllow
List of inline types to counted.
Definition: attachments.c:58
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
Log of notifications.
Definition: logging.h:45
All Attachment regexes have been deleted.
Definition: attachments.h:40
static void attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t.
Definition: attachments.c:69
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:387
Attachment command changed, NotifyAttach.
Definition: notify_type.h:37
void mutt_list_free_type(struct ListHead *h, list_free_t fn)
Free a List of type.
Definition: list.c:144
#define _(a)
Definition: message.h:28
static struct Notify * AttachmentsNotify
Definition: attachments.c:60
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Warning: Help given to the user.
Definition: mutt_commands.h:37
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
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: attachments.c:56
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
void(* list_free_t)(void **ptr)
Prototype for a function to free List data.
Definition: list.h:45
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
+ Here is the call graph for this function:

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

289 {
292  if (mutt_buffer_len(buf) == 0)
293  {
294  if (HomeDir)
296  else
297  {
298  mutt_buffer_printf(err, _("%s: too few arguments"), "cd");
299  return MUTT_CMD_ERROR;
300  }
301  }
302 
303  if (chdir(mutt_buffer_string(buf)) != 0)
304  {
305  mutt_buffer_printf(err, "cd: %s", strerror(errno));
306  return MUTT_CMD_ERROR;
307  }
308 
309  return MUTT_CMD_SUCCESS;
310 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
char * HomeDir
User&#39;s home directory.
Definition: mutt_globals.h:45
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:356
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Success: Command worked.
Definition: mutt_commands.h:38
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:322
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ 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 315 of file command_parse.c.

317 {
318  if (!MoreArgs(s))
319  {
320  mutt_buffer_printf(err, _("%s: too few arguments"), "echo");
321  return MUTT_CMD_WARNING;
322  }
324  OptForceRefresh = true;
325  mutt_message("%s", buf->data);
326  OptForceRefresh = false;
327  mutt_sleep(0);
328 
329  return MUTT_CMD_SUCCESS;
330 }
#define _(a)
Definition: message.h:28
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
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1461
WHERE bool OptForceRefresh
(pseudo) refresh even during macros
Definition: options.h:36
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define mutt_message(...)
Definition: logging.h:87
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

341 {
342  if (MoreArgs(s))
343  {
344  mutt_buffer_printf(err, _("%s: too many arguments"), "finish");
345  return MUTT_CMD_WARNING;
346  }
347 
348  return MUTT_CMD_FINISH;
349 }
#define _(a)
Definition: message.h:28
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
Warning: Help given to the user.
Definition: mutt_commands.h:37
Finish: Stop processing this file.
Definition: mutt_commands.h:39
+ Here is the call graph for this function:

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

356 {
357  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
358  enum GroupState state = GS_NONE;
359 
360  do
361  {
363  if (parse_grouplist(&gl, buf, s, err) == -1)
364  goto bail;
365 
366  if ((data == MUTT_UNGROUP) && mutt_istr_equal(buf->data, "*"))
367  {
369  goto out;
370  }
371 
372  if (mutt_istr_equal(buf->data, "-rx"))
373  state = GS_RX;
374  else if (mutt_istr_equal(buf->data, "-addr"))
375  state = GS_ADDR;
376  else
377  {
378  switch (state)
379  {
380  case GS_NONE:
381  mutt_buffer_printf(err, _("%sgroup: missing -rx or -addr"),
382  (data == MUTT_UNGROUP) ? "un" : "");
383  goto warn;
384 
385  case GS_RX:
386  if ((data == MUTT_GROUP) &&
387  (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0))
388  {
389  goto bail;
390  }
391  else if ((data == MUTT_UNGROUP) &&
392  (mutt_grouplist_remove_regex(&gl, buf->data) < 0))
393  {
394  goto bail;
395  }
396  break;
397 
398  case GS_ADDR:
399  {
400  char *estr = NULL;
401  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
402  mutt_addrlist_parse2(&al, buf->data);
403  if (TAILQ_EMPTY(&al))
404  goto bail;
405  if (mutt_addrlist_to_intl(&al, &estr))
406  {
407  mutt_buffer_printf(err, _("%sgroup: warning: bad IDN '%s'"),
408  (data == 1) ? "un" : "", estr);
409  mutt_addrlist_clear(&al);
410  FREE(&estr);
411  goto bail;
412  }
413  if (data == MUTT_GROUP)
414  mutt_grouplist_add_addrlist(&gl, &al);
415  else if (data == MUTT_UNGROUP)
417  mutt_addrlist_clear(&al);
418  break;
419  }
420  }
421  }
422  } while (MoreArgs(s));
423 
424 out:
426  return MUTT_CMD_SUCCESS;
427 
428 bail:
430  return MUTT_CMD_ERROR;
431 
432 warn:
434  return MUTT_CMD_WARNING;
435 }
int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, struct Buffer *err)
Parse a group context.
#define MUTT_UNGROUP
&#39;ungroup&#39; config command
Definition: group.h:34
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
void mutt_grouplist_clear(struct GroupList *gl)
Clear a GroupList.
Definition: group.c:103
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1470
#define _(a)
Definition: message.h:28
void mutt_grouplist_add_addrlist(struct GroupList *gl, struct AddressList *al)
Add Address list to a GroupList.
Definition: group.c:226
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:616
#define MoreArgs(buf)
Definition: buffer.h:40
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:276
int mutt_grouplist_remove_regex(struct GroupList *gl, const char *s)
Remove matching addresses from a GroupList.
Definition: group.c:301
GroupState
Type of email address group.
Definition: command_parse.c:72
int mutt_grouplist_remove_addrlist(struct GroupList *gl, struct AddressList *al)
Remove an AddressList from a GroupList.
Definition: group.c:245
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
Entry is an address.
Definition: command_parse.c:76
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Group is missing an argument.
Definition: command_parse.c:74
Success: Command worked.
Definition: mutt_commands.h:38
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1305
Warning: Help given to the user.
Definition: mutt_commands.h:37
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:157
#define FREE(x)
Definition: memory.h:40
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define TAILQ_EMPTY(head)
Definition: queue.h:721
Entry is a regular expression.
Definition: command_parse.c:75
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
#define MUTT_GROUP
&#39;group&#39; config command
Definition: group.h:33
+ Here is the call graph for this function:

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

452 {
454 
455  // is the item defined as:
456  bool res = cs_subset_lookup(NeoMutt->sub, buf->data) // a variable?
457  || feature_enabled(buf->data) // a compiled-in feature?
458  || is_function(buf->data) // a function?
459  || mutt_command_get(buf->data) // a command?
460  || myvar_get(buf->data) // a my_ variable?
461  || mutt_str_getenv(buf->data); // an environment variable?
462 
463  if (!MoreArgs(s))
464  {
465  mutt_buffer_printf(err, _("%s: too few arguments"), (data ? "ifndef" : "ifdef"));
466  return MUTT_CMD_WARNING;
467  }
469 
470  /* ifdef KNOWN_SYMBOL or ifndef UNKNOWN_SYMBOL */
471  if ((res && (data == 0)) || (!res && (data == 1)))
472  {
473  enum CommandResult rc = mutt_parse_rc_line(buf->data, err);
474  if (rc == MUTT_CMD_ERROR)
475  {
476  mutt_error(_("Error: %s"), err->data);
477  return MUTT_CMD_ERROR;
478  }
479  return rc;
480  }
481  return MUTT_CMD_SUCCESS;
482 }
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
bool feature_enabled(const char *name)
Test if a compile-time feature is enabled.
Definition: version.c:565
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:88
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: init.c:1039
#define _(a)
Definition: message.h:28
static bool is_function(const char *name)
Is the argument a neomutt function?
Definition: command_parse.c:85
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
Definition: subset.c:179
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:1024
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:69
char * data
Pointer to data.
Definition: buffer.h:35
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
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

489 {
490  do
491  {
494  add_to_stailq(&Ignore, buf->data);
495  } while (MoreArgs(s));
496 
497  return MUTT_CMD_SUCCESS;
498 }
#define MoreArgs(buf)
Definition: buffer.h:40
struct ListHead Ignore
List of header patterns to ignore.
Definition: globals.c:35
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: muttlib.c:1728
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: muttlib.c:1753
Success: Command worked.
Definition: mutt_commands.h:38
struct ListHead UnIgnore
List of header patterns to unignore (see)
Definition: globals.c:36
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

505 {
506  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
507 
508  do
509  {
511 
512  if (parse_grouplist(&gl, buf, s, err) == -1)
513  goto bail;
514 
516 
517  if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
518  goto bail;
519 
520  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
521  goto bail;
522  } while (MoreArgs(s));
523 
525  return MUTT_CMD_SUCCESS;
526 
527 bail:
529  return MUTT_CMD_ERROR;
530 }
int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, struct Buffer *err)
Parse a group context.
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:227
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
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:132
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: globals.c:41
#define MoreArgs(buf)
Definition: buffer.h:40
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:276
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
Definition: globals.c:42
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:157
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ parse_mailboxes()

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

Parse the 'mailboxes' command - Implements Command::parse() -This is also used by 'virtual-mailboxes'.

Definition at line 537 of file command_parse.c.

539 {
540  while (MoreArgs(s))
541  {
542  struct Mailbox *m = mailbox_new();
543 
544  if (data & MUTT_NAMED)
545  {
546  // This may be empty, e.g. `named-mailboxes "" +inbox`
548  m->name = mutt_buffer_strdup(buf);
549  }
550 
552  if (mutt_buffer_is_empty(buf))
553  {
554  /* Skip empty tokens. */
555  mailbox_free(&m);
556  continue;
557  }
558 
559  mutt_buffer_strcpy(&m->pathbuf, buf->data);
560  const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
561  /* int rc = */ mx_path_canon2(m, c_folder);
562 
563  if (m->type <= MUTT_UNKNOWN)
564  {
565  mutt_error("Unknown Mailbox: %s", m->realpath);
566  mailbox_free(&m);
567  return MUTT_CMD_ERROR;
568  }
569 
570  bool new_account = false;
571  struct Account *a = mx_ac_find(m);
572  if (!a)
573  {
574  a = account_new(NULL, NeoMutt->sub);
575  a->type = m->type;
576  new_account = true;
577  }
578 
579  if (!new_account)
580  {
581  struct Mailbox *m_old = mx_mbox_find(a, m->realpath);
582  if (m_old)
583  {
584  const bool show = (m_old->flags == MB_HIDDEN);
585  if (show)
586  {
587  m_old->flags = MB_NORMAL;
588  m_old->gen = mailbox_gen();
589  }
590 
591  const bool rename = (data & MUTT_NAMED) && !mutt_str_equal(m_old->name, m->name);
592  if (rename)
593  {
594  mutt_str_replace(&m_old->name, m->name);
595  }
596 
597  mailbox_free(&m);
598  continue;
599  }
600  }
601 
602  if (!mx_ac_add(a, m))
603  {
604  //error
605  mailbox_free(&m);
606  if (new_account)
607  {
608  cs_subset_free(&a->sub);
609  FREE(&a->name);
610  notify_free(&a->notify);
611  FREE(&a);
612  }
613  continue;
614  }
615  if (new_account)
616  {
618  }
619 
620 #ifdef USE_INOTIFY
621  mutt_monitor_add(m);
622 #endif
623  }
624  return MUTT_CMD_SUCCESS;
625 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
char * name
Name of Account.
Definition: account.h:39
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
int mx_path_canon2(struct Mailbox *m, const char *folder)
Canonicalise the path to realpath.
Definition: mx.c:1468
#define mutt_error(...)
Definition: logging.h:88
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer&#39;s string.
Definition: buffer.c:432
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:42
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
A group of associated Mailboxes.
Definition: account.h:36
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
#define MUTT_NAMED
Definition: mutt_commands.h:79
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1578
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:104
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:481
struct Account * mx_ac_find(struct Mailbox *m)
Find the Account owning a Mailbox.
Definition: mx.c:1554
int mailbox_gen(void)
Get the next generation number.
Definition: mailbox.c:58
Container for Accounts, Notifications.
Definition: neomutt.h:36
#define MoreArgs(buf)
Definition: buffer.h:40
char * name
A short name for the Mailbox.
Definition: mailbox.h:85
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:87
#define MB_HIDDEN
Definition: mailbox.h:38
A mailbox.
Definition: mailbox.h:81
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
struct Account * account_new(const char *name, struct ConfigSubset *sub)
Create a new Account.
Definition: account.c:42
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
bool mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add()
Definition: mx.c:1756
uint8_t flags
e.g. MB_NORMAL
Definition: mailbox.h:134
struct Mailbox * mailbox_new(void)
Create a new Mailbox.
Definition: mailbox.c:68
Success: Command worked.
Definition: mutt_commands.h:38
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
#define FREE(x)
Definition: memory.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
bool neomutt_account_add(struct NeoMutt *n, struct Account *a)
Add an Account to the global list.
Definition: neomutt.c:84
struct Buffer pathbuf
Definition: mailbox.h:83
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
#define MB_NORMAL
Definition: mailbox.h:37
int gen
Generation number, for sorting.
Definition: mailbox.h:150
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ parse_my_hdr()

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

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

Definition at line 630 of file command_parse.c.

632 {
634  char *p = strpbrk(buf->data, ": \t");
635  if (!p || (*p != ':'))
636  {
637  mutt_buffer_strcpy(err, _("invalid header field"));
638  return MUTT_CMD_WARNING;
639  }
640 
641  struct EventHeader ev_h = { buf->data };
642  struct ListNode *n = header_find(&UserHeader, buf->data);
643 
644  if (n)
645  {
646  header_update(n, buf->data);
647  mutt_debug(LL_NOTIFY, "NT_HEADER_CHANGE: %s\n", buf->data);
649  }
650  else
651  {
652  header_add(&UserHeader, buf->data);
653  mutt_debug(LL_NOTIFY, "NT_HEADER_ADD: %s\n", buf->data);
655  }
656 
657  return MUTT_CMD_SUCCESS;
658 }
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
An existing header has been changed.
Definition: email.h:170
Log of notifications.
Definition: logging.h:45
An event that happened to a header.
Definition: email.h:176
struct ListNode * header_add(struct ListHead *hdrlist, const char *header)
Add a header to a list.
Definition: email.c:203
#define _(a)
Definition: message.h:28
Container for Accounts, Notifications.
Definition: neomutt.h:36
Header has been added.
Definition: email.h:168
#define MUTT_TOKEN_QUOTE
Don&#39;t interpret quotes.
Definition: mutt.h:70
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:69
struct ListNode * header_update(struct ListNode *hdr, const char *header)
Update an existing header.
Definition: email.c:217
char * data
Pointer to data.
Definition: buffer.h:35
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
A header has changed, NotifyHeader EventHeader.
Definition: notify_type.h:46
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
A List node for strings.
Definition: list.h:34
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
+ Here is the call graph for this function:
+ 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 665 of file command_parse.c.

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

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

1044 {
1045  char **envp = mutt_envlist_getlist();
1046 
1047  bool query = false;
1048  bool prefix = false;
1049  bool unset = (data == MUTT_SET_UNSET);
1050 
1051  if (!MoreArgs(s))
1052  {
1053  mutt_buffer_printf(err, _("%s: too few arguments"), "setenv");
1054  return MUTT_CMD_WARNING;
1055  }
1056 
1057  if (*s->dptr == '?')
1058  {
1059  query = true;
1060  prefix = true;
1061 
1062  if (unset)
1063  {
1064  mutt_buffer_printf(err, _("Can't query a variable with the '%s' command"), "unsetenv");
1065  return MUTT_CMD_WARNING;
1066  }
1067 
1068  s->dptr++;
1069  }
1070 
1071  /* get variable name */
1073 
1074  if (*s->dptr == '?')
1075  {
1076  if (unset)
1077  {
1078  mutt_buffer_printf(err, _("Can't query a variable with the '%s' command"), "unsetenv");
1079  return MUTT_CMD_WARNING;
1080  }
1081 
1082  if (prefix)
1083  {
1084  mutt_buffer_printf(err, _("Can't use a prefix when querying a variable"));
1085  return MUTT_CMD_WARNING;
1086  }
1087 
1088  query = true;
1089  s->dptr++;
1090  }
1091 
1092  if (query)
1093  {
1094  bool found = false;
1095  while (envp && *envp)
1096  {
1097  /* This will display all matches for "^QUERY" */
1098  if (mutt_str_startswith(*envp, buf->data))
1099  {
1100  if (!found)
1101  {
1102  mutt_endwin();
1103  found = true;
1104  }
1105  puts(*envp);
1106  }
1107  envp++;
1108  }
1109 
1110  if (found)
1111  {
1113  return MUTT_CMD_SUCCESS;
1114  }
1115 
1116  mutt_buffer_printf(err, _("%s is unset"), buf->data);
1117  return MUTT_CMD_WARNING;
1118  }
1119 
1120  if (unset)
1121  {
1122  if (mutt_envlist_unset(buf->data))
1123  return MUTT_CMD_SUCCESS;
1124  return MUTT_CMD_ERROR;
1125  }
1126 
1127  /* set variable */
1128 
1129  if (*s->dptr == '=')
1130  {
1131  s->dptr++;
1132  SKIPWS(s->dptr);
1133  }
1134 
1135  if (!MoreArgs(s))
1136  {
1137  mutt_buffer_printf(err, _("%s: too few arguments"), "setenv");
1138  return MUTT_CMD_WARNING;
1139  }
1140 
1141  char *name = mutt_str_dup(buf->data);
1143  mutt_envlist_set(name, buf->data, true);
1144  FREE(&name);
1145 
1146  return MUTT_CMD_SUCCESS;
1147 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
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
#define SKIPWS(ch)
Definition: string2.h:46
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:160
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:422
bool mutt_envlist_unset(const char *name)
Unset an environment variable.
Definition: envlist.c:132
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
default is to unset all vars
Definition: mutt_commands.h:74
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:455
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define FREE(x)
Definition: memory.h:40
bool mutt_envlist_set(const char *name, const char *value, bool overwrite)
Set an environment variable.
Definition: envlist.c:85
#define MUTT_TOKEN_EQUAL
Treat &#39;=&#39; as a special.
Definition: mutt.h:67
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
#define MUTT_TOKEN_QUESTION
Treat &#39;?&#39; as a special.
Definition: mutt.h:76
char ** mutt_envlist_getlist(void)
Get the private environment.
Definition: envlist.c:169
+ Here is the call graph for this function:

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

1154 {
1155  char path[PATH_MAX];
1156 
1157  do
1158  {
1159  if (mutt_extract_token(buf, s, MUTT_TOKEN_NO_FLAGS) != 0)
1160  {
1161  mutt_buffer_printf(err, _("source: error at %s"), s->dptr);
1162  return MUTT_CMD_ERROR;
1163  }
1164  mutt_str_copy(path, buf->data, sizeof(path));
1165  mutt_expand_path(path, sizeof(path));
1166 
1167  if (source_rc(path, err) < 0)
1168  {
1169  mutt_buffer_printf(err, _("source: file %s could not be sourced"), path);
1170  return MUTT_CMD_ERROR;
1171  }
1172 
1173  } while (MoreArgs(s));
1174 
1175  return MUTT_CMD_SUCCESS;
1176 }
int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:122
#define MoreArgs(buf)
Definition: buffer.h:40
#define PATH_MAX
Definition: mutt.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
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:749
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

1183 {
1184  struct Buffer templ;
1185 
1186  mutt_buffer_init(&templ);
1187 
1188  /* Insist on at least one parameter */
1189  if (!MoreArgs(s))
1190  {
1191  if (data == MUTT_SPAM)
1192  mutt_buffer_strcpy(err, _("spam: no matching pattern"));
1193  else
1194  mutt_buffer_strcpy(err, _("nospam: no matching pattern"));
1195  return MUTT_CMD_ERROR;
1196  }
1197 
1198  /* Extract the first token, a regex */
1200 
1201  /* data should be either MUTT_SPAM or MUTT_NOSPAM. MUTT_SPAM is for spam commands. */
1202  if (data == MUTT_SPAM)
1203  {
1204  /* If there's a second parameter, it's a template for the spam tag. */
1205  if (MoreArgs(s))
1206  {
1208 
1209  /* Add to the spam list. */
1210  if (mutt_replacelist_add(&SpamList, buf->data, templ.data, err) != 0)
1211  {
1212  FREE(&templ.data);
1213  return MUTT_CMD_ERROR;
1214  }
1215  FREE(&templ.data);
1216  }
1217  /* If not, try to remove from the nospam list. */
1218  else
1219  {
1221  }
1222 
1223  return MUTT_CMD_SUCCESS;
1224  }
1225  /* MUTT_NOSPAM is for nospam commands. */
1226  else if (data == MUTT_NOSPAM)
1227  {
1228  /* nospam only ever has one parameter. */
1229 
1230  /* "*" is a special case. */
1231  if (mutt_str_equal(buf->data, "*"))
1232  {
1235  return MUTT_CMD_SUCCESS;
1236  }
1237 
1238  /* If it's on the spam list, just remove it. */
1239  if (mutt_replacelist_remove(&SpamList, buf->data) != 0)
1240  return MUTT_CMD_SUCCESS;
1241 
1242  /* Otherwise, add it to the nospam list. */
1243  if (mutt_regexlist_add(&NoSpamList, buf->data, REG_ICASE, err) != 0)
1244  return MUTT_CMD_ERROR;
1245 
1246  return MUTT_CMD_SUCCESS;
1247  }
1248 
1249  /* This should not happen. */
1250  mutt_buffer_strcpy(err, "This is no good at all.");
1251  return MUTT_CMD_ERROR;
1252 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
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:263
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:227
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define MUTT_NOSPAM
Definition: mutt.h:111
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:132
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:448
#define MoreArgs(buf)
Definition: buffer.h:40
#define MUTT_SPAM
Definition: mutt.h:110
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
Definition: globals.c:33
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
struct ReplaceList SpamList
List of regexes and patterns to match spam emails.
Definition: globals.c:34
Success: Command worked.
Definition: mutt_commands.h:38
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:565
#define FREE(x)
Definition: memory.h:40
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:171
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

1261 {
1262  do
1263  {
1265  add_to_stailq((struct ListHead *) data, buf->data);
1266  } while (MoreArgs(s));
1267 
1268  return MUTT_CMD_SUCCESS;
1269 }
#define MoreArgs(buf)
Definition: buffer.h:40
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: muttlib.c:1728
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

1276 {
1277  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1278 
1279  do
1280  {
1282 
1283  if (parse_grouplist(&gl, buf, s, err) == -1)
1284  goto bail;
1285 
1288 
1289  if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
1290  goto bail;
1291  if (mutt_regexlist_add(&SubscribedLists, buf->data, REG_ICASE, err) != 0)
1292  goto bail;
1293  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
1294  goto bail;
1295  } while (MoreArgs(s));
1296 
1298  return MUTT_CMD_SUCCESS;
1299 
1300 bail:
1302  return MUTT_CMD_ERROR;
1303 }
int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, struct Buffer *err)
Parse a group context.
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: globals.c:43
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:227
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
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:132
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
Definition: globals.c:40
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: globals.c:41
#define MoreArgs(buf)
Definition: buffer.h:40
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:276
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
Definition: globals.c:42
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:157
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ parse_subscribe_to()

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

Parse the 'subscribe-to' command - Implements Command::parse() -The 'subscribe-to' command allows to subscribe to an IMAP-Mailbox.

Patterns are not supported. Use it as follows: subscribe-to =folder

Definition at line 1313 of file command_parse.c.

1315 {
1316  if (!buf || !s || !err)
1317  return MUTT_CMD_ERROR;
1318 
1319  mutt_buffer_reset(err);
1320 
1321  if (MoreArgs(s))
1322  {
1324 
1325  if (MoreArgs(s))
1326  {
1327  mutt_buffer_printf(err, _("%s: too many arguments"), "subscribe-to");
1328  return MUTT_CMD_WARNING;
1329  }
1330 
1331  if (buf->data && (*buf->data != '\0'))
1332  {
1333  /* Expand and subscribe */
1334  if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), true) == 0)
1335  {
1336  mutt_message(_("Subscribed to %s"), buf->data);
1337  return MUTT_CMD_SUCCESS;
1338  }
1339 
1340  mutt_buffer_printf(err, _("Could not subscribe to %s"), buf->data);
1341  return MUTT_CMD_ERROR;
1342  }
1343 
1344  mutt_debug(LL_DEBUG1, "Corrupted buffer");
1345  return MUTT_CMD_ERROR;
1346  }
1347 
1348  mutt_buffer_addstr(err, _("No folder specified"));
1349  return MUTT_CMD_WARNING;
1350 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
size_t dsize
Length of data.
Definition: buffer.h:37
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:122
#define MoreArgs(buf)
Definition: buffer.h:40
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Success: Command worked.
Definition: mutt_commands.h:38
Log at debug level 1.
Definition: logging.h:40
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define mutt_message(...)
Definition: logging.h:87
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1286
+ Here is the call graph for this function:

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

Definition at line 1356 of file command_parse.c.

1358 {
1359  if (!buf || !s)
1360  return MUTT_CMD_ERROR;
1361 
1362  char *tmp = NULL;
1363 
1364  while (MoreArgs(s))
1365  {
1366  char *tag = NULL, *format = NULL;
1367 
1369  if (buf->data && (*buf->data != '\0'))
1370  tag = mutt_str_dup(buf->data);
1371  else
1372  continue;
1373 
1375  format = mutt_str_dup(buf->data);
1376 
1377  /* avoid duplicates */
1378  tmp = mutt_hash_find(TagFormats, format);
1379  if (tmp)
1380  {
1381  mutt_debug(LL_DEBUG3, "tag format '%s' already registered as '%s'\n", format, tmp);
1382  FREE(&tag);
1383  FREE(&format);
1384  continue;
1385  }
1386 
1387  mutt_hash_insert(TagFormats, format, tag);
1388  }
1389  return MUTT_CMD_SUCCESS;
1390 }
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:354
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:327
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Success: Command worked.
Definition: mutt_commands.h:38
#define FREE(x)
Definition: memory.h:40
WHERE struct HashTable * TagFormats
Hash Table of tag-formats (tag -> format string)
Definition: mutt_globals.h:55
Log at debug level 3.
Definition: logging.h:42
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

Definition at line 1395 of file command_parse.c.

1397 {
1398  if (!buf || !s)
1399  return MUTT_CMD_ERROR;
1400 
1401  char *tmp = NULL;
1402 
1403  while (MoreArgs(s))
1404  {
1405  char *tag = NULL, *transform = NULL;
1406 
1408  if (buf->data && (*buf->data != '\0'))
1409  tag = mutt_str_dup(buf->data);
1410  else
1411  continue;
1412 
1414  transform = mutt_str_dup(buf->data);
1415 
1416  /* avoid duplicates */
1417  tmp = mutt_hash_find(TagTransforms, tag);
1418  if (tmp)
1419  {
1420  mutt_debug(LL_DEBUG3, "tag transform '%s' already registered as '%s'\n", tag, tmp);
1421  FREE(&tag);
1422  FREE(&transform);
1423  continue;
1424  }
1425 
1426  mutt_hash_insert(TagTransforms, tag, transform);
1427  }
1428  return MUTT_CMD_SUCCESS;
1429 }
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:354
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:327
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
struct HashTable * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:37
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Success: Command worked.
Definition: mutt_commands.h:38
#define FREE(x)
Definition: memory.h:40
Log at debug level 3.
Definition: logging.h:42
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

1436 {
1437  do
1438  {
1440 
1441  /* don't add "*" to the unignore list */
1442  if (strcmp(buf->data, "*") != 0)
1443  add_to_stailq(&UnIgnore, buf->data);
1444 
1445  remove_from_stailq(&Ignore, buf->data);
1446  } while (MoreArgs(s));
1447 
1448  return MUTT_CMD_SUCCESS;
1449 }
#define MoreArgs(buf)
Definition: buffer.h:40
struct ListHead Ignore
List of header patterns to ignore.
Definition: globals.c:35
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: muttlib.c:1728
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: muttlib.c:1753
Success: Command worked.
Definition: mutt_commands.h:38
struct ListHead UnIgnore
List of header patterns to unignore (see)
Definition: globals.c:36
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

1456 {
1458  do
1459  {
1463 
1464  if (!mutt_str_equal(buf->data, "*") &&
1465  (mutt_regexlist_add(&UnMailLists, buf->data, REG_ICASE, err) != 0))
1466  {
1467  return MUTT_CMD_ERROR;
1468  }
1469  } while (MoreArgs(s));
1470 
1471  return MUTT_CMD_SUCCESS;
1472 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: globals.c:43
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:227
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:449
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:132
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: globals.c:41
struct HashTable * AutoSubscribeCache
Hash Table of auto-subscribed mailing lists.
Definition: globals.c:38
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
Definition: globals.c:42
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ parse_unmailboxes()

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

Parse the 'unmailboxes' command - Implements Command::parse() -This is also used by 'unvirtual-mailboxes'.

Definition at line 1519 of file command_parse.c.

1521 {
1522  while (MoreArgs(s))
1523  {
1525 
1526  if (mutt_str_equal(buf->data, "*"))
1527  {
1529  return MUTT_CMD_SUCCESS;
1530  }
1531 
1533 
1534  struct Account *a = NULL;
1535  TAILQ_FOREACH(a, &NeoMutt->accounts, entries)
1536  {
1537  struct Mailbox *m = mx_mbox_find(a, mutt_buffer_string(buf));
1538  if (m)
1539  {
1540  do_unmailboxes(m);
1541  break;
1542  }
1543  }
1544  }
1545  return MUTT_CMD_SUCCESS;
1546 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
A group of associated Mailboxes.
Definition: account.h:36
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1578
Container for Accounts, Notifications.
Definition: neomutt.h:36
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
#define MoreArgs(buf)
Definition: buffer.h:40
A mailbox.
Definition: mailbox.h:81
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
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.
Success: Command worked.
Definition: mutt_commands.h:38
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:322
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

1553 {
1554  struct ListNode *np = NULL, *tmp = NULL;
1555  size_t l;
1556 
1557  do
1558  {
1560  if (mutt_str_equal("*", buf->data))
1561  {
1562  /* Clear all headers, send a notification for each header */
1563  STAILQ_FOREACH(np, &UserHeader, entries)
1564  {
1565  mutt_debug(LL_NOTIFY, "NT_HEADER_DELETE: %s\n", np->data);
1566  struct EventHeader ev_h = { np->data };
1568  }
1569  mutt_list_free(&UserHeader);
1570  continue;
1571  }
1572 
1573  l = mutt_str_len(buf->data);
1574  if (buf->data[l - 1] == ':')
1575  l--;
1576 
1577  STAILQ_FOREACH_SAFE(np, &UserHeader, entries, tmp)
1578  {
1579  if (mutt_istrn_equal(buf->data, np->data, l) && (np->data[l] == ':'))
1580  {
1581  mutt_debug(LL_NOTIFY, "NT_HEADER_DELETE: %s\n", np->data);
1582  struct EventHeader ev_h = { np->data };
1584 
1585  header_free(&UserHeader, np);
1586  }
1587  }
1588  } while (MoreArgs(s));
1589  return MUTT_CMD_SUCCESS;
1590 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
Log of notifications.
Definition: logging.h:45
An event that happened to a header.
Definition: email.h:176
Header has been removed.
Definition: email.h:169
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:621
Container for Accounts, Notifications.
Definition: neomutt.h:36
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
#define MoreArgs(buf)
Definition: buffer.h:40
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
A header has changed, NotifyHeader EventHeader.
Definition: notify_type.h:46
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
void header_free(struct ListHead *hdrlist, struct ListNode *target)
Free and remove a header from a header list.
Definition: email.c:245
Success: Command worked.
Definition: mutt_commands.h:38
char * data
String.
Definition: list.h:36
A List node for strings.
Definition: list.h:34
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
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
+ Here is the call graph for this function:

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

1599 {
1600  do
1601  {
1603  /* Check for deletion of entire list */
1604  if (mutt_str_equal(buf->data, "*"))
1605  {
1606  mutt_list_free((struct ListHead *) data);
1607  break;
1608  }
1609  remove_from_stailq((struct ListHead *) data, buf->data);
1610  } while (MoreArgs(s));
1611 
1612  return MUTT_CMD_SUCCESS;
1613 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: muttlib.c:1753
Success: Command worked.
Definition: mutt_commands.h:38
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

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

1620 {
1622  do
1623  {
1626 
1627  if (!mutt_str_equal(buf->data, "*") &&
1628  (mutt_regexlist_add(&UnSubscribedLists, buf->data, REG_ICASE, err) != 0))
1629  {
1630  return MUTT_CMD_ERROR;
1631  }
1632  } while (MoreArgs(s));
1633 
1634  return MUTT_CMD_SUCCESS;
1635 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: globals.c:43
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:227
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:449
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:132
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
Definition: globals.c:40
struct HashTable * AutoSubscribeCache
Hash Table of auto-subscribed mailing lists.
Definition: globals.c:38
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ parse_unsubscribe_from()

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

Parse the 'unsubscribe-from' command - Implements Command::parse() -The 'unsubscribe-from' command allows to unsubscribe from an IMAP-Mailbox.

Patterns are not supported. Use it as follows: unsubscribe-from =folder

Definition at line 1645 of file command_parse.c.

1647 {
1648  if (!buf || !s || !err)
1649  return MUTT_CMD_ERROR;
1650 
1651  if (MoreArgs(s))
1652  {
1654 
1655  if (MoreArgs(s))
1656  {
1657  mutt_buffer_printf(err, _("%s: too many arguments"), "unsubscribe-from");
1658  return MUTT_CMD_WARNING;
1659  }
1660 
1661  if (buf->data && (*buf->data != '\0'))
1662  {
1663  /* Expand and subscribe */
1664  if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), false) == 0)
1665  {
1666  mutt_message(_("Unsubscribed from %s"), buf->data);
1667  return MUTT_CMD_SUCCESS;
1668  }
1669 
1670  mutt_buffer_printf(err, _("Could not unsubscribe from %s"), buf->data);
1671  return MUTT_CMD_ERROR;
1672  }
1673 
1674  mutt_debug(LL_DEBUG1, "Corrupted buffer");
1675  return MUTT_CMD_ERROR;
1676  }
1677 
1678  mutt_buffer_addstr(err, _("No folder specified"));
1679  return MUTT_CMD_WARNING;
1680 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
size_t dsize
Length of data.
Definition: buffer.h:37
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:122
#define MoreArgs(buf)
Definition: buffer.h:40
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Success: Command worked.
Definition: mutt_commands.h:38
Log at debug level 1.
Definition: logging.h:40
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define mutt_message(...)
Definition: logging.h:87
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1286
+ Here is the call graph for this function:

◆ mutt_parse_uncolor()

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

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

Definition at line 955 of file color.c.

957 {
958  if (OptNoCurses || !has_colors())
959  {
960  *s->dptr = '\0'; /* fake that we're done parsing */
961  return MUTT_CMD_SUCCESS;
962  }
963  return parse_uncolor(buf, s, err, true);
964 }
static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, struct Buffer *err, bool uncolor)
Parse an &#39;uncolor&#39; command.
Definition: color.c:849
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:47
char * dptr
Current read/write position.
Definition: buffer.h:36
Success: Command worked.
Definition: mutt_commands.h:38
+ Here is the call graph for this function:

◆ mutt_parse_unmono()

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

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

Definition at line 970 of file color.c.

972 {
973  if (OptNoCurses || !has_colors())
974  {
975  *s->dptr = '\0'; /* fake that we're done parsing */
976  return MUTT_CMD_SUCCESS;
977  }
978  return parse_uncolor(buf, s, err, false);
979 }
static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, struct Buffer *err, bool uncolor)
Parse an &#39;uncolor&#39; command.
Definition: color.c:849
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:47
char * dptr
Current read/write position.
Definition: buffer.h:36
Success: Command worked.
Definition: mutt_commands.h:38
+ Here is the call graph for this function:

◆ 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 1391 of file color.c.

1393 {
1394  bool dry_run = false;
1395 
1396  if (OptNoCurses || !has_colors())
1397  dry_run = true;
1398 
1399  return parse_color(buf, s, err, parse_color_pair, dry_run, true);
1400 }
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:47
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 &#39;color&#39; command.
Definition: color.c:1215
static enum CommandResult parse_color_pair(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err)
Parse a pair of colours - Implements parser_callback_t.
Definition: color.c:1098
+ Here is the call graph for this function:

◆ mutt_parse_mono()

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

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

Definition at line 1406 of file color.c.

1408 {
1409  bool dry_run = false;
1410 
1411 #ifdef HAVE_COLOR
1412  if (OptNoCurses || has_colors())
1413  dry_run = true;
1414 #else
1415  if (OptNoCurses)
1416  dry_run = true;
1417 #endif
1418 
1419  return parse_color(buf, s, err, parse_attr_spec, dry_run, false);
1420 }
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:47
static enum CommandResult parse_attr_spec(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err)
Parse an attribute description - Implements parser_callback_t.
Definition: color.c:1148
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 &#39;color&#39; command.
Definition: color.c:1215
+ Here is the call graph for this function:

◆ mutt_parse_hook()

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

Parse the 'hook' family of commands - Implements Command::parse() -This is used by 'account-hook', 'append-hook' and many more.

Definition at line 82 of file hook.c.

84 {
85  struct Hook *hook = NULL;
86  int rc = MUTT_CMD_ERROR;
87  bool pat_not = false;
88  bool use_regex = true;
89  regex_t *rx = NULL;
90  struct PatternList *pat = NULL;
91  const bool folder_or_mbox = (data & (MUTT_FOLDER_HOOK | MUTT_MBOX_HOOK));
92 
93  struct Buffer *cmd = mutt_buffer_pool_get();
94  struct Buffer *pattern = mutt_buffer_pool_get();
95 
96  if (~data & MUTT_GLOBAL_HOOK) /* NOT a global hook */
97  {
98  if (*s->dptr == '!')
99  {
100  s->dptr++;
101  SKIPWS(s->dptr);
102  pat_not = true;
103  }
104 
106  if (folder_or_mbox &&
107  mutt_str_equal(mutt_buffer_string(pattern), "-noregex"))
108  {
109  use_regex = false;
110  if (!MoreArgs(s))
111  {
112  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
113  rc = MUTT_CMD_WARNING;
114  goto cleanup;
115  }
117  }
118 
119  if (!MoreArgs(s))
120  {
121  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
122  rc = MUTT_CMD_WARNING;
123  goto cleanup;
124  }
125  }
126 
127  mutt_extract_token(cmd, s,
132 
133  if (mutt_buffer_is_empty(cmd))
134  {
135  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
136  rc = MUTT_CMD_WARNING;
137  goto cleanup;
138  }
139 
140  if (MoreArgs(s))
141  {
142  mutt_buffer_printf(err, _("%s: too many arguments"), buf->data);
143  rc = MUTT_CMD_WARNING;
144  goto cleanup;
145  }
146 
147  const char *const c_default_hook =
148  cs_subset_string(NeoMutt->sub, "default_hook");
149  if (folder_or_mbox)
150  {
151  /* Accidentally using the ^ mailbox shortcut in the .neomuttrc is a
152  * common mistake */
153  if ((pattern->data[0] == '^') && !CurrentFolder)
154  {
155  mutt_buffer_strcpy(err, _("current mailbox shortcut '^' is unset"));
156  goto cleanup;
157  }
158 
159  struct Buffer *tmp = mutt_buffer_pool_get();
160  mutt_buffer_copy(tmp, pattern);
161  mutt_buffer_expand_path_regex(tmp, use_regex);
162 
163  /* Check for other mailbox shortcuts that expand to the empty string.
164  * This is likely a mistake too */
165  if (mutt_buffer_is_empty(tmp) && !mutt_buffer_is_empty(pattern))
166  {
167  mutt_buffer_strcpy(err, _("mailbox shortcut expanded to empty regex"));
169  goto cleanup;
170  }
171 
172  if (use_regex)
173  {
174  mutt_buffer_copy(pattern, tmp);
175  }
176  else
177  {
179  }
181  }
182 #ifdef USE_COMP_MBOX
184  {
186  {
187  mutt_buffer_strcpy(err, _("badly formatted command string"));
188  goto cleanup;
189  }
190  }
191 #endif
192  else if (c_default_hook && (~data & MUTT_GLOBAL_HOOK) &&
194  (!WithCrypto || !(data & MUTT_CRYPT_HOOK)))
195  {
196  /* At this stage remain only message-hooks, reply-hooks, send-hooks,
197  * send2-hooks, save-hooks, and fcc-hooks: All those allowing full
198  * patterns. If given a simple regex, we expand $default_hook. */
199  mutt_check_simple(pattern, c_default_hook);
200  }
201 
203  {
205  }
206 
207  /* check to make sure that a matching hook doesn't already exist */
208  TAILQ_FOREACH(hook, &Hooks, entries)
209  {
210  if (data & MUTT_GLOBAL_HOOK)
211  {
212  /* Ignore duplicate global hooks */
213  if (mutt_str_equal(hook->command, mutt_buffer_string(cmd)))
214  {
215  rc = MUTT_CMD_SUCCESS;
216  goto cleanup;
217  }
218  }
219  else if ((hook->type == data) && (hook->regex.pat_not == pat_not) &&
221  {
223  MUTT_ACCOUNT_HOOK | MUTT_REPLY_HOOK | MUTT_CRYPT_HOOK |
225  {
226  /* these hooks allow multiple commands with the same
227  * pattern, so if we've already seen this pattern/command pair, just
228  * ignore it instead of creating a duplicate */
229  if (mutt_str_equal(hook->command, mutt_buffer_string(cmd)))
230  {
231  rc = MUTT_CMD_SUCCESS;
232  goto cleanup;
233  }
234  }
235  else
236  {
237  /* other hooks only allow one command per pattern, so update the
238  * entry with the new command. this currently does not change the
239  * order of execution of the hooks, which i think is desirable since
240  * a common action to perform is to change the default (.) entry
241  * based upon some other information. */
242  FREE(&hook->command);
243  hook->command = mutt_buffer_strdup(cmd);
244  rc = MUTT_CMD_SUCCESS;
245  goto cleanup;
246  }
247  }
248  }
249 
251  {
252  /* These are managed separately by the charset code */
254  if (mutt_ch_lookup_add(type, mutt_buffer_string(pattern), mutt_buffer_string(cmd), err))
255  rc = MUTT_CMD_SUCCESS;
256  goto cleanup;
257  }
260  {
261  PatternCompFlags comp_flags;
262 
263  if (data & (MUTT_SEND2_HOOK))
264  comp_flags = MUTT_PC_SEND_MODE_SEARCH;
265  else if (data & (MUTT_SEND_HOOK | MUTT_FCC_HOOK))
266  comp_flags = MUTT_PC_NO_FLAGS;
267  else
268  comp_flags = MUTT_PC_FULL_MSG;
269 
271  mutt_buffer_string(pattern), comp_flags, err);
272  if (!pat)
273  goto cleanup;
274  }
275  else if (~data & MUTT_GLOBAL_HOOK) /* NOT a global hook */
276  {
277  /* Hooks not allowing full patterns: Check syntax of regex */
278  rx = mutt_mem_malloc(sizeof(regex_t));
279  int rc2 = REG_COMP(rx, NONULL(mutt_buffer_string(pattern)),
280  ((data & MUTT_CRYPT_HOOK) ? REG_ICASE : 0));
281  if (rc2 != 0)
282  {
283  regerror(rc2, rx, err->data, err->dsize);
284  FREE(&rx);
285  goto cleanup;
286  }
287  }
288 
289  hook = mutt_mem_calloc(1, sizeof(struct Hook));
290  hook->type = data;
291  hook->command = mutt_buffer_strdup(cmd);
292  hook->pattern = pat;
293  hook->regex.pattern = mutt_buffer_strdup(pattern);
294  hook->regex.regex = rx;
295  hook->regex.pat_not = pat_not;
296  TAILQ_INSERT_TAIL(&Hooks, hook, entries);
297  rc = MUTT_CMD_SUCCESS;
298 
299 cleanup:
301  mutt_buffer_pool_release(&pattern);
302  return rc;
303 }
#define MUTT_SEND_HOOK
send-hook: when composing a new email
Definition: hook.h:41
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
The "current" mailbox.
Definition: context.h:37
static struct HookList Hooks
Definition: hook.c:72
#define NONULL(x)
Definition: string2.h:37
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define WithCrypto
Definition: lib.h:113
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define MUTT_SHUTDOWN_HOOK
shutdown-hook: run when leaving NeoMutt
Definition: hook.h:59
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
struct Mailbox * ctx_mailbox(struct Context *ctx)
wrapper to get the mailbox in a Context, or NULL
Definition: context.c:444
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer&#39;s contents to another Buffer.
Definition: buffer.c:445
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer&#39;s string.
Definition: buffer.c:432
HookFlags type
Hook type.
Definition: hook.c:64
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
regex_t * regex
compiled expression
Definition: regex3.h:92
String manipulation buffer.
Definition: buffer.h:33
bool pat_not
do not match
Definition: regex3.h:93
A list of user hooks.
Definition: hook.c:62
#define _(a)
Definition: message.h:28
#define MUTT_CHARSET_HOOK
charset-hook: create a charset alias for malformed emails
Definition: hook.h:44
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:54
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:46
void mutt_check_simple(struct Buffer *s, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:113
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
#define MUTT_CRYPT_HOOK
crypt-hook: automatically select a PGP/SMIME key
Definition: hook.h:47
void mutt_buffer_expand_path_regex(struct Buffer *buf, bool regex)
Create the canonical path (with regex char escaping)
Definition: muttlib.c:134
Character set conversion.
Definition: charset.h:68
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
size_t dsize
Length of data.
Definition: buffer.h:37
#define MoreArgs(buf)
Definition: buffer.h:40
#define MUTT_ICONV_HOOK
iconv-hook: create a system charset alias
Definition: hook.h:45
#define SKIPWS(ch)
Definition: string2.h:46
#define MUTT_PC_SEND_MODE_SEARCH
Allow send-mode body searching.
Definition: lib.h:63
struct Menu * menu
Needed for pattern compilation.
Definition: context.h:45
struct Regex regex
Regular expression.
Definition: hook.c:65
#define MUTT_APPEND_HOOK
append-hook: append to a compressed mailbox
Definition: hook.h:53
#define MUTT_MBOX_HOOK
mbox-hook: move messages after reading them
Definition: hook.h:40
#define MUTT_GLOBAL_HOOK
Hooks which don&#39;t take a regex.
Definition: hook.h:60
Alias for another character set.
Definition: charset.h:67
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:1092
int mutt_file_sanitize_regex(struct Buffer *dest, const char *src)
Escape any regex-magic characters in a string.
Definition: file.c:637
#define MUTT_SAVE_HOOK
save-hook: set a default folder when saving an email
Definition: hook.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
#define MUTT_CLOSE_HOOK
close-hook: write to a compressed mailbox
Definition: hook.h:54
char * dptr
Current read/write position.
Definition: buffer.h:36
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:69
#define MUTT_PC_NO_FLAGS
No flags are set.
Definition: lib.h:60
char * data
Pointer to data.
Definition: buffer.h:35
int mutt_comp_valid_command(const char *cmd)
Is this command string allowed?
Definition: compress.c:408
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
#define MUTT_OPEN_HOOK
open-hook: to read a compressed mailbox
Definition: hook.h:52
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
#define MUTT_TIMEOUT_HOOK
timeout-hook: run a command periodically
Definition: hook.h:57
Success: Command worked.
Definition: mutt_commands.h:38
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:322
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:50
WHERE char * CurrentFolder
Currently selected mailbox.
Definition: mutt_globals.h:50
#define MUTT_REPLY_HOOK
reply-hook: when replying to an email
Definition: hook.h:49
#define FREE(x)
Definition: memory.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
char * pattern
printable version
Definition: regex3.h:91
#define MUTT_PC_FULL_MSG
Enable body and header matching.
Definition: lib.h:61
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
#define MUTT_STARTUP_HOOK
startup-hook: run when starting NeoMutt
Definition: hook.h:58
LookupType
Types of character set lookups.
Definition: charset.h:65
#define MUTT_FCC_HOOK
fcc-hook: to save outgoing email
Definition: hook.h:42
struct PatternList * pattern
Used for fcc,save,send-hook.
Definition: hook.c:67
uint8_t PatternCompFlags
Flags for mutt_pattern_comp(), e.g. MUTT_PC_FULL_MSG.
Definition: lib.h:59
#define MUTT_ACCOUNT_HOOK
account-hook: when changing between accounts
Definition: hook.h:48
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:489
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
#define MUTT_FOLDER_HOOK
folder-hook: when entering a mailbox
Definition: hook.h:39
+ Here is the call graph for this function:
+ 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 372 of file hook.c.

374 {
375  enum CommandResult rc = MUTT_CMD_ERROR;
376  bool pat_not = false;
377 
378  struct Buffer *name = mutt_buffer_pool_get();
379  struct Buffer *pattern = mutt_buffer_pool_get();
380  struct Buffer *fmtstring = mutt_buffer_pool_get();
381 
382  if (!IdxFmtHooks)
383  {
386  }
387 
388  if (!MoreArgs(s))
389  {
390  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
391  goto out;
392  }
394  struct HookList *hl = mutt_hash_find(IdxFmtHooks, mutt_buffer_string(name));
395 
396  if (*s->dptr == '!')
397  {
398  s->dptr++;
399  SKIPWS(s->dptr);
400  pat_not = true;
401  }
403 
404  if (!MoreArgs(s))
405  {
406  mutt_buffer_printf(err, _("%s: too few arguments"), buf->data);
407  goto out;
408  }
410 
411  if (MoreArgs(s))
412  {
413  mutt_buffer_printf(err, _("%s: too many arguments"), buf->data);
414  goto out;
415  }
416 
417  const char *const c_default_hook =
418  cs_subset_string(NeoMutt->sub, "default_hook");
419  if (c_default_hook)
420  mutt_check_simple(pattern, c_default_hook);
421 
422  /* check to make sure that a matching hook doesn't already exist */
423  struct Hook *hook = NULL;
424  if (hl)
425  {
426  TAILQ_FOREACH(hook, hl, entries)
427  {
428  if ((hook->regex.pat_not == pat_not) &&
430  {
431  mutt_str_replace(&hook->command, mutt_buffer_string(fmtstring));
432  rc = MUTT_CMD_SUCCESS;
433  goto out;
434  }
435  }
436  }
437 
438  /* MUTT_PC_PATTERN_DYNAMIC sets so that date ranges are regenerated during
439  * matching. This of course is slower, but index-format-hook is commonly
440  * used for date ranges, and they need to be evaluated relative to "now", not
441  * the hook compilation time. */
442  struct PatternList *pat =
444  mutt_buffer_string(pattern),
446  if (!pat)
447  goto out;
448 
449  hook = mutt_mem_calloc(1, sizeof(struct Hook));
450  hook->type = MUTT_IDXFMTHOOK;
451  hook->command = mutt_buffer_strdup(fmtstring);
452  hook->pattern = pat;
453  hook->regex.pattern = mutt_buffer_strdup(pattern);
454  hook->regex.regex = NULL;
455  hook->regex.pat_not = pat_not;
456 
457  if (!hl)
458  {
459  hl = mutt_mem_calloc(1, sizeof(*hl));
460  TAILQ_INIT(hl);
462  }
463 
464  TAILQ_INSERT_TAIL(hl, hook, entries);
465  rc = MUTT_CMD_SUCCESS;
466 
467 out:
469  mutt_buffer_pool_release(&pattern);
470  mutt_buffer_pool_release(&fmtstring);
471 
472  return rc;
473 }
#define MUTT_PC_PATTERN_DYNAMIC
Enable runtime date range evaluation.
Definition: lib.h:62
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:354
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
The "current" mailbox.
Definition: context.h:37
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:327
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
struct Mailbox * ctx_mailbox(struct Context *ctx)
wrapper to get the mailbox in a Context, or NULL
Definition: context.c:444
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer&#39;s string.
Definition: buffer.c:432
HookFlags type
Hook type.
Definition: hook.c:64
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
regex_t * regex
compiled expression
Definition: regex3.h:92
String manipulation buffer.
Definition: buffer.h:33
bool pat_not
do not match
Definition: regex3.h:93
A list of user hooks.
Definition: hook.c:62
#define _(a)
Definition: message.h:28
void mutt_check_simple(struct Buffer *s, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:113
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MUTT_IDXFMTHOOK
index-format-hook: customise the format of the index
Definition: hook.h:56
Container for Accounts, Notifications.
Definition: neomutt.h:36
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
#define MoreArgs(buf)
Definition: buffer.h:40
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:346
#define SKIPWS(ch)
Definition: string2.h:46
#define TAILQ_INIT(head)
Definition: queue.h:765
struct Menu * menu
Needed for pattern compilation.
Definition: context.h:45
struct Regex regex
Regular expression.
Definition: hook.c:65
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:1092
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:293
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
Success: Command worked.
Definition: mutt_commands.h:38
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
static struct HashTable * IdxFmtHooks
Definition: hook.c:74
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
char * pattern
printable version
Definition: regex3.h:91
#define MUTT_HASH_STRDUP_KEYS
make a copy of the keys
Definition: hash.h:102
#define MUTT_PC_FULL_MSG
Enable body and header matching.
Definition: lib.h:61
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
Definition: hash.c:251
struct PatternList * pattern
Used for fcc,save,send-hook.
Definition: hook.c:67
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:
+ 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 478 of file hook.c.

480 {
481  while (MoreArgs(s))
482  {
484  if (mutt_str_equal("*", buf->data))
485  {
487  {
488  mutt_buffer_printf(err, "%s", _("unhook: Can't do unhook * from within a hook"));
489  return MUTT_CMD_WARNING;
490  }
494  }
495  else
496  {
497  HookFlags type = mutt_get_hook_type(buf->data);
498 
499  if (type == MUTT_HOOK_NO_FLAGS)
500  {
501  mutt_buffer_printf(err, _("unhook: unknown hook type: %s"), buf->data);
502  return MUTT_CMD_ERROR;
503  }
504  if (type & (MUTT_CHARSET_HOOK | MUTT_ICONV_HOOK))
505  {
507  return MUTT_CMD_SUCCESS;
508  }
509  if (current_hook_type == type)
510  {
511  mutt_buffer_printf(err, _("unhook: Can't delete a %s from within a %s"),
512  buf->data, buf->data);
513  return MUTT_CMD_WARNING;
514  }
515  if (type == MUTT_IDXFMTHOOK)
517  else
518  mutt_delete_hooks(type);
519  }
520  }
521  return MUTT_CMD_SUCCESS;
522 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
static void delete_idxfmt_hooks(void)
Delete all the index-format-hooks.
Definition: hook.c:364
HookFlags mutt_get_hook_type(const char *name)
Find a hook by name.
Definition: init.c:693
static HookFlags current_hook_type
Definition: hook.c:75
#define _(a)
Definition: message.h:28
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
Definition: hook.c:328
#define MUTT_CHARSET_HOOK
charset-hook: create a charset alias for malformed emails
Definition: hook.h:44
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
uint32_t HookFlags
Flags for mutt_parse_hook(), e.g. MUTT_FOLDER_HOOK.
Definition: hook.h:35
#define MUTT_IDXFMTHOOK
index-format-hook: customise the format of the index
Definition: hook.h:56
void mutt_ch_lookup_remove(void)
Remove all the character set lookups.
Definition: charset.c:521
#define MoreArgs(buf)
Definition: buffer.h:40
#define MUTT_ICONV_HOOK
iconv-hook: create a system charset alias
Definition: hook.h:45
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:38
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ mutt_parse_push()

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

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

Definition at line 1200 of file keymap.c.

1202 {
1204  if (MoreArgs(s))
1205  {
1206  mutt_buffer_printf(err, _("%s: too many arguments"), "push");
1207  return MUTT_CMD_ERROR;
1208  }
1209 
1211  return MUTT_CMD_SUCCESS;
1212 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:620
#define _(a)
Definition: message.h:28
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
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:68
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
static void generic_tokenize_push_string(char *s, void(*generic_push)(int, int))
Parse and queue a &#39;push&#39; command.
Definition: keymap.c:536
Success: Command worked.
Definition: mutt_commands.h:38
+ Here is the call graph for this function:

◆ mutt_parse_bind()

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

Parse the 'bind' command - Implements Command::parse() -bind menu-name <key_sequence> function-name.

Definition at line 1363 of file keymap.c.

1365 {
1366  const struct Binding *bindings = NULL;
1367  enum MenuType mtypes[MenuNamesLen];
1368  int num_menus = 0;
1369  enum CommandResult rc = MUTT_CMD_SUCCESS;
1370 
1371  char *key = parse_keymap(mtypes, s, mutt_array_size(mtypes), &num_menus, err, true);
1372  if (!key)
1373  return MUTT_CMD_ERROR;
1374 
1375  /* function to execute */
1377  if (MoreArgs(s))
1378  {
1379  mutt_buffer_printf(err, _("%s: too many arguments"), "bind");
1380  rc = MUTT_CMD_ERROR;
1381  }
1382  else if (mutt_istr_equal("noop", buf->data))
1383  {
1384  for (int i = 0; i < num_menus; i++)
1385  {
1386  km_bindkey(key, mtypes[i], OP_NULL); /* the 'unbind' command */
1387  bindings = km_get_table(mtypes[i]);
1388  if (bindings)
1389  {
1390  char keystr[32] = { 0 };
1391  km_expand_key_string(key, keystr, sizeof(keystr));
1392  const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1393  mutt_debug(LL_NOTIFY, "NT_BINDING_DELETE: %s %s\n", mname, keystr);
1394 
1395  int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1396  struct EventBinding ev_b = { mtypes[i], key, op };
1398  }
1399  }
1400  }
1401  else
1402  {
1403  for (int i = 0; i < num_menus; i++)
1404  {
1405  /* The pager and editor menus don't use the generic map,
1406  * however for other menus try generic first. */
1407  if ((mtypes[i] != MENU_PAGER) && (mtypes[i] != MENU_EDITOR) && (mtypes[i] != MENU_GENERIC))
1408  {
1409  rc = try_bind(key, mtypes[i], buf->data, OpGeneric, err);
1410  if (rc == MUTT_CMD_SUCCESS)
1411  {
1412  char keystr[32] = { 0 };
1413  km_expand_key_string(key, keystr, sizeof(keystr));
1414  const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1415  mutt_debug(LL_NOTIFY, "NT_BINDING_NEW: %s %s\n", mname, keystr);
1416 
1417  int op = get_op(OpGeneric, buf->data, mutt_str_len(buf->data));
1418  struct EventBinding ev_b = { mtypes[i], key, op };
1420  continue;
1421  }
1422  if (rc == MUTT_CMD_WARNING)
1423  break;
1424  }
1425 
1426  /* Clear any error message, we're going to try again */
1427  err->data[0] = '\0';
1428  bindings = km_get_table(mtypes[i]);
1429  if (bindings)
1430  {
1431  rc = try_bind(key, mtypes[i], buf->data, bindings, err);
1432  if (rc == MUTT_CMD_SUCCESS)
1433  {
1434  char keystr[32] = { 0 };
1435  km_expand_key_string(key, keystr, sizeof(keystr));
1436  const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1437  mutt_debug(LL_NOTIFY, "NT_BINDING_NEW: %s %s\n", mname, keystr);
1438 
1439  int op = get_op(bindings, buf->data, mutt_str_len(buf->data));
1440  struct EventBinding ev_b = { mtypes[i], key, op };
1442  continue;
1443  }
1444  }
1445  }
1446  }
1447  FREE(&key);
1448  return rc;
1449 }
MenuType
Types of GUI selections.
Definition: type.h:35
const int MenuNamesLen
Definition: type.c:56
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
Log of notifications.
Definition: logging.h:45
Generic selection list.
Definition: type.h:45
int op
function id number
Definition: keymap.h:94
int op
Operation the key&#39;s bound to (for bind), e.g. OP_DELETE.
Definition: keymap.h:105
static enum CommandResult try_bind(char *key, enum MenuType mtype, char *func, const struct Binding *bindings, struct Buffer *err)
Try to make a key binding.
Definition: keymap.c:1290
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:104
#define mutt_array_size(x)
Definition: memory.h:33
Pager pager (email viewer)
Definition: type.h:54
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
#define MoreArgs(buf)
Definition: buffer.h:40
Text entry area.
Definition: type.h:43
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:481
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
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:1228
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
Key binding has been added.
Definition: keymap.h:117
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
static int km_expand_key_string(char *str, char *buf, size_t buflen)
Get a human-readable key string.
Definition: keymap.c:893
char * data
Pointer to data.
Definition: buffer.h:35
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
const struct Binding * km_get_table(enum MenuType mtype)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1313
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:31
#define FREE(x)
Definition: memory.h:40
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:493
Mapping between a user key and a function.
Definition: keymap.h:91
A key binding Event.
Definition: keymap.h:101
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
Key binding has been deleted.
Definition: keymap.h:118
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
+ Here is the call graph for this function:

◆ mutt_parse_unbind()

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

Parse the 'unbind' command - Implements Command::parse() -Command unbinds:

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

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

Definition at line 1512 of file keymap.c.

1514 {
1515  bool menu_matches[MENU_MAX] = { 0 };
1516  bool all_keys = false;
1517  char *key = NULL;
1518 
1520  if (mutt_str_equal(buf->data, "*"))
1521  {
1522  for (enum MenuType i = 0; i < MENU_MAX; i++)
1523  menu_matches[i] = true;
1524  }
1525  else
1526  parse_menu(menu_matches, buf->data, err);
1527 
1528  if (MoreArgs(s))
1529  {
1531  key = buf->data;
1532  }
1533  else
1534  all_keys = true;
1535 
1536  if (MoreArgs(s))
1537  {
1538  const char *cmd = (data & MUTT_UNMACRO) ? "unmacro" : "unbind";
1539 
1540  mutt_buffer_printf(err, _("%s: too many arguments"), cmd);
1541  return MUTT_CMD_ERROR;
1542  }
1543 
1544  for (enum MenuType i = 0; i < MENU_MAX; i++)
1545  {
1546  if (!menu_matches[i])
1547  continue;
1548  if (all_keys)
1549  {
1550  km_unbind_all(&Keymaps[i], data);
1551  km_bindkey("<enter>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1552  km_bindkey("<return>", MENU_GENERIC, OP_GENERIC_SELECT_ENTRY);
1553  km_bindkey("<enter>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1554  km_bindkey("<return>", MENU_MAIN, OP_DISPLAY_MESSAGE);
1555  km_bindkey("<backspace>", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1556  km_bindkey("\177", MENU_EDITOR, OP_EDITOR_BACKSPACE);
1557  km_bindkey(":", MENU_GENERIC, OP_ENTER_COMMAND);
1558  km_bindkey(":", MENU_PAGER, OP_ENTER_COMMAND);
1559  if (i != MENU_EDITOR)
1560  {
1561  km_bindkey("?", i, OP_HELP);
1562  km_bindkey("q", i, OP_EXIT);
1563  }
1564 
1565  const char *mname = mutt_map_get_name(i, MenuNames);
1566  mutt_debug(LL_NOTIFY, "NT_MACRO_DELETE_ALL: %s\n", mname);
1567 
1568  struct EventBinding ev_b = { i, NULL, OP_NULL };
1571  &ev_b);
1572  }
1573  else
1574  {
1575  char keystr[32] = { 0 };
1576  km_expand_key_string(key, keystr, sizeof(keystr));
1577  const char *mname = mutt_map_get_name(i, MenuNames);
1578  mutt_debug(LL_NOTIFY, "NT_MACRO_DELETE: %s %s\n", mname, keystr);
1579 
1580  km_bindkey(key, i, OP_NULL);
1581  struct EventBinding ev_b = { i, key, OP_NULL };
1583  (data & MUTT_UNMACRO) ? NT_MACRO_DELETE : NT_BINDING_DELETE, &ev_b);
1584  }
1585  }
1586 
1587  return MUTT_CMD_SUCCESS;
1588 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
MenuType
Types of GUI selections.
Definition: type.h:35
struct KeymapList Keymaps[MENU_MAX]
Array of Keymap keybindings, one for each Menu.
Definition: keymap.c:126
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
Log of notifications.
Definition: logging.h:45
Generic selection list.
Definition: type.h:45
#define _(a)
Definition: message.h:28
#define MUTT_UNMACRO
Definition: keymap.h:34
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
All key bindings have been deleted.
Definition: keymap.h:119
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:104
Definition: type.h:59
Pager pager (email viewer)
Definition: type.h:54
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
#define MoreArgs(buf)
Definition: buffer.h:40
Text entry area.
Definition: type.h:43
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:481
static void * parse_menu(bool *menus, char *s, struct Buffer *err)
Parse menu-names into an array.
Definition: keymap.c:1459
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
Key macro has been deleted.
Definition: keymap.h:122
All key macros have been deleted.
Definition: keymap.h:123
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
static int km_expand_key_string(char *str, char *buf, size_t buflen)
Get a human-readable key string.
Definition: keymap.c:893
char * data
Pointer to data.
Definition: buffer.h:35
Index panel (list of emails)
Definition: type.h:50
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Success: Command worked.
Definition: mutt_commands.h:38
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:31
A key binding Event.
Definition: keymap.h:101
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
static void km_unbind_all(struct KeymapList *km_list, unsigned long mode)
Free all the keys in the supplied Keymap.
Definition: keymap.c:1488
Key binding has been deleted.
Definition: keymap.h:118
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
+ Here is the call graph for this function:

◆ mutt_parse_macro()

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

Parse the 'macro' command - Implements Command::parse() -macro <menu> <key> <macro> <description>

Definition at line 1595 of file keymap.c.

1597 {
1598  enum MenuType mtypes[MenuNamesLen];
1599  int num_menus = 0;
1600  enum CommandResult rc = MUTT_CMD_ERROR;
1601 
1602  char *key = parse_keymap(mtypes, s, mutt_array_size(mtypes), &num_menus, err, false);
1603  if (!key)
1604  return MUTT_CMD_ERROR;
1605 
1607  /* make sure the macro sequence is not an empty string */
1608  if (buf->data[0] == '\0')
1609  {
1610  mutt_buffer_strcpy(err, _("macro: empty key sequence"));
1611  }
1612  else
1613  {
1614  if (MoreArgs(s))
1615  {
1616  char *seq = mutt_str_dup(buf->data);
1618 
1619  if (MoreArgs(s))
1620  {
1621  mutt_buffer_printf(err, _("%s: too many arguments"), "macro");
1622  }
1623  else
1624  {
1625  for (int i = 0; i < num_menus; i++)
1626  {
1627  rc = km_bind(key, mtypes[i], OP_MACRO, seq, buf->data);
1628  if (rc == MUTT_CMD_SUCCESS)
1629  {
1630  char keystr[32] = { 0 };
1631  km_expand_key_string(key, keystr, sizeof(keystr));
1632  const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1633  mutt_debug(LL_NOTIFY, "NT_MACRO_NEW: %s %s\n", mname, keystr);
1634 
1635  struct EventBinding ev_b = { mtypes[i], key, OP_MACRO };
1637  continue;
1638  }
1639  }
1640  }
1641 
1642  FREE(&seq);
1643  }
1644  else
1645  {
1646  for (int i = 0; i < num_menus; i++)
1647  {
1648  rc = km_bind(key, mtypes[i], OP_MACRO, buf->data, NULL);
1649  if (rc == MUTT_CMD_SUCCESS)
1650  {
1651  char keystr[32] = { 0 };
1652  km_expand_key_string(key, keystr, sizeof(keystr));
1653  const char *mname = mutt_map_get_name(mtypes[i], MenuNames);
1654  mutt_debug(LL_NOTIFY, "NT_MACRO_NEW: %s %s\n", mname, keystr);
1655 
1656  struct EventBinding ev_b = { mtypes[i], key, OP_MACRO };
1658  continue;
1659  }
1660  }
1661  }
1662  }
1663  FREE(&key);
1664  return rc;
1665 }
Key macro has been added.
Definition: keymap.h:121
MenuType
Types of GUI selections.
Definition: type.h:35
const int MenuNamesLen
Definition: type.c:56
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
Log of notifications.
Definition: logging.h:45
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
const char * key
Key string being bound (for new bind/macro)
Definition: keymap.h:104
#define mutt_array_size(x)
Definition: memory.h:33
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
#define MoreArgs(buf)
Definition: buffer.h:40
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:1228
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:68
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
static int km_expand_key_string(char *str, char *buf, size_t buflen)
Get a human-readable key string.
Definition: keymap.c:893
enum CommandResult km_bind(char *s, enum MenuType mtype, int op, char *macro, char *desc)
Bind a key to a macro.
Definition: keymap.c:455
char * data
Pointer to data.
Definition: buffer.h:35
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Success: Command worked.
Definition: mutt_commands.h:38
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:31
#define FREE(x)
Definition: memory.h:40
A key binding Event.
Definition: keymap.h:101
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
+ Here is the call graph for this function:

◆ mutt_parse_exec()

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

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

Definition at line 1670 of file keymap.c.

1672 {
1673  int ops[128];
1674  int nops = 0;
1675  const struct Binding *bindings = NULL;
1676  char *function = NULL;
1677 
1678  if (!MoreArgs(s))
1679  {
1680  mutt_buffer_strcpy(err, _("exec: no arguments"));
1681  return MUTT_CMD_ERROR;
1682  }
1683 
1684  do
1685  {
1687  function = buf->data;
1688 
1689  const enum MenuType mtype = menu_get_current_type();
1690  bindings = km_get_table(mtype);
1691  if (!bindings && (mtype != MENU_PAGER))
1692  bindings = OpGeneric;
1693 
1694  ops[nops] = get_op(bindings, function, mutt_str_len(function));
1695  if ((ops[nops] == OP_NULL) && (mtype != MENU_PAGER))
1696  ops[nops] = get_op(OpGeneric, function, mutt_str_len(function));
1697 
1698  if (ops[nops] == OP_NULL)
1699  {
1700  mutt_flushinp();
1701  mutt_error(_("%s: no such function"), function);
1702  return MUTT_CMD_ERROR;
1703  }
1704  nops++;
1705  } while (MoreArgs(s) && nops < mutt_array_size(ops));
1706 
1707  while (nops)
1708  mutt_push_macro_event(0, ops[--nops]);
1709 
1710  return MUTT_CMD_SUCCESS;
1711 }
MenuType
Types of GUI selections.
Definition: type.h:35
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:88
void mutt_push_macro_event(int ch, int op)
Add the character/operation to the macro buffer.
Definition: curs_lib.c:620
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:668
#define _(a)
Definition: message.h:28
#define mutt_array_size(x)
Definition: memory.h:33
Pager pager (email viewer)
Definition: type.h:54
#define MoreArgs(buf)
Definition: buffer.h:40
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.c:53
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
const struct Binding * km_get_table(enum MenuType mtype)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1313
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
Success: Command worked.
Definition: mutt_commands.h:38
static int get_op(const struct Binding *bindings, const char *start, size_t len)
Get the function by its name.
Definition: keymap.c:493
Mapping between a user key and a function.
Definition: keymap.h:91
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ mutt_lua_parse()

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

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

Definition at line 477 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 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
lua_State * LuaState
Global Lua State.
Definition: mutt_lua.c:56
static bool lua_init(lua_State **l)
Initialise a Lua State.
Definition: mutt_lua.c:441
Log at debug level 2.
Definition: logging.h:41
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Success: Command worked.
Definition: mutt_commands.h:38
+ Here is the call graph for this function:

◆ mutt_lua_source_file()

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

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

Definition at line 499 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 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:88
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
lua_State * LuaState
Global Lua State.
Definition: mutt_lua.c:56
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:122
#define MoreArgs(buf)
Definition: buffer.h:40
static bool lua_init(lua_State **l)
Initialise a Lua State.
Definition: mutt_lua.c:441
Log at debug level 2.
Definition: logging.h:41
#define PATH_MAX
Definition: mutt.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
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:749
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ mutt_parse_score()

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

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

Definition at line 88 of file score.c.

90 {
91  struct Score *ptr = NULL, *last = NULL;
92  char *pattern = NULL, *pc = NULL;
93 
95  if (!MoreArgs(s))
96  {
97  mutt_buffer_printf(err, _("%s: too few arguments"), "score");
98  return MUTT_CMD_WARNING;
99  }
100  pattern = mutt_buffer_strdup(buf);
102  if (MoreArgs(s))
103  {
104  FREE(&pattern);
105  mutt_buffer_printf(err, _("%s: too many arguments"), "score");
106  return MUTT_CMD_WARNING;
107  }
108 
109  /* look for an existing entry and update the value, else add it to the end
110  * of the list */
111  for (ptr = ScoreList, last = NULL; ptr; last = ptr, ptr = ptr->next)
112  if (mutt_str_equal(pattern, ptr->str))
113  break;
114  if (!ptr)
115  {
116  struct PatternList *pat =
118  pattern, MUTT_PC_NO_FLAGS, err);
119  if (!pat)
120  {
121  FREE(&pattern);
122  return MUTT_CMD_ERROR;
123  }
124  ptr = mutt_mem_calloc(1, sizeof(struct Score));
125  if (last)
126  last->next = ptr;
127  else
128  ScoreList = ptr;
129  ptr->pat = pat;
130  ptr->str = pattern;
131  }
132  else
133  {
134  /* 'buf' arg was cleared and 'pattern' holds the only reference;
135  * as here 'ptr' != NULL -> update the value only in which case
136  * ptr->str already has the string, so pattern should be freed. */
137  FREE(&pattern);
138  }
139  pc = buf->data;
140  if (*pc == '=')
141  {
142  ptr->exact = true;
143  pc++;
144  }
145  if (mutt_str_atoi(pc, &ptr->val) < 0)
146  {
147  FREE(&pattern);
148  mutt_buffer_strcpy(err, _("Error: score: invalid number"));
149  return MUTT_CMD_ERROR;
150  }
151  OptNeedRescore = true;
152  return MUTT_CMD_SUCCESS;
153 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
The "current" mailbox.
Definition: context.h:37
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
int mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: string.c:252
struct Mailbox * ctx_mailbox(struct Context *ctx)
wrapper to get the mailbox in a Context, or NULL
Definition: context.c:444
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
struct PatternList * pat
Definition: score.c:53
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer&#39;s string.
Definition: buffer.c:432
#define _(a)
Definition: message.h:28
static struct Score * ScoreList
Definition: score.c:59
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
WHERE bool OptNeedRescore
(pseudo) set when the &#39;score&#39; command is used
Definition: options.h:41
#define MoreArgs(buf)
Definition: buffer.h:40
struct Menu * menu
Needed for pattern compilation.
Definition: context.h:45
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:1092
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
#define MUTT_PC_NO_FLAGS
No flags are set.
Definition: lib.h:60
char * data
Pointer to data.
Definition: buffer.h:35
Scoring rule for email.
Definition: score.c:50
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define FREE(x)
Definition: memory.h:40
struct Score * next
Definition: score.c:56
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ mutt_parse_unscore()

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

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

Definition at line 200 of file score.c.

202 {
203  struct Score *tmp = NULL, *last = NULL;
204 
205  while (MoreArgs(s))
206  {
208  if (mutt_str_equal("*", buf->data))
209  {
210  for (tmp = ScoreList; tmp;)
211  {
212  last = tmp;
213  tmp = tmp->next;
214  mutt_pattern_free(&last->pat);
215  FREE(&last);
216  }
217  ScoreList = NULL;
218  }
219  else
220  {
221  for (tmp = ScoreList; tmp; last = tmp, tmp = tmp->next)
222  {
223  if (mutt_str_equal(buf->data, tmp->str))
224  {
225  if (last)
226  last->next = tmp->next;
227  else
228  ScoreList = tmp->next;
229  mutt_pattern_free(&tmp->pat);
230  FREE(&tmp);
231  /* there should only be one score per pattern, so we can stop here */
232  break;
233  }
234  }
235  }
236  }
237  OptNeedRescore = true;
238  return MUTT_CMD_SUCCESS;
239 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
static struct Score * ScoreList
Definition: score.c:59
WHERE bool OptNeedRescore
(pseudo) set when the &#39;score&#39; command is used
Definition: options.h:41
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Scoring rule for email.
Definition: score.c:50
Success: Command worked.
Definition: mutt_commands.h:38
#define FREE(x)
Definition: memory.h:40
struct Score * next
Definition: score.c:56
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition: compile.c:1038
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ 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 42 of file commands.c.

44 {
45  struct Buffer *path = mutt_buffer_pool_get();
46 
47  do
48  {
52  } while (MoreArgs(s));
54 
55  return MUTT_CMD_SUCCESS;
56 }
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
#define MoreArgs(buf)
Definition: buffer.h:40
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: muttlib.c:1728
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
Success: Command worked.
Definition: mutt_commands.h:38
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:322
#define MUTT_TOKEN_BACKTICK_VARS
Expand variables within backticks.
Definition: mutt.h:74
+ Here is the call graph for this function:
+ 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 61 of file commands.c.

63 {
64  struct Buffer *path = mutt_buffer_pool_get();
65 
66  do
67  {
69  /* Check for deletion of entire list */
70  if (mutt_str_equal(mutt_buffer_string(path), "*"))
71  {
73  break;
74  }
77  } while (MoreArgs(s));
79 
80  return MUTT_CMD_SUCCESS;
81 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: muttlib.c:1753
Success: Command worked.
Definition: mutt_commands.h:38
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:322
#define MUTT_TOKEN_BACKTICK_VARS
Expand variables within backticks.
Definition: mutt.h:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_unreplace_list()

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

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

Definition at line 67 of file subjectrx.c.

69 {
70  /* First token is a regex. */
71  if (!MoreArgs(s))
72  {
73  mutt_buffer_printf(err, _("%s: too few arguments"), "unsubjectrx");
74  return MUTT_CMD_WARNING;
75  }
76 
78 
79  /* "*" is a special case. */
80  if (mutt_str_equal(buf->data, "*"))
81  {
83  return MUTT_CMD_SUCCESS;
84  }
85 
86  mutt_replacelist_remove(list, buf->data);
87  return MUTT_CMD_SUCCESS;
88 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:448
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:565
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_replace_list()

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

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

Definition at line 93 of file subjectrx.c.

95 {
96  struct Buffer templ = mutt_buffer_make(0);
97 
98  /* First token is a regex. */
99  if (!MoreArgs(s))
100  {
101  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
102  return MUTT_CMD_WARNING;
103  }
105 
106  /* Second token is a replacement template */
107  if (!MoreArgs(s))
108  {
109  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
110  return MUTT_CMD_WARNING;
111  }
113 
114  if (mutt_replacelist_add(list, buf->data, templ.data, err) != 0)
115  {
116  FREE(&templ.data);
117  return MUTT_CMD_ERROR;
118  }
119  FREE(&templ.data);
120 
121  return MUTT_CMD_SUCCESS;
122 }
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:263
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
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
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define FREE(x)
Definition: memory.h:40
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_subjectrx_list()

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

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

Definition at line 164 of file subjectrx.c.

166 {
167  enum CommandResult rc;
168 
169  rc = parse_replace_list(buf, s, &SubjectRegexList, err);
170  if (rc == MUTT_CMD_SUCCESS)
171  {
172  mutt_debug(LL_NOTIFY, "NT_SUBJRX_ADD: %s\n", buf->data);
174  }