Go to the documentation of this file.
39 #include <sys/utsname.h>
106 int base_space = 512;
109 const int space = base_space + extra_space;
111 memset(&
Matches[current + 1], 0, space - current);
124 static void candidate(
char *user,
const char *src,
char *dest,
size_t dlen)
126 if (!dest || !user || !src)
129 if (strstr(src, user) != src)
139 for (l = 0; src[l] && src[l] == dest[l]; l++)
172 for (
int i = 0;
nm_tags[i]; i++)
190 for (
int num = 0; num < tag_count_1; num++)
242 static char *
find_cfg(
const char *home,
const char *xdg_cfg_home)
244 const char *names[] = {
250 const char *locations[][2] = {
251 { xdg_cfg_home,
"neomutt/" },
252 { xdg_cfg_home,
"mutt/" },
253 { home,
".neomutt/" },
259 for (
int i = 0; locations[i][0] || locations[i][1]; i++)
261 if (!locations[i][0])
264 for (
int j = 0; names[j]; j++)
268 snprintf(buf,
sizeof(buf),
"%s/%s%s", locations[i][0], locations[i][1], names[j]);
269 if (access(buf, F_OK) == 0)
285 char *mailname = NULL;
286 static const char *mn_files[] = {
"/etc/mailname",
"/etc/mail/mailname" };
297 if (mailname && *mailname)
318 struct utsname utsname;
329 if ((uname(&utsname)) == -1)
331 mutt_perror(
_(
"unable to determine nodename via uname()"));
335 str = utsname.nodename;
339 char *dot = strchr(str,
'.');
411 while ((ch = *tok->
dptr))
432 else if (!qc && ((ch ==
'\'') || (ch ==
'"')) && !(flags &
MUTT_TOKEN_QUOTE))
434 else if ((ch ==
'\\') && (qc !=
'\''))
436 if (tok->
dptr[0] ==
'\0')
438 switch (ch = *tok->
dptr++)
442 if (tok->
dptr[0] ==
'\0')
463 if (isdigit((
unsigned char) ch) && isdigit((
unsigned char) tok->
dptr[0]) &&
464 isdigit((
unsigned char) tok->
dptr[1]))
475 if (tok->
dptr[0] ==
'\0')
482 else if (isalpha((
unsigned char) ch))
490 else if ((ch ==
'`') && (!qc || (qc ==
'"')))
498 pc = strpbrk(pc,
"\\`");
505 }
while (pc && (pc[0] !=
'`'));
566 else if ((ch ==
'$') && (!qc || (qc ==
'"')) &&
567 ((tok->
dptr[0] ==
'{') || isalpha((
unsigned char) tok->
dptr[0])))
569 const char *env = NULL;
572 if (tok->
dptr[0] ==
'{')
574 pc = strchr(tok->
dptr,
'}');
592 for (pc = tok->
dptr; isalnum((
unsigned char) *pc) || (pc[0] ==
'_'); pc++)
822 if (getsid(0) == getpid())
865 if (access(np->
data, F_OK))
934 struct passwd *pw = getpwuid(getuid());
1002 if (*line->
dptr ==
'#')
1004 if (*line->
dptr ==
';')
1014 for (i = 0; i < size; i++)
1018 rc = cmd[i].
parse(token, line, cmd[i].
data, err);
1046 if (!line || (*line ==
'\0'))
1135 struct MyVar *myv = NULL;
1140 pt = buf + pos - spaces;
1141 while ((pt > buf) && !isspace((
unsigned char) *pt))
1180 strncpy(buf,
Completed, buflen - spaces);
1185 static const char *
const prefixes[] = {
"no",
"inv",
"?",
"&", 0 };
1191 for (
int num = 0; prefixes[num]; num++)
1211 for (
size_t i = 0; list[i]; i++)
1249 strncpy(pt,
Completed, buf + buflen - pt - spaces);
1266 for (
int num = 0; menu[num].
name; num++)
1272 for (
int num = 0; menu[num].
name; num++)
1297 strncpy(pt,
Completed, buf + buflen - pt - spaces);
1360 strncpy(buf,
Completed, buflen - spaces);
1414 strncpy(pt,
Completed, buf + buflen - pt - spaces);
1442 char *last_space = strrchr(buf,
' ');
1444 pt = (last_space + 1);
1447 if ((pt[0] ==
'+') || (pt[0] ==
'-'))
1475 strncpy(pt,
Completed, buf + buflen - pt);
1495 const int spaces = buf - pt;
1497 pt = buf + pos - spaces;
1498 while ((pt > buf) && !isspace((
unsigned char) *pt))
1506 const char *myvarval = NULL;
1514 var[vlen - 1] =
'\0';
1524 snprintf(pt, buflen - (pt - buf),
"%s=%s", var, pretty.
data);
1538 snprintf(pt, buflen - (pt - buf),
"%s=%s", var, pretty.
data);
const char * mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle)
Find last instance of a substring.
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
static char * find_cfg(const char *home, const char *xdg_cfg_home)
Find a config file.
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
void alias_init(void)
Set up the Alias globals.
static char Completed[256]
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
struct ListHead InlineAllow
List of inline types to counted.
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
#define MUTT_TOKEN_PATTERN
~%=!| are terms (for patterns)
void mutt_hist_free(void)
Free all the history lists.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
WHERE char * C_Hostname
Config: Fully-qualified domain name of this machine.
#define MUTT_TOKEN_BACKTICK_VARS
Expand variables within backticks.
Mapping between a user key and a function.
WHERE char * C_RealName
Config: Real name of the user.
#define MUTT_TOKEN_SEMICOLON
Don't treat ; as special.
void imap_init(void)
Setup feature commands.
#define DT_DEPRECATED
Config item shouldn't be used any more.
union HashKey key
Key representing the data.
size_t mutt_commands_array(struct Command **first)
Get Commands array.
@ XDG_CONFIG_DIRS
XDG system dir: /etc/xdg.
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
bool C_VirtualSpoolFile
Config: (notmuch) Use the first virtual mailbox as a spool file.
String manipulation buffer.
int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
void mutt_buffer_seek(struct Buffer *buf, size_t offset)
set current read/write position to offset from beginning
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu's keybindings.
#define CSR_SUCCESS
Action completed successfully.
struct Notify * notify
Notifications handler.
void alias_shutdown(void)
Clean up the Alias globals.
struct ListHead Ignore
List of header patterns to ignore.
void mutt_grouplist_free(void)
Free GroupList singleton resource.
#define DTYPE(x)
Mask for the Data Type.
void mutt_hist_read_file(void)
Read the History from a file.
#define TAILQ_FOREACH(var, head, field)
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
#define MUTT_TOKEN_QUESTION
Treat '?' as a special.
char * mutt_str_dup(const char *str)
Copy a string, safely.
static void candidate(char *user, const char *src, char *dest, size_t dlen)
helper function for completion
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
@ LL_DEBUG1
Log at debug level 1.
int mutt_query_variables(struct ListHead *queries, bool show_docs)
Implement the -Q command line flag.
#define STAILQ_FIRST(head)
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
int getdnsdomainname(struct Buffer *result)
Lookup the host's name using DNS.
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
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.
char * dptr
Current read/write position.
void(* list_free_t)(void **ptr)
Prototype for a function to free List data.
size_t dsize
Length of data.
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.
void mutt_opts_free(void)
clean up before quitting
struct Mailbox * mailbox
Mailbox in the list.
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
const char * name
name of the function
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
#define STAILQ_EMPTY(head)
WHERE char * Username
User's login name.
int(* sort_t)(const void *a, const void *b)
Prototype for a function to compare two emails.
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
#define mutt_array_size(x)
#define STAILQ_FOREACH(var, head, field)
struct HashTable * label_hash
Hash Table for x-labels.
void clear_source_stack(void)
Free memory from the stack used for the souce command.
int log_disp_terminal(time_t stamp, const char *file, int line, const char *function, enum LogLevel level,...)
Save a log line to the terminal - Implements log_dispatcher_t.
void mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
HookFlags mutt_get_hook_type(const char *name)
Find a hook by name.
static int execute_commands(struct ListHead *p)
Execute a set of NeoMutt commands.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
#define CS_DUMP_NO_FLAGS
No flags are set.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
struct HashElem ** get_elem_list(struct ConfigSet *cs)
Create a sorted list of all config items.
int mutt_label_complete(char *buf, size_t buflen, int numtabs)
Complete a label name.
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
#define MUTT_RL_NO_FLAGS
No flags are set.
WHERE bool C_Suspend
Config: Allow the user to suspend NeoMutt using '^Z'.
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
void mutt_comp_init(void)
Setup feature commands.
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
pid_t filter_create(const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err)
Set up filter program.
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
@ NT_COMMAND
A Command has been executed, Command.
WHERE char AttachmentMarker[256]
Unique ANSI string to mark PGP messages in an email.
const char * strkey
String key.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
#define MUTT_TOKEN_COMMENT
Don't reap comments.
static bool get_hostname(struct ConfigSet *cs)
Find the Fully-Qualified Domain Name.
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
#define DT_SYNONYM
synonym for another variable
#define DT_NUMBER
a number
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
int mutt_command_complete(char *buf, size_t buflen, int pos, int numtabs)
Complete a command name.
struct RegexList MailLists
List of regexes to match mailing lists.
struct ListHead InlineExclude
List of inline types to ignore.
uint16_t TokenFlags
Flags for mutt_extract_token(), e.g. MUTT_TOKEN_EQUAL.
bool mutt_nm_tag_complete(char *buf, size_t buflen, int numtabs)
Complete to the nearest notmuch tag.
enum CommandResult mutt_parse_rc_buffer(struct Buffer *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
WHERE char * LastFolder
Previously selected mailbox.
WHERE char ProtectedHeaderMarker[256]
Unique ANSI string to mark protected headers in an email.
struct ConfigSet * cs
Parent ConfigSet.
#define DT_LONG
a number (long)
size_t pretty_var(const char *str, struct Buffer *buf)
Escape and stringify a config item value.
void nm_db_longrun_init(struct Mailbox *m, bool writable)
Start a long transaction.
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
#define DT_PATH
a path to a file/directory
void mutt_list_free_type(struct ListHead *h, list_free_t fn)
Free a List of type.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
void nm_db_longrun_done(struct Mailbox *m)
Finish a long transaction.
size_t mutt_buffer_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
int nm_get_all_tags(struct Mailbox *m, char **tag_list, int *tag_count)
Fill a list with all notmuch tags.
uint64_t mutt_rand64(void)
Create a 64-bit random number.
void mutt_attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t.
#define mutt_debug(LEVEL,...)
uint32_t HookFlags
Flags for mutt_parse_hook(), e.g. MUTT_FOLDER_HOOK.
struct HashElem * mutt_hash_walk(const struct HashTable *table, struct HashWalkState *state)
Iterate through all the HashElem's in a Hash Table.
@ MUTT_CMD_SUCCESS
Success: Command worked.
int type
Type of data stored in Hash Table, e.g. DT_STRING.
char * C_Tmpdir
Config: Directory for temporary files.
void mutt_colors_free(struct Colors **ptr)
Free all the colours.
#define MUTT_TOKEN_EQUAL
Treat '=' as a special.
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
@ MUTT_CMD_ERROR
Error: Can't help the user.
Cursor to iterate through a Hash Table.
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
void mutt_hist_init(void)
Create a set of empty History ring buffers.
static const char ** Matches
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
intptr_t data
Data or flags to pass to the command.
CommandResult
Error codes for command_t parse functions.
#define DT_BOOL
boolean option
void mutt_commands_init(void)
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
#define STAILQ_HEAD_INITIALIZER(head)
bool mutt_nm_query_complete(char *buf, size_t buflen, int pos, int numtabs)
Complete to the nearest notmuch tag.
void mutt_commands_free(void)
Free Commands array.
#define MUTT_HASH_NO_FLAGS
No flags are set.
The item stored in a Hash Table.
int mutt_set_xdg_path(enum XdgType type, struct Buffer *buf)
Find an XDG path or its fallback.
@ MUTT_CMD_WARNING
Warning: Help given to the user.
enum CommandResult parse_my_hdr(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'my_hdr' command - Implements Command::parse()
char * HomeDir
User's home directory.
void mutt_lua_init(void)
Setup feature commands.
#define MUTT_HASH_STRCASECMP
use strcasecmp() to compare keys
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
WHERE char * ShortHostname
Short version of the hostname.
struct ListHead MailToAllow
List of permitted fields in a mailto: url.
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
@ MENU_MAIN
Index panel (list of emails)
Container for Accounts, Notifications.
#define MUTT_TOKEN_QUOTE
Don't interpret quotes.
enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'hook' family of commands - Implements Command::parse()
int cs_subset_he_string_get(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Container for lots of config items.
int cs_subset_str_string_get(const struct ConfigSubset *sub, const char *name, struct Buffer *result)
Get a config item as a string.
static int MatchesListsize
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
char * mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw)
Lookup a user's real name in /etc/passwd.
int cs_str_reset(const struct ConfigSet *cs, const char *name, struct Buffer *err)
Reset a config item to its initial value.
void nm_init(void)
Setup feature commands.
int mutt_init(struct ConfigSet *cs, bool skip_sys_rc, struct ListHead *commands)
Initialise NeoMutt.
struct ConfigSubset * sub
Inherited config items.
WHERE char * CurrentFolder
Currently selected mailbox.
const char * name
Name of the command.
#define CS_DUMP_SHOW_DOCS
Show one-liner documentation for the config item.
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
#define MUTT_TOKEN_NOSHELL
Don't expand environment variables.
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
static void matches_ensure_morespace(int current)
Allocate more space for auto-completion.
int mutt_var_value_complete(char *buf, size_t buflen, int pos)
Complete a variable/value.
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
void mutt_grouplist_init(void)
Initialize the GroupList singleton.
static char * getmailname(void)
Try to retrieve the FQDN from mailname files.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
char * mutt_ch_get_langinfo_charset(void)
Get the user's choice of character set.
WHERE struct HashTable * TagFormats
Hash Table of tag-formats (tag -> format string)
struct ReplaceList SpamList
List of regexes and patterns to match spam emails.
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
char * C_Charset
Config: Default character set for displaying text on screen.
void mutt_pretty_mailbox(char *buf, size_t buflen)
Shorten a mailbox path using '~' or '='.
char * data
Pointer to data.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
struct ListHead UnIgnore
List of header patterns to unignore (see)
char * name
Name of user variable.
struct MyVarList MyVars
List of all the user's custom config variables.
const struct Binding OpGeneric[]
Key bindings for the generic menu.
static char UserTyped[1024]
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
int cs_str_string_set(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
#define mutt_warning(...)
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
#define MUTT_TOKEN_MINUS
Treat '-' as a special.
struct ReplaceList SubjectRegexList
List of regexes to tidy the view of the email's subject.
#define MUTT_TOKEN_PLUS
Treat '+' as a special.
@ MENU_PAGER
Pager pager (email viewer)
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
struct ListHead AttachAllow
List of attachment types to be counted.
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
#define MUTT_TOKEN_SPACE
Don't treat whitespace as a term.
enum CommandResult(* parse)(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Function to parse a command.
enum CommandResult mutt_parse_idxfmt_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'index-format-hook' command - Implements Command::parse()
static int complete_all_nm_tags(const char *pt)
Pass a list of Notmuch tags to the completion code.
#define MUTT_HOOK_NO_FLAGS
No flags are set.
void mutt_keys_free(void)
Free the key maps.
struct ListHead AttachExclude
List of attachment types to be ignored.
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)