NeoMutt  2018-07-16 +2481-68dcde
Teaching an old dog new tricks
DOXYGEN
mutt.h File Reference

Many unsorted constants and some structs. More...

#include "config.h"
#include <stddef.h>
#include <limits.h>
#include <regex.h>
#include <stdbool.h>
#include <stdint.h>
#include "config/lib.h"
#include "email/lib.h"
#include "hook.h"
#include "keymap.h"
#include "mutt_commands.h"
+ Include dependency graph for mutt.h:

Go to the source code of this file.

Data Structures

struct  AttachMatch
 An attachment matching a regex. More...
 

Macros

#define PATH_MAX   4096
 
#define MUTT_COMP_NO_FLAGS   0
 No flags are set. More...
 
#define MUTT_ALIAS   (1 << 0)
 Do alias "completion" by calling up the alias-menu. More...
 
#define MUTT_FILE   (1 << 1)
 Do file completion. More...
 
#define MUTT_EFILE   (1 << 2)
 Do file completion, plus incoming folders. More...
 
#define MUTT_CMD   (1 << 3)
 Do completion on previous word. More...
 
#define MUTT_PASS   (1 << 4)
 Password mode (no echo) More...
 
#define MUTT_CLEAR   (1 << 5)
 Clear input if printable character is pressed. More...
 
#define MUTT_COMMAND   (1 << 6)
 Do command completion. More...
 
#define MUTT_PATTERN   (1 << 7)
 Pattern mode - only used for history classes. More...
 
#define MUTT_LABEL   (1 << 8)
 Do label completion. More...
 
#define MUTT_NM_QUERY   (1 << 9)
 Notmuch query mode. More...
 
#define MUTT_NM_TAG   (1 << 10)
 Notmuch tag +/- mode. More...
 
#define MUTT_TOKEN_NO_FLAGS   0
 No flags are set. More...
 
#define MUTT_TOKEN_EQUAL   (1 << 0)
 Treat '=' as a special. More...
 
#define MUTT_TOKEN_CONDENSE   (1 << 1)
 ^(char) to control chars (macros) More...
 
#define MUTT_TOKEN_SPACE   (1 << 2)
 Don't treat whitespace as a term. More...
 
#define MUTT_TOKEN_QUOTE   (1 << 3)
 Don't interpret quotes. More...
 
#define MUTT_TOKEN_PATTERN   (1 << 4)
 ~%=!| are terms (for patterns) More...
 
#define MUTT_TOKEN_COMMENT   (1 << 5)
 Don't reap comments. More...
 
#define MUTT_TOKEN_SEMICOLON   (1 << 6)
 Don't treat ; as special. More...
 
#define MUTT_TOKEN_BACKTICK_VARS   (1 << 7)
 Expand variables within backticks. More...
 
#define MUTT_TOKEN_NOSHELL   (1 << 8)
 Don't expand environment variables. More...
 
#define MUTT_TOKEN_QUESTION   (1 << 9)
 Treat '?' as a special. More...
 
#define MUTT_SPAM   1
 
#define MUTT_NOSPAM   2
 
#define EXEC_SHELL   "/bin/sh"
 

Typedefs

typedef uint16_t CompletionFlags
 Flags for mutt_enter_string_full(), e.g. MUTT_ALIAS. More...
 
typedef uint16_t TokenFlags
 Flags for mutt_extract_token(), e.g. MUTT_TOKEN_EQUAL. More...
 

Enumerations

enum  MessageType {
  MUTT_ALL = 1, MUTT_NONE, MUTT_NEW, MUTT_OLD,
  MUTT_REPLIED, MUTT_READ, MUTT_UNREAD, MUTT_DELETE,
  MUTT_UNDELETE, MUTT_PURGE, MUTT_DELETED, MUTT_FLAG,
  MUTT_TAG, MUTT_UNTAG, MUTT_LIMIT, MUTT_EXPIRED,
  MUTT_SUPERSEDED, MUTT_TRASH, MUTT_MT_MAX
}
 To set flags or match patterns. More...
 

Functions

int mutt_init (bool skip_sys_rc, struct ListHead *commands)
 Initialise NeoMutt. More...
 
struct ConfigSetinit_config (size_t size)
 Initialise the config system. More...
 
char * mutt_compile_help (char *buf, size_t buflen, enum MenuType menu, const struct Mapping *items)
 Create the text for the help menu. 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...
 
enum QuadOption query_quadoption (enum QuadOption opt, const char *prompt)
 Ask the user a quad-question. More...
 
int mutt_label_complete (char *buf, size_t buflen, int numtabs)
 Complete a label name. More...
 
int mutt_command_complete (char *buf, size_t buflen, int pos, int numtabs)
 Complete a command name. More...
 
int mutt_var_value_complete (char *buf, size_t buflen, int pos)
 Complete a variable/value. More...
 
void myvar_set (const char *var, const char *val)
 Set the value of a "my_" variable. 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...
 
HookFlags mutt_get_hook_type (const char *name)
 Find a hook by name. 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...
 
void reset_value (const char *name)
 

Detailed Description

Many unsorted constants and some structs.

Authors
  • Michael R. Elkins
  • g10 Code GmbH

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 mutt.h.

Macro Definition Documentation

◆ PATH_MAX

#define PATH_MAX   4096

Definition at line 52 of file mutt.h.

◆ MUTT_COMP_NO_FLAGS

#define MUTT_COMP_NO_FLAGS   0

No flags are set.

Definition at line 64 of file mutt.h.

◆ MUTT_ALIAS

#define MUTT_ALIAS   (1 << 0)

Do alias "completion" by calling up the alias-menu.

Definition at line 65 of file mutt.h.

◆ MUTT_FILE

#define MUTT_FILE   (1 << 1)

Do file completion.

Definition at line 66 of file mutt.h.

◆ MUTT_EFILE

#define MUTT_EFILE   (1 << 2)

Do file completion, plus incoming folders.

Definition at line 67 of file mutt.h.

◆ MUTT_CMD

#define MUTT_CMD   (1 << 3)

Do completion on previous word.

Definition at line 68 of file mutt.h.

◆ MUTT_PASS

#define MUTT_PASS   (1 << 4)

Password mode (no echo)

Definition at line 69 of file mutt.h.

◆ MUTT_CLEAR

#define MUTT_CLEAR   (1 << 5)

Clear input if printable character is pressed.

Definition at line 70 of file mutt.h.

◆ MUTT_COMMAND

#define MUTT_COMMAND   (1 << 6)

Do command completion.

Definition at line 71 of file mutt.h.

◆ MUTT_PATTERN

#define MUTT_PATTERN   (1 << 7)

Pattern mode - only used for history classes.

Definition at line 72 of file mutt.h.

◆ MUTT_LABEL

#define MUTT_LABEL   (1 << 8)

Do label completion.

Definition at line 73 of file mutt.h.

◆ MUTT_NM_QUERY

#define MUTT_NM_QUERY   (1 << 9)

Notmuch query mode.

Definition at line 74 of file mutt.h.

◆ MUTT_NM_TAG

#define MUTT_NM_TAG   (1 << 10)

Notmuch tag +/- mode.

Definition at line 75 of file mutt.h.

◆ MUTT_TOKEN_NO_FLAGS

#define MUTT_TOKEN_NO_FLAGS   0

No flags are set.

Definition at line 78 of file mutt.h.

◆ MUTT_TOKEN_EQUAL

#define MUTT_TOKEN_EQUAL   (1 << 0)

Treat '=' as a special.

Definition at line 79 of file mutt.h.

◆ MUTT_TOKEN_CONDENSE

#define MUTT_TOKEN_CONDENSE   (1 << 1)

^(char) to control chars (macros)

Definition at line 80 of file mutt.h.

◆ MUTT_TOKEN_SPACE

#define MUTT_TOKEN_SPACE   (1 << 2)

Don't treat whitespace as a term.

Definition at line 81 of file mutt.h.

◆ MUTT_TOKEN_QUOTE

#define MUTT_TOKEN_QUOTE   (1 << 3)

Don't interpret quotes.

Definition at line 82 of file mutt.h.

◆ MUTT_TOKEN_PATTERN

#define MUTT_TOKEN_PATTERN   (1 << 4)

~%=!| are terms (for patterns)

Definition at line 83 of file mutt.h.

◆ MUTT_TOKEN_COMMENT

#define MUTT_TOKEN_COMMENT   (1 << 5)

Don't reap comments.

Definition at line 84 of file mutt.h.

◆ MUTT_TOKEN_SEMICOLON

#define MUTT_TOKEN_SEMICOLON   (1 << 6)

Don't treat ; as special.

Definition at line 85 of file mutt.h.

◆ MUTT_TOKEN_BACKTICK_VARS

#define MUTT_TOKEN_BACKTICK_VARS   (1 << 7)

Expand variables within backticks.

Definition at line 86 of file mutt.h.

◆ MUTT_TOKEN_NOSHELL

#define MUTT_TOKEN_NOSHELL   (1 << 8)

Don't expand environment variables.

Definition at line 87 of file mutt.h.

◆ MUTT_TOKEN_QUESTION

#define MUTT_TOKEN_QUESTION   (1 << 9)

Treat '?' as a special.

Definition at line 88 of file mutt.h.

◆ MUTT_SPAM

#define MUTT_SPAM   1

Definition at line 120 of file mutt.h.

◆ MUTT_NOSPAM

#define MUTT_NOSPAM   2

Definition at line 121 of file mutt.h.

◆ EXEC_SHELL

#define EXEC_SHELL   "/bin/sh"

Definition at line 139 of file mutt.h.

Typedef Documentation

◆ CompletionFlags

typedef uint16_t CompletionFlags

Flags for mutt_enter_string_full(), e.g. MUTT_ALIAS.

Definition at line 63 of file mutt.h.

◆ TokenFlags

typedef uint16_t TokenFlags

Flags for mutt_extract_token(), e.g. MUTT_TOKEN_EQUAL.

Definition at line 77 of file mutt.h.

Enumeration Type Documentation

◆ MessageType

To set flags or match patterns.

See also
mutt_set_flag(), mutt_pattern_func()
Enumerator
MUTT_ALL 

All messages.

MUTT_NONE 

No messages.

MUTT_NEW 

New messages.

MUTT_OLD 

Old messages.

MUTT_REPLIED 

Messages that have been replied to.

MUTT_READ 

Messages that have been read.

MUTT_UNREAD 

Unread messages.

MUTT_DELETE 

Messages to be deleted.

MUTT_UNDELETE 

Messages to be un-deleted.

MUTT_PURGE 

Messages to be purged (bypass trash)

MUTT_DELETED 

Deleted messages.

MUTT_FLAG 

Flagged messages.

MUTT_TAG 

Tagged messages.

MUTT_UNTAG 

Messages to be un-tagged.

MUTT_LIMIT 

Messages in limited view.

MUTT_EXPIRED 

Expired messages.

MUTT_SUPERSEDED 

Superseded messages.

MUTT_TRASH 

Trashed messages.

MUTT_MT_MAX 

Definition at line 95 of file mutt.h.

96 {
97  MUTT_ALL = 1,
98  MUTT_NONE,
99  MUTT_NEW,
100  MUTT_OLD,
101  MUTT_REPLIED,
102  MUTT_READ,
103  MUTT_UNREAD,
104  MUTT_DELETE,
105  MUTT_UNDELETE,
106  MUTT_PURGE,
107  MUTT_DELETED,
108  MUTT_FLAG,
109  MUTT_TAG,
110  MUTT_UNTAG,
111  MUTT_LIMIT,
112  MUTT_EXPIRED,
114  MUTT_TRASH,
115 
116  MUTT_MT_MAX,
117 };
Deleted messages.
Definition: mutt.h:107
Messages in limited view.
Definition: mutt.h:111
Messages to be un-deleted.
Definition: mutt.h:105
Flagged messages.
Definition: mutt.h:108
No messages.
Definition: mutt.h:98
Messages to be purged (bypass trash)
Definition: mutt.h:106
Messages that have been replied to.
Definition: mutt.h:101
All messages.
Definition: mutt.h:97
Old messages.
Definition: mutt.h:100
Messages to be deleted.
Definition: mutt.h:104
Superseded messages.
Definition: mutt.h:113
Tagged messages.
Definition: mutt.h:109
New messages.
Definition: mutt.h:99
Messages that have been read.
Definition: mutt.h:102
Expired messages.
Definition: mutt.h:112
Unread messages.
Definition: mutt.h:103
Messages to be un-tagged.
Definition: mutt.h:110
Trashed messages.
Definition: mutt.h:114

Function Documentation

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

2974 {
2975  char buf[1024];
2976  int need_pause = 0;
2977  struct Buffer err = mutt_buffer_make(256);
2978 
2980  /* reverse alias keys need to be strdup'ed because of idna conversions */
2985 
2986  mutt_menu_init();
2987 
2988  snprintf(AttachmentMarker, sizeof(AttachmentMarker), "\033]9;%" PRIu64 "\a", // Escape
2989  mutt_rand64());
2990 
2991  snprintf(ProtectedHeaderMarker, sizeof(ProtectedHeaderMarker), "\033]8;%lld\a", // Escape
2992  (long long) mutt_date_epoch());
2993 
2994  /* "$spoolfile" precedence: config file, environment */
2995  const char *p = mutt_str_getenv("MAIL");
2996  if (!p)
2997  p = mutt_str_getenv("MAILDIR");
2998  if (!p)
2999  {
3000 #ifdef HOMESPOOL
3001  mutt_path_concat(buf, NONULL(HomeDir), MAILPATH, sizeof(buf));
3002 #else
3003  mutt_path_concat(buf, MAILPATH, NONULL(Username), sizeof(buf));
3004 #endif
3005  p = buf;
3006  }
3007  cs_str_initial_set(Config, "spoolfile", p, NULL);
3008  cs_str_reset(Config, "spoolfile", NULL);
3009 
3010  p = mutt_str_getenv("REPLYTO");
3011  if (p)
3012  {
3013  struct Buffer tmp, token;
3014 
3015  snprintf(buf, sizeof(buf), "Reply-To: %s", p);
3016 
3017  mutt_buffer_init(&tmp);
3018  tmp.data = buf;
3019  tmp.dptr = buf;
3020  tmp.dsize = mutt_str_strlen(buf);
3021 
3022  mutt_buffer_init(&token);
3023  parse_my_hdr(&token, &tmp, 0, &err); /* adds to UserHeader */
3024  FREE(&token.data);
3025  }
3026 
3027  p = mutt_str_getenv("EMAIL");
3028  if (p)
3029  {
3030  cs_str_initial_set(Config, "from", p, NULL);
3031  cs_str_reset(Config, "from", NULL);
3032  }
3033 
3034  /* "$mailcap_path" precedence: config file, environment, code */
3035  const char *env_mc = mutt_str_getenv("MAILCAPS");
3036  if (env_mc)
3037  cs_str_string_set(Config, "mailcap_path", env_mc, NULL);
3038 
3039  /* "$tmpdir" precedence: config file, environment, code */
3040  const char *env_tmp = mutt_str_getenv("TMPDIR");
3041  if (env_tmp)
3042  cs_str_string_set(Config, "tmpdir", env_tmp, NULL);
3043 
3044  /* "$visual", "$editor" precedence: config file, environment, code */
3045  const char *env_ed = mutt_str_getenv("VISUAL");
3046  if (!env_ed)
3047  env_ed = mutt_str_getenv("EDITOR");
3048  if (env_ed)
3049  {
3050  cs_str_string_set(Config, "editor", env_ed, NULL);
3051  cs_str_string_set(Config, "visual", env_ed, NULL);
3052  }
3053 
3056 
3057  Matches = mutt_mem_calloc(MatchesListsize, sizeof(char *));
3058 
3060 
3061 #ifdef HAVE_GETSID
3062  /* Unset suspend by default if we're the session leader */
3063  if (getsid(0) == getpid())
3064  C_Suspend = false;
3065 #endif
3066 
3067  /* RFC2368, "4. Unsafe headers"
3068  * The creator of a mailto URL can't expect the resolver of a URL to
3069  * understand more than the "subject" and "body" headers. Clients that
3070  * resolve mailto URLs into mail messages should be able to correctly
3071  * create RFC822-compliant mail messages using the "subject" and "body"
3072  * headers. */
3073  add_to_stailq(&MailToAllow, "body");
3074  add_to_stailq(&MailToAllow, "subject");
3075  /* Cc, In-Reply-To, and References help with not breaking threading on
3076  * mailing lists, see https://github.com/neomutt/neomutt/issues/115 */
3077  add_to_stailq(&MailToAllow, "cc");
3078  add_to_stailq(&MailToAllow, "in-reply-to");
3079  add_to_stailq(&MailToAllow, "references");
3080 
3081  if (STAILQ_EMPTY(&Muttrc))
3082  {
3083  const char *xdg_cfg_home = mutt_str_getenv("XDG_CONFIG_HOME");
3084 
3085  if (!xdg_cfg_home && HomeDir)
3086  {
3087  snprintf(buf, sizeof(buf), "%s/.config", HomeDir);
3088  xdg_cfg_home = buf;
3089  }
3090 
3091  char *config = find_cfg(HomeDir, xdg_cfg_home);
3092  if (config)
3093  {
3094  mutt_list_insert_tail(&Muttrc, config);
3095  }
3096  }
3097  else
3098  {
3099  struct ListNode *np = NULL;
3100  STAILQ_FOREACH(np, &Muttrc, entries)
3101  {
3102  mutt_str_strfcpy(buf, np->data, sizeof(buf));
3103  FREE(&np->data);
3104  mutt_expand_path(buf, sizeof(buf));
3105  np->data = mutt_str_strdup(buf);
3106  if (access(np->data, F_OK))
3107  {
3108  mutt_perror(np->data);
3109  return 1; // TEST10: neomutt -F missing
3110  }
3111  }
3112  }
3113 
3114  if (!STAILQ_EMPTY(&Muttrc))
3115  {
3116  cs_str_string_set(Config, "alias_file", STAILQ_FIRST(&Muttrc)->data, NULL);
3117  }
3118 
3119  /* Process the global rc file if it exists and the user hasn't explicitly
3120  * requested not to via "-n". */
3121  if (!skip_sys_rc)
3122  {
3123  do
3124  {
3125  if (mutt_set_xdg_path(XDG_CONFIG_DIRS, buf, sizeof(buf)))
3126  break;
3127 
3128  snprintf(buf, sizeof(buf), "%s/neomuttrc", SYSCONFDIR);
3129  if (access(buf, F_OK) == 0)
3130  break;
3131 
3132  snprintf(buf, sizeof(buf), "%s/Muttrc", SYSCONFDIR);
3133  if (access(buf, F_OK) == 0)
3134  break;
3135 
3136  snprintf(buf, sizeof(buf), "%s/neomuttrc", PKGDATADIR);
3137  if (access(buf, F_OK) == 0)
3138  break;
3139 
3140  snprintf(buf, sizeof(buf), "%s/Muttrc", PKGDATADIR);
3141  } while (false);
3142 
3143  if (access(buf, F_OK) == 0)
3144  {
3145  if (source_rc(buf, &err) != 0)
3146  {
3147  mutt_error("%s", err.data);
3148  need_pause = 1; // TEST11: neomutt (error in /etc/neomuttrc)
3149  }
3150  }
3151  }
3152 
3153  /* Read the user's initialization file. */
3154  struct ListNode *np = NULL;
3155  STAILQ_FOREACH(np, &Muttrc, entries)
3156  {
3157  if (np->data)
3158  {
3159  if (source_rc(np->data, &err) != 0)
3160  {
3161  mutt_error("%s", err.data);
3162  need_pause = 1; // TEST12: neomutt (error in ~/.neomuttrc)
3163  }
3164  }
3165  }
3166 
3167  if (execute_commands(commands) != 0)
3168  need_pause = 1; // TEST13: neomutt -e broken
3169 
3170  if (!get_hostname())
3171  return 1;
3172 
3173  if (!C_Realname)
3174  {
3175  struct passwd *pw = getpwuid(getuid());
3176  if (pw)
3177  {
3178  char name[256];
3179  C_Realname = mutt_str_strdup(mutt_gecos_name(name, sizeof(name), pw));
3180  }
3181  }
3182  cs_str_initial_set(Config, "realname", C_Realname, NULL);
3183 
3184  if (need_pause && !OptNoCurses)
3185  {
3187  if (mutt_any_key_to_continue(NULL) == 'q')
3188  return 1; // TEST14: neomutt -e broken (press 'q')
3189  }
3190 
3191  mutt_file_mkdir(C_Tmpdir, S_IRWXU);
3192 
3193  mutt_hist_init();
3195 
3196 #ifdef USE_NOTMUCH
3197  if (C_VirtualSpoolfile)
3198  {
3199  /* Find the first virtual folder and open it */
3200  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_NOTMUCH);
3201  struct MailboxNode *mp = STAILQ_FIRST(&ml);
3202  if (mp)
3203  cs_str_string_set(Config, "spoolfile", mailbox_path(mp->mailbox), NULL);
3205  }
3206 #endif
3207 
3208  FREE(&err.data);
3209  return 0;
3210 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:410
WHERE char * Username
User&#39;s login name.
Definition: globals.h:52
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:194
char * mutt_path_concat(char *d, const char *dir, const char *fname, size_t l)
Join a directory name and a filename.
Definition: path.c:330
#define NONULL(x)
Definition: string2.h:37
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define mutt_perror(...)
Definition: logging.h:85
struct Hash * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
int cs_str_string_set(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.c:627
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:134
WHERE char AttachmentMarker[256]
Unique ANSI string to mark PGP messages in an email.
Definition: globals.h:46
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:87
struct ListHead MailToAllow
List of permitted fields in a mailto: uri.
Definition: email_globals.c:47
String manipulation buffer.
Definition: buffer.h:33
static int execute_commands(struct ListHead *p)
Execute a set of NeoMutt commands.
Definition: init.c:284
static int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
Definition: init.c:757
WHERE struct Hash * TagFormats
Hash table of tag-formats (tag -> format string)
Definition: globals.h:60
WHERE struct ConfigSet * Config
Wrapper around the user&#39;s config settings.
Definition: globals.h:40
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:46
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
Index panel (list of emails)
Definition: keymap.h:68
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
Definition: charset.c:997
static enum CommandResult parse_my_hdr(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse the &#39;my_hdr&#39; command - Implements command_t.
Definition: init.c:1405
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
Definition: logging.c:356
static char * find_cfg(const char *home, const char *xdg_cfg_home)
Find a config file.
Definition: init.c:315
Container for Accounts, Notifications.
Definition: neomutt.h:35
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:1049
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
#define MUTT_HASH_STRCASECMP
use strcasecmp() to compare keys
Definition: hash.h:75
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:128
void mutt_hist_read_file(void)
Read the History from a file.
Definition: history.c:584
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:871
const char * name
Definition: pgpmicalg.c:45
struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType magic)
Get a List of all Mailboxes.
Definition: neomutt.c:156
WHERE char * HomeDir
User&#39;s home directory.
Definition: globals.h:49
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_HASH_ALLOW_DUPS
allow duplicate keys to be inserted
Definition: hash.h:77
static int MatchesListsize
Definition: init.c:94
void mutt_grouplist_init(void)
Initialize the GroupList singleton.
Definition: group.c:45
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 Hash * mutt_hash_new(size_t nelem, HashFlags flags)
Create a new Hash table (with string keys)
Definition: hash.c:276
char * mutt_ch_get_langinfo_charset(void)
Get the user&#39;s choice of character set.
Definition: charset.c:456
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
void mutt_hist_init(void)
Create a set of empty History ring buffers.
Definition: history.c:462
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition: muttlib.c:540
int mutt_set_xdg_path(enum XdgType type, char *buf, size_t bufsize)
Find an XDG path or its fallback.
Definition: muttlib.c:1565
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:53
WHERE char ProtectedHeaderMarker[256]
Unique ANSI string to mark protected headers in an email.
Definition: globals.h:47
int cs_str_reset(const struct ConfigSet *cs, const char *name, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.c:423
WHERE struct Hash * ReverseAliases
Hash table of aliases (email address -> alias)
Definition: globals.h:59
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:532
char * data
String.
Definition: list.h:35
WHERE bool C_Suspend
Config: Allow the user to suspend NeoMutt using &#39;^Z&#39;.
Definition: globals.h:267
char * mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw)
Lookup a user&#39;s real name in /etc/passwd.
Definition: muttlib.c:362
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define mutt_error(...)
Definition: logging.h:84
char * C_Tmpdir
Config: Directory for temporary files.
Definition: file.c:53
static const char ** Matches
Definition: init.c:92
#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
List of Mailboxes.
Definition: mailbox.h:156
WHERE char * C_Realname
Config: Real name of the user.
Definition: globals.h:143
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
#define MUTT_HASH_STRDUP_KEYS
make a copy of the keys
Definition: hash.h:76
A List node for strings.
Definition: list.h:33
static bool get_hostname(void)
Find the Fully-Qualified Domain Name.
Definition: init.c:388
XDG system dir: /etc/xdg.
Definition: protos.h:49
#define STAILQ_FIRST(head)
Definition: queue.h:348
#define MUTT_HASH_NO_FLAGS
No flags are set.
Definition: hash.h:74
int log_disp_terminal(time_t stamp, const char *file, int line, const char *function, int level,...)
Save a log line to the terminal - Implements log_dispatcher_t.
Definition: logging.c:449
static void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: init.c:118
WHERE bool C_VirtualSpoolfile
Config: (notmuch) Use the first virtual mailbox as a spool file.
Definition: globals.h:298
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:158
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_config()

struct ConfigSet* init_config ( size_t  size)

Initialise the config system.

Return values
ptrNew Config Set

Definition at line 3769 of file init.c.

3770 {
3771  struct ConfigSet *cs = cs_new(size);
3772 
3773  address_init(cs);
3774  bool_init(cs);
3775  enum_init(cs);
3776  long_init(cs);
3777  mbtable_init(cs);
3778  number_init(cs);
3779  quad_init(cs);
3780  regex_init(cs);
3781  slist_init(cs);
3782  sort_init(cs);
3783  string_init(cs);
3784 
3785  if (!cs_register_variables(cs, MuttVars, 0))
3786  {
3787  mutt_error("cs_register_variables() failed");
3788  cs_free(&cs);
3789  return NULL;
3790  }
3791 
3792  return cs;
3793 }
Container for lots of config items.
Definition: set.h:187
void quad_init(struct ConfigSet *cs)
Register the Quad-option config type.
Definition: quad.c:190
void bool_init(struct ConfigSet *cs)
Register the Bool config type.
Definition: bool.c:188
void number_init(struct ConfigSet *cs)
Register the Number config type.
Definition: number.c:191
void sort_init(struct ConfigSet *cs)
Register the Sort config type.
Definition: sort.c:381
void enum_init(struct ConfigSet *cs)
Register the Enumeration config type.
Definition: enum.c:218
void mbtable_init(struct ConfigSet *cs)
Register the MbTable config type.
Definition: mbtable.c:293
void slist_init(struct ConfigSet *cs)
Register the Slist config type.
Definition: slist.c:266
void address_init(struct ConfigSet *cs)
Register the Address config type.
Definition: address.c:249
void string_init(struct ConfigSet *cs)
Register the String config type.
Definition: string.c:239
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition: set.c:198
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition: set.c:171
void long_init(struct ConfigSet *cs)
Register the Long config type.
Definition: long.c:172
struct ConfigDef MuttVars[]
Definition: init.h:129
#define mutt_error(...)
Definition: logging.h:84
void regex_init(struct ConfigSet *cs)
Register the Regex config type.
Definition: regex.c:314
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
Register a set of config items.
Definition: set.c:289
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_compile_help()

char* mutt_compile_help ( char *  buf,
size_t  buflen,
enum MenuType  menu,
const struct Mapping items 
)

Create the text for the help menu.

Parameters
bufBuffer for the result
buflenLength of buffer
menuCurrent Menu, e.g. MENU_PAGER
itemsMap of functions to display in the help bar
Return values
ptrBuffer containing result

Definition at line 115 of file help.c.

117 {
118  char *pbuf = buf;
119 
120  for (int i = 0; items[i].name && buflen > 2; i++)
121  {
122  if (i)
123  {
124  *pbuf++ = ' ';
125  *pbuf++ = ' ';
126  buflen -= 2;
127  }
128  mutt_make_help(pbuf, buflen, _(items[i].name), menu, items[i].value);
129  const size_t len = mutt_str_strlen(pbuf);
130  pbuf += len;
131  buflen -= len;
132  }
133  return buf;
134 }
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
const char * name
Definition: pgpmicalg.c:45
void mutt_make_help(char *buf, size_t buflen, const char *txt, enum MenuType menu, int op)
Create one entry for the help bar.
Definition: help.c:92
const char * name
Definition: mapping.h:31
static unsigned char * pbuf
Cache PGP data packet.
Definition: pgppacket.c:37
+ 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 2649 of file init.c.

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

◆ mutt_opts_free()

void mutt_opts_free ( void  )

clean up before quitting

Definition at line 2886 of file init.c.

2887 {
2889 
2890  FREE(&Matches);
2891 
2892  mutt_aliaslist_free(&Aliases);
2893 
2894  mutt_regexlist_free(&Alternates);
2898  mutt_regexlist_free(&UnAlternates);
2901 
2906 
2907  /* Lists of strings */
2908  mutt_list_free(&AlternativeOrderList);
2909  mutt_list_free(&AutoViewList);
2910  mutt_list_free(&HeaderOrderList);
2913  mutt_list_free(&MimeLookupList);
2914  mutt_list_free(&Muttrc);
2916 #ifdef USE_SIDEBAR
2917  mutt_list_free(&SidebarWhitelist);
2918 #endif
2920  mutt_list_free(&UserHeader);
2921 
2922  /* Lists of AttachMatch */
2927 
2928  mutt_colors_free();
2929 
2930  FREE(&CurrentFolder);
2931  FREE(&HomeDir);
2932  FREE(&LastFolder);
2933  FREE(&ShortHostname);
2934  FREE(&Username);
2935 
2938 
2940 
2941  mutt_hist_free();
2942  mutt_keys_free();
2943 
2945 }
WHERE char * Username
User&#39;s login name.
Definition: globals.h:52
void mutt_aliaslist_free(struct AliasList *a_list)
Free a List of Aliases.
Definition: alias.c:759
struct Hash * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
static struct ListHead MuttrcStack
Definition: init.c:79
struct ReplaceList SpamList
List of regexes and patterns to match spam emails.
Definition: email_globals.c:44
void mutt_list_free_type(struct ListHead *h, list_free_t fn)
Free a List of type.
Definition: list.c:145
struct ListHead MailToAllow
List of permitted fields in a mailto: uri.
Definition: email_globals.c:47
WHERE struct Hash * TagFormats
Hash table of tag-formats (tag -> format string)
Definition: globals.h:60
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
Definition: hook.c:316
WHERE char * LastFolder
Previously selected mailbox.
Definition: globals.h:55
struct ListHead UnIgnore
List of header patterns to unignore (see)
Definition: email_globals.c:46
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:447
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
WHERE char * HomeDir
User&#39;s home directory.
Definition: globals.h:49
WHERE char * CurrentFolder
Currently selected mailbox.
Definition: globals.h:54
void mutt_attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t.
Definition: init.c:2289
void mutt_keys_free(void)
Free the key maps.
Definition: keymap.c:1597
struct RegexList MailLists
List of regexes to match mailing lists.
Definition: email_globals.c:50
void mutt_colors_free(void)
Free all the colours (on shutdown)
Definition: color.c:1263
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
Definition: email_globals.c:52
WHERE struct Hash * ReverseAliases
Hash table of aliases (email address -> alias)
Definition: globals.h:59
static const char ** Matches
Definition: init.c:92
WHERE char * ShortHostname
Short version of the hostname.
Definition: globals.h:50
#define FREE(x)
Definition: memory.h:40
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:44
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
Definition: email_globals.c:51
void mutt_grouplist_free(void)
Free GroupList singleton resource.
Definition: group.c:55
void mutt_hash_free(struct Hash **ptr)
free_hdata a hash table
Definition: hash.c:472
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
Definition: email_globals.c:43
void mutt_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:

◆ query_quadoption()

enum QuadOption query_quadoption ( enum QuadOption  opt,
const char *  prompt 
)

Ask the user a quad-question.

Parameters
optOption to use
promptMessage to show to the user
Return values
QuadOptionResult, e.g. MUTT_NO

Definition at line 3331 of file init.c.

3332 {
3333  switch (opt)
3334  {
3335  case MUTT_YES:
3336  case MUTT_NO:
3337  return opt;
3338 
3339  default:
3340  opt = mutt_yesorno(prompt, (opt == MUTT_ASKYES) ? MUTT_YES : MUTT_NO);
3342  return opt;
3343  }
3344 
3345  /* not reached */
3346 }
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
Ask the user, defaulting to &#39;Yes&#39;.
Definition: quad.h:41
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: curs_lib.c:332
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:95
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:38
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_label_complete()

int mutt_label_complete ( char *  buf,
size_t  buflen,
int  numtabs 
)

Complete a label name.

Parameters
bufBuffer for the result
buflenLength of the buffer
numtabsNumber of times the user has hit 'tab'
Return values
1Success, a match
0Error, no match

Definition at line 3527 of file init.c.

3528 {
3529  char *pt = buf;
3530  int spaces; /* keep track of the number of leading spaces on the line */
3531 
3532  if (!Context || !Context->mailbox->label_hash)
3533  return 0;
3534 
3535  SKIPWS(buf);
3536  spaces = buf - pt;
3537 
3538  /* first TAB. Collect all the matches */
3539  if (numtabs == 1)
3540  {
3541  struct HashElem *entry = NULL;
3542  struct HashWalkState state = { 0 };
3543 
3544  NumMatched = 0;
3545  mutt_str_strfcpy(UserTyped, buf, sizeof(UserTyped));
3546  memset(Matches, 0, MatchesListsize);
3547  memset(Completed, 0, sizeof(Completed));
3548  while ((entry = mutt_hash_walk(Context->mailbox->label_hash, &state)))
3549  candidate(UserTyped, entry->key.strkey, Completed, sizeof(Completed));
3551  qsort(Matches, NumMatched, sizeof(char *), (sort_t *) mutt_str_strcasecmp);
3553 
3554  /* All matches are stored. Longest non-ambiguous string is ""
3555  * i.e. don't change 'buf'. Fake successful return this time */
3556  if (UserTyped[0] == '\0')
3557  return 1;
3558  }
3559 
3560  if ((Completed[0] == '\0') && (UserTyped[0] != '\0'))
3561  return 0;
3562 
3563  /* NumMatched will _always_ be at least 1 since the initial
3564  * user-typed string is always stored */
3565  if ((numtabs == 1) && (NumMatched == 2))
3566  snprintf(Completed, sizeof(Completed), "%s", Matches[0]);
3567  else if ((numtabs > 1) && (NumMatched > 2))
3568  {
3569  /* cycle through all the matches */
3570  snprintf(Completed, sizeof(Completed), "%s", Matches[(numtabs - 2) % NumMatched]);
3571  }
3572 
3573  /* return the completed label */
3574  strncpy(buf, Completed, buflen - spaces);
3575 
3576  return 1;
3577 }
The "current" mailbox.
Definition: context.h:36
union HashKey key
Definition: hash.h:45
int sort_t(const void *a, const void *b)
typedef sort_t - Prototype for a function to compare two emails
Definition: sort.h:48
static int NumMatched
Definition: init.c:90
Cursor to iterate through a Hash Table.
Definition: hash.h:96
struct Mailbox * mailbox
Definition: context.h:50
#define SKIPWS(ch)
Definition: string2.h:47
static char Completed[256]
Definition: init.c:91
static int MatchesListsize
Definition: init.c:94
static void matches_ensure_morespace(int current)
Allocate more space for auto-completion.
Definition: init.c:164
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
struct HashElem * mutt_hash_walk(const struct Hash *table, struct HashWalkState *state)
Iterate through all the HashElem&#39;s in a Hash table.
Definition: hash.c:504
static char UserTyped[1024]
Definition: init.c:88
const char * strkey
Definition: hash.h:35
static const char ** Matches
Definition: init.c:92
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
The item stored in a Hash Table.
Definition: hash.h:42
struct Hash * label_hash
Hash table for x-labels.
Definition: mailbox.h:140
static void candidate(char *user, const char *src, char *dest, size_t dlen)
helper function for completion
Definition: init.c:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_command_complete()

int mutt_command_complete ( char *  buf,
size_t  buflen,
int  pos,
int  numtabs 
)

Complete a command name.

Parameters
bufBuffer for the result
buflenLength of the buffer
posCursor position in the buffer
numtabsNumber of times the user has hit 'tab'
Return values
1Success, a match
0Error, no match

Definition at line 3357 of file init.c.

3358 {
3359  char *pt = buf;
3360  int num;
3361  int spaces; /* keep track of the number of leading spaces on the line */
3362  struct MyVar *myv = NULL;
3363 
3364  SKIPWS(buf);
3365  spaces = buf - pt;
3366 
3367  pt = buf + pos - spaces;
3368  while ((pt > buf) && !isspace((unsigned char) *pt))
3369  pt--;
3370 
3371  if (pt == buf) /* complete cmd */
3372  {
3373  /* first TAB. Collect all the matches */
3374  if (numtabs == 1)
3375  {
3376  NumMatched = 0;
3377  mutt_str_strfcpy(UserTyped, pt, sizeof(UserTyped));
3378  memset(Matches, 0, MatchesListsize);
3379  memset(Completed, 0, sizeof(Completed));
3380  for (num = 0; Commands[num].name; num++)
3384 
3385  /* All matches are stored. Longest non-ambiguous string is ""
3386  * i.e. don't change 'buf'. Fake successful return this time */
3387  if (UserTyped[0] == '\0')
3388  return 1;
3389  }
3390 
3391  if ((Completed[0] == '\0') && (UserTyped[0] != '\0'))
3392  return 0;
3393 
3394  /* NumMatched will _always_ be at least 1 since the initial
3395  * user-typed string is always stored */
3396  if ((numtabs == 1) && (NumMatched == 2))
3397  snprintf(Completed, sizeof(Completed), "%s", Matches[0]);
3398  else if ((numtabs > 1) && (NumMatched > 2))
3399  {
3400  /* cycle through all the matches */
3401  snprintf(Completed, sizeof(Completed), "%s", Matches[(numtabs - 2) % NumMatched]);
3402  }
3403 
3404  /* return the completed command */
3405  strncpy(buf, Completed, buflen - spaces);
3406  }
3407  else if (mutt_str_startswith(buf, "set", CASE_MATCH) ||
3408  mutt_str_startswith(buf, "unset", CASE_MATCH) ||
3409  mutt_str_startswith(buf, "reset", CASE_MATCH) ||
3410  mutt_str_startswith(buf, "toggle", CASE_MATCH))
3411  { /* complete variables */
3412  static const char *const prefixes[] = { "no", "inv", "?", "&", 0 };
3413 
3414  pt++;
3415  /* loop through all the possible prefixes (no, inv, ...) */
3416  if (mutt_str_startswith(buf, "set", CASE_MATCH))
3417  {
3418  for (num = 0; prefixes[num]; num++)
3419  {
3420  if (mutt_str_startswith(pt, prefixes[num], CASE_MATCH))
3421  {
3422  pt += mutt_str_strlen(prefixes[num]);
3423  break;
3424  }
3425  }
3426  }
3427 
3428  /* first TAB. Collect all the matches */
3429  if (numtabs == 1)
3430  {
3431  NumMatched = 0;
3432  mutt_str_strfcpy(UserTyped, pt, sizeof(UserTyped));
3433  memset(Matches, 0, MatchesListsize);
3434  memset(Completed, 0, sizeof(Completed));
3435  for (num = 0; MuttVars[num].name; num++)
3436  candidate(UserTyped, MuttVars[num].name, Completed, sizeof(Completed));
3437  TAILQ_FOREACH(myv, &MyVars, entries)
3438  {
3439  candidate(UserTyped, myv->name, Completed, sizeof(Completed));
3440  }
3443 
3444  /* All matches are stored. Longest non-ambiguous string is ""
3445  * i.e. don't change 'buf'. Fake successful return this time */
3446  if (UserTyped[0] == '\0')
3447  return 1;
3448  }
3449 
3450  if ((Completed[0] == 0) && UserTyped[0])
3451  return 0;
3452 
3453  /* NumMatched will _always_ be at least 1 since the initial
3454  * user-typed string is always stored */
3455  if ((numtabs == 1) && (NumMatched == 2))
3456  snprintf(Completed, sizeof(Completed), "%s", Matches[0]);
3457  else if ((numtabs > 1) && (NumMatched > 2))
3458  {
3459  /* cycle through all the matches */
3460  snprintf(Completed, sizeof(Completed), "%s", Matches[(numtabs - 2) % NumMatched]);
3461  }
3462 
3463  strncpy(pt, Completed, buf + buflen - pt - spaces);
3464  }
3465  else if (mutt_str_startswith(buf, "exec", CASE_MATCH))
3466  {
3467  const struct Binding *menu = km_get_table(CurrentMenu);
3468 
3469  if (!menu && (CurrentMenu != MENU_PAGER))
3470  menu = OpGeneric;
3471 
3472  pt++;
3473  /* first TAB. Collect all the matches */
3474  if (numtabs == 1)
3475  {
3476  NumMatched = 0;
3477  mutt_str_strfcpy(UserTyped, pt, sizeof(UserTyped));
3478  memset(Matches, 0, MatchesListsize);
3479  memset(Completed, 0, sizeof(Completed));
3480  for (num = 0; menu[num].name; num++)
3481  candidate(UserTyped, menu[num].name, Completed, sizeof(Completed));
3482  /* try the generic menu */
3483  if ((Completed[0] == '\0') && (CurrentMenu != MENU_PAGER))
3484  {
3485  menu = OpGeneric;
3486  for (num = 0; menu[num].name; num++)
3487  candidate(UserTyped, menu[num].name, Completed, sizeof(Completed));
3488  }
3491 
3492  /* All matches are stored. Longest non-ambiguous string is ""
3493  * i.e. don't change 'buf'. Fake successful return this time */
3494  if (UserTyped[0] == '\0')
3495  return 1;
3496  }
3497 
3498  if ((Completed[0] == '\0') && (UserTyped[0] != '\0'))
3499  return 0;
3500 
3501  /* NumMatched will _always_ be at least 1 since the initial
3502  * user-typed string is always stored */
3503  if ((numtabs == 1) && (NumMatched == 2))
3504  snprintf(Completed, sizeof(Completed), "%s", Matches[0]);
3505  else if ((numtabs > 1) && (NumMatched > 2))
3506  {
3507  /* cycle through all the matches */
3508  snprintf(Completed, sizeof(Completed), "%s", Matches[(numtabs - 2) % NumMatched]);
3509  }
3510 
3511  strncpy(pt, Completed, buf + buflen - pt - spaces);
3512  }
3513  else
3514  return 0;
3515 
3516  return 1;
3517 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
static int NumMatched
Definition: init.c:90
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:87
const char * name
Name of the command.
Definition: mutt_commands.h:56
Match case when comparing strings.
Definition: string2.h:67
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
char * name
Name of user variable.
Definition: myvar.h:33
const struct Command Commands[]
Definition: init.h:4972
Pager pager (email viewer)
Definition: keymap.h:69
const char * name
Definition: pgpmicalg.c:45
A user-set variable.
Definition: myvar.h:31
struct MyVarList MyVars
List of all the user&#39;s custom config variables.
Definition: myvar.c:34
const char * name
name of the function
Definition: keymap.h:107
#define SKIPWS(ch)
Definition: string2.h:47
static char Completed[256]
Definition: init.c:91
const char * name
User-visible name.
Definition: set.h:155
static int MatchesListsize
Definition: init.c:94
static void matches_ensure_morespace(int current)
Allocate more space for auto-completion.
Definition: init.c:164
const struct Binding OpGeneric[]
Key bindings for the generic menu.
Definition: functions.h:54
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
static char UserTyped[1024]
Definition: init.c:88
struct ConfigDef MuttVars[]
Definition: init.h:129
static const char ** Matches
Definition: init.c:92
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu&#39;s keybindings.
Definition: keymap.c:1219
Mapping between a user key and a function.
Definition: keymap.h:105
static void candidate(char *user, const char *src, char *dest, size_t dlen)
helper function for completion
Definition: init.c:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_var_value_complete()

int mutt_var_value_complete ( char *  buf,
size_t  buflen,
int  pos 
)

Complete a variable/value.

Parameters
bufBuffer for the result
buflenLength of the buffer
posCursor position in the buffer

Definition at line 3701 of file init.c.

3702 {
3703  char *pt = buf;
3704 
3705  if (buf[0] == '\0')
3706  return 0;
3707 
3708  SKIPWS(buf);
3709  const int spaces = buf - pt;
3710 
3711  pt = buf + pos - spaces;
3712  while ((pt > buf) && !isspace((unsigned char) *pt))
3713  pt--;
3714  pt++; /* move past the space */
3715  if (*pt == '=') /* abort if no var before the '=' */
3716  return 0;
3717 
3718  if (mutt_str_startswith(buf, "set", CASE_MATCH))
3719  {
3720  const char *myvarval = NULL;
3721  char var[256];
3722  mutt_str_strfcpy(var, pt, sizeof(var));
3723  /* ignore the trailing '=' when comparing */
3724  int vlen = mutt_str_strlen(var);
3725  if (vlen == 0)
3726  return 0;
3727 
3728  var[vlen - 1] = '\0';
3729 
3730  struct HashElem *he = cs_get_elem(Config, var);
3731  if (!he)
3732  {
3733  myvarval = myvar_get(var);
3734  if (myvarval)
3735  {
3736  struct Buffer pretty = mutt_buffer_make(256);
3737  pretty_var(myvarval, &pretty);
3738  snprintf(pt, buflen - (pt - buf), "%s=%s", var, pretty.data);
3739  mutt_buffer_dealloc(&pretty);
3740  return 1;
3741  }
3742  return 0; /* no such variable. */
3743  }
3744  else
3745  {
3746  struct Buffer value = mutt_buffer_make(256);
3747  struct Buffer pretty = mutt_buffer_make(256);
3748  int rc = cs_he_string_get(Config, he, &value);
3749  if (CSR_RESULT(rc) == CSR_SUCCESS)
3750  {
3751  pretty_var(value.data, &pretty);
3752  snprintf(pt, buflen - (pt - buf), "%s=%s", var, pretty.data);
3753  mutt_buffer_dealloc(&value);
3754  mutt_buffer_dealloc(&pretty);
3755  return 0;
3756  }
3757  mutt_buffer_dealloc(&value);
3758  mutt_buffer_dealloc(&pretty);
3759  return 1;
3760  }
3761  }
3762  return 0;
3763 }
#define CSR_RESULT(x)
Definition: set.h:62
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:40
Match case when comparing strings.
Definition: string2.h:67
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
#define SKIPWS(ch)
Definition: string2.h:47
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:293
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:216
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
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
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
size_t pretty_var(const char *str, struct Buffer *buf)
Escape and stringify a config item value.
Definition: dump.c:80
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ myvar_set()

void myvar_set ( const char *  var,
const char *  val 
)

Set the value of a "my_" variable.

Parameters
varVariable name
valValue to set

Definition at line 91 of file myvar.c.

92 {
93  struct MyVar *myv = NULL;
94 
95  TAILQ_FOREACH(myv, &MyVars, entries)
96  {
97  if (mutt_str_strcmp(myv->name, var) == 0)
98  {
99  mutt_str_replace(&myv->value, val);
100  return;
101  }
102  }
103 
104  myv = myvar_new(var, val);
105  TAILQ_INSERT_TAIL(&MyVars, myv, entries);
106 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
static struct MyVar * myvar_new(const char *name, const char *value)
Create a new MyVar.
Definition: myvar.c:44
char * name
Name of user variable.
Definition: myvar.h:33
A user-set variable.
Definition: myvar.h:31
struct MyVarList MyVars
List of all the user&#39;s custom config variables.
Definition: myvar.c:34
char * value
Value of user variable.
Definition: myvar.h:34
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:803
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:453
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
+ Here is the caller graph for this function:

◆ mutt_nm_query_complete()

bool mutt_nm_query_complete ( char *  buf,
size_t  buflen,
int  pos,
int  numtabs 
)

Complete to the nearest notmuch tag.

Parameters
bufBuffer for the result
buflenLength of the buffer
posCursor position in the buffer
numtabsNumber of times the user has hit 'tab'
Return values
trueSuccess, a match
falseError, no match

Complete the nearest "tag:"-prefixed string previous to pos.

Definition at line 3591 of file init.c.

3592 {
3593  char *pt = buf;
3594  int spaces;
3595 
3596  SKIPWS(buf);
3597  spaces = buf - pt;
3598 
3599  pt = (char *) mutt_str_rstrnstr((char *) buf, pos, "tag:");
3600  if (pt)
3601  {
3602  pt += 4;
3603  if (numtabs == 1)
3604  {
3605  /* First TAB. Collect all the matches */
3607 
3608  /* All matches are stored. Longest non-ambiguous string is ""
3609  * i.e. don't change 'buf'. Fake successful return this time. */
3610  if (UserTyped[0] == '\0')
3611  return true;
3612  }
3613 
3614  if ((Completed[0] == '\0') && (UserTyped[0] != '\0'))
3615  return false;
3616 
3617  /* NumMatched will _always_ be at least 1 since the initial
3618  * user-typed string is always stored */
3619  if ((numtabs == 1) && (NumMatched == 2))
3620  snprintf(Completed, sizeof(Completed), "%s", Matches[0]);
3621  else if ((numtabs > 1) && (NumMatched > 2))
3622  {
3623  /* cycle through all the matches */
3624  snprintf(Completed, sizeof(Completed), "%s", Matches[(numtabs - 2) % NumMatched]);
3625  }
3626 
3627  /* return the completed query */
3628  strncpy(pt, Completed, buf + buflen - pt - spaces);
3629  }
3630  else
3631  return false;
3632 
3633  return true;
3634 }
static int NumMatched
Definition: init.c:90
#define SKIPWS(ch)
Definition: string2.h:47
static char Completed[256]
Definition: init.c:91
static int complete_all_nm_tags(const char *pt)
Pass a list of Notmuch tags to the completion code.
Definition: init.c:227
static char UserTyped[1024]
Definition: init.c:88
static const char ** Matches
Definition: init.c:92
const char * mutt_str_rstrnstr(const char *haystack, size_t haystack_length, const char *needle)
Find last instance of a substring.
Definition: string.c:938
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_nm_tag_complete()

bool mutt_nm_tag_complete ( char *  buf,
size_t  buflen,
int  numtabs 
)

Complete to the nearest notmuch tag.

Parameters
bufBuffer for the result
buflenLength of the buffer
numtabsNumber of times the user has hit 'tab'
Return values
trueSuccess, a match
falseError, no match

Complete the nearest "+" or "-" -prefixed string previous to pos.

Definition at line 3648 of file init.c.

3649 {
3650  if (!buf)
3651  return false;
3652 
3653  char *pt = buf;
3654 
3655  /* Only examine the last token */
3656  char *last_space = strrchr(buf, ' ');
3657  if (last_space)
3658  pt = (last_space + 1);
3659 
3660  /* Skip the +/- */
3661  if ((pt[0] == '+') || (pt[0] == '-'))
3662  pt++;
3663 
3664  if (numtabs == 1)
3665  {
3666  /* First TAB. Collect all the matches */
3668 
3669  /* All matches are stored. Longest non-ambiguous string is ""
3670  * i.e. don't change 'buf'. Fake successful return this time. */
3671  if (UserTyped[0] == '\0')
3672  return true;
3673  }
3674 
3675  if ((Completed[0] == '\0') && (UserTyped[0] != '\0'))
3676  return false;
3677 
3678  /* NumMatched will _always_ be at least 1 since the initial
3679  * user-typed string is always stored */
3680  if ((numtabs == 1) && (NumMatched == 2))
3681  snprintf(Completed, sizeof(Completed), "%s", Matches[0]);
3682  else if ((numtabs > 1) && (NumMatched > 2))
3683  {
3684  /* cycle through all the matches */
3685  snprintf(Completed, sizeof(Completed), "%s", Matches[(numtabs - 2) % NumMatched]);
3686  }
3687 
3688  /* return the completed query */
3689  strncpy(pt, Completed, buf + buflen - pt);
3690 
3691  return true;
3692 }
static int NumMatched
Definition: init.c:90
static char Completed[256]
Definition: init.c:91
static int complete_all_nm_tags(const char *pt)
Pass a list of Notmuch tags to the completion code.
Definition: init.c:227
static char UserTyped[1024]
Definition: init.c:88
static const char ** Matches
Definition: init.c:92
+ 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 2953 of file init.c.

2954 {
2955  for (const struct Command *c = Commands; c->name; c++)
2956  {
2957  if (((c->func == mutt_parse_hook) || (c->func == mutt_parse_idxfmt_hook)) &&
2958  (mutt_str_strcasecmp(c->name, name) == 0))
2959  {
2960  return c->data;
2961  }
2962  }
2963  return MUTT_HOOK_NO_FLAGS;
2964 }
A user-callable command.
Definition: mutt_commands.h:54
const char * name
Name of the command.
Definition: mutt_commands.h:56
const struct Command Commands[]
Definition: init.h:4972
enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse the &#39;hook&#39; family of commands - Implements command_t.
Definition: hook.c:85
const char * name
Definition: pgpmicalg.c:45
enum CommandResult mutt_parse_idxfmt_hook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
Parse the &#39;index-format-hook&#39; command - Implements command_t.
Definition: hook.c:363
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_parse_rc_line()

enum CommandResult mutt_parse_rc_line ( char *  line,
struct Buffer token,
struct Buffer err 
)

Parse a line of user config.

Parameters
lineconfig line to read
tokenscratch buffer to be used by parser
errwhere to write error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Caller should free token->data when finished. the reason for this variable is to avoid having to allocate and deallocate a lot of memory if we are parsing many lines. the caller can pass in the memory to use, which avoids having to create new space for every call to this function.

Definition at line 3224 of file init.c.

3226 {
3227  if (!line || !*line)
3228  return 0;
3229 
3230  int i;
3231  enum CommandResult rc = MUTT_CMD_SUCCESS;
3232 
3233  struct Buffer expn = mutt_buffer_make(0);
3234  mutt_buffer_addstr(&expn, line);
3235  expn.dptr = expn.data;
3236 
3237  *err->data = 0;
3238 
3239  SKIPWS(expn.dptr);
3240  while (*expn.dptr != '\0')
3241  {
3242  if (*expn.dptr == '#')
3243  break; /* rest of line is a comment */
3244  if (*expn.dptr == ';')
3245  {
3246  expn.dptr++;
3247  continue;
3248  }
3249  mutt_extract_token(token, &expn, MUTT_TOKEN_NO_FLAGS);
3250  for (i = 0; Commands[i].name; i++)
3251  {
3252  if (mutt_str_strcmp(token->data, Commands[i].name) == 0)
3253  {
3254  rc = Commands[i].func(token, &expn, Commands[i].data, err);
3255  if (rc != MUTT_CMD_SUCCESS)
3256  { /* -1 Error, +1 Finish */
3257  goto finish; /* Propagate return code */
3258  }
3259  break; /* Continue with next command */
3260  }
3261  }
3262  if (!Commands[i].name)
3263  {
3264  mutt_buffer_printf(err, _("%s: unknown command"), NONULL(token->data));
3265  rc = MUTT_CMD_ERROR;
3266  break; /* Ignore the rest of the line */
3267  }
3268  }
3269 finish:
3270  mutt_buffer_dealloc(&expn);
3271  return rc;
3272 }
#define NONULL(x)
Definition: string2.h:37
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
command_t func
Function to parse the command.
Definition: mutt_commands.h:57
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
const char * name
Name of the command.
Definition: mutt_commands.h:56
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const struct Command Commands[]
Definition: init.h:4972
const char * name
Definition: pgpmicalg.c:45
#define SKIPWS(ch)
Definition: string2.h:47
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:293
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
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:2649
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h: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:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_query_variables()

int mutt_query_variables ( struct ListHead *  queries)

Implement the -Q command line flag.

Parameters
queriesList of query strings
Return values
0Success, all queries exist
1Error

Definition at line 3280 of file init.c.

3281 {
3282  struct Buffer value = mutt_buffer_make(256);
3283  struct Buffer tmp = mutt_buffer_make(256);
3284  int rc = 0;
3285 
3286  struct ListNode *np = NULL;
3287  STAILQ_FOREACH(np, queries, entries)
3288  {
3289  mutt_buffer_reset(&value);
3290 
3291  struct HashElem *he = cs_get_elem(Config, np->data);
3292  if (!he)
3293  {
3294  rc = 1;
3295  continue;
3296  }
3297 
3298  int rv = cs_he_string_get(Config, he, &value);
3299  if (CSR_RESULT(rv) != CSR_SUCCESS)
3300  {
3301  rc = 1;
3302  continue;
3303  }
3304 
3305  int type = DTYPE(he->type);
3306  if (IS_PATH(he) && !(he->type & DT_MAILBOX))
3307  mutt_pretty_mailbox(value.data, value.dsize);
3308 
3309  if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) && (type != DT_QUAD))
3310  {
3311  mutt_buffer_reset(&tmp);
3312  pretty_var(value.data, &tmp);
3313  mutt_buffer_strcpy(&value, tmp.data);
3314  }
3315 
3316  dump_config_neo(Config, he, &value, NULL, CS_DUMP_NO_FLAGS, stdout);
3317  }
3318 
3319  mutt_buffer_dealloc(&value);
3320  mutt_buffer_dealloc(&tmp);
3321 
3322  return rc; // TEST16: neomutt -Q charset
3323 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
#define DT_LONG
a number (long)
Definition: types.h:33
#define IS_PATH(x)
Definition: types.h:55
#define CSR_RESULT(x)
Definition: set.h:62
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:40
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:36
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
size_t dsize
Length of data.
Definition: buffer.h:37
void dump_config_neo(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value, struct Buffer *initial, ConfigDumpFlags flags, FILE *fp)
Dump the config in the style of NeoMutt.
Definition: dump.c:150
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:293
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:216
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:310
#define DT_MAILBOX
Don&#39;t perform path expansions.
Definition: types.h:47
#define CS_DUMP_NO_FLAGS
No flags are set.
Definition: dump.h:35
char * data
Pointer to data.
Definition: buffer.h:35
void mutt_pretty_mailbox(char *buf, size_t buflen)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:612
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
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
size_t pretty_var(const char *str, struct Buffer *buf)
Escape and stringify a config item value.
Definition: dump.c:80
char * data
String.
Definition: list.h:35
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
A List node for strings.
Definition: list.h:33
#define DT_NUMBER
a number
Definition: types.h:35
#define DT_BOOL
boolean option
Definition: types.h:30
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_value()

void reset_value ( const char *  name)