NeoMutt  2019-11-11
Teaching an old dog new tricks
DOXYGEN
init.c File Reference

Config/command parsing. More...

#include "config.h"
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <pwd.h>
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <unistd.h>
#include "mutt/mutt.h"
#include "address/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "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_menu.h"
#include "mutt_parse.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 struct AttachMatchmutt_attachmatch_new (void)
 Create a new AttachMatch. More...
 
static enum CommandResult parse_attach_list (struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
 Parse the "attachments" command. More...
 
static int parse_grouplist (struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse a group context. More...
 
static enum CommandResult parse_replace_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse a string replacement rule - Implements command_t. More...
 
static enum CommandResult parse_unattach_list (struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
 Parse the "unattachments" command. More...
 
static enum CommandResult parse_unreplace_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Remove a string replacement rule - Implements command_t. More...
 
static int print_attach_list (struct ListHead *h, const char op, const char *name)
 Print a list of attachments. More...
 
static void remove_from_stailq (struct ListHead *head, const char *str)
 Remove an item, matching a string, from a List. More...
 
static int source_rc (const char *rcfile_path, struct Buffer *err)
 Read an initialization file. More...
 
static enum CommandResult parse_alias (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'alias' command - Implements command_t. More...
 
static enum CommandResult parse_alternates (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'alternates' command - Implements command_t. More...
 
static enum CommandResult parse_attachments (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'attachments' command - Implements command_t. More...
 
static enum CommandResult parse_echo (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'echo' command - Implements command_t. More...
 
static enum CommandResult parse_finish (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'finish' command - Implements command_t. More...
 
static enum CommandResult parse_group (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'group' and 'ungroup' commands - Implements command_t. More...
 
static bool is_function (const char *name)
 Is the argument a neomutt function? More...
 
static enum CommandResult parse_ifdef (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'ifdef' and 'ifndef' commands - Implements command_t. More...
 
static enum CommandResult parse_ignore (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'ignore' command - Implements command_t. More...
 
static enum CommandResult parse_lists (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'lists' command - Implements command_t. More...
 
static enum CommandResult parse_mailboxes (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'mailboxes' command - Implements command_t. More...
 
static enum CommandResult parse_my_hdr (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'my_hdr' command - Implements command_t. More...
 
static enum CommandResult parse_path_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'sidebar_whitelist' command - Implements command_t. More...
 
static enum CommandResult parse_path_unlist (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unsidebar_whitelist' command - Implements command_t. More...
 
static enum CommandResult parse_set (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'set' family of commands - Implements command_t. More...
 
static enum CommandResult parse_setenv (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'setenv' and 'unsetenv' commands - Implements command_t. More...
 
static enum CommandResult parse_source (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'source' command - Implements command_t. More...
 
static enum CommandResult parse_spam_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'spam' and 'nospam' commands - Implements command_t. More...
 
static enum CommandResult parse_stailq (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse a list command - Implements command_t. More...
 
static enum CommandResult parse_subjectrx_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'subjectrx' command - Implements command_t. More...
 
static enum CommandResult parse_subscribe (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'subscribe' command - Implements command_t. More...
 
static enum CommandResult parse_subscribe_to (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'subscribe-to' command - Implements command_t. More...
 
static enum CommandResult parse_tag_formats (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'tag-formats' command - Implements command_t. More...
 
static enum CommandResult parse_tag_transforms (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'tag-transforms' command - Implements command_t. More...
 
static enum CommandResult parse_unalias (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unalias' command - Implements command_t. More...
 
static enum CommandResult parse_unalternates (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unalternates' command - Implements command_t. More...
 
void mutt_attachmatch_free (struct AttachMatch **ptr)
 Free an AttachMatch - Implements list_free_t. More...
 
static enum CommandResult parse_unattachments (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unattachments' command - Implements command_t. More...
 
static enum CommandResult parse_unignore (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unignore' command - Implements command_t. More...
 
static enum CommandResult parse_unlists (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unlists' command - Implements command_t. More...
 
static enum CommandResult parse_unmailboxes (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unmailboxes' command - Implements command_t. More...
 
static enum CommandResult parse_unmy_hdr (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unmy_hdr' command - Implements command_t. More...
 
static enum CommandResult parse_unstailq (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse an unlist command - Implements command_t. More...
 
static enum CommandResult parse_unsubjectrx_list (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unsubjectrx' command - Implements command_t. More...
 
static enum CommandResult parse_unsubscribe (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unsubscribe' command - Implements command_t. More...
 
static enum CommandResult parse_unsubscribe_from (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unsubscribe-from' command - Implements command_t. More...
 
const struct Commandmutt_command_get (const char *s)
 Get a Command by its name. More...
 
int mutt_extract_token (struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
 Extract one token from a string. More...
 
void mutt_opts_free (void)
 clean up before quitting More...
 
HookFlags mutt_get_hook_type (const char *name)
 Find a hook by name. More...
 
int mutt_init (bool skip_sys_rc, struct ListHead *commands)
 Initialise NeoMutt. More...
 
enum CommandResult mutt_parse_rc_line (char *line, struct Buffer *token, struct Buffer *err)
 Parse a line of user config. More...
 
int mutt_query_variables (struct ListHead *queries)
 Implement the -Q command line flag. More...
 
enum QuadOption query_quadoption (enum QuadOption opt, const char *prompt)
 Ask the user a quad-question. More...
 
int mutt_command_complete (char *buf, size_t buflen, int pos, int numtabs)
 Complete a command name. More...
 
int mutt_label_complete (char *buf, size_t buflen, int numtabs)
 Complete a label name. More...
 
bool mutt_nm_query_complete (char *buf, size_t buflen, int pos, int numtabs)
 Complete to the nearest notmuch tag. More...
 
bool mutt_nm_tag_complete (char *buf, size_t buflen, int numtabs)
 Complete to the nearest notmuch tag. More...
 
int mutt_var_value_complete (char *buf, size_t buflen, int pos)
 Complete a variable/value. More...
 
struct ConfigSetinit_config (size_t size)
 Initialise the config system. More...
 
int charset_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "charset" config variable - Implements cs_validator() More...
 
int hcache_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "header_cache_backend" config variable - Implements cs_validator() More...
 
int pager_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Check for config variables that can't be set from the pager - Implements cs_validator() More...
 
int multipart_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "show_multipart_alternative" config variable - Implements cs_validator() More...
 
int reply_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "reply_regex" config variable - Implements cs_validator() More...
 
int wrapheaders_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "wrap_headers" config variable - Implements cs_validator() More...
 

Variables

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

Detailed Description

Config/command parsing.

Authors
  • Michael R. Elkins
  • Pietro Cerutti

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

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

Definition in file init.c.

Macro Definition Documentation

◆ MAX_ERRS

#define MAX_ERRS   128

Definition at line 79 of file init.c.

◆ NUM_VARS

#define NUM_VARS   mutt_array_size(MuttVars)

Definition at line 81 of file init.c.

◆ NUM_COMMANDS

#define NUM_COMMANDS   mutt_array_size(Commands)

Definition at line 82 of file init.c.

Enumeration Type Documentation

◆ GroupState

enum GroupState

Type of email address group.

Enumerator
GS_NONE 

Group is missing an argument.

GS_RX 

Entry is a regular expression.

GS_ADDR 

Entry is an address.

Definition at line 102 of file init.c.

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

Function Documentation

◆ add_to_stailq()

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

Add a string to a list.

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

Definition at line 116 of file init.c.

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

◆ alternates_clean()

static void alternates_clean ( void  )
static

Clear the recipient valid flag of all emails.

Definition at line 137 of file init.c.

138 {
139  if (!Context)
140  return;
141 
142  for (int i = 0; i < Context->mailbox->msg_count; i++)
143  Context->mailbox->emails[i]->recip_valid = false;
144 }
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:58
+ Here is the caller graph for this function:

◆ attachments_clean()

static void attachments_clean ( void  )
static

always wise to do what someone else did before

Definition at line 149 of file init.c.

150 {
151  if (!Context)
152  return;
153 
154  for (int i = 0; i < Context->mailbox->msg_count; i++)
155  Context->mailbox->emails[i]->attach_valid = false;
156 }
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:70
+ Here is the caller graph for this function:

◆ matches_ensure_morespace()

static void matches_ensure_morespace ( int  current)
static

Allocate more space for auto-completion.

Parameters
currentCurrent allocation

Definition at line 162 of file init.c.

163 {
164  if (current <= (MatchesListsize - 2))
165  return;
166 
167  int base_space = MAX(NUM_VARS, NUM_COMMANDS) + 1;
168  int extra_space = MatchesListsize - base_space;
169  extra_space *= 2;
170  const int space = base_space + extra_space;
171  mutt_mem_realloc(&Matches, space * sizeof(char *));
172  memset(&Matches[current + 1], 0, space - current);
173  MatchesListsize = space;
174 }
#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:92
#define NUM_VARS
Definition: init.c:81
static const char ** Matches
Definition: init.c:90
#define NUM_COMMANDS
Definition: init.c:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ candidate()

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

helper function for completion

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

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

Definition at line 185 of file init.c.

186 {
187  if (!dest || !user || !src)
188  return;
189 
190  if (strstr(src, user) != src)
191  return;
192 
194  Matches[NumMatched++] = src;
195  if (dest[0] == '\0')
196  mutt_str_strfcpy(dest, src, dlen);
197  else
198  {
199  int l;
200  for (l = 0; src[l] && src[l] == dest[l]; l++)
201  ;
202  dest[l] = '\0';
203  }
204 }
static int NumMatched
Definition: init.c:88
static void matches_ensure_morespace(int current)
Allocate more space for auto-completion.
Definition: init.c:162
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:90
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear_subject_mods()

static void clear_subject_mods ( void  )
static

Clear out all modified email subjects.

Definition at line 209 of file init.c.

210 {
211  if (!Context)
212  return;
213 
214  for (int i = 0; i < Context->mailbox->msg_count; i++)
216 }
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:89
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ complete_all_nm_tags()

static int complete_all_nm_tags ( const char *  pt)
static

Pass a list of Notmuch tags to the completion code.

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

Definition at line 225 of file init.c.

226 {
227  int tag_count_1 = 0;
228  int tag_count_2 = 0;
229 
230  NumMatched = 0;
231  mutt_str_strfcpy(UserTyped, pt, sizeof(UserTyped));
232  memset(Matches, 0, MatchesListsize);
233  memset(Completed, 0, sizeof(Completed));
234 
236 
237  /* Work out how many tags there are. */
238  if (nm_get_all_tags(Context->mailbox, NULL, &tag_count_1) || (tag_count_1 == 0))
239  goto done;
240 
241  /* Free the old list, if any. */
242  if (nm_tags)
243  {
244  for (int i = 0; nm_tags[i]; i++)
245  FREE(&nm_tags[i]);
246  FREE(&nm_tags);
247  }
248  /* Allocate a new list, with sentinel. */
249  nm_tags = mutt_mem_malloc((tag_count_1 + 1) * sizeof(char *));
250  nm_tags[tag_count_1] = NULL;
251 
252  /* Get all the tags. */
253  if (nm_get_all_tags(Context->mailbox, nm_tags, &tag_count_2) || (tag_count_1 != tag_count_2))
254  {
255  FREE(&nm_tags);
256  nm_tags = NULL;
258  return -1;
259  }
260 
261  /* Put them into the completion machinery. */
262  for (int num = 0; num < tag_count_1; num++)
263  {
264  candidate(UserTyped, nm_tags[num], Completed, sizeof(Completed));
265  }
266 
269 
270 done:
272  return 0;
273 }
The "current" mailbox.
Definition: context.h:36
static int NumMatched
Definition: init.c:88
static char ** nm_tags
Definition: init.c:96
struct Mailbox * mailbox
Definition: context.h:50
static char Completed[256]
Definition: init.c:89
void nm_db_longrun_done(struct Mailbox *m)
Finish a long transaction.
Definition: nm_db.c:304
static int MatchesListsize
Definition: init.c:92
static void matches_ensure_morespace(int current)
Allocate more space for auto-completion.
Definition: init.c:162
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:86
static const char ** Matches
Definition: init.c:90
#define FREE(x)
Definition: memory.h:40
void nm_db_longrun_init(struct Mailbox *m, bool writable)
Start a long transaction.
Definition: nm_db.c:289
static void candidate(char *user, const char *src, char *dest, size_t dlen)
helper function for completion
Definition: init.c:185
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_commands()

static int execute_commands ( struct ListHead *  p)
static

Execute a set of NeoMutt commands.

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

Definition at line 282 of file init.c.

283 {
284  int rc = 0;
285  struct Buffer *err = mutt_buffer_pool_get();
286  struct Buffer *token = mutt_buffer_pool_get();
287 
288  struct ListNode *np = NULL;
289  STAILQ_FOREACH(np, p, entries)
290  {
291  enum CommandResult rc2 = mutt_parse_rc_line(np->data, token, err);
292  if (rc2 == MUTT_CMD_ERROR)
293  mutt_error(_("Error in command line: %s"), mutt_b2s(err));
294 
295  if ((rc2 == MUTT_CMD_ERROR) || (rc2 == MUTT_CMD_WARNING))
296  mutt_warning(_("Warning in command line: %s"), mutt_b2s(err));
297 
298  if ((rc2 == MUTT_CMD_ERROR) || (rc2 == MUTT_CMD_WARNING))
299  {
300  mutt_buffer_pool_release(&token);
302  return -1;
303  }
304  }
305  mutt_buffer_pool_release(&token);
307 
308  return rc;
309 }
#define mutt_warning(...)
Definition: logging.h:82
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:100
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:111
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
String.
Definition: list.h:35
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:84
A List node for strings.
Definition: list.h:33
enum CommandResult mutt_parse_rc_line(char *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
Definition: init.c:3232
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_cfg()

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

Find a config file.

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

Definition at line 318 of file init.c.

319 {
320  const char *names[] = {
321  "neomuttrc",
322  "muttrc",
323  NULL,
324  };
325 
326  const char *locations[][2] = {
327  { xdg_cfg_home, "neomutt/" },
328  { xdg_cfg_home, "mutt/" },
329  { home, ".neomutt/" },
330  { home, ".mutt/" },
331  { home, "." },
332  { NULL, NULL },
333  };
334 
335  for (int i = 0; locations[i][0] || locations[i][1]; i++)
336  {
337  if (!locations[i][0])
338  continue;
339 
340  for (int j = 0; names[j]; j++)
341  {
342  char buf[256];
343 
344  snprintf(buf, sizeof(buf), "%s/%s%s", locations[i][0], locations[i][1], names[j]);
345  if (access(buf, F_OK) == 0)
346  return mutt_str_strdup(buf);
347  }
348  }
349 
350  return NULL;
351 }
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getmailname()

static char* getmailname ( void  )
static

Try to retrieve the FQDN from mailname files.

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

Definition at line 359 of file init.c.

360 {
361  char *mailname = NULL;
362  static const char *mn_files[] = { "/etc/mailname", "/etc/mail/mailname" };
363 
364  for (size_t i = 0; i < mutt_array_size(mn_files); i++)
365  {
366  FILE *fp = mutt_file_fopen(mn_files[i], "r");
367  if (!fp)
368  continue;
369 
370  size_t len = 0;
371  mailname = mutt_file_read_line(NULL, &len, fp, NULL, 0);
372  mutt_file_fclose(&fp);
373  if (mailname && *mailname)
374  break;
375 
376  FREE(&mailname);
377  }
378 
379  return mailname;
380 }
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, int flags)
Read a line from a file.
Definition: file.c:664
#define mutt_array_size(x)
Definition: memory.h:33
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
#define FREE(x)
Definition: memory.h:40
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:585
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_hostname()

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

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

◆ mutt_attachmatch_new()

static struct AttachMatch* mutt_attachmatch_new ( void  )
static

Create a new AttachMatch.

Return values
ptrNew AttachMatch

Definition at line 464 of file init.c.

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

◆ parse_attach_list()

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

Parse the "attachments" command.

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

Definition at line 477 of file init.c.

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

◆ parse_grouplist()

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

Parse a group context.

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

Definition at line 554 of file init.c.

556 {
557  while (mutt_str_strcasecmp(buf->data, "-group") == 0)
558  {
559  if (!MoreArgs(s))
560  {
561  mutt_buffer_strcpy(err, _("-group: no group name"));
562  return -1;
563  }
564 
566 
568 
569  if (!MoreArgs(s))
570  {
571  mutt_buffer_strcpy(err, _("out of arguments"));
572  return -1;
573  }
574 
576  }
577 
578  return 0;
579 }
void mutt_grouplist_add(struct GroupList *gl, struct Group *group)
Add a Group to a GroupList.
Definition: group.c:138
#define _(a)
Definition: message.h:28
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
struct Group * mutt_pattern_group(const char *pat)
Match a pattern to a Group.
Definition: group.c:66
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_replace_list()

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

Parse a string replacement rule - Implements command_t.

Definition at line 584 of file init.c.

586 {
587  struct ReplaceList *list = (struct ReplaceList *) data;
588  struct Buffer templ = mutt_buffer_make(0);
589 
590  /* First token is a regex. */
591  if (!MoreArgs(s))
592  {
593  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
594  return MUTT_CMD_WARNING;
595  }
597 
598  /* Second token is a replacement template */
599  if (!MoreArgs(s))
600  {
601  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
602  return MUTT_CMD_WARNING;
603  }
605 
606  if (mutt_replacelist_add(list, buf->data, templ.data, err) != 0)
607  {
608  FREE(&templ.data);
609  return MUTT_CMD_ERROR;
610  }
611  FREE(&templ.data);
612 
613  return MUTT_CMD_SUCCESS;
614 }
int mutt_replacelist_add(struct ReplaceList *rl, const char *pat, const char *templ, struct Buffer *err)
Add a pattern and a template to a list.
Definition: regex.c:262
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define FREE(x)
Definition: memory.h:40
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_unattach_list()

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

Parse the "unattachments" command.

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

Definition at line 624 of file init.c.

626 {
627  struct AttachMatch *a = NULL;
628  char *tmp = NULL;
629  char *minor = NULL;
630 
631  do
632  {
634  FREE(&tmp);
635 
636  if (mutt_str_strcasecmp(buf->data, "any") == 0)
637  tmp = mutt_str_strdup("*/.*");
638  else if (mutt_str_strcasecmp(buf->data, "none") == 0)
639  tmp = mutt_str_strdup("cheap_hack/this_should_never_match");
640  else
641  tmp = mutt_str_strdup(buf->data);
642 
643  minor = strchr(tmp, '/');
644  if (minor)
645  {
646  *minor = '\0';
647  minor++;
648  }
649  else
650  {
651  minor = "unknown";
652  }
653  const enum ContentType major = mutt_check_mime_type(tmp);
654 
655  struct ListNode *np = NULL, *tmp2 = NULL;
656  STAILQ_FOREACH_SAFE(np, head, entries, tmp2)
657  {
658  a = (struct AttachMatch *) np->data;
659  mutt_debug(LL_DEBUG3, "check %s/%s [%d] : %s/%s [%d]\n", a->major,
660  a->minor, a->major_int, tmp, minor, major);
661  if ((a->major_int == major) && (mutt_str_strcasecmp(minor, a->minor) == 0))
662  {
663  mutt_debug(LL_DEBUG3, "removed %s/%s [%d]\n", a->major, a->minor, a->major_int);
664  regfree(&a->minor_regex);
665  FREE(&a->major);
666  STAILQ_REMOVE(head, np, ListNode, entries);
667  FREE(&np->data);
668  FREE(&np);
669  }
670  }
671 
672  } while (MoreArgs(s));
673 
674  FREE(&tmp);
676  return MUTT_CMD_SUCCESS;
677 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:400
enum ContentType major_int
Definition: mutt_parse.h:38
#define MoreArgs(buf)
Definition: buffer.h:43
enum ContentType mutt_check_mime_type(const char *s)
Check a MIME type string.
Definition: parse.c:317
const char * major
Definition: mutt_parse.h:37
#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:149
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * data
String.
Definition: list.h:35
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
regex_t minor_regex
Definition: mutt_parse.h:40
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
An attachment matching a regex for attachment counter.
Definition: mutt_parse.h:35
A List node for strings.
Definition: list.h:33
const char * minor
Definition: mutt_parse.h:39
Log at debug level 3.
Definition: logging.h:58
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
ContentType
Content-Type.
Definition: mime.h:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_unreplace_list()

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

Remove a string replacement rule - Implements command_t.

Definition at line 682 of file init.c.

684 {
685  struct ReplaceList *list = (struct ReplaceList *) data;
686 
687  /* First token is a regex. */
688  if (!MoreArgs(s))
689  {
690  mutt_buffer_printf(err, _("%s: too few arguments"), "unsubjectrx");
691  return MUTT_CMD_WARNING;
692  }
693 
695 
696  /* "*" is a special case. */
697  if (mutt_str_strcmp(buf->data, "*") == 0)
698  {
699  mutt_replacelist_free(list);
700  return MUTT_CMD_SUCCESS;
701  }
702 
703  mutt_replacelist_remove(list, buf->data);
704  return MUTT_CMD_SUCCESS;
705 }
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:447
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:564
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_attach_list()

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

Print a list of attachments.

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

Definition at line 714 of file init.c.

715 {
716  struct ListNode *np = NULL;
717  STAILQ_FOREACH(np, h, entries)
718  {
719  printf("attachments %c%s %s/%s\n", op, name,
720  ((struct AttachMatch *) np->data)->major,
721  ((struct AttachMatch *) np->data)->minor);
722  }
723 
724  return 0;
725 }
const char * name
Definition: pgpmicalg.c:45
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
char * data
String.
Definition: list.h:35
An attachment matching a regex for attachment counter.
Definition: mutt_parse.h:35
A List node for strings.
Definition: list.h:33
+ Here is the caller graph for this function:

◆ remove_from_stailq()

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

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

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

Definition at line 734 of file init.c.

735 {
736  if (mutt_str_strcmp("*", str) == 0)
737  mutt_list_free(head); /* "unCMD *" means delete all current entries */
738  else
739  {
740  struct ListNode *np = NULL, *tmp = NULL;
741  STAILQ_FOREACH_SAFE(np, head, entries, tmp)
742  {
743  if (mutt_str_strcasecmp(str, np->data) == 0)
744  {
745  STAILQ_REMOVE(head, np, ListNode, entries);
746  FREE(&np->data);
747  FREE(&np);
748  break;
749  }
750  }
751  }
752 }
#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
String.
Definition: list.h:35
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
#define FREE(x)
Definition: memory.h:40
A List node for strings.
Definition: list.h:33
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ source_rc()

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

Read an initialization file.

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

Definition at line 760 of file init.c.

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

◆ parse_alias()

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

Parse the 'alias' command - Implements command_t.

Definition at line 895 of file init.c.

897 {
898  struct Alias *tmp = NULL;
899  char *estr = NULL;
900  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
901 
902  if (!MoreArgs(s))
903  {
904  mutt_buffer_strcpy(err, _("alias: no address"));
905  return MUTT_CMD_WARNING;
906  }
907 
909 
910  if (parse_grouplist(&gl, buf, s, data, err) == -1)
911  return MUTT_CMD_ERROR;
912 
913  /* check to see if an alias with this name already exists */
914  TAILQ_FOREACH(tmp, &Aliases, entries)
915  {
916  if (mutt_str_strcasecmp(tmp->name, buf->data) == 0)
917  break;
918  }
919 
920  if (tmp)
921  {
923  /* override the previous value */
924  mutt_addrlist_clear(&tmp->addr);
925  if (CurrentMenu == MENU_ALIAS)
927  }
928  else
929  {
930  /* create a new alias */
931  tmp = mutt_alias_new();
932  tmp->name = mutt_str_strdup(buf->data);
933  TAILQ_INSERT_TAIL(&Aliases, tmp, entries);
934  /* give the main addressbook code a chance */
935  if (CurrentMenu == MENU_ALIAS)
936  OptMenuCaller = true;
937  }
938 
940  mutt_debug(LL_DEBUG5, "Second token is '%s'\n", buf->data);
941 
942  mutt_addrlist_parse2(&tmp->addr, buf->data);
943 
944  if (mutt_addrlist_to_intl(&tmp->addr, &estr))
945  {
946  mutt_buffer_printf(err, _("Warning: Bad IDN '%s' in alias '%s'"), estr, tmp->name);
947  FREE(&estr);
948  goto bail;
949  }
950 
951  mutt_grouplist_add_addrlist(&gl, &tmp->addr);
953 
954  if (C_DebugLevel > LL_DEBUG4)
955  {
956  /* A group is terminated with an empty address, so check a->mailbox */
957  struct Address *a = NULL;
958  TAILQ_FOREACH(a, &tmp->addr, entries)
959  {
960  if (!a->mailbox)
961  break;
962 
963  if (a->group)
964  mutt_debug(LL_DEBUG5, " Group %s\n", a->mailbox);
965  else
966  mutt_debug(LL_DEBUG5, " %s\n", a->mailbox);
967  }
968  }
970  return MUTT_CMD_SUCCESS;
971 
972 bail:
974  return MUTT_CMD_ERROR;
975 }
void mutt_alias_delete_reverse(struct Alias *t)
Remove an email address lookup for an Alias.
Definition: alias.c:575
A shortcut for an email address.
Definition: alias.h:37
Log at debug level 4.
Definition: logging.h:59
char * name
Short 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:1381
WHERE bool OptMenuCaller
(pseudo) tell menu to give caller a take
Definition: options.h:38
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:84
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:34
char * mailbox
Mailbox and host address.
Definition: address.h:37
void mutt_grouplist_add_addrlist(struct GroupList *gl, struct AddressList *al)
Add Address list to a GroupList.
Definition: group.c:227
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:606
#define MoreArgs(buf)
Definition: buffer.h:43
struct Alias * mutt_alias_new(void)
Create a new Alias.
Definition: alias.c:144
#define MUTT_TOKEN_QUOTE
Don&#39;t interpret quotes.
Definition: mutt.h:80
static int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a group context.
Definition: init.c:554
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:2655
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:79
char * data
Pointer to data.
Definition: buffer.h:35
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:803
Select an email address by its alias.
Definition: keymap.h:71
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
#define MUTT_TOKEN_SEMICOLON
Don&#39;t treat ; as special.
Definition: mutt.h:83
Success: Command worked.
Definition: mutt_commands.h:37
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1216
bool group
Group mailbox?
Definition: address.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:36
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
void mutt_alias_add_reverse(struct Alias *t)
Add an email address lookup for an Alias.
Definition: alias.c:553
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:158
#define FREE(x)
Definition: memory.h:40
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:322
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct AddressList addr
List of Addresses the Alias expands to.
Definition: alias.h:40
Log at debug level 5.
Definition: logging.h:60
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_alternates()

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

Parse the 'alternates' command - Implements command_t.

Definition at line 980 of file init.c.

982 {
983  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
984 
986 
987  do
988  {
990 
991  if (parse_grouplist(&gl, buf, s, data, err) == -1)
992  goto bail;
993 
994  mutt_regexlist_remove(&UnAlternates, buf->data);
995 
996  if (mutt_regexlist_add(&Alternates, buf->data, REG_ICASE, err) != 0)
997  goto bail;
998 
999  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
1000  goto bail;
1001  } while (MoreArgs(s));
1002 
1004  return MUTT_CMD_SUCCESS;
1005 
1006 bail:
1008  return MUTT_CMD_ERROR;
1009 }
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:137
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, int flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:277
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
static int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a group context.
Definition: init.c:554
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:158
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:322
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_attachments()

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

Parse the 'attachments' command - Implements command_t.

Definition at line 1014 of file init.c.

1016 {
1017  char op;
1018  char *category = NULL;
1019  struct ListHead *head = NULL;
1020 
1022  if (!buf->data || (*buf->data == '\0'))
1023  {
1024  mutt_buffer_strcpy(err, _("attachments: no disposition"));
1025  return MUTT_CMD_WARNING;
1026  }
1027 
1028  category = buf->data;
1029  op = *category++;
1030 
1031  if (op == '?')
1032  {
1033  mutt_endwin();
1034  fflush(stdout);
1035  printf("\n%s\n\n", _("Current attachments settings:"));
1036  print_attach_list(&AttachAllow, '+', "A");
1037  print_attach_list(&AttachExclude, '-', "A");
1038  print_attach_list(&InlineAllow, '+', "I");
1039  print_attach_list(&InlineExclude, '-', "I");
1041  return MUTT_CMD_SUCCESS;
1042  }
1043 
1044  if ((op != '+') && (op != '-'))
1045  {
1046  op = '+';
1047  category--;
1048  }
1049  if (mutt_str_startswith("attachment", category, CASE_IGNORE))
1050  {
1051  if (op == '+')
1052  head = &AttachAllow;
1053  else
1054  head = &AttachExclude;
1055  }
1056  else if (mutt_str_startswith("inline", category, CASE_IGNORE))
1057  {
1058  if (op == '+')
1059  head = &InlineAllow;
1060  else
1061  head = &InlineExclude;
1062  }
1063  else
1064  {
1065  mutt_buffer_strcpy(err, _("attachments: invalid disposition"));
1066  return MUTT_CMD_ERROR;
1067  }
1068 
1069  return parse_attach_list(buf, s, head, err);
1070 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
struct ListHead InlineAllow
List of inline types to counted.
Definition: mutt_parse.c:41
#define _(a)
Definition: message.h:28
struct ListHead InlineExclude
List of inline types to ignore.
Definition: mutt_parse.c:42
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:544
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
Ignore case when comparing strings.
Definition: string2.h:68
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:577
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: mutt_parse.c:40
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
static enum CommandResult parse_attach_list(struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
Parse the "attachments" command.
Definition: init.c:477
static int print_attach_list(struct ListHead *h, const char op, const char *name)
Print a list of attachments.
Definition: init.c:714
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: mutt_parse.c:39
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_echo()

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

Parse the 'echo' command - Implements command_t.

Definition at line 1075 of file init.c.

1077 {
1078  if (!MoreArgs(s))
1079  {
1080  mutt_buffer_printf(err, _("%s: too few arguments"), "echo");
1081  return MUTT_CMD_WARNING;
1082  }
1084  OptForceRefresh = true;
1085  mutt_message("%s", buf->data);
1086  OptForceRefresh = false;
1087  mutt_sleep(0);
1088 
1089  return MUTT_CMD_SUCCESS;
1090 }
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:43
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1546
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:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_finish()

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

Parse the 'finish' command - Implements command_t.

Return values
MUTT_CMD_FINISHStop processing the current file
MUTT_CMD_WARNINGFailed

If the 'finish' command is found, we should stop reading the current file.

Definition at line 1099 of file init.c.

1101 {
1102  if (MoreArgs(s))
1103  {
1104  mutt_buffer_printf(err, _("%s: too many arguments"), "finish");
1105  return MUTT_CMD_WARNING;
1106  }
1107 
1108  return MUTT_CMD_FINISH;
1109 }
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:43
Warning: Help given to the user.
Definition: mutt_commands.h:36
Finish: Stop processing this file.
Definition: mutt_commands.h:38
+ Here is the call graph for this function:

◆ parse_group()

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

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

Definition at line 1114 of file init.c.

1116 {
1117  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1118  enum GroupState state = GS_NONE;
1119 
1120  do
1121  {
1123  if (parse_grouplist(&gl, buf, s, data, err) == -1)
1124  goto bail;
1125 
1126  if ((data == MUTT_UNGROUP) && (mutt_str_strcasecmp(buf->data, "*") == 0))
1127  {
1128  mutt_grouplist_clear(&gl);
1129  goto out;
1130  }
1131 
1132  if (mutt_str_strcasecmp(buf->data, "-rx") == 0)
1133  state = GS_RX;
1134  else if (mutt_str_strcasecmp(buf->data, "-addr") == 0)
1135  state = GS_ADDR;
1136  else
1137  {
1138  switch (state)
1139  {
1140  case GS_NONE:
1141  mutt_buffer_printf(err, _("%sgroup: missing -rx or -addr"),
1142  (data == MUTT_UNGROUP) ? "un" : "");
1143  goto warn;
1144 
1145  case GS_RX:
1146  if ((data == MUTT_GROUP) &&
1147  (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0))
1148  {
1149  goto bail;
1150  }
1151  else if ((data == MUTT_UNGROUP) &&
1152  (mutt_grouplist_remove_regex(&gl, buf->data) < 0))
1153  {
1154  goto bail;
1155  }
1156  break;
1157 
1158  case GS_ADDR:
1159  {
1160  char *estr = NULL;
1161  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
1162  mutt_addrlist_parse2(&al, buf->data);
1163  if (TAILQ_EMPTY(&al))
1164  goto bail;
1165  if (mutt_addrlist_to_intl(&al, &estr))
1166  {
1167  mutt_buffer_printf(err, _("%sgroup: warning: bad IDN '%s'"),
1168  (data == 1) ? "un" : "", estr);
1169  mutt_addrlist_clear(&al);
1170  FREE(&estr);
1171  goto bail;
1172  }
1173  if (data == MUTT_GROUP)
1174  mutt_grouplist_add_addrlist(&gl, &al);
1175  else if (data == MUTT_UNGROUP)
1177  mutt_addrlist_clear(&al);
1178  break;
1179  }
1180  }
1181  }
1182  } while (MoreArgs(s));
1183 
1184 out:
1186  return MUTT_CMD_SUCCESS;
1187 
1188 bail:
1190  return MUTT_CMD_ERROR;
1191 
1192 warn:
1194  return MUTT_CMD_WARNING;
1195 }
#define MUTT_UNGROUP
&#39;ungroup&#39; config command
Definition: group.h:33
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
void mutt_grouplist_clear(struct GroupList *gl)
Clear a GroupList.
Definition: group.c:104
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1381
#define _(a)
Definition: message.h:28
void mutt_grouplist_add_addrlist(struct GroupList *gl, struct AddressList *al)
Add Address list to a GroupList.
Definition: group.c:227
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:606
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, int flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:277
int mutt_grouplist_remove_regex(struct GroupList *gl, const char *s)
Remove matching addresses from a GroupList.
Definition: group.c:301
int mutt_grouplist_remove_addrlist(struct GroupList *gl, struct AddressList *al)
Remove an AddressList from a GroupList.
Definition: group.c:246
static int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a group context.
Definition: init.c:554
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
Group is missing an argument.
Definition: init.c:104
Success: Command worked.
Definition: mutt_commands.h:37
GroupState
Type of email address group.
Definition: init.c:102
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1216
Warning: Help given to the user.
Definition: mutt_commands.h:36
Entry is an address.
Definition: init.c:106
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:158
#define FREE(x)
Definition: memory.h:40
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:322
Entry is a regular expression.
Definition: init.c:105
#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:76
#define MUTT_GROUP
&#39;group&#39; config command
Definition: group.h:32
+ Here is the call graph for this function:

◆ is_function()

static bool is_function ( const char *  name)
static

Is the argument a neomutt function?

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

Definition at line 1203 of file init.c.

1204 {
1205  for (enum MenuType i = 0; i < MENU_MAX; i++)
1206  {
1207  const struct Binding *b = km_get_table(Menus[i].value);
1208  if (!b)
1209  continue;
1210 
1211  for (int j = 0; b[j].name; j++)
1212  if (mutt_str_strcmp(name, b[j].name) == 0)
1213  return true;
1214  }
1215  return false;
1216 }
MenuType
Types of GUI selections.
Definition: keymap.h:69
const char * name
Definition: pgpmicalg.c:45
const char * name
name of the function
Definition: keymap.h:116
const struct Mapping Menus[]
Menu name lookup table.
Definition: keymap.c:62
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1223
Mapping between a user key and a function.
Definition: keymap.h:114
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_ifdef()

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

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

The 'ifdef' command allows conditional elements in the config file. If a given variable, function, command or compile-time symbol exists, then read the rest of the line of config commands. e.g. ifdef sidebar source ~/.neomutt/sidebar.rc

If (data == 1) then it means use the 'ifndef' (if-not-defined) command. e.g. ifndef imap finish

Definition at line 1231 of file init.c.

1233 {
1234  struct Buffer token = mutt_buffer_make(0);
1235 
1237 
1238  // is the item defined as:
1239  bool res = cs_get_elem(Config, buf->data) // a variable?
1240  || feature_enabled(buf->data) // a compiled-in feature?
1241  || is_function(buf->data) // a function?
1242  || mutt_command_get(buf->data) // a command?
1243  || myvar_get(buf->data) // a my_ variable?
1244  || mutt_str_getenv(buf->data); // an environment variable?
1245 
1246  if (!MoreArgs(s))
1247  {
1248  mutt_buffer_printf(err, _("%s: too few arguments"), (data ? "ifndef" : "ifdef"));
1249  return MUTT_CMD_WARNING;
1250  }
1252 
1253  /* ifdef KNOWN_SYMBOL or ifndef UNKNOWN_SYMBOL */
1254  if ((res && (data == 0)) || (!res && (data == 1)))
1255  {
1256  enum CommandResult rc = mutt_parse_rc_line(buf->data, &token, err);
1257  if (rc == MUTT_CMD_ERROR)
1258  {
1259  mutt_error(_("Error: %s"), err->data);
1260  FREE(&token.data);
1261  return MUTT_CMD_ERROR;
1262  }
1263  FREE(&token.data);
1264  return rc;
1265  }
1266  return MUTT_CMD_SUCCESS;
1267 }
static bool is_function(const char *name)
Is the argument a neomutt function?
Definition: init.c:1203
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
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
WHERE struct ConfigSet * Config
Wrapper around the user&#39;s config settings.
Definition: globals.h:41
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const struct Command * mutt_command_get(const char *s)
Get a Command by its name.
Definition: init.c:2624
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:1048
#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:216
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:79
char * data
Pointer to data.
Definition: buffer.h:35
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
Definition: myvar.c:73
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:84
#define FREE(x)
Definition: memory.h:40
enum CommandResult mutt_parse_rc_line(char *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
Definition: init.c:3232
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_ignore()

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

Parse the 'ignore' command - Implements command_t.

Definition at line 1272 of file init.c.

1274 {
1275  do
1276  {
1279  add_to_stailq(&Ignore, buf->data);
1280  } while (MoreArgs(s));
1281 
1282  return MUTT_CMD_SUCCESS;
1283 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:734
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:2655
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:116
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_lists()

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

Parse the 'lists' command - Implements command_t.

Definition at line 1288 of file init.c.

1290 {
1291  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
1292 
1293  do
1294  {
1296 
1297  if (parse_grouplist(&gl, buf, s, data, err) == -1)
1298  goto bail;
1299 
1301 
1302  if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
1303  goto bail;
1304 
1305  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
1306  goto bail;
1307  } while (MoreArgs(s));
1308 
1310  return MUTT_CMD_SUCCESS;
1311 
1312 bail:
1314  return MUTT_CMD_ERROR;
1315 }
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, int flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:277
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
static int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a group context.
Definition: init.c:554
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: email_globals.c:50
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:158
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h: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:76
+ Here is the call graph for this function:

◆ parse_mailboxes()

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

Parse the 'mailboxes' command - Implements command_t.

This is also used by 'virtual-mailboxes'.

Definition at line 1322 of file init.c.

1324 {
1325  while (MoreArgs(s))
1326  {
1327  struct Mailbox *m = mailbox_new();
1328 
1329  if (data & MUTT_NAMED)
1330  {
1332  if (buf->data && (*buf->data != '\0'))
1333  {
1334  m->name = mutt_str_strdup(buf->data);
1335  }
1336  else
1337  {
1338  mailbox_free(&m);
1339  continue;
1340  }
1341  }
1342 
1344  if (mutt_buffer_is_empty(buf))
1345  {
1346  /* Skip empty tokens. */
1347  mailbox_free(&m);
1348  continue;
1349  }
1350 
1351  mutt_buffer_strcpy(&m->pathbuf, buf->data);
1352  /* int rc = */ mx_path_canon2(m, C_Folder);
1353 
1354  if (m->magic <= MUTT_UNKNOWN)
1355  {
1356  mutt_error("Unknown Mailbox: %s", m->realpath);
1357  mailbox_free(&m);
1358  return MUTT_CMD_ERROR;
1359  }
1360 
1361  bool new_account = false;
1362  struct Account *a = mx_ac_find(m);
1363  if (!a)
1364  {
1365  a = account_new(NULL, NeoMutt->sub);
1366  a->magic = m->magic;
1367  new_account = true;
1368  }
1369 
1370  if (!new_account)
1371  {
1372  struct Mailbox *m_old = mx_mbox_find(a, m->realpath);
1373  if (m_old)
1374  {
1375  if (m_old->flags == MB_HIDDEN)
1376  {
1377  m_old->flags = MB_NORMAL;
1378  mutt_sb_notify_mailbox(m_old, true);
1379  }
1380  mailbox_free(&m);
1381  continue;
1382  }
1383  }
1384 
1385  if (mx_ac_add(a, m) < 0)
1386  {
1387  //error
1388  mailbox_free(&m);
1389  if (new_account)
1390  {
1391  cs_subset_free(&a->sub);
1392  FREE(&a->name);
1393  notify_free(&a->notify);
1394  FREE(&a);
1395  }
1396  continue;
1397  }
1398  if (new_account)
1399  {
1401  }
1402 
1403 #ifdef USE_SIDEBAR
1404  mutt_sb_notify_mailbox(m, true);
1405 #endif
1406 #ifdef USE_INOTIFY
1407  mutt_monitor_add(m);
1408 #endif
1409  }
1410  return MUTT_CMD_SUCCESS;
1411 }
char * name
Name of Account.
Definition: account.h:39
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
int mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add()
Definition: mx.c:1572
int mx_path_canon2(struct Mailbox *m, const char *folder)
XXX canonicalise the path to realpath.
Definition: mx.c:1406
struct Notify * notify
Notifications handler.
Definition: account.h:42
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:95
A group of associated Mailboxes.
Definition: account.h:36
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:46
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
XXX.
Definition: mx.c:1509
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:44
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:476
struct Account * mx_ac_find(struct Mailbox *m)
XXX.
Definition: mx.c:1486
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
WHERE char * C_Folder
Config: Base folder for a set of mailboxes.
Definition: globals.h:121
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:2655
char * data
Pointer to data.
Definition: buffer.h:35
#define MUTT_NAMED
Definition: init.h:109
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:69
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 mutt_error(...)
Definition: logging.h:84
#define FREE(x)
Definition: memory.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:38
bool neomutt_account_add(struct NeoMutt *n, struct Account *a)
Add an Account to the global list.
Definition: neomutt.c:83
struct Buffer pathbuf
Definition: mailbox.h:94
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
#define MB_NORMAL
Definition: mailbox.h:36
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_my_hdr()

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

Parse the 'my_hdr' command - Implements command_t.

Definition at line 1416 of file init.c.

1418 {
1419  struct ListNode *n = NULL;
1420  size_t keylen;
1421 
1423  char *p = strpbrk(buf->data, ": \t");
1424  if (!p || (*p != ':'))
1425  {
1426  mutt_buffer_strcpy(err, _("invalid header field"));
1427  return MUTT_CMD_WARNING;
1428  }
1429  keylen = p - buf->data + 1;
1430 
1431  STAILQ_FOREACH(n, &UserHeader, entries)
1432  {
1433  /* see if there is already a field by this name */
1434  if (mutt_str_strncasecmp(buf->data, n->data, keylen) == 0)
1435  {
1436  break;
1437  }
1438  }
1439 
1440  if (!n)
1441  {
1442  /* not found, allocate memory for a new node and add it to the list */
1443  n = mutt_list_insert_tail(&UserHeader, NULL);
1444  }
1445  else
1446  {
1447  /* found, free the existing data */
1448  FREE(&n->data);
1449  }
1450 
1451  n->data = buf->data;
1452  mutt_buffer_init(buf);
1453 
1454  return MUTT_CMD_SUCCESS;
1455 }
#define _(a)
Definition: message.h:28
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:65
#define MUTT_TOKEN_QUOTE
Don&#39;t interpret quotes.
Definition: mutt.h:80
int mutt_str_strncasecmp(const char *a, const char *b, size_t l)
Compare two strings ignoring case (to a maximum), safely.
Definition: string.c:656
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
#define MUTT_TOKEN_SPACE
Don&#39;t treat whitespace as a term.
Definition: mutt.h:79
char * data
Pointer to data.
Definition: buffer.h:35
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Success: Command worked.
Definition: mutt_commands.h:37
char * data
String.
Definition: list.h:35
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define FREE(x)
Definition: memory.h:40
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
A List node for strings.
Definition: list.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_path_list()

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

Parse the 'sidebar_whitelist' command - Implements command_t.

Definition at line 1461 of file init.c.

1463 {
1464  struct Buffer *path = mutt_buffer_pool_get();
1465 
1466  do
1467  {
1470  add_to_stailq((struct ListHead *) data, mutt_b2s(path));
1471  } while (MoreArgs(s));
1472  mutt_buffer_pool_release(&path);
1473 
1474  return MUTT_CMD_SUCCESS;
1475 }
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:100
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:111
String manipulation buffer.
Definition: buffer.h:33
#define MoreArgs(buf)
Definition: buffer.h:43
#define mutt_b2s(buf)
Definition: buffer.h:41
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:343
static void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: init.c:116
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_path_unlist()

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

Parse the 'unsidebar_whitelist' command - Implements command_t.

Definition at line 1482 of file init.c.

1484 {
1485  struct Buffer *path = mutt_buffer_pool_get();
1486 
1487  do
1488  {
1490  /* Check for deletion of entire list */
1491  if (mutt_str_strcmp(mutt_b2s(path), "*") == 0)
1492  {
1493  mutt_list_free((struct ListHead *) data);
1494  break;
1495  }
1497  remove_from_stailq((struct ListHead *) data, mutt_b2s(path));
1498  } while (MoreArgs(s));
1499  mutt_buffer_pool_release(&path);
1500 
1501  return MUTT_CMD_SUCCESS;
1502 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:734
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:100
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:111
String manipulation buffer.
Definition: buffer.h:33
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
#define MoreArgs(buf)
Definition: buffer.h:43
#define mutt_b2s(buf)
Definition: buffer.h:41
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:343
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_set()

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

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

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

Definition at line 1510 of file init.c.

1512 {
1513  /* The order must match `enum MuttSetCommand` */
1514  static const char *set_commands[] = { "set", "toggle", "unset", "reset" };
1515 
1516  int rc = 0;
1517 
1518  while (MoreArgs(s))
1519  {
1520  bool prefix = false;
1521  bool query = false;
1522  bool inv = (data == MUTT_SET_INV);
1523  bool reset = (data == MUTT_SET_RESET);
1524  bool unset = (data == MUTT_SET_UNSET);
1525 
1526  if (*s->dptr == '?')
1527  {
1528  prefix = true;
1529  query = true;
1530  s->dptr++;
1531  }
1532  else if (mutt_str_startswith(s->dptr, "no", CASE_MATCH))
1533  {
1534  prefix = true;
1535  unset = !unset;
1536  s->dptr += 2;
1537  }
1538  else if (mutt_str_startswith(s->dptr, "inv", CASE_MATCH))
1539  {
1540  prefix = true;
1541  inv = !inv;
1542  s->dptr += 3;
1543  }
1544  else if (*s->dptr == '&')
1545  {
1546  prefix = true;
1547  reset = true;
1548  s->dptr++;
1549  }
1550 
1551  if (prefix && (data != MUTT_SET_SET))
1552  {
1553  mutt_buffer_printf(err, "ERR22 can't use 'inv', 'no', '&' or '?' with the '%s' command",
1554  set_commands[data]);
1555  return MUTT_CMD_WARNING;
1556  }
1557 
1558  /* get the variable name */
1560 
1561  bool bq = false;
1562  bool equals = false;
1563 
1564  struct HashElem *he = NULL;
1565  bool my = mutt_str_startswith(buf->data, "my_", CASE_MATCH);
1566  if (!my)
1567  {
1568  he = cs_get_elem(Config, buf->data);
1569  if (!he)
1570  {
1571  if (reset && (mutt_str_strcmp(buf->data, "all") == 0))
1572  {
1573  struct HashElem **list = get_elem_list(Config);
1574  if (!list)
1575  return MUTT_CMD_ERROR;
1576 
1577  for (size_t i = 0; list[i]; i++)
1578  cs_he_reset(Config, list[i], NULL);
1579 
1580  FREE(&list);
1581  break;
1582  }
1583  else
1584  {
1585  mutt_buffer_printf(err, "ERR01 unknown variable: %s", buf->data);
1586  return MUTT_CMD_ERROR;
1587  }
1588  }
1589 
1590  bq = ((DTYPE(he->type) == DT_BOOL) || (DTYPE(he->type) == DT_QUAD));
1591  }
1592 
1593  if (*s->dptr == '?')
1594  {
1595  if (prefix)
1596  {
1597  mutt_buffer_printf(err,
1598  "ERR02 can't use a prefix when querying a variable");
1599  return MUTT_CMD_WARNING;
1600  }
1601 
1602  if (reset || unset || inv)
1603  {
1604  mutt_buffer_printf(err, "ERR03 can't query a variable with the '%s' command",
1605  set_commands[data]);
1606  return MUTT_CMD_WARNING;
1607  }
1608 
1609  query = true;
1610  s->dptr++;
1611  }
1612  else if (*s->dptr == '=')
1613  {
1614  if (prefix)
1615  {
1616  mutt_buffer_printf(err,
1617  "ERR04 can't use prefix when setting a variable");
1618  return MUTT_CMD_WARNING;
1619  }
1620 
1621  if (reset || unset || inv)
1622  {
1623  mutt_buffer_printf(err, "ERR05 can't set a variable with the '%s' command",
1624  set_commands[data]);
1625  return MUTT_CMD_WARNING;
1626  }
1627 
1628  equals = true;
1629  s->dptr++;
1630  }
1631 
1632  if (!bq && (inv || (unset && prefix)))
1633  {
1634  if (data == MUTT_SET_SET)
1635  {
1636  mutt_buffer_printf(err, "ERR06 prefixes 'no' and 'inv' may only be "
1637  "used with bool/quad variables");
1638  }
1639  else
1640  {
1641  mutt_buffer_printf(err, "ERR07 command '%s' can only be used with bool/quad variables",
1642  set_commands[data]);
1643  }
1644  return MUTT_CMD_WARNING;
1645  }
1646 
1647  if (reset)
1648  {
1649  // mutt_buffer_printf(err, "ACT24 reset variable %s", buf->data);
1650  if (he)
1651  {
1652  rc = cs_he_reset(Config, he, err);
1653  if (CSR_RESULT(rc) != CSR_SUCCESS)
1654  return MUTT_CMD_ERROR;
1655  }
1656  else
1657  {
1658  myvar_del(buf->data);
1659  }
1660  continue;
1661  }
1662 
1663  if ((data == MUTT_SET_SET) && !inv && !unset)
1664  {
1665  if (query)
1666  {
1667  // mutt_buffer_printf(err, "ACT08 query variable %s", buf->data);
1668  if (he)
1669  {
1670  mutt_buffer_addstr(err, buf->data);
1671  mutt_buffer_addch(err, '=');
1672  mutt_buffer_reset(buf);
1673  rc = cs_he_string_get(Config, he, buf);
1674  if (CSR_RESULT(rc) != CSR_SUCCESS)
1675  {
1676  mutt_buffer_addstr(err, buf->data);
1677  return MUTT_CMD_ERROR;
1678  }
1679  pretty_var(buf->data, err);
1680  }
1681  else
1682  {
1683  const char *val = myvar_get(buf->data);
1684  if (val)
1685  {
1686  mutt_buffer_addstr(err, buf->data);
1687  mutt_buffer_addch(err, '=');
1688  pretty_var(val, err);
1689  }
1690  else
1691  {
1692  mutt_buffer_printf(err, _("%s: unknown variable"), buf->data);
1693  return MUTT_CMD_ERROR;
1694  }
1695  }
1696  break;
1697  }
1698  else if (equals)
1699  {
1700  // mutt_buffer_printf(err, "ACT11 set variable %s to ", buf->data);
1701  const char *name = NULL;
1702  if (my)
1703  {
1704  name = mutt_str_strdup(buf->data);
1705  }
1707  if (my)
1708  {
1709  myvar_set(name, buf->data);
1710  FREE(&name);
1711  }
1712  else
1713  {
1714  if (IS_PATH(he))
1715  {
1717  struct Buffer scratch = mutt_buffer_make(1024);
1718  mutt_buffer_copy(&scratch, buf);
1719  size_t scratchlen = mutt_buffer_len(&scratch);
1720  if (!(he->type & DT_MAILBOX) && (scratchlen != 0))
1721  {
1722  if ((mutt_b2s(&scratch)[scratchlen - 1] != '|') && /* not a command */
1723  (url_check_scheme(mutt_b2s(&scratch)) == U_UNKNOWN)) /* probably a local file */
1724  {
1725  struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
1726  if (mutt_path_to_absolute(scratch.data, np ? NONULL(np->data) : "./"))
1727  {
1728  mutt_buffer_reset(buf);
1729  mutt_buffer_addstr(buf, mutt_b2s(&scratch));
1730  }
1731  else
1732  {
1733  mutt_error(_("Error: Can't build path of '%s'"), mutt_b2s(&scratch));
1734  }
1735  }
1736  }
1737  mutt_buffer_dealloc(&scratch);
1738  }
1739  else if (IS_COMMAND(he))
1740  {
1741  struct Buffer scratch = mutt_buffer_make(1024);
1742  mutt_buffer_copy(&scratch, buf);
1743 
1744  if (mutt_str_strcmp(buf->data, "builtin") != 0)
1745  {
1746  mutt_buffer_expand_path(&scratch);
1747  }
1748  mutt_buffer_reset(buf);
1749  mutt_buffer_addstr(buf, mutt_b2s(&scratch));
1750  mutt_buffer_dealloc(&scratch);
1751  }
1752 
1753  rc = cs_he_string_set(Config, he, buf->data, err);
1754  if (CSR_RESULT(rc) != CSR_SUCCESS)
1755  return MUTT_CMD_ERROR;
1756  }
1757  continue;
1758  }
1759  else
1760  {
1761  if (bq)
1762  {
1763  // mutt_buffer_printf(err, "ACT23 set variable %s to 'yes'", buf->data);
1764  rc = cs_he_native_set(Config, he, true, err);
1765  if (CSR_RESULT(rc) != CSR_SUCCESS)
1766  return MUTT_CMD_ERROR;
1767  continue;
1768  }
1769  else
1770  {
1771  // mutt_buffer_printf(err, "ACT10 query variable %s", buf->data);
1772  if (he)
1773  {
1774  mutt_buffer_addstr(err, buf->data);
1775  mutt_buffer_addch(err, '=');
1776  mutt_buffer_reset(buf);
1777  rc = cs_he_string_get(Config, he, buf);
1778  if (CSR_RESULT(rc) != CSR_SUCCESS)
1779  {
1780  mutt_buffer_addstr(err, buf->data);
1781  return MUTT_CMD_ERROR;
1782  }
1783  pretty_var(buf->data, err);
1784  }
1785  else
1786  {
1787  const char *val = myvar_get(buf->data);
1788  if (val)
1789  {
1790  mutt_buffer_addstr(err, buf->data);
1791  mutt_buffer_addch(err, '=');
1792  pretty_var(val, err);
1793  }
1794  else
1795  {
1796  mutt_buffer_printf(err, _("%s: unknown variable"), buf->data);
1797  return MUTT_CMD_ERROR;
1798  }
1799  }
1800  break;
1801  }
1802  }
1803  }
1804 
1805  if (my)
1806  {
1807  myvar_del(buf->data);
1808  }
1809  else if (bq)
1810  {
1811  if (inv)
1812  {
1813  // mutt_buffer_printf(err, "ACT25 TOGGLE bool/quad variable %s", buf->data);
1814  if (DTYPE(he->type) == DT_BOOL)
1815  bool_he_toggle(Config, he, err);
1816  else
1817  quad_he_toggle(Config, he, err);
1818  }
1819  else
1820  {
1821  // mutt_buffer_printf(err, "ACT26 UNSET bool/quad variable %s", buf->data);
1822  rc = cs_he_native_set(Config, he, false, err);
1823  if (CSR_RESULT(rc) != CSR_SUCCESS)
1824  return MUTT_CMD_ERROR;
1825  }
1826  continue;
1827  }
1828  else
1829  {
1830  rc = cs_he_string_set(Config, he, NULL, err);
1831  if (CSR_RESULT(rc) != CSR_SUCCESS)
1832  return MUTT_CMD_ERROR;
1833  }
1834  }
1835 
1836  return MUTT_CMD_SUCCESS;
1837 }
#define NONULL(x)
Definition: string2.h:37
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
#define IS_PATH(x)
Definition: types.h:55
#define CSR_RESULT(x)
Definition: set.h:62
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer&#39;s contents to another Buffer.
Definition: buffer.c:445
static struct ListHead MuttrcStack
Definition: init.c:77
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
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:41
Match case when comparing strings.
Definition: string2.h:67
struct HashElem ** get_elem_list(struct ConfigSet *cs)
Create a sorted list of all config items.
Definition: dump.c:118
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
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
#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:375
default is to invert all vars
Definition: init.h:103
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
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:721
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:216
void myvar_del(const char *var)
Unset the value of a "my_" variable.
Definition: myvar.c:112
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
void myvar_set(const char *var, const char *val)
Set the value of a "my_" variable.
Definition: myvar.c:91
#define mutt_b2s(buf)
Definition: buffer.h:41
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:356
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
#define DT_MAILBOX
Don&#39;t perform path expansions.
Definition: types.h:47
bool mutt_path_to_absolute(char *path, const char *reference)
Convert relative filepath to an absolute path.
Definition: path.c:375
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
default is to reset all vars to default
Definition: init.h:105
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
Definition: myvar.c:73
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
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:650
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
String.
Definition: list.h:35
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:343
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:84
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:77
#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:576
#define MUTT_TOKEN_QUESTION
Treat &#39;?&#39; as a special.
Definition: mutt.h:86
+ Here is the call graph for this function:

◆ parse_setenv()

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

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

Definition at line 1842 of file init.c.

1844 {
1845  char **envp = mutt_envlist_getlist();
1846 
1847  bool query = false;
1848  bool unset = (data == MUTT_SET_UNSET);
1849 
1850  if (!MoreArgs(s))
1851  {
1852  mutt_buffer_printf(err, _("%s: too few arguments"), "setenv");
1853  return MUTT_CMD_WARNING;
1854  }
1855 
1856  if (*s->dptr == '?')
1857  {
1858  query = true;
1859  s->dptr++;
1860  }
1861 
1862  /* get variable name */
1864 
1865  if (query)
1866  {
1867  bool found = false;
1868  while (envp && *envp)
1869  {
1870  /* This will display all matches for "^QUERY" */
1871  if (mutt_str_startswith(*envp, buf->data, CASE_MATCH))
1872  {
1873  if (!found)
1874  {
1875  mutt_endwin();
1876  found = true;
1877  }
1878  puts(*envp);
1879  }
1880  envp++;
1881  }
1882 
1883  if (found)
1884  {
1886  return MUTT_CMD_SUCCESS;
1887  }
1888 
1889  mutt_buffer_printf(err, _("%s is unset"), buf->data);
1890  return MUTT_CMD_WARNING;
1891  }
1892 
1893  if (unset)
1894  {
1895  if (mutt_envlist_unset(buf->data))
1896  return MUTT_CMD_SUCCESS;
1897  return MUTT_CMD_ERROR;
1898  }
1899 
1900  /* set variable */
1901 
1902  if (*s->dptr == '=')
1903  {
1904  s->dptr++;
1905  SKIPWS(s->dptr);
1906  }
1907 
1908  if (!MoreArgs(s))
1909  {
1910  mutt_buffer_printf(err, _("%s: too few arguments"), "setenv");
1911  return MUTT_CMD_WARNING;
1912  }
1913 
1914  char *name = mutt_str_strdup(buf->data);
1916  mutt_envlist_set(name, buf->data, true);
1917  FREE(&name);
1918 
1919  return MUTT_CMD_SUCCESS;
1920 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define _(a)
Definition: message.h:28
Match case when comparing strings.
Definition: string2.h:67
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:43
const char * name
Definition: pgpmicalg.c:45
#define SKIPWS(ch)
Definition: string2.h:47
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:544
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:2655
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:577
default is to unset all vars
Definition: init.h:104
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
bool mutt_envlist_set(const char *name, const char *value, bool overwrite)
Set an environment variable.
Definition: envlist.c:84
#define MUTT_TOKEN_EQUAL
Treat &#39;=&#39; as a special.
Definition: mutt.h:77
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
char ** mutt_envlist_getlist(void)
Get the private environment.
Definition: envlist.c:168
+ Here is the call graph for this function:

◆ parse_source()

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

Parse the 'source' command - Implements command_t.

Definition at line 1925 of file init.c.

1927 {
1928  char path[PATH_MAX];
1929 
1930  do
1931  {
1932  if (mutt_extract_token(buf, s, MUTT_TOKEN_NO_FLAGS) != 0)
1933  {
1934  mutt_buffer_printf(err, _("source: error at %s"), s->dptr);
1935  return MUTT_CMD_ERROR;
1936  }
1937  mutt_str_strfcpy(path, buf->data, sizeof(path));
1938  mutt_expand_path(path, sizeof(path));
1939 
1940  if (source_rc(path, err) < 0)
1941  {
1942  mutt_buffer_printf(err, _("source: file %s could not be sourced"), path);
1943  return MUTT_CMD_ERROR;
1944  }
1945 
1946  } while (MoreArgs(s));
1947 
1948  return MUTT_CMD_SUCCESS;
1949 }
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:760
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:134
#define MoreArgs(buf)
Definition: buffer.h:43
#define PATH_MAX
Definition: mutt.h:50
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
Success: Command worked.
Definition: mutt_commands.h:37
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_spam_list()

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

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

Definition at line 1954 of file init.c.

1956 {
1957  struct Buffer templ;
1958 
1959  mutt_buffer_init(&templ);
1960 
1961  /* Insist on at least one parameter */
1962  if (!MoreArgs(s))
1963  {
1964  if (data == MUTT_SPAM)
1965  mutt_buffer_strcpy(err, _("spam: no matching pattern"));
1966  else
1967  mutt_buffer_strcpy(err, _("nospam: no matching pattern"));
1968  return MUTT_CMD_ERROR;
1969  }
1970 
1971  /* Extract the first token, a regex */
1973 
1974  /* data should be either MUTT_SPAM or MUTT_NOSPAM. MUTT_SPAM is for spam commands. */
1975  if (data == MUTT_SPAM)
1976  {
1977  /* If there's a second parameter, it's a template for the spam tag. */
1978  if (MoreArgs(s))
1979  {
1981 
1982  /* Add to the spam list. */
1983  if (mutt_replacelist_add(&SpamList, buf->data, templ.data, err) != 0)
1984  {
1985  FREE(&templ.data);
1986  return MUTT_CMD_ERROR;
1987  }
1988  FREE(&templ.data);
1989  }
1990  /* If not, try to remove from the nospam list. */
1991  else
1992  {
1994  }
1995 
1996  return MUTT_CMD_SUCCESS;
1997  }
1998  /* MUTT_NOSPAM is for nospam commands. */
1999  else if (data == MUTT_NOSPAM)
2000  {
2001  /* nospam only ever has one parameter. */
2002 
2003  /* "*" is a special case. */
2004  if (mutt_str_strcmp(buf->data, "*") == 0)
2005  {
2008  return MUTT_CMD_SUCCESS;
2009  }
2010 
2011  /* If it's on the spam list, just remove it. */
2012  if (mutt_replacelist_remove(&SpamList, buf->data) != 0)
2013  return MUTT_CMD_SUCCESS;
2014 
2015  /* Otherwise, add it to the nospam list. */
2016  if (mutt_regexlist_add(&NoSpamList, buf->data, REG_ICASE, err) != 0)
2017  return MUTT_CMD_ERROR;
2018 
2019  return MUTT_CMD_SUCCESS;
2020  }
2021 
2022  /* This should not happen. */
2023  mutt_buffer_strcpy(err, "This is no good at all.");
2024  return MUTT_CMD_ERROR;
2025 }
int mutt_replacelist_add(struct ReplaceList *rl, const char *pat, const char *templ, struct Buffer *err)
Add a pattern and a template to a list.
Definition: regex.c:262
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define MUTT_NOSPAM
Definition: mutt.h:119
struct ReplaceList SpamList
List of regexes and patterns to match spam emails.
Definition: email_globals.c:44
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:447
#define MoreArgs(buf)
Definition: buffer.h:43
#define MUTT_SPAM
Definition: mutt.h:118
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Success: Command worked.
Definition: mutt_commands.h:37
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:564
#define FREE(x)
Definition: memory.h:40
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
Definition: email_globals.c:43
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:170
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_stailq()

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

Parse a list command - Implements command_t.

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

Definition at line 2032 of file init.c.

2034 {
2035  do
2036  {
2038  add_to_stailq((struct ListHead *) data, buf->data);
2039  } while (MoreArgs(s));
2040 
2041  return MUTT_CMD_SUCCESS;
2042 }
#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:2655
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:116
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_subjectrx_list()

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

Parse the 'subjectrx' command - Implements command_t.

Definition at line 2047 of file init.c.

2049 {
2050  enum CommandResult rc;
2051 
2052  rc = parse_replace_list(buf, s, data, err);
2053  if (rc == MUTT_CMD_SUCCESS)
2055  return rc;
2056 }
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:584
static void clear_subject_mods(void)
Clear out all modified email subjects.
Definition: init.c:209
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
+ Here is the call graph for this function:

◆ parse_subscribe()

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

Parse the 'subscribe' command - Implements command_t.

Definition at line 2061 of file init.c.

2063 {
2064  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
2065 
2066  do
2067  {
2069 
2070  if (parse_grouplist(&gl, buf, s, data, err) == -1)
2071  goto bail;
2072 
2075 
2076  if (mutt_regexlist_add(&MailLists, buf->data, REG_ICASE, err) != 0)
2077  goto bail;
2078  if (mutt_regexlist_add(&SubscribedLists, buf->data, REG_ICASE, err) != 0)
2079  goto bail;
2080  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
2081  goto bail;
2082  } while (MoreArgs(s));
2083 
2085  return MUTT_CMD_SUCCESS;
2086 
2087 bail:
2089  return MUTT_CMD_ERROR;
2090 }
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:226
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, int flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:277
int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
static int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse a group context.
Definition: init.c:554
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: email_globals.c:50
char * data
Pointer to data.
Definition: buffer.h:35
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: email_globals.c:52
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:158
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h: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:76
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
Definition: email_globals.c:49
+ Here is the call graph for this function:

◆ parse_subscribe_to()

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

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

The 'subscribe-to' command allows to subscribe to an IMAP-Mailbox. Patterns are not supported. Use it as follows: subscribe-to =folder

Definition at line 2100 of file init.c.

2102 {
2103  if (!buf || !s || !err)
2104  return MUTT_CMD_ERROR;
2105 
2106  mutt_buffer_reset(err);
2107 
2108  if (MoreArgs(s))
2109  {
2111 
2112  if (MoreArgs(s))
2113  {
2114  mutt_buffer_printf(err, _("%s: too many arguments"), "subscribe-to");
2115  return MUTT_CMD_WARNING;
2116  }
2117 
2118  if (buf->data && (*buf->data != '\0'))
2119  {
2120  /* Expand and subscribe */
2121  if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), true) == 0)
2122  {
2123  mutt_message(_("Subscribed to %s"), buf->data);
2124  return MUTT_CMD_SUCCESS;
2125  }
2126 
2127  mutt_buffer_printf(err, _("Could not subscribe to %s"), buf->data);
2128  return MUTT_CMD_ERROR;
2129  }
2130 
2131  mutt_debug(LL_DEBUG1, "Corrupted buffer");
2132  return MUTT_CMD_ERROR;
2133  }
2134 
2135  mutt_buffer_addstr(err, _("No folder specified"));
2136  return MUTT_CMD_WARNING;
2137 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
size_t dsize
Length of data.
Definition: buffer.h:37
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:134
#define MoreArgs(buf)
Definition: buffer.h:43
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
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:76
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1382
+ Here is the call graph for this function:

◆ parse_tag_formats()

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

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

Definition at line 2143 of file init.c.

2145 {
2146  if (!buf || !s)
2147  return MUTT_CMD_ERROR;
2148 
2149  char *tmp = NULL;
2150 
2151  while (MoreArgs(s))
2152  {
2153  char *tag = NULL, *format = NULL;
2154 
2156  if (buf->data && (*buf->data != '\0'))
2157  tag = mutt_str_strdup(buf->data);
2158  else
2159  continue;
2160 
2162  format = mutt_str_strdup(buf->data);
2163 
2164  /* avoid duplicates */
2165  tmp = mutt_hash_find(TagFormats, format);
2166  if (tmp)
2167  {
2168  mutt_debug(LL_DEBUG3, "tag format '%s' already registered as '%s'\n", format, tmp);
2169  FREE(&tag);
2170  FREE(&format);
2171  continue;
2172  }
2173 
2174  mutt_hash_insert(TagFormats, format, tag);
2175  }
2176  return MUTT_CMD_SUCCESS;
2177 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
void * mutt_hash_find(const struct Hash *table, const char *strkey)
Find the HashElem data in a Hash table element using a key.
Definition: hash.c:378
WHERE struct Hash * TagFormats
Hash table of tag-formats (tag -> format string)
Definition: globals.h:62
#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:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct HashElem * mutt_hash_insert(struct Hash *table, const char *strkey, void *data)
Add a new element to the Hash table (with string keys)
Definition: hash.c:351
Log at debug level 3.
Definition: logging.h:58
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_tag_transforms()

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

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

Definition at line 2182 of file init.c.

2184 {
2185  if (!buf || !s)
2186  return MUTT_CMD_ERROR;
2187 
2188  char *tmp = NULL;
2189 
2190  while (MoreArgs(s))
2191  {
2192  char *tag = NULL, *transform = NULL;
2193 
2195  if (buf->data && (*buf->data != '\0'))
2196  tag = mutt_str_strdup(buf->data);
2197  else
2198  continue;
2199 
2201  transform = mutt_str_strdup(buf->data);
2202 
2203  /* avoid duplicates */
2204  tmp = mutt_hash_find(TagTransforms, tag);
2205  if (tmp)
2206  {
2207  mutt_debug(LL_DEBUG3, "tag transform '%s' already registered as '%s'\n", tag, tmp);
2208  FREE(&tag);
2209  FREE(&transform);
2210  continue;
2211  }
2212 
2213  mutt_hash_insert(TagTransforms, tag, transform);
2214  }
2215  return MUTT_CMD_SUCCESS;
2216 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
struct Hash * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
void * mutt_hash_find(const struct Hash *table, const char *strkey)
Find the HashElem data in a Hash table element using a key.
Definition: hash.c:378
#define MoreArgs(buf)
Definition: buffer.h:43
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct HashElem * mutt_hash_insert(struct Hash *table, const char *strkey, void *data)
Add a new element to the Hash table (with string keys)
Definition: hash.c:351
Log at debug level 3.
Definition: logging.h:58
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unalias()

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

Parse the 'unalias' command - Implements command_t.

Definition at line 2221 of file init.c.

2223 {
2224  struct Alias *a = NULL;
2225 
2226  do
2227  {
2229 
2230  if (mutt_str_strcmp("*", buf->data) == 0)
2231  {
2232  if (CurrentMenu == MENU_ALIAS)
2233  {
2234  TAILQ_FOREACH(a, &Aliases, entries)
2235  {
2236  a->del = true;
2237  }
2239  }
2240  else
2241  mutt_aliaslist_free(&Aliases);
2242  break;
2243  }
2244  else
2245  {
2246  TAILQ_FOREACH(a, &Aliases, entries)
2247  {
2248  if (mutt_str_strcasecmp(buf->data, a->name) == 0)
2249  {
2250  if (CurrentMenu == MENU_ALIAS)
2251  {
2252  a->del = true;
2254  }
2255  else
2256  {
2257  TAILQ_REMOVE(&Aliases, a, entries);
2258  mutt_alias_free(&a);
2259  }
2260  break;
2261  }
2262  }
2263  }
2264  } while (MoreArgs(s));
2265  return MUTT_CMD_SUCCESS;
2266 }
A shortcut for an email address.
Definition: alias.h:37
char * name
Short name.
Definition: alias.h:39
void mutt_aliaslist_free(struct AliasList *a_list)
Free a List of Aliases.
Definition: alias.c:758
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:84
#define MoreArgs(buf)
Definition: buffer.h:43
bool del
Is it deleted?
Definition: alias.h:42
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:821
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
void mutt_alias_free(struct Alias **ptr)
Free an Alias.
Definition: alias.c:741
char * data
Pointer to data.
Definition: buffer.h:35
Select an email address by its alias.
Definition: keymap.h:71
Success: Command worked.
Definition: mutt_commands.h:37
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unalternates()

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

Parse the 'unalternates' command - Implements command_t.

Definition at line 2271 of file init.c.

2273 {
2274  alternates_clean();
2275  do
2276  {
2278  mutt_regexlist_remove(&Alternates, buf->data);
2279 
2280  if ((mutt_str_strcmp(buf->data, "*") != 0) &&
2281  (mutt_regexlist_add(&UnAlternates, buf->data, REG_ICASE, err) != 0))
2282  {
2283  return MUTT_CMD_ERROR;
2284  }
2285 
2286  } while (MoreArgs(s));
2287 
2288  return MUTT_CMD_SUCCESS;
2289 }
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:137
#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:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ mutt_attachmatch_free()

void mutt_attachmatch_free ( struct AttachMatch **  ptr)

Free an AttachMatch - Implements list_free_t.

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

Definition at line 2298 of file init.c.

2299 {
2300  if (!ptr || !*ptr)
2301  return;
2302 
2303  struct AttachMatch *am = *ptr;
2304  regfree(&am->minor_regex);
2305  FREE(&am->major);
2306  FREE(ptr);
2307 }
const char * major
Definition: mutt_parse.h:37
regex_t minor_regex
Definition: mutt_parse.h:40
#define FREE(x)
Definition: memory.h:40
An attachment matching a regex for attachment counter.
Definition: mutt_parse.h:35
+ Here is the caller graph for this function:

◆ parse_unattachments()

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

Parse the 'unattachments' command - Implements command_t.

Definition at line 2312 of file init.c.

2314 {
2315  char op;
2316  char *p = NULL;
2317  struct ListHead *head = NULL;
2318 
2320  if (!buf->data || (*buf->data == '\0'))
2321  {
2322  mutt_buffer_strcpy(err, _("unattachments: no disposition"));
2323  return MUTT_CMD_WARNING;
2324  }
2325 
2326  p = buf->data;
2327  op = *p++;
2328 
2329  if (op == '*')
2330  {
2336  return 0;
2337  }
2338 
2339  if ((op != '+') && (op != '-'))
2340  {
2341  op = '+';
2342  p--;
2343  }
2344  if (mutt_str_startswith("attachment", p, CASE_IGNORE))
2345  {
2346  if (op == '+')
2347  head = &AttachAllow;
2348  else
2349  head = &AttachExclude;
2350  }
2351  else if (mutt_str_startswith("inline", p, CASE_IGNORE))
2352  {
2353  if (op == '+')
2354  head = &InlineAllow;
2355  else
2356  head = &InlineExclude;
2357  }
2358  else
2359  {
2360  mutt_buffer_strcpy(err, _("unattachments: invalid disposition"));
2361  return MUTT_CMD_ERROR;
2362  }
2363 
2364  return parse_unattach_list(buf, s, head, err);
2365 }
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:624
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
struct ListHead InlineAllow
List of inline types to counted.
Definition: mutt_parse.c:41
void mutt_list_free_type(struct ListHead *h, list_free_t fn)
Free a List of type.
Definition: list.c:145
#define _(a)
Definition: message.h:28
static void attachments_clean(void)
always wise to do what someone else did before
Definition: init.c:149
void mutt_attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t.
Definition: init.c:2298
struct ListHead InlineExclude
List of inline types to ignore.
Definition: mutt_parse.c:42
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
char * data
Pointer to data.
Definition: buffer.h:35
Ignore case when comparing strings.
Definition: string2.h:68
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: mutt_parse.c:40
Warning: Help given to the user.
Definition: mutt_commands.h:36
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: mutt_parse.c:39
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
void(* list_free_t)(void **ptr)
typedef list_free_t - Prototype for a function to free List data
Definition: list.h:44
+ Here is the call graph for this function:

◆ parse_unignore()

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

Parse the 'unignore' command - Implements command_t.

Definition at line 2370 of file init.c.

2372 {
2373  do
2374  {
2376 
2377  /* don't add "*" to the unignore list */
2378  if (strcmp(buf->data, "*") != 0)
2379  add_to_stailq(&UnIgnore, buf->data);
2380 
2381  remove_from_stailq(&Ignore, buf->data);
2382  } while (MoreArgs(s));
2383 
2384  return MUTT_CMD_SUCCESS;
2385 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:734
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:2655
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:116
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unlists()

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

Parse the 'unlists' command - Implements command_t.

Definition at line 2390 of file init.c.

2392 {
2394  do
2395  {
2399 
2400  if ((mutt_str_strcmp(buf->data, "*") != 0) &&
2401  (mutt_regexlist_add(&UnMailLists, buf->data, REG_ICASE, err) != 0))
2402  {
2403  return MUTT_CMD_ERROR;
2404  }
2405  } while (MoreArgs(s));
2406 
2407  return MUTT_CMD_SUCCESS;
2408 }
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:2655
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:471
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unmailboxes()

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

Parse the 'unmailboxes' command - Implements command_t.

This is also used by 'unvirtual-mailboxes'

Definition at line 2415 of file init.c.

2417 {
2418  bool tmp_valid = false;
2419  bool clear_all = false;
2420 
2421  while (!clear_all && MoreArgs(s))
2422  {
2424 
2425  if (mutt_str_strcmp(buf->data, "*") == 0)
2426  {
2427  clear_all = true;
2428  tmp_valid = false;
2429  }
2430  else
2431  {
2433  tmp_valid = true;
2434  }
2435 
2436  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
2437  struct MailboxNode *np = NULL;
2438  struct MailboxNode *nptmp = NULL;
2439  STAILQ_FOREACH_SAFE(np, &ml, entries, nptmp)
2440  {
2441  /* Decide whether to delete all normal mailboxes or all virtual */
2442  bool virt = ((np->mailbox->magic == MUTT_NOTMUCH) && (data & MUTT_VIRTUAL));
2443  bool norm = ((np->mailbox->magic != MUTT_NOTMUCH) && !(data & MUTT_VIRTUAL));
2444  bool clear_this = clear_all && (virt || norm);
2445 
2446  /* Compare against path or desc? Ensure 'buf' is valid */
2447  if (!clear_this && tmp_valid)
2448  {
2449  clear_this =
2450  (mutt_str_strcasecmp(mutt_b2s(buf), mailbox_path(np->mailbox)) == 0) ||
2451  (mutt_str_strcasecmp(mutt_b2s(buf), np->mailbox->name) == 0);
2452  }
2453 
2454  if (clear_this)
2455  {
2456 #ifdef USE_SIDEBAR
2457  mutt_sb_notify_mailbox(np->mailbox, false);
2458 #endif
2459 #ifdef USE_INOTIFY
2461 #endif
2462  if (Context && (Context->mailbox == np->mailbox))
2463  {
2464  np->mailbox->flags |= MB_HIDDEN;
2465  }
2466  else
2467  {
2469  mailbox_free(&np->mailbox);
2470  }
2471  }
2472  }
2474  }
2475  return MUTT_CMD_SUCCESS;
2476 }
The "current" mailbox.
Definition: context.h:36
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:194
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:521
Match any Mailbox type.
Definition: mailbox.h:44
Container for Accounts, Notifications.
Definition: neomutt.h:35
#define MoreArgs(buf)
Definition: buffer.h:43
char * name
A short name for the Mailbox.
Definition: mailbox.h:96
struct Mailbox * mailbox
Definition: context.h:50
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:55
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:2655
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
Success: Command worked.
Definition: mutt_commands.h:37
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:343
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:84
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:76
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:158
+ Here is the call graph for this function:

◆ parse_unmy_hdr()

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

Parse the 'unmy_hdr' command - Implements command_t.

Definition at line 2481 of file init.c.

2483 {
2484  struct ListNode *np = NULL, *tmp = NULL;
2485  size_t l;
2486 
2487  do
2488  {
2490  if (mutt_str_strcmp("*", buf->data) == 0)
2491  {
2492  mutt_list_free(&UserHeader);
2493  continue;
2494  }
2495 
2496  l = mutt_str_strlen(buf->data);
2497  if (buf->data[l - 1] == ':')
2498  l--;
2499 
2500  STAILQ_FOREACH_SAFE(np, &UserHeader, entries, tmp)
2501  {
2502  if ((mutt_str_strncasecmp(buf->data, np->data, l) == 0) && (np->data[l] == ':'))
2503  {
2504  STAILQ_REMOVE(&UserHeader, np, ListNode, entries);
2505  FREE(&np->data);
2506  FREE(&np);
2507  }
2508  }
2509  } while (MoreArgs(s));
2510  return MUTT_CMD_SUCCESS;
2511 }
#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:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * data
String.
Definition: list.h:35
#define FREE(x)
Definition: memory.h:40
A List node for strings.
Definition: list.h:33
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unstailq()

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

Parse an unlist command - Implements command_t.

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

Definition at line 2518 of file init.c.

2520 {
2521  do
2522  {
2524  /* Check for deletion of entire list */
2525  if (mutt_str_strcmp(buf->data, "*") == 0)
2526  {
2527  mutt_list_free((struct ListHead *) data);
2528  break;
2529  }
2530  remove_from_stailq((struct ListHead *) data, buf->data);
2531  } while (MoreArgs(s));
2532 
2533  return MUTT_CMD_SUCCESS;
2534 }
static void remove_from_stailq(struct ListHead *head, const char *str)
Remove an item, matching a string, from a List.
Definition: init.c:734
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:2655
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
char * data
String.
Definition: list.h:35
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
+ Here is the call graph for this function:

◆ parse_unsubjectrx_list()

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

Parse the 'unsubjectrx' command - Implements command_t.

Definition at line 2539 of file init.c.

2541 {
2542  enum CommandResult rc;
2543 
2544  rc = parse_unreplace_list(buf, s, data, err);
2545  if (rc == MUTT_CMD_SUCCESS)
2547  return rc;
2548 }
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:209
Success: Command worked.
Definition: mutt_commands.h:37
char * data
String.
Definition: list.h:35
static enum CommandResult parse_unreplace_list(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Remove a string replacement rule - Implements command_t.
Definition: init.c:682
+ Here is the call graph for this function:

◆ parse_unsubscribe()

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

Parse the 'unsubscribe' command - Implements command_t.

Definition at line 2553 of file init.c.

2555 {
2557  do
2558  {
2561 
2562  if ((mutt_str_strcmp(buf->data, "*") != 0) &&
2563  (mutt_regexlist_add(&UnSubscribedLists, buf->data, REG_ICASE, err) != 0))
2564  {
2565  return MUTT_CMD_ERROR;
2566  }
2567  } while (MoreArgs(s));
2568 
2569  return MUTT_CMD_SUCCESS;
2570 }
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:2655
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:471
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:76
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
Definition: email_globals.c:49
+ Here is the call graph for this function:

◆ parse_unsubscribe_from()

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

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

The 'unsubscribe-from' command allows to unsubscribe from an IMAP-Mailbox. Patterns are not supported. Use it as follows: unsubscribe-from =folder

Definition at line 2580 of file init.c.

2582 {
2583  if (!buf || !s || !err)
2584  return MUTT_CMD_ERROR;
2585 
2586  if (MoreArgs(s))
2587  {
2589 
2590  if (MoreArgs(s))
2591  {
2592  mutt_buffer_printf(err, _("%s: too many arguments"), "unsubscribe-from");
2593  return MUTT_CMD_WARNING;
2594  }
2595 
2596  if (buf->data && (*buf->data != '\0'))
2597  {
2598  /* Expand and subscribe */
2599  if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), false) == 0)
2600  {
2601  mutt_message(_("Unsubscribed from %s"), buf->data);
2602  return MUTT_CMD_SUCCESS;
2603  }
2604 
2605  mutt_buffer_printf(err, _("Could not unsubscribe from %s"), buf->data);
2606  return MUTT_CMD_ERROR;
2607  }
2608 
2609  mutt_debug(LL_DEBUG1, "Corrupted buffer");
2610  return MUTT_CMD_ERROR;
2611  }
2612 
2613  mutt_buffer_addstr(err, _("No folder specified"));
2614  return MUTT_CMD_WARNING;
2615 }
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
size_t dsize
Length of data.
Definition: buffer.h:37
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:134
#define MoreArgs(buf)
Definition: buffer.h:43
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:2655
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:76
int imap_subscribe(char *path, bool subscribe)
Subscribe to a mailbox.
Definition: imap.c:1382
+ Here is the call graph for this function:

◆ mutt_command_get()

const struct Command* mutt_command_get ( const char *  s)

Get a Command by its name.

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

Definition at line 2624 of file init.c.

2625 {
2626  for (int i = 0; Commands[i].name; i++)
2627  if (mutt_str_strcmp(s, Commands[i].name) == 0)
2628  return &Commands[i];
2629  return NULL;
2630 }
const char * name
Name of the command.
Definition: mutt_commands.h:56
const struct Command Commands[]
Definition: init.h:4982
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:

◆ mutt_extract_token()

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

Extract one token from a string.

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

Definition at line 2655 of file init.c.

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

◆ mutt_opts_free()

void mutt_opts_free ( void  )

clean up before quitting

Definition at line 2890 of file init.c.

2891 {
2893 
2894  FREE(&Matches);
2895 
2896  mutt_aliaslist_free(&Aliases);
2897 
2898  mutt_regexlist_free(&Alternates);
2902  mutt_regexlist_free(&UnAlternates);
2905 
2910 
2911  /* Lists of strings */
2912  mutt_list_free(&AlternativeOrderList);
2913  mutt_list_free(&AutoViewList);
2914  mutt_list_free(&HeaderOrderList);
2917  mutt_list_free(&MimeLookupList);
2918  mutt_list_free(&Muttrc);
2920 #ifdef USE_SIDEBAR
2921  mutt_list_free(&SidebarWhitelist);
2922 #endif
2924  mutt_list_free(&UserHeader);
2925 
2926  /* Lists of AttachMatch */
2931 
2933 
2934  FREE(&CurrentFolder);
2935  FREE(&HomeDir);
2936  FREE(&LastFolder);
2937  FREE(&ShortHostname);
2938  FREE(&Username);
2939 
2942 
2944 
2945  mutt_hist_free();
2946  mutt_keys_free();
2947 
2949 }
WHERE char * Username
User&#39;s login name.
Definition: globals.h:54
void mutt_aliaslist_free(struct AliasList *a_list)
Free a List of Aliases.
Definition: alias.c:758
struct Hash * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
struct ListHead InlineAllow
List of inline types to counted.
Definition: mutt_parse.c:41
static struct ListHead MuttrcStack
Definition: init.c:77
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:62
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
Definition: hook.c:302
WHERE char * LastFolder
Previously selected mailbox.
Definition: globals.h:57
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:51
WHERE char * CurrentFolder
Currently selected mailbox.
Definition: globals.h:56
void mutt_attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t.
Definition: init.c:2298
struct ListHead InlineExclude
List of inline types to ignore.
Definition: mutt_parse.c:42
void mutt_keys_free(void)
Free the key maps.
Definition: keymap.c:1601
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: email_globals.c:50
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: email_globals.c:52
Definition: color.h:130
WHERE struct Hash * ReverseAliases
Hash table of aliases (email address -> alias)
Definition: globals.h:61
void mutt_colors_free(struct Colors **ptr)
Free all the colours.
Definition: color.c:354
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: mutt_parse.c:40
static const char ** Matches
Definition: init.c:90
WHERE char * ShortHostname
Short version of the hostname.
Definition: globals.h:52
#define FREE(x)
Definition: memory.h:40
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:44
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
Definition: email_globals.c:51
void mutt_grouplist_free(void)
Free GroupList singleton resource.
Definition: group.c:55
void mutt_hash_free(struct Hash **ptr)
free_hdata a hash table
Definition: hash.c:471
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: mutt_parse.c:39
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
Definition: email_globals.c:43
void mutt_hist_free(void)
Free all the history lists.
Definition: history.c:439
struct ListHead Ignore
List of header patterns to ignore.
Definition: email_globals.c:45
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:170
void(* list_free_t)(void **ptr)
typedef list_free_t - Prototype for a function to free List data
Definition: list.h:44
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
Definition: email_globals.c:49
struct ReplaceList SubjectRegexList
List of regexes to tidy the view of the email&#39;s subject.
Definition: email_globals.c:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_get_hook_type()

HookFlags mutt_get_hook_type ( const char *  name)

Find a hook by name.

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

Definition at line 2957 of file init.c.

2958 {
2959  for (const struct Command *c = Commands; c->name; c++)
2960  {
2961  if (((c->func == mutt_parse_hook) || (c->func == mutt_parse_idxfmt_hook)) &&
2962  (mutt_str_strcasecmp(c->name, name) == 0))
2963  {
2964  return c->data;
2965  }
2966  }
2967  return MUTT_HOOK_NO_FLAGS;
2968 }
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:4982
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:349
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:

◆ mutt_init()

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

2978 {
2979  char buf[1024];
2980  int need_pause = 0;
2981  int rc = 1;
2982  struct Buffer err = mutt_buffer_make(256);
2983 
2985  /* reverse alias keys need to be strdup'ed because of idna conversions */
2990 
2991  mutt_menu_init();
2992&#