NeoMutt  2018-07-16 +2388-bcedc8
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 <time.h>
#include <unistd.h>
#include <wchar.h>
#include "mutt/mutt.h"
#include "address/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "mutt.h"
#include "init.h"
#include "alias.h"
#include "context.h"
#include "filter.h"
#include "hcache/hcache.h"
#include "keymap.h"
#include "monitor.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
#include "mutt_window.h"
#include "mx.h"
#include "myvar.h"
#include "options.h"
#include "protos.h"
#include "sidebar.h"
#include "version.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 (void)
 Find the Fully-Qualified Domain Name. 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...
 
void mutt_free_attachmatch (struct AttachMatch **am)
 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_free_opts (void)
 clean up before quitting More...
 
HookFlags mutt_get_hook_type (const char *name)
 Find a hook by name. More...
 
int mutt_init (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...
 

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

#define MAX_ERRS   128

Definition at line 81 of file init.c.

#define NUM_VARS   mutt_array_size(MuttVars)

Definition at line 83 of file init.c.

#define NUM_COMMANDS   mutt_array_size(Commands)

Definition at line 84 of file init.c.

Enumeration Type Documentation

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

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:350
char * data
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:

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)
142  return;
143 
144  for (int i = 0; i < Context->mailbox->msg_count; i++)
145  Context->mailbox->emails[i]->recip_valid = false;
146 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:110
The "current" mailbox.
Definition: context.h:36
int msg_count
Total number of messages.
Definition: mailbox.h:102
struct Mailbox * mailbox
Definition: context.h:50
bool recip_valid
Is_recipient is valid.
Definition: email.h:60

+ Here is the caller graph for this function:

static void attachments_clean ( void  )
static

always wise to do what someone else did before

Definition at line 151 of file init.c.

152 {
153  if (!Context)
154  return;
155 
156  for (int i = 0; i < Context->mailbox->msg_count; i++)
157  Context->mailbox->emails[i]->attach_valid = false;
158 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:110
The "current" mailbox.
Definition: context.h:36
int msg_count
Total number of messages.
Definition: mailbox.h:102
struct Mailbox * mailbox
Definition: context.h:50
bool attach_valid
true when the attachment count is valid
Definition: email.h:72

+ Here is the caller graph for this function:

static void matches_ensure_morespace ( int  current)
static

Allocate more space for auto-completion.

Parameters
currentCurrent allocation

Definition at line 164 of file init.c.

165 {
166  if (current <= (MatchesListsize - 2))
167  return;
168 
169  int base_space = MAX(NUM_VARS, NUM_COMMANDS) + 1;
170  int extra_space = MatchesListsize - base_space;
171  extra_space *= 2;
172  const int space = base_space + extra_space;
173  mutt_mem_realloc(&Matches, space * sizeof(char *));
174  memset(&Matches[current + 1], 0, space - current);
175  MatchesListsize = space;
176 }
#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:

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

188 {
189  if (!dest || !user || !src)
190  return;
191 
192  if (strstr(src, user) != src)
193  return;
194 
196  Matches[NumMatched++] = src;
197  if (dest[0] == '\0')
198  mutt_str_strfcpy(dest, src, dlen);
199  else
200  {
201  int l;
202  for (l = 0; src[l] && src[l] == dest[l]; l++)
203  ;
204  dest[l] = '\0';
205  }
206 }
static int NumMatched
Definition: init.c:90
static void matches_ensure_morespace(int current)
Allocate more space for auto-completion.
Definition: init.c:164
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:

static void clear_subject_mods ( void  )
static

Clear out all modified email subjects.

Definition at line 211 of file init.c.

212 {
213  if (!Context)
214  return;
215 
216  for (int i = 0; i < Context->mailbox->msg_count; i++)
218 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:110
The "current" mailbox.
Definition: context.h:36
int msg_count
Total number of messages.
Definition: mailbox.h:102
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:91
#define FREE(x)
Definition: memory.h:40

+ Here is the caller graph for this function:

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

228 {
229  int tag_count_1 = 0;
230  int tag_count_2 = 0;
231 
232  NumMatched = 0;
233  mutt_str_strfcpy(UserTyped, pt, sizeof(UserTyped));
234  memset(Matches, 0, MatchesListsize);
235  memset(Completed, 0, sizeof(Completed));
236 
238 
239  /* Work out how many tags there are. */
240  if (nm_get_all_tags(Context->mailbox, NULL, &tag_count_1) || (tag_count_1 == 0))
241  goto done;
242 
243  /* Free the old list, if any. */
244  if (nm_tags)
245  {
246  for (int i = 0; nm_tags[i]; i++)
247  FREE(&nm_tags[i]);
248  FREE(&nm_tags);
249  }
250  /* Allocate a new list, with sentinel. */
251  nm_tags = mutt_mem_malloc((tag_count_1 + 1) * sizeof(char *));
252  nm_tags[tag_count_1] = NULL;
253 
254  /* Get all the tags. */
255  if (nm_get_all_tags(Context->mailbox, nm_tags, &tag_count_2) || (tag_count_1 != tag_count_2))
256  {
257  FREE(&nm_tags);
258  nm_tags = NULL;
260  return -1;
261  }
262 
263  /* Put them into the completion machinery. */
264  for (int num = 0; num < tag_count_1; num++)
265  {
266  candidate(UserTyped, nm_tags[num], Completed, sizeof(Completed));
267  }
268 
271 
272 done:
274  return 0;
275 }
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:305
static int MatchesListsize
Definition: init.c:94
static void matches_ensure_morespace(int current)
Allocate more space for auto-completion.
Definition: init.c:164
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:290
static void candidate(char *user, const char *src, char *dest, size_t dlen)
helper function for completion
Definition: init.c:187

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

285 {
286  int rc = 0;
287  struct Buffer *err = mutt_buffer_pool_get();
288  struct Buffer *token = mutt_buffer_pool_get();
289 
290  struct ListNode *np = NULL;
291  STAILQ_FOREACH(np, p, entries)
292  {
293  if (mutt_parse_rc_line(np->data, token, err) == MUTT_CMD_ERROR)
294  {
295  mutt_error(_("Error in command line: %s"), mutt_b2s(err));
296  mutt_buffer_pool_release(&token);
298 
299  return -1;
300  }
301  }
302  mutt_buffer_pool_release(&token);
304 
305  return rc;
306 }
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:75
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:86
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:350
char * data
Definition: list.h:35
#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:3216

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

316 {
317  const char *names[] = {
318  "neomuttrc",
319  "muttrc",
320  NULL,
321  };
322 
323  const char *locations[][2] = {
324  { xdg_cfg_home, "neomutt/" },
325  { xdg_cfg_home, "mutt/" },
326  { home, ".neomutt/" },
327  { home, ".mutt/" },
328  { home, "." },
329  { NULL, NULL },
330  };
331 
332  for (int i = 0; locations[i][0] || locations[i][1]; i++)
333  {
334  if (!locations[i][0])
335  continue;
336 
337  for (int j = 0; names[j]; j++)
338  {
339  char buf[256];
340 
341  snprintf(buf, sizeof(buf), "%s/%s%s", locations[i][0], locations[i][1], names[j]);
342  if (access(buf, F_OK) == 0)
343  return mutt_str_strdup(buf);
344  }
345  }
346 
347  return NULL;
348 }
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:

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

357 {
358  char *mailname = NULL;
359  static const char *mn_files[] = { "/etc/mailname", "/etc/mail/mailname" };
360 
361  for (size_t i = 0; i < mutt_array_size(mn_files); i++)
362  {
363  FILE *fp = mutt_file_fopen(mn_files[i], "r");
364  if (!fp)
365  continue;
366 
367  size_t len = 0;
368  mailname = mutt_file_read_line(NULL, &len, fp, NULL, 0);
369  mutt_file_fclose(&fp);
370  if (mailname && *mailname)
371  break;
372 
373  FREE(&mailname);
374  }
375 
376  return mailname;
377 }
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:663
#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:149
#define FREE(x)
Definition: memory.h:40
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:584

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool get_hostname ( void  )
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 388 of file init.c.

389 {
390  char *str = NULL;
391  struct utsname utsname;
392 
393  if (C_Hostname)
394  {
395  str = C_Hostname;
396  }
397  else
398  {
399  /* The call to uname() shouldn't fail, but if it does, the system is horribly
400  * broken, and the system's networking configuration is in an unreliable
401  * state. We should bail. */
402  if ((uname(&utsname)) == -1)
403  {
404  mutt_perror(_("unable to determine nodename via uname()"));
405  return false; // TEST09: can't test
406  }
407 
408  str = utsname.nodename;
409  }
410 
411  /* some systems report the FQDN instead of just the hostname */
412  char *dot = strchr(str, '.');
413  if (dot)
415  else
417 
418  if (!C_Hostname)
419  {
420  /* now get FQDN. Use configured domain first, DNS next, then uname */
421 #ifdef DOMAIN
422  /* we have a compile-time domain name, use that for C_Hostname */
423  C_Hostname =
425  sprintf((char *) C_Hostname, "%s.%s", NONULL(ShortHostname), DOMAIN);
426 #else
428  if (!C_Hostname)
429  {
430  char buffer[1024];
431  if (getdnsdomainname(buffer, sizeof(buffer)) == 0)
432  {
435  sprintf((char *) C_Hostname, "%s.%s", NONULL(ShortHostname), buffer);
436  }
437  else
438  {
439  /* DNS failed, use the nodename. Whether or not the nodename had a '.'
440  * in it, we can use the nodename as the FQDN. On hosts where DNS is
441  * not being used, e.g. small network that relies on hosts files, a
442  * short host name is all that is required for SMTP to work correctly.
443  * It could be wrong, but we've done the best we can, at this point the
444  * onus is on the user to provide the correct hostname if the nodename
445  * won't work in their network. */
446  C_Hostname = mutt_str_strdup(utsname.nodename);
447  }
448  }
449 #endif
450  }
451  if (C_Hostname)
452  cs_str_initial_set(Config, "hostname", C_Hostname, NULL);
453 
454  return true;
455 }
#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:356
#define _(a)
Definition: message.h:28
WHERE struct ConfigSet * Config
Wrapper around the user&#39;s config settings.
Definition: globals.h:39
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:44
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:485
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:49
WHERE char * C_Hostname
Config: Fully-qualified domain name of this machine.
Definition: globals.h:115
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:

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

467 {
468  struct AttachMatch *a = NULL;
469  char *p = NULL;
470  char *tmpminor = NULL;
471  size_t len;
472  int ret;
473 
474  do
475  {
477 
478  if (!buf->data || (*buf->data == '\0'))
479  continue;
480 
481  a = mutt_mem_malloc(sizeof(struct AttachMatch));
482 
483  /* some cheap hacks that I expect to remove */
484  if (mutt_str_strcasecmp(buf->data, "any") == 0)
485  a->major = mutt_str_strdup("*/.*");
486  else if (mutt_str_strcasecmp(buf->data, "none") == 0)
487  a->major = mutt_str_strdup("cheap_hack/this_should_never_match");
488  else
489  a->major = mutt_str_strdup(buf->data);
490 
491  p = strchr(a->major, '/');
492  if (p)
493  {
494  *p = '\0';
495  p++;
496  a->minor = p;
497  }
498  else
499  {
500  a->minor = "unknown";
501  }
502 
503  len = strlen(a->minor);
504  tmpminor = mutt_mem_malloc(len + 3);
505  strcpy(&tmpminor[1], a->minor);
506  tmpminor[0] = '^';
507  tmpminor[len + 1] = '$';
508  tmpminor[len + 2] = '\0';
509 
511  ret = REG_COMP(&a->minor_regex, tmpminor, REG_ICASE);
512 
513  FREE(&tmpminor);
514 
515  if (ret != 0)
516  {
517  regerror(ret, &a->minor_regex, err->data, err->dsize);
518  FREE(&a->major);
519  FREE(&a);
520  return MUTT_CMD_ERROR;
521  }
522 
523  mutt_debug(LL_DEBUG3, "added %s/%s [%d]\n", a->major, a->minor, a->major_int);
524 
525  mutt_list_insert_tail(head, (char *) a);
526  } while (MoreArgs(s));
527 
529  return MUTT_CMD_SUCCESS;
530 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
enum ContentType major_int
Definition: mutt.h:133
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.h:132
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:151
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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.h:135
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.
Definition: mutt.h:130
const char * minor
Definition: mutt.h:134
Log at debug level 3.
Definition: logging.h:58
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

544 {
545  while (mutt_str_strcasecmp(buf->data, "-group") == 0)
546  {
547  if (!MoreArgs(s))
548  {
549  mutt_buffer_strcpy(err, _("-group: no group name"));
550  return -1;
551  }
552 
554 
556 
557  if (!MoreArgs(s))
558  {
559  mutt_buffer_strcpy(err, _("out of arguments"));
560  return -1;
561  }
562 
564  }
565 
566  return 0;
567 }
void mutt_grouplist_add(struct GroupList *gl, struct Group *group)
Add a Group to a GroupList.
Definition: group.c:137
#define _(a)
Definition: message.h:28
#define MoreArgs(buf)
Definition: buffer.h:43
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:314
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
char * data
Pointer to data.
Definition: buffer.h:35
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:77

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

574 {
575  struct ReplaceList *list = (struct ReplaceList *) data;
576  struct Buffer templ = { 0 };
577 
578  /* First token is a regex. */
579  if (!MoreArgs(s))
580  {
581  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
582  return MUTT_CMD_WARNING;
583  }
585 
586  /* Second token is a replacement template */
587  if (!MoreArgs(s))
588  {
589  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
590  return MUTT_CMD_WARNING;
591  }
593 
594  if (mutt_replacelist_add(list, buf->data, templ.data, err) != 0)
595  {
596  FREE(&templ.data);
597  return MUTT_CMD_ERROR;
598  }
599  FREE(&templ.data);
600 
601  return MUTT_CMD_SUCCESS;
602 }
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
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:191
#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:2638
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:77

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

614 {
615  struct AttachMatch *a = NULL;
616  char *tmp = NULL;
617  char *minor = NULL;
618 
619  do
620  {
622  FREE(&tmp);
623 
624  if (mutt_str_strcasecmp(buf->data, "any") == 0)
625  tmp = mutt_str_strdup("*/.*");
626  else if (mutt_str_strcasecmp(buf->data, "none") == 0)
627  tmp = mutt_str_strdup("cheap_hack/this_should_never_match");
628  else
629  tmp = mutt_str_strdup(buf->data);
630 
631  minor = strchr(tmp, '/');
632  if (minor)
633  {
634  *minor = '\0';
635  minor++;
636  }
637  else
638  {
639  minor = "unknown";
640  }
641  const enum ContentType major = mutt_check_mime_type(tmp);
642 
643  struct ListNode *np = NULL, *tmp2 = NULL;
644  STAILQ_FOREACH_SAFE(np, head, entries, tmp2)
645  {
646  a = (struct AttachMatch *) np->data;
647  mutt_debug(LL_DEBUG3, "check %s/%s [%d] : %s/%s [%d]\n", a->major,
648  a->minor, a->major_int, tmp, minor, major);
649  if ((a->major_int == major) && (mutt_str_strcasecmp(minor, a->minor) == 0))
650  {
651  mutt_debug(LL_DEBUG3, "removed %s/%s [%d]\n", a->major, a->minor, a->major_int);
652  regfree(&a->minor_regex);
653  FREE(&a->major);
654  STAILQ_REMOVE(head, np, ListNode, entries);
655  FREE(&np->data);
656  FREE(&np);
657  }
658  }
659 
660  } while (MoreArgs(s));
661 
662  FREE(&tmp);
664  return MUTT_CMD_SUCCESS;
665 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:400
enum ContentType major_int
Definition: mutt.h:133
#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.h:132
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:360
static void attachments_clean(void)
always wise to do what someone else did before
Definition: init.c:151
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * data
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.h:135
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.
Definition: mutt.h:130
A List node for strings.
Definition: list.h:33
const char * minor
Definition: mutt.h:134
Log at debug level 3.
Definition: logging.h:58
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77
ContentType
Content-Type.
Definition: mime.h:29

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

672 {
673  struct ReplaceList *list = (struct ReplaceList *) data;
674 
675  /* First token is a regex. */
676  if (!MoreArgs(s))
677  {
678  mutt_buffer_printf(err, _("%s: too few arguments"), "unsubjectrx");
679  return MUTT_CMD_WARNING;
680  }
681 
683 
684  /* "*" is a special case. */
685  if (mutt_str_strcmp(buf->data, "*") == 0)
686  {
687  mutt_replacelist_free(list);
688  return MUTT_CMD_SUCCESS;
689  }
690 
691  mutt_replacelist_remove(list, buf->data);
692  return MUTT_CMD_SUCCESS;
693 }
#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:191
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:2638
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:77

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

703 {
704  struct ListNode *np = NULL;
705  STAILQ_FOREACH(np, h, entries)
706  {
707  printf("attachments %c%s %s/%s\n", op, name,
708  ((struct AttachMatch *) np->data)->major,
709  ((struct AttachMatch *) np->data)->minor);
710  }
711 
712  return 0;
713 }
const char * name
Definition: pgpmicalg.c:45
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
char * data
Definition: list.h:35
An attachment matching a regex.
Definition: mutt.h:130
A List node for strings.
Definition: list.h:33

+ Here is the caller graph for this function:

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

723 {
724  if (mutt_str_strcmp("*", str) == 0)
725  mutt_list_free(head); /* "unCMD *" means delete all current entries */
726  else
727  {
728  struct ListNode *np = NULL, *tmp = NULL;
729  STAILQ_FOREACH_SAFE(np, head, entries, tmp)
730  {
731  if (mutt_str_strcasecmp(str, np->data) == 0)
732  {
733  STAILQ_REMOVE(head, np, ListNode, entries);
734  FREE(&np->data);
735  FREE(&np);
736  break;
737  }
738  }
739  }
740 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:400
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:360
char * data
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:

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

749 {
750  int line = 0, rc = 0, warnings = 0;
751  enum CommandResult line_rc;
752  struct Buffer token;
753  char *linebuf = NULL;
754  char *currentline = NULL;
755  char rcfile[PATH_MAX];
756  size_t buflen;
757 
758  pid_t pid;
759 
760  mutt_str_strfcpy(rcfile, rcfile_path, sizeof(rcfile));
761 
762  size_t rcfilelen = mutt_str_strlen(rcfile);
763  if (rcfilelen == 0)
764  return -1;
765 
766  bool ispipe = rcfile[rcfilelen - 1] == '|';
767 
768  if (!ispipe)
769  {
770  struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
771  if (!mutt_path_to_absolute(rcfile, np ? NONULL(np->data) : ""))
772  {
773  mutt_error(_("Error: Can't build path of '%s'"), rcfile_path);
774  return -1;
775  }
776 
777  STAILQ_FOREACH(np, &MuttrcStack, entries)
778  {
779  if (mutt_str_strcmp(np->data, rcfile) == 0)
780  {
781  break;
782  }
783  }
784  if (!np)
785  {
787  }
788  else
789  {
790  mutt_error(_("Error: Cyclic sourcing of configuration file '%s'"), rcfile);
791  return -1;
792  }
793  }
794 
795  mutt_debug(LL_DEBUG2, "Reading configuration file '%s'\n", rcfile);
796 
797  FILE *fp = mutt_open_read(rcfile, &pid);
798  if (!fp)
799  {
800  mutt_buffer_printf(err, "%s: %s", rcfile, strerror(errno));
801  return -1;
802  }
803 
804  mutt_buffer_init(&token);
805  while ((linebuf = mutt_file_read_line(linebuf, &buflen, fp, &line, MUTT_CONT)))
806  {
807  const bool conv = C_ConfigCharset && C_Charset;
808  if (conv)
809  {
810  currentline = mutt_str_strdup(linebuf);
811  if (!currentline)
812  continue;
813  mutt_ch_convert_string(&currentline, C_ConfigCharset, C_Charset, 0);
814  }
815  else
816  currentline = linebuf;
817  mutt_buffer_reset(err);
818  line_rc = mutt_parse_rc_line(currentline, &token, err);
819  if (line_rc == MUTT_CMD_ERROR)
820  {
821  mutt_error(_("Error in %s, line %d: %s"), rcfile, line, err->data);
822  if (--rc < -MAX_ERRS)
823  {
824  if (conv)
825  FREE(&currentline);
826  break;
827  }
828  }
829  else if (line_rc == MUTT_CMD_WARNING)
830  {
831  /* Warning */
832  mutt_warning(_("Warning in %s, line %d: %s"), rcfile, line, err->data);
833  warnings++;
834  }
835  else if (line_rc == MUTT_CMD_FINISH)
836  {
837  break; /* Found "finish" command */
838  }
839  else
840  {
841  if (rc < 0)
842  rc = -1;
843  }
844  if (conv)
845  FREE(&currentline);
846  }
847  FREE(&token.data);
848  FREE(&linebuf);
849  mutt_file_fclose(&fp);
850  if (pid != -1)
851  mutt_wait_filter(pid);
852  if (rc)
853  {
854  /* the neomuttrc source keyword */
855  mutt_buffer_reset(err);
856  mutt_buffer_printf(err, (rc >= -MAX_ERRS) ? _("source: errors in %s") : _("source: reading aborted due to too many errors in %s"),
857  rcfile);
858  rc = -1;
859  }
860  else
861  {
862  /* Don't alias errors with warnings */
863  if (warnings > 0)
864  {
865  mutt_buffer_printf(err, ngettext("source: %d warning in %s", "source: %d warnings in %s", warnings),
866  warnings, rcfile);
867  rc = -2;
868  }
869  }
870 
871  if (!ispipe && !STAILQ_EMPTY(&MuttrcStack))
872  {
873  struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
874  STAILQ_REMOVE_HEAD(&MuttrcStack, entries);
875  FREE(&np->data);
876  FREE(&np);
877  }
878 
879  return rc;
880 }
#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:723
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
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:663
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:420
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:191
#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:108
Log at debug level 2.
Definition: logging.h:57
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:149
const char * line
Definition: common.c:36
#define PATH_MAX
Definition: mutt.h:51
bool mutt_path_to_absolute(char *path, const char *reference)
Convert relative filepath to an absolute path.
Definition: path.c:433
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:350
char * data
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:346
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:61
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:228
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:1363
#define STAILQ_FIRST(head)
Definition: queue.h:348
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:3216

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

887 {
888  struct Alias *tmp = NULL;
889  char *estr = NULL;
890  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
891 
892  if (!MoreArgs(s))
893  {
894  mutt_buffer_strcpy(err, _("alias: no address"));
895  return MUTT_CMD_WARNING;
896  }
897 
899 
900  if (parse_grouplist(&gl, buf, s, data, err) == -1)
901  return MUTT_CMD_ERROR;
902 
903  /* check to see if an alias with this name already exists */
904  TAILQ_FOREACH(tmp, &Aliases, entries)
905  {
906  if (mutt_str_strcasecmp(tmp->name, buf->data) == 0)
907  break;
908  }
909 
910  if (!tmp)
911  {
912  /* create a new alias */
913  tmp = mutt_alias_new();
914  tmp->name = mutt_str_strdup(buf->data);
915  TAILQ_INSERT_TAIL(&Aliases, tmp, entries);
916  /* give the main addressbook code a chance */
917  if (CurrentMenu == MENU_ALIAS)
918  OptMenuCaller = true;
919  }
920  else
921  {
923  /* override the previous value */
924  mutt_addrlist_clear(&tmp->addr);
925  if (CurrentMenu == MENU_ALIAS)
927  }
928 
930  mutt_debug(LL_DEBUG5, "Second token is '%s'\n", buf->data);
931 
932  mutt_addrlist_parse2(&tmp->addr, buf->data);
933 
934  if (mutt_addrlist_to_intl(&tmp->addr, &estr))
935  {
936  mutt_buffer_printf(err, _("Warning: Bad IDN '%s' in alias '%s'"), estr, tmp->name);
937  FREE(&estr);
938  goto bail;
939  }
940 
941  mutt_grouplist_add_addrlist(&gl, &tmp->addr);
943 
944  if (C_DebugLevel > LL_DEBUG4)
945  {
946  /* A group is terminated with an empty address, so check a->mailbox */
947  struct Address *a = NULL;
948  TAILQ_FOREACH(a, &tmp->addr, entries)
949  {
950  if (!a->mailbox)
951  break;
952 
953  if (a->group)
954  mutt_debug(LL_DEBUG5, " Group %s\n", a->mailbox);
955  else
956  mutt_debug(LL_DEBUG5, " %s\n", a->mailbox);
957  }
958  }
960  return MUTT_CMD_SUCCESS;
961 
962 bail:
964  return MUTT_CMD_ERROR;
965 }
void mutt_alias_delete_reverse(struct Alias *t)
Remove an email address lookup for an Alias.
Definition: alias.c:561
A shortcut for an email address.
Definition: alias.h:37
Log at debug level 4.
Definition: logging.h:59
char * name
Definition: alias.h:39
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
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:1378
WHERE bool OptMenuCaller
(pseudo) tell menu to give caller a take
Definition: options.h:38
#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:225
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:191
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:603
#define MoreArgs(buf)
Definition: buffer.h:43
struct Alias * mutt_alias_new()
Create a new Alias.
Definition: alias.c:130
#define MUTT_TOKEN_QUOTE
Don&#39;t interpret quotes.
Definition: mutt.h:81
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:542
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:314
short C_DebugLevel
Config: Logging level for debug logs.
Definition: mutt_logging.c:50
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:80
char * data
Pointer to data.
Definition: buffer.h:35
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:803
Select an email address by its alias.
Definition: keymap.h:71
#define MUTT_TOKEN_SEMICOLON
Don&#39;t treat ; as special.
Definition: mutt.h:84
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:1213
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:539
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:157
#define FREE(x)
Definition: memory.h:40
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:322
WHERE int CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:86
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct AddressList addr
Definition: alias.h:40
Log at debug level 5.
Definition: logging.h:60
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77

+ Here is the call graph for this function:

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

972 {
973  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
974 
976 
977  do
978  {
980 
981  if (parse_grouplist(&gl, buf, s, data, err) == -1)
982  goto bail;
983 
984  mutt_regexlist_remove(&UnAlternates, buf->data);
985 
986  if (mutt_regexlist_add(&Alternates, buf->data, REG_ICASE, err) != 0)
987  goto bail;
988 
989  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
990  goto bail;
991  } while (MoreArgs(s));
992 
994  return MUTT_CMD_SUCCESS;
995 
996 bail:
998  return MUTT_CMD_ERROR;
999 }
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:275
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:542
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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:157
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:322
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77

+ Here is the call graph for this function:

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

1006 {
1007  char op;
1008  char *category = NULL;
1009  struct ListHead *head = NULL;
1010 
1012  if (!buf->data || (*buf->data == '\0'))
1013  {
1014  mutt_buffer_strcpy(err, _("attachments: no disposition"));
1015  return MUTT_CMD_WARNING;
1016  }
1017 
1018  category = buf->data;
1019  op = *category++;
1020 
1021  if (op == '?')
1022  {
1023  mutt_endwin();
1024  fflush(stdout);
1025  printf("\n%s\n\n", _("Current attachments settings:"));
1026  print_attach_list(&AttachAllow, '+', "A");
1027  print_attach_list(&AttachExclude, '-', "A");
1028  print_attach_list(&InlineAllow, '+', "I");
1029  print_attach_list(&InlineExclude, '-', "I");
1031  return MUTT_CMD_SUCCESS;
1032  }
1033 
1034  if ((op != '+') && (op != '-'))
1035  {
1036  op = '+';
1037  category--;
1038  }
1039  if (mutt_str_startswith("attachment", category, CASE_IGNORE))
1040  {
1041  if (op == '+')
1042  head = &AttachAllow;
1043  else
1044  head = &AttachExclude;
1045  }
1046  else if (mutt_str_startswith("inline", category, CASE_IGNORE))
1047  {
1048  if (op == '+')
1049  head = &InlineAllow;
1050  else
1051  head = &InlineExclude;
1052  }
1053  else
1054  {
1055  mutt_buffer_strcpy(err, _("attachments: invalid disposition"));
1056  return MUTT_CMD_ERROR;
1057  }
1058 
1059  return parse_attach_list(buf, s, head, err);
1060 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define _(a)
Definition: message.h:28
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:314
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:499
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
char * data
Pointer to data.
Definition: buffer.h:35
Ignore case when comparing strings.
Definition: string2.h:68
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:544
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:465
static int print_attach_list(struct ListHead *h, const char op, const char *name)
Print a list of attachments.
Definition: init.c:702
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77

+ Here is the call graph for this function:

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

1067 {
1068  if (!MoreArgs(s))
1069  {
1070  mutt_buffer_printf(err, _("%s: too few arguments"), "echo");
1071  return MUTT_CMD_WARNING;
1072  }
1074  OptForceRefresh = true;
1075  mutt_message("%s", buf->data);
1076  OptForceRefresh = false;
1077  mutt_sleep(0);
1078 
1079  return MUTT_CMD_SUCCESS;
1080 }
#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:191
#define MoreArgs(buf)
Definition: buffer.h:43
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1502
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:2638
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:77

+ Here is the call graph for this function:

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

1091 {
1092  if (MoreArgs(s))
1093  {
1094  mutt_buffer_printf(err, _("%s: too many arguments"), "finish");
1095  return MUTT_CMD_WARNING;
1096  }
1097 
1098  return MUTT_CMD_FINISH;
1099 }
#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:191
#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:

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

1106 {
1107  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1108  enum GroupState state = GS_NONE;
1109 
1110  do
1111  {
1113  if (parse_grouplist(&gl, buf, s, data, err) == -1)
1114  goto bail;
1115 
1116  if ((data == MUTT_UNGROUP) && (mutt_str_strcasecmp(buf->data, "*") == 0))
1117  {
1118  mutt_grouplist_clear(&gl);
1119  goto out;
1120  }
1121 
1122  if (mutt_str_strcasecmp(buf->data, "-rx") == 0)
1123  state = GS_RX;
1124  else if (mutt_str_strcasecmp(buf->data, "-addr") == 0)
1125  state = GS_ADDR;
1126  else
1127  {
1128  switch (state)
1129  {
1130  case GS_NONE:
1131  mutt_buffer_printf(err, _("%sgroup: missing -rx or -addr"),
1132  (data == MUTT_UNGROUP) ? "un" : "");
1133  goto warn;
1134 
1135  case GS_RX:
1136  if ((data == MUTT_GROUP) &&
1137  (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0))
1138  {
1139  goto bail;
1140  }
1141  else if ((data == MUTT_UNGROUP) &&
1142  (mutt_grouplist_remove_regex(&gl, buf->data) < 0))
1143  {
1144  goto bail;
1145  }
1146  break;
1147 
1148  case GS_ADDR:
1149  {
1150  char *estr = NULL;
1151  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
1152  mutt_addrlist_parse2(&al, buf->data);
1153  if (TAILQ_EMPTY(&al))
1154  goto bail;
1155  if (mutt_addrlist_to_intl(&al, &estr))
1156  {
1157  mutt_buffer_printf(err, _("%sgroup: warning: bad IDN '%s'"),
1158  (data == 1) ? "un" : "", estr);
1159  mutt_addrlist_clear(&al);
1160  FREE(&estr);
1161  goto bail;
1162  }
1163  if (data == MUTT_GROUP)
1164  mutt_grouplist_add_addrlist(&gl, &al);
1165  else if (data == MUTT_UNGROUP)
1167  mutt_addrlist_clear(&al);
1168  break;
1169  }
1170  }
1171  }
1172  } while (MoreArgs(s));
1173 
1174 out:
1176  return MUTT_CMD_SUCCESS;
1177 
1178 bail:
1180  return MUTT_CMD_ERROR;
1181 
1182 warn:
1184  return MUTT_CMD_WARNING;
1185 }
#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:103
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1378
#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:225
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:191
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:603
#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:275
int mutt_grouplist_remove_regex(struct GroupList *gl, const char *s)
Remove matching addresses from a GroupList.
Definition: group.c:299
int mutt_grouplist_remove_addrlist(struct GroupList *gl, struct AddressList *al)
Remove an AddressList from a GroupList.
Definition: group.c:244
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:542
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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:1213
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:157
#define FREE(x)
Definition: memory.h:40
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:322
Entry is a regular expression.
Definition: init.c:107
#define TAILQ_EMPTY(head)
Definition: queue.h:715
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:631
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77
#define MUTT_GROUP
&#39;group&#39; config command
Definition: group.h:32

+ Here is the call graph for this 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 1193 of file init.c.

1194 {
1195  for (int i = 0; i < MENU_MAX; i++)
1196  {
1197  const struct Binding *b = km_get_table(Menus[i].value);
1198  if (!b)
1199  continue;
1200 
1201  for (int j = 0; b[j].name; j++)
1202  if (mutt_str_strcmp(name, b[j].name) == 0)
1203  return true;
1204  }
1205  return false;
1206 }
const char * name
Definition: pgpmicalg.c:45
const char * name
name of the function
Definition: keymap.h:107
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:60
const struct Binding * km_get_table(int menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1218
Mapping between a user key and a function.
Definition: keymap.h:105
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:

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

1223 {
1224  struct Buffer token = { 0 };
1225 
1227 
1228  // is the item defined as:
1229  bool res = cs_get_elem(Config, buf->data) // a variable?
1230  || feature_enabled(buf->data) // a compiled-in feature?
1231  || is_function(buf->data) // a function?
1232  || mutt_command_get(buf->data) // a command?
1233  || myvar_get(buf->data) // a my_ variable?
1234  || mutt_str_getenv(buf->data); // an environment variable?
1235 
1236  if (!MoreArgs(s))
1237  {
1238  mutt_buffer_printf(err, _("%s: too few arguments"), (data ? "ifndef" : "ifdef"));
1239  return MUTT_CMD_WARNING;
1240  }
1242 
1243  /* ifdef KNOWN_SYMBOL or ifndef UNKNOWN_SYMBOL */
1244  if ((res && (data == 0)) || (!res && (data == 1)))
1245  {
1246  enum CommandResult rc = mutt_parse_rc_line(buf->data, &token, err);
1247  if (rc == MUTT_CMD_ERROR)
1248  {
1249  mutt_error(_("Error: %s"), err->data);
1250  FREE(&token.data);
1251  return MUTT_CMD_ERROR;
1252  }
1253  FREE(&token.data);
1254  return rc;
1255  }
1256  return MUTT_CMD_SUCCESS;
1257 }
static bool is_function(const char *name)
Is the argument a neomutt function?
Definition: init.c:1193
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:487
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
WHERE struct ConfigSet * Config
Wrapper around the user&#39;s config settings.
Definition: globals.h:39
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:191
const struct Command * mutt_command_get(const char *s)
Get a Command by its name.
Definition: init.c:2607
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:1049
#define MoreArgs(buf)
Definition: buffer.h:43
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:80
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:42
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
enum CommandResult mutt_parse_rc_line(char *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
Definition: init.c:3216
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77

+ Here is the call graph for this function:

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

1264 {
1265  do
1266  {
1269  add_to_stailq(&Ignore, buf->data);
1270  } while (MoreArgs(s));
1271 
1272  return MUTT_CMD_SUCCESS;
1273 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:722
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:2638
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:77

+ Here is the call graph for this function:

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

1280 {
1281  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1282 
1283  do
1284  {
1286 
1287  if (parse_grouplist(&gl, buf, s, data, err) == -1)
1288  goto bail;
1289 
1291 
1292  if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
1293  goto bail;
1294 
1295  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
1296  goto bail;
1297  } while (MoreArgs(s));
1298 
1300  return MUTT_CMD_SUCCESS;
1301 
1302 bail:
1304  return MUTT_CMD_ERROR;
1305 }
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:275
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:542
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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:157
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:322
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:77

+ Here is the call graph for this function:

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

1314 {
1315  while (MoreArgs(s))
1316  {
1317  struct Mailbox *m = mailbox_new();
1318 
1319  if (data & MUTT_NAMED)
1320  {
1322  if (buf->data && (*buf->data != '\0'))
1323  {
1324  m->name = mutt_str_strdup(buf->data);
1325  }
1326  else
1327  {
1328  mailbox_free(&m);
1329  continue;
1330  }
1331  }
1332 
1334  if (mutt_buffer_is_empty(buf))
1335  {
1336  /* Skip empty tokens. */
1337  mailbox_free(&m);
1338  continue;
1339  }
1340 
1341  mutt_buffer_strcpy(m->pathbuf, buf->data);
1342  /* int rc = */ mx_path_canon2(m, C_Folder);
1343 
1344  bool new_account = false;
1345  struct Account *a = mx_ac_find(m);
1346  if (!a)
1347  {
1348  a = account_new(NULL, NeoMutt->sub);
1349  a->magic = m->magic;
1350  new_account = true;
1351  }
1352 
1353  if (!new_account)
1354  {
1355  struct Mailbox *m_old = mx_mbox_find(a, m->realpath);
1356  if (m_old)
1357  {
1358  if (m_old->flags == MB_HIDDEN)
1359  {
1360  m_old->flags = MB_NORMAL;
1361  mutt_sb_notify_mailbox(m_old, true);
1362  }
1363  mailbox_free(&m);
1364  continue;
1365  }
1366  }
1367 
1368  if (mx_ac_add(a, m) < 0)
1369  {
1370  //error
1371  mailbox_free(&m);
1372  if (new_account)
1373  {
1374  FREE(&a);
1375  }
1376  continue;
1377  }
1378  if (new_account)
1379  {
1381  }
1382 
1383 #ifdef USE_SIDEBAR
1384  mutt_sb_notify_mailbox(m, true);
1385 #endif
1386 #ifdef USE_INOTIFY
1387  mutt_monitor_add(m);
1388 #endif
1389  }
1390  return MUTT_CMD_SUCCESS;
1391 }
int mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add.
Definition: mx.c:1561
int mx_path_canon2(struct Mailbox *m, const char *folder)
XXX canonicalise the path to realpath.
Definition: mx.c:1395
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:95
A group of associated Mailboxes.
Definition: account.h:36
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
XXX.
Definition: mx.c:1498
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:463
struct Account * mx_ac_find(struct Mailbox *m)
XXX.
Definition: mx.c:1475
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:96
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:55
enum MailboxType magic
Mailbox type.
Definition: mailbox.h:116
struct Account * account_new(const char *name, struct ConfigSubset *sub)
Create a new Account.
Definition: account.c:42
int flags
e.g. MB_NORMAL
Definition: mailbox.h:145
#define MB_HIDDEN
Definition: mailbox.h:37
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:314
WHERE char * C_Folder
Config: Base folder for a set of mailboxes.
Definition: globals.h:123
A mailbox.
Definition: mailbox.h:92
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:2638
char * data
Pointer to data.
Definition: buffer.h:35
#define MUTT_NAMED
Definition: init.h:109
struct Buffer * pathbuf
Definition: mailbox.h:94
struct Mailbox * mailbox_new(void)
Create a new Mailbox.
Definition: mailbox.c:41
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
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:83
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:283
#define MB_NORMAL
Definition: mailbox.h:36
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77

+ Here is the call graph for this function:

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

1398 {
1399  struct ListNode *n = NULL;
1400  size_t keylen;
1401 
1403  char *p = strpbrk(buf->data, ": \t");
1404  if (!p || (*p != ':'))
1405  {
1406  mutt_buffer_strcpy(err, _("invalid header field"));
1407  return MUTT_CMD_WARNING;
1408  }
1409  keylen = p - buf->data + 1;
1410 
1411  STAILQ_FOREACH(n, &UserHeader, entries)
1412  {
1413  /* see if there is already a field by this name */
1414  if (mutt_str_strncasecmp(buf->data, n->data, keylen) == 0)
1415  {
1416  break;
1417  }
1418  }
1419 
1420  if (!n)
1421  {
1422  /* not found, allocate memory for a new node and add it to the list */
1423  n = mutt_list_insert_tail(&UserHeader, NULL);
1424  }
1425  else
1426  {
1427  /* found, free the existing data */
1428  FREE(&n->data);
1429  }
1430 
1431  n->data = buf->data;
1432  mutt_buffer_init(buf);
1433 
1434  return MUTT_CMD_SUCCESS;
1435 }
#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:81
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:314
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:2638
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:80
char * data
Pointer to data.
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
Success: Command worked.
Definition: mutt_commands.h:37
char * data
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:61
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:

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

1443 {
1444  char path[PATH_MAX];
1445 
1446  do
1447  {
1449  mutt_str_strfcpy(path, buf->data, sizeof(path));
1450  mutt_expand_path(path, sizeof(path));
1451  add_to_stailq((struct ListHead *) data, path);
1452  } while (MoreArgs(s));
1453 
1454  return MUTT_CMD_SUCCESS;
1455 }
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:128
#define MoreArgs(buf)
Definition: buffer.h:43
#define PATH_MAX
Definition: mutt.h:51
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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
char * data
Definition: list.h:35
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:77

+ Here is the call graph for this function:

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

1464 {
1465  char path[PATH_MAX];
1466 
1467  do
1468  {
1470  /* Check for deletion of entire list */
1471  if (mutt_str_strcmp(buf->data, "*") == 0)
1472  {
1473  mutt_list_free((struct ListHead *) data);
1474  break;
1475  }
1476  mutt_str_strfcpy(path, buf->data, sizeof(path));
1477  mutt_expand_path(path, sizeof(path));
1478  remove_from_stailq((struct ListHead *) data, path);
1479  } while (MoreArgs(s));
1480 
1481  return MUTT_CMD_SUCCESS;
1482 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:722
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:128
#define MoreArgs(buf)
Definition: buffer.h:43
#define PATH_MAX
Definition: mutt.h:51
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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
char * data
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:77

+ Here is the call graph for this function:

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

1492 {
1493  /* The order must match `enum MuttSetCommand` */
1494  static const char *set_commands[] = { "set", "toggle", "unset", "reset" };
1495 
1496  int rc = 0;
1497 
1498  while (MoreArgs(s))
1499  {
1500  bool prefix = false;
1501  bool query = false;
1502  bool inv = (data == MUTT_SET_INV);
1503  bool reset = (data == MUTT_SET_RESET);
1504  bool unset = (data == MUTT_SET_UNSET);
1505 
1506  if (*s->dptr == '?')
1507  {
1508  prefix = true;
1509  query = true;
1510  s->dptr++;
1511  }
1512  else if (mutt_str_startswith(s->dptr, "no", CASE_MATCH))
1513  {
1514  prefix = true;
1515  unset = !unset;
1516  s->dptr += 2;
1517  }
1518  else if (mutt_str_startswith(s->dptr, "inv", CASE_MATCH))
1519  {
1520  prefix = true;
1521  inv = !inv;
1522  s->dptr += 3;
1523  }
1524  else if (*s->dptr == '&')
1525  {
1526  prefix = true;
1527  reset = true;
1528  s->dptr++;
1529  }
1530 
1531  if (prefix && (data != MUTT_SET_SET))
1532  {
1533  mutt_buffer_printf(err, "ERR22 can't use 'inv', 'no', '&' or '?' with the '%s' command",
1534  set_commands[data]);
1535  return MUTT_CMD_WARNING;
1536  }
1537 
1538  /* get the variable name */
1540 
1541  bool bq = false;
1542  bool equals = false;
1543 
1544  struct HashElem *he = NULL;
1545  bool my = mutt_str_startswith(buf->data, "my_", CASE_MATCH);
1546  if (!my)
1547  {
1548  he = cs_get_elem(Config, buf->data);
1549  if (!he)
1550  {
1551  if (reset && (mutt_str_strcmp(buf->data, "all") == 0))
1552  {
1553  struct HashElem **list = get_elem_list(Config);
1554  if (!list)
1555  return MUTT_CMD_ERROR;
1556 
1557  for (size_t i = 0; list[i]; i++)
1558  cs_he_reset(Config, list[i], NULL);
1559 
1560  FREE(&list);
1561  break;
1562  }
1563  else
1564  {
1565  mutt_buffer_printf(err, "ERR01 unknown variable: %s", buf->data);
1566  return MUTT_CMD_ERROR;
1567  }
1568  }
1569 
1570  bq = ((DTYPE(he->type) == DT_BOOL) || (DTYPE(he->type) == DT_QUAD));
1571  }
1572 
1573  if (*s->dptr == '?')
1574  {
1575  if (prefix)
1576  {
1577  mutt_buffer_printf(err,
1578  "ERR02 can't use a prefix when querying a variable");
1579  return MUTT_CMD_WARNING;
1580  }
1581 
1582  if (reset || unset || inv)
1583  {
1584  mutt_buffer_printf(err, "ERR03 can't query a variable with the '%s' command",
1585  set_commands[data]);
1586  return MUTT_CMD_WARNING;
1587  }
1588 
1589  query = true;
1590  s->dptr++;
1591  }
1592  else if (*s->dptr == '=')
1593  {
1594  if (prefix)
1595  {
1596  mutt_buffer_printf(err,
1597  "ERR04 can't use prefix when setting a variable");
1598  return MUTT_CMD_WARNING;
1599  }
1600 
1601  if (reset || unset || inv)
1602  {
1603  mutt_buffer_printf(err, "ERR05 can't set a variable with the '%s' command",
1604  set_commands[data]);
1605  return MUTT_CMD_WARNING;
1606  }
1607 
1608  equals = true;
1609  s->dptr++;
1610  }
1611 
1612  if (!bq && (inv || (unset && prefix)))
1613  {
1614  if (data == MUTT_SET_SET)
1615  {
1616  mutt_buffer_printf(err, "ERR06 prefixes 'no' and 'inv' may only be "
1617  "used with bool/quad variables");
1618  }
1619  else
1620  {
1621  mutt_buffer_printf(err, "ERR07 command '%s' can only be used with bool/quad variables",
1622  set_commands[data]);
1623  }
1624  return MUTT_CMD_WARNING;
1625  }
1626 
1627  if (reset)
1628  {
1629  // mutt_buffer_printf(err, "ACT24 reset variable %s", buf->data);
1630  if (he)
1631  {
1632  rc = cs_he_reset(Config, he, err);
1633  if (CSR_RESULT(rc) != CSR_SUCCESS)
1634  return MUTT_CMD_ERROR;
1635  }
1636  else
1637  {
1638  myvar_del(buf->data);
1639  }
1640  continue;
1641  }
1642 
1643  if ((data == MUTT_SET_SET) && !inv && !unset)
1644  {
1645  if (query)
1646  {
1647  // mutt_buffer_printf(err, "ACT08 query variable %s", buf->data);
1648  if (he)
1649  {
1650  mutt_buffer_addstr(err, buf->data);
1651  mutt_buffer_addch(err, '=');
1652  mutt_buffer_reset(buf);
1653  rc = cs_he_string_get(Config, he, buf);
1654  if (CSR_RESULT(rc) != CSR_SUCCESS)
1655  {
1656  mutt_buffer_addstr(err, buf->data);
1657  return MUTT_CMD_ERROR;
1658  }
1659  pretty_var(buf->data, err);
1660  }
1661  else
1662  {
1663  const char *val = myvar_get(buf->data);
1664  if (val)
1665  {
1666  mutt_buffer_addstr(err, buf->data);
1667  mutt_buffer_addch(err, '=');
1668  pretty_var(val, err);
1669  }
1670  else
1671  {
1672  mutt_buffer_printf(err, _("%s: unknown variable"), buf->data);
1673  return MUTT_CMD_ERROR;
1674  }
1675  }
1676  break;
1677  }
1678  else if (equals)
1679  {
1680  // mutt_buffer_printf(err, "ACT11 set variable %s to ", buf->data);
1681  const char *name = NULL;
1682  if (my)
1683  {
1684  name = mutt_str_strdup(buf->data);
1685  }
1687  if (my)
1688  {
1689  myvar_set(name, buf->data);
1690  FREE(&name);
1691  }
1692  else
1693  {
1694  if (IS_PATH(he))
1695  {
1696  mutt_expand_path(buf->data, buf->dsize);
1697  char scratch[PATH_MAX];
1698  mutt_str_strfcpy(scratch, buf->data, sizeof(scratch));
1699  size_t scratchlen = mutt_str_strlen(scratch);
1700  if (!(he->type & DT_MAILBOX) && (scratchlen != 0))
1701  {
1702  if ((scratch[scratchlen - 1] != '|') && /* not a command */
1703  (url_check_scheme(scratch) == U_UNKNOWN)) /* probably a local file */
1704  {
1705  struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
1706  if (mutt_path_to_absolute(scratch, np ? NONULL(np->data) : "./"))
1707  {
1708  mutt_buffer_reset(buf);
1709  mutt_buffer_addstr(buf, scratch);
1710  }
1711  else
1712  {
1713  mutt_error(_("Error: Can't build path of '%s'"), scratch);
1714  }
1715  }
1716  }
1717  }
1718  else if (IS_COMMAND(he))
1719  {
1720  char scratch[PATH_MAX];
1721  mutt_str_strfcpy(scratch, buf->data, sizeof(scratch));
1722 
1723  if (mutt_str_strcmp(buf->data, "builtin") != 0)
1724  {
1725  mutt_expand_path(scratch, sizeof(scratch));
1726  }
1727  mutt_buffer_reset(buf);
1728  mutt_buffer_addstr(buf, scratch);
1729  }
1730 
1731  rc = cs_he_string_set(Config, he, buf->data, err);
1732  if (CSR_RESULT(rc) != CSR_SUCCESS)
1733  return MUTT_CMD_ERROR;
1734  }
1735  continue;
1736  }
1737  else
1738  {
1739  if (bq)
1740  {
1741  // mutt_buffer_printf(err, "ACT23 set variable %s to 'yes'", buf->data);
1742  rc = cs_he_native_set(Config, he, true, err);
1743  if (CSR_RESULT(rc) != CSR_SUCCESS)
1744  return MUTT_CMD_ERROR;
1745  continue;
1746  }
1747  else
1748  {
1749  // mutt_buffer_printf(err, "ACT10 query variable %s", buf->data);
1750  if (he)
1751  {
1752  mutt_buffer_addstr(err, buf->data);
1753  mutt_buffer_addch(err, '=');
1754  mutt_buffer_reset(buf);
1755  rc = cs_he_string_get(Config, he, buf);
1756  if (CSR_RESULT(rc) != CSR_SUCCESS)
1757  {
1758  mutt_buffer_addstr(err, buf->data);
1759  return MUTT_CMD_ERROR;
1760  }
1761  pretty_var(buf->data, err);
1762  }
1763  else
1764  {
1765  const char *val = myvar_get(buf->data);
1766  if (val)
1767  {
1768  mutt_buffer_addstr(err, buf->data);
1769  mutt_buffer_addch(err, '=');
1770  pretty_var(val, err);
1771  }
1772  else
1773  {
1774  mutt_buffer_printf(err, _("%s: unknown variable"), buf->data);
1775  return MUTT_CMD_ERROR;
1776  }
1777  }
1778  break;
1779  }
1780  }
1781  }
1782 
1783  if (my)
1784  {
1785  myvar_del(buf->data);
1786  }
1787  else if (bq)
1788  {
1789  if (inv)
1790  {
1791  // mutt_buffer_printf(err, "ACT25 TOGGLE bool/quad variable %s", buf->data);
1792  if (DTYPE(he->type) == DT_BOOL)
1793  bool_he_toggle(Config, he, err);
1794  else
1795  quad_he_toggle(Config, he, err);
1796  }
1797  else
1798  {
1799  // mutt_buffer_printf(err, "ACT26 UNSET bool/quad variable %s", buf->data);
1800  rc = cs_he_native_set(Config, he, false, err);
1801  if (CSR_RESULT(rc) != CSR_SUCCESS)
1802  return MUTT_CMD_ERROR;
1803  }
1804  continue;
1805  }
1806  else
1807  {
1808  rc = cs_he_string_set(Config, he, NULL, err);
1809  if (CSR_RESULT(rc) != CSR_SUCCESS)
1810  return MUTT_CMD_ERROR;
1811  }
1812  }
1813 
1814  return MUTT_CMD_SUCCESS;
1815 }
#define NONULL(x)
Definition: string2.h:37
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
#define IS_PATH(x)
Definition: types.h:55
#define CSR_RESULT(x)
Definition: set.h:62
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
static struct ListHead MuttrcStack
Definition: init.c:79
Url wasn&#39;t recognised.
Definition: url.h:34
#define _(a)
Definition: message.h:28
WHERE struct ConfigSet * Config
Wrapper around the user&#39;s config settings.
Definition: globals.h:39
Match case when comparing strings.
Definition: string2.h:67
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
struct HashElem ** get_elem_list(struct ConfigSet *cs)
Create a sorted list of all config items.
Definition: dump.c:118
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:191
int bool_he_toggle(struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Toggle the value of a bool.
Definition: bool.c:209
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:36
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
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:128
#define MoreArgs(buf)
Definition: buffer.h:43
const char * name
Definition: pgpmicalg.c:45
int cs_he_reset(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.c:373
default is to invert all vars
Definition: init.h:103
int cs_he_native_set(const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err)
Natively set the value of a HashElem config item.
Definition: set.c:719
default is to set all vars
Definition: init.h:102
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:214
void myvar_del(const char *var)
Unset the value of a "my_" variable.
Definition: myvar.c:83
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:256
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
void myvar_set(const char *var, const char *val)
Set the value of a "my_" variable.
Definition: myvar.c:60
#define PATH_MAX
Definition: mutt.h:51
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
#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:433
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
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:271
default is to reset all vars to default
Definition: init.h:105
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
Definition: myvar.c:42
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 cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: set.c:648
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:104
Success: Command worked.
Definition: mutt_commands.h:37
char * data
Definition: list.h:35
Warning: Help given to the user.
Definition: mutt_commands.h:36
int quad_he_toggle(struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Toggle the value of a quad.
Definition: quad.c:225
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define mutt_error(...)
Definition: logging.h:84
#define MUTT_TOKEN_BACKTICK_VARS
Expand variables within backticks.
Definition: mutt.h:85
int type
Definition: hash.h:44
#define FREE(x)
Definition: memory.h:40
The item stored in a Hash Table.
Definition: hash.h:42
#define MUTT_TOKEN_EQUAL
Treat &#39;=&#39; as a special.
Definition: mutt.h:78
#define IS_COMMAND(x)
Definition: types.h:56
A List node for strings.
Definition: list.h:33
#define STAILQ_FIRST(head)
Definition: queue.h:348
#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
int cs_he_string_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.c:574
#define MUTT_TOKEN_QUESTION
Treat &#39;?&#39; as a special.
Definition: mutt.h:87

+ Here is the call graph for this function:

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

1822 {
1823  char **envp = mutt_envlist_getlist();
1824 
1825  bool query = false;
1826  bool unset = (data == MUTT_SET_UNSET);
1827 
1828  if (!MoreArgs(s))
1829  {
1830  mutt_buffer_printf(err, _("%s: too few arguments"), "setenv");
1831  return MUTT_CMD_WARNING;
1832  }
1833 
1834  if (*s->dptr == '?')
1835  {
1836  query = true;
1837  s->dptr++;
1838  }
1839 
1840  /* get variable name */
1842 
1843  if (query)
1844  {
1845  bool found = false;
1846  while (envp && *envp)
1847  {
1848  /* This will display all matches for "^QUERY" */
1849  if (mutt_str_startswith(*envp, buf->data, CASE_MATCH))
1850  {
1851  if (!found)
1852  {
1853  mutt_endwin();
1854  found = true;
1855  }
1856  puts(*envp);
1857  }
1858  envp++;
1859  }
1860 
1861  if (found)
1862  {
1864  return MUTT_CMD_SUCCESS;
1865  }
1866 
1867  mutt_buffer_printf(err, _("%s is unset"), buf->data);
1868  return MUTT_CMD_WARNING;
1869  }
1870 
1871  if (unset)
1872  {
1873  if (mutt_envlist_unset(buf->data))
1874  return MUTT_CMD_SUCCESS;
1875  return MUTT_CMD_ERROR;
1876  }
1877 
1878  /* set variable */
1879 
1880  if (*s->dptr == '=')
1881  {
1882  s->dptr++;
1883  SKIPWS(s->dptr);
1884  }
1885 
1886  if (!MoreArgs(s))
1887  {
1888  mutt_buffer_printf(err, _("%s: too few arguments"), "setenv");
1889  return MUTT_CMD_WARNING;
1890  }
1891 
1892  char *name = mutt_str_strdup(buf->data);
1894  mutt_envlist_set(name, buf->data, true);
1895  FREE(&name);
1896 
1897  return MUTT_CMD_SUCCESS;
1898 }
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:191
#define MoreArgs(buf)
Definition: buffer.h:43
const char * name
Definition: pgpmicalg.c:45
#define SKIPWS(ch)
Definition: string2.h:47
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:499
bool mutt_envlist_unset(const char *name)
Unset an environment variable.
Definition: envlist.c:131
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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:544
default is to unset all vars
Definition: init.h:104
Success: Command worked.
Definition: mutt_commands.h:37
char * data
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
#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:84
#define MUTT_TOKEN_EQUAL
Treat &#39;=&#39; as a special.
Definition: mutt.h:78
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77
char ** mutt_envlist_getlist(void)
Get the private environment.
Definition: envlist.c:167

+ Here is the call graph for this function:

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

1905 {
1906  char path[PATH_MAX];
1907 
1908  do
1909  {
1910  if (mutt_extract_token(buf, s, MUTT_TOKEN_NO_FLAGS) != 0)
1911  {
1912  mutt_buffer_printf(err, _("source: error at %s"), s->dptr);
1913  return MUTT_CMD_ERROR;
1914  }
1915  mutt_str_strfcpy(path, buf->data, sizeof(path));
1916  mutt_expand_path(path, sizeof(path));
1917 
1918  if (source_rc(path, err) < 0)
1919  {
1920  mutt_buffer_printf(err, _("source: file %s could not be sourced"), path);
1921  return MUTT_CMD_ERROR;
1922  }
1923 
1924  } while (MoreArgs(s));
1925 
1926  return MUTT_CMD_SUCCESS;
1927 }
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:748
#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:191
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:128
#define MoreArgs(buf)
Definition: buffer.h:43
#define PATH_MAX
Definition: mutt.h:51
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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:77

+ Here is the call graph for this function:

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

1934 {
1935  struct Buffer templ;
1936 
1937  mutt_buffer_init(&templ);
1938 
1939  /* Insist on at least one parameter */
1940  if (!MoreArgs(s))
1941  {
1942  if (data == MUTT_SPAM)
1943  mutt_buffer_strcpy(err, _("spam: no matching pattern"));
1944  else
1945  mutt_buffer_strcpy(err, _("nospam: no matching pattern"));
1946  return MUTT_CMD_ERROR;
1947  }
1948 
1949  /* Extract the first token, a regex */
1951 
1952  /* data should be either MUTT_SPAM or MUTT_NOSPAM. MUTT_SPAM is for spam commands. */
1953  if (data == MUTT_SPAM)
1954  {
1955  /* If there's a second parameter, it's a template for the spam tag. */
1956  if (MoreArgs(s))
1957  {
1959 
1960  /* Add to the spam list. */
1961  if (mutt_replacelist_add(&SpamList, buf->data, templ.data, err) != 0)
1962  {
1963  FREE(&templ.data);
1964  return MUTT_CMD_ERROR;
1965  }
1966  FREE(&templ.data);
1967  }
1968  /* If not, try to remove from the nospam list. */
1969  else
1970  {
1972  }
1973 
1974  return MUTT_CMD_SUCCESS;
1975  }
1976  /* MUTT_NOSPAM is for nospam commands. */
1977  else if (data == MUTT_NOSPAM)
1978  {
1979  /* nospam only ever has one parameter. */
1980 
1981  /* "*" is a special case. */
1982  if (mutt_str_strcmp(buf->data, "*") == 0)
1983  {
1986  return MUTT_CMD_SUCCESS;
1987  }
1988 
1989  /* If it's on the spam list, just remove it. */
1990  if (mutt_replacelist_remove(&SpamList, buf->data) != 0)
1991  return MUTT_CMD_SUCCESS;
1992 
1993  /* Otherwise, add it to the nospam list. */
1994  if (mutt_regexlist_add(&NoSpamList, buf->data, REG_ICASE, err) != 0)
1995  return MUTT_CMD_ERROR;
1996 
1997  return MUTT_CMD_SUCCESS;
1998  }
1999 
2000  /* This should not happen. */
2001  mutt_buffer_strcpy(err, "This is no good at all.");
2002  return MUTT_CMD_ERROR;
2003 }
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:120
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:119
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
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:314
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
char * data
Pointer to data.
Definition: buffer.h:35
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:61
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:77

+ Here is the call graph for this function:

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

2012 {
2013  do
2014  {
2016  add_to_stailq((struct ListHead *) data, buf->data);
2017  } while (MoreArgs(s));
2018 
2019  return MUTT_CMD_SUCCESS;
2020 }
#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:2638
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:77

+ Here is the call graph for this function:

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

2027 {
2028  enum CommandResult rc;
2029 
2030  rc = parse_replace_list(buf, s, data, err);
2031  if (rc == MUTT_CMD_SUCCESS)
2033  return rc;
2034 }
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:572
static void clear_subject_mods(void)
Clear out all modified email subjects.
Definition: init.c:211
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:

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

2041 {
2042  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
2043 
2044  do
2045  {
2047 
2048  if (parse_grouplist(&gl, buf, s, data, err) == -1)
2049  goto bail;
2050 
2053 
2054  if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
2055  goto bail;
2056  if (mutt_regexlist_add(&SubscribedLists, buf->data, REG_ICASE, err) != 0)
2057  goto bail;
2058  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
2059  goto bail;
2060  } while (MoreArgs(s));
2061 
2063  return MUTT_CMD_SUCCESS;
2064 
2065 bail:
2067  return MUTT_CMD_ERROR;
2068 }
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:275
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:542
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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:157
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:322
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:77
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:

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

2080 {
2081  if (!buf || !s || !err)
2082  return MUTT_CMD_ERROR;
2083 
2084  mutt_buffer_reset(err);
2085 
2086  if (MoreArgs(s))
2087  {
2089 
2090  if (MoreArgs(s))
2091  {
2092  mutt_buffer_printf(err, _("%s: too many arguments"), "subscribe-to");
2093  return MUTT_CMD_WARNING;
2094  }
2095 
2096  if (buf->data && (*buf->data != '\0'))
2097  {
2098  /* Expand and subscribe */
2099  if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), true) != 0)
2100  {
2101  mutt_buffer_printf(err, _("Could not subscribe to %s"), buf->data);
2102  return MUTT_CMD_ERROR;
2103  }
2104  else
2105  {
2106  mutt_message(_("Subscribed to %s"), buf->data);
2107  return MUTT_CMD_SUCCESS;
2108  }
2109  }
2110  else
2111  {
2112  mutt_debug(LL_DEBUG1, "Corrupted buffer");
2113  return MUTT_CMD_ERROR;
2114  }
2115  }
2116 
2117  mutt_buffer_addstr(err, _("No folder specified"));
2118  return MUTT_CMD_WARNING;
2119 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
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:191
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:128
#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:256
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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:56
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:77
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1383

+ Here is the call graph for this function:

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

2127 {
2128  if (!buf || !s)
2129  return MUTT_CMD_ERROR;
2130 
2131  char *tmp = NULL;
2132 
2133  while (MoreArgs(s))
2134  {
2135  char *tag = NULL, *format = NULL;
2136 
2138  if (buf->data && (*buf->data != '\0'))
2139  tag = mutt_str_strdup(buf->data);
2140  else
2141  continue;
2142 
2144  format = mutt_str_strdup(buf->data);
2145 
2146  /* avoid duplicates */
2147  tmp = mutt_hash_find(TagFormats, format);
2148  if (tmp)
2149  {
2150  mutt_debug(LL_DEBUG3, "tag format '%s' already registered as '%s'\n", format, tmp);
2151  FREE(&tag);
2152  FREE(&format);
2153  continue;
2154  }
2155 
2156  mutt_hash_insert(TagFormats, format, tag);
2157  }
2158  return MUTT_CMD_SUCCESS;
2159 }
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:379
WHERE struct Hash * TagFormats
Hash table of tag-formats (tag -> format string)
Definition: globals.h:59
#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:2638
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:352
Log at debug level 3.
Definition: logging.h:58
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77

+ Here is the call graph for this function:

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

2166 {
2167  if (!buf || !s)
2168  return MUTT_CMD_ERROR;
2169 
2170  char *tmp = NULL;
2171 
2172  while (MoreArgs(s))
2173  {
2174  char *tag = NULL, *transform = NULL;
2175 
2177  if (buf->data && (*buf->data != '\0'))
2178  tag = mutt_str_strdup(buf->data);
2179  else
2180  continue;
2181 
2183  transform = mutt_str_strdup(buf->data);
2184 
2185  /* avoid duplicates */
2186  tmp = mutt_hash_find(TagTransforms, tag);
2187  if (tmp)
2188  {
2189  mutt_debug(LL_DEBUG3, "tag transform '%s' already registered as '%s'\n", tag, tmp);
2190  FREE(&tag);
2191  FREE(&transform);
2192  continue;
2193  }
2194 
2195  mutt_hash_insert(TagTransforms, tag, transform);
2196  }
2197  return MUTT_CMD_SUCCESS;
2198 }
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:379
#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:2638
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:352
Log at debug level 3.
Definition: logging.h:58
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77

+ Here is the call graph for this function:

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

2205 {
2206  struct Alias *a = NULL;
2207 
2208  do
2209  {
2211 
2212  if (mutt_str_strcmp("*", buf->data) == 0)
2213  {
2214  if (CurrentMenu == MENU_ALIAS)
2215  {
2216  TAILQ_FOREACH(a, &Aliases, entries)
2217  {
2218  a->del = true;
2219  }
2221  }
2222  else
2223  mutt_aliaslist_free(&Aliases);
2224  break;
2225  }
2226  else
2227  {
2228  TAILQ_FOREACH(a, &Aliases, entries)
2229  {
2230  if (mutt_str_strcasecmp(buf->data, a->name) == 0)
2231  {
2232  if (CurrentMenu == MENU_ALIAS)
2233  {
2234  a->del = true;
2236  }
2237  else
2238  {
2239  TAILQ_REMOVE(&Aliases, a, entries);
2240  mutt_alias_free(&a);
2241  }
2242  break;
2243  }
2244  }
2245  }
2246  } while (MoreArgs(s));
2247  return MUTT_CMD_SUCCESS;
2248 }
A shortcut for an email address.
Definition: alias.h:37
char * name
Definition: alias.h:39
void mutt_aliaslist_free(struct AliasList *a_list)
Free a List of Aliases.
Definition: alias.c:742
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
#define MoreArgs(buf)
Definition: buffer.h:43
bool del
Definition: alias.h:42
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:821
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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
void mutt_alias_free(struct Alias **p)
Free an Alias.
Definition: alias.c:727
WHERE int CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:86
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:77

+ Here is the call graph for this function:

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

2255 {
2256  alternates_clean();
2257  do
2258  {
2260  mutt_regexlist_remove(&Alternates, buf->data);
2261 
2262  if ((mutt_str_strcmp(buf->data, "*") != 0) &&
2263  (mutt_regexlist_add(&UnAlternates, buf->data, REG_ICASE, err) != 0))
2264  {
2265  return MUTT_CMD_ERROR;
2266  }
2267 
2268  } while (MoreArgs(s));
2269 
2270  return MUTT_CMD_SUCCESS;
2271 }
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:2638
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:77

+ Here is the call graph for this function:

void mutt_free_attachmatch ( struct AttachMatch **  am)

Free an AttachMatch - Implements list_free_t.

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

Definition at line 2279 of file init.c.

2280 {
2281  if (!am || !*am)
2282  return;
2283 
2284  regfree(&(*am)->minor_regex);
2285  FREE(&(*am)->major);
2286  FREE(am);
2287 }
#define FREE(x)
Definition: memory.h:40

+ Here is the caller graph for this function:

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

2294 {
2295  char op;
2296  char *p = NULL;
2297  struct ListHead *head = NULL;
2298 
2300  if (!buf->data || (*buf->data == '\0'))
2301  {
2302  mutt_buffer_strcpy(err, _("unattachments: no disposition"));
2303  return MUTT_CMD_WARNING;
2304  }
2305 
2306  p = buf->data;
2307  op = *p++;
2308 
2309  if (op == '*')
2310  {
2316  return 0;
2317  }
2318 
2319  if ((op != '+') && (op != '-'))
2320  {
2321  op = '+';
2322  p--;
2323  }
2324  if (mutt_str_startswith("attachment", p, CASE_IGNORE))
2325  {
2326  if (op == '+')
2327  head = &AttachAllow;
2328  else
2329  head = &AttachExclude;
2330  }
2331  else if (mutt_str_startswith("inline", p, CASE_IGNORE))
2332  {
2333  if (op == '+')
2334  head = &InlineAllow;
2335  else
2336  head = &InlineExclude;
2337  }
2338  else
2339  {
2340  mutt_buffer_strcpy(err, _("unattachments: invalid disposition"));
2341  return MUTT_CMD_ERROR;
2342  }
2343 
2344  return parse_unattach_list(buf, s, head, err);
2345 }
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:612
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
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:151
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:314
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
char * data
Pointer to data.
Definition: buffer.h:35
Ignore case when comparing strings.
Definition: string2.h:68
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
Warning: Help given to the user.
Definition: mutt_commands.h:36
void mutt_free_attachmatch(struct AttachMatch **am)
Free an AttachMatch - Implements list_free_t.
Definition: init.c:2279
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:77
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:

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

2352 {
2353  do
2354  {
2356 
2357  /* don't add "*" to the unignore list */
2358  if (strcmp(buf->data, "*") != 0)
2359  add_to_stailq(&UnIgnore, buf->data);
2360 
2361  remove_from_stailq(&Ignore, buf->data);
2362  } while (MoreArgs(s));
2363 
2364  return MUTT_CMD_SUCCESS;
2365 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:722
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:2638
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:77

+ Here is the call graph for this function:

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

2372 {
2374  do
2375  {
2379 
2380  if ((mutt_str_strcmp(buf->data, "*") != 0) &&
2381  (mutt_regexlist_add(&UnMailLists, buf->data, REG_ICASE, err) != 0))
2382  {
2383  return MUTT_CMD_ERROR;
2384  }
2385  } while (MoreArgs(s));
2386 
2387  return MUTT_CMD_SUCCESS;
2388 }
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:2638
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_hdata a hash table
Definition: hash.c:472
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:77

+ Here is the call graph for this function:

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

2397 {
2398  bool tmp_valid = false;
2399  bool clear_all = false;
2400 
2401  while (!clear_all && MoreArgs(s))
2402  {
2404 
2405  if (mutt_str_strcmp(buf->data, "*") == 0)
2406  {
2407  clear_all = true;
2408  tmp_valid = false;
2409  }
2410  else
2411  {
2413  tmp_valid = true;
2414  }
2415 
2416  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
2417  struct MailboxNode *np = NULL;
2418  struct MailboxNode *nptmp = NULL;
2419  STAILQ_FOREACH_SAFE(np, &ml, entries, nptmp)
2420  {
2421  /* Decide whether to delete all normal mailboxes or all virtual */
2422  bool virt = ((np->mailbox->magic == MUTT_NOTMUCH) && (data & MUTT_VIRTUAL));
2423  bool norm = ((np->mailbox->magic != MUTT_NOTMUCH) && !(data & MUTT_VIRTUAL));
2424  bool clear_this = clear_all && (virt || norm);
2425 
2426  /* Compare against path or desc? Ensure 'buf' is valid */
2427  if (!clear_this && tmp_valid)
2428  {
2429  clear_this =
2430  (mutt_str_strcasecmp(mutt_b2s(buf), mutt_b2s(np->mailbox->pathbuf)) == 0) ||
2431  (mutt_str_strcasecmp(mutt_b2s(buf), np->mailbox->name) == 0);
2432  }
2433 
2434  if (clear_this)
2435  {
2436 #ifdef USE_SIDEBAR
2437  mutt_sb_notify_mailbox(np->mailbox, false);
2438 #endif
2439 #ifdef USE_INOTIFY
2441 #endif
2442  if (Context && (Context->mailbox == np->mailbox))
2443  {
2444  np->mailbox->flags |= MB_HIDDEN;
2445  }
2446  else
2447  {
2449  }
2450  }
2451  }
2453  }
2454  return MUTT_CMD_SUCCESS;
2455 }
The "current" mailbox.
Definition: context.h:36
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:134
int mutt_monitor_remove(struct Mailbox *m)
Remove a watch for a mailbox.
Definition: monitor.c:508
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:96
struct Mailbox * mailbox
Definition: context.h:50
enum MailboxType magic
Mailbox type.
Definition: mailbox.h:116
struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType magic)
Get a List of all Mailboxes.
Definition: neomutt.c:156
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:360
int flags
e.g. MB_NORMAL
Definition: mailbox.h:145
#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:2638
char * data
Pointer to data.
Definition: buffer.h:35
#define MUTT_VIRTUAL
Definition: init.h:110
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:53
struct Buffer * pathbuf
Definition: mailbox.h:94
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:323
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:142
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition: account.c:83
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:156
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:77
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:158

+ Here is the call graph for this function:

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

2462 {
2463  struct ListNode *np = NULL, *tmp = NULL;
2464  size_t l;
2465 
2466  do
2467  {
2469  if (mutt_str_strcmp("*", buf->data) == 0)
2470  {
2471  mutt_list_free(&UserHeader);
2472  continue;
2473  }
2474 
2475  l = mutt_str_strlen(buf->data);
2476  if (buf->data[l - 1] == ':')
2477  l--;
2478 
2479  STAILQ_FOREACH_SAFE(np, &UserHeader, entries, tmp)
2480  {
2481  if ((mutt_str_strncasecmp(buf->data, np->data, l) == 0) && (np->data[l] == ':'))
2482  {
2483  STAILQ_REMOVE(&UserHeader, np, ListNode, entries);
2484  FREE(&np->data);
2485  FREE(&np);
2486  }
2487  }
2488  } while (MoreArgs(s));
2489  return MUTT_CMD_SUCCESS;
2490 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:400
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:360
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:2638
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * data
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:77

+ Here is the call graph for this function:

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

2499 {
2500  do
2501  {
2503  /* Check for deletion of entire list */
2504  if (mutt_str_strcmp(buf->data, "*") == 0)
2505  {
2506  mutt_list_free((struct ListHead *) data);
2507  break;
2508  }
2509  remove_from_stailq((struct ListHead *) data, buf->data);
2510  } while (MoreArgs(s));
2511 
2512  return MUTT_CMD_SUCCESS;
2513 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:722
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:2638
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * data
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:77

+ Here is the call graph for this function:

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

2520 {
2521  enum CommandResult rc;
2522 
2523  rc = parse_unreplace_list(buf, s, data, err);
2524  if (rc == MUTT_CMD_SUCCESS)
2526  return rc;
2527 }
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:211
Success: Command worked.
Definition: mutt_commands.h:37
char * data
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:670

+ Here is the call graph for this function:

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

2534 {
2536  do
2537  {
2540 
2541  if ((mutt_str_strcmp(buf->data, "*") != 0) &&
2542  (mutt_regexlist_add(&UnSubscribedLists, buf->data, REG_ICASE, err) != 0))
2543  {
2544  return MUTT_CMD_ERROR;
2545  }
2546  } while (MoreArgs(s));
2547 
2548  return MUTT_CMD_SUCCESS;
2549 }
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:2638
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_hdata a hash table
Definition: hash.c:472
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:77
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:

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

2561 {
2562  if (!buf || !s || !err)
2563  return MUTT_CMD_ERROR;
2564 
2565  if (MoreArgs(s))
2566  {
2568 
2569  if (MoreArgs(s))
2570  {
2571  mutt_buffer_printf(err, _("%s: too many arguments"), "unsubscribe-from");
2572  return MUTT_CMD_WARNING;
2573  }
2574 
2575  if (buf->data && (*buf->data != '\0'))
2576  {
2577  /* Expand and subscribe */
2578  if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), false) != 0)
2579  {
2580  mutt_buffer_printf(err, _("Could not unsubscribe from %s"), buf->data);
2581  return MUTT_CMD_ERROR;
2582  }
2583  else
2584  {
2585  mutt_message(_("Unsubscribed from %s"), buf->data);
2586  return MUTT_CMD_SUCCESS;
2587  }
2588  }
2589  else
2590  {
2591  mutt_debug(LL_DEBUG1, "Corrupted buffer");
2592  return MUTT_CMD_ERROR;
2593  }
2594  }
2595 
2596  mutt_buffer_addstr(err, _("No folder specified"));
2597  return MUTT_CMD_WARNING;
2598 }
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:191
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:128
#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:256
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2638
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:56
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:77
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1383

+ Here is the call graph for this function:

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

2608 {
2609  for (int i = 0; Commands[i].name; i++)
2610  if (mutt_str_strcmp(s, Commands[i].name) == 0)
2611  return &Commands[i];
2612  return NULL;
2613 }
const char * name
Name of the command.
Definition: mutt_commands.h:56
const struct Command Commands[]
Definition: init.h:4972
const char * name
Definition: pgpmicalg.c:45
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:

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

2639 {
2640  if (!dest || !tok)
2641  return -1;
2642 
2643  char ch;
2644  char qc = '\0'; /* quote char */
2645  char *pc = NULL;
2646 
2647  mutt_buffer_reset(dest);
2648 
2649  SKIPWS(tok->dptr);
2650  while ((ch = *tok->dptr))
2651  {
2652  if (qc == '\0')
2653  {
2654  if ((IS_SPACE(ch) && !(flags & MUTT_TOKEN_SPACE)) ||
2655  ((ch == '#') && !(flags & MUTT_TOKEN_COMMENT)) ||
2656  ((ch == '=') && (flags & MUTT_TOKEN_EQUAL)) ||
2657  ((ch == '?') && (flags & MUTT_TOKEN_QUESTION)) ||
2658  ((ch == ';') && !(flags & MUTT_TOKEN_SEMICOLON)) ||
2659  ((flags & MUTT_TOKEN_PATTERN) && strchr("~%=!|", ch)))
2660  {
2661  break;
2662  }
2663  }
2664 
2665  tok->dptr++;
2666 
2667  if (ch == qc)
2668  qc = 0; /* end of quote */
2669  else if (!qc && ((ch == '\'') || (ch == '"')) && !(flags & MUTT_TOKEN_QUOTE))
2670  qc = ch;
2671  else if ((ch == '\\') && (qc != '\''))
2672  {
2673  if (tok->dptr[0] == '\0')
2674  return -1; /* premature end of token */
2675  switch (ch = *tok->dptr++)
2676  {
2677  case 'c':
2678  case 'C':
2679  if (tok->dptr[0] == '\0')
2680  return -1; /* premature end of token */
2681  mutt_buffer_addch(dest, (toupper((unsigned char) tok->dptr[0]) - '@') & 0x7f);
2682  tok->dptr++;
2683  break;
2684  case 'e':
2685  mutt_buffer_addch(dest, '\033'); // Escape
2686  break;
2687  case 'f':
2688  mutt_buffer_addch(dest, '\f');
2689  break;
2690  case 'n':
2691  mutt_buffer_addch(dest, '\n');
2692  break;
2693  case 'r':
2694  mutt_buffer_addch(dest, '\r');
2695  break;
2696  case 't':
2697  mutt_buffer_addch(dest, '\t');
2698  break;
2699  default:
2700  if (isdigit((unsigned char) ch) && isdigit((unsigned char) tok->dptr[0]) &&
2701  isdigit((unsigned char) tok->dptr[1]))
2702  {
2703  mutt_buffer_addch(dest, (ch << 6) + (tok->dptr[0] << 3) + tok->dptr[1] - 3504);
2704  tok->dptr += 2;
2705  }
2706  else
2707  mutt_buffer_addch(dest, ch);
2708  }
2709  }
2710  else if ((ch == '^') && (flags & MUTT_TOKEN_CONDENSE))
2711  {
2712  if (tok->dptr[0] == '\0')
2713  return -1; /* premature end of token */
2714  ch = *tok->dptr++;
2715  if (ch == '^')
2716  mutt_buffer_addch(dest, ch);
2717  else if (ch == '[')
2718  mutt_buffer_addch(dest, '\033'); // Escape
2719  else if (isalpha((unsigned char) ch))
2720  mutt_buffer_addch(dest, toupper((unsigned char) ch) - '@');
2721  else
2722  {
2723  mutt_buffer_addch(dest, '^');
2724  mutt_buffer_addch(dest, ch);
2725  }
2726  }
2727  else if ((ch == '`') && (!qc || (qc == '"')))
2728  {
2729  FILE *fp = NULL;
2730  pid_t pid;
2731  char *ptr = NULL;
2732  size_t expnlen;
2733  struct Buffer expn;
2734  int line = 0;
2735 
2736  pc = tok->dptr;
2737  do
2738  {
2739  pc = strpbrk(pc, "\\`");
2740  if (pc)
2741  {
2742  /* skip any quoted chars */
2743  if (*pc == '\\')
2744  pc += 2;
2745  }
2746  } while (pc && (pc[0] != '`'));
2747  if (!pc)
2748  {
2749  mutt_debug(LL_DEBUG1, "mismatched backticks\n");
2750  return -1;
2751  }
2752  struct Buffer cmd;
2753  mutt_buffer_init(&cmd);
2754  *pc = '\0';
2755  if (flags & MUTT_TOKEN_BACKTICK_VARS)
2756  {
2757  /* recursively extract tokens to interpolate variables */
2758  mutt_extract_token(&cmd, tok,
2759  MUTT_TOKEN_QUOTE | MUTT_TOKEN_SPACE | MUTT_TOKEN_COMMENT |
2760  MUTT_TOKEN_SEMICOLON | MUTT_TOKEN_NOSHELL);
2761  }
2762  else
2763  {
2764  cmd.data = mutt_str_strdup(tok->dptr);
2765  }
2766  *pc = '`';
2767  pid = mutt_create_filter(cmd.data, NULL, &fp, NULL);
2768  if (pid < 0)
2769  {
2770  mutt_debug(LL_DEBUG1, "unable to fork command: %s\n", cmd.data);
2771  FREE(&cmd.data);
2772  return -1;
2773  }
2774  FREE(&cmd.data);
2775 
2776  tok->dptr = pc + 1;
2777 
2778  /* read line */
2779  mutt_buffer_init(&expn);
2780  expn.data = mutt_file_read_line(NULL, &expn.dsize, fp, &line, 0);
2781  mutt_file_fclose(&fp);
2782  mutt_wait_filter(pid);
2783 
2784  /* if we got output, make a new string consisting of the shell output
2785  * plus whatever else was left on the original line */
2786  /* BUT: If this is inside a quoted string, directly add output to
2787  * the token */
2788  if (expn.data && qc)
2789  {
2790  mutt_buffer_addstr(dest, expn.data);
2791  FREE(&expn.data);
2792  }
2793  else if (expn.data)
2794  {
2795  expnlen = mutt_str_strlen(expn.data);
2796  tok->dsize = expnlen + mutt_str_strlen(tok->dptr) + 1;
2797  ptr = mutt_mem_malloc(tok->dsize);
2798  memcpy(ptr, expn.data, expnlen);
2799  strcpy(ptr + expnlen, tok->dptr);
2800  tok->data = mutt_str_strdup(ptr);
2801  tok->dptr = tok->data;
2802  ptr = NULL;
2803  FREE(&expn.data);
2804  }
2805  }
2806  else if ((ch == '$') && (!qc || (qc == '"')) &&
2807  ((tok->dptr[0] == '{') || isalpha((unsigned char) tok->dptr[0])))
2808  {
2809  const char *env = NULL;
2810  char *var = NULL;
2811 
2812  if (tok->dptr[0] == '{')
2813  {
2814  pc = strchr(tok->dptr, '}');
2815  if (pc)
2816  {
2817  var = mutt_str_substr_dup(tok->dptr + 1, pc);
2818  tok->dptr = pc + 1;
2819 
2820  if ((flags & MUTT_TOKEN_NOSHELL))
2821  {
2822  mutt_buffer_addch(dest, ch);
2823  mutt_buffer_addch(dest, '{');
2824  mutt_buffer_addstr(dest, var);
2825  mutt_buffer_addch(dest, '}');
2826  FREE(&var);
2827  }
2828  }
2829  }
2830  else
2831  {
2832  for (pc = tok->dptr; isalnum((unsigned char) *pc) || (pc[0] == '_'); pc++)
2833  ;
2834  var = mutt_str_substr_dup(tok->dptr, pc);
2835  tok->dptr = pc;
2836  }
2837  if (var)
2838  {
2839  struct Buffer result;
2840  mutt_buffer_init(&result);
2841  int rc = cs_str_string_get(Config, var, &result);
2842 
2843  if (CSR_RESULT(rc) == CSR_SUCCESS)
2844  {
2845  mutt_buffer_addstr(dest, result.data);
2846  FREE(&result.data);
2847  }
2848  else if ((env = myvar_get(var)))
2849  {
2850  mutt_buffer_addstr(dest, env);
2851  }
2852  else if (!(flags & MUTT_TOKEN_NOSHELL) && (env = mutt_str_getenv(var)))
2853  {
2854  mutt_buffer_addstr(dest, env);
2855  }
2856  else
2857  {
2858  mutt_buffer_addch(dest, ch);
2859  mutt_buffer_addstr(dest, var);
2860  }
2861  FREE(&var);
2862  }
2863  }
2864  else
2865  mutt_buffer_addch(dest, ch);
2866  }
2867  mutt_buffer_addch(dest, 0); /* terminate the string */
2868  SKIPWS(tok->dptr);
2869  return 0;
2870 }
pid_t mutt_create_filter(const char *s, FILE **fp_in, FILE **fp_out, FILE **fp_err)
Set up filter program.
Definition: filter.c:217
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
#define CSR_RESULT(x)
Definition: set.h:62
#define MUTT_TOKEN_COMMENT
Don&#39;t reap comments.
Definition: mutt.h:83
String manipulation buffer.
Definition: buffer.h:33
WHERE struct ConfigSet * Config
Wrapper around the user&#39;s config settings.
Definition: globals.h:39
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:663
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:1049
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:149
int cs_str_string_get(const struct ConfigSet *cs, const char *name, struct Buffer *result)
Get a config item as a string.
Definition: set.c:696
#define SKIPWS(ch)
Definition: string2.h:47
#define MUTT_TOKEN_NOSHELL
Don&#39;t expand environment variables.
Definition: mutt.h:86
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:256
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
#define MUTT_TOKEN_QUOTE
Don&#39;t interpret quotes.
Definition: mutt.h:81
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
Definition: mutt.h:79
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:2638
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
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:80
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:271
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
Definition: myvar.c:42
#define MUTT_TOKEN_SEMICOLON
Don&#39;t treat ; as special.
Definition: mutt.h:84
#define IS_SPACE(ch)
Definition: string2.h:38
Log at debug level 1.
Definition: logging.h:56
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:85
#define FREE(x)
Definition: memory.h:40
#define MUTT_TOKEN_EQUAL
Treat &#39;=&#39; as a special.
Definition: mutt.h:78
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:61
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:228
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:82
#define MUTT_TOKEN_QUESTION
Treat &#39;?&#39; as a special.
Definition: mutt.h:87
void mutt_free_opts ( void  )

clean up before quitting

Definition at line 2875 of file init.c.

2876 {
2878 
2879  FREE(&Matches);
2880 
2881  mutt_aliaslist_free(&Aliases);
2882 
2883  mutt_regexlist_free(&Alternates);
2887  mutt_regexlist_free(&UnAlternates);
2890 
2895 
2896  /* Lists of strings */
2897  mutt_list_free(&AlternativeOrderList);
2898  mutt_list_free(&AutoViewList);
2899  mutt_list_free(&HeaderOrderList);
2902  mutt_list_free(&MimeLookupList);
2903  mutt_list_free(&Muttrc);
2905 #ifdef USE_SIDEBAR
2906  mutt_list_free(&SidebarWhitelist);
2907 #endif
2909  mutt_list_free(&UserHeader);
2910 
2911  /* Lists of AttachMatch */
2916 
2917  mutt_free_colors();
2918 
2919  FREE(&CurrentFolder);
2920  FREE(&HomeDir);
2921  FREE(&LastFolder);
2922  FREE(&ShortHostname);
2923  FREE(&Username);
2924 
2927 
2929 
2930  mutt_hist_free();
2931  mutt_free_keys();
2932 
2934 }
WHERE char * Username
User&#39;s login name.
Definition: globals.h:51
void mutt_aliaslist_free(struct AliasList *a_list)
Free a List of Aliases.
Definition: alias.c:742
struct Hash * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
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:59
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
Definition: hook.c:316
WHERE char * LastFolder
Previously selected mailbox.
Definition: globals.h:54
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:48
WHERE char * CurrentFolder
Currently selected mailbox.
Definition: globals.h:53
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
WHERE struct Hash * ReverseAliases
Hash table of aliases (email address -> alias)
Definition: globals.h:58
static const char ** Matches
Definition: init.c:92
void mutt_free_colors(void)
Free all the colours (on shutdown)
Definition: color.c:1262
WHERE char * ShortHostname
Short version of the hostname.
Definition: globals.h:49
#define FREE(x)
Definition: memory.h:40
void mutt_free_keys(void)
Free the key maps.
Definition: keymap.c:1593
#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_hdata a hash table
Definition: hash.c:472
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
Definition: email_globals.c:43
void mutt_free_attachmatch(struct AttachMatch **am)
Free an AttachMatch - Implements list_free_t.
Definition: init.c:2279
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:

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

2943 {
2944  for (const struct Command *c = Commands; c->name; c++)
2945  {
2946  if (((c->func == mutt_parse_hook) || (c->func == mutt_parse_idxfmt_hook)) &&
2947  (mutt_str_strcasecmp(c->name, name) == 0))
2948  {
2949  return c->data;
2950  }
2951  }
2952  return MUTT_HOOK_NO_FLAGS;
2953 }
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:4972
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:45
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:363
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_init ( bool  skip_sys_rc,
struct ListHead *  commands 
)

Initialise NeoMutt.

Parameters
skip_sys_rcIf true, don't read the system config file
commandsList of config commands to execute
Return values
0Success
1Error

Definition at line 2962 of file init.c.

2963 {
2964  char buf[1024];
2965  int need_pause = 0;
2966  struct Buffer err;
2967 
2968  mutt_buffer_init(&err);
2969  mutt_buffer_increase_size(&err, 256);
2970 
2972  /* reverse alias keys need to be strdup'ed because of idna conversions */
2977 
2978  mutt_menu_init();
2979 
2980  snprintf(AttachmentMarker, sizeof(AttachmentMarker), "\033]9;%" PRIu64 "\a", // Escape
2981  mutt_rand64());
2982 
2983  snprintf(ProtectedHeaderMarker, sizeof(ProtectedHeaderMarker), "\033]8;%ld\a", // Escape
2984  (long) time(NULL));
2985 
2986  /* "$spoolfile" precedence: config file, environment */
2987  const char *p = mutt_str_getenv("MAIL");
2988  if (!p)
2989  p = mutt_str_getenv("MAILDIR");
2990  if (!p)
2991  {
2992 #ifdef HOMESPOOL
2993  mutt_path_concat(buf, NONULL(HomeDir), MAILPATH, sizeof(buf));
2994 #else
2995  mutt_path_concat(buf, MAILPATH, NONULL(Username), sizeof(buf));
2996 #endif
2997  p = buf;
2998  }
2999  cs_str_initial_set(Config, "spoolfile", p, NULL);
3000  cs_str_reset(Config, "spoolfile", NULL);
3001 
3002  p = mutt_str_getenv("REPLYTO");
3003  if (p)
3004  {
3005  struct Buffer tmp, token;
3006 
3007  snprintf(buf, sizeof(buf), "Reply-To: %s", p);
3008 
3009  mutt_buffer_init(&tmp);
3010  tmp.data = buf;
3011  tmp.dptr = buf;
3012  tmp.dsize = mutt_str_strlen(buf);
3013 
3014  mutt_buffer_init(&token);
3015  parse_my_hdr(&token, &tmp, 0, &err); /* adds to UserHeader */
3016  FREE(&token.data);
3017  }
3018 
3019  p = mutt_str_getenv("EMAIL");
3020  if (p)
3021  {
3022  cs_str_initial_set(Config, "from", p, NULL);
3023  cs_str_reset(Config, "from", NULL);
3024  }
3025 
3026  /* "$mailcap_path" precedence: config file, environment, code */
3027  const char *env_mc = mutt_str_getenv("MAILCAPS");
3028  if (env_mc)
3029  cs_str_string_set(Config, "mailcap_path", env_mc, NULL);
3030 
3031  /* "$tmpdir" precedence: config file, environment, code */
3032  const char *env_tmp = mutt_str_getenv("TMPDIR");
3033  if (env_tmp)
3034  cs_str_string_set(Config, "tmpdir", env_tmp, NULL);
3035 
3036  /* "$visual", "$editor" precedence: config file, environment, code */
3037  const char *env_ed = mutt_str_getenv("VISUAL");
3038  if (!env_ed)
3039  env_ed = mutt_str_getenv("EDITOR");
3040  if (env_ed)
3041  {
3042  cs_str_string_set(Config, "editor", env_ed, NULL);
3043  cs_str_string_set(Config, "visual", env_ed, NULL);
3044  }
3045 
3048 
3049  Matches = mutt_mem_calloc(MatchesListsize, sizeof(char *));
3050 
3052 
3053 #ifdef HAVE_GETSID
3054  /* Unset suspend by default if we're the session leader */
3055  if (getsid(0) == getpid())
3056  C_Suspend = false;
3057 #endif
3058 
3059  /* RFC2368, "4. Unsafe headers"
3060  * The creator of a mailto URL can't expect the resolver of a URL to
3061  * understand more than the "subject" and "body" headers. Clients that
3062  * resolve mailto URLs into mail messages should be able to correctly
3063  * create RFC822-compliant mail messages using the "subject" and "body"
3064  * headers. */
3065  add_to_stailq(&MailToAllow, "body");
3066  add_to_stailq(&MailToAllow, "subject");
3067  /* Cc, In-Reply-To, and References help with not breaking threading on
3068  * mailing lists, see https://github.com/neomutt/neomutt/issues/115 */
3069  add_to_stailq(&MailToAllow, "cc");
3070  add_to_stailq(&MailToAllow, "in-reply-to");
3071  add_to_stailq(&MailToAllow, "references");
3072 
3073  if (STAILQ_EMPTY(&Muttrc))
3074  {
3075  const char *xdg_cfg_home = mutt_str_getenv("XDG_CONFIG_HOME");
3076 
3077  if (!xdg_cfg_home && HomeDir)
3078  {
3079  snprintf(buf, sizeof(buf), "%s/.config", HomeDir);
3080  xdg_cfg_home = buf;
3081  }
3082 
3083  char *config = find_cfg(HomeDir, xdg_cfg_home);
3084  if (config)
3085  {
3086  mutt_list_insert_tail(&Muttrc, config);
3087  }
3088  }
3089  else
3090  {
3091  struct ListNode *np = NULL;
3092  STAILQ_FOREACH(np, &Muttrc, entries)
3093  {
3094  mutt_str_strfcpy(buf, np->data, sizeof(buf));
3095  FREE(&np->data);
3096  mutt_expand_path(buf, sizeof(buf));
3097  np->data = mutt_str_strdup(buf);
3098  if (access(np->data, F_OK))
3099  {
3100  mutt_perror(np->data);
3101  return 1; // TEST10: neomutt -F missing
3102  }
3103  }
3104  }
3105 
3106  if (!STAILQ_EMPTY(&Muttrc))
3107  {
3108  cs_str_string_set(Config, "alias_file", STAILQ_FIRST(&Muttrc)->data, NULL);
3109  }
3110 
3111  /* Process the global rc file if it exists and the user hasn't explicitly
3112  * requested not to via "-n". */
3113  if (!skip_sys_rc)
3114  {
3115  do
3116  {
3117  if (mutt_set_xdg_path(XDG_CONFIG_DIRS, buf, sizeof(buf)))
3118  break;
3119 
3120  snprintf(buf, sizeof(buf), "%s/neomuttrc", SYSCONFDIR);
3121  if (access(buf, F_OK) == 0)
3122  break;
3123 
3124  snprintf(buf, sizeof(buf), "%s/Muttrc", SYSCONFDIR);
3125  if (access(buf, F_OK) == 0)
3126  break;
3127 
3128  snprintf(buf, sizeof(buf), "%s/neomuttrc", PKGDATADIR);
3129  if (access(buf, F_OK) == 0)
3130  break;
3131 
3132  snprintf(buf, sizeof(buf), "%s/Muttrc", PKGDATADIR);
3133  } while (false);
3134 
3135  if (access(buf, F_OK) == 0)
3136  {
3137  if (source_rc(buf, &err) != 0)
3138  {
3139  mutt_error("%s", err.data);
3140  need_pause = 1; // TEST11: neomutt (error in /etc/neomuttrc)
3141  }
3142  }
3143  }
3144 
3145  /* Read the user's initialization file. */
3146  struct ListNode *np = NULL;
3147  STAILQ_FOREACH(np, &Muttrc, entries)
3148  {
3149  if (np->data)
3150  {
3151  if (source_rc(np->data, &err) != 0)
3152  {
3153  mutt_error("%s", err.data);
3154  need_pause = 1; // TEST12: neomutt (error in ~/.neomuttrc)
3155  }
3156  }
3157  }
3158 
3159  if (execute_commands(commands) != 0)
3160  need_pause = 1; // TEST13: neomutt -e broken
3161 
3162  if (!get_hostname())
3163  return 1;
3164 
3165  if (!C_Realname)
<