37#include <sys/utsname.h>
113static char *
find_cfg(
const char *home,
const char *xdg_cfg_home)
115 const char *names[] = {
121 const char *locations[][2] = {
122 { xdg_cfg_home,
"neomutt/" },
123 { xdg_cfg_home,
"mutt/" },
124 { home,
".neomutt/" },
130 for (
int i = 0; locations[i][0] || locations[i][1]; i++)
132 if (!locations[i][0])
135 for (
int j = 0; names[j]; j++)
137 char buf[256] = { 0 };
139 snprintf(buf,
sizeof(buf),
"%s/%s%s", locations[i][0], locations[i][1], names[j]);
140 if (access(buf, F_OK) == 0)
156 char *mailname = NULL;
157 static const char *mn_files[] = {
"/etc/mailname",
"/etc/mail/mailname" };
168 if (mailname && *mailname)
188 const char *short_host = NULL;
189 struct utsname utsname = { 0 };
194 short_host = c_hostname;
201 if ((uname(&utsname)) == -1)
203 mutt_perror(
_(
"unable to determine nodename via uname()"));
207 short_host = utsname.nodename;
211 char *dot = strchr(short_host,
'.');
290 while ((ch = *tok->
dptr))
311 else if (!qc && ((ch ==
'\'') || (ch ==
'"')) && !(flags &
MUTT_TOKEN_QUOTE))
313 else if ((ch ==
'\\') && (qc !=
'\''))
315 if (tok->
dptr[0] ==
'\0')
317 switch (ch = *tok->
dptr++)
321 if (tok->
dptr[0] ==
'\0')
342 if (isdigit((
unsigned char) ch) && isdigit((
unsigned char) tok->
dptr[0]) &&
343 isdigit((
unsigned char) tok->
dptr[1]))
354 if (tok->
dptr[0] ==
'\0')
361 else if (isalpha((
unsigned char) ch))
369 else if ((ch ==
'`') && (!qc || (qc ==
'"')))
377 pc = strpbrk(pc,
"\\`");
384 }
while (pc && (pc[0] !=
'`'));
448 else if ((ch ==
'$') && (!qc || (qc ==
'"')) &&
449 ((tok->
dptr[0] ==
'{') || isalpha((
unsigned char) tok->
dptr[0])))
451 const char *env = NULL;
454 if (tok->
dptr[0] ==
'{')
456 pc = strchr(tok->
dptr,
'}');
474 for (pc = tok->
dptr; isalnum((
unsigned char) *pc) || (pc[0] ==
'_'); pc++)
667 if (getsid(0) == getpid())
710 if (access(np->
data, F_OK))
778 char name[256] = { 0 };
782 struct passwd *pw = getpwuid(getuid());
805 if (c_virtual_spool_file)
851 if (*line->
dptr ==
'#')
853 if (*line->
dptr ==
';')
863 for (i = 0; i < size; i++)
868 rc = cmd[i].
parse(token, line, cmd[i].
data, err);
895 if (!line || (*line ==
'\0'))
void alias_init(void)
Set up the Alias globals.
void alias_shutdown(void)
Clean up the Alias globals.
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
void mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
void mutt_buffer_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
size_t mutt_buffer_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Color and attribute parsing.
void mutt_colors_cleanup(void)
Cleanup all the colours.
CommandResult
Error codes for command_t parse functions.
@ MUTT_CMD_SUCCESS
Success: Command worked.
@ MUTT_CMD_ERROR
Error: Can't help the user.
@ MUTT_CMD_WARNING
Warning: Help given to the user.
@ MUTT_CMD_FINISH
Finish: Stop processing this file.
void clear_source_stack(void)
Free memory from the stack used for the source command.
int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
Functions to parse commands in a config file.
void mutt_comp_init(void)
Setup feature commands.
Compressed mbox local mailbox type.
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Convenience wrapper for the config headers.
char * HomeDir
User's home directory.
Convenience wrapper for the core headers.
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
size_t pretty_var(const char *str, struct Buffer *buf)
Escape and stringify a config item value.
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.
void mutt_pretty_mailbox(char *buf, size_t buflen)
Shorten a mailbox path using '~' or '='.
#define CS_DUMP_NO_FLAGS
No flags are set.
#define CS_DUMP_SHOW_DOCS
Show one-liner documentation for the config item.
Structs that make up an email.
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
#define MUTT_RL_NO_FLAGS
No flags are set.
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
pid_t filter_create(const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err)
Set up filter program.
int getdnsdomainname(struct Buffer *result)
Lookup the host's name using DNS.
struct ReplaceList SpamList
List of regexes and patterns to match spam emails.
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
struct RegexList MailLists
List of regexes to match mailing lists.
struct ListHead MailToAllow
List of permitted fields in a mailto: url.
struct ListHead Ignore
List of header patterns to ignore.
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
struct ListHead UnIgnore
List of header patterns to unignore (see)
void mutt_grouplist_free(void)
Free GroupList singleton resource.
void mutt_grouplist_init(void)
Initialize the GroupList singleton.
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() -.
#define mutt_warning(...)
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 -.
#define mutt_debug(LEVEL,...)
Convenience wrapper for the gui headers.
Read/write command history from/to a file.
void mutt_hist_read_file(void)
Read the History from a file.
void mutt_hist_init(void)
Create a set of empty History ring buffers.
void mutt_hist_free(void)
Free all the history lists.
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
Parse and execute user-defined hooks.
#define MUTT_HOOK_NO_FLAGS
No flags are set.
void imap_init(void)
Setup feature commands.
static char * find_cfg(const char *home, const char *xdg_cfg_home)
Find a config file.
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
enum CommandResult mutt_parse_rc_buffer(struct Buffer *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
static char * getmailname(void)
Try to retrieve the FQDN from mailname files.
static int execute_commands(struct ListHead *p)
Execute a set of NeoMutt commands.
int mutt_query_variables(struct ListHead *queries, bool show_docs)
Implement the -Q command line flag.
void mutt_opts_free(void)
Clean up before quitting.
int mutt_init(struct ConfigSet *cs, bool skip_sys_rc, struct ListHead *commands)
Initialise NeoMutt.
static bool get_hostname(struct ConfigSet *cs)
Find the Fully-Qualified Domain Name.
void mutt_keys_free(void)
Free the key maps.
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
@ LL_DEBUG1
Log at debug level 1.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
#define mutt_array_size(x)
char * mutt_ch_get_langinfo_charset(void)
Get the user's choice of character set.
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
Convenience wrapper for the library headers.
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Many unsorted constants and some structs.
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
#define MUTT_TOKEN_BACKTICK_VARS
Expand variables within backticks.
#define MUTT_TOKEN_MINUS
Treat '-' as a special.
#define MUTT_TOKEN_PLUS
Treat '+' as a special.
#define MUTT_TOKEN_COMMENT
Don't reap comments.
#define MUTT_TOKEN_QUOTE
Don't interpret quotes.
#define MUTT_TOKEN_NOSHELL
Don't expand environment variables.
uint16_t TokenFlags
Flags for mutt_extract_token(), e.g. MUTT_TOKEN_EQUAL.
#define MUTT_TOKEN_SPACE
Don't treat whitespace as a term.
#define MUTT_TOKEN_SEMICOLON
Don't treat ; as special.
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
#define MUTT_TOKEN_PATTERN
~%=!| are terms (for patterns)
#define MUTT_TOKEN_EQUAL
Treat '=' as a special.
#define MUTT_TOKEN_QUESTION
Treat '?' as a special.
void mutt_commands_free(void)
Free Commands array.
size_t mutt_commands_array(struct Command **first)
Get Commands array.
void mutt_commands_init(void)
Initialize commands array and register default commands.
struct CommandArray commands
Definitions of NeoMutt commands.
Hundreds of global variables to back the user variables.
char * LastFolder
Previously selected mailbox.
char * ShortHostname
Short version of the hostname.
struct ListHead MimeLookupList
List of mime types that that shouldn't use the mailcap entry.
struct ListHead AlternativeOrderList
List of preferred mime types to display.
struct ListHead AutoViewList
List of mime types to auto view.
char * CurrentFolder
Currently selected mailbox.
struct ListHead UserHeader
List of custom headers to add to outgoing emails.
struct ListHead Muttrc
List of config files to read.
char * Username
User's login name.
struct ListHead HeaderOrderList
List of header fields in the order they should be displayed.
void mutt_lua_init(void)
Setup feature commands.
Integrated Lua scripting.
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
char * mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw)
Lookup a user's real name in /etc/passwd.
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
int mutt_set_xdg_path(enum XdgType type, struct Buffer *buf)
Find an XDG path or its fallback.
Some miscellaneous functions.
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
Handling of personal config ('my' variables)
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
@ NT_COMMAND
A Command has been executed, Command.
Notmuch virtual mailbox type.
void nm_init(void)
Setup feature commands.
Handling of global boolean variables.
bool OptNoCurses
(pseudo) when sending in batch mode
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Prototypes for many functions.
@ XDG_CONFIG_DIRS
XDG system dir: /etc/xdg.
#define STAILQ_HEAD_INITIALIZER(head)
#define STAILQ_FIRST(head)
#define STAILQ_FOREACH(var, head, field)
#define STAILQ_EMPTY(head)
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.
int cs_str_reset(const struct ConfigSet *cs, const char *name, struct Buffer *err)
Reset a config item to its initial value.
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 CSR_SUCCESS
Action completed successfully.
String manipulation buffer.
char * dptr
Current read/write position.
size_t dsize
Length of data.
char * data
Pointer to data.
enum CommandResult(* parse)(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
intptr_t data
Data or flags to pass to the command.
const char * name
Name of the command.
Container for lots of config items.
struct ConfigSet * cs
Parent ConfigSet.
The item stored in a Hash Table.
int type
Type of data stored in Hash Table, e.g. DT_STRING.
struct Mailbox * mailbox
Mailbox in the list.
Container for Accounts, Notifications.
struct Notify * notify
Notifications handler.
struct ConfigSubset * sub
Inherited config items.
int cs_subset_he_string_get(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
int cs_subset_str_string_get(const struct ConfigSubset *sub, const char *name, struct Buffer *result)
Get a config item as a string.
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
#define DTYPE(x)
Mask for the Data Type.
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
#define DT_LONG
a number (long)
#define DT_BOOL
boolean option
#define DT_DEPRECATED
Config item shouldn't be used any more.
#define DT_PATH
a path to a file/directory
#define DT_NUMBER
a number