NeoMutt  2024-02-01-35-geee02f
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
init.c File Reference

Config/command parsing. More...

#include "config.h"
#include <errno.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "alias/lib.h"
#include "gui/lib.h"
#include "init.h"
#include "color/lib.h"
#include "compmbox/lib.h"
#include "history/lib.h"
#include "imap/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "notmuch/lib.h"
#include "parse/lib.h"
#include "sidebar/lib.h"
#include "commands.h"
#include "globals.h"
#include "hook.h"
#include "mutt_logging.h"
#include "muttlib.h"
#include "protos.h"
#include "conn/lib.h"
#include "mutt_lua.h"
+ Include dependency graph for init.c:

Go to the source code of this file.

Functions

static int execute_commands (struct ListHead *p)
 Execute a set of NeoMutt commands.
 
static char * find_cfg (const char *home, const char *xdg_cfg_home)
 Find a config file.
 
static char * getmailname (void)
 Try to retrieve the FQDN from mailname files.
 
static bool get_hostname (struct ConfigSet *cs)
 Find the Fully-Qualified Domain Name.
 
void mutt_opts_cleanup (void)
 Clean up before quitting.
 
int mutt_init (struct ConfigSet *cs, const char *dlevel, const char *dfile, bool skip_sys_rc, struct ListHead *commands)
 Initialise NeoMutt.
 
int mutt_query_variables (struct ListHead *queries, bool show_docs)
 Implement the -Q command line flag.
 

Detailed Description

Config/command parsing.

Authors
  • Michael R. Elkins
  • Pietro Cerutti
  • Richard Russon
  • Rayford Shireman

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

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

Definition in file init.c.

Function Documentation

◆ execute_commands()

static int execute_commands ( struct ListHead *  p)
static

Execute a set of NeoMutt commands.

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

Definition at line 77 of file init.c.

78{
79 int rc = 0;
80 struct Buffer *err = buf_pool_get();
81
82 struct ListNode *np = NULL;
83 STAILQ_FOREACH(np, p, entries)
84 {
85 enum CommandResult rc2 = parse_rc_line(np->data, err);
86 if (rc2 == MUTT_CMD_ERROR)
87 mutt_error(_("Error in command line: %s"), buf_string(err));
88 else if (rc2 == MUTT_CMD_WARNING)
89 mutt_warning(_("Warning in command line: %s"), buf_string(err));
90
91 if ((rc2 == MUTT_CMD_ERROR) || (rc2 == MUTT_CMD_WARNING))
92 {
93 buf_pool_release(&err);
94 return -1;
95 }
96 }
97 buf_pool_release(&err);
98
99 return rc;
100}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:97
CommandResult
Error codes for command_t parse functions.
Definition: command.h:36
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition: command.h:37
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition: command.h:38
#define mutt_warning(...)
Definition: logging2.h:90
#define mutt_error(...)
Definition: logging2.h:92
#define _(a)
Definition: message.h:28
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
enum CommandResult parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: rc.c:104
String manipulation buffer.
Definition: buffer.h:36
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_cfg()

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

Find a config file.

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

Definition at line 109 of file init.c.

110{
111 const char *names[] = {
112 "neomuttrc",
113 "muttrc",
114 NULL,
115 };
116
117 const char *locations[][2] = {
118 { xdg_cfg_home, "neomutt/" },
119 { xdg_cfg_home, "mutt/" },
120 { home, ".neomutt/" },
121 { home, ".mutt/" },
122 { home, "." },
123 { NULL, NULL },
124 };
125
126 for (int i = 0; locations[i][0] || locations[i][1]; i++)
127 {
128 if (!locations[i][0])
129 continue;
130
131 for (int j = 0; names[j]; j++)
132 {
133 char buf[256] = { 0 };
134
135 snprintf(buf, sizeof(buf), "%s/%s%s", locations[i][0], locations[i][1], names[j]);
136 if (access(buf, F_OK) == 0)
137 return mutt_str_dup(buf);
138 }
139 }
140
141 return NULL;
142}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getmailname()

static char * getmailname ( void  )
static

Try to retrieve the FQDN from mailname files.

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

Definition at line 150 of file init.c.

151{
152 char *mailname = NULL;
153 static const char *mn_files[] = { "/etc/mailname", "/etc/mail/mailname" };
154
155 for (size_t i = 0; i < mutt_array_size(mn_files); i++)
156 {
157 FILE *fp = mutt_file_fopen(mn_files[i], "r");
158 if (!fp)
159 continue;
160
161 size_t len = 0;
162 mailname = mutt_file_read_line(NULL, &len, fp, NULL, MUTT_RL_NO_FLAGS);
163 mutt_file_fclose(&fp);
164 if (mailname && *mailname)
165 break;
166
167 FREE(&mailname);
168 }
169
170 return mailname;
171}
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
Definition: file.c:801
#define mutt_file_fclose(FP)
Definition: file.h:148
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:147
#define MUTT_RL_NO_FLAGS
No flags are set.
Definition: file.h:40
#define FREE(x)
Definition: memory.h:45
#define mutt_array_size(x)
Definition: memory.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_hostname()

static bool get_hostname ( struct ConfigSet cs)
static

Find the Fully-Qualified Domain Name.

Parameters
csConfig Set
Return values
trueSuccess
falseError, failed to find any name

Use several methods to try to find the Fully-Qualified domain name of this host. If the user has already configured a hostname, this function will use it.

Definition at line 183 of file init.c.

184{
185 const char *short_host = NULL;
186 struct utsname utsname = { 0 };
187
188 const char *const c_hostname = cs_subset_string(NeoMutt->sub, "hostname");
189 if (c_hostname)
190 {
191 short_host = c_hostname;
192 }
193 else
194 {
195 /* The call to uname() shouldn't fail, but if it does, the system is horribly
196 * broken, and the system's networking configuration is in an unreliable
197 * state. We should bail. */
198 if ((uname(&utsname)) == -1)
199 {
200 mutt_perror(_("unable to determine nodename via uname()"));
201 return false; // TEST09: can't test
202 }
203
204 short_host = utsname.nodename;
205 }
206
207 /* some systems report the FQDN instead of just the hostname */
208 char *dot = strchr(short_host, '.');
209 if (dot)
210 ShortHostname = mutt_strn_dup(short_host, dot - short_host);
211 else
212 ShortHostname = mutt_str_dup(short_host);
213
214 // All the code paths from here alloc memory for the fqdn
215 char *fqdn = mutt_str_dup(c_hostname);
216 if (!fqdn)
217 {
218 mutt_debug(LL_DEBUG1, "Setting $hostname\n");
219 /* now get FQDN. Use configured domain first, DNS next, then uname */
220#ifdef DOMAIN
221 /* we have a compile-time domain name, use that for `$hostname` */
222 mutt_str_asprintf(&fqdn, "%s.%s", NONULL(ShortHostname), DOMAIN);
223#else
224 fqdn = getmailname();
225 if (!fqdn)
226 {
227 struct Buffer *domain = buf_pool_get();
228 if (getdnsdomainname(domain) == 0)
229 {
230 mutt_str_asprintf(&fqdn, "%s.%s", NONULL(ShortHostname), buf_string(domain));
231 }
232 else
233 {
234 /* DNS failed, use the nodename. Whether or not the nodename had a '.'
235 * in it, we can use the nodename as the FQDN. On hosts where DNS is
236 * not being used, e.g. small network that relies on hosts files, a
237 * short host name is all that is required for SMTP to work correctly.
238 * It could be wrong, but we've done the best we can, at this point the
239 * onus is on the user to provide the correct hostname if the nodename
240 * won't work in their network. */
241 fqdn = mutt_str_dup(utsname.nodename);
242 }
243 buf_pool_release(&domain);
244 mutt_debug(LL_DEBUG1, "Hostname: %s\n", NONULL(fqdn));
245 }
246#endif
247 }
248
249 if (fqdn)
250 {
251 cs_str_initial_set(cs, "hostname", fqdn, NULL);
252 cs_str_reset(cs, "hostname", NULL);
253 FREE(&fqdn);
254 }
255
256 return true;
257}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
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:503
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:438
int getdnsdomainname(struct Buffer *result)
Lookup the host's name using DNS.
Definition: getdomain.c:125
char * ShortHostname
Short version of the hostname.
Definition: globals.c:39
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
#define mutt_perror(...)
Definition: logging2.h:93
static char * getmailname(void)
Try to retrieve the FQDN from mailname files.
Definition: init.c:150
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
Definition: string.c:429
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:852
#define NONULL(x)
Definition: string2.h:37
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_opts_cleanup()

void mutt_opts_cleanup ( void  )

Clean up before quitting.

Definition at line 262 of file init.c.

263{
265
267 sb_cleanup();
268
274
277
278 /* Lists of strings */
288
290
292 FREE(&HomeDir);
295 FREE(&Username);
296
298
300
303
306}
void alias_cleanup(void)
Clean up the Alias globals.
Definition: alias.c:727
void mutt_colors_cleanup(void)
Cleanup all the colours.
Definition: color.c:64
void source_stack_cleanup(void)
Free memory from the stack used for the source command.
Definition: commands.c:1627
char * HomeDir
User's home directory.
Definition: globals.c:38
void commands_cleanup(void)
Free Commands array.
Definition: command.c:65
struct ReplaceList SpamList
List of regexes to match subscribed mailing lists.
Definition: globals.c:46
struct RegexList SubscribedLists
List of header patterns to unignore (see)
Definition: globals.c:48
struct RegexList UnSubscribedLists
Definition: globals.c:54
struct RegexList UnMailLists
List of regexes to exclude false matches in SubscribedLists.
Definition: globals.c:52
struct RegexList MailLists
List of permitted fields in a mailto: url.
Definition: globals.c:40
struct ListHead MailToAllow
List of regexes to identify non-spam emails.
Definition: globals.c:42
struct ListHead Ignore
List of regexes to match mailing lists.
Definition: globals.c:38
struct RegexList NoSpamList
List of regexes and patterns to match spam emails.
Definition: globals.c:44
struct ListHead UnIgnore
List of regexes to exclude false matches in MailLists.
Definition: globals.c:50
char * LastFolder
Previously selected mailbox.
Definition: globals.c:44
struct ListHead MimeLookupList
List of mime types that that shouldn't use the mailcap entry.
Definition: globals.c:51
struct ListHead AlternativeOrderList
List of preferred mime types to display.
Definition: globals.c:48
struct ListHead AutoViewList
List of mime types to auto view.
Definition: globals.c:49
char * CurrentFolder
Currently selected mailbox.
Definition: globals.c:43
struct ListHead UserHeader
List of custom headers to add to outgoing emails.
Definition: globals.c:54
struct ListHead Muttrc
List of config files to read.
Definition: globals.c:52
char * Username
User's login name.
Definition: globals.c:41
struct ListHead HeaderOrderList
List of header fields in the order they should be displayed.
Definition: globals.c:50
void mutt_grouplist_cleanup(void)
Free GroupList singleton resource.
Definition: group.c:108
void mutt_hist_cleanup(void)
Free all the history lists.
Definition: history.c:442
void mutt_delete_hooks(HookFlags type)
Delete matching hooks.
Definition: hook.c:380
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:36
void mutt_keys_cleanup(void)
Free the key maps.
Definition: init.c:230
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:179
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:475
void sb_cleanup(void)
Clean up the Sidebar.
Definition: sidebar.c:213
void driver_tags_cleanup(void)
Deinitialize structures used for tags.
Definition: tags.c:245
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_init()

int mutt_init ( struct ConfigSet cs,
const char *  dlevel,
const char *  dfile,
bool  skip_sys_rc,
struct ListHead *  commands 
)

Initialise NeoMutt.

Parameters
csConfig Set
dlevelCommand line debug level
dfileCommand line debug file
skip_sys_rcIf true, don't read the system config file
commandsList of config commands to execute
Return values
0Success
1Error

Definition at line 318 of file init.c.

320{
321 bool need_pause = false;
322 int rc = 1;
323 struct Buffer err = buf_make(256);
324 struct Buffer buf = buf_make(256);
325
327 alias_init();
329 hooks_init();
331 imap_init();
332#ifdef USE_LUA
334#endif
336
337 menu_init();
338 sb_init();
339#ifdef USE_NOTMUCH
340 nm_init();
341#endif
342
343#ifdef NEOMUTT_DIRECT_COLORS
344 /* Test if we run in a terminal which supports direct colours.
345 *
346 * The user/terminal can indicate their capability independent of the
347 * terminfo file by setting the COLORTERM environment variable to "truecolor"
348 * or "24bit" (case sensitive).
349 *
350 * Note: This is to test is less about whether the terminal understands
351 * direct color commands but more about whether ncurses believes it can send
352 * them to the terminal, e.g. ncurses ignores COLORTERM.
353 */
354 if (COLORS == 16777216) // 2^24
355 {
356 /* Ncurses believes the Terminal supports it check the environment variable
357 * to respect the user's choice */
358 const char *env_colorterm = mutt_str_getenv("COLORTERM");
359 if (env_colorterm && (mutt_str_equal(env_colorterm, "truecolor") ||
360 mutt_str_equal(env_colorterm, "24bit")))
361 {
362 cs_str_initial_set(cs, "color_directcolor", "yes", NULL);
363 cs_str_reset(cs, "color_directcolor", NULL);
364 }
365 }
366#endif
367
368 /* "$spool_file" precedence: config file, environment */
369 const char *p = mutt_str_getenv("MAIL");
370 if (!p)
371 p = mutt_str_getenv("MAILDIR");
372 if (!p)
373 {
374#ifdef HOMESPOOL
375 buf_concat_path(&buf, NONULL(HomeDir), MAILPATH);
376#else
377 buf_concat_path(&buf, MAILPATH, NONULL(Username));
378#endif
379 p = buf_string(&buf);
380 }
381 cs_str_initial_set(cs, "spool_file", p, NULL);
382 cs_str_reset(cs, "spool_file", NULL);
383
384 p = mutt_str_getenv("REPLYTO");
385 if (p)
386 {
387 struct Buffer *token = buf_pool_get();
388
389 buf_printf(&buf, "Reply-To: %s", p);
390 buf_seek(&buf, 0);
391 parse_my_hdr(token, &buf, 0, &err); /* adds to UserHeader */
392 buf_pool_release(&token);
393 }
394
395 p = mutt_str_getenv("EMAIL");
396 if (p)
397 {
398 cs_str_initial_set(cs, "from", p, NULL);
399 cs_str_reset(cs, "from", NULL);
400 }
401
402 /* "$mailcap_path" precedence: config file, environment, code */
403 const char *env_mc = mutt_str_getenv("MAILCAPS");
404 if (env_mc)
405 {
406 cs_str_initial_set(cs, "mailcap_path", env_mc, NULL);
407 cs_str_reset(cs, "mailcap_path", NULL);
408 }
409
410 /* "$tmp_dir" precedence: config file, environment, code */
411 const char *env_tmp = mutt_str_getenv("TMPDIR");
412 if (env_tmp)
413 {
414 cs_str_initial_set(cs, "tmp_dir", env_tmp, NULL);
415 cs_str_reset(cs, "tmp_dir", NULL);
416 }
417
418 /* "$visual", "$editor" precedence: config file, environment, code */
419 const char *env_ed = mutt_str_getenv("VISUAL");
420 if (!env_ed)
421 env_ed = mutt_str_getenv("EDITOR");
422 if (!env_ed)
423 env_ed = "vi";
424 cs_str_initial_set(cs, "editor", env_ed, NULL);
425
426 const char *const c_editor = cs_subset_string(NeoMutt->sub, "editor");
427 if (!c_editor)
428 cs_str_reset(cs, "editor", NULL);
429
430 const char *charset = mutt_ch_get_langinfo_charset();
431 cs_str_initial_set(cs, "charset", charset, NULL);
432 cs_str_reset(cs, "charset", NULL);
433 mutt_ch_set_charset(charset);
434 FREE(&charset);
435
436#ifdef HAVE_GETSID
437 /* Unset suspend by default if we're the session leader */
438 if (getsid(0) == getpid())
439 {
440 cs_str_initial_set(cs, "suspend", "no", NULL);
441 cs_str_reset(cs, "suspend", NULL);
442 }
443#endif
444
445 /* RFC2368, "4. Unsafe headers"
446 * The creator of a mailto URL can't expect the resolver of a URL to
447 * understand more than the "subject" and "body" headers. Clients that
448 * resolve mailto URLs into mail messages should be able to correctly
449 * create RFC822-compliant mail messages using the "subject" and "body"
450 * headers. */
451 add_to_stailq(&MailToAllow, "body");
452 add_to_stailq(&MailToAllow, "subject");
453 /* Cc, In-Reply-To, and References help with not breaking threading on
454 * mailing lists, see https://github.com/neomutt/neomutt/issues/115 */
456 add_to_stailq(&MailToAllow, "in-reply-to");
457 add_to_stailq(&MailToAllow, "references");
458
459 if (STAILQ_EMPTY(&Muttrc))
460 {
461 const char *xdg_cfg_home = mutt_str_getenv("XDG_CONFIG_HOME");
462
463 if (!xdg_cfg_home && HomeDir)
464 {
465 buf_printf(&buf, "%s/.config", HomeDir);
466 xdg_cfg_home = buf_string(&buf);
467 }
468
469 char *config = find_cfg(HomeDir, xdg_cfg_home);
470 if (config)
471 {
473 }
474 }
475 else
476 {
477 struct ListNode *np = NULL;
478 STAILQ_FOREACH(np, &Muttrc, entries)
479 {
480 buf_strcpy(&buf, np->data);
481 FREE(&np->data);
482 buf_expand_path(&buf);
483 np->data = buf_strdup(&buf);
484 if (access(np->data, F_OK))
485 {
486 mutt_perror("%s", np->data);
487 goto done; // TEST10: neomutt -F missing
488 }
489 }
490 }
491
492 if (!STAILQ_EMPTY(&Muttrc))
493 {
494 cs_str_string_set(cs, "alias_file", STAILQ_FIRST(&Muttrc)->data, NULL);
495 }
496
497 /* Process the global rc file if it exists and the user hasn't explicitly
498 * requested not to via "-n". */
499 if (!skip_sys_rc)
500 {
501 do
502 {
504 break;
505
506 buf_printf(&buf, "%s/neomuttrc", SYSCONFDIR);
507 if (access(buf_string(&buf), F_OK) == 0)
508 break;
509
510 buf_printf(&buf, "%s/Muttrc", SYSCONFDIR);
511 if (access(buf_string(&buf), F_OK) == 0)
512 break;
513
514 buf_printf(&buf, "%s/neomuttrc", PKGDATADIR);
515 if (access(buf_string(&buf), F_OK) == 0)
516 break;
517
518 buf_printf(&buf, "%s/Muttrc", PKGDATADIR);
519 } while (false);
520
521 if (access(buf_string(&buf), F_OK) == 0)
522 {
523 if (source_rc(buf_string(&buf), &err) != 0)
524 {
525 mutt_error("%s", err.data);
526 need_pause = true; // TEST11: neomutt (error in /etc/neomuttrc)
527 }
528 }
529 }
530
531 /* Read the user's initialization file. */
532 struct ListNode *np = NULL;
533 STAILQ_FOREACH(np, &Muttrc, entries)
534 {
535 if (np->data)
536 {
537 if (source_rc(np->data, &err) != 0)
538 {
539 mutt_error("%s", err.data);
540 need_pause = true; // TEST12: neomutt (error in ~/.neomuttrc)
541 }
542 }
543 }
544
545 if (execute_commands(commands) != 0)
546 need_pause = true; // TEST13: neomutt -e broken
547
548 if (!get_hostname(cs))
549 goto done;
550
551 char name[256] = { 0 };
552 const char *c_real_name = cs_subset_string(NeoMutt->sub, "real_name");
553 if (!c_real_name)
554 {
555 struct passwd *pw = getpwuid(getuid());
556 if (pw)
557 {
558 c_real_name = mutt_gecos_name(name, sizeof(name), pw);
559 }
560 }
561 cs_str_initial_set(cs, "real_name", c_real_name, NULL);
562 cs_str_reset(cs, "real_name", NULL);
563
564 /* The command line overrides the config */
565 if (dlevel)
566 cs_str_reset(cs, "debug_level", NULL);
567 if (dfile)
568 cs_str_reset(cs, "debug_file", NULL);
569
570 if (mutt_log_start() < 0)
571 {
572 mutt_perror("log file");
573 goto done;
574 }
575
576 if (need_pause && !OptNoCurses)
577 {
579 if (mutt_any_key_to_continue(NULL) == 'q')
580 goto done; // TEST14: neomutt -e broken (press 'q')
581 }
582
583 const char *const c_tmp_dir = cs_subset_path(NeoMutt->sub, "tmp_dir");
584 if (mutt_file_mkdir(c_tmp_dir, S_IRWXU) < 0)
585 {
586 mutt_error(_("Can't create %s: %s"), c_tmp_dir, strerror(errno));
587 goto done;
588 }
589
592
593#ifdef USE_NOTMUCH
594 const bool c_virtual_spool_file = cs_subset_bool(NeoMutt->sub, "virtual_spool_file");
595 if (c_virtual_spool_file)
596 {
597 /* Find the first virtual folder and open it */
598 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
600 struct MailboxNode *mp = STAILQ_FIRST(&ml);
601 if (mp)
602 cs_str_string_set(cs, "spool_file", mailbox_path(mp->mailbox), NULL);
604 }
605#endif
606 rc = 0;
607
608done:
609 buf_dealloc(&err);
610 buf_dealloc(&buf);
611 return rc;
612}
void alias_init(void)
Set up the Alias globals.
Definition: alias.c:719
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:178
void buf_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
Definition: buffer.c:639
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:394
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:75
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:412
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:588
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:526
void commands_init(void)
Initialize commands array and register default commands.
Definition: commands.c:1703
int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
Definition: commands.c:205
void mutt_comp_init(void)
Setup feature commands.
Definition: compress.c:74
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:169
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
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:640
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:211
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition: curs_lib.c:175
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition: file.c:1015
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:72
void mutt_grouplist_init(void)
Initialize the GroupList singleton.
Definition: group.c:96
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() -.
Definition: commands.c:814
int log_disp_terminal(time_t stamp, const char *file, int line, const char *function, enum LogLevel level, const char *format,...)
Save a log line to the terminal - Implements log_dispatcher_t -.
Definition: logging.c:441
void mutt_hist_read_file(void)
Read the History from a file.
Definition: history.c:597
void mutt_hist_init(void)
Create a set of empty History ring buffers.
Definition: history.c:469
void hooks_init(void)
Setup feature commands.
Definition: hook.c:1024
void imap_init(void)
Setup feature commands.
Definition: imap.c:96
static char * find_cfg(const char *home, const char *xdg_cfg_home)
Find a config file.
Definition: init.c:109
static int execute_commands(struct ListHead *p)
Execute a set of NeoMutt commands.
Definition: init.c:77
static bool get_hostname(struct ConfigSet *cs)
Find the Fully-Qualified Domain Name.
Definition: init.c:183
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
void menu_init(void)
Initialise all the Menus.
Definition: menu.c:78
char * mutt_ch_get_langinfo_charset(void)
Get the user's choice of character set.
Definition: charset.c:485
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
Definition: charset.c:1077
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
Definition: logging.c:346
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:709
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:775
int mutt_log_start(void)
Enable file logging.
Definition: mutt_logging.c:248
void mutt_lua_init(void)
Setup feature commands.
Definition: mutt_lua.c:469
char * mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw)
Lookup a user's real name in /etc/passwd.
Definition: muttlib.c:370
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition: muttlib.c:1690
int mutt_set_xdg_path(enum XdgType type, struct Buffer *buf)
Find an XDG path or its fallback.
Definition: muttlib.c:1475
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:331
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:163
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:186
void nm_init(void)
Setup feature commands.
Definition: notmuch.c:108
@ XDG_CONFIG_DIRS
XDG system dir: /etc/xdg.
Definition: protos.h:45
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define STAILQ_FIRST(head)
Definition: queue.h:350
#define STAILQ_EMPTY(head)
Definition: queue.h:348
void sb_init(void)
Set up the Sidebar.
Definition: sidebar.c:201
char * data
Pointer to data.
Definition: buffer.h:37
List of Mailboxes.
Definition: mailbox.h:154
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:155
void driver_tags_init(void)
Initialize structures used for tags.
Definition: tags.c:233
+ Here is the caller graph for this function:

◆ mutt_query_variables()

int mutt_query_variables ( struct ListHead *  queries,
bool  show_docs 
)

Implement the -Q command line flag.

Parameters
queriesList of query strings
show_docsIf true, show one-liner docs for the config item
Return values
0Success, all queries exist
1Error

Definition at line 621 of file init.c.

622{
623 struct Buffer value = buf_make(256);
624 struct Buffer tmp = buf_make(256);
625 int rc = 0;
626
627 struct ListNode *np = NULL;
628 STAILQ_FOREACH(np, queries, entries)
629 {
630 buf_reset(&value);
631
632 struct HashElem *he = cs_subset_lookup(NeoMutt->sub, np->data);
633 if (he)
634 {
635 if (he->type & D_INTERNAL_DEPRECATED)
636 {
637 mutt_warning(_("Option %s is deprecated"), np->data);
638 rc = 1;
639 continue;
640 }
641
642 int rv = cs_subset_he_string_get(NeoMutt->sub, he, &value);
643 if (CSR_RESULT(rv) != CSR_SUCCESS)
644 {
645 rc = 1;
646 continue;
647 }
648
649 int type = DTYPE(he->type);
650 if (type == DT_PATH)
651 mutt_pretty_mailbox(value.data, value.dsize);
652
653 if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) && (type != DT_QUAD))
654 {
655 buf_reset(&tmp);
656 pretty_var(value.data, &tmp);
657 buf_strcpy(&value, tmp.data);
658 }
659
660 dump_config_neo(NeoMutt->sub->cs, he, &value, NULL,
661 show_docs ? CS_DUMP_SHOW_DOCS : CS_DUMP_NO_FLAGS, stdout);
662 continue;
663 }
664
665 mutt_warning(_("Unknown option %s"), np->data);
666 rc = 1;
667 }
668
669 buf_dealloc(&value);
670 buf_dealloc(&tmp);
671
672 return rc; // TEST16: neomutt -Q charset
673}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:93
size_t pretty_var(const char *str, struct Buffer *buf)
Escape and stringify a config item value.
Definition: dump.c:85
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:108
void mutt_pretty_mailbox(char *buf, size_t buflen)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:478
#define CS_DUMP_NO_FLAGS
No flags are set.
Definition: dump.h:35
#define CS_DUMP_SHOW_DOCS
Show one-liner documentation for the config item.
Definition: dump.h:45
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
size_t dsize
Length of data.
Definition: buffer.h:39
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
The item stored in a Hash Table.
Definition: hash.h:43
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:44
int cs_subset_he_string_get(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: subset.c:332
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
Definition: subset.c:187
#define DTYPE(t)
Definition: types.h:49
#define D_INTERNAL_DEPRECATED
Config item shouldn't be used any more.
Definition: types.h:85
@ DT_NUMBER
a number
Definition: types.h:38
@ DT_BOOL
boolean option
Definition: types.h:32
@ DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:40
@ DT_LONG
a number (long)
Definition: types.h:35
@ DT_PATH
a path to a file/directory
Definition: types.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function: