NeoMutt  2019-12-07-60-g0cfa53
Teaching an old dog new tricks
DOXYGEN
init.c File Reference

Config/command parsing. More...

#include "config.h"
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <pwd.h>
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <unistd.h>
#include "mutt/mutt.h"
#include "address/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "init.h"
#include "alias.h"
#include "context.h"
#include "filter.h"
#include "keymap.h"
#include "monitor.h"
#include "mutt_menu.h"
#include "mutt_parse.h"
#include "mx.h"
#include "myvar.h"
#include "options.h"
#include "protos.h"
#include "sidebar.h"
#include "version.h"
#include "hcache/hcache.h"
#include "notmuch/mutt_notmuch.h"
#include "imap/imap.h"
#include <libintl.h>
+ Include dependency graph for init.c:

Go to the source code of this file.

Macros

#define MAX_ERRS   128
 
#define NUM_VARS   mutt_array_size(MuttVars)
 
#define NUM_COMMANDS   mutt_array_size(Commands)
 

Enumerations

enum  GroupState { GS_NONE, GS_RX, GS_ADDR }
 Type of email address group. More...
 

Functions

static void add_to_stailq (struct ListHead *head, const char *str)
 Add a string to a list. More...
 
static void alternates_clean (void)
 Clear the recipient valid flag of all emails. More...
 
static void attachments_clean (void)
 always wise to do what someone else did before More...
 
static void matches_ensure_morespace (int current)
 Allocate more space for auto-completion. More...
 
static void candidate (char *user, const char *src, char *dest, size_t dlen)
 helper function for completion More...
 
static void clear_subject_mods (void)
 Clear out all modified email subjects. More...
 
static int complete_all_nm_tags (const char *pt)
 Pass a list of Notmuch tags to the completion code. More...
 
static int execute_commands (struct ListHead *p)
 Execute a set of NeoMutt commands. More...
 
static char * find_cfg (const char *home, const char *xdg_cfg_home)
 Find a config file. More...
 
static char * getmailname (void)
 Try to retrieve the FQDN from mailname files. More...
 
static bool get_hostname (struct ConfigSet *cs)
 Find the Fully-Qualified Domain Name. More...
 
static struct AttachMatchmutt_attachmatch_new (void)
 Create a new AttachMatch. More...
 
static enum CommandResult parse_attach_list (struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
 Parse the "attachments" command. More...
 
static int parse_grouplist (struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse a group context. More...
 
static enum CommandResult parse_replace_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse a string replacement rule - Implements command_t. More...
 
static enum CommandResult parse_unattach_list (struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
 Parse the "unattachments" command. More...
 
static enum CommandResult parse_unreplace_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Remove a string replacement rule - Implements command_t. More...
 
static int print_attach_list (struct ListHead *h, const char op, const char *name)
 Print a list of attachments. More...
 
static void remove_from_stailq (struct ListHead *head, const char *str)
 Remove an item, matching a string, from a List. More...
 
static int source_rc (const char *rcfile_path, struct Buffer *err)
 Read an initialization file. More...
 
static enum CommandResult parse_alias (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'alias' command - Implements command_t. More...
 
static enum CommandResult parse_alternates (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'alternates' command - Implements command_t. More...
 
static enum CommandResult parse_attachments (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'attachments' command - Implements command_t. More...
 
static enum CommandResult parse_echo (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'echo' command - Implements command_t. More...
 
static enum CommandResult parse_finish (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'finish' command - Implements command_t. More...
 
static enum CommandResult parse_group (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'group' and 'ungroup' commands - Implements command_t. More...
 
static bool is_function (const char *name)
 Is the argument a neomutt function? More...
 
static enum CommandResult parse_ifdef (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'ifdef' and 'ifndef' commands - Implements command_t. More...
 
static enum CommandResult parse_ignore (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'ignore' command - Implements command_t. More...
 
static enum CommandResult parse_lists (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'lists' command - Implements command_t. More...
 
static enum CommandResult parse_mailboxes (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'mailboxes' command - Implements command_t. More...
 
static enum CommandResult parse_my_hdr (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'my_hdr' command - Implements command_t. More...
 
static enum CommandResult parse_path_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'sidebar_whitelist' command - Implements command_t. More...
 
static enum CommandResult parse_path_unlist (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unsidebar_whitelist' command - Implements command_t. More...
 
static enum CommandResult parse_set (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'set' family of commands - Implements command_t. More...
 
static enum CommandResult parse_setenv (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'setenv' and 'unsetenv' commands - Implements command_t. More...
 
static enum CommandResult parse_source (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'source' command - Implements command_t. More...
 
static enum CommandResult parse_spam_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'spam' and 'nospam' commands - Implements command_t. More...
 
static enum CommandResult parse_stailq (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse a list command - Implements command_t. More...
 
static enum CommandResult parse_subjectrx_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'subjectrx' command - Implements command_t. More...
 
static enum CommandResult parse_subscribe (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'subscribe' command - Implements command_t. More...
 
static enum CommandResult parse_subscribe_to (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'subscribe-to' command - Implements command_t. More...
 
static enum CommandResult parse_tag_formats (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'tag-formats' command - Implements command_t. More...
 
static enum CommandResult parse_tag_transforms (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'tag-transforms' command - Implements command_t. More...
 
static enum CommandResult parse_unalias (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unalias' command - Implements command_t. More...
 
static enum CommandResult parse_unalternates (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unalternates' command - Implements command_t. More...
 
static void mutt_attachmatch_free (struct AttachMatch **ptr)
 Free an AttachMatch - Implements list_free_t. More...
 
static enum CommandResult parse_unattachments (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unattachments' command - Implements command_t. More...
 
static enum CommandResult parse_unignore (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unignore' command - Implements command_t. More...
 
static enum CommandResult parse_unlists (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unlists' command - Implements command_t. More...
 
static enum CommandResult parse_unmailboxes (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unmailboxes' command - Implements command_t. More...
 
static enum CommandResult parse_unmy_hdr (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unmy_hdr' command - Implements command_t. More...
 
static enum CommandResult parse_unstailq (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse an unlist command - Implements command_t. More...
 
static enum CommandResult parse_unsubjectrx_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unsubjectrx' command - Implements command_t. More...
 
static enum CommandResult parse_unsubscribe (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unsubscribe' command - Implements command_t. More...
 
static enum CommandResult parse_unsubscribe_from (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unsubscribe-from' command - Implements command_t. More...
 
const struct Commandmutt_command_get (const char *s)
 Get a Command by its name. More...
 
int mutt_extract_token (struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
 Extract one token from a string. More...
 
void mutt_opts_free (void)
 clean up before quitting More...
 
HookFlags mutt_get_hook_type (const char *name)
 Find a hook by name. More...
 
int mutt_init (struct ConfigSet *cs, bool skip_sys_rc, struct ListHead *commands)
 Initialise NeoMutt. More...
 
enum CommandResult mutt_parse_rc_line (char *line, struct Buffer *token, struct Buffer *err)
 Parse a line of user config. More...
 
int mutt_query_variables (struct ListHead *queries)
 Implement the -Q command line flag. More...
 
enum QuadOption query_quadoption (enum QuadOption opt, const char *prompt)
 Ask the user a quad-question. More...
 
int mutt_command_complete (char *buf, size_t buflen, int pos, int numtabs)
 Complete a command name. More...
 
int mutt_label_complete (char *buf, size_t buflen, int numtabs)
 Complete a label name. More...
 
bool mutt_nm_query_complete (char *buf, size_t buflen, int pos, int numtabs)
 Complete to the nearest notmuch tag. More...
 
bool mutt_nm_tag_complete (char *buf, size_t buflen, int numtabs)
 Complete to the nearest notmuch tag. More...
 
int mutt_var_value_complete (char *buf, size_t buflen, int pos)
 Complete a variable/value. More...
 
struct ConfigSetinit_config (size_t size)
 Initialise the config system. More...
 
int charset_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "charset" config variable - Implements cs_validator() More...
 
int hcache_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "header_cache_backend" config variable - Implements cs_validator() More...
 
int pager_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Check for config variables that can't be set from the pager - Implements cs_validator() More...
 
int multipart_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "show_multipart_alternative" config variable - Implements cs_validator() More...
 
int reply_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "reply_regex" config variable - Implements cs_validator() More...
 
int wrapheaders_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "wrap_headers" config variable - Implements cs_validator() More...
 

Variables

static struct ListHead MuttrcStack = STAILQ_HEAD_INITIALIZER(MuttrcStack)
 
static char UserTyped [1024] = { 0 }
 
static int NumMatched = 0
 
static char Completed [256] = { 0 }
 
static const char ** Matches
 
static int MatchesListsize = MAX(NUM_VARS, NUM_COMMANDS) + 10
 
static char ** nm_tags
 

Detailed Description

Config/command parsing.

Authors
  • Michael R. Elkins
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file init.c.

Macro Definition Documentation

◆ MAX_ERRS

#define MAX_ERRS   128

Definition at line 81 of file init.c.

◆ NUM_VARS

#define NUM_VARS   mutt_array_size(MuttVars)

Definition at line 83 of file init.c.

◆ NUM_COMMANDS

#define NUM_COMMANDS   mutt_array_size(Commands)

Definition at line 84 of file init.c.

Enumeration Type Documentation

◆ GroupState

enum GroupState

Type of email address group.

Enumerator
GS_NONE 

Group is missing an argument.

GS_RX 

Entry is a regular expression.

GS_ADDR 

Entry is an address.

Definition at line 104 of file init.c.

105 {
106  GS_NONE,
107  GS_RX,
108  GS_ADDR,
109 };
Group is missing an argument.
Definition: init.c:106
Entry is an address.
Definition: init.c:108
Entry is a regular expression.
Definition: init.c:107

Function Documentation

◆ add_to_stailq()

static void add_to_stailq ( struct ListHead *  head,
const char *  str 
)
static

Add a string to a list.

Parameters
headString list
strString to add
Note
Duplicate or empty strings will not be added

Definition at line 118 of file init.c.

119 {
120  /* don't add a NULL or empty string to the list */
121  if (!str || (*str == '\0'))
122  return;
123 
124  /* check to make sure the item is not already on this list */
125  struct ListNode *np = NULL;
126  STAILQ_FOREACH(np, head, entries)
127  {
128  if (mutt_str_strcasecmp(str, np->data) == 0)
129  {
130  return;
131  }
132  }
134 }
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:65
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
char * data
String.
Definition: list.h:35
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
A List node for strings.
Definition: list.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alternates_clean()

static void alternates_clean ( void  )
static

Clear the recipient valid flag of all emails.

Definition at line 139 of file init.c.

140 {
141  if (!Context || !Context->mailbox)
142  return;
143 
144  struct Mailbox *m = Context->mailbox;
145  for (int i = 0; i < m->msg_count; i++)
146  {
147  struct Email *e = m->emails[i];
148  if (!e)
149  break;
150  e->recip_valid = false;
151  }
152 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:98
The "current" mailbox.
Definition: context.h:36
int msg_count
Total number of messages.
Definition: mailbox.h:90
The envelope/body of an email.
Definition: email.h:37
struct Mailbox * mailbox
Definition: context.h:50
A mailbox.
Definition: mailbox.h:80
bool recip_valid
Is_recipient is valid.
Definition: email.h:58
+ Here is the caller graph for this function:

◆ attachments_clean()

static void attachments_clean ( void  )
static

always wise to do what someone else did before

Definition at line 157 of file init.c.

158 {
159  if (!Context || !Context->mailbox)
160  return;
161 
162  struct Mailbox *m = Context->mailbox;
163  for (int i = 0; i < m->msg_count; i++)
164  {
165  struct Email *e = m->emails[i];
166  if (!e)
167  break;
168  e->attach_valid = false;
169  }
170 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:98
The "current" mailbox.
Definition: context.h:36
int msg_count
Total number of messages.
Definition: mailbox.h:90
The envelope/body of an email.
Definition: email.h:37
struct Mailbox * mailbox
Definition: context.h:50
A mailbox.
Definition: mailbox.h:80
bool attach_valid
true when the attachment count is valid
Definition: email.h:70
+ Here is the caller graph for this function:

◆ matches_ensure_morespace()

static void matches_ensure_morespace ( int  current)
static

Allocate more space for auto-completion.

Parameters
currentCurrent allocation

Definition at line 176 of file init.c.

177 {
178  if (current <= (MatchesListsize - 2))
179  return;
180 
181  int base_space = MAX(NUM_VARS, NUM_COMMANDS) + 1;
182  int extra_space = MatchesListsize - base_space;
183  extra_space *= 2;
184  const int space = base_space + extra_space;
185  mutt_mem_realloc(&Matches, space * sizeof(char *));
186  memset(&Matches[current + 1], 0, space - current);
187  MatchesListsize = space;
188 }
#define MAX(a, b)
Definition: memory.h:30
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
static int MatchesListsize
Definition: init.c:94
#define NUM_VARS
Definition: init.c:83
static const char ** Matches
Definition: init.c:92
#define NUM_COMMANDS
Definition: init.c:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ candidate()

static void candidate ( char *  user,
const char *  src,
char *  dest,
size_t  dlen 
)
static

helper function for completion

Parameters
userUser entered data for completion
srcCandidate for completion
destCompletion result gets here
dlenLength of dest buffer

Changes the dest buffer if necessary/possible to aid completion.

Definition at line 199 of file init.c.

200 {
201  if (!dest || !user || !src)
202  return;
203 
204  if (strstr(src, user) != src)
205  return;
206 
208  Matches[NumMatched++] = src;
209  if (dest[0] == '\0')
210  mutt_str_strfcpy(dest, src, dlen);
211  else
212  {
213  int l;
214  for (l = 0; src[l] && src[l] == dest[l]; l++)
215  ;
216  dest[l] = '\0';
217  }
218 }
static int NumMatched
Definition: init.c:90
static void matches_ensure_morespace(int current)
Allocate more space for auto-completion.
Definition: init.c:176
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
static const char ** Matches
Definition: init.c:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear_subject_mods()

static void clear_subject_mods ( void  )
static

Clear out all modified email subjects.

Definition at line 223 of file init.c.

224 {
225  if (!Context || !Context->mailbox)
226  return;
227 
228  struct Mailbox *m = Context->mailbox;
229  for (int i = 0; i < m->msg_count; i++)
230  {
231  struct Email *e = m->emails[i];
232  if (!e || !e->env)
233  continue;
234  FREE(&e->env->disp_subj);
235  }
236 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:98
The "current" mailbox.
Definition: context.h:36
int msg_count
Total number of messages.
Definition: mailbox.h:90
The envelope/body of an email.
Definition: email.h:37
char * disp_subj
Display subject (modified copy of subject)
Definition: envelope.h:68
struct Mailbox * mailbox
Definition: context.h:50
struct Envelope * env
Envelope information.
Definition: email.h:89
A mailbox.
Definition: mailbox.h:80
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ complete_all_nm_tags()

static int complete_all_nm_tags ( const char *  pt)
static

Pass a list of Notmuch tags to the completion code.

Parameters
ptList of all Notmuch tags
Return values
0Success
-1Error

Definition at line 245 of file init.c.

246 {
247  int tag_count_1 = 0;
248  int tag_count_2 = 0;
249 
250  NumMatched = 0;
251  mutt_str_strfcpy(UserTyped, pt, sizeof(UserTyped));
252  memset(Matches, 0, MatchesListsize);
253  memset(Completed, 0, sizeof(Completed));
254 
256 
257  /* Work out how many tags there are. */
258  if (nm_get_all_tags(Context->mailbox, NULL, &tag_count_1) || (tag_count_1 == 0))
259  goto done;
260 
261  /* Free the old list, if any. */
262  if (nm_tags)
263  {
264  for (int i = 0; nm_tags[i]; i++)
265  FREE(&nm_tags[i]);
266  FREE(&nm_tags);
267  }
268  /* Allocate a new list, with sentinel. */
269  nm_tags = mutt_mem_malloc((tag_count_1 + 1) * sizeof(char *));
270  nm_tags[tag_count_1] = NULL;
271 
272  /* Get all the tags. */
273  if (nm_get_all_tags(Context->mailbox, nm_tags, &tag_count_2) || (tag_count_1 != tag_count_2))
274  {
275  FREE(&nm_tags);
276  nm_tags = NULL;
278  return -1;
279  }
280 
281  /* Put them into the completion machinery. */
282  for (int num = 0; num < tag_count_1; num++)
283  {
284  candidate(UserTyped, nm_tags[num], Completed, sizeof(Completed));
285  }
286 
289 
290 done:
292  return 0;
293 }
The "current" mailbox.
Definition: context.h:36
static int NumMatched
Definition: init.c:90
static char ** nm_tags
Definition: init.c:98
struct Mailbox * mailbox
Definition: context.h:50
static char Completed[256]
Definition: init.c:91
void nm_db_longrun_done(struct Mailbox *m)
Finish a long transaction.
Definition: nm_db.c:304
static int MatchesListsize
Definition: init.c:94
static void matches_ensure_morespace(int current)
Allocate more space for auto-completion.
Definition: init.c:176
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
int nm_get_all_tags(struct Mailbox *m, char **tag_list, int *tag_count)
Fill a list with all notmuch tags.
static char UserTyped[1024]
Definition: init.c:88
static const char ** Matches
Definition: init.c:92
#define FREE(x)
Definition: memory.h:40
void nm_db_longrun_init(struct Mailbox *m, bool writable)
Start a long transaction.
Definition: nm_db.c:289
static void candidate(char *user, const char *src, char *dest, size_t dlen)
helper function for completion
Definition: init.c:199
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_commands()

static int execute_commands ( struct ListHead *  p)
static

Execute a set of NeoMutt commands.

Parameters
pList of command strings
Return values
0Success, all the commands succeeded
-1Error

Definition at line 302 of file init.c.

303 {
304  int rc = 0;
305  struct Buffer *err = mutt_buffer_pool_get();
306  struct Buffer *token = mutt_buffer_pool_get();
307 
308  struct ListNode *np = NULL;
309  STAILQ_FOREACH(np, p, entries)
310  {
311  enum CommandResult rc2 = mutt_parse_rc_line(np->data, token, err);
312  if (rc2 == MUTT_CMD_ERROR)
313  mutt_error(_("Error in command line: %s"), mutt_b2s(err));
314  else if (rc2 == MUTT_CMD_WARNING)
315  mutt_warning(_("Warning in command line: %s"), mutt_b2s(err));
316 
317  if ((rc2 == MUTT_CMD_ERROR) || (rc2 == MUTT_CMD_WARNING))
318  {
319  mutt_buffer_pool_release(&token);
321  return -1;
322  }
323  }
324  mutt_buffer_pool_release(&token);
326 
327  return rc;
328 }
#define mutt_warning(...)
Definition: logging.h:82
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:33
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
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
#define _(a)
Definition: message.h:28
#define mutt_b2s(buf)
Definition: buffer.h:41
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
char * data
String.
Definition: list.h:35
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:84
A List node for strings.
Definition: list.h:33
enum CommandResult mutt_parse_rc_line(char *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
Definition: init.c:3252
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_cfg()

static char* find_cfg ( const char *  home,
const char *  xdg_cfg_home 
)
static

Find a config file.

Parameters
homeUser's home directory
xdg_cfg_homeXDG home directory
Return values
ptrSuccess, first matching directory
NULLError, no matching directories

Definition at line 337 of file init.c.

338 {
339  const char *names[] = {
340  "neomuttrc",
341  "muttrc",
342  NULL,
343  };
344 
345  const char *locations[][2] = {
346  { xdg_cfg_home, "neomutt/" },
347  { xdg_cfg_home, "mutt/" },
348  { home, ".neomutt/" },
349  { home, ".mutt/" },
350  { home, "." },
351  { NULL, NULL },
352  };
353 
354  for (int i = 0; locations[i][0] || locations[i][1]; i++)
355  {
356  if (!locations[i][0])
357  continue;
358 
359  for (int j = 0; names[j]; j++)
360  {
361  char buf[256];
362 
363  snprintf(buf, sizeof(buf), "%s/%s%s", locations[i][0], locations[i][1], names[j]);
364  if (access(buf, F_OK) == 0)
365  return mutt_str_strdup(buf);
366  }
367  }
368 
369  return NULL;
370 }
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getmailname()

static char* getmailname ( void  )
static

Try to retrieve the FQDN from mailname files.

Return values
ptrHeap allocated string with the FQDN
NULLif no valid mailname file could be read

Definition at line 378 of file init.c.

379 {
380  char *mailname = NULL;
381  static const char *mn_files[] = { "/etc/mailname", "/etc/mail/mailname" };
382 
383  for (size_t i = 0; i < mutt_array_size(mn_files); i++)
384  {
385  FILE *fp = mutt_file_fopen(mn_files[i], "r");
386  if (!fp)
387  continue;
388 
389  size_t len = 0;
390  mailname = mutt_file_read_line(NULL, &len, fp, NULL, 0);
391  mutt_file_fclose(&fp);
392  if (mailname && *mailname)
393  break;
394 
395  FREE(&mailname);
396  }
397 
398  return mailname;
399 }
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, int flags)
Read a line from a file.
Definition: file.c:664
#define mutt_array_size(x)
Definition: memory.h:33
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
#define FREE(x)
Definition: memory.h:40
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:585
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_hostname()

static bool get_hostname ( struct ConfigSet cs)
static

Find the Fully-Qualified Domain Name.

Return values
trueSuccess
falseError, failed to find any name

Use several methods to try to find the Fully-Qualified domain name of this host. If the user has already configured a hostname, this function will use it.

Definition at line 410 of file init.c.

411 {
412  char *str = NULL;
413  struct utsname utsname;
414 
415  if (C_Hostname)
416  {
417  str = C_Hostname;
418  }
419  else
420  {
421  /* The call to uname() shouldn't fail, but if it does, the system is horribly
422  * broken, and the system's networking configuration is in an unreliable
423  * state. We should bail. */
424  if ((uname(&utsname)) == -1)
425  {
426  mutt_perror(_("unable to determine nodename via uname()"));
427  return false; // TEST09: can't test
428  }
429 
430  str = utsname.nodename;
431  }
432 
433  /* some systems report the FQDN instead of just the hostname */
434  char *dot = strchr(str, '.');
435  if (dot)
437  else
439 
440  if (!C_Hostname)
441  {
442  /* now get FQDN. Use configured domain first, DNS next, then uname */
443 #ifdef DOMAIN
444  /* we have a compile-time domain name, use that for C_Hostname */
445  C_Hostname =
447  sprintf((char *) C_Hostname, "%s.%s", NONULL(ShortHostname), DOMAIN);
448 #else
449  C_Hostname = getmailname();
450  if (!C_Hostname)
451  {
452  char buffer[1024];
453  if (getdnsdomainname(buffer, sizeof(buffer)) == 0)
454  {
455  C_Hostname = mutt_mem_malloc(mutt_str_strlen(buffer) +
457  sprintf((char *) C_Hostname, "%s.%s", NONULL(ShortHostname), buffer);
458  }
459  else
460  {
461  /* DNS failed, use the nodename. Whether or not the nodename had a '.'
462  * in it, we can use the nodename as the FQDN. On hosts where DNS is
463  * not being used, e.g. small network that relies on hosts files, a
464  * short host name is all that is required for SMTP to work correctly.
465  * It could be wrong, but we've done the best we can, at this point the
466  * onus is on the user to provide the correct hostname if the nodename
467  * won't work in their network. */
468  C_Hostname = mutt_str_strdup(utsname.nodename);
469  }
470  }
471 #endif
472  }
473  if (C_Hostname)
474  cs_str_initial_set(cs, "hostname", C_Hostname, NULL);
475 
476  return true;
477 }
#define NONULL(x)
Definition: string2.h:37
#define mutt_perror(...)
Definition: logging.h:85
static char * getmailname(void)
Try to retrieve the FQDN from mailname files.
Definition: init.c:378
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
int getdnsdomainname(char *buf, size_t buflen)
Lookup the host&#39;s name using DNS.
Definition: getdomain.c:45
int cs_str_initial_set(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
Set the initial value of a config item.
Definition: set.c:453
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
WHERE char * ShortHostname
Short version of the hostname.
Definition: globals.h:50
WHERE char * C_Hostname
Config: Fully-qualified domain name of this machine.
Definition: globals.h:111
char * mutt_str_substr_dup(const char *begin, const char *end)
Duplicate a sub-string.
Definition: string.c:579
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_attachmatch_new()

static struct AttachMatch* mutt_attachmatch_new ( void  )
static

Create a new AttachMatch.

Return values
ptrNew AttachMatch

Definition at line 483 of file init.c.

484 {
485  return mutt_mem_calloc(1, sizeof(struct AttachMatch));
486 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
An attachment matching a regex for attachment counter.
Definition: mutt_parse.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_attach_list()

static enum CommandResult parse_attach_list ( struct Buffer buf,
struct Buffer s,
struct ListHead *  head,
struct Buffer err 
)
static

Parse the "attachments" command.

Parameters
bufBuffer for temporary storage
sBuffer containing the attachments command
headList of AttachMatch to add to
errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 496 of file init.c.

498 {
499  struct AttachMatch *a = NULL;
500  char *p = NULL;
501  char *tmpminor = NULL;
502  size_t len;
503  int ret;
504 
505  do
506  {
508 
509  if (!buf->data || (*buf->data == '\0'))
510  continue;
511 
512  a = mutt_attachmatch_new();
513 
514  /* some cheap hacks that I expect to remove */
515  if (mutt_str_strcasecmp(buf->data, "any") == 0)
516  a->major = mutt_str_strdup("*/.*");
517  else if (mutt_str_strcasecmp(buf->data, "none") == 0)
518  a->major = mutt_str_strdup("cheap_hack/this_should_never_match");
519  else
520  a->major = mutt_str_strdup(buf->data);
521 
522  p = strchr(a->major, '/');
523  if (p)
524  {
525  *p = '\0';
526  p++;
527  a->minor = p;
528  }
529  else
530  {
531  a->minor = "unknown";
532  }
533 
534  len = strlen(a->minor);
535  tmpminor = mutt_mem_malloc(len + 3);
536  strcpy(&tmpminor[1], a->minor);
537  tmpminor[0] = '^';
538  tmpminor[len + 1] = '$';
539  tmpminor[len + 2] = '\0';
540 
542  ret = REG_COMP(&a->minor_regex, tmpminor, REG_ICASE);
543 
544  FREE(&tmpminor);
545 
546  if (ret != 0)
547  {
548  regerror(ret, &a->minor_regex, err->data, err->dsize);
549  FREE(&a->major);
550  FREE(&a);
551  return MUTT_CMD_ERROR;
552  }
553 
554  mutt_debug(LL_DEBUG3, "added %s/%s [%d]\n", a->major, a->minor, a->major_int);
555 
556  mutt_list_insert_tail(head, (char *) a);
557  } while (MoreArgs(s));
558 
560  return MUTT_CMD_SUCCESS;
561 }
static struct AttachMatch * mutt_attachmatch_new(void)
Create a new AttachMatch.
Definition: init.c:483
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
enum ContentType major_int
Definition: mutt_parse.h:38
size_t dsize
Length of data.
Definition: buffer.h:37
#define MoreArgs(buf)
Definition: buffer.h:43
enum ContentType mutt_check_mime_type(const char *s)
Check a MIME type string.
Definition: parse.c:319
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:52
const char * major
Definition: mutt_parse.h:37
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:65
static void attachments_clean(void)
always wise to do what someone else did before
Definition: init.c:157
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
regex_t minor_regex
Definition: mutt_parse.h:40
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
An attachment matching a regex for attachment counter.
Definition: mutt_parse.h:35
const char * minor
Definition: mutt_parse.h:39
Log at debug level 3.
Definition: logging.h:42
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_grouplist()

static int parse_grouplist ( struct GroupList *  gl,
struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse a group context.

Parameters
glGroupList to add to
bufTemporary Buffer space
sBuffer containing string to be parsed
dataFlags associated with the command
errBuffer for error messages
Return values
0Success
-1Error

Definition at line 573 of file init.c.

575 {
576  while (mutt_str_strcasecmp(buf->data, "-group") == 0)
577  {
578  if (!MoreArgs(s))
579  {
580  mutt_buffer_strcpy(err, _("-group: no group name"));
581  return -1;
582  }
583 
585 
587 
588  if (!MoreArgs(s))
589  {
590  mutt_buffer_strcpy(err, _("out of arguments"));
591  return -1;
592  }
593 
595  }
596 
597  return 0;
598 }
void mutt_grouplist_add(struct GroupList *gl, struct Group *group)
Add a Group to a GroupList.
Definition: group.c:138
#define _(a)
Definition: message.h:28
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
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
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
struct Group * mutt_pattern_group(const char *pat)
Match a pattern to a Group.
Definition: group.c:66
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ 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,
unsigned long  data,
struct Buffer err 
)
static

Parse a string replacement rule - Implements command_t.

Definition at line 603 of file init.c.

605 {
606  struct ReplaceList *list = (struct ReplaceList *) data;
607  struct Buffer templ = mutt_buffer_make(0);
608 
609  /* First token is a regex. */
610  if (!MoreArgs(s))
611  {
612  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
613  return MUTT_CMD_WARNING;
614  }
616 
617  /* Second token is a replacement template */
618  if (!MoreArgs(s))
619  {
620  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
621  return MUTT_CMD_WARNING;
622  }
624 
625  if (mutt_replacelist_add(list, buf->data, templ.data, err) != 0)
626  {
627  FREE(&templ.data);
628  return MUTT_CMD_ERROR;
629  }
630  FREE(&templ.data);
631 
632  return MUTT_CMD_SUCCESS;
633 }
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:262
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
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:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define FREE(x)
Definition: memory.h:40
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_unattach_list()

static enum CommandResult parse_unattach_list ( struct Buffer buf,
struct Buffer s,
struct ListHead *  head,
struct Buffer err 
)
static

Parse the "unattachments" command.

Parameters
bufBuffer for temporary storage
sBuffer containing the unattachments command
headList of AttachMatch to remove from
errBuffer for error messages
Return values
MUTT_CMD_SUCCESSAlways

Definition at line 643 of file init.c.

645 {
646  struct AttachMatch *a = NULL;
647  char *tmp = NULL;
648  char *minor = NULL;
649 
650  do
651  {
653  FREE(&tmp);
654 
655  if (mutt_str_strcasecmp(buf->data, "any") == 0)
656  tmp = mutt_str_strdup("*/.*");
657  else if (mutt_str_strcasecmp(buf->data, "none") == 0)
658  tmp = mutt_str_strdup("cheap_hack/this_should_never_match");
659  else
660  tmp = mutt_str_strdup(buf->data);
661 
662  minor = strchr(tmp, '/');
663  if (minor)
664  {
665  *minor = '\0';
666  minor++;
667  }
668  else
669  {
670  minor = "unknown";
671  }
672  const enum ContentType major = mutt_check_mime_type(tmp);
673 
674  struct ListNode *np = NULL, *tmp2 = NULL;
675  STAILQ_FOREACH_SAFE(np, head, entries, tmp2)
676  {
677  a = (struct AttachMatch *) np->data;
678  mutt_debug(LL_DEBUG3, "check %s/%s [%d] : %s/%s [%d]\n", a->major,
679  a->minor, a->major_int, tmp, minor, major);
680  if ((a->major_int == major) && (mutt_str_strcasecmp(minor, a->minor) == 0))
681  {
682  mutt_debug(LL_DEBUG3, "removed %s/%s [%d]\n", a->major, a->minor, a->major_int);
683  regfree(&a->minor_regex);
684  FREE(&a->major);
685  STAILQ_REMOVE(head, np, ListNode, entries);
686  FREE(&np->data);
687  FREE(&np);
688  }
689  }
690 
691  } while (MoreArgs(s));
692 
693  FREE(&tmp);
695  return MUTT_CMD_SUCCESS;
696 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
enum ContentType major_int
Definition: mutt_parse.h:38
#define MoreArgs(buf)
Definition: buffer.h:43
enum ContentType mutt_check_mime_type(const char *s)
Check a MIME type string.
Definition: parse.c:319
const char * major
Definition: mutt_parse.h:37
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
static void attachments_clean(void)
always wise to do what someone else did before
Definition: init.c:157
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * data
String.
Definition: list.h:35
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
regex_t minor_regex
Definition: mutt_parse.h:40
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
An attachment matching a regex for attachment counter.
Definition: mutt_parse.h:35
A List node for strings.
Definition: list.h:33
const char * minor
Definition: mutt_parse.h:39
Log at debug level 3.
Definition: logging.h:42
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
ContentType
Content-Type.
Definition: mime.h:29
+ 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,
unsigned long  data,
struct Buffer err 
)
static

Remove a string replacement rule - Implements command_t.

Definition at line 701 of file init.c.

703 {
704  struct ReplaceList *list = (struct ReplaceList *) data;
705 
706  /* First token is a regex. */
707  if (!MoreArgs(s))
708  {
709  mutt_buffer_printf(err, _("%s: too few arguments"), "unsubjectrx");
710  return MUTT_CMD_WARNING;
711  }
712 
714 
715  /* "*" is a special case. */
716  if (mutt_str_strcmp(buf->data, "*") == 0)
717  {
718  mutt_replacelist_free(list);
719  return MUTT_CMD_SUCCESS;
720  }
721 
722  mutt_replacelist_remove(list, buf->data);
723  return MUTT_CMD_SUCCESS;
724 }
#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:447
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:564
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_attach_list()

static int print_attach_list ( struct ListHead *  h,
const char  op,
const char *  name 
)
static

Print a list of attachments.

Parameters
hList of attachments
opOperation, e.g. '+', '-'
nameAttached/Inline, 'A', 'I'
Return values
0Always

Definition at line 733 of file init.c.

734 {
735  struct ListNode *np = NULL;
736  STAILQ_FOREACH(np, h, entries)
737  {
738  printf("attachments %c%s %s/%s\n", op, name,
739  ((struct AttachMatch *) np->data)->major,
740  ((struct AttachMatch *) np->data)->minor);
741  }
742 
743  return 0;
744 }
const char * name
Definition: pgpmicalg.c:46
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
char * data
String.
Definition: list.h:35
An attachment matching a regex for attachment counter.
Definition: mutt_parse.h:35
A List node for strings.
Definition: list.h:33
+ Here is the caller graph for this function:

◆ remove_from_stailq()

static void remove_from_stailq ( struct ListHead *  head,
const char *  str 
)
static

Remove an item, matching a string, from a List.

Parameters
headHead of the List
strString to match
Note
The string comparison is case-insensitive

Definition at line 753 of file init.c.

754 {
755  if (mutt_str_strcmp("*", str) == 0)
756  mutt_list_free(head); /* "unCMD *" means delete all current entries */
757  else
758  {
759  struct ListNode *np = NULL, *tmp = NULL;
760  STAILQ_FOREACH_SAFE(np, head, entries, tmp)
761  {
762  if (mutt_str_strcasecmp(str, np->data) == 0)
763  {
764  STAILQ_REMOVE(head, np, ListNode, entries);
765  FREE(&np->data);
766  FREE(&np);
767  break;
768  }
769  }
770  }
771 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
char * data
String.
Definition: list.h:35
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
#define FREE(x)
Definition: memory.h:40
A List node for strings.
Definition: list.h:33
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ source_rc()

static int source_rc ( const char *  rcfile_path,
struct Buffer err 
)
static

Read an initialization file.

Parameters
rcfile_pathPath to initialization file
errBuffer for error messages
Return values
<0if neomutt should pause to let the user know

Definition at line 779 of file init.c.

780 {
781  int line = 0, rc = 0, warnings = 0;
782  enum CommandResult line_rc;
783  struct Buffer token;
784  char *linebuf = NULL;
785  char *currentline = NULL;
786  char rcfile[PATH_MAX];
787  size_t buflen;
788 
789  pid_t pid;
790 
791  mutt_str_strfcpy(rcfile, rcfile_path, sizeof(rcfile));
792 
793  size_t rcfilelen = mutt_str_strlen(rcfile);
794  if (rcfilelen == 0)
795  return -1;
796 
797  bool ispipe = rcfile[rcfilelen - 1] == '|';
798 
799  if (!ispipe)
800  {
801  struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
802  if (!mutt_path_to_absolute(rcfile, np ? NONULL(np->data) : ""))
803  {
804  mutt_error(_("Error: Can't build path of '%s'"), rcfile_path);
805  return -1;
806  }
807 
808  STAILQ_FOREACH(np, &MuttrcStack, entries)
809  {
810  if (mutt_str_strcmp(np->data, rcfile) == 0)
811  {
812  break;
813  }
814  }
815  if (np)
816  {
817  mutt_error(_("Error: Cyclic sourcing of configuration file '%s'"), rcfile);
818  return -1;
819  }
820 
822  }
823 
824  mutt_debug(LL_DEBUG2, "Reading configuration file '%s'\n", rcfile);
825 
826  FILE *fp = mutt_open_read(rcfile, &pid);
827  if (!fp)
828  {
829  mutt_buffer_printf(err, "%s: %s", rcfile, strerror(errno));
830  return -1;
831  }
832 
833  mutt_buffer_init(&token);
834  while ((linebuf = mutt_file_read_line(linebuf, &buflen, fp, &line, MUTT_CONT)))
835  {
836  const bool conv = C_ConfigCharset && C_Charset;
837  if (conv)
838  {
839  currentline = mutt_str_strdup(linebuf);
840  if (!currentline)
841  continue;
842  mutt_ch_convert_string(&currentline, C_ConfigCharset, C_Charset, 0);
843  }
844  else
845  currentline = linebuf;
846  mutt_buffer_reset(err);
847  line_rc = mutt_parse_rc_line(currentline, &token, err);
848  if (line_rc == MUTT_CMD_ERROR)
849  {
850  mutt_error(_("Error in %s, line %d: %s"), rcfile, line, err->data);
851  if (--rc < -MAX_ERRS)
852  {
853  if (conv)
854  FREE(&currentline);
855  break;
856  }
857  }
858  else if (line_rc == MUTT_CMD_WARNING)
859  {
860  /* Warning */
861  mutt_warning(_("Warning in %s, line %d: %s"), rcfile, line, err->data);
862  warnings++;
863  }
864  else if (line_rc == MUTT_CMD_FINISH)
865  {
866  break; /* Found "finish" command */
867  }
868  else
869  {
870  if (rc < 0)
871  rc = -1;
872  }
873  if (conv)
874  FREE(&currentline);
875  }
876  FREE(&token.data);
877  FREE(&linebuf);
878  mutt_file_fclose(&fp);
879  if (pid != -1)
880  mutt_wait_filter(pid);
881  if (rc)
882  {
883  /* the neomuttrc source keyword */
884  mutt_buffer_reset(err);
885  mutt_buffer_printf(err, (rc >= -MAX_ERRS) ? _("source: errors in %s") : _("source: reading aborted due to too many errors in %s"),
886  rcfile);
887  rc = -1;
888  }
889  else
890  {
891  /* Don't alias errors with warnings */
892  if (warnings > 0)
893  {
894  mutt_buffer_printf(err, ngettext("source: %d warning in %s", "source: %d warnings in %s", warnings),
895  warnings, rcfile);
896  rc = -2;
897  }
898  }
899 
900  if (!ispipe && !STAILQ_EMPTY(&MuttrcStack))
901  {
902  struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
903  STAILQ_REMOVE_HEAD(&MuttrcStack, entries);
904  FREE(&np->data);
905  FREE(&np);
906  }
907 
908  return rc;
909 }
#define mutt_warning(...)
Definition: logging.h:82
#define NONULL(x)
Definition: string2.h:37
int mutt_ch_convert_string(char **ps, const char *from, const char *to, int flags)
Convert a string between encodings.
Definition: charset.c:748
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
static struct ListHead MuttrcStack
Definition: init.c:79
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, int flags)
Read a line from a file.
Definition: file.c:664
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
#define STAILQ_REMOVE_HEAD(head, field)
Definition: queue.h:419
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MUTT_CONT
-continuation
Definition: file.h:38
#define MAX_ERRS
Definition: init.c:81
WHERE char * C_ConfigCharset
Config: Character set that the config files are in.
Definition: globals.h:104
Log at debug level 2.
Definition: logging.h:41
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
const char * line
Definition: common.c:36
#define PATH_MAX
Definition: mutt.h:50
bool mutt_path_to_absolute(char *path, const char *reference)
Convert relative filepath to an absolute path.
Definition: path.c:375
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
struct ListNode * mutt_list_insert_head(struct ListHead *h, char *s)
Insert a string at the beginning of a List.
Definition: list.c:46
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
char * data
String.
Definition: list.h:35
Warning: Help given to the user.
Definition: mutt_commands.h:36
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
Finish: Stop processing this file.
Definition: mutt_commands.h:38
#define mutt_error(...)
Definition: logging.h:84
#define FREE(x)
Definition: memory.h:40
#define STAILQ_EMPTY(head)
Definition: queue.h:345
char * C_Charset
Config: Default character set for displaying text on screen.
Definition: charset.c:54
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:220
A List node for strings.
Definition: list.h:33
FILE * mutt_open_read(const char *path, pid_t *thepid)
Run a command to read from.
Definition: muttlib.c:1403
#define STAILQ_FIRST(head)
Definition: queue.h:347
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
enum CommandResult mutt_parse_rc_line(char *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
Definition: init.c:3252
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_alias()

static enum CommandResult parse_alias ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'alias' command - Implements command_t.

Definition at line 914 of file init.c.

916 {
917  struct Alias *tmp = NULL;
918  char *estr = NULL;
919  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
920 
921  if (!MoreArgs(s))
922  {
923  mutt_buffer_strcpy(err, _("alias: no address"));
924  return MUTT_CMD_WARNING;
925  }
926 
928 
929  if (parse_grouplist(&gl, buf, s, data, err) == -1)
930  return MUTT_CMD_ERROR;
931 
932  /* check to see if an alias with this name already exists */
933  TAILQ_FOREACH(tmp, &Aliases, entries)
934  {
935  if (mutt_str_strcasecmp(tmp->name, buf->data) == 0)
936  break;
937  }
938 
939  if (tmp)
940  {
942  /* override the previous value */
943  mutt_addrlist_clear(&tmp->addr);
944  if (CurrentMenu == MENU_ALIAS)
946  }
947  else
948  {
949  /* create a new alias */
950  tmp = mutt_alias_new();
951  tmp->name = mutt_str_strdup(buf->data);
952  TAILQ_INSERT_TAIL(&Aliases, tmp, entries);
953  /* give the main addressbook code a chance */
954  if (CurrentMenu == MENU_ALIAS)
955  OptMenuCaller = true;
956  }
957 
959  mutt_debug(LL_DEBUG5, "Second token is '%s'\n", buf->data);
960 
961  mutt_addrlist_parse2(&tmp->addr, buf->data);
962 
963  if (mutt_addrlist_to_intl(&tmp->addr, &estr))
964  {
965  mutt_buffer_printf(err, _("Warning: Bad IDN '%s' in alias '%s'"), estr, tmp->name);
966  FREE(&estr);
967  goto bail;
968  }
969 
970  mutt_grouplist_add_addrlist(&gl, &tmp->addr);
972 
973  if (C_DebugLevel > LL_DEBUG4)
974  {
975  /* A group is terminated with an empty address, so check a->mailbox */
976  struct Address *a = NULL;
977  TAILQ_FOREACH(a, &tmp->addr, entries)
978  {
979  if (!a->mailbox)
980  break;
981 
982  if (a->group)
983  mutt_debug(LL_DEBUG5, " Group %s\n", a->mailbox);
984  else
985  mutt_debug(LL_DEBUG5, " %s\n", a->mailbox);
986  }
987  }
989  return MUTT_CMD_SUCCESS;
990 
991 bail:
993  return MUTT_CMD_ERROR;
994 }
void mutt_alias_delete_reverse(struct Alias *t)
Remove an email address lookup for an Alias.
Definition: alias.c:575
A shortcut for an email address.
Definition: alias.h:37
Log at debug level 4.
Definition: logging.h:43
char * name
Short name.
Definition: alias.h:39
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1382
WHERE bool OptMenuCaller
(pseudo) tell menu to give caller a take
Definition: options.h:38
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:82
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:34
char * mailbox
Mailbox and host address.
Definition: address.h:37
void mutt_grouplist_add_addrlist(struct GroupList *gl, struct AddressList *al)
Add Address list to a GroupList.
Definition: group.c:227
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:607
#define MoreArgs(buf)
Definition: buffer.h:43
struct Alias * mutt_alias_new(void)
Create a new Alias.
Definition: alias.c:144
#define MUTT_TOKEN_QUOTE
Don&#39;t interpret quotes.
Definition: mutt.h:80
static int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a group context.
Definition: init.c:573
short C_DebugLevel
Config: Logging level for debug logs.
Definition: mutt_logging.c:48
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:79
char * data
Pointer to data.
Definition: buffer.h:35
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:802
Select an email address by its alias.
Definition: keymap.h:71
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:83
Success: Command worked.
Definition: mutt_commands.h:37
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1217
bool group
Group mailbox?
Definition: address.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:36
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
void mutt_alias_add_reverse(struct Alias *t)
Add an email address lookup for an Alias.
Definition: alias.c:553
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:158
#define FREE(x)
Definition: memory.h:40
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct AddressList addr
List of Addresses the Alias expands to.
Definition: alias.h:40
Log at debug level 5.
Definition: logging.h:44
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_alternates()

static enum CommandResult parse_alternates ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'alternates' command - Implements command_t.

Definition at line 999 of file init.c.

1001 {
1002  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1003 
1004  alternates_clean();
1005 
1006  do
1007  {
1009 
1010  if (parse_grouplist(&gl, buf, s, data, err) == -1)
1011  goto bail;
1012 
1013  mutt_regexlist_remove(&UnAlternates, buf->data);
1014 
1015  if (mutt_regexlist_add(&Alternates, buf->data, REG_ICASE, err) != 0)
1016  goto bail;
1017 
1018  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
1019  goto bail;
1020  } while (MoreArgs(s));
1021 
1023  return MUTT_CMD_SUCCESS;
1024 
1025 bail:
1027  return MUTT_CMD_ERROR;
1028 }
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
static void alternates_clean(void)
Clear the recipient valid flag of all emails.
Definition: init.c:139
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, int flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:277
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
static int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a group context.
Definition: init.c:573
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:158
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_attachments()

static enum CommandResult parse_attachments ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'attachments' command - Implements command_t.

Definition at line 1033 of file init.c.

1035 {
1036  char op;
1037  char *category = NULL;
1038  struct ListHead *head = NULL;
1039 
1041  if (!buf->data || (*buf->data == '\0'))
1042  {
1043  mutt_buffer_strcpy(err, _("attachments: no disposition"));
1044  return MUTT_CMD_WARNING;
1045  }
1046 
1047  category = buf->data;
1048  op = *category++;
1049 
1050  if (op == '?')
1051  {
1052  mutt_endwin();
1053  fflush(stdout);
1054  printf("\n%s\n\n", _("Current attachments settings:"));
1055  print_attach_list(&AttachAllow, '+', "A");
1056  print_attach_list(&AttachExclude, '-', "A");
1057  print_attach_list(&InlineAllow, '+', "I");
1058  print_attach_list(&InlineExclude, '-', "I");
1060  return MUTT_CMD_SUCCESS;
1061  }
1062 
1063  if ((op != '+') && (op != '-'))
1064  {
1065  op = '+';
1066  category--;
1067  }
1068  if (mutt_str_startswith("attachment", category, CASE_IGNORE))
1069  {
1070  if (op == '+')
1071  head = &AttachAllow;
1072  else
1073  head = &AttachExclude;
1074  }
1075  else if (mutt_str_startswith("inline", category, CASE_IGNORE))
1076  {
1077  if (op == '+')
1078  head = &InlineAllow;
1079  else
1080  head = &InlineExclude;
1081  }
1082  else
1083  {
1084  mutt_buffer_strcpy(err, _("attachments: invalid disposition"));
1085  return MUTT_CMD_ERROR;
1086  }
1087 
1088  return parse_attach_list(buf, s, head, err);
1089 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
struct ListHead InlineAllow
List of inline types to counted.
Definition: mutt_parse.c:41
#define _(a)
Definition: message.h:28
struct ListHead InlineExclude
List of inline types to ignore.
Definition: mutt_parse.c:42
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:545
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Ignore case when comparing strings.
Definition: string2.h:68
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_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:578
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: mutt_parse.c:40
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
static enum CommandResult parse_attach_list(struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
Parse the "attachments" command.
Definition: init.c:496
static int print_attach_list(struct ListHead *h, const char op, const char *name)
Print a list of attachments.
Definition: init.c:733
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: mutt_parse.c:39
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_echo()

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

Parse the 'echo' command - Implements command_t.

Definition at line 1094 of file init.c.

1096 {
1097  if (!MoreArgs(s))
1098  {
1099  mutt_buffer_printf(err, _("%s: too few arguments"), "echo");
1100  return MUTT_CMD_WARNING;
1101  }
1103  OptForceRefresh = true;
1104  mutt_message("%s", buf->data);
1105  OptForceRefresh = false;
1106  mutt_sleep(0);
1107 
1108  return MUTT_CMD_SUCCESS;
1109 }
#define mutt_message(...)
Definition: logging.h:83
#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:43
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1545
WHERE bool OptForceRefresh
(pseudo) refresh even during macros
Definition: options.h:35
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_finish()

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

Parse the 'finish' command - Implements command_t.

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 1118 of file init.c.

1120 {
1121  if (MoreArgs(s))
1122  {
1123  mutt_buffer_printf(err, _("%s: too many arguments"), "finish");
1124  return MUTT_CMD_WARNING;
1125  }
1126 
1127  return MUTT_CMD_FINISH;
1128 }
#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:43
Warning: Help given to the user.
Definition: mutt_commands.h:36
Finish: Stop processing this file.
Definition: mutt_commands.h:38
+ Here is the call graph for this function:

◆ parse_group()

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

Parse the 'group' and 'ungroup' commands - Implements command_t.

Definition at line 1133 of file init.c.

1135 {
1136  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1137  enum GroupState state = GS_NONE;
1138 
1139  do
1140  {
1142  if (parse_grouplist(&gl, buf, s, data, err) == -1)
1143  goto bail;
1144 
1145  if ((data == MUTT_UNGROUP) && (mutt_str_strcasecmp(buf->data, "*") == 0))
1146  {
1147  mutt_grouplist_clear(&gl);
1148  goto out;
1149  }
1150 
1151  if (mutt_str_strcasecmp(buf->data, "-rx") == 0)
1152  state = GS_RX;
1153  else if (mutt_str_strcasecmp(buf->data, "-addr") == 0)
1154  state = GS_ADDR;
1155  else
1156  {
1157  switch (state)
1158  {
1159  case GS_NONE:
1160  mutt_buffer_printf(err, _("%sgroup: missing -rx or -addr"),
1161  (data == MUTT_UNGROUP) ? "un" : "");
1162  goto warn;
1163 
1164  case GS_RX:
1165  if ((data == MUTT_GROUP) &&
1166  (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0))
1167  {
1168  goto bail;
1169  }
1170  else if ((data == MUTT_UNGROUP) &&
1171  (mutt_grouplist_remove_regex(&gl, buf->data) < 0))
1172  {
1173  goto bail;
1174  }
1175  break;
1176 
1177  case GS_ADDR:
1178  {
1179  char *estr = NULL;
1180  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
1181  mutt_addrlist_parse2(&al, buf->data);
1182  if (TAILQ_EMPTY(&al))
1183  goto bail;
1184  if (mutt_addrlist_to_intl(&al, &estr))
1185  {
1186  mutt_buffer_printf(err, _("%sgroup: warning: bad IDN '%s'"),
1187  (data == 1) ? "un" : "", estr);
1188  mutt_addrlist_clear(&al);
1189  FREE(&estr);
1190  goto bail;
1191  }
1192  if (data == MUTT_GROUP)
1193  mutt_grouplist_add_addrlist(&gl, &al);
1194  else if (data == MUTT_UNGROUP)
1196  mutt_addrlist_clear(&al);
1197  break;
1198  }
1199  }
1200  }
1201  } while (MoreArgs(s));
1202 
1203 out:
1205  return MUTT_CMD_SUCCESS;
1206 
1207 bail:
1209  return MUTT_CMD_ERROR;
1210 
1211 warn:
1213  return MUTT_CMD_WARNING;
1214 }
#define MUTT_UNGROUP
&#39;ungroup&#39; config command
Definition: group.h:33
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
void mutt_grouplist_clear(struct GroupList *gl)
Clear a GroupList.
Definition: group.c:104
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1382
#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:227
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:607
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, int flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:277
int mutt_grouplist_remove_regex(struct GroupList *gl, const char *s)
Remove matching addresses from a GroupList.
Definition: group.c:301
int mutt_grouplist_remove_addrlist(struct GroupList *gl, struct AddressList *al)
Remove an AddressList from a GroupList.
Definition: group.c:246
static int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a group context.
Definition: init.c:573
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Group is missing an argument.
Definition: init.c:106
Success: Command worked.
Definition: mutt_commands.h:37
GroupState
Type of email address group.
Definition: init.c:104
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1217
Warning: Help given to the user.
Definition: mutt_commands.h:36
Entry is an address.
Definition: init.c:108
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:158
#define FREE(x)
Definition: memory.h:40
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
Entry is a regular expression.
Definition: init.c:107
#define TAILQ_EMPTY(head)
Definition: queue.h:714
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:630
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
#define MUTT_GROUP
&#39;group&#39; config command
Definition: group.h:32
+ Here is the call graph for this function:

◆ is_function()

static bool is_function ( const char *  name)
static

Is the argument a neomutt function?

Parameters
nameCommand name to be searched for
Return values
trueFunction found
falseFunction not found

Definition at line 1222 of file init.c.

1223 {
1224  for (enum MenuType i = 0; i < MENU_MAX; i++)
1225  {
1226  const struct Binding *b = km_get_table(Menus[i].value);
1227  if (!b)
1228  continue;
1229 
1230  for (int j = 0; b[j].name; j++)
1231  if (mutt_str_strcmp(name, b[j].name) == 0)
1232  return true;
1233  }
1234  return false;
1235 }
MenuType
Types of GUI selections.
Definition: keymap.h:69
const char * name
Definition: pgpmicalg.c:46
const char * name
name of the function
Definition: keymap.h:116
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1221
Mapping between a user key and a function.
Definition: keymap.h:114
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_ifdef()

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

Parse the 'ifdef' and 'ifndef' commands - Implements command_t.

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 1250 of file init.c.

1252 {
1253  struct Buffer token = mutt_buffer_make(0);
1254 
1256 
1257  // is the item defined as:
1258  bool res = cs_subset_lookup(NeoMutt->sub, buf->data) // a variable?
1259  || feature_enabled(buf->data) // a compiled-in feature?
1260  || is_function(buf->data) // a function?
1261  || mutt_command_get(buf->data) // a command?
1262  || myvar_get(buf->data) // a my_ variable?
1263  || mutt_str_getenv(buf->data); // an environment variable?
1264 
1265  if (!MoreArgs(s))
1266  {
1267  mutt_buffer_printf(err, _("%s: too few arguments"), (data ? "ifndef" : "ifdef"));
1268  return MUTT_CMD_WARNING;
1269  }
1271 
1272  /* ifdef KNOWN_SYMBOL or ifndef UNKNOWN_SYMBOL */
1273  if ((res && (data == 0)) || (!res && (data == 1)))
1274  {
1275  enum CommandResult rc = mutt_parse_rc_line(buf->data, &token, err);
1276  if (rc == MUTT_CMD_ERROR)
1277  {
1278  mutt_error(_("Error: %s"), err->data);
1279  FREE(&token.data);
1280  return MUTT_CMD_ERROR;
1281  }
1282  FREE(&token.data);
1283  return rc;
1284  }
1285  return MUTT_CMD_SUCCESS;
1286 }
static bool is_function(const char *name)
Is the argument a neomutt function?
Definition: init.c:1222
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
bool feature_enabled(const char *name)
Test if a compile-time feature is enabled.
Definition: version.c:500
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
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
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
Definition: subset.c:119
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:35
const struct Command * mutt_command_get(const char *s)
Get a Command by its name.
Definition: init.c:2643
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:1048
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:79
char * data
Pointer to data.
Definition: buffer.h:35
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
Definition: myvar.c:73
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:84
#define FREE(x)
Definition: memory.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:38
enum CommandResult mutt_parse_rc_line(char *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
Definition: init.c:3252
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_ignore()

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

Parse the 'ignore' command - Implements command_t.

Definition at line 1291 of file init.c.

1293 {
1294  do
1295  {
1298  add_to_stailq(&Ignore, buf->data);
1299  } while (MoreArgs(s));
1300 
1301  return MUTT_CMD_SUCCESS;
1302 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:753
struct ListHead UnIgnore
List of header patterns to unignore (see)
Definition: email_globals.c:46
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
struct ListHead Ignore
List of header patterns to ignore.
Definition: email_globals.c:45
static void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: init.c:118
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_lists()

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

Parse the 'lists' command - Implements command_t.

Definition at line 1307 of file init.c.

1309 {
1310  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1311 
1312  do
1313  {
1315 
1316  if (parse_grouplist(&gl, buf, s, data, err) == -1)
1317  goto bail;
1318 
1320 
1321  if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
1322  goto bail;
1323 
1324  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
1325  goto bail;
1326  } while (MoreArgs(s));
1327 
1329  return MUTT_CMD_SUCCESS;
1330 
1331 bail:
1333  return MUTT_CMD_ERROR;
1334 }
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, int flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:277
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
static int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a group context.
Definition: init.c:573
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: email_globals.c:50
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:158
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
Definition: email_globals.c:51
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_mailboxes()

static enum CommandResult parse_mailboxes ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'mailboxes' command - Implements command_t.

This is also used by 'virtual-mailboxes'.

Definition at line 1341 of file init.c.

1343 {
1344  while (MoreArgs(s))
1345  {
1346  struct Mailbox *m = mailbox_new();
1347 
1348  if (data & MUTT_NAMED)
1349  {
1351  if (buf->data && (*buf->data != '\0'))
1352  {
1353  m->name = mutt_str_strdup(buf->data);
1354  }
1355  else
1356  {
1357  mailbox_free(&m);
1358  continue;
1359  }
1360  }
1361 
1363  if (mutt_buffer_is_empty(buf))
1364  {
1365  /* Skip empty tokens. */
1366  mailbox_free(&m);
1367  continue;
1368  }
1369 
1370  mutt_buffer_strcpy(&m->pathbuf, buf->data);
1371  /* int rc = */ mx_path_canon2(m, C_Folder);
1372 
1373  if (m->magic <= MUTT_UNKNOWN)
1374  {
1375  mutt_error("Unknown Mailbox: %s", m->realpath);
1376  mailbox_free(&m);
1377  return MUTT_CMD_ERROR;
1378  }
1379 
1380  bool new_account = false;
1381  struct Account *a = mx_ac_find(m);
1382  if (!a)
1383  {
1384  a = account_new(NULL, NeoMutt->sub);
1385  a->magic = m->magic;
1386  new_account = true;
1387  }
1388 
1389  if (!new_account)
1390  {
1391  struct Mailbox *m_old = mx_mbox_find(a, m->realpath);
1392  if (m_old)
1393  {
1394  if (m_old->flags == MB_HIDDEN)
1395  {
1396  m_old->flags = MB_NORMAL;
1397  mutt_sb_notify_mailbox(m_old, true);
1398  }
1399  mailbox_free(&m);
1400  continue;
1401  }
1402  }
1403 
1404  if (mx_ac_add(a, m) < 0)
1405  {
1406  //error
1407  mailbox_free(&m);
1408  if (new_account)
1409  {
1410  cs_subset_free(&a->sub);
1411  FREE(&a->name);
1412  notify_free(&a->notify);
1413  FREE(&a);
1414  }
1415  continue;
1416  }
1417  if (new_account)
1418  {
1420  }
1421 
1422 #ifdef USE_SIDEBAR
1423  mutt_sb_notify_mailbox(m, true);
1424 #endif
1425 #ifdef USE_INOTIFY
1426  mutt_monitor_add(m);
1427 #endif
1428  }
1429  return MUTT_CMD_SUCCESS;
1430 }
char * name
Name of Account.
Definition: account.h:39
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
int mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add()
Definition: mx.c:1623
int mx_path_canon2(struct Mailbox *m, const char *folder)
Canonicalise the path to realpath.
Definition: mx.c:1448
struct Notify * notify
Notifications handler.
Definition: account.h:42
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:83
A group of associated Mailboxes.
Definition: account.h:36
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:46
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1555
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:44
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:476
struct Account * mx_ac_find(struct Mailbox *m)
Find the Account owning a Mailbox.
Definition: mx.c:1531
Container for Accounts, Notifications.
Definition: neomutt.h:35
#define MoreArgs(buf)
Definition: buffer.h:43
char * name
A short name for the Mailbox.
Definition: mailbox.h:84
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:60
enum MailboxType magic
Mailbox type.
Definition: mailbox.h:104
struct Account * account_new(const char *name, struct ConfigSubset *sub)
Create a new Account.
Definition: account.c:43
int flags
e.g. MB_NORMAL
Definition: mailbox.h:133
#define MB_HIDDEN
Definition: mailbox.h:37
WHERE char * C_Folder
Config: Base folder for a set of mailboxes.
Definition: globals.h:119
A mailbox.
Definition: mailbox.h:80
enum MailboxType magic
Type of Mailboxes this Account contains.
Definition: account.h:38
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
#define MUTT_NAMED
Definition: init.h:112
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:63
struct Mailbox * mailbox_new(void)
Create a new Mailbox.
Definition: mailbox.c:42
Success: Command worked.
Definition: mutt_commands.h:37
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define mutt_error(...)
Definition: logging.h:84
#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:38
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:82
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
#define MB_NORMAL
Definition: mailbox.h:36
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_my_hdr()

static enum CommandResult parse_my_hdr ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'my_hdr' command - Implements command_t.

Definition at line 1435 of file init.c.

1437 {
1438  struct ListNode *n = NULL;
1439  size_t keylen;
1440 
1442  char *p = strpbrk(buf->data, ": \t");
1443  if (!p || (*p != ':'))
1444  {
1445  mutt_buffer_strcpy(err, _("invalid header field"));
1446  return MUTT_CMD_WARNING;
1447  }
1448  keylen = p - buf->data + 1;
1449 
1450  STAILQ_FOREACH(n, &UserHeader, entries)
1451  {
1452  /* see if there is already a field by this name */
1453  if (mutt_str_strncasecmp(buf->data, n->data, keylen) == 0)
1454  {
1455  break;
1456  }
1457  }
1458 
1459  if (!n)
1460  {
1461  /* not found, allocate memory for a new node and add it to the list */
1462  n = mutt_list_insert_tail(&UserHeader, NULL);
1463  }
1464  else
1465  {
1466  /* found, free the existing data */
1467  FREE(&n->data);
1468  }
1469 
1470  n->data = buf->data;
1471  mutt_buffer_init(buf);
1472 
1473  return MUTT_CMD_SUCCESS;
1474 }
#define _(a)
Definition: message.h:28
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:65
#define MUTT_TOKEN_QUOTE
Don&#39;t interpret quotes.
Definition: mutt.h:80
int mutt_str_strncasecmp(const char *a, const char *b, size_t l)
Compare two strings ignoring case (to a maximum), safely.
Definition: string.c:656
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:79
char * data
Pointer to data.
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
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:37
char * data
String.
Definition: list.h:35
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define FREE(x)
Definition: memory.h:40
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
A List node for strings.
Definition: list.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_path_list()

static enum CommandResult parse_path_list ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'sidebar_whitelist' command - Implements command_t.

Definition at line 1480 of file init.c.

1482 {
1483  struct Buffer *path = mutt_buffer_pool_get();
1484 
1485  do
1486  {
1489  add_to_stailq((struct ListHead *) data, mutt_b2s(path));
1490  } while (MoreArgs(s));
1491  mutt_buffer_pool_release(&path);
1492 
1493  return MUTT_CMD_SUCCESS;
1494 }
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
#define MoreArgs(buf)
Definition: buffer.h:43
#define mutt_b2s(buf)
Definition: buffer.h:41
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:342
static void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: init.c:118
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_path_unlist()

static enum CommandResult parse_path_unlist ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'unsidebar_whitelist' command - Implements command_t.

Definition at line 1501 of file init.c.

1503 {
1504  struct Buffer *path = mutt_buffer_pool_get();
1505 
1506  do
1507  {
1509  /* Check for deletion of entire list */
1510  if (mutt_str_strcmp(mutt_b2s(path), "*") == 0)
1511  {
1512  mutt_list_free((struct ListHead *) data);
1513  break;
1514  }
1516  remove_from_stailq((struct ListHead *) data, mutt_b2s(path));
1517  } while (MoreArgs(s));
1518  mutt_buffer_pool_release(&path);
1519 
1520  return MUTT_CMD_SUCCESS;
1521 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:753
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:123
#define MoreArgs(buf)
Definition: buffer.h:43
#define mutt_b2s(buf)
Definition: buffer.h:41
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:342
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_set()

static enum CommandResult parse_set ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'set' family of commands - Implements command_t.

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

Definition at line 1529 of file init.c.

1531 {
1532  /* The order must match `enum MuttSetCommand` */
1533  static const char *set_commands[] = { "set", "toggle", "unset", "reset" };
1534 
1535  int rc = 0;
1536 
1537  while (MoreArgs(s))
1538  {
1539  bool prefix = false;
1540  bool query = false;
1541  bool inv = (data == MUTT_SET_INV);
1542  bool reset = (data == MUTT_SET_RESET);
1543  bool unset = (data == MUTT_SET_UNSET);
1544 
1545  if (*s->dptr == '?')
1546  {
1547  prefix = true;
1548  query = true;
1549  s->dptr++;
1550  }
1551  else if (mutt_str_startswith(s->dptr, "no", CASE_MATCH))
1552  {
1553  prefix = true;
1554  unset = !unset;
1555  s->dptr += 2;
1556  }
1557  else if (mutt_str_startswith(s->dptr, "inv", CASE_MATCH))
1558  {
1559  prefix = true;
1560  inv = !inv;
1561  s->dptr += 3;
1562  }
1563  else if (*s->dptr == '&')
1564  {
1565  prefix = true;
1566  reset = true;
1567  s->dptr++;
1568  }
1569 
1570  if (prefix && (data != MUTT_SET_SET))
1571  {
1572  mutt_buffer_printf(err, "ERR22 can't use 'inv', 'no', '&' or '?' with the '%s' command",
1573  set_commands[data]);
1574  return MUTT_CMD_WARNING;
1575  }
1576 
1577  /* get the variable name */
1579 
1580  bool bq = false;
1581  bool equals = false;
1582 
1583  struct HashElem *he = NULL;
1584  bool my = mutt_str_startswith(buf->data, "my_", CASE_MATCH);
1585  if (!my)
1586  {
1587  he = cs_subset_lookup(NeoMutt->sub, buf->data);
1588  if (!he)
1589  {
1590  if (reset && (mutt_str_strcmp(buf->data, "all") == 0))
1591  {
1592  struct HashElem **list = get_elem_list(NeoMutt->sub->cs);
1593  if (!list)
1594  return MUTT_CMD_ERROR;
1595 
1596  for (size_t i = 0; list[i]; i++)
1597  cs_subset_he_reset(NeoMutt->sub, list[i], NULL);
1598 
1599  FREE(&list);
1600  break;
1601  }
1602  else
1603  {
1604  mutt_buffer_printf(err, "ERR01 unknown variable: %s", buf->data);
1605  return MUTT_CMD_ERROR;
1606  }
1607  }
1608 
1609  bq = ((DTYPE(he->type) == DT_BOOL) || (DTYPE(he->type) == DT_QUAD));
1610  }
1611 
1612  if (*s->dptr == '?')
1613  {
1614  if (prefix)
1615  {
1616  mutt_buffer_printf(err,
1617  "ERR02 can't use a prefix when querying a variable");
1618  return MUTT_CMD_WARNING;
1619  }
1620 
1621  if (reset || unset || inv)
1622  {
1623  mutt_buffer_printf(err, "ERR03 can't query a variable with the '%s' command",
1624  set_commands[data]);
1625  return MUTT_CMD_WARNING;
1626  }
1627 
1628  query = true;
1629  s->dptr++;
1630  }
1631  else if (*s->dptr == '=')
1632  {
1633  if (prefix)
1634  {
1635  mutt_buffer_printf(err,
1636  "ERR04 can't use prefix when setting a variable");
1637  return MUTT_CMD_WARNING;
1638  }
1639 
1640  if (reset || unset || inv)
1641  {
1642  mutt_buffer_printf(err, "ERR05 can't set a variable with the '%s' command",
1643  set_commands[data]);
1644  return MUTT_CMD_WARNING;
1645  }
1646 
1647  equals = true;
1648  s->dptr++;
1649  }
1650 
1651  if (!bq && (inv || (unset && prefix)))
1652  {
1653  if (data == MUTT_SET_SET)
1654  {
1655  mutt_buffer_printf(err, "ERR06 prefixes 'no' and 'inv' may only be "
1656  "used with bool/quad variables");
1657  }
1658  else
1659  {
1660  mutt_buffer_printf(err, "ERR07 command '%s' can only be used with bool/quad variables",
1661  set_commands[data]);
1662  }
1663  return MUTT_CMD_WARNING;
1664  }
1665 
1666  if (reset)
1667  {
1668  // mutt_buffer_printf(err, "ACT24 reset variable %s", buf->data);
1669  if (he)
1670  {
1671  rc = cs_subset_he_reset(NeoMutt->sub, he, err);
1672  if (CSR_RESULT(rc) != CSR_SUCCESS)
1673  return MUTT_CMD_ERROR;
1674  }
1675  else
1676  {
1677  myvar_del(buf->data);
1678  }
1679  continue;
1680  }
1681 
1682  if ((data == MUTT_SET_SET) && !inv && !unset)
1683  {
1684  if (query)
1685  {
1686  // mutt_buffer_printf(err, "ACT08 query variable %s", buf->data);
1687  if (he)
1688  {
1689  mutt_buffer_addstr(err, buf->data);
1690  mutt_buffer_addch(err, '=');
1691  mutt_buffer_reset(buf);
1692  rc = cs_subset_he_string_get(NeoMutt->sub, he, buf);
1693  if (CSR_RESULT(rc) != CSR_SUCCESS)
1694  {
1695  mutt_buffer_addstr(err, buf->data);
1696  return MUTT_CMD_ERROR;
1697  }
1698  pretty_var(buf->data, err);
1699  }
1700  else
1701  {
1702  const char *val = myvar_get(buf->data);
1703  if (val)
1704  {
1705  mutt_buffer_addstr(err, buf->data);
1706  mutt_buffer_addch(err, '=');
1707  pretty_var(val, err);
1708  }
1709  else
1710  {
1711  mutt_buffer_printf(err, _("%s: unknown variable"), buf->data);
1712  return MUTT_CMD_ERROR;
1713  }
1714  }
1715  break;
1716  }
1717  else if (equals)
1718  {
1719  // mutt_buffer_printf(err, "ACT11 set variable %s to ", buf->data);
1720  const char *name = NULL;
1721  if (my)
1722  {
1723  name = mutt_str_strdup(buf->data);
1724  }
1726  if (my)
1727  {
1728  myvar_set(name, buf->data);
1729  FREE(&name);
1730  }
1731  else
1732  {
1733  if (IS_PATH(he))
1734  {
1736  struct Buffer scratch = mutt_buffer_make(1024);
1737  mutt_buffer_copy(&scratch, buf);
1738  size_t scratchlen = mutt_buffer_len(&scratch);
1739  if (!(he->type & DT_MAILBOX) && (scratchlen != 0))
1740  {
1741  if ((mutt_b2s(&scratch)[scratchlen - 1] != '|') && /* not a command */
1742  (url_check_scheme(mutt_b2s(&scratch)) == U_UNKNOWN)) /* probably a local file */
1743  {
1744  struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
1745  if (mutt_path_to_absolute(scratch.data, np ? NONULL(np->data) : "./"))
1746  {
1747  mutt_buffer_reset(buf);
1748  mutt_buffer_addstr(buf, mutt_b2s(&scratch));
1749  }
1750  else
1751  {
1752  mutt_error(_("Error: Can't build path of '%s'"), mutt_b2s(&scratch));
1753  }
1754  }
1755  }
1756  mutt_buffer_dealloc(&scratch);
1757  }
1758  else if (IS_COMMAND(he))
1759  {
1760  struct Buffer scratch = mutt_buffer_make(1024);
1761  mutt_buffer_copy(&scratch, buf);
1762 
1763  if (mutt_str_strcmp(buf->data, "builtin") != 0)
1764  {
1765  mutt_buffer_expand_path(&scratch);
1766  }
1767  mutt_buffer_reset(buf);
1768  mutt_buffer_addstr(buf, mutt_b2s(&scratch));
1769  mutt_buffer_dealloc(&scratch);
1770  }
1771 
1772  rc = cs_subset_he_string_set(NeoMutt->sub, he, buf->data, err);
1773  if (CSR_RESULT(rc) != CSR_SUCCESS)
1774  return MUTT_CMD_ERROR;
1775  }
1776  continue;
1777  }
1778  else
1779  {
1780  if (bq)
1781  {
1782  // mutt_buffer_printf(err, "ACT23 set variable %s to 'yes'", buf->data);
1783  rc = cs_subset_he_native_set(NeoMutt->sub, he, true, err);
1784  if (CSR_RESULT(rc) != CSR_SUCCESS)
1785  return MUTT_CMD_ERROR;
1786  continue;
1787  }
1788  else
1789  {
1790  // mutt_buffer_printf(err, "ACT10 query variable %s", buf->data);
1791  if (he)
1792  {
1793  mutt_buffer_addstr(err, buf->data);
1794  mutt_buffer_addch(err, '=');
1795  mutt_buffer_reset(buf);
1796  rc = cs_subset_he_string_get(NeoMutt->sub, he, buf);
1797  if (CSR_RESULT(rc) != CSR_SUCCESS)
1798  {
1799  mutt_buffer_addstr(err, buf->data);
1800  return MUTT_CMD_ERROR;
1801  }
1802  pretty_var(buf->data, err);
1803  }
1804  else
1805  {
1806  const char *val = myvar_get(buf->data);
1807  if (val)
1808  {
1809  mutt_buffer_addstr(err, buf->data);
1810  mutt_buffer_addch(err, '=');
1811  pretty_var(val, err);
1812  }
1813  else
1814  {
1815  mutt_buffer_printf(err, _("%s: unknown variable"), buf->data);
1816  return MUTT_CMD_ERROR;
1817  }
1818  }
1819  break;
1820  }
1821  }
1822  }
1823 
1824  if (my)
1825  {
1826  myvar_del(buf->data);
1827  }
1828  else if (bq)
1829  {
1830  if (inv)
1831  {
1832  // mutt_buffer_printf(err, "ACT25 TOGGLE bool/quad variable %s", buf->data);
1833  if (DTYPE(he->type) == DT_BOOL)
1834  bool_he_toggle(NeoMutt->sub, he, err);
1835  else
1836  quad_he_toggle(NeoMutt->sub, he, err);
1837  }
1838  else
1839  {
1840  // mutt_buffer_printf(err, "ACT26 UNSET bool/quad variable %s", buf->data);
1841  rc = cs_subset_he_native_set(NeoMutt->sub, he, false, err);
1842  if (CSR_RESULT(rc) != CSR_SUCCESS)
1843  return MUTT_CMD_ERROR;
1844  }
1845  continue;
1846  }
1847  else
1848  {
1849  rc = cs_subset_he_string_set(NeoMutt->sub, he, NULL, err);
1850  if (CSR_RESULT(rc) != CSR_SUCCESS)
1851  return MUTT_CMD_ERROR;
1852  }
1853  }
1854 
1855  return MUTT_CMD_SUCCESS;
1856 }
#define NONULL(x)
Definition: string2.h:37
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
#define IS_PATH(x)
Definition: types.h:55
#define CSR_RESULT(x)
Definition: set.h:53
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
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
static struct ListHead MuttrcStack
Definition: init.c:79
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
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:292
Url wasn&#39;t recognised.
Definition: url.h:34
#define _(a)
Definition: message.h:28
Match case when comparing strings.
Definition: string2.h:67
struct HashElem ** get_elem_list(struct ConfigSet *cs)
Create a sorted list of all config items.
Definition: dump.c:118
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
Definition: subset.c:119
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:35
enum UrlScheme url_check_scheme(const char *s)
Check the protocol of a URL.
Definition: url.c:132
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
#define MoreArgs(buf)
Definition: buffer.h:43
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:49
const char * name
Definition: pgpmicalg.c:46
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:324
default is to invert all vars
Definition: init.h:106
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
default is to set all vars
Definition: init.h:105
void myvar_del(const char *var)
Unset the value of a "my_" variable.
Definition: myvar.c:112
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:37
#define mutt_b2s(buf)
Definition: buffer.h:41
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:2674
#define DT_MAILBOX
Don&#39;t perform path expansions.
Definition: types.h:47
bool mutt_path_to_absolute(char *path, const char *reference)
Convert relative filepath to an absolute path.
Definition: path.c:375
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:91
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
default is to reset all vars to default
Definition: init.h:108
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
Definition: myvar.c:73
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
void * data
Definition: hash.h:46
size_t pretty_var(const char *str, struct Buffer *buf)
Escape and stringify a config item value.
Definition: dump.c:80
default is to unset all vars
Definition: init.h:107
Success: Command worked.
Definition: mutt_commands.h:37
char * data
String.
Definition: list.h:35
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:342
Warning: Help given to the user.
Definition: mutt_commands.h:36
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
int bool_he_toggle(struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
Toggle the value of a bool.
Definition: bool.c:211
#define mutt_error(...)
Definition: logging.h:84
#define MUTT_TOKEN_BACKTICK_VARS
Expand variables within backticks.
Definition: mutt.h:84
int type
Definition: hash.h:44
#define FREE(x)
Definition: memory.h:40
int quad_he_toggle(struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
Toggle the value of a quad.
Definition: quad.c:228
The item stored in a Hash Table.
Definition: hash.h:42
#define MUTT_TOKEN_EQUAL
Treat &#39;=&#39; as a special.
Definition: mutt.h:77
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:38
#define IS_COMMAND(x)
Definition: types.h:56
A List node for strings.
Definition: list.h:33
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:221
#define STAILQ_FIRST(head)
Definition: queue.h:347
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:258
#define DT_BOOL
boolean option
Definition: types.h:30
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_QUESTION
Treat &#39;?&#39; as a special.
Definition: mutt.h:86
+ Here is the call graph for this function:

◆ parse_setenv()

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

Parse the 'setenv' and 'unsetenv' commands - Implements command_t.

Definition at line 1861 of file init.c.

1863 {
1864  char **envp = mutt_envlist_getlist();
1865 
1866  bool query = false;
1867  bool unset = (data == MUTT_SET_UNSET);
1868 
1869  if (!MoreArgs(s))
1870  {
1871  mutt_buffer_printf(err, _("%s: too few arguments"), "setenv");
1872  return MUTT_CMD_WARNING;
1873  }
1874 
1875  if (*s->dptr == '?')
1876  {
1877  query = true;
1878  s->dptr++;
1879  }
1880 
1881  /* get variable name */
1883 
1884  if (query)
1885  {
1886  bool found = false;
1887  while (envp && *envp)
1888  {
1889  /* This will display all matches for "^QUERY" */
1890  if (mutt_str_startswith(*envp, buf->data, CASE_MATCH))
1891  {
1892  if (!found)
1893  {
1894  mutt_endwin();
1895  found = true;
1896  }
1897  puts(*envp);
1898  }
1899  envp++;
1900  }
1901 
1902  if (found)
1903  {
1905  return MUTT_CMD_SUCCESS;
1906  }
1907 
1908  mutt_buffer_printf(err, _("%s is unset"), buf->data);
1909  return MUTT_CMD_WARNING;
1910  }
1911 
1912  if (unset)
1913  {
1914  if (mutt_envlist_unset(buf->data))
1915  return MUTT_CMD_SUCCESS;
1916  return MUTT_CMD_ERROR;
1917  }
1918 
1919  /* set variable */
1920 
1921  if (*s->dptr == '=')
1922  {
1923  s->dptr++;
1924  SKIPWS(s->dptr);
1925  }
1926 
1927  if (!MoreArgs(s))
1928  {
1929  mutt_buffer_printf(err, _("%s: too few arguments"), "setenv");
1930  return MUTT_CMD_WARNING;
1931  }
1932 
1933  char *name = mutt_str_strdup(buf->data);
1935  mutt_envlist_set(name, buf->data, true);
1936  FREE(&name);
1937 
1938  return MUTT_CMD_SUCCESS;
1939 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define _(a)
Definition: message.h:28
Match case when comparing strings.
Definition: string2.h:67
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:43
const char * name
Definition: pgpmicalg.c:46
#define SKIPWS(ch)
Definition: string2.h:47
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:545
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:2674
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:578
default is to unset all vars
Definition: init.h:107
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#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:77
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
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()

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

Parse the 'source' command - Implements command_t.

Definition at line 1944 of file init.c.

1946 {
1947  char path[PATH_MAX];
1948 
1949  do
1950  {
1951  if (mutt_extract_token(buf, s, MUTT_TOKEN_NO_FLAGS) != 0)
1952  {
1953  mutt_buffer_printf(err, _("source: error at %s"), s->dptr);
1954  return MUTT_CMD_ERROR;
1955  }
1956  mutt_str_strfcpy(path, buf->data, sizeof(path));
1957  mutt_expand_path(path, sizeof(path));
1958 
1959  if (source_rc(path, err) < 0)
1960  {
1961  mutt_buffer_printf(err, _("source: file %s could not be sourced"), path);
1962  return MUTT_CMD_ERROR;
1963  }
1964 
1965  } while (MoreArgs(s));
1966 
1967  return MUTT_CMD_SUCCESS;
1968 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
static int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
Definition: init.c:779
#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:133
#define MoreArgs(buf)
Definition: buffer.h:43
#define PATH_MAX
Definition: mutt.h:50
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
Success: Command worked.
Definition: mutt_commands.h:37
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_spam_list()

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

Parse the 'spam' and 'nospam' commands - Implements command_t.

Definition at line 1973 of file init.c.

1975 {
1976  struct Buffer templ;
1977 
1978  mutt_buffer_init(&templ);
1979 
1980  /* Insist on at least one parameter */
1981  if (!MoreArgs(s))
1982  {
1983  if (data == MUTT_SPAM)
1984  mutt_buffer_strcpy(err, _("spam: no matching pattern"));
1985  else
1986  mutt_buffer_strcpy(err, _("nospam: no matching pattern"));
1987  return MUTT_CMD_ERROR;
1988  }
1989 
1990  /* Extract the first token, a regex */
1992 
1993  /* data should be either MUTT_SPAM or MUTT_NOSPAM. MUTT_SPAM is for spam commands. */
1994  if (data == MUTT_SPAM)
1995  {
1996  /* If there's a second parameter, it's a template for the spam tag. */
1997  if (MoreArgs(s))
1998  {
2000 
2001  /* Add to the spam list. */
2002  if (mutt_replacelist_add(&SpamList, buf->data, templ.data, err) != 0)
2003  {
2004  FREE(&templ.data);
2005  return MUTT_CMD_ERROR;
2006  }
2007  FREE(&templ.data);
2008  }
2009  /* If not, try to remove from the nospam list. */
2010  else
2011  {
2013  }
2014 
2015  return MUTT_CMD_SUCCESS;
2016  }
2017  /* MUTT_NOSPAM is for nospam commands. */
2018  else if (data == MUTT_NOSPAM)
2019  {
2020  /* nospam only ever has one parameter. */
2021 
2022  /* "*" is a special case. */
2023  if (mutt_str_strcmp(buf->data, "*") == 0)
2024  {
2027  return MUTT_CMD_SUCCESS;
2028  }
2029 
2030  /* If it's on the spam list, just remove it. */
2031  if (mutt_replacelist_remove(&SpamList, buf->data) != 0)
2032  return MUTT_CMD_SUCCESS;
2033 
2034  /* Otherwise, add it to the nospam list. */
2035  if (mutt_regexlist_add(&NoSpamList, buf->data, REG_ICASE, err) != 0)
2036  return MUTT_CMD_ERROR;
2037 
2038  return MUTT_CMD_SUCCESS;
2039  }
2040 
2041  /* This should not happen. */
2042  mutt_buffer_strcpy(err, "This is no good at all.");
2043  return MUTT_CMD_ERROR;
2044 }
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:262
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define MUTT_NOSPAM
Definition: mutt.h:119
struct ReplaceList SpamList
List of regexes and patterns to match spam emails.
Definition: email_globals.c:44
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:447
#define MoreArgs(buf)
Definition: buffer.h:43
#define MUTT_SPAM
Definition: mutt.h:118
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
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
Success: Command worked.
Definition: mutt_commands.h:37
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:564
#define FREE(x)
Definition: memory.h:40
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
Definition: email_globals.c:43
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:170
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_stailq()

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

Parse a list command - Implements command_t.

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

Definition at line 2051 of file init.c.

2053 {
2054  do
2055  {
2057  add_to_stailq((struct ListHead *) data, buf->data);
2058  } while (MoreArgs(s));
2059 
2060  return MUTT_CMD_SUCCESS;
2061 }
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
static void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: init.c:118
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_subjectrx_list()

static enum CommandResult parse_subjectrx_list ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'subjectrx' command - Implements command_t.

Definition at line 2066 of file init.c.

2068 {
2069  enum CommandResult rc;
2070 
2071  rc = parse_replace_list(buf, s, data, err);
2072  if (rc == MUTT_CMD_SUCCESS)
2074  return rc;
2075 }
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
static enum CommandResult parse_replace_list(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a string replacement rule - Implements command_t.
Definition: init.c:603
static void clear_subject_mods(void)
Clear out all modified email subjects.
Definition: init.c:223
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
+ Here is the call graph for this function:

◆ parse_subscribe()

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

Parse the 'subscribe' command - Implements command_t.

Definition at line 2080 of file init.c.

2082 {
2083  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
2084 
2085  do
2086  {
2088 
2089  if (parse_grouplist(&gl, buf, s, data, err) == -1)
2090  goto bail;
2091 
2094 
2095  if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
2096  goto bail;
2097  if (mutt_regexlist_add(&SubscribedLists, buf->data, REG_ICASE, err) != 0)
2098  goto bail;
2099  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
2100  goto bail;
2101  } while (MoreArgs(s));
2102 
2104  return MUTT_CMD_SUCCESS;
2105 
2106 bail:
2108  return MUTT_CMD_ERROR;
2109 }
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, int flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:277
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
static int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a group context.
Definition: init.c:573
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: email_globals.c:50
char * data
Pointer to data.
Definition: buffer.h:35
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: email_globals.c:52
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:158
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
Definition: email_globals.c:51
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
Definition: email_globals.c:49
+ Here is the call graph for this function:

◆ parse_subscribe_to()

static enum CommandResult parse_subscribe_to ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'subscribe-to' command - Implements command_t.

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 2119 of file init.c.

2121 {
2122  if (!buf || !s || !err)
2123  return MUTT_CMD_ERROR;
2124 
2125  mutt_buffer_reset(err);
2126 
2127  if (MoreArgs(s))
2128  {
2130 
2131  if (MoreArgs(s))
2132  {
2133  mutt_buffer_printf(err, _("%s: too many arguments"), "subscribe-to");
2134  return MUTT_CMD_WARNING;
2135  }
2136 
2137  if (buf->data && (*buf->data != '\0'))
2138  {
2139  /* Expand and subscribe */
2140  if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), true) == 0)
2141  {
2142  mutt_message(_("Subscribed to %s"), buf->data);
2143  return MUTT_CMD_SUCCESS;
2144  }
2145 
2146  mutt_buffer_printf(err, _("Could not subscribe to %s"), buf->data);
2147  return MUTT_CMD_ERROR;
2148  }
2149 
2150  mutt_debug(LL_DEBUG1, "Corrupted buffer");
2151  return MUTT_CMD_ERROR;
2152  }
2153 
2154  mutt_buffer_addstr(err, _("No folder specified"));
2155  return MUTT_CMD_WARNING;
2156 }
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:35
#define mutt_message(...)
Definition: logging.h:83
#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:133
#define MoreArgs(buf)
Definition: buffer.h:43
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:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Log at debug level 1.
Definition: logging.h:40
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1391
+ Here is the call graph for this function:

◆ parse_tag_formats()

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

Parse the 'tag-formats' command - Implements command_t.

Definition at line 2162 of file init.c.

2164 {
2165  if (!buf || !s)
2166  return MUTT_CMD_ERROR;
2167 
2168  char *tmp = NULL;
2169 
2170  while (MoreArgs(s))
2171  {
2172  char *tag = NULL, *format = NULL;
2173 
2175  if (buf->data && (*buf->data != '\0'))
2176  tag = mutt_str_strdup(buf->data);
2177  else
2178  continue;
2179 
2181  format = mutt_str_strdup(buf->data);
2182 
2183  /* avoid duplicates */
2184  tmp = mutt_hash_find(TagFormats, format);
2185  if (tmp)
2186  {
2187  mutt_debug(LL_DEBUG3, "tag format '%s' already registered as '%s'\n", format, tmp);
2188  FREE(&tag);
2189  FREE(&format);
2190  continue;
2191  }
2192 
2193  mutt_hash_insert(TagFormats, format, tag);
2194  }
2195  return MUTT_CMD_SUCCESS;
2196 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
void * mutt_hash_find(const struct Hash *table, const char *strkey)
Find the HashElem data in a Hash table element using a key.
Definition: hash.c:378
WHERE struct Hash * TagFormats
Hash table of tag-formats (tag -> format string)
Definition: globals.h:60
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct HashElem * mutt_hash_insert(struct Hash *table, const char *strkey, void *data)
Add a new element to the Hash table (with string keys)
Definition: hash.c:351
Log at debug level 3.
Definition: logging.h:42
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_tag_transforms()

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

Parse the 'tag-transforms' command - Implements command_t.

Definition at line 2201 of file init.c.

2203 {
2204  if (!buf || !s)
2205  return MUTT_CMD_ERROR;
2206 
2207  char *tmp = NULL;
2208 
2209  while (MoreArgs(s))
2210  {
2211  char *tag = NULL, *transform = NULL;
2212 
2214  if (buf->data && (*buf->data != '\0'))
2215  tag = mutt_str_strdup(buf->data);
2216  else
2217  continue;
2218 
2220  transform = mutt_str_strdup(buf->data);
2221 
2222  /* avoid duplicates */
2223  tmp = mutt_hash_find(TagTransforms, tag);
2224  if (tmp)
2225  {
2226  mutt_debug(LL_DEBUG3, "tag transform '%s' already registered as '%s'\n", tag, tmp);
2227  FREE(&tag);
2228  FREE(&transform);
2229  continue;
2230  }
2231 
2232  mutt_hash_insert(TagTransforms, tag, transform);
2233  }
2234  return MUTT_CMD_SUCCESS;
2235 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
struct Hash * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
void * mutt_hash_find(const struct Hash *table, const char *strkey)
Find the HashElem data in a Hash table element using a key.
Definition: hash.c:378
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct HashElem * mutt_hash_insert(struct Hash *table, const char *strkey, void *data)
Add a new element to the Hash table (with string keys)
Definition: hash.c:351
Log at debug level 3.
Definition: logging.h:42
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unalias()

static enum CommandResult parse_unalias ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'unalias' command - Implements command_t.

Definition at line 2240 of file init.c.

2242 {
2243  struct Alias *a = NULL;
2244 
2245  do
2246  {
2248 
2249  if (mutt_str_strcmp("*", buf->data) == 0)
2250  {
2251  if (CurrentMenu == MENU_ALIAS)
2252  {
2253  TAILQ_FOREACH(a, &Aliases, entries)
2254  {
2255  a->del = true;
2256  }
2258  }
2259  else
2260  mutt_aliaslist_free(&Aliases);
2261  break;
2262  }
2263  else
2264  {
2265  TAILQ_FOREACH(a, &Aliases, entries)
2266  {
2267  if (mutt_str_strcasecmp(buf->data, a->name) == 0)
2268  {
2269  if (CurrentMenu == MENU_ALIAS)
2270  {
2271  a->del = true;
2273  }
2274  else
2275  {
2276  TAILQ_REMOVE(&Aliases, a, entries);
2277  mutt_alias_free(&a);
2278  }
2279  break;
2280  }
2281  }
2282  }
2283  } while (MoreArgs(s));
2284  return MUTT_CMD_SUCCESS;
2285 }
A shortcut for an email address.
Definition: alias.h:37
char * name
Short name.
Definition: alias.h:39
void mutt_aliaslist_free(struct AliasList *a_list)
Free a List of Aliases.
Definition: alias.c:758
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:718
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:82
#define MoreArgs(buf)
Definition: buffer.h:43
bool del
Is it deleted?
Definition: alias.h:42
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:834
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
void mutt_alias_free(struct Alias **ptr)
Free an Alias.
Definition: alias.c:741
char * data
Pointer to data.
Definition: buffer.h:35
Select an email address by its alias.
Definition: keymap.h:71
Success: Command worked.
Definition: mutt_commands.h:37
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unalternates()

static enum CommandResult parse_unalternates ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'unalternates' command - Implements command_t.

Definition at line 2290 of file init.c.

2292 {
2293  alternates_clean();
2294  do
2295  {
2297  mutt_regexlist_remove(&Alternates, buf->data);
2298 
2299  if ((mutt_str_strcmp(buf->data, "*") != 0) &&
2300  (mutt_regexlist_add(&UnAlternates, buf->data, REG_ICASE, err) != 0))
2301  {
2302  return MUTT_CMD_ERROR;
2303  }
2304 
2305  } while (MoreArgs(s));
2306 
2307  return MUTT_CMD_SUCCESS;
2308 }
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
static void alternates_clean(void)
Clear the recipient valid flag of all emails.
Definition: init.c:139
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ mutt_attachmatch_free()

static void mutt_attachmatch_free ( struct AttachMatch **  ptr)
static

Free an AttachMatch - Implements list_free_t.

Parameters
ptrAttachMatch to free
Note
We don't free minor because it is either a pointer into major, or a static string.

Definition at line 2317 of file init.c.

2318 {
2319  if (!ptr || !*ptr)
2320  return;
2321 
2322  struct AttachMatch *am = *ptr;
2323  regfree(&am->minor_regex);
2324  FREE(&am->major);
2325  FREE(ptr);
2326 }
const char * major
Definition: mutt_parse.h:37
regex_t minor_regex
Definition: mutt_parse.h:40
#define FREE(x)
Definition: memory.h:40
An attachment matching a regex for attachment counter.
Definition: mutt_parse.h:35
+ Here is the caller graph for this function:

◆ parse_unattachments()

static enum CommandResult parse_unattachments ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'unattachments' command - Implements command_t.

Definition at line 2331 of file init.c.

2333 {
2334  char op;
2335  char *p = NULL;
2336  struct ListHead *head = NULL;
2337 
2339  if (!buf->data || (*buf->data == '\0'))
2340  {
2341  mutt_buffer_strcpy(err, _("unattachments: no disposition"));
2342  return MUTT_CMD_WARNING;
2343  }
2344 
2345  p = buf->data;
2346  op = *p++;
2347 
2348  if (op == '*')
2349  {
2355  return 0;
2356  }
2357 
2358  if ((op != '+') && (op != '-'))
2359  {
2360  op = '+';
2361  p--;
2362  }
2363  if (mutt_str_startswith("attachment", p, CASE_IGNORE))
2364  {
2365  if (op == '+')
2366  head = &AttachAllow;
2367  else
2368  head = &AttachExclude;
2369  }
2370  else if (mutt_str_startswith("inline", p, CASE_IGNORE))
2371  {
2372  if (op == '+')
2373  head = &InlineAllow;
2374  else
2375  head = &InlineExclude;
2376  }
2377  else
2378  {
2379  mutt_buffer_strcpy(err, _("unattachments: invalid disposition"));
2380  return MUTT_CMD_ERROR;
2381  }
2382 
2383  return parse_unattach_list(buf, s, head, err);
2384 }
static enum CommandResult parse_unattach_list(struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
Parse the "unattachments" command.
Definition: init.c:643
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
struct ListHead InlineAllow
List of inline types to counted.
Definition: mutt_parse.c:41
void mutt_list_free_type(struct ListHead *h, list_free_t fn)
Free a List of type.
Definition: list.c:145
#define _(a)
Definition: message.h:28
static void attachments_clean(void)
always wise to do what someone else did before
Definition: init.c:157
struct ListHead InlineExclude
List of inline types to ignore.
Definition: mutt_parse.c:42
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
static void mutt_attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t.
Definition: init.c:2317
char * data
Pointer to data.
Definition: buffer.h:35
Ignore case when comparing strings.
Definition: string2.h:68
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_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: mutt_parse.c:40
Warning: Help given to the user.
Definition: mutt_commands.h:36
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: mutt_parse.c:39
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
void(* list_free_t)(void **ptr)
typedef list_free_t - Prototype for a function to free List data
Definition: list.h:44
+ Here is the call graph for this function:

◆ parse_unignore()

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

Parse the 'unignore' command - Implements command_t.

Definition at line 2389 of file init.c.

2391 {
2392  do
2393  {
2395 
2396  /* don't add "*" to the unignore list */
2397  if (strcmp(buf->data, "*") != 0)
2398  add_to_stailq(&UnIgnore, buf->data);
2399 
2400  remove_from_stailq(&Ignore, buf->data);
2401  } while (MoreArgs(s));
2402 
2403  return MUTT_CMD_SUCCESS;
2404 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:753
struct ListHead UnIgnore
List of header patterns to unignore (see)
Definition: email_globals.c:46
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
struct ListHead Ignore
List of header patterns to ignore.
Definition: email_globals.c:45
static void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: init.c:118
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unlists()

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

Parse the 'unlists' command - Implements command_t.

Definition at line 2409 of file init.c.

2411 {
2413  do
2414  {
2418 
2419  if ((mutt_str_strcmp(buf->data, "*") != 0) &&
2420  (mutt_regexlist_add(&UnMailLists, buf->data, REG_ICASE, err) != 0))
2421  {
2422  return MUTT_CMD_ERROR;
2423  }
2424  } while (MoreArgs(s));
2425 
2426  return MUTT_CMD_SUCCESS;
2427 }
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
struct Hash * AutoSubscribeCache
Hash table of auto-subscribed mailing lists.
Definition: email_globals.c:48
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: email_globals.c:50
char * data
Pointer to data.
Definition: buffer.h:35
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: email_globals.c:52
Success: Command worked.
Definition: mutt_commands.h:37
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
Definition: email_globals.c:51
void mutt_hash_free(struct Hash **ptr)
Free a hash table.
Definition: hash.c:471
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unmailboxes()

static enum CommandResult parse_unmailboxes ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'unmailboxes' command - Implements command_t.

This is also used by 'unvirtual-mailboxes'

Definition at line 2434 of file init.c.

2436 {
2437  bool tmp_valid = false;
2438  bool clear_all = false;
2439 
2440  while (!clear_all && MoreArgs(s))
2441  {
2443 
2444  if (mutt_str_strcmp(buf->data, "*") == 0)
2445  {
2446  clear_all = true;
2447  tmp_valid = false;
2448  }
2449  else
2450  {
2452  tmp_valid = true;
2453  }
2454 
2455  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
2456  struct MailboxNode *np = NULL;
2457  struct MailboxNode *nptmp = NULL;
2458  STAILQ_FOREACH_SAFE(np, &ml, entries, nptmp)
2459  {
2460  /* Decide whether to delete all normal mailboxes or all virtual */
2461  bool virt = ((np->mailbox->magic == MUTT_NOTMUCH) && (data & MUTT_VIRTUAL));
2462  bool norm = ((np->mailbox->magic != MUTT_NOTMUCH) && !(data & MUTT_VIRTUAL));
2463  bool clear_this = clear_all && (virt || norm);
2464 
2465  /* Compare against path or desc? Ensure 'buf' is valid */
2466  if (!clear_this && tmp_valid)
2467  {
2468  clear_this =
2469  (mutt_str_strcasecmp(mutt_b2s(buf), mailbox_path(np->mailbox)) == 0) ||
2470  (mutt_str_strcasecmp(mutt_b2s(buf), np->mailbox->name) == 0);
2471  }
2472 
2473  if (clear_this)
2474  {
2475 #ifdef USE_SIDEBAR
2476  mutt_sb_notify_mailbox(np->mailbox, false);
2477 #endif
2478 #ifdef USE_INOTIFY
2480 #endif
2481  if (Context && (Context->mailbox == np->mailbox))
2482  {
2483  np->mailbox->flags |= MB_HIDDEN;
2484  }
2485  else
2486  {
2488  mailbox_free(&np->mailbox);
2489  }
2490  }
2491  }
2493  }
2494  return MUTT_CMD_SUCCESS;
2495 }
The "current" mailbox.
Definition: context.h:36
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:135
int mutt_monitor_remove(struct Mailbox *m)
Remove a watch for a mailbox.
Definition: monitor.c:521
Match any Mailbox type.
Definition: mailbox.h:44
Container for Accounts, Notifications.
Definition: neomutt.h:35
#define MoreArgs(buf)
Definition: buffer.h:43
char * name
A short name for the Mailbox.
Definition: mailbox.h:84
struct Mailbox * mailbox
Definition: context.h:50
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:60
enum MailboxType magic
Mailbox type.
Definition: mailbox.h:104
struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType magic)
Get a List of all Mailboxes.
Definition: neomutt.c:157
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
int flags
e.g. MB_NORMAL
Definition: mailbox.h:133
#define mutt_b2s(buf)
Definition: buffer.h:41
#define MB_HIDDEN
Definition: mailbox.h:37
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
#define MUTT_VIRTUAL
Definition: init.h:113
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:53
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:342
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:130
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition: account.c:95
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
List of Mailboxes.
Definition: mailbox.h:144
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:146
+ Here is the call graph for this function:

◆ parse_unmy_hdr()

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

Parse the 'unmy_hdr' command - Implements command_t.

Definition at line 2500 of file init.c.

2502 {
2503  struct ListNode *np = NULL, *tmp = NULL;
2504  size_t l;
2505 
2506  do
2507  {
2509  if (mutt_str_strcmp("*", buf->data) == 0)
2510  {
2511  mutt_list_free(&UserHeader);
2512  continue;
2513  }
2514 
2515  l = mutt_str_strlen(buf->data);
2516  if (buf->data[l - 1] == ':')
2517  l--;
2518 
2519  STAILQ_FOREACH_SAFE(np, &UserHeader, entries, tmp)
2520  {
2521  if ((mutt_str_strncasecmp(buf->data, np->data, l) == 0) && (np->data[l] == ':'))
2522  {
2523  STAILQ_REMOVE(&UserHeader, np, ListNode, entries);
2524  FREE(&np->data);
2525  FREE(&np);
2526  }
2527  }
2528  } while (MoreArgs(s));
2529  return MUTT_CMD_SUCCESS;
2530 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
#define MoreArgs(buf)
Definition: buffer.h:43
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
int mutt_str_strncasecmp(const char *a, const char *b, size_t l)
Compare two strings ignoring case (to a maximum), safely.
Definition: string.c:656
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * data
String.
Definition: list.h:35
#define FREE(x)
Definition: memory.h:40
A List node for strings.
Definition: list.h:33
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unstailq()

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

Parse an unlist command - Implements command_t.

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

Definition at line 2537 of file init.c.

2539 {
2540  do
2541  {
2543  /* Check for deletion of entire list */
2544  if (mutt_str_strcmp(buf->data, "*") == 0)
2545  {
2546  mutt_list_free((struct ListHead *) data);
2547  break;
2548  }
2549  remove_from_stailq((struct ListHead *) data, buf->data);
2550  } while (MoreArgs(s));
2551 
2552  return MUTT_CMD_SUCCESS;
2553 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:753
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * data
String.
Definition: list.h:35
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unsubjectrx_list()

static enum CommandResult parse_unsubjectrx_list ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'unsubjectrx' command - Implements command_t.

Definition at line 2558 of file init.c.

2560 {
2561  enum CommandResult rc;
2562 
2563  rc = parse_unreplace_list(buf, s, data, err);
2564  if (rc == MUTT_CMD_SUCCESS)
2566  return rc;
2567 }
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
static void clear_subject_mods(void)
Clear out all modified email subjects.
Definition: init.c:223
Success: Command worked.
Definition: mutt_commands.h:37
char * data
String.
Definition: list.h:35
static enum CommandResult parse_unreplace_list(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Remove a string replacement rule - Implements command_t.
Definition: init.c:701
+ Here is the call graph for this function:

◆ parse_unsubscribe()

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

Parse the 'unsubscribe' command - Implements command_t.

Definition at line 2572 of file init.c.

2574 {
2576  do
2577  {
2580 
2581  if ((mutt_str_strcmp(buf->data, "*") != 0) &&
2582  (mutt_regexlist_add(&UnSubscribedLists, buf->data, REG_ICASE, err) != 0))
2583  {
2584  return MUTT_CMD_ERROR;
2585  }
2586  } while (MoreArgs(s));
2587 
2588  return MUTT_CMD_SUCCESS;
2589 }
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
struct Hash * AutoSubscribeCache
Hash table of auto-subscribed mailing lists.
Definition: email_globals.c:48
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
char * data
Pointer to data.
Definition: buffer.h:35
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: email_globals.c:52
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_hash_free(struct Hash **ptr)
Free a hash table.
Definition: hash.c:471
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
Definition: email_globals.c:49
+ Here is the call graph for this function:

◆ parse_unsubscribe_from()

static enum CommandResult parse_unsubscribe_from ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)
static

Parse the 'unsubscribe-from' command - Implements command_t.

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 2599 of file init.c.

2601 {
2602  if (!buf || !s || !err)
2603  return MUTT_CMD_ERROR;
2604 
2605  if (MoreArgs(s))
2606  {
2608 
2609  if (MoreArgs(s))
2610  {
2611  mutt_buffer_printf(err, _("%s: too many arguments"), "unsubscribe-from");
2612  return MUTT_CMD_WARNING;
2613  }
2614 
2615  if (buf->data && (*buf->data != '\0'))
2616  {
2617  /* Expand and subscribe */
2618  if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), false) == 0)
2619  {
2620  mutt_message(_("Unsubscribed from %s"), buf->data);
2621  return MUTT_CMD_SUCCESS;
2622  }
2623 
2624  mutt_buffer_printf(err, _("Could not unsubscribe from %s"), buf->data);
2625  return MUTT_CMD_ERROR;
2626  }
2627 
2628  mutt_debug(LL_DEBUG1, "Corrupted buffer");
2629  return MUTT_CMD_ERROR;
2630  }
2631 
2632  mutt_buffer_addstr(err, _("No folder specified"));
2633  return MUTT_CMD_WARNING;
2634 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define mutt_message(...)
Definition: logging.h:83
#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:133
#define MoreArgs(buf)
Definition: buffer.h:43
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:2674
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Log at debug level 1.
Definition: logging.h:40
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1391
+ Here is the call graph for this function:

◆ mutt_command_get()

const struct Command* mutt_command_get ( const char *  s)

Get a Command by its name.

Parameters
sCommand string to lookup
Return values
ptrSuccess, Command
NULLError, no such command

Definition at line 2643 of file init.c.

2644 {
2645  for (int i = 0; Commands[i].name; i++)
2646  if (mutt_str_strcmp(s, Commands[i].name) == 0)
2647  return &Commands[i];
2648  return NULL;
2649 }
const char * name
Name of the command.
Definition: mutt_commands.h:56
const struct Command Commands[]
Definition: init.h:5001
const char * name
Definition: pgpmicalg.c:46
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_extract_token()

int mutt_extract_token ( struct Buffer dest,
struct Buffer tok,
TokenFlags  flags 
)

Extract one token from a string.

Parameters
destBuffer for the result
tokBuffer containing tokens
flagsFlags, see TokenFlags
Return values
0Success
-1Error

Definition at line 2674 of file init.c.

2675 {
2676  if (!dest || !tok)
2677  return -1;
2678 
2679  char ch;
2680  char qc = '\0'; /* quote char */
2681  char *pc = NULL;
2682 
2683  mutt_buffer_reset(dest);
2684 
2685  SKIPWS(tok->dptr);
2686  while ((ch = *tok->dptr))
2687  {
2688  if (qc == '\0')
2689  {
2690  if ((IS_SPACE(ch) && !(flags & MUTT_TOKEN_SPACE)) ||
2691  ((ch == '#') && !(flags & MUTT_TOKEN_COMMENT)) ||
2692  ((ch == '=') && (flags & MUTT_TOKEN_EQUAL)) ||
2693  ((ch == '?') && (flags & MUTT_TOKEN_QUESTION)) ||
2694  ((ch == ';') && !(flags & MUTT_TOKEN_SEMICOLON)) ||
2695  ((flags & MUTT_TOKEN_PATTERN) && strchr("~%=!|", ch)))
2696  {
2697  break;
2698  }
2699  }
2700 
2701  tok->dptr++;
2702 
2703  if (ch == qc)
2704  qc = 0; /* end of quote */
2705  else if (!qc && ((ch == '\'') || (ch == '"')) && !(flags & MUTT_TOKEN_QUOTE))
2706  qc = ch;
2707  else if ((ch == '\\') && (qc != '\''))
2708  {
2709  if (tok->dptr[0] == '\0')
2710  return -1; /* premature end of token */
2711  switch (ch = *tok->dptr++)
2712  {
2713  case 'c':
2714  case 'C':
2715  if (tok->dptr[0] == '\0')
2716  return -1; /* premature end of token */
2717  mutt_buffer_addch(dest, (toupper((unsigned char) tok->dptr[0]) - '@') & 0x7f);
2718  tok->dptr++;
2719  break;
2720  case 'e':
2721  mutt_buffer_addch(dest, '\033'); // Escape
2722  break;
2723  case 'f':
2724  mutt_buffer_addch(dest, '\f');
2725  break;
2726  case 'n':
2727  mutt_buffer_addch(dest, '\n');
2728  break;
2729  case 'r':
2730  mutt_buffer_addch(dest, '\r');
2731  break;
2732  case 't':
2733  mutt_buffer_addch(dest, '\t');
2734  break;
2735  default:
2736  if (isdigit((unsigned char) ch) && isdigit((unsigned char) tok->dptr[0]) &&
2737  isdigit((unsigned char) tok->dptr[1]))
2738  {
2739  mutt_buffer_addch(dest, (ch << 6) + (tok->dptr[0] << 3) + tok->dptr[1] - 3504);
2740  tok->dptr += 2;
2741  }
2742  else
2743  mutt_buffer_addch(dest, ch);
2744  }
2745  }
2746  else if ((ch == '^') && (flags & MUTT_TOKEN_CONDENSE))
2747  {
2748  if (tok->dptr[0] == '\0')
2749  return -1; /* premature end of token */
2750  ch = *tok->dptr++;
2751  if (ch == '^')
2752  mutt_buffer_addch(dest, ch);
2753  else if (ch == '[')
2754  mutt_buffer_addch(dest, '\033'); // Escape
2755  else if (isalpha((unsigned char) ch))
2756  mutt_buffer_addch(dest, toupper((unsigned char) ch) - '@');
2757  else
2758  {
2759  mutt_buffer_addch(dest, '^');
2760  mutt_buffer_addch(dest, ch);
2761  }
2762  }
2763  else if ((ch == '`') && (!qc || (qc == '"')))
2764  {
2765  FILE *fp = NULL;
2766  pid_t pid;
2767  int line = 0;
2768 
2769  pc = tok->dptr;
2770  do
2771  {
2772  pc = strpbrk(pc, "\\`");
2773  if (pc)
2774  {
2775  /* skip any quoted chars */
2776  if (*pc == '\\')
2777  pc += 2;
2778  }
2779  } while (pc && (pc[0] != '`'));
2780  if (!pc)
2781  {
2782  mutt_debug(LL_DEBUG1, "mismatched backticks\n");
2783  return -1;
2784  }
2785  struct Buffer cmd;
2786  mutt_buffer_init(&cmd);
2787  *pc = '\0';
2788  if (flags & MUTT_TOKEN_BACKTICK_VARS)
2789  {
2790  /* recursively extract tokens to interpolate variables */
2791  mutt_extract_token(&cmd, tok,
2792  MUTT_TOKEN_QUOTE | MUTT_TOKEN_SPACE | MUTT_TOKEN_COMMENT |
2793  MUTT_TOKEN_SEMICOLON | MUTT_TOKEN_NOSHELL);
2794  }
2795  else
2796  {
2797  cmd.data = mutt_str_strdup(tok->dptr);
2798  }
2799  *pc = '`';
2800  pid = mutt_create_filter(cmd.data, NULL, &fp, NULL);
2801  if (pid < 0)
2802  {
2803  mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", cmd.data);
2804  FREE(&cmd.data);
2805  return -1;
2806  }
2807  FREE(&cmd.data);
2808 
2809  tok->dptr = pc + 1;
2810 
2811  /* read line */
2812  struct Buffer expn = mutt_buffer_make(0);
2813  expn.data = mutt_file_read_line(NULL, &expn.dsize, fp, &line, 0);
2814  mutt_file_fclose(&fp);
2815  mutt_wait_filter(pid);
2816 
2817  /* if we got output, make a new string consisting of the shell output
2818  * plus whatever else was left on the original line */
2819  /* BUT: If this is inside a quoted string, directly add output to
2820  * the token */
2821  if (expn.data)
2822  {
2823  if (qc)
2824  {
2825  mutt_buffer_addstr(dest, expn.data);
2826  }
2827  else
2828  {
2829  struct Buffer *copy = mutt_buffer_pool_get();
2830  mutt_buffer_fix_dptr(&expn);
2831  mutt_buffer_copy(copy, &expn);
2832  mutt_buffer_addstr(copy, tok->dptr);
2833  mutt_buffer_copy(tok, copy);
2834  tok->dptr = tok->data;
2835  mutt_buffer_pool_release(&copy);
2836  }
2837  FREE(&expn.data);
2838  }
2839  }
2840  else if ((ch == '$') && (!qc || (qc == '"')) &&
2841  ((tok->dptr[0] == '{') || isalpha((unsigned char) tok->dptr[0])))
2842  {
2843  const char *env = NULL;
2844  char *var = NULL;
2845 
2846  if (tok->dptr[0] == '{')
2847  {
2848  pc = strchr(tok->dptr, '}');
2849  if (pc)
2850  {
2851  var = mutt_str_substr_dup(tok->dptr + 1, pc);
2852  tok->dptr = pc + 1;
2853 
2854  if ((flags & MUTT_TOKEN_NOSHELL))
2855  {
2856  mutt_buffer_addch(dest, ch);
2857  mutt_buffer_addch(dest, '{');
2858  mutt_buffer_addstr(dest, var);
2859  mutt_buffer_addch(dest, '}');
2860  FREE(&var);
2861  }
2862  }
2863  }
2864  else
2865  {
2866  for (pc = tok->dptr; isalnum((unsigned char) *pc) || (pc[0] == '_'); pc++)
2867  ;
2868  var = mutt_str_substr_dup(tok->dptr, pc);
2869  tok->dptr = pc;
2870  }
2871  if (var)
2872  {
2873  struct Buffer result;
2874  mutt_buffer_init(&result);
2875  int rc = cs_subset_str_string_get(NeoMutt->sub, var, &result);
2876 
2877  if (CSR_RESULT(rc) == CSR_SUCCESS)
2878  {
2879  mutt_buffer_addstr(dest, result.data);
2880  FREE(&result.data);
2881  }
2882  else if ((env = myvar_get(var)))
2883  {
2884  mutt_buffer_addstr(dest, env);
2885  }
2886  else if (!(flags & MUTT_TOKEN_NOSHELL) && (env = mutt_str_getenv(var)))
2887  {
2888  mutt_buffer_addstr(dest, env);
2889  }
2890  else
2891  {
2892  mutt_buffer_addch(dest, ch);
2893  mutt_buffer_addstr(dest, var);
2894  }
2895  FREE(&var);
2896  }
2897  }
2898  else
2899  mutt_buffer_addch(dest, ch);
2900  }
2901  mutt_buffer_addch(dest, 0); /* terminate the string */
2902  SKIPWS(tok->dptr);
2903  return 0;
2904 }
pid_t mutt_create_filter(const char *s, FILE **fp_in, FILE **fp_out, FILE **fp_err)
Set up filter program.
Definition: filter.c:209
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define CSR_RESULT(x)
Definition: set.h:53
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
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
#define MUTT_TOKEN_COMMENT
Don&#39;t reap comments.
Definition: mutt.h:82
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_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, int flags)
Read a line from a file.
Definition: file.c:664
Container for Accounts, Notifications.
Definition: neomutt.h:35
int cs_subset_str_string_get(const struct ConfigSubset *sub, const char *name, struct Buffer *result)
Get a config item as a string.
Definition: subset.c:308
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:1048
size_t dsize
Length of data.
Definition: buffer.h:37
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
#define SKIPWS(ch)
Definition: string2.h:47
#define MUTT_TOKEN_NOSHELL
Don&#39;t expand environment variables.
Definition: mutt.h:85
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:181
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:37
#define MUTT_TOKEN_QUOTE
Don&#39;t interpret quotes.
Definition: mutt.h:80
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:78
const char * line
Definition: common.c:36
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2674
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:79
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
Definition: myvar.c:73
#define MUTT_TOKEN_SEMICOLON
Don&#39;t treat ; as special.
Definition: mutt.h:83
#define IS_SPACE(ch)
Definition: string2.h:38
Log at debug level 1.
Definition: logging.h:40
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define MUTT_TOKEN_BACKTICK_VARS
Expand variables within backticks.
Definition: mutt.h:84
#define FREE(x)
Definition: memory.h:40
#define MUTT_TOKEN_EQUAL
Treat &#39;=&#39; as a special.
Definition: mutt.h:77
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:38
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:220
char * mutt_str_substr_dup(const char *begin, const char *end)
Duplicate a sub-string.
Definition: string.c:579
#define MUTT_TOKEN_PATTERN
~%=!| are terms (for patterns)
Definition: mutt.h:81
#define MUTT_TOKEN_QUESTION
Treat &#39;?&#39; as a special.
Definition: mutt.h:86

◆ mutt_opts_free()

void mutt_opts_free ( void  )

clean up before quitting

Definition at line 2909 of file init.c.

2910 {
2912 
2913  FREE(&Matches);
2914 
2915  mutt_aliaslist_free(&Aliases);
2916 
2917  mutt_regexlist_free(&Alternates);
2921  mutt_regexlist_free(&UnAlternates);
2924 
2929 
2930  /* Lists of strings */
2931  mutt_list_free(&AlternativeOrderList);
2932  mutt_list_free(&AutoViewList);
2933  mutt_list_free(&HeaderOrderList);
2936  mutt_list_free(&MimeLookupList);
2937  mutt_list_free(&Muttrc);
2939 #ifdef USE_SIDEBAR
2940  mutt_list_free(&SidebarWhitelist);
2941 #endif
2943  mutt_list_free(&UserHeader);
2944 
2945  /* Lists of AttachMatch */
2950 
2952 
2953  FREE(&CurrentFolder);
2954  FREE(&HomeDir);
2955  FREE(&LastFolder);
2956  FREE(&ShortHostname);
2957  FREE(&Username);
2958 
2961 
2963 
2964  mutt_hist_free();
2965  mutt_keys_free();
2966 
2968 }
WHERE char * Username
User&#39;s login name.
Definition: globals.h:52
void mutt_aliaslist_free(struct AliasList *a_list)
Free a List of Aliases.
Definition: alias.c:758
struct Hash * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
struct ListHead InlineAllow
List of inline types to counted.
Definition: mutt_parse.c:41
static struct ListHead MuttrcStack
Definition: init.c:79
struct ReplaceList SpamList
List of regexes and patterns to match spam emails.
Definition: email_globals.c:44
void mutt_list_free_type(struct ListHead *h, list_free_t fn)
Free a List of type.
Definition: list.c:145
struct ListHead MailToAllow
List of permitted fields in a mailto: uri.
Definition: email_globals.c:47
WHERE struct Hash * TagFormats
Hash table of tag-formats (tag -> format string)
Definition: globals.h:60
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
Definition: hook.c:302
WHERE char * LastFolder
Previously selected mailbox.
Definition: globals.h:55
struct ListHead UnIgnore
List of header patterns to unignore (see)
Definition: email_globals.c:46
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:447
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
WHERE char * HomeDir
User&#39;s home directory.
Definition: globals.h:49
WHERE char * CurrentFolder
Currently selected mailbox.
Definition: globals.h:54
struct ListHead InlineExclude
List of inline types to ignore.
Definition: mutt_parse.c:42
void mutt_keys_free(void)
Free the key maps.
Definition: keymap.c:1599
static void mutt_attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t.
Definition: init.c:2317
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: email_globals.c:50
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: email_globals.c:52
Definition: color.h:130
WHERE struct Hash * ReverseAliases
Hash table of aliases (email address -> alias)
Definition: globals.h:59
void mutt_colors_free(struct Colors **ptr)
Free all the colours.
Definition: color.c:355
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: mutt_parse.c:40
static const char ** Matches
Definition: init.c:92
WHERE char * ShortHostname
Short version of the hostname.
Definition: globals.h:50
#define FREE(x)
Definition: memory.h:40
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:44
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
Definition: email_globals.c:51
void mutt_grouplist_free(void)
Free GroupList singleton resource.
Definition: group.c:55
void mutt_hash_free(struct Hash **ptr)
Free a hash table.
Definition: hash.c:471
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: mutt_parse.c:39
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
Definition: email_globals.c:43
void mutt_hist_free(void)
Free all the history lists.
Definition: history.c:439
struct ListHead Ignore
List of header patterns to ignore.
Definition: email_globals.c:45
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:170
void(* list_free_t)(void **ptr)
typedef list_free_t - Prototype for a function to free List data
Definition: list.h:44
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
Definition: email_globals.c:49
struct ReplaceList SubjectRegexList
List of regexes to tidy the view of the email&#39;s subject.
Definition: email_globals.c:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_get_hook_type()

HookFlags mutt_get_hook_type ( const char *  name)

Find a hook by name.

Parameters
nameName to find
Return values
numHook ID, e.g. MUTT_FOLDER_HOOK
MUTT_HOOK_NO_FLAGSError, no matching hook

Definition at line 2976 of file init.c.

2977 {
2978  for (const struct Command *c = Commands; c->name; c++)
2979  {
2980  if (((c->func == mutt_parse_hook) || (c->func == mutt_parse_idxfmt_hook)) &&
2981  (mutt_str_strcasecmp(c->name, name) == 0))
2982  {
2983  return c->data;
2984  }
2985  }
2986  return MUTT_HOOK_NO_FLAGS;
2987 }
A user-callable command.
Definition: mutt_commands.h:54
const char * name
Name of the command.
Definition: mutt_commands.h:56
const struct Command Commands[]
Definition: init.h:5001
enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse the &#39;hook&#39; family of commands - Implements command_t.
Definition: hook.c:85
const char * name
Definition: pgpmicalg.c:46
enum CommandResult mutt_parse_idxfmt_hook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse the &#39;index-format-hook&#39; command - Implements command_t.
Definition: hook.c:349
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628