NeoMutt  2025-12-11-117-gc1a713
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
29
104
110
111#define GNULIB_defined_setlocale
112
113#include "config.h"
114#include <errno.h>
115#include <limits.h>
116#include <pwd.h>
117#include <stdbool.h>
118#include <stdio.h>
119#include <string.h>
120#include <sys/stat.h>
121#include <sys/utsname.h>
122#include <time.h>
123#include <unistd.h>
124#include "mutt/lib.h"
125#include "address/lib.h"
126#include "config/lib.h"
127#include "email/lib.h"
128#include "core/lib.h"
129#include "alias/lib.h"
130#include "conn/lib.h"
131#include "gui/lib.h"
132#include "mutt.h"
133#include "attach/lib.h"
134#include "browser/lib.h"
135#include "cli/lib.h"
136#include "color/lib.h"
137#include "commands/lib.h"
138#include "compose/lib.h"
139#include "editor/lib.h"
140#include "history/lib.h"
141#include "hooks/lib.h"
142#include "imap/lib.h"
143#include "index/lib.h"
144#include "key/lib.h"
145#include "lua/lib.h"
146#include "menu/lib.h"
147#include "ncrypt/lib.h"
148#include "nntp/lib.h"
149#include "pager/lib.h"
150#include "parse/lib.h"
151#include "pop/lib.h"
152#include "postpone/lib.h"
153#include "question/lib.h"
154#include "send/lib.h"
155#include "sidebar/lib.h"
156#include "external.h"
157#include "globals.h"
158#include "mutt_logging.h"
159#include "mutt_mailbox.h"
160#include "muttlib.h"
161#include "mx.h"
162#include "nntp/adata.h" // IWYU pragma: keep
163#include "protos.h"
164#include "version.h"
165#ifdef ENABLE_NLS
166#include <libintl.h>
167#endif
168#ifdef USE_AUTOCRYPT
169#include "autocrypt/lib.h"
170#endif
171#if defined(USE_DEBUG_NOTIFY) || defined(USE_DEBUG_BACKTRACE)
172#include "debug/lib.h"
173#endif
174#ifndef DOMAIN
175#include "conn/lib.h"
176#endif
177
178bool StartupComplete = false;
179
180void show_cli(enum HelpMode mode, bool use_color);
181
182// clang-format off
183extern const struct Module ModuleMain;
184extern const struct Module ModuleAddress; extern const struct Module ModuleAlias; extern const struct Module ModuleAttach; extern const struct Module ModuleAutocrypt;
185extern const struct Module ModuleBcache; extern const struct Module ModuleBrowser; extern const struct Module ModuleColor; extern const struct Module ModuleCommands;
186extern const struct Module ModuleComplete; extern const struct Module ModuleCompmbox; extern const struct Module ModuleCompose; extern const struct Module ModuleCompress;
187extern const struct Module ModuleConfig; extern const struct Module ModuleConn; extern const struct Module ModuleConvert; extern const struct Module ModuleCore;
188extern const struct Module ModuleEditor; extern const struct Module ModuleEmail; extern const struct Module ModuleEnvelope; extern const struct Module ModuleExpando;
189extern const struct Module ModuleGui; extern const struct Module ModuleHcache; extern const struct Module ModuleHelpbar; extern const struct Module ModuleHistory;
190extern const struct Module ModuleHooks; extern const struct Module ModuleImap; extern const struct Module ModuleIndex; extern const struct Module ModuleKey;
191extern const struct Module ModuleLua; extern const struct Module ModuleMaildir; extern const struct Module ModuleMbox; extern const struct Module ModuleMenu;
192extern const struct Module ModuleMh; extern const struct Module ModuleMutt; extern const struct Module ModuleNcrypt; extern const struct Module ModuleNntp;
193extern const struct Module ModuleNotmuch; extern const struct Module ModulePager; extern const struct Module ModuleParse; extern const struct Module ModulePattern;
194extern const struct Module ModulePop; extern const struct Module ModulePostpone; extern const struct Module ModuleProgress; extern const struct Module ModuleQuestion;
195extern const struct Module ModuleSend; extern const struct Module ModuleSidebar; extern const struct Module ModuleStore;
196// clang-format on
197
201static const struct Module *Modules[] = {
202 // clang-format off
203 &ModuleMain, &ModuleGui, // These two have priority
212// clang-format on
213#ifdef USE_AUTOCRYPT
215#endif
216#ifdef USE_HCACHE_COMPRESSION
218#endif
219#ifdef USE_HCACHE
221#endif
222#ifdef USE_LUA
223 &ModuleLua,
224#endif
225#ifdef USE_NOTMUCH
227#endif
228#ifdef USE_HCACHE
230#endif
231 NULL,
232};
233
240static int execute_commands(struct StringArray *sa)
241{
242 int rc = 0;
243 struct Buffer *err = buf_pool_get();
244 struct Buffer *line = buf_pool_get();
245
246 const char **cp = NULL;
247 ARRAY_FOREACH(cp, sa)
248 {
249 buf_strcpy(line, *cp);
250 enum CommandResult rc2 = parse_rc_line(line, err);
251 if (rc2 == MUTT_CMD_ERROR)
252 mutt_error(_("Error in command line: %s"), buf_string(err));
253 else if (rc2 == MUTT_CMD_WARNING)
254 mutt_warning(_("Warning in command line: %s"), buf_string(err));
255
256 if ((rc2 == MUTT_CMD_ERROR) || (rc2 == MUTT_CMD_WARNING))
257 {
258 buf_pool_release(&err);
259 return -1;
260 }
261 }
262
263 buf_pool_release(&line);
264 buf_pool_release(&err);
265
266 return rc;
267}
268
276static char *find_cfg(const char *home, const char *xdg_cfg_home)
277{
278 const char *names[] = {
279 "neomuttrc",
280 "muttrc",
281 NULL,
282 };
283
284 const char *locations[][2] = {
285 { xdg_cfg_home, "neomutt/" },
286 { xdg_cfg_home, "mutt/" },
287 { home, ".neomutt/" },
288 { home, ".mutt/" },
289 { home, "." },
290 { NULL, NULL },
291 };
292
293 struct Buffer *buf = buf_pool_get();
294 char *cfg = NULL;
295
296 for (int i = 0; locations[i][0] || locations[i][1]; i++)
297 {
298 if (!locations[i][0])
299 continue;
300
301 for (int j = 0; names[j]; j++)
302 {
303 buf_printf(buf, "%s/%s%s", locations[i][0], locations[i][1], names[j]);
304 if (access(buf_string(buf), F_OK) == 0)
305 {
306 cfg = buf_strdup(buf);
307 goto done;
308 }
309 }
310 }
311
312done:
313 buf_pool_release(&buf);
314 return cfg;
315}
316
317#ifndef DOMAIN
323static char *getmailname(void)
324{
325 char *mailname = NULL;
326 static const char *mn_files[] = { "/etc/mailname", "/etc/mail/mailname" };
327
328 for (size_t i = 0; i < countof(mn_files); i++)
329 {
330 FILE *fp = mutt_file_fopen(mn_files[i], "r");
331 if (!fp)
332 continue;
333
334 size_t len = 0;
335 mailname = mutt_file_read_line(NULL, &len, fp, NULL, MUTT_RL_NO_FLAGS);
336 mutt_file_fclose(&fp);
337 if (mailname && *mailname)
338 break;
339
340 FREE(&mailname);
341 }
342
343 return mailname;
344}
345#endif
346
356static bool get_hostname(struct ConfigSet *cs)
357{
358 const char *short_host = NULL;
359 struct utsname utsname = { 0 };
360
361 const char *const c_hostname = cs_subset_string(NeoMutt->sub, "hostname");
362 if (c_hostname)
363 {
364 short_host = c_hostname;
365 }
366 else
367 {
368 /* The call to uname() shouldn't fail, but if it does, the system is horribly
369 * broken, and the system's networking configuration is in an unreliable
370 * state. We should bail. */
371 if ((uname(&utsname)) == -1)
372 {
373 mutt_perror(_("unable to determine nodename via uname()"));
374 return false; // TEST09: can't test
375 }
376
377 short_host = utsname.nodename;
378 }
379
380 /* some systems report the FQDN instead of just the hostname */
381 char *dot = strchr(short_host, '.');
382 if (dot)
383 ShortHostname = mutt_strn_dup(short_host, dot - short_host);
384 else
385 ShortHostname = mutt_str_dup(short_host);
386
387 // All the code paths from here alloc memory for the fqdn
388 char *fqdn = mutt_str_dup(c_hostname);
389 if (!fqdn)
390 {
391 mutt_debug(LL_DEBUG1, "Setting $hostname\n");
392 /* now get FQDN. Use configured domain first, DNS next, then uname */
393#ifdef DOMAIN
394 /* we have a compile-time domain name, use that for `$hostname` */
395 mutt_str_asprintf(&fqdn, "%s.%s", NONULL(ShortHostname), DOMAIN);
396#else
397 fqdn = getmailname();
398 if (!fqdn)
399 {
400 struct Buffer *domain = buf_pool_get();
401 if (getdnsdomainname(domain) == 0)
402 {
403 mutt_str_asprintf(&fqdn, "%s.%s", NONULL(ShortHostname), buf_string(domain));
404 }
405 else
406 {
407 /* DNS failed, use the nodename. Whether or not the nodename had a '.'
408 * in it, we can use the nodename as the FQDN. On hosts where DNS is
409 * not being used, e.g. small network that relies on hosts files, a
410 * short host name is all that is required for SMTP to work correctly.
411 * It could be wrong, but we've done the best we can, at this point the
412 * onus is on the user to provide the correct hostname if the nodename
413 * won't work in their network. */
414 fqdn = mutt_str_dup(utsname.nodename);
415 }
416 buf_pool_release(&domain);
417 mutt_debug(LL_DEBUG1, "Hostname: %s\n", NONULL(fqdn));
418 }
419#endif
420 }
421
422 if (fqdn)
423 {
424 config_str_set_initial(cs, "hostname", fqdn);
425 FREE(&fqdn);
426 }
427
428 return true;
429}
430
442static int mutt_init(struct ConfigSet *cs, struct Buffer *dlevel,
443 struct Buffer *dfile, bool skip_sys_rc,
444 struct StringArray *user_files, struct StringArray *commands)
445{
446 bool need_pause = false;
447 int rc = 1;
448 struct Buffer *err = buf_pool_get();
449 struct Buffer *buf = buf_pool_get();
450 const char **cp = NULL;
451
452#ifdef NEOMUTT_DIRECT_COLORS
453 /* Test if we run in a terminal which supports direct colours.
454 *
455 * The user/terminal can indicate their capability independent of the
456 * terminfo file by setting the COLORTERM environment variable to "truecolor"
457 * or "24bit" (case sensitive).
458 *
459 * Note: This is to test is less about whether the terminal understands
460 * direct color commands but more about whether ncurses believes it can send
461 * them to the terminal, e.g. ncurses ignores COLORTERM.
462 */
463 if (COLORS == 16777216) // 2^24
464 {
465 /* Ncurses believes the Terminal supports it check the environment variable
466 * to respect the user's choice */
467 const char *env_colorterm = mutt_str_getenv("COLORTERM");
468 if (env_colorterm && (mutt_str_equal(env_colorterm, "truecolor") ||
469 mutt_str_equal(env_colorterm, "24bit")))
470 {
471 config_str_set_initial(cs, "color_directcolor", "yes");
472 }
473 }
474#endif
475
476 /* "$spool_file" precedence: config file, environment */
477 const char *p = mutt_str_getenv("MAIL");
478 if (!p)
479 p = mutt_str_getenv("MAILDIR");
480 if (!p)
481 {
482#ifdef HOMESPOOL
483 buf_concat_path(buf, NONULL(NeoMutt->home_dir), MAILPATH);
484#else
485 buf_concat_path(buf, MAILPATH, NONULL(NeoMutt->username));
486#endif
487 p = buf_string(buf);
488 }
489 config_str_set_initial(cs, "spool_file", p);
490
491 p = mutt_str_getenv("REPLYTO");
492 if (p)
493 {
494 buf_printf(buf, "Reply-To: %s", p);
495 buf_seek(buf, 0);
496
497 // Create a temporary Command struct for parse_my_hdr
498 const struct Command my_hdr_cmd = { .name = "my-header", .data = 0 };
499 parse_my_header(&my_hdr_cmd, buf, err); /* adds to UserHeader */
500 }
501
502 p = mutt_str_getenv("EMAIL");
503 if (p)
504 config_str_set_initial(cs, "from", p);
505
506 /* "$mailcap_path" precedence: config file, environment, code */
507 struct Buffer *mc = buf_pool_get();
508 struct Slist *sl_mc = NULL;
509 const char *env_mc = mutt_str_getenv("MAILCAPS");
510 if (env_mc)
511 {
512 sl_mc = slist_parse(env_mc, D_SLIST_SEP_COLON);
513 }
514 else
515 {
516 cs_str_initial_get(cs, "mailcap_path", mc);
518 buf_reset(mc);
519 }
520 slist_to_buffer(sl_mc, mc);
521 config_str_set_initial(cs, "mailcap_path", buf_string(mc));
522 slist_free(&sl_mc);
523 buf_pool_release(&mc);
524
525 /* "$tmp_dir" precedence: config file, environment, code */
526 const char *env_tmp = mutt_str_getenv("TMPDIR");
527 if (env_tmp)
528 config_str_set_initial(cs, "tmp_dir", env_tmp);
529
530 /* "$visual", "$editor" precedence: config file, environment, code */
531 const char *env_ed = mutt_str_getenv("VISUAL");
532 if (!env_ed)
533 env_ed = mutt_str_getenv("EDITOR");
534 if (!env_ed)
535 env_ed = "vi";
536 config_str_set_initial(cs, "editor", env_ed);
537
538 const char *charset = mutt_ch_get_langinfo_charset();
539 config_str_set_initial(cs, "charset", charset);
540 mutt_ch_set_charset(charset);
541 FREE(&charset);
542
543 char name[256] = { 0 };
544 const char *c_real_name = cs_subset_string(NeoMutt->sub, "real_name");
545 if (!c_real_name)
546 {
547 struct passwd *pw = getpwuid(getuid());
548 if (pw)
549 {
550 c_real_name = mutt_gecos_name(name, sizeof(name), pw);
551 }
552 }
553 config_str_set_initial(cs, "real_name", c_real_name);
554
555#ifdef HAVE_GETSID
556 /* Unset suspend by default if we're the session leader */
557 if (getsid(0) == getpid())
558 config_str_set_initial(cs, "suspend", "no");
559#endif
560
561 /* RFC2368, "4. Unsafe headers"
562 * The creator of a mailto URL can't expect the resolver of a URL to
563 * understand more than the "subject" and "body" headers. Clients that
564 * resolve mailto URLs into mail messages should be able to correctly
565 * create RFC822-compliant mail messages using the "subject" and "body"
566 * headers. */
567 add_to_stailq(&MailToAllow, "body");
568 add_to_stailq(&MailToAllow, "subject");
569 /* Cc, In-Reply-To, and References help with not breaking threading on
570 * mailing lists, see https://github.com/neomutt/neomutt/issues/115 */
572 add_to_stailq(&MailToAllow, "in-reply-to");
573 add_to_stailq(&MailToAllow, "references");
574
575 if (ARRAY_EMPTY(user_files))
576 {
577 const char *xdg_cfg_home = mutt_str_getenv("XDG_CONFIG_HOME");
578
579 if (!xdg_cfg_home && NeoMutt->home_dir)
580 {
581 buf_printf(buf, "%s/.config", NeoMutt->home_dir);
582 xdg_cfg_home = buf_string(buf);
583 }
584
585 char *config = find_cfg(NeoMutt->home_dir, xdg_cfg_home);
586 if (config)
587 {
588 ARRAY_ADD(user_files, config);
589 }
590 }
591 else
592 {
593 ARRAY_FOREACH(cp, user_files)
594 {
595 buf_strcpy(buf, *cp);
596 FREE(cp);
597 buf_expand_path(buf);
598 ARRAY_SET(user_files, ARRAY_FOREACH_IDX_cp, buf_strdup(buf));
599 if (access(buf_string(buf), F_OK))
600 {
601 mutt_perror("%s", buf_string(buf));
602 goto done; // TEST10: neomutt -F missing
603 }
604 }
605 }
606
607 ARRAY_FOREACH(cp, user_files)
608 {
609 if (*cp && !mutt_str_equal(*cp, "/dev/null"))
610 {
611 cs_str_string_set(cs, "alias_file", *cp, NULL);
612 break;
613 }
614 }
615
616 /* Process the global rc file if it exists and the user hasn't explicitly
617 * requested not to via "-n". */
618 if (!skip_sys_rc)
619 {
620 do
621 {
623 break;
624
625 buf_printf(buf, "%s/neomuttrc", SYSCONFDIR);
626 if (access(buf_string(buf), F_OK) == 0)
627 break;
628
629 buf_printf(buf, "%s/Muttrc", SYSCONFDIR);
630 if (access(buf_string(buf), F_OK) == 0)
631 break;
632
633 buf_printf(buf, "%s/neomuttrc", PKGDATADIR);
634 if (access(buf_string(buf), F_OK) == 0)
635 break;
636
637 buf_printf(buf, "%s/Muttrc", PKGDATADIR);
638 } while (false);
639
640 if (access(buf_string(buf), F_OK) == 0)
641 {
642 if (source_rc(buf_string(buf), err) != 0)
643 {
644 mutt_error("%s", buf_string(err));
645 need_pause = true; // TEST11: neomutt (error in /etc/neomuttrc)
646 }
647 }
648 }
649
650 /* Read the user's initialization file. */
651 ARRAY_FOREACH(cp, user_files)
652 {
653 if (*cp)
654 {
655 if (source_rc(*cp, err) != 0)
656 {
657 mutt_error("%s", buf_string(err));
658 need_pause = true; // TEST12: neomutt (error in ~/.neomuttrc)
659 }
660 }
661 }
662
663 if (execute_commands(commands) != 0)
664 need_pause = true; // TEST13: neomutt -e broken
665
666 if (!get_hostname(cs))
667 goto done;
668
669 /* The command line overrides the config */
670 if (!buf_is_empty(dlevel))
671 cs_str_reset(cs, "debug_level", NULL);
672 if (!buf_is_empty(dfile))
673 cs_str_reset(cs, "debug_file", NULL);
674
675 if (mutt_log_start() < 0)
676 {
677 mutt_perror("log file");
678 goto done;
679 }
680
681 if (need_pause && OptGui)
682 {
684 if (mutt_any_key_to_continue(NULL) == 'q')
685 goto done; // TEST14: neomutt -e broken (press 'q')
686 }
687
688 const char *const c_tmp_dir = cs_subset_path(NeoMutt->sub, "tmp_dir");
689 if (mutt_file_mkdir(c_tmp_dir, S_IRWXU) < 0)
690 {
691 mutt_error(_("Can't create %s: %s"), c_tmp_dir, strerror(errno));
692 goto done;
693 }
694
695 rc = 0;
696
697done:
698 buf_pool_release(&err);
699 buf_pool_release(&buf);
700 return rc;
701}
702
710static int get_elem_queries(struct StringArray *queries, struct HashElemArray *hea)
711{
712 int rc = 0;
713 const char **cp = NULL;
714 ARRAY_FOREACH(cp, queries)
715 {
716 struct HashElem *he = cs_subset_lookup(NeoMutt->sub, *cp);
717 if (!he)
718 {
719 mutt_warning(_("Unknown option %s"), *cp);
720 rc = 1;
721 continue;
722 }
723
724 if (he->type & D_INTERNAL_DEPRECATED)
725 {
726 mutt_warning(_("Option %s is deprecated"), *cp);
727 rc = 1;
728 continue;
729 }
730
731 ARRAY_ADD(hea, he);
732 }
733
734 return rc; // TEST16: neomutt -Q charset
735}
736
740static void init_keys(void)
741{
742 km_init();
743
744 struct SubMenu *sm_generic = generic_init_keys();
745
746 alias_init_keys(sm_generic);
747 attach_init_keys(sm_generic);
748#ifdef USE_AUTOCRYPT
749 autocrypt_init_keys(sm_generic);
750#endif
751 browser_init_keys(sm_generic);
752 compose_init_keys(sm_generic);
753 editor_init_keys(sm_generic);
754 sidebar_init_keys(sm_generic);
755 index_init_keys(sm_generic);
756 pager_init_keys(sm_generic);
757 pgp_init_keys(sm_generic);
758 postponed_init_keys(sm_generic);
759}
760
766static int start_curses(void)
767{
768 /* should come before initscr() so that ncurses 4.2 doesn't try to install
769 * its own SIGWINCH handler */
771
772 if (!initscr())
773 {
774 mutt_error(_("Error initializing terminal"));
775 return 1;
776 }
777
778 colors_init();
779 keypad(stdscr, true);
780 cbreak();
781 noecho();
782 nonl();
783 typeahead(-1); /* simulate smooth scrolling */
784 meta(stdscr, true);
786 /* Now that curses is set up, we drop back to normal screen mode.
787 * This simplifies displaying error messages to the user.
788 * The first call to refresh() will swap us back to curses screen mode. */
789 endwin();
790 return 0;
791}
792
800static bool get_user_info(struct ConfigSet *cs)
801{
802 const char *shell = mutt_str_getenv("SHELL");
803
804 /* Get some information about the user */
805 struct passwd *pw = getpwuid(getuid());
806 if (pw)
807 {
808 if (!NeoMutt->username)
809 NeoMutt->username = mutt_str_dup(pw->pw_name);
810 if (!NeoMutt->home_dir)
811 NeoMutt->home_dir = mutt_str_dup(pw->pw_dir);
812 if (!shell)
813 shell = pw->pw_shell;
814 }
815
816 if (!NeoMutt->username)
817 {
818 mutt_error(_("unable to determine username"));
819 return false; // TEST05: neomutt (unset $USER, delete user from /etc/passwd)
820 }
821
822 if (!NeoMutt->home_dir)
823 {
824 mutt_error(_("unable to determine home directory"));
825 return false; // TEST06: neomutt (unset $HOME, delete user from /etc/passwd)
826 }
827
828 if (shell)
829 config_str_set_initial(cs, "shell", shell);
830
831 return true;
832}
833
841static void log_translation(void)
842{
843 const char *header = ""; // Do not merge these two lines
844 header = _(header); // otherwise the .po files will end up badly ordered
845 const char *label = "Language:"; // the start of the lookup/needle
846 const char *lang = mutt_istr_find(header, label);
847 int len = 64;
848 if (lang)
849 {
850 lang += strlen(label); // skip label
851 SKIPWS(lang);
852 char *nl = strchr(lang, '\n');
853 if (nl)
854 len = (nl - lang);
855 }
856 else
857 {
858 lang = "NONE";
859 }
860
861 mutt_debug(LL_DEBUG1, "Translation: %.*s\n", len, lang);
862}
863
867static void log_gui(void)
868{
869 const char *term = mutt_str_getenv("TERM");
870 const char *color_term = mutt_str_getenv("COLORTERM");
871 bool true_color = false;
872#ifdef NEOMUTT_DIRECT_COLORS
873 true_color = true;
874#endif
875
876 mutt_debug(LL_DEBUG1, "GUI:\n");
877 mutt_debug(LL_DEBUG1, " Curses: %s\n", curses_version());
878 mutt_debug(LL_DEBUG1, " COLORS=%d\n", COLORS);
879 mutt_debug(LL_DEBUG1, " COLOR_PAIRS=%d\n", COLOR_PAIRS);
880 mutt_debug(LL_DEBUG1, " TERM=%s\n", NONULL(term));
881 mutt_debug(LL_DEBUG1, " COLORTERM=%s\n", NONULL(color_term));
882 mutt_debug(LL_DEBUG1, " True color support: %s\n", true_color ? "YES" : "NO");
883 mutt_debug(LL_DEBUG1, " Screen: %dx%d\n", RootWindow->state.cols,
884 RootWindow->state.rows);
885}
886
891{
892 static time_t last_run = 0;
893
894 if (nc->event_type != NT_TIMEOUT)
895 return 0;
896
897 const short c_timeout = cs_subset_number(NeoMutt->sub, "timeout");
898 if (c_timeout <= 0)
899 goto done;
900
901 time_t now = mutt_date_now();
902 if (now < (last_run + c_timeout))
903 goto done;
904
905 // Limit hook to running under the Index or Pager
907 struct MuttWindow *dlg = dialog_find(focus);
908 if (!dlg || (dlg->type != WT_DLG_INDEX))
909 goto done;
910
911 last_run = now;
913
914done:
915 mutt_debug(LL_DEBUG5, "timeout done\n");
916 return 0;
917}
918
924static bool show_help(struct CliHelp *help)
925{
926 if (!help->is_set)
927 return true;
928
930
931 const bool tty = isatty(STDOUT_FILENO);
932
933 if (help->help)
934 {
935 show_cli(help->mode, tty);
936 }
937 else if (help->license)
938 {
940 }
941 else
942 {
943 print_version(stdout, tty);
944 }
945
946 return false; // Stop
947}
948
955static bool init_logging(struct CliShared *shared, struct ConfigSet *cs)
956{
957 if (!shared->is_set)
958 return true;
959
960 if (!buf_is_empty(&shared->log_file))
961 config_str_set_initial(cs, "debug_file", buf_string(&shared->log_file));
962
963 if (!buf_is_empty(&shared->log_level))
964 {
965 const char *dlevel = buf_string(&shared->log_level);
966 short num = 0;
967 if (!mutt_str_atos_full(dlevel, &num) || (num < LL_MESSAGE) || (num >= LL_MAX))
968 {
969 mutt_error(_("Error: value '%s' is invalid for -d"), dlevel);
970 return false;
971 }
972
973 config_str_set_initial(cs, "debug_level", dlevel);
974 }
975
976 return true;
977}
978
984static void init_nntp(struct Buffer *server, struct ConfigSet *cs)
985{
986 const char *cli_nntp = NULL;
987 if (!buf_is_empty(server))
988 cli_nntp = buf_string(server);
989
990 /* "$news_server" precedence: command line, config file, environment, system file */
991 if (cli_nntp)
992 cli_nntp = cs_subset_string(NeoMutt->sub, "news_server");
993
994 if (!cli_nntp)
995 cli_nntp = mutt_str_getenv("NNTPSERVER");
996
997 if (!cli_nntp)
998 {
999 char buf[1024] = { 0 };
1000 cli_nntp = mutt_file_read_keyword(SYSCONFDIR "/nntpserver", buf, sizeof(buf));
1001 }
1002
1003 if (cli_nntp)
1004 config_str_set_initial(cs, "news_server", cli_nntp);
1005}
1006
1013static bool dump_info(struct CliInfo *ci, struct ConfigSet *cs)
1014{
1015 if (!ci->is_set)
1016 return true;
1017
1018 if (ci->dump_config || !ARRAY_EMPTY(&ci->queries))
1019 {
1020 const bool tty = isatty(STDOUT_FILENO);
1021
1023 if (tty)
1024 cdflags |= CS_DUMP_LINK_DOCS;
1025 if (ci->hide_sensitive)
1026 cdflags |= CS_DUMP_HIDE_SENSITIVE;
1027 if (ci->show_help)
1028 cdflags |= CS_DUMP_SHOW_DOCS;
1029
1030 struct HashElemArray hea = ARRAY_HEAD_INITIALIZER;
1031 if (ci->dump_config)
1032 {
1034 hea = get_elem_list(cs, gel_flags);
1035 }
1036 else
1037 {
1038 get_elem_queries(&ci->queries, &hea);
1039 }
1040
1041 dump_config(cs, &hea, cdflags, stdout);
1042 ARRAY_FREE(&hea);
1043 }
1044 else if (!ARRAY_EMPTY(&ci->alias_queries))
1045 {
1046 const char **cp = NULL;
1048 {
1049 struct AddressList *al = alias_lookup(*cp);
1050 if (al)
1051 {
1052 /* output in machine-readable form */
1053 mutt_addrlist_to_intl(al, NULL);
1054 struct Buffer *buf = buf_pool_get();
1055 mutt_addrlist_write(al, buf, false);
1056 printf("%s\n", buf_string(buf));
1057 buf_pool_release(&buf);
1058 }
1059 else
1060 {
1061 printf("%s\n", NONULL(*cp)); // TEST19: neomutt -A unknown
1062 }
1063 }
1064 }
1065
1066 return false; // Stop
1067}
1068
1077int main(int argc, char *argv[], char *envp[])
1078{
1079 struct Email *e = NULL;
1080 SendFlags sendflags = SEND_NO_FLAGS;
1081 int rc = 1;
1082 bool repeat_error = false;
1083 struct Buffer *expanded_infile = buf_pool_get();
1084 struct Buffer *tempfile = buf_pool_get();
1085 struct ConfigSet *cs = NULL;
1086 struct CommandLine *cli = command_line_new();
1087
1089
1090 /* sanity check against stupid administrators */
1091 if (getegid() != getgid())
1092 {
1093 mutt_error("%s: I don't want to run with privileges!", (argc != 0) ? argv[0] : "neomutt");
1094 goto main_exit; // TEST01: neomutt (as root, chgrp mail neomutt; chmod +s neomutt)
1095 }
1096
1097 OptGui = true;
1098
1099 NeoMutt = neomutt_new();
1100 if (!neomutt_init(NeoMutt, envp, Modules))
1101 goto main_curses;
1102
1103 cli_parse(argc, argv, cli);
1104
1105 if (!show_help(&cli->help))
1106 goto main_ok;
1107
1108 subjrx_init();
1109 attach_init();
1111 init_keys();
1112
1113#ifdef USE_DEBUG_NOTIFY
1115#endif
1116
1117 cs = NeoMutt->sub->cs;
1118 if (!get_user_info(cs))
1119 goto main_exit;
1120
1121 if (!init_logging(&cli->shared, cs))
1122 goto main_exit;
1123
1124 mutt_log_prep();
1127
1128 /* Check for a batch send. */
1129 if (!isatty(STDIN_FILENO) || !ARRAY_EMPTY(&cli->info.queries) ||
1131 {
1132 OptGui = false;
1133 sendflags |= SEND_BATCH;
1136 }
1137
1138 /* Check to make sure stdout is available in curses mode. */
1139 if (OptGui && !isatty(STDOUT_FILENO))
1140 goto main_curses;
1141
1142 /* This must come before mutt_init() because curses needs to be started
1143 * before calling the init_pair() function to set the color scheme. */
1144 if (OptGui)
1145 {
1146 int crc = start_curses();
1147 if (crc != 0)
1148 goto main_curses; // TEST08: can't test -- fake term?
1149 }
1150
1151 /* Always create the mutt_windows because batch mode has some shared code
1152 * paths that end up referencing them. */
1153 rootwin_new();
1154
1155 if (OptGui)
1156 {
1157 /* check whether terminal status is supported (must follow curses init) */
1160 log_gui();
1161 }
1162
1163 alias_init();
1165 menu_init();
1166 sb_init();
1167
1168 /* set defaults and read init files */
1169 int rc2 = mutt_init(cs, &cli->shared.log_level, &cli->shared.log_file,
1171 &cli->shared.commands);
1172 if (rc2 != 0)
1173 goto main_curses;
1174
1177
1178#ifdef USE_NOTMUCH
1179 const bool c_virtual_spool_file = cs_subset_bool(NeoMutt->sub, "virtual_spool_file");
1180 if (c_virtual_spool_file)
1181 {
1182 /* Find the first virtual folder and open it */
1183 struct MailboxArray ma = neomutt_mailboxes_get(NeoMutt, MUTT_NOTMUCH);
1184 struct Mailbox **mp = ARRAY_FIRST(&ma);
1185 if (mp)
1186 cs_str_string_set(cs, "spool_file", mailbox_path(*mp), NULL);
1187 ARRAY_FREE(&ma); // Clean up the ARRAY, but not the Mailboxes
1188 }
1189#endif
1190
1192
1193 init_nntp(&cli->tui.nntp_server, cs);
1194
1195 /* Initialize crypto backends. */
1196 crypt_init();
1197
1198 if (!buf_is_empty(&cli->shared.mbox_type) &&
1199 !config_str_set_initial(cs, "mbox_type", buf_string(&cli->shared.mbox_type)))
1200 {
1201 goto main_curses;
1202 }
1203
1204 if (!dump_info(&cli->info, cs))
1205 goto main_ok;
1206
1207 if (OptGui)
1208 {
1210 clear();
1214 }
1215
1216#ifdef USE_AUTOCRYPT
1217 /* Initialize autocrypt after curses messages are working,
1218 * because of the initial account setup screens. */
1219 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
1220 if (c_autocrypt)
1221 mutt_autocrypt_init(!(sendflags & SEND_BATCH));
1222#endif
1223
1224 /* Create the `$folder` directory if it doesn't exist. */
1225 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
1226 if (OptGui && c_folder)
1227 {
1228 struct stat st = { 0 };
1229 struct Buffer *fpath = buf_pool_get();
1230
1231 buf_strcpy(fpath, c_folder);
1232 buf_expand_path(fpath);
1233 bool skip = false;
1234 /* we're not connected yet - skip mail folder creation */
1235 skip |= (imap_path_probe(buf_string(fpath), NULL) == MUTT_IMAP);
1236 skip |= (pop_path_probe(buf_string(fpath), NULL) == MUTT_POP);
1237 skip |= (nntp_path_probe(buf_string(fpath), NULL) == MUTT_NNTP);
1238 if (!skip && (stat(buf_string(fpath), &st) == -1) && (errno == ENOENT))
1239 {
1240 char msg2[256] = { 0 };
1241 snprintf(msg2, sizeof(msg2), _("%s does not exist. Create it?"), c_folder);
1242 if (query_yesorno(msg2, MUTT_YES) == MUTT_YES)
1243 {
1244 if ((mkdir(buf_string(fpath), 0700) == -1) && (errno != EEXIST))
1245 mutt_error(_("Can't create %s: %s"), c_folder, strerror(errno)); // TEST21: neomutt -n -F /dev/null (and ~/Mail doesn't exist)
1246 }
1247 }
1248 buf_pool_release(&fpath);
1249 }
1250
1251 StartupComplete = true;
1252
1256
1257 if (cli->tui.start_postponed)
1258 {
1259 if (OptGui)
1260 mutt_flushinp();
1261 if (mutt_send_message(SEND_POSTPONED, NULL, NULL, NULL, NULL, NeoMutt->sub) == 0)
1262 rc = 0;
1263 // TEST23: neomutt -p (postponed message, cancel)
1264 // TEST24: neomutt -p (no postponed message)
1266 repeat_error = true;
1267 goto main_curses;
1268 }
1269 else if (cli->send.is_set)
1270 {
1271 FILE *fp_in = NULL;
1272 FILE *fp_out = NULL;
1273 const char *infile = NULL;
1274 char *bodytext = NULL;
1275 const char *bodyfile = NULL;
1276 int rv = 0;
1277
1278 if (OptGui)
1279 mutt_flushinp();
1280
1281 e = email_new();
1282 e->env = mutt_env_new();
1283
1284 const char **cp = NULL;
1285 ARRAY_FOREACH(cp, &cli->send.bcc_list)
1286 {
1287 mutt_addrlist_parse(&e->env->bcc, *cp);
1288 }
1289
1290 ARRAY_FOREACH(cp, &cli->send.cc_list)
1291 {
1292 mutt_addrlist_parse(&e->env->cc, *cp);
1293 }
1294
1295 ARRAY_FOREACH(cp, &cli->send.addresses)
1296 {
1297 if (url_check_scheme(*cp) == U_MAILTO)
1298 {
1299 if (!mutt_parse_mailto(e->env, &bodytext, *cp))
1300 {
1301 mutt_error(_("Failed to parse mailto: link"));
1302 email_free(&e);
1303 goto main_curses; // TEST25: neomutt mailto:?
1304 }
1305 }
1306 else
1307 {
1308 mutt_addrlist_parse(&e->env->to, *cp);
1309 }
1310 }
1311
1312 const bool c_auto_edit = cs_subset_bool(NeoMutt->sub, "auto_edit");
1313 if (buf_is_empty(&cli->send.draft_file) && c_auto_edit &&
1314 TAILQ_EMPTY(&e->env->to) && TAILQ_EMPTY(&e->env->cc))
1315 {
1316 mutt_error(_("No recipients specified"));
1317 email_free(&e);
1318 goto main_curses; // TEST26: neomutt -s test (with auto_edit=yes)
1319 }
1320
1321 if (!buf_is_empty(&cli->send.subject))
1322 {
1323 /* prevent header injection */
1326 }
1327
1328 if (!buf_is_empty(&cli->send.draft_file))
1329 {
1330 infile = buf_string(&cli->send.draft_file);
1331 }
1332 else if (!buf_is_empty(&cli->send.include_file))
1333 {
1334 infile = buf_string(&cli->send.include_file);
1335 }
1336 else
1337 {
1338 cli->send.edit_infile = false;
1339 }
1340
1341 if (infile || bodytext)
1342 {
1343 /* Prepare fp_in and expanded_infile. */
1344 if (infile)
1345 {
1346 if (mutt_str_equal("-", infile))
1347 {
1348 if (cli->send.edit_infile)
1349 {
1350 mutt_error(_("Can't use -E flag with stdin"));
1351 email_free(&e);
1352 goto main_curses; // TEST27: neomutt -E -H -
1353 }
1354 fp_in = stdin;
1355 }
1356 else
1357 {
1358 buf_strcpy(expanded_infile, infile);
1359 buf_expand_path(expanded_infile);
1360 fp_in = mutt_file_fopen(buf_string(expanded_infile), "r");
1361 if (!fp_in)
1362 {
1363 mutt_perror("%s", buf_string(expanded_infile));
1364 email_free(&e);
1365 goto main_curses; // TEST28: neomutt -E -H missing
1366 }
1367 }
1368 }
1369
1370 if (cli->send.edit_infile)
1371 {
1372 /* If editing the infile, keep it around afterwards so
1373 * it doesn't get unlinked, and we can rebuild the draft_file */
1374 sendflags |= SEND_NO_FREE_HEADER;
1375 }
1376 else
1377 {
1378 /* Copy input to a tempfile, and re-point fp_in to the tempfile.
1379 * Note: stdin is always copied to a tempfile, ensuring draft_file
1380 * can stat and get the correct st_size below. */
1381 buf_mktemp(tempfile);
1382
1383 fp_out = mutt_file_fopen(buf_string(tempfile), "w");
1384 if (!fp_out)
1385 {
1386 mutt_file_fclose(&fp_in);
1387 mutt_perror("%s", buf_string(tempfile));
1388 email_free(&e);
1389 goto main_curses; // TEST29: neomutt -H existing-file (where tmpdir=/path/to/FILE blocking tmpdir)
1390 }
1391 if (fp_in)
1392 {
1393 mutt_file_copy_stream(fp_in, fp_out);
1394 if (fp_in == stdin)
1395 sendflags |= SEND_CONSUMED_STDIN;
1396 else
1397 mutt_file_fclose(&fp_in);
1398 }
1399 else if (bodytext)
1400 {
1401 fputs(bodytext, fp_out);
1402 }
1403 mutt_file_fclose(&fp_out);
1404
1405 fp_in = mutt_file_fopen(buf_string(tempfile), "r");
1406 if (!fp_in)
1407 {
1408 mutt_perror("%s", buf_string(tempfile));
1409 email_free(&e);
1410 goto main_curses; // TEST30: can't test
1411 }
1412 }
1413
1414 /* Parse the draft_file into the full Email/Body structure.
1415 * Set SEND_DRAFT_FILE so mutt_send_message doesn't overwrite
1416 * our e->body. */
1417 if (!buf_is_empty(&cli->send.draft_file))
1418 {
1419 struct Envelope *opts_env = e->env;
1420 struct stat st = { 0 };
1421
1422 sendflags |= SEND_DRAFT_FILE;
1423
1424 /* Set up a tmp Email with just enough information so that
1425 * mutt_prepare_template() can parse the message in fp_in. */
1426 struct Email *e_tmp = email_new();
1427 e_tmp->offset = 0;
1428 e_tmp->body = mutt_body_new();
1429 if (fstat(fileno(fp_in), &st) != 0)
1430 {
1431 mutt_perror("%s", buf_string(&cli->send.draft_file));
1432 email_free(&e);
1433 email_free(&e_tmp);
1434 goto main_curses; // TEST31: can't test
1435 }
1436 e_tmp->body->length = st.st_size;
1437
1438 if (mutt_prepare_template(fp_in, NULL, e, e_tmp, false) < 0)
1439 {
1440 mutt_error(_("Can't parse message template: %s"),
1441 buf_string(&cli->send.draft_file));
1442 email_free(&e);
1443 email_free(&e_tmp);
1444 goto main_curses;
1445 }
1446
1447 /* Scan for neomutt header to set `$resume_draft_files` */
1448 struct ListNode *tmp = NULL;
1449 const bool c_resume_edited_draft_files = cs_subset_bool(NeoMutt->sub, "resume_edited_draft_files");
1450 struct ListNode *np = NULL;
1451 STAILQ_FOREACH_SAFE(np, &e->env->userhdrs, entries, tmp)
1452 {
1453 if (mutt_istr_startswith(np->data, "X-Mutt-Resume-Draft:"))
1454 {
1455 if (c_resume_edited_draft_files)
1456 cs_str_native_set(cs, "resume_draft_files", true, NULL);
1457
1458 STAILQ_REMOVE(&e->env->userhdrs, np, ListNode, entries);
1459 FREE(&np->data);
1460 FREE(&np);
1461 }
1462 }
1463
1464 mutt_addrlist_copy(&e->env->to, &opts_env->to, false);
1465 mutt_addrlist_copy(&e->env->cc, &opts_env->cc, false);
1466 mutt_addrlist_copy(&e->env->bcc, &opts_env->bcc, false);
1467 if (opts_env->subject)
1468 mutt_env_set_subject(e->env, opts_env->subject);
1469
1470 mutt_env_free(&opts_env);
1471 email_free(&e_tmp);
1472 }
1473 else if (cli->send.edit_infile)
1474 {
1475 /* Editing the include_file: pass it directly in.
1476 * Note that SEND_NO_FREE_HEADER is set above so it isn't unlinked. */
1477 bodyfile = buf_string(expanded_infile);
1478 }
1479 else
1480 {
1481 // For bodytext and unedited include_file: use the tempfile.
1482 bodyfile = buf_string(tempfile);
1483 }
1484
1485 mutt_file_fclose(&fp_in);
1486 }
1487
1488 FREE(&bodytext);
1489
1490 if (!ARRAY_EMPTY(&cli->send.attach))
1491 {
1492 struct Body *b = e->body;
1493
1494 while (b && b->next)
1495 b = b->next;
1496
1497 ARRAY_FOREACH(cp, &cli->send.attach)
1498 {
1499 if (b)
1500 {
1502 b = b->next;
1503 }
1504 else
1505 {
1507 e->body = b;
1508 }
1509 if (!b)
1510 {
1511 mutt_error(_("%s: unable to attach file"), *cp);
1512 email_free(&e);
1513 goto main_curses; // TEST32: neomutt john@example.com -a missing
1514 }
1515 }
1516 }
1517
1518 rv = mutt_send_message(sendflags, e, bodyfile, NULL, NULL, NeoMutt->sub);
1519 /* We WANT the "Mail sent." and any possible, later error */
1521 if (ErrorBufMessage)
1522 mutt_message("%s", ErrorBuf);
1523
1524 if (cli->send.edit_infile)
1525 {
1526 if (!buf_is_empty(&cli->send.draft_file))
1527 {
1528 if (truncate(buf_string(expanded_infile), 0) == -1)
1529 {
1530 mutt_perror("%s", buf_string(expanded_infile));
1531 email_free(&e);
1532 goto main_curses; // TEST33: neomutt -H read-only -s test john@example.com -E
1533 }
1534 fp_out = mutt_file_fopen(buf_string(expanded_infile), "a");
1535 if (!fp_out)
1536 {
1537 mutt_perror("%s", buf_string(expanded_infile));
1538 email_free(&e);
1539 goto main_curses; // TEST34: can't test
1540 }
1541
1542 /* If the message was sent or postponed, these will already
1543 * have been done. */
1544 if (rv < 0)
1545 {
1546 if (e->body->next)
1547 e->body = mutt_make_multipart(e->body);
1549 mutt_prepare_envelope(e->env, false, NeoMutt->sub);
1550 mutt_env_to_intl(e->env, NULL, NULL);
1551 }
1552
1553 const bool c_crypt_protected_headers_read = cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_read");
1555 c_crypt_protected_headers_read &&
1557 NeoMutt->sub);
1558 const bool c_resume_edited_draft_files = cs_subset_bool(NeoMutt->sub, "resume_edited_draft_files");
1559 if (c_resume_edited_draft_files)
1560 fprintf(fp_out, "X-Mutt-Resume-Draft: 1\n");
1561 fputc('\n', fp_out);
1562 if ((mutt_write_mime_body(e->body, fp_out, NeoMutt->sub) == -1))
1563 {
1564 mutt_file_fclose(&fp_out);
1565 email_free(&e);
1566 goto main_curses; // TEST35: can't test
1567 }
1568 mutt_file_fclose(&fp_out);
1569 }
1570
1571 email_free(&e);
1572 }
1573
1574 /* !edit_infile && draft_file will leave the tempfile around */
1575 if (!buf_is_empty(tempfile))
1576 unlink(buf_string(tempfile));
1577
1579
1580 if (rv != 0)
1581 goto main_curses; // TEST36: neomutt -H existing -s test john@example.com -E (cancel sending)
1582 }
1583 else if (sendflags & SEND_BATCH)
1584 {
1585 /* This guards against invoking `neomutt < /dev/null` and accidentally
1586 * sending an email due to a my-header or other setting. */
1587 mutt_error(_("No recipients specified"));
1588 goto main_curses;
1589 }
1590 else
1591 {
1592 struct Buffer *folder = &cli->tui.folder;
1593 bool explicit_folder = !buf_is_empty(folder);
1594
1595 if (cli->tui.start_new_mail)
1596 {
1597 const bool c_imap_passive = cs_subset_bool(NeoMutt->sub, "imap_passive");
1598 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", false, NULL);
1600 if (mutt_mailbox_check(NULL, csflags) == 0)
1601 {
1602 mutt_message(_("No mailbox with new mail"));
1603 repeat_error = true;
1604 goto main_curses; // TEST37: neomutt -Z (no new mail)
1605 }
1606 buf_reset(folder);
1607 mutt_mailbox_next(NULL, folder);
1608 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", c_imap_passive, NULL);
1609 }
1610 else if (cli->tui.start_nntp || cli->tui.start_browser)
1611 {
1612 if (cli->tui.start_nntp)
1613 {
1614 const char *const c_news_server = cs_subset_string(NeoMutt->sub, "news_server");
1615 OptNews = true;
1616 CurrentNewsSrv = nntp_select_server(NULL, c_news_server, false);
1617 if (!CurrentNewsSrv)
1618 goto main_curses; // TEST38: neomutt -G (unset news_server)
1619 }
1620 else if (ARRAY_EMPTY(&NeoMutt->accounts))
1621 {
1622 mutt_error(_("No incoming mailboxes defined"));
1623 goto main_curses; // TEST39: neomutt -n -F /dev/null -y
1624 }
1625 buf_reset(folder);
1626 dlg_browser(folder, MUTT_SEL_FOLDER | MUTT_SEL_MAILBOX, NULL, NULL, NULL);
1627 if (buf_is_empty(folder))
1628 {
1629 goto main_ok; // TEST40: neomutt -y (quit selection)
1630 }
1631 }
1632
1633 if (buf_is_empty(folder))
1634 {
1635 const char *const c_spool_file = cs_subset_string(NeoMutt->sub, "spool_file");
1636 if (c_spool_file)
1637 {
1638 // Check if `$spool_file` corresponds a mailboxes' description.
1639 struct Mailbox *m_desc = mailbox_find_name(c_spool_file);
1640 if (m_desc)
1641 buf_strcpy(folder, m_desc->realpath);
1642 else
1643 buf_strcpy(folder, c_spool_file);
1644 }
1645 else if (c_folder)
1646 {
1647 buf_strcpy(folder, c_folder);
1648 }
1649 /* else no folder */
1650 }
1651
1652 if (OptNews)
1653 {
1654 OptNews = false;
1655 buf_alloc(folder, PATH_MAX);
1656 nntp_expand_path(folder->data, folder->dsize, &CurrentNewsSrv->conn->account);
1657 }
1658 else
1659 {
1660 buf_expand_path(folder);
1661 }
1662
1665
1666 if (cli->tui.start_any_mail || cli->tui.start_new_mail)
1667 {
1668 /* check to see if there are any messages in the folder */
1669 switch (mx_path_is_empty(folder))
1670 {
1671 case -1:
1672 mutt_perror("%s", buf_string(folder));
1673 goto main_curses; // TEST41: neomutt -z -f missing
1674 case 1:
1675 mutt_error(_("Mailbox is empty"));
1676 goto main_curses; // TEST42: neomutt -z -f /dev/null
1677 }
1678 }
1679
1680 struct Mailbox *m_cur = mailbox_find(buf_string(folder));
1681 // Take a copy of the name just in case the hook alters m_cur
1682 const char *name = m_cur ? mutt_str_dup(m_cur->name) : NULL;
1684 FREE(&name);
1686 mutt_debug(LL_NOTIFY, "NT_GLOBAL_STARTUP\n");
1688
1690 window_redraw(NULL);
1691
1692 repeat_error = true;
1693 struct Mailbox *m = mx_resolve(buf_string(folder));
1694 const bool c_read_only = cs_subset_bool(NeoMutt->sub, "read_only");
1695 if (!mx_mbox_open(m, (cli->tui.read_only || c_read_only) ? MUTT_READONLY : MUTT_OPEN_NO_FLAGS))
1696 {
1697 if (m->account)
1699
1700 mailbox_free(&m);
1701 mutt_error(_("Unable to open mailbox %s"), buf_string(folder));
1702 repeat_error = false;
1703 }
1704 if (m || !explicit_folder)
1705 {
1706 struct MuttWindow *dlg = index_pager_init();
1707 dialog_push(dlg);
1708
1710 m = dlg_index(dlg, m);
1712 mailbox_free(&m);
1713
1714 dialog_pop();
1715 mutt_window_free(&dlg);
1717 repeat_error = false;
1718 }
1720#ifdef USE_SASL_CYRUS
1722#endif
1723#ifdef USE_SASL_GNU
1725#endif
1726#ifdef USE_AUTOCRYPT
1728#endif
1729 // TEST43: neomutt (no change to mailbox)
1730 // TEST44: neomutt (change mailbox)
1731 }
1732
1733main_ok:
1734 rc = 0;
1735main_curses:
1736 mutt_endwin();
1738 /* Repeat the last message to the user */
1739 if (repeat_error && ErrorBufMessage)
1740 puts(ErrorBuf);
1741main_exit:
1742 if (NeoMutt && NeoMutt->sub)
1743 {
1747 }
1749 buf_pool_release(&expanded_infile);
1750 buf_pool_release(&tempfile);
1754 if (NeoMutt)
1758 menu_cleanup();
1759 crypt_cleanup();
1761 command_line_free(&cli);
1762
1764
1765 alias_cleanup();
1766 sb_cleanup();
1767
1773
1775
1776 /* Lists of strings */
1785
1787
1789 FREE(&LastFolder);
1791
1793
1795
1797
1799 if (NeoMutt)
1801
1802 lua_cleanup();
1806 km_cleanup();
1812 mutt_log_stop();
1813 return rc;
1814}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition address.c:765
size_t mutt_addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display)
Write an Address to a buffer.
Definition address.c:1206
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition address.c:480
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition address.c:1293
Email Address Handling.
const struct Module ModuleAddress
Module for the Address library.
Definition module.c:48
void alias_init_keys(struct SubMenu *sm_generic)
Initialise the Alias Keybindings - Implements ::init_keys_api.
Definition functions.c:128
Email Aliases.
const struct Module ModuleAlias
Module for the Alias library.
Definition module.c:48
void alias_cleanup(void)
Clean up the Alias globals.
Definition alias.c:718
struct AddressList * alias_lookup(const char *name)
Find an Alias.
Definition alias.c:276
void alias_init(void)
Set up the Alias globals.
Definition alias.c:710
void alternates_cleanup(void)
Free the alternates lists.
Definition alternates.c:48
void alternates_init(void)
Set up the alternates lists.
Definition alternates.c:59
#define ARRAY_SET(head, idx, elem)
Set an element in the array.
Definition array.h:123
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition array.h:136
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
void attach_init(void)
Set up the attachments lists.
Definition commands.c:105
void attach_cleanup(void)
Free the attachments lists.
Definition commands.c:91
void attach_init_keys(struct SubMenu *sm_generic)
Initialise the Attach Keybindings - Implements ::init_keys_api.
Definition functions.c:129
GUI display the mailboxes in a side panel.
const struct Module ModuleAttach
Module for the Attach library.
Definition module.c:36
void autocrypt_init_keys(struct SubMenu *sm_generic)
Initialise the Autocrypt Keybindings - Implements ::init_keys_api.
Definition functions.c:78
Autocrypt end-to-end encryption.
const struct Module ModuleAutocrypt
Module for the Autocrypt library.
Definition module.c:54
void mutt_autocrypt_cleanup(void)
Shutdown Autocrypt.
Definition autocrypt.c:129
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition autocrypt.c:99
const struct Module ModuleBcache
Module for the Bcache library.
Definition module.c:36
void browser_init_keys(struct SubMenu *sm_generic)
Initialise the Browser Keybindings - Implements ::init_keys_api.
Definition functions.c:132
Select a Mailbox from a list.
#define MUTT_SEL_MAILBOX
Select a mailbox.
Definition lib.h:60
#define MUTT_SEL_FOLDER
Select a local directory.
Definition lib.h:62
const struct Module ModuleBrowser
Module for the Browser library.
Definition module.c:48
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
void buf_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
Definition buffer.c:622
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition buffer.c:509
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition buffer.c:337
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
Parse the Command Line.
bool cli_parse(int argc, char *const *argv, struct CommandLine *cli)
Parse the Command Line.
Definition parse.c:93
Color and attribute parsing.
const struct Module ModuleColor
Module for the Color library.
Definition module.c:36
void colors_cleanup(void)
Cleanup all the colours.
Definition color.c:84
void colors_init(void)
Initialize colours.
Definition color.c:49
@ MT_COLOR_NORMAL
Plain text.
Definition color.h:54
@ CMD_STARTUP_HOOK
:startup-hook
Definition command.h:113
@ CMD_NONE
No Command.
Definition command.h:57
CommandResult
Error codes for command_t parse functions.
Definition command.h:35
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:36
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:37
NeoMutt Commands.
const struct Module ModuleCommands
Module for the Commands library.
Definition module.c:47
const struct Module ModuleComplete
Module for the Complete library.
Definition module.c:36
const struct Module ModuleCompmbox
Module for the Compmbox library.
Definition module.c:47
void compose_init_keys(struct SubMenu *sm_generic)
Initialise the Compose Keybindings - Implements ::init_keys_api.
Definition functions.c:218
GUI editor for an email's headers.
const struct Module ModuleCompose
Module for the Compose library.
Definition module.c:48
const struct Module ModuleCompress
Module for the Compress library.
Definition module.c:36
bool dump_config(struct ConfigSet *cs, struct HashElemArray *hea, ConfigDumpFlags flags, FILE *fp)
Write all the config to a file.
Definition dump.c:199
#define CS_DUMP_HIDE_SENSITIVE
Obscure sensitive information like passwords.
Definition dump.h:38
uint16_t ConfigDumpFlags
Flags for dump_config(), e.g. CS_DUMP_ONLY_CHANGED.
Definition dump.h:35
#define CS_DUMP_LINK_DOCS
Link to the online docs.
Definition dump.h:47
#define CS_DUMP_NO_FLAGS
No flags are set.
Definition dump.h:36
#define CS_DUMP_SHOW_DOCS
Show one-liner documentation for the config item.
Definition dump.h:46
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition helpers.c:143
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition helpers.c:168
bool config_str_set_initial(struct ConfigSet *cs, const char *name, const char *value)
Set the initial value of a Config Option.
Definition helpers.c:332
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
Convenience wrapper for the config headers.
const struct Module ModuleConfig
Module for the Config library.
Definition module.c:74
int cs_str_initial_get(const struct ConfigSet *cs, const char *name, struct Buffer *result)
Get the initial, or parent, value of a config item.
Definition set.c:594
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:447
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:669
int cs_str_native_set(const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition set.c:789
bool StartupComplete
When the config has been read.
Definition address.c:13
void config_cache_cleanup(void)
Cleanup the cache of charset config variables.
Connection Library.
const struct Module ModuleConn
Module for the Conn library.
Definition module.c:75
const struct Module ModuleConvert
Module for the Convert library.
Definition module.c:36
void account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition account.c:94
void commands_clear(struct CommandArray *ca)
Clear an Array of Commands.
Definition command.c:70
Convenience wrapper for the core headers.
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition mailbox.c:90
struct Mailbox * mailbox_find_name(const char *name)
Find the mailbox with a given name.
Definition mailbox.c:187
struct Mailbox * mailbox_find(const char *path)
Find the mailbox with a given path.
Definition mailbox.c:151
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:214
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition mailbox.h:51
@ MUTT_POP
'POP3' Mailbox type
Definition mailbox.h:52
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition mailbox.h:49
@ MUTT_IMAP
'IMAP' Mailbox type
Definition mailbox.h:50
const struct Module ModuleCore
Module for the Core library.
Definition module.c:36
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
Definition crypt.c:1102
void crypto_module_cleanup(void)
Clean up the crypto modules.
Definition crypt_mod.c:84
void crypt_cleanup(void)
Clean up backend.
Definition cryptglue.c:141
void crypt_init(void)
Initialise the crypto backends.
Definition cryptglue.c:93
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition curs_lib.c:174
void mutt_endwin(void)
Shutdown curses.
Definition curs_lib.c:152
Convenience wrapper for the debug headers.
int debug_all_observer(struct NotifyCallback *nc)
Definition notify.c:196
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition dialog.c:109
void dialog_pop(void)
Hide a Window from the user.
Definition dialog.c:142
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition dialog.c:89
void mutt_browser_cleanup(void)
Clean up working Buffers.
struct MuttWindow * index_pager_init(void)
Allocate the Windows for the Index/Pager.
Definition dlg_index.c:1436
void editor_init_keys(struct SubMenu *sm_generic)
Initialise the Editor Keybindings - Implements ::init_keys_api.
Definition functions.c:129
Edit a string.
const struct Module ModuleEditor
Module for the Editor library.
Definition module.c:36
struct Body * mutt_body_new(void)
Create a new Body.
Definition body.c:44
struct Email * email_new(void)
Create a new Email.
Definition email.c:77
void email_free(struct Email **ptr)
Free an Email.
Definition email.c:46
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
Structs that make up an email.
const struct Module ModuleEmail
Module for the Email library.
Definition module.c:48
bool mutt_parse_mailto(struct Envelope *env, char **body, const char *src)
Parse a mailto:// url.
Definition parse.c:1754
void mutt_filter_commandline_header_value(char *header)
Sanitise characters in a header value.
Definition parse.c:93
void driver_tags_cleanup(void)
Deinitialize structures used for tags.
Definition tags.c:245
void driver_tags_init(void)
Initialize structures used for tags.
Definition tags.c:233
const struct Module ModuleEnvelope
Module for the Envelope library.
Definition module.c:36
int mutt_env_to_intl(struct Envelope *env, const char **tag, char **err)
Convert an Envelope's Address fields to Punycode format.
Definition envelope.c:354
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition envelope.c:125
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition envelope.c:45
void mutt_env_set_subject(struct Envelope *env, const char *subj)
Set both subject and real_subj to subj.
Definition envelope.c:68
void envlist_free(char ***envp)
Free the private copy of the environment.
Definition envlist.c:42
const struct Module ModuleExpando
Module for the Expando library.
Definition module.c:48
void ext_keys_init(void)
Initialise map of ncurses extended keys.
Definition extended.c:114
void external_cleanup(void)
Clean up commands globals.
Definition external.c:80
Manage where the email is piped to external commands.
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition file.c:226
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:686
char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen)
Read a keyword from a file.
Definition file.c:1300
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition file.c:852
#define mutt_file_fclose(FP)
Definition file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition file.h:138
#define MUTT_RL_NO_FLAGS
No flags are set.
Definition file.h:40
const struct Module ModulePop
Module for the Pop library.
Definition module.c:48
const struct Module ModuleParse
Module for the Parse library.
Definition module.c:36
const struct Module ModuleMaildir
Module for the Maildir library.
Definition module.c:55
const struct Module ModulePostpone
Module for the Postpone library.
Definition module.c:36
const struct Module ModuleSidebar
Module for the Sidebar library.
Definition module.c:58
const struct Module ModuleMh
Module for the Mh library.
Definition module.c:48
const struct Module ModuleLua
Module for the Lua library.
Definition module.c:47
const struct Module ModulePager
Module for the Pager library.
Definition module.c:48
const struct Module ModuleGui
Module for the Gui library.
Definition module.c:36
const struct Module ModuleProgress
Module for the Progress library.
Definition module.c:48
const struct Module ModuleMenu
Module for the Menu library.
Definition module.c:48
static const struct Module * Modules[]
All the library Modules.
Definition address.c:34
const struct Module ModuleNcrypt
Module for the Ncrypt library.
Definition module.c:67
const struct Module ModuleMutt
Module for the Mutt library.
Definition module.c:36
const struct Module ModuleHcache
Module for the Hcache library.
Definition module.c:69
const struct Module ModuleSend
Module for the Send library.
Definition module.c:48
const struct Module ModuleQuestion
Module for the Question library.
Definition module.c:36
const struct Module ModuleImap
Module for the Imap library.
Definition module.c:65
const struct Module ModuleMain
Module for the Main library.
Definition module.c:55
const struct Module ModuleStore
Module for the Store library.
Definition module.c:36
const struct Module ModuleMbox
Module for the Mbox library.
Definition module.c:48
const struct Module ModulePattern
Module for the Pattern library.
Definition module.c:48
const struct Module ModuleNntp
Module for the Nntp library.
Definition module.c:48
const struct Module ModuleHelpbar
Module for the Helpbar library.
Definition module.c:48
const struct Module ModuleHistory
Module for the History library.
Definition module.c:48
const struct Module ModuleNotmuch
Module for the Notmuch library.
Definition module.c:64
const struct Module ModuleKey
Module for the Key library.
Definition module.c:47
const struct Module ModuleIndex
Module for the Index library.
Definition module.c:48
const struct Module ModuleHooks
Module for the Hooks library.
Definition module.c:50
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition get.c:64
int getdnsdomainname(struct Buffer *result)
Lookup the host's name using DNS.
Definition getdomain.c:124
bool OptNews
(pseudo) used to change reader mode
Definition globals.c:64
char * LastFolder
Previously selected mailbox.
Definition globals.c:40
char * ShortHostname
Short version of the hostname.
Definition globals.c:37
struct ListHead MimeLookupList
List of mime types that that shouldn't use the mailcap entry.
Definition globals.c:47
struct ListHead AlternativeOrderList
List of preferred mime types to display.
Definition globals.c:44
struct ListHead AutoViewList
List of mime types to auto view.
Definition globals.c:45
char ErrorBuf[1024]
Copy of the last error message.
Definition globals.c:35
bool ErrorBufMessage
true if the last message was an error
Definition globals.c:34
char * CurrentFolder
Currently selected mailbox.
Definition globals.c:39
bool OptGui
(pseudo) when the gui (and curses) are started
Definition globals.c:59
struct ListHead UserHeader
List of custom headers to add to outgoing emails.
Definition globals.c:49
struct ListHead HeaderOrderList
List of header fields in the order they should be displayed.
Definition globals.c:46
Global variables.
enum CommandResult parse_my_header(const struct Command *cmd, struct Buffer *line, struct Buffer *err)
Parse the 'my-header' command - Implements Command::parse() -.
Definition my_header.c:52
void dlg_browser(struct Buffer *file, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
Let the user select a file -.
struct Mailbox * dlg_index(struct MuttWindow *dlg, struct Mailbox *m_init)
Display a list of emails -.
Definition dlg_index.c:1099
int log_disp_queue(time_t stamp, const char *file, int line, const char *function, enum LogLevel level, const char *format,...)
Save a log line to an internal queue - Implements log_dispatcher_t -.
Definition logging.c:379
#define mutt_warning(...)
Definition logging2.h:92
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:422
int log_disp_curses(time_t stamp, const char *file, int line, const char *function, enum LogLevel level, const char *format,...)
Display a log line in the message line - Implements log_dispatcher_t -.
#define mutt_error(...)
Definition logging2.h:94
#define mutt_message(...)
Definition logging2.h:93
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
#define mutt_perror(...)
Definition logging2.h:95
enum MailboxType nntp_path_probe(const char *path, const struct stat *st)
Is this an NNTP Mailbox?
Definition nntp.c:2786
enum MailboxType pop_path_probe(const char *path, const struct stat *st)
Is this a POP Mailbox?
Definition pop.c:1156
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox?
Definition imap.c:2470
int main_hist_observer(struct NotifyCallback *nc)
Notification that a Config Variable has change - Implements observer_t -.
Definition history.c:701
static int main_timeout_observer(struct NotifyCallback *nc)
Notification that a timeout has occurred - Implements observer_t -.
Definition main.c:890
int main_log_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
void mutt_gsasl_cleanup(void)
Shutdown GNU SASL library.
Definition gsasl.c:149
struct SubMenu * generic_init_keys(void)
Initialise the Generic Keybindings.
Definition functions.c:191
Convenience wrapper for the gui headers.
int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *b, enum MuttWriteHeaderMode mode, bool privacy, bool hide_protected_subject, struct ConfigSubset *sub)
Write out one RFC822 header line.
Definition header.c:578
@ MUTT_WRITE_HEADER_POSTPONE
A postponed Email, just the envelope info.
Definition header.h:42
Read/write command history from/to a file.
void mutt_hist_read_file(void)
Read the History from a file.
Definition history.c:592
void mutt_hist_init(void)
Create a set of empty History ring buffers.
Definition history.c:464
void mutt_hist_cleanup(void)
Free all the history lists.
Definition history.c:437
Hook Commands.
void mutt_delete_hooks(enum CommandId id)
Delete matching hooks.
Definition parse.c:996
IMAP network mailbox.
void imap_logout_all(void)
Close all open connections.
Definition imap.c:660
void index_init_keys(struct SubMenu *sm_generic)
Initialise the Index Keybindings - Implements ::init_keys_api.
Definition functions.c:327
GUI manage the main index (list of emails)
void km_cleanup(void)
Free the key maps.
Definition init.c:181
void km_init(void)
Initialise all the menu keybindings.
Definition init.c:170
void km_set_abort_key(void)
Parse the abort_key config string.
Definition init.c:210
Manage keymappings.
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition list.c:123
int log_dispatcher_t MuttLogger
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ LL_MESSAGE
Log informational message.
Definition logging2.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:50
@ LL_MAX
Definition logging2.h:52
void lua_cleanup(void)
Clean up Lua.
Definition commands.c:162
Integrated Lua scripting.
static char * find_cfg(const char *home, const char *xdg_cfg_home)
Find a config file.
Definition main.c:276
static char * getmailname(void)
Try to retrieve the FQDN from mailname files.
Definition main.c:323
static bool init_logging(struct CliShared *shared, struct ConfigSet *cs)
Initialise the Logging.
Definition main.c:955
static void log_translation(void)
Log the translation being used.
Definition main.c:841
static void log_gui(void)
Log info about the GUI.
Definition main.c:867
static void init_nntp(struct Buffer *server, struct ConfigSet *cs)
Initialise the NNTP config.
Definition main.c:984
static bool show_help(struct CliHelp *help)
Show the Help.
Definition main.c:924
static int start_curses(void)
Start the Curses UI.
Definition main.c:766
static bool dump_info(struct CliInfo *ci, struct ConfigSet *cs)
Show config info.
Definition main.c:1013
static bool get_user_info(struct ConfigSet *cs)
Find the user's name, home and shell.
Definition main.c:800
void show_cli(enum HelpMode mode, bool use_color)
Show Instructions on how to run NeoMutt.
Definition usage.c:332
static bool get_hostname(struct ConfigSet *cs)
Find the Fully-Qualified Domain Name.
Definition main.c:356
static int get_elem_queries(struct StringArray *queries, struct HashElemArray *hea)
Lookup the HashElems for a set of queries.
Definition main.c:710
static int execute_commands(struct StringArray *sa)
Execute a set of NeoMutt commands.
Definition main.c:240
int main(int argc, char *argv[], char *envp[])
Start NeoMutt.
Definition main.c:1077
static int mutt_init(struct ConfigSet *cs, struct Buffer *dlevel, struct Buffer *dfile, bool skip_sys_rc, struct StringArray *user_files, struct StringArray *commands)
Initialise NeoMutt.
Definition main.c:442
static void init_keys(void)
Initialise the Keybindings.
Definition main.c:740
#define countof(x)
Definition memory.h:45
#define FREE(x)
Definition memory.h:63
GUI present the user with a selectable list.
void menu_init(void)
Initialise all the Menus.
Definition menu.c:79
void menu_cleanup(void)
Free the saved Menu searches.
Definition menu.c:70
struct Body * mutt_make_multipart(struct Body *b)
Create a multipart email.
Definition multipart.c:100
char * mutt_ch_get_langinfo_charset(void)
Get the user's choice of character set.
Definition charset.c:472
void mutt_ch_cache_cleanup(void)
Clean up the cached iconv handles and charset strings.
Definition charset.c:1161
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
Definition charset.c:1061
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition date.c:457
Convenience wrapper for the library headers.
void log_queue_empty(void)
Free the contents of the queue.
Definition logging.c:326
void log_queue_set_max_size(int size)
Set a upper limit for the queue length.
Definition logging.c:314
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
Definition logging.c:348
#define _(a)
Definition message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition notify.c:230
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition notify.c:191
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition notify.c:173
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:450
struct Slist * slist_parse(const char *str, uint32_t flags)
Parse a list of strings into a list.
Definition slist.c:177
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition slist.c:124
int slist_to_buffer(const struct Slist *list, struct Buffer *buf)
Export an Slist to a Buffer.
Definition slist.c:269
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
Definition string.c:384
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition string.c:805
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:662
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition string.c:728
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
Definition string.c:525
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition string.c:246
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:284
Many unsorted constants and some structs.
#define PATH_MAX
Definition mutt.h:42
void mutt_temp_attachments_cleanup(void)
Delete all temporary attachments.
enum MuttCursorState mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition mutt_curses.c:94
const struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the Colour ID.
Definition mutt_curses.c:79
void mutt_resize_screen(void)
Update NeoMutt's opinion about the window size.
Definition resize.c:76
@ MUTT_CURSOR_INVISIBLE
Hide the cursor.
Definition mutt_curses.h:65
@ MUTT_CURSOR_VISIBLE
Display a normal cursor.
Definition mutt_curses.h:66
void mutt_log_stop(void)
Close the log file.
int mutt_log_start(void)
Enable file logging.
void mutt_log_prep(void)
Prepare to log.
NeoMutt Logging.
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
struct Mailbox * mutt_mailbox_next(struct Mailbox *m_cur, struct Buffer *s)
Incoming folders completion routine.
Mailbox helper functions.
void mutt_signal_init(void)
Initialise the signal handling.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition mutt_window.h:87
char * mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw)
Lookup a user's real name in /etc/passwd.
Definition muttlib.c:332
void add_to_stailq(struct ListHead *head, const char *str)
Add a string to a list.
Definition muttlib.c:1039
int mutt_set_xdg_path(enum XdgType type, struct Buffer *buf)
Find an XDG path or its fallback.
Definition muttlib.c:883
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Definition muttlib.c:315
Some miscellaneous functions.
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition mx.c:288
struct Mailbox * mx_resolve(const char *path_or_name)
Get a Mailbox from either a path or name.
Definition mx.c:1722
int mx_path_is_empty(struct Buffer *path)
Is the mailbox empty.
Definition mx.c:1257
API for mailboxes.
#define MUTT_READONLY
Open in read-only mode.
Definition mxapi.h:43
#define MUTT_MAILBOX_CHECK_IMMEDIATE
Don't postpone the actual checking.
Definition mxapi.h:53
#define MUTT_OPEN_NO_FLAGS
No flags are set.
Definition mxapi.h:40
uint8_t CheckStatsFlags
Flags for mutt_mailbox_check.
Definition mxapi.h:49
void pgp_init_keys(struct SubMenu *sm_generic)
Initialise the PGP Keybindings - Implements ::init_keys_api.
Definition functions.c:88
API for encryption/signing of emails.
struct MailboxArray neomutt_mailboxes_get(struct NeoMutt *n, enum MailboxType type)
Get an Array of matching Mailboxes.
Definition neomutt.c:488
void neomutt_cleanup(struct NeoMutt *n)
Clean up NeoMutt and Modules.
Definition neomutt.c:370
bool neomutt_init(struct NeoMutt *n, char **envp, const struct Module **modules)
Initialise NeoMutt.
Definition neomutt.c:315
struct NeoMutt * neomutt_new(void)
Create the main NeoMutt object.
Definition neomutt.c:303
void neomutt_free(struct NeoMutt **ptr)
Free a NeoMutt.
Definition neomutt.c:382
@ NT_GLOBAL_STARTUP
NeoMutt is initialised.
Definition neomutt.h:155
Nntp-specific Account data.
Usenet network mailbox type; talk to an NNTP server.
void nntp_expand_path(char *buf, size_t buflen, struct ConnAccount *acct)
Make fully qualified url from newsgroup name.
Definition newsrc.c:556
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition nntp.c:77
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition newsrc.c:945
@ NT_TIMEOUT
Timeout has occurred.
Definition notify_type.h:56
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
@ NT_ALL
Register for all notifications.
Definition notify_type.h:35
@ NT_GLOBAL
Not object-related, NotifyGlobal.
Definition notify_type.h:46
@ NT_RESIZE
Window has been resized.
Definition notify_type.h:52
struct CommandLine * command_line_new(void)
Create a new CommandLine.
Definition objects.c:105
void command_line_free(struct CommandLine **ptr)
Free a CommandLine.
Definition objects.c:114
HelpMode
Show detailed help.
Definition objects.h:33
void pager_init_keys(struct SubMenu *sm_generic)
Initialise the Pager Keybindings - Implements ::init_keys_api.
Definition functions.c:322
GUI display a file/email/help in a viewport with paging.
Text parsing functions.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:96
void buf_pool_cleanup(void)
Release the Buffer pool.
Definition pool.c:68
POP network mailbox.
void postponed_init_keys(struct SubMenu *sm_generic)
Initialise the Postponed Keybindings - Implements ::init_keys_api.
Definition functions.c:73
Postponed Emails.
int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *e_new, struct Email *e, bool resend)
Prepare a message template.
Definition postpone.c:487
void mutt_prex_cleanup(void)
Cleanup heap memory allocated by compiled regexes.
Definition prex.c:338
Prototypes for many functions.
@ XDG_CONFIG_DIRS
XDG system dir: /etc/xdg.
Definition protos.h:45
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition quad.h:39
Ask the user a question.
enum QuadOption query_yesorno(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question.
Definition question.c:326
#define STAILQ_REMOVE(head, elm, type, field)
Definition queue.h:441
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition queue.h:400
#define TAILQ_EMPTY(head)
Definition queue.h:778
enum CommandResult parse_rc_line(struct Buffer *line, struct Buffer *err)
Parse a line of user config.
Definition rc.c:42
void rootwin_cleanup(void)
Free all the default Windows.
Definition rootwin.c:202
struct MuttWindow * RootWindow
Parent of all Windows.
Definition rootwin.c:106
void rootwin_new(void)
Create the default Windows.
Definition rootwin.c:214
void mutt_timeout_hook(void)
Execute any timeout hooks.
Definition run.c:365
void mutt_folder_hook(const char *path, const char *desc)
Perform a folder hook.
Definition run.c:63
void mutt_startup_shutdown_hook(enum CommandId id)
Execute any startup/shutdown hooks.
Definition run.c:397
void mutt_sasl_cleanup(void)
Invoke when processing is complete.
Definition sasl.c:786
int mutt_write_mime_body(struct Body *b, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
Definition body.c:300
Convenience wrapper for the send headers.
void mutt_encode_descriptions(struct Body *b, bool recurse, struct ConfigSubset *sub)
RFC2047 encode the content-descriptions.
Definition send.c:1489
int mutt_send_message(SendFlags flags, struct Email *e_templ, const char *tempfile, struct Mailbox *m, struct EmailArray *ea, struct ConfigSubset *sub)
Send an email.
Definition send.c:2034
#define SEND_BATCH
Send email in batch mode (without user interaction)
Definition send.h:47
#define SEND_NO_FREE_HEADER
Used by the -E flag.
Definition send.h:51
#define SEND_DRAFT_FILE
Used by the -H flag.
Definition send.h:52
uint32_t SendFlags
Flags for mutt_send_message(), e.g. SEND_REPLY.
Definition send.h:40
#define SEND_POSTPONED
Recall a postponed email.
Definition send.h:46
#define SEND_CONSUMED_STDIN
stdin has been read; don't read it twice
Definition send.h:57
#define SEND_NO_FLAGS
No flags are set.
Definition send.h:41
struct Body * mutt_make_file_attach(const char *path, struct ConfigSubset *sub)
Create a file attachment.
Definition sendlib.c:608
void mutt_prepare_envelope(struct Envelope *env, bool final, struct ConfigSubset *sub)
Prepare an email header.
Definition sendlib.c:741
void sidebar_init_keys(struct SubMenu *sm_generic)
Initialise the Sidebar Keybindings - Implements ::init_keys_api.
Definition functions.c:70
GUI display the mailboxes in a side panel.
void sb_init(void)
Set up the Sidebar.
Definition sidebar.c:213
void sb_cleanup(void)
Clean up the Sidebar.
Definition sidebar.c:227
int endwin(void)
void source_stack_cleanup(void)
Free memory from the stack used for the source command.
Definition source.c:257
int source_rc(const char *rcfile_path, struct Buffer *err)
Read an initialization file.
Definition source.c:66
#define NONULL(x)
Definition string2.h:44
#define SKIPWS(ch)
Definition string2.h:52
The body of an email.
Definition body.h:36
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition body.h:68
LOFF_T length
length (in bytes) of attachment
Definition body.h:53
struct Body * next
next attachment in the list
Definition body.h:72
String manipulation buffer.
Definition buffer.h:36
size_t dsize
Length of data.
Definition buffer.h:39
char * data
Pointer to data.
Definition buffer.h:37
Help Mode Command Line options.
Definition objects.h:64
bool license
-vv Print license
Definition objects.h:68
enum HelpMode mode
Display detailed help.
Definition objects.h:70
bool help
-h Print help
Definition objects.h:66
bool is_set
This struct has been used.
Definition objects.h:65
Info Mode Command Line options.
Definition objects.h:77
bool show_help
-O Show one-liner help
Definition objects.h:81
bool is_set
This struct has been used.
Definition objects.h:78
struct StringArray queries
-Q Query a config option
Definition objects.h:85
struct StringArray alias_queries
-A Lookup an alias
Definition objects.h:84
bool dump_config
-D Dump the config
Definition objects.h:79
bool dump_changed
-DD Dump the changed config
Definition objects.h:80
bool hide_sensitive
-S Hide sensitive config
Definition objects.h:82
struct Buffer draft_file
-H Use this draft file
Definition objects.h:102
bool is_set
This struct has been used.
Definition objects.h:93
struct Buffer include_file
-i Use this include file
Definition objects.h:103
struct StringArray cc_list
-c Add a Cc:
Definition objects.h:99
struct StringArray attach
-a Attach a file
Definition objects.h:97
bool edit_infile
-E Edit the draft/include
Definition objects.h:95
struct StringArray bcc_list
-b Add a Bcc:
Definition objects.h:98
struct StringArray addresses
Send to these addresses.
Definition objects.h:100
struct Buffer subject
-s Use this Subject:
Definition objects.h:104
Shared Command Line options.
Definition objects.h:47
struct Buffer log_level
-d Debug log level
Definition objects.h:56
struct Buffer log_file
-l Debug log file
Definition objects.h:57
struct StringArray commands
-e Run these commands
Definition objects.h:53
bool is_set
This struct has been used.
Definition objects.h:48
bool disable_system
-n Don't read the system config file
Definition objects.h:51
struct StringArray user_files
-F Use these user config files
Definition objects.h:50
struct Buffer mbox_type
-m Set the default Mailbox type
Definition objects.h:54
bool read_only
-R Open Mailbox read-only
Definition objects.h:113
bool start_any_mail
-z Check for Any Mail
Definition objects.h:118
bool start_nntp
-G Open an NNTP Mailbox
Definition objects.h:116
struct Buffer nntp_server
-g Open this NNTP Mailbox
Definition objects.h:121
struct Buffer folder
-f Open this Mailbox
Definition objects.h:120
bool start_postponed
-p Open Postponed emails
Definition objects.h:114
bool start_new_mail
-Z Check for New Mail
Definition objects.h:117
bool start_browser
-y Open the Mailbox Browser
Definition objects.h:115
Command Line options.
Definition objects.h:128
struct CliSend send
Send Mode command line options.
Definition objects.h:132
struct CliShared shared
Shared command line options.
Definition objects.h:129
struct CliHelp help
Help Mode command line options.
Definition objects.h:130
struct CliInfo info
Info Mode command line options.
Definition objects.h:131
struct CliTui tui
Tui Mode command line options.
Definition objects.h:133
Container for lots of config items.
Definition set.h:248
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
struct ConfigSet * cs
Parent ConfigSet.
Definition subset.h:50
The envelope/body of an email.
Definition email.h:39
struct Envelope * env
Envelope information.
Definition email.h:68
struct Body * body
List of MIME parts.
Definition email.h:69
LOFF_T offset
Where in the stream does this message begin?
Definition email.h:71
The header of an Email.
Definition envelope.h:57
struct ListHead userhdrs
user defined headers
Definition envelope.h:85
char *const subject
Email's subject.
Definition envelope.h:70
struct AddressList to
Email's 'To' list.
Definition envelope.h:60
struct AddressList cc
Email's 'Cc' list.
Definition envelope.h:61
struct AddressList bcc
Email's 'Bcc' list.
Definition envelope.h:62
The item stored in a Hash Table.
Definition hash.h:44
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition hash.h:45
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
A mailbox.
Definition mailbox.h:79
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:81
char * name
A short name for the Mailbox.
Definition mailbox.h:82
struct Account * account
Account that owns this Mailbox.
Definition mailbox.h:127
struct MuttWindow * focus
Focused Window.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Container for Accounts, Notifications.
Definition neomutt.h:128
struct AccountArray accounts
All Accounts.
Definition neomutt.h:135
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:138
struct Notify * notify_resize
Window resize notifications handler.
Definition neomutt.h:131
char ** env
Private copy of the environment variables.
Definition neomutt.h:143
char * username
User's login name.
Definition neomutt.h:142
char * home_dir
User's home directory.
Definition neomutt.h:141
struct Notify * notify
Notifications handler.
Definition neomutt.h:130
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:134
Data passed to a notification function.
Definition observer.h:34
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition observer.h:36
String list.
Definition slist.h:37
Collection of related functions.
Definition menu.h:69
void subjrx_init(void)
Create new Subject Regex List.
Definition subjectrx.c:54
void subjrx_cleanup(void)
Free the Subject Regex List.
Definition subjectrx.c:45
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.
Definition subset.c:303
struct HashElemArray get_elem_list(struct ConfigSet *cs, enum GetElemListFlags flags)
Create a sorted list of all config items.
Definition subset.c:81
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
Definition subset.c:193
GetElemListFlags
Flags for get_elem_list()
Definition subset.h:80
@ GEL_CHANGED_CONFIG
Only config that has been changed.
Definition subset.h:82
@ GEL_ALL_CONFIG
All the normal config (no synonyms or deprecated)
Definition subset.h:81
bool TsSupported
Terminal Setting is supported.
Definition terminal.c:53
bool mutt_ts_capability(void)
Check terminal capabilities.
Definition terminal.c:83
#define buf_mktemp(buf)
Definition tmp.h:33
#define D_SLIST_SEP_COLON
Slist items are colon-separated.
Definition types.h:111
#define D_INTERNAL_DEPRECATED
Config item shouldn't be used any more.
Definition types.h:87
enum UrlScheme url_check_scheme(const char *str)
Check the protocol of a URL.
Definition url.c:226
@ U_MAILTO
Url is mailto://.
Definition url.h:45
bool print_copyright(void)
Print copyright message.
Definition version.c:702
bool print_version(FILE *fp, bool use_ansi)
Print system and compile info to a file.
Definition version.c:591
Display version and copyright about NeoMutt.