39 #include <sys/utsname.h> 108 int base_space = 512;
111 const int space = base_space + extra_space;
113 memset(&
Matches[current + 1], 0, space - current);
126 static void candidate(
char *user,
const char *src,
char *dest,
size_t dlen)
128 if (!dest || !user || !src)
131 if (strstr(src, user) != src)
141 for (l = 0; src[l] && src[l] == dest[l]; l++)
174 for (
int i = 0;
nm_tags[i]; i++)
192 for (
int num = 0; num < tag_count_1; num++)
244 static char *
find_cfg(
const char *home,
const char *xdg_cfg_home)
246 const char *names[] = {
252 const char *locations[][2] = {
253 { xdg_cfg_home,
"neomutt/" },
254 { xdg_cfg_home,
"mutt/" },
255 { home,
".neomutt/" },
261 for (
int i = 0; locations[i][0] || locations[i][1]; i++)
263 if (!locations[i][0])
266 for (
int j = 0; names[j]; j++)
270 snprintf(buf,
sizeof(buf),
"%s/%s%s", locations[i][0], locations[i][1], names[j]);
271 if (access(buf, F_OK) == 0)
287 char *mailname = NULL;
288 static const char *mn_files[] = {
"/etc/mailname",
"/etc/mail/mailname" };
299 if (mailname && *mailname)
320 struct utsname utsname;
331 if ((uname(&utsname)) == -1)
333 mutt_perror(
_(
"unable to determine nodename via uname()"));
337 str = utsname.nodename;
341 char *dot = strchr(str,
'.');
406 while ((ch = *tok->
dptr))
427 else if (!qc && ((ch ==
'\'') || (ch ==
'"')) && !(flags &
MUTT_TOKEN_QUOTE))
429 else if ((ch ==
'\\') && (qc !=
'\''))
431 if (tok->
dptr[0] ==
'\0')
433 switch (ch = *tok->
dptr++)
437 if (tok->
dptr[0] ==
'\0')
458 if (isdigit((
unsigned char) ch) && isdigit((
unsigned char) tok->
dptr[0]) &&
459 isdigit((
unsigned char) tok->
dptr[1]))
470 if (tok->
dptr[0] ==
'\0')
477 else if (isalpha((
unsigned char) ch))
485 else if ((ch ==
'`') && (!qc || (qc ==
'"')))
493 pc = strpbrk(pc,
"\\`");
500 }
while (pc && (pc[0] !=
'`'));
561 else if ((ch ==
'$') && (!qc || (qc ==
'"')) &&
562 ((tok->
dptr[0] ==
'{') || isalpha((
unsigned char) tok->
dptr[0])))
564 const char *env = NULL;
567 if (tok->
dptr[0] ==
'{')
569 pc = strchr(tok->
dptr,
'}');
587 for (pc = tok->
dptr; isalnum((
unsigned char) *pc) || (pc[0] ==
'_'); pc++)
817 if (getsid(0) == getpid())
860 if (access(np->
data, F_OK))
883 if (access(
mutt_b2s(&buf), F_OK) == 0)
887 if (access(
mutt_b2s(&buf), F_OK) == 0)
891 if (access(
mutt_b2s(&buf), F_OK) == 0)
897 if (access(
mutt_b2s(&buf), F_OK) == 0)
929 struct passwd *pw = getpwuid(getuid());
997 if (*line->
dptr ==
'#')
999 if (*line->
dptr ==
';')
1009 for (i = 0; i < size; i++)
1013 rc = cmd[i].
parse(token, line, cmd[i].
data, err);
1041 if (!line || (*line ==
'\0'))
1130 struct MyVar *myv = NULL;
1135 pt = buf + pos - spaces;
1136 while ((pt > buf) && !isspace((
unsigned char) *pt))
1175 strncpy(buf,
Completed, buflen - spaces);
1180 static const char *
const prefixes[] = {
"no",
"inv",
"?",
"&", 0 };
1186 for (
int num = 0; prefixes[num]; num++)
1206 for (
size_t i = 0; list[i]; i++)
1244 strncpy(pt,
Completed, buf + buflen - pt - spaces);
1261 for (
int num = 0; menu[num].
name; num++)
1267 for (
int num = 0; menu[num].
name; num++)
1292 strncpy(pt,
Completed, buf + buflen - pt - spaces);
1355 strncpy(buf,
Completed, buflen - spaces);
1409 strncpy(pt,
Completed, buf + buflen - pt - spaces);
1437 char *last_space = strrchr(buf,
' ');
1439 pt = (last_space + 1);
1442 if ((pt[0] ==
'+') || (pt[0] ==
'-'))
1470 strncpy(pt,
Completed, buf + buflen - pt);
1490 const int spaces = buf - pt;
1492 pt = buf + pos - spaces;
1493 while ((pt > buf) && !isspace((
unsigned char) *pt))
1501 const char *myvarval = NULL;
1509 var[vlen - 1] =
'\0';
1519 snprintf(pt, buflen - (pt - buf),
"%s=%s", var, pretty.
data);
1533 snprintf(pt, buflen - (pt - buf),
"%s=%s", var, pretty.
data);
#define CSR_SUCCESS
Action completed successfully.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Convenience wrapper for the gui headers.
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
#define mutt_warning(...)
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
struct RegexList SubscribedLists
List of regexes to match subscribed mailing lists.
union HashKey key
Key representing the data.
void mutt_comp_init(void)
Setup feature commands.
void mutt_pretty_mailbox(char *buf, size_t buflen)
Shorten a mailbox path using '~' or '='.
Container for lots of config items.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Miscellaneous email parsing routines.
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
pid_t filter_create(const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err)
Set up filter program.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
#define DT_LONG
a number (long)
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
intptr_t data
Data or flags to pass to the command.
CommandResult
Error codes for command_t parse functions.
#define TAILQ_FOREACH(var, head, field)
Error: Can't help the user.
struct ReplaceList SubjectRegexList
List of regexes to tidy the view of the email's subject.
Structs that make up an email.
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
The "currently-open" mailbox.
void mutt_lua_init(void)
Setup feature commands.
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
static char * getmailname(void)
Try to retrieve the FQDN from mailname files.
struct HashTable * label_hash
Hash Table for x-labels.
struct ListHead InlineAllow
List of inline types to counted.
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()
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
int mutt_label_complete(char *buf, size_t buflen, int numtabs)
Complete a label name.
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
size_t pretty_var(const char *str, struct Buffer *buf)
Escape and stringify a config item value.
void mutt_list_free_type(struct ListHead *h, list_free_t fn)
Free a List of type.
Cursor to iterate through a Hash Table.
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_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
#define MUTT_TOKEN_COMMENT
Don't reap comments.
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
HookFlags mutt_get_hook_type(const char *name)
Find a hook by name.
struct RegexList UnSubscribedLists
List of regexes to blacklist false matches in SubscribedLists.
bool mutt_nm_tag_complete(char *buf, size_t buflen, int numtabs)
Complete to the nearest notmuch tag.
String manipulation buffer.
static int execute_commands(struct ListHead *p)
Execute a set of NeoMutt commands.
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
WHERE char * C_Realname
Config: Real name of the user.
char * mutt_str_dup(const char *str)
Copy a string, safely.
void alias_init(void)
Set up the Alias globals.
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
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.
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, int flags)
Read a line from a file.
void mutt_commands_init(void)
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
const char * name
Name of the command.
WHERE char * C_Hostname
Config: Fully-qualified domain name of this machine.
void nm_db_longrun_init(struct Mailbox *m, bool writable)
Start a long transaction.
int cs_str_string_set(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
Index panel (list of emails)
A Command has been executed, Command.
void imap_init(void)
Setup feature commands.
size_t mutt_commands_array(struct Command **first)
Get Commands array.
bool mutt_nm_query_complete(char *buf, size_t buflen, int pos, int numtabs)
Complete to the nearest notmuch tag.
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
uint32_t HookFlags
Flags for mutt_parse_hook(), e.g. MUTT_FOLDER_HOOK.
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
char * name
Name of user variable.
static char * find_cfg(const char *home, const char *xdg_cfg_home)
Find a config file.
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Container for Accounts, Notifications.
#define DTYPE(x)
Mask for the Data Type.
struct HashElem ** get_elem_list(struct ConfigSet *cs)
Create a sorted list of all config items.
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Integrated Lua scripting.
Convenience wrapper for the config headers.
enum CommandResult(* parse)(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Function to parse a command.
char * HomeDir
User's home directory.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Assorted sorting methods.
WHERE char ProtectedHeaderMarker[256]
Unique ANSI string to mark protected headers in an email.
API for the header cache compression.
WHERE char * Username
User's login name.
Some miscellaneous functions.
#define mutt_array_size(x)
#define MUTT_HASH_STRCASECMP
use strcasecmp() to compare keys
Pager pager (email viewer)
size_t dsize
Length of data.
void mutt_hist_read_file(void)
Read the History from a file.
struct ConfigSet * cs
Parent ConfigSet.
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Header cache multiplexor.
Many unsorted constants and some structs.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
void clear_source_stack(void)
Free memory from the stack used for the souce command.
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
const struct Binding OpGeneric[]
Key bindings for the generic menu.
int cs_subset_he_string_get(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Convenience wrapper for the core headers.
struct MyVarList MyVars
List of all the user's custom config variables.
const char * name
name of the function
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
static char Completed[256]
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.
#define MUTT_TOKEN_NOSHELL
Don't expand environment variables.
bool config_init_main(struct ConfigSet *cs)
void alias_shutdown(void)
Clean up the Alias globals.
Compressed mbox local mailbox type.
struct ListHead Ignore
List of header patterns to ignore.
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.
int(* sort_t)(const void *a, const void *b)
Prototype for a function to compare two emails.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Read/write command history from/to a file.
#define MUTT_TOKEN_QUOTE
Don't interpret quotes.
Prototypes for many functions.
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
#define MUTT_TOKEN_CONDENSE
^(char) to control chars (macros)
int mutt_query_variables(struct ListHead *queries, bool show_docs)
Implement the -Q command line flag.
struct ListHead InlineExclude
List of inline types to ignore.
Notmuch virtual mailbox type.
int mutt_init(struct ConfigSet *cs, bool skip_sys_rc, struct ListHead *commands)
Initialise NeoMutt.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
WHERE bool C_Suspend
Config: Allow the user to suspend NeoMutt using '^Z'.
#define DT_PATH
a path to a file/directory
void nm_init(void)
Setup feature commands.
struct RegexList NoSpamList
List of regexes to whitelist non-spam emails.
static int MatchesListsize
void mutt_grouplist_init(void)
Initialize the GroupList singleton.
void mutt_keys_free(void)
Free the key maps.
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
static void matches_ensure_morespace(int current)
Allocate more space for auto-completion.
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Functions to parse commands in a config file.
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
WHERE char AttachmentMarker[256]
Unique ANSI string to mark PGP messages in an email.
#define DT_DEPRECATED
Config item shouldn't be used any more.
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
#define CS_DUMP_NO_FLAGS
No flags are set.
char * dptr
Current read/write position.
WHERE char * ShortHostname
Short version of the hostname.
#define MUTT_TOKEN_SPACE
Don't treat whitespace as a term.
struct ListHead MailToAllow
List of permitted fields in a mailto: url.
char * data
Pointer to data.
static bool get_hostname(struct ConfigSet *cs)
Find the Fully-Qualified Domain Name.
void nm_db_longrun_done(struct Mailbox *m)
Finish a long transaction.
Definitions of NeoMutt commands.
#define CS_DUMP_SHOW_DOCS
Show one-liner documentation for the config item.
int nm_get_all_tags(struct Mailbox *m, char **tag_list, int *tag_count)
Fill a list with all notmuch tags.
#define MUTT_TOKEN_PLUS
Treat '+' as a special.
enum CommandResult mutt_parse_rc_buffer(struct Buffer *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
#define STAILQ_FOREACH(var, head, field)
int cs_subset_str_string_get(const struct ConfigSubset *sub, const char *name, struct Buffer *result)
Get a config item as a string.
struct Notify * notify
Notifications handler.
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
void mutt_hist_init(void)
Create a set of empty History ring buffers.
void mutt_opts_free(void)
clean up before quitting
WHERE char * LastFolder
Previously selected mailbox.
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
const char * myvar_get(const char *var)
Get the value of a "my_" variable.
'Notmuch' (virtual) Mailbox type
int mutt_set_xdg_path(enum XdgType type, struct Buffer *buf)
Find an XDG path or its fallback.
#define MUTT_TOKEN_SEMICOLON
Don't treat ; as special.
void mutt_colors_free(struct Colors **ptr)
Free all the colours.
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
struct ReplaceList SpamList
List of regexes and patterns to match spam emails.
struct ListHead AttachExclude
List of attachment types to be ignored.
static int complete_all_nm_tags(const char *pt)
Pass a list of Notmuch tags to the completion code.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
#define DT_SYNONYM
synonym for another variable
Definitions of user functions.
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
struct ListHead UnIgnore
List of header patterns to unignore (see)
Warning: Help given to the user.
char * mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw)
Lookup a user's real name in /etc/passwd.
static char UserTyped[1024]
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
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.
const char * strkey
String key.
#define MUTT_TOKEN_MINUS
Treat '-' as a special.
char * C_Tmpdir
Config: Directory for temporary files.
static const char ** Matches
WHERE char * CurrentFolder
Currently selected mailbox.
struct RegexList UnMailLists
List of regexes to blacklist false matches in MailLists.
const struct Binding * km_get_table(enum MenuType menu)
Lookup a menu's keybindings.
#define MUTT_TOKEN_BACKTICK_VARS
Expand variables within backticks.
int type
Type of data stored in Hash Table, e.g. DT_STRING.
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()
size_t mutt_buffer_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
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()
#define MUTT_HOOK_NO_FLAGS
No flags are set.
#define STAILQ_EMPTY(head)
#define STAILQ_HEAD_INITIALIZER(head)
struct HashElem * mutt_hash_walk(const struct HashTable *table, struct HashWalkState *state)
Iterate through all the HashElem's in a Hash Table.
The item stored in a Hash Table.
#define MUTT_TOKEN_EQUAL
Treat '=' as a special.
int cs_str_reset(const struct ConfigSet *cs, const char *name, struct Buffer *err)
Reset a config item to its initial value.
Hundreds of global variables to back the user variables.
Handling of global boolean variables.
#define mutt_debug(LEVEL,...)
struct ConfigSubset * sub
Inherited config items.
void mutt_attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t.
uint16_t TokenFlags
Flags for mutt_extract_token(), e.g. MUTT_TOKEN_EQUAL.
void mutt_commands_free(void)
Free Commands array.
void mutt_grouplist_free(void)
Free GroupList singleton resource.
int getdnsdomainname(struct Buffer *domain)
Lookup the host's name using DNS.
const char * mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle)
Find last instance of a substring.
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Convenience wrapper for the library headers.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
WHERE struct HashTable * TagFormats
Hash Table of tag-formats (tag -> format string)
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
XDG system dir: /etc/xdg.
Handling of personal config ('my' variables)
struct ListHead AttachAllow
List of attachment types to be counted.
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
char * C_Charset
Config: Default character set for displaying text on screen.
char * mutt_ch_get_langinfo_charset(void)
Get the user's choice of character set.
#define MUTT_TOKEN_PATTERN
~%=!| are terms (for patterns)
#define STAILQ_FIRST(head)
void mutt_hist_free(void)
Free all the history lists.
#define MUTT_HASH_NO_FLAGS
No flags are set.
Mapping between a user key and a function.
#define DT_NUMBER
a number
#define DT_BOOL
boolean option
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
static void candidate(char *user, const char *src, char *dest, size_t dlen)
helper function for completion
bool C_VirtualSpoolfile
Config: (notmuch) Use the first virtual mailbox as a spool file.
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
#define MUTT_TOKEN_QUESTION
Treat '?' as a special.
void(* list_free_t)(void **ptr)
Prototype for a function to free List data.
struct Mailbox * mailbox
Mailbox in the list.
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
int mutt_var_value_complete(char *buf, size_t buflen, int pos)
Complete a variable/value.