NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
29
90
96
97#define GNULIB_defined_setlocale
98
99#include "config.h"
100#include <errno.h>
101#include <limits.h>
102#include <pwd.h>
103#include <stdbool.h>
104#include <stdio.h>
105#include <string.h>
106#include <sys/stat.h>
107#include <sys/utsname.h>
108#include <time.h>
109#include <unistd.h>
110#include "mutt/lib.h"
111#include "address/lib.h"
112#include "config/lib.h"
113#include "email/lib.h"
114#include "core/lib.h"
115#include "alias/lib.h"
116#include "conn/lib.h"
117#include "gui/lib.h"
118#include "mutt.h"
119#include "attach/lib.h"
120#include "browser/lib.h"
121#include "cli/lib.h"
122#include "color/lib.h"
123#include "commands/lib.h"
124#include "compose/lib.h"
125#include "editor/lib.h"
126#include "history/lib.h"
127#include "hooks/lib.h"
128#include "imap/lib.h"
129#include "index/lib.h"
130#include "key/lib.h"
131#include "lua/lib.h"
132#include "menu/lib.h"
133#include "ncrypt/lib.h"
134#include "nntp/lib.h"
135#include "pager/lib.h"
136#include "parse/lib.h"
137#include "pop/lib.h"
138#include "postpone/lib.h"
139#include "question/lib.h"
140#include "send/lib.h"
141#include "sidebar/lib.h"
142#include "external.h"
143#include "globals.h"
144#include "mutt_logging.h"
145#include "mutt_mailbox.h"
146#include "muttlib.h"
147#include "mx.h"
148#include "nntp/adata.h" // IWYU pragma: keep
149#include "version.h"
150#ifdef ENABLE_NLS
151#include <libintl.h>
152#endif
153#ifdef USE_AUTOCRYPT
154#include "autocrypt/lib.h"
155#endif
156#if defined(USE_DEBUG_NOTIFY) || defined(USE_DEBUG_BACKTRACE)
157#include "debug/lib.h"
158#endif
159#ifndef DOMAIN
160#include "conn/lib.h"
161#endif
162
163bool StartupComplete = false;
164
165void show_cli(enum HelpMode mode, bool use_color);
166
167// clang-format off
168extern const struct Module ModuleMain;
169extern const struct Module ModuleAddress; extern const struct Module ModuleAlias; extern const struct Module ModuleAttach; extern const struct Module ModuleAutocrypt;
170extern const struct Module ModuleBcache; extern const struct Module ModuleBrowser; extern const struct Module ModuleColor; extern const struct Module ModuleCommands;
171extern const struct Module ModuleComplete; extern const struct Module ModuleCompmbox; extern const struct Module ModuleCompose; extern const struct Module ModuleCompress;
172extern const struct Module ModuleConfig; extern const struct Module ModuleConn; extern const struct Module ModuleConvert; extern const struct Module ModuleCore;
173extern const struct Module ModuleEditor; extern const struct Module ModuleEmail; extern const struct Module ModuleEnvelope; extern const struct Module ModuleExpando;
174extern const struct Module ModuleGui; extern const struct Module ModuleHcache; extern const struct Module ModuleHelpbar; extern const struct Module ModuleHistory;
175extern const struct Module ModuleHooks; extern const struct Module ModuleImap; extern const struct Module ModuleIndex; extern const struct Module ModuleKey;
176extern const struct Module ModuleLua; extern const struct Module ModuleMaildir; extern const struct Module ModuleMbox; extern const struct Module ModuleMenu;
177extern const struct Module ModuleMh; extern const struct Module ModuleMutt; extern const struct Module ModuleNcrypt; extern const struct Module ModuleNntp;
178extern const struct Module ModuleNotmuch; extern const struct Module ModulePager; extern const struct Module ModuleParse; extern const struct Module ModulePattern;
179extern const struct Module ModulePop; extern const struct Module ModulePostpone; extern const struct Module ModuleProgress; extern const struct Module ModuleQuestion;
180extern const struct Module ModuleSend; extern const struct Module ModuleSidebar; extern const struct Module ModuleStore;
181// clang-format on
182
186static const struct Module *Modules[] = {
187 // clang-format off
188 &ModuleMain, &ModuleGui, // These two have priority
197// clang-format on
198#ifdef USE_AUTOCRYPT
200#endif
201#ifdef USE_HCACHE_COMPRESSION
203#endif
204#ifdef USE_HCACHE
206#endif
207#ifdef USE_LUA
208 &ModuleLua,
209#endif
210#ifdef USE_NOTMUCH
212#endif
213#ifdef USE_HCACHE
215#endif
216 NULL,
217};
218
225static int execute_commands(struct StringArray *sa)
226{
227 int rc = 0;
228 struct Buffer *line = buf_pool_get();
229 struct ParseContext *pc = parse_context_new();
230 struct ParseError *pe = parse_error_new();
231
232 const char **cp = NULL;
233 ARRAY_FOREACH(cp, sa)
234 {
235 buf_strcpy(line, *cp);
236 enum CommandResult rc2 = parse_rc_line(line, pc, pe);
237 if (rc2 == MUTT_CMD_ERROR)
238 mutt_error(_("Error in command line: %s"), buf_string(pe->message));
239 else if (rc2 == MUTT_CMD_WARNING)
240 mutt_warning(_("Warning in command line: %s"), buf_string(pe->message));
241
242 if ((rc2 == MUTT_CMD_ERROR) || (rc2 == MUTT_CMD_WARNING))
243 {
244 rc = -1;
245 goto done;
246 }
247 }
248
249done:
250 buf_pool_release(&line);
252 parse_error_free(&pe);
253
254 return rc;
255}
256
264static char *find_cfg(const char *home, const char *xdg_cfg_home)
265{
266 const char *names[] = {
267 "neomuttrc",
268 "muttrc",
269 NULL,
270 };
271
272 const char *locations[][2] = {
273 { xdg_cfg_home, "neomutt/" },
274 { xdg_cfg_home, "mutt/" },
275 { home, ".neomutt/" },
276 { home, ".mutt/" },
277 { home, "." },
278 { NULL, NULL },
279 };
280
281 struct Buffer *buf = buf_pool_get();
282 char *cfg = NULL;
283
284 for (int i = 0; locations[i][0] || locations[i][1]; i++)
285 {
286 if (!locations[i][0])
287 continue;
288
289 for (int j = 0; names[j]; j++)
290 {
291 buf_printf(buf, "%s/%s%s", locations[i][0], locations[i][1], names[j]);
292 if (access(buf_string(buf), F_OK) == 0)
293 {
294 cfg = buf_strdup(buf);
295 goto done;
296 }
297 }
298 }
299
300done:
301 buf_pool_release(&buf);
302 return cfg;
303}
304
305#ifndef DOMAIN
311static char *getmailname(void)
312{
313 char *mailname = NULL;
314 static const char *mn_files[] = { "/etc/mailname", "/etc/mail/mailname" };
315
316 for (size_t i = 0; i < countof(mn_files); i++)
317 {
318 FILE *fp = mutt_file_fopen(mn_files[i], "r");
319 if (!fp)
320 continue;
321
322 size_t len = 0;
323 mailname = mutt_file_read_line(NULL, &len, fp, NULL, MUTT_RL_NO_FLAGS);
324 mutt_file_fclose(&fp);
325 if (mailname && *mailname)
326 break;
327
328 FREE(&mailname);
329 }
330
331 return mailname;
332}
333#endif
334
344static bool get_hostname(struct ConfigSet *cs)
345{
346 const char *short_host = NULL;
347 struct utsname utsname = { 0 };
348
349 const char *const c_hostname = cs_subset_string(NeoMutt->sub, "hostname");
350 if (c_hostname)
351 {
352 short_host = c_hostname;
353 }
354 else
355 {
356 /* The call to uname() shouldn't fail, but if it does, the system is horribly
357 * broken, and the system's networking configuration is in an unreliable
358 * state. We should bail. */
359 if ((uname(&utsname)) == -1)
360 {
361 mutt_perror(_("unable to determine nodename via uname()"));
362 return false; // TEST09: can't test
363 }
364
365 short_host = utsname.nodename;
366 }
367
368 /* some systems report the FQDN instead of just the hostname */
369 char *dot = strchr(short_host, '.');
370 if (dot)
371 ShortHostname = mutt_strn_dup(short_host, dot - short_host);
372 else
373 ShortHostname = mutt_str_dup(short_host);
374
375 // All the code paths from here alloc memory for the fqdn
376 char *fqdn = mutt_str_dup(c_hostname);
377 if (!fqdn)
378 {
379 mutt_debug(LL_DEBUG1, "Setting $hostname\n");
380 /* now get FQDN. Use configured domain first, DNS next, then uname */
381#ifdef DOMAIN
382 /* we have a compile-time domain name, use that for `$hostname` */
383 mutt_str_asprintf(&fqdn, "%s.%s", NONULL(ShortHostname), DOMAIN);
384#else
385 fqdn = getmailname();
386 if (!fqdn)
387 {
388 struct Buffer *domain = buf_pool_get();
389 if (getdnsdomainname(domain) == 0)
390 {
391 mutt_str_asprintf(&fqdn, "%s.%s", NONULL(ShortHostname), buf_string(domain));
392 }
393 else
394 {
395 /* DNS failed, use the nodename. Whether or not the nodename had a '.'
396 * in it, we can use the nodename as the FQDN. On hosts where DNS is
397 * not being used, e.g. small network that relies on hosts files, a
398 * short host name is all that is required for SMTP to work correctly.
399 * It could be wrong, but we've done the best we can, at this point the
400 * onus is on the user to provide the correct hostname if the nodename
401 * won't work in their network. */
402 fqdn = mutt_str_dup(utsname.nodename);
403 }
404 buf_pool_release(&domain);
405 mutt_debug(LL_DEBUG1, "Hostname: %s\n", NONULL(fqdn));
406 }
407#endif
408 }
409
410 if (fqdn)
411 {
412 config_str_set_initial(cs, "hostname", fqdn);
413 FREE(&fqdn);
414 }
415
416 return true;
417}
418
430static int mutt_init(struct ConfigSet *cs, struct Buffer *dlevel,
431 struct Buffer *dfile, bool skip_sys_rc,
432 struct StringArray *user_files, struct StringArray *commands)
433{
434 bool need_pause = false;
435 int rc = 1;
436 struct Buffer *buf = buf_pool_get();
437 struct ParseContext *pc = parse_context_new();
438 struct ParseError *pe = parse_error_new();
439 const char **cp = NULL;
440
441#ifdef NEOMUTT_DIRECT_COLORS
442 /* Test if we run in a terminal which supports direct colours.
443 *
444 * The user/terminal can indicate their capability independent of the
445 * terminfo file by setting the COLORTERM environment variable to "truecolor"
446 * or "24bit" (case sensitive).
447 *
448 * Note: This is to test is less about whether the terminal understands
449 * direct color commands but more about whether ncurses believes it can send
450 * them to the terminal, e.g. ncurses ignores COLORTERM.
451 */
452 if (COLORS == 16777216) // 2^24
453 {
454 /* Ncurses believes the Terminal supports it check the environment variable
455 * to respect the user's choice */
456 const char *env_colorterm = mutt_str_getenv("COLORTERM");
457 if (env_colorterm && (mutt_str_equal(env_colorterm, "truecolor") ||
458 mutt_str_equal(env_colorterm, "24bit")))
459 {
460 config_str_set_initial(cs, "color_directcolor", "yes");
461 }
462 }
463#endif
464
465 /* "$spool_file" precedence: config file, environment */
466 const char *p = mutt_str_getenv("MAIL");
467 if (!p)
468 p = mutt_str_getenv("MAILDIR");
469 if (!p)
470 {
471#ifdef HOMESPOOL
472 buf_concat_path(buf, NONULL(NeoMutt->home_dir), MAILPATH);
473#else
474 buf_concat_path(buf, MAILPATH, NONULL(NeoMutt->username));
475#endif
476 p = buf_string(buf);
477 }
478 config_str_set_initial(cs, "spool_file", p);
479
480 p = mutt_str_getenv("REPLYTO");
481 if (p)
482 {
483 buf_printf(buf, "Reply-To: %s", p);
484 buf_seek(buf, 0);
485
487 ASSERT(cmd);
488 parse_my_header(cmd, buf, pc, pe);
489 }
490
491 p = mutt_str_getenv("EMAIL");
492 if (p)
493 config_str_set_initial(cs, "from", p);
494
495 /* "$mailcap_path" precedence: config file, environment, code */
496 struct Buffer *mc = buf_pool_get();
497 struct Slist *sl_mc = NULL;
498 const char *env_mc = mutt_str_getenv("MAILCAPS");
499 if (env_mc)
500 {
501 sl_mc = slist_parse(env_mc, D_SLIST_SEP_COLON);
502 }
503 else
504 {
505 cs_str_initial_get(cs, "mailcap_path", mc);
507 buf_reset(mc);
508 }
509 slist_to_buffer(sl_mc, mc);
510 config_str_set_initial(cs, "mailcap_path", buf_string(mc));
511 slist_free(&sl_mc);
512 buf_pool_release(&mc);
513
514 /* "$tmp_dir" precedence: config file, environment, code */
515 const char *env_tmp = mutt_str_getenv("TMPDIR");
516 if (env_tmp)
517 {
518 config_str_set_initial(cs, "tmp_dir", env_tmp);
519 config_str_set_initial(cs, "tmp_draft_dir", env_tmp);
520 }
521
522 /* "$visual", "$editor" precedence: config file, environment, code */
523 const char *env_ed = mutt_str_getenv("VISUAL");
524 if (!env_ed)
525 env_ed = mutt_str_getenv("EDITOR");
526 if (!env_ed)
527 env_ed = "vi";
528 config_str_set_initial(cs, "editor", env_ed);
529
530 const char *charset = mutt_ch_get_langinfo_charset();
531 config_str_set_initial(cs, "charset", charset);
532 mutt_ch_set_charset(charset);
533 FREE(&charset);
534
535 char name[256] = { 0 };
536 const char *c_real_name = cs_subset_string(NeoMutt->sub, "real_name");
537 if (!c_real_name)
538 {
539 struct passwd *pw = getpwuid(getuid());
540 if (pw)
541 {
542 c_real_name = mutt_gecos_name(name, sizeof(name), pw);
543 }
544 }
545 config_str_set_initial(cs, "real_name", c_real_name);
546
547 if (ARRAY_EMPTY(user_files))
548 {
549 const char *xdg_cfg_home = mutt_str_getenv("XDG_CONFIG_HOME");
550
551 if (!xdg_cfg_home && NeoMutt->home_dir)
552 {
553 buf_printf(buf, "%s/.config", NeoMutt->home_dir);
554 xdg_cfg_home = buf_string(buf);
555 }
556
557 char *config = find_cfg(NeoMutt->home_dir, xdg_cfg_home);
558 if (config)
559 {
560 ARRAY_ADD(user_files, config);
561 }
562 }
563 else
564 {
565 ARRAY_FOREACH(cp, user_files)
566 {
567 buf_strcpy(buf, *cp);
568 FREE(cp);
569 expand_path(buf, false);
570 ARRAY_SET(user_files, ARRAY_FOREACH_IDX_cp, buf_strdup(buf));
571 if (access(buf_string(buf), F_OK))
572 {
573 mutt_perror("%s", buf_string(buf));
574 goto done; // TEST10: neomutt -F missing
575 }
576 }
577 }
578
579 ARRAY_FOREACH(cp, user_files)
580 {
581 if (*cp && !mutt_str_equal(*cp, "/dev/null"))
582 {
583 cs_str_string_set(cs, "alias_file", *cp, NULL);
584 break;
585 }
586 }
587
588 /* Process the global rc file if it exists and the user hasn't explicitly
589 * requested not to via "-n". */
590 if (!skip_sys_rc)
591 {
592 do
593 {
595 break;
596
597 buf_printf(buf, "%s/neomuttrc", SYSCONFDIR);
598 if (access(buf_string(buf), F_OK) == 0)
599 break;
600
601 buf_printf(buf, "%s/Muttrc", SYSCONFDIR);
602 if (access(buf_string(buf), F_OK) == 0)
603 break;
604
605 buf_printf(buf, "%s/neomuttrc", PKGDATADIR);
606 if (access(buf_string(buf), F_OK) == 0)
607 break;
608
609 buf_printf(buf, "%s/Muttrc", PKGDATADIR);
610 } while (false);
611
612 if (access(buf_string(buf), F_OK) == 0)
613 {
614 if (source_rc(buf_string(buf), pc, pe) != 0)
615 {
616 mutt_error("%s", buf_string(pe->message));
617 need_pause = true; // TEST11: neomutt (error in /etc/neomuttrc)
618 }
619 }
620 }
621
622 /* Read the user's initialization file. */
623 ARRAY_FOREACH(cp, user_files)
624 {
625 if (*cp)
626 {
627 if (source_rc(*cp, pc, pe) != 0)
628 {
629 mutt_error("%s", buf_string(pe->message));
630 need_pause = true; // TEST12: neomutt (error in ~/.neomuttrc)
631 }
632 }
633 }
634
635 if (execute_commands(commands) != 0)
636 need_pause = true; // TEST13: neomutt -e broken
637
638 if (!get_hostname(cs))
639 goto done;
640
641 /* The command line overrides the config */
642 if (!buf_is_empty(dlevel))
643 cs_str_reset(cs, "debug_level", NULL);
644 if (!buf_is_empty(dfile))
645 cs_str_reset(cs, "debug_file", NULL);
646
647 if (mutt_log_start() < 0)
648 {
649 mutt_perror("log file");
650 goto done;
651 }
652
653 if (need_pause && OptGui)
654 {
656 if (mutt_any_key_to_continue(NULL) == 'q')
657 goto done; // TEST14: neomutt -e broken (press 'q')
658 }
659
660 const char *const c_tmp_dir = cs_subset_path(NeoMutt->sub, "tmp_dir");
661 if (mutt_file_mkdir(c_tmp_dir, S_IRWXU) < 0)
662 {
663 mutt_error(_("Can't create %s: %s"), c_tmp_dir, strerror(errno));
664 goto done;
665 }
666
667 rc = 0;
668
669done:
671 parse_error_free(&pe);
672 buf_pool_release(&buf);
673 return rc;
674}
675
683static int get_elem_queries(struct StringArray *queries, struct HashElemArray *hea)
684{
685 int rc = 0;
686 const char **cp = NULL;
687 ARRAY_FOREACH(cp, queries)
688 {
689 struct HashElem *he = cs_subset_lookup(NeoMutt->sub, *cp);
690 if (!he)
691 {
692 mutt_warning(_("Unknown option %s"), *cp);
693 rc = 1;
694 continue;
695 }
696
697 if (he->type & D_INTERNAL_DEPRECATED)
698 {
699 mutt_warning(_("Option %s is deprecated"), *cp);
700 rc = 1;
701 continue;
702 }
703
704 ARRAY_ADD(hea, he);
705 }
706
707 return rc; // TEST16: neomutt -Q charset
708}
709
713static void init_keys(void)
714{
715 km_init();
716
717 struct SubMenu *sm_generic = generic_init_keys();
718
719 alias_init_keys(sm_generic);
720 attach_init_keys(sm_generic);
721#ifdef USE_AUTOCRYPT
722 autocrypt_init_keys(sm_generic);
723#endif
724 browser_init_keys(sm_generic);
725 compose_init_keys(sm_generic);
726 editor_init_keys(sm_generic);
727 sidebar_init_keys(sm_generic);
728 index_init_keys(sm_generic);
729 pager_init_keys(sm_generic);
730 pgp_init_keys(sm_generic);
731 postponed_init_keys(sm_generic);
732
733 km_sort();
734}
735
741static int start_curses(void)
742{
743 /* should come before initscr() so that ncurses 4.2 doesn't try to install
744 * its own SIGWINCH handler */
746
747 if (!initscr())
748 {
749 mutt_error(_("Error initializing terminal"));
750 return 1;
751 }
752
753 colors_init();
754 keypad(stdscr, true);
755 cbreak();
756 noecho();
757 nonl();
758 typeahead(-1); /* simulate smooth scrolling */
759 meta(stdscr, true);
761 /* Now that curses is set up, we drop back to normal screen mode.
762 * This simplifies displaying error messages to the user.
763 * The first call to refresh() will swap us back to curses screen mode. */
764 endwin();
765 return 0;
766}
767
775static bool get_user_info(struct ConfigSet *cs)
776{
777 const char *shell = mutt_str_getenv("SHELL");
778
779 /* Get some information about the user */
780 struct passwd *pw = getpwuid(getuid());
781 if (pw)
782 {
783 if (!NeoMutt->username)
784 NeoMutt->username = mutt_str_dup(pw->pw_name);
785 if (!NeoMutt->home_dir)
786 NeoMutt->home_dir = mutt_str_dup(pw->pw_dir);
787 if (!shell)
788 shell = pw->pw_shell;
789 }
790
791 if (!NeoMutt->username)
792 {
793 mutt_error(_("unable to determine username"));
794 return false; // TEST05: neomutt (unset $USER, delete user from /etc/passwd)
795 }
796
797 if (!NeoMutt->home_dir)
798 {
799 mutt_error(_("unable to determine home directory"));
800 return false; // TEST06: neomutt (unset $HOME, delete user from /etc/passwd)
801 }
802
803 if (shell)
804 config_str_set_initial(cs, "shell", shell);
805
806 return true;
807}
808
816static void log_translation(void)
817{
818 const char *header = ""; // Do not merge these two lines
819 header = _(header); // otherwise the .po files will end up badly ordered
820 const char *label = "Language:"; // the start of the lookup/needle
821 const char *lang = mutt_istr_find(header, label);
822 int len = 64;
823 if (lang)
824 {
825 lang += strlen(label); // skip label
826 SKIPWS(lang);
827 char *nl = strchr(lang, '\n');
828 if (nl)
829 len = (nl - lang);
830 }
831 else
832 {
833 lang = "NONE";
834 }
835
836 mutt_debug(LL_DEBUG1, "Translation: %.*s\n", len, lang);
837}
838
842static void log_gui(void)
843{
844 const char *term = mutt_str_getenv("TERM");
845 const char *color_term = mutt_str_getenv("COLORTERM");
846 bool true_color = false;
847#ifdef NEOMUTT_DIRECT_COLORS
848 true_color = true;
849#endif
850
851 mutt_debug(LL_DEBUG1, "GUI:\n");
852 mutt_debug(LL_DEBUG1, " Curses: %s\n", curses_version());
853 mutt_debug(LL_DEBUG1, " COLORS=%d\n", COLORS);
854 mutt_debug(LL_DEBUG1, " COLOR_PAIRS=%d\n", COLOR_PAIRS);
855 mutt_debug(LL_DEBUG1, " TERM=%s\n", NONULL(term));
856 mutt_debug(LL_DEBUG1, " COLORTERM=%s\n", NONULL(color_term));
857 mutt_debug(LL_DEBUG1, " True color support: %s\n", true_color ? "YES" : "NO");
858 mutt_debug(LL_DEBUG1, " Screen: %dx%d\n", RootWindow->state.cols,
859 RootWindow->state.rows);
860}
861
866{
867 static time_t last_run = 0;
868
869 if (nc->event_type != NT_TIMEOUT)
870 return 0;
871
872 const short c_timeout = cs_subset_number(NeoMutt->sub, "timeout");
873 if (c_timeout <= 0)
874 goto done;
875
876 time_t now = mutt_date_now();
877 if (now < (last_run + c_timeout))
878 goto done;
879
880 // Limit hook to running under the Index or Pager
882 struct MuttWindow *dlg = dialog_find(focus);
883 if (!dlg || (dlg->type != WT_DLG_INDEX))
884 goto done;
885
886 last_run = now;
888
889done:
890 mutt_debug(LL_DEBUG5, "timeout done\n");
891 return 0;
892}
893
899static bool show_help(struct CliHelp *help)
900{
901 if (!help->is_set)
902 return true;
903
905
906 const bool tty = isatty(STDOUT_FILENO);
907
908 if (help->help)
909 {
910 show_cli(help->mode, tty);
911 }
912 else if (help->license)
913 {
915 }
916 else
917 {
918 print_version(stdout, tty);
919 }
920
921 return false; // Stop
922}
923
930static bool init_logging(struct CliShared *shared, struct ConfigSet *cs)
931{
932 if (!shared->is_set)
933 return true;
934
935 if (!buf_is_empty(&shared->log_file))
936 config_str_set_initial(cs, "debug_file", buf_string(&shared->log_file));
937
938 if (!buf_is_empty(&shared->log_level))
939 {
940 const char *dlevel = buf_string(&shared->log_level);
941 short num = 0;
942 if (!mutt_str_atos_full(dlevel, &num) || (num < LL_MESSAGE) || (num >= LL_MAX))
943 {
944 mutt_error(_("Error: value '%s' is invalid for -d"), dlevel);
945 return false;
946 }
947
948 config_str_set_initial(cs, "debug_level", dlevel);
949 }
950
951 return true;
952}
953
959static void init_nntp(struct Buffer *server, struct ConfigSet *cs)
960{
961 const char *cli_nntp = NULL;
962 if (!buf_is_empty(server))
963 cli_nntp = buf_string(server);
964
965 /* "$news_server" precedence: command line, config file, environment, system file */
966 if (cli_nntp)
967 cli_nntp = cs_subset_string(NeoMutt->sub, "news_server");
968
969 if (!cli_nntp)
970 cli_nntp = mutt_str_getenv("NNTPSERVER");
971
972 if (!cli_nntp)
973 {
974 char buf[1024] = { 0 };
975 cli_nntp = mutt_file_read_keyword(SYSCONFDIR "/nntpserver", buf, sizeof(buf));
976 }
977
978 if (cli_nntp)
979 config_str_set_initial(cs, "news_server", cli_nntp);
980}
981
988static bool dump_info(struct CliInfo *ci, struct ConfigSet *cs)
989{
990 if (!ci->is_set)
991 return true;
992
993 if (ci->dump_config || !ARRAY_EMPTY(&ci->queries))
994 {
995 const bool tty = isatty(STDOUT_FILENO);
996
998 if (tty)
999 cdflags |= CS_DUMP_LINK_DOCS;
1000 if (ci->hide_sensitive)
1001 cdflags |= CS_DUMP_HIDE_SENSITIVE;
1002 if (ci->show_help)
1003 cdflags |= CS_DUMP_SHOW_DOCS;
1004
1005 struct HashElemArray hea = ARRAY_HEAD_INITIALIZER;
1006 if (ci->dump_config)
1007 {
1009 hea = get_elem_list(cs, gel_flags);
1010 }
1011 else
1012 {
1013 get_elem_queries(&ci->queries, &hea);
1014 }
1015
1016 dump_config(cs, &hea, cdflags, stdout);
1017 ARRAY_FREE(&hea);
1018 }
1019 else if (!ARRAY_EMPTY(&ci->alias_queries))
1020 {
1021 const char **cp = NULL;
1023 {
1024 struct AddressList *al = alias_lookup(*cp);
1025 if (al)
1026 {
1027 /* output in machine-readable form */
1028 mutt_addrlist_to_intl(al, NULL);
1029 struct Buffer *buf = buf_pool_get();
1030 mutt_addrlist_write(al, buf, false);
1031 printf("%s\n", buf_string(buf));
1032 buf_pool_release(&buf);
1033 }
1034 else
1035 {
1036 printf("%s\n", NONULL(*cp)); // TEST19: neomutt -A unknown
1037 }
1038 }
1039 }
1040
1041 return false; // Stop
1042}
1043
1052int main(int argc, char *argv[], char *envp[])
1053{
1054 struct Email *e = NULL;
1055 SendFlags sendflags = SEND_NO_FLAGS;
1056 int rc = 1;
1057 bool repeat_error = false;
1058 struct Buffer *expanded_infile = buf_pool_get();
1059 struct Buffer *tempfile = buf_pool_get();
1060 struct ConfigSet *cs = NULL;
1061 struct CommandLine *cli = command_line_new();
1062
1064
1065 /* sanity check against stupid administrators */
1066 if (getegid() != getgid())
1067 {
1068 mutt_error("%s: I don't want to run with privileges!", (argc != 0) ? argv[0] : "neomutt");
1069 goto main_exit; // TEST01: neomutt (as root, chgrp mail neomutt; chmod +s neomutt)
1070 }
1071
1072 OptGui = true;
1073
1074 NeoMutt = neomutt_new();
1075 if (!neomutt_init(NeoMutt, envp, Modules))
1076 goto main_curses;
1077
1078 cli_parse(argc, argv, cli);
1079
1080 if (!show_help(&cli->help))
1081 goto main_ok;
1082
1083 init_keys();
1084
1085#ifdef USE_DEBUG_NOTIFY
1087#endif
1088
1089 cs = NeoMutt->sub->cs;
1090 if (!get_user_info(cs))
1091 goto main_exit;
1092
1093 if (!init_logging(&cli->shared, cs))
1094 goto main_exit;
1095
1096 mutt_log_prep();
1099
1100 /* Check for a batch send. */
1101 if (!isatty(STDIN_FILENO) || !ARRAY_EMPTY(&cli->info.queries) ||
1103 {
1104 OptGui = false;
1105 sendflags |= SEND_BATCH;
1108 }
1109
1110 /* Check to make sure stdout is available in curses mode. */
1111 if (OptGui && !isatty(STDOUT_FILENO))
1112 goto main_curses;
1113
1114 /* This must come before mutt_init() because curses needs to be started
1115 * before calling the init_pair() function to set the color scheme. */
1116 if (OptGui)
1117 {
1118 int crc = start_curses();
1119 if (crc != 0)
1120 goto main_curses; // TEST08: can't test -- fake term?
1121 }
1122
1123 /* Always create the mutt_windows because batch mode has some shared code
1124 * paths that end up referencing them. */
1125 rootwin_new();
1126
1127 if (OptGui)
1128 {
1129 /* check whether terminal status is supported (must follow curses init) */
1132 log_gui();
1133 }
1134
1135 menu_init();
1136 sb_init();
1137
1138 /* set defaults and read init files */
1139 int rc2 = mutt_init(cs, &cli->shared.log_level, &cli->shared.log_file,
1141 &cli->shared.commands);
1142 if (rc2 != 0)
1143 goto main_curses;
1144
1147
1148#ifdef USE_NOTMUCH
1149 const bool c_virtual_spool_file = cs_subset_bool(NeoMutt->sub, "virtual_spool_file");
1150 if (c_virtual_spool_file)
1151 {
1152 /* Find the first virtual folder and open it */
1153 struct MailboxArray ma = neomutt_mailboxes_get(NeoMutt, MUTT_NOTMUCH);
1154 struct Mailbox **mp = ARRAY_FIRST(&ma);
1155 if (mp)
1156 cs_str_string_set(cs, "spool_file", mailbox_path(*mp), NULL);
1157 ARRAY_FREE(&ma); // Clean up the ARRAY, but not the Mailboxes
1158 }
1159#endif
1160
1162
1163 init_nntp(&cli->tui.nntp_server, cs);
1164
1165 /* Initialize crypto backends. */
1166 crypt_init();
1167
1168 if (!buf_is_empty(&cli->shared.mbox_type) &&
1169 !config_str_set_initial(cs, "mbox_type", buf_string(&cli->shared.mbox_type)))
1170 {
1171 goto main_curses;
1172 }
1173
1174 if (!dump_info(&cli->info, cs))
1175 goto main_ok;
1176
1177 if (OptGui)
1178 {
1180 clear();
1184 }
1185
1186#ifdef USE_AUTOCRYPT
1187 /* Initialize autocrypt after curses messages are working,
1188 * because of the initial account setup screens. */
1189 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
1190 if (c_autocrypt)
1191 (void) mutt_autocrypt_init(!(sendflags & SEND_BATCH));
1192#endif
1193
1194 /* Create the `$folder` directory if it doesn't exist. */
1195 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
1196 if (OptGui && c_folder)
1197 {
1198 struct stat st = { 0 };
1199 struct Buffer *fpath = buf_pool_get();
1200
1201 buf_strcpy(fpath, c_folder);
1202 expand_path(fpath, false);
1203 bool skip = false;
1204 /* we're not connected yet - skip mail folder creation */
1205 skip |= (imap_path_probe(buf_string(fpath), NULL) == MUTT_IMAP);
1206 skip |= (pop_path_probe(buf_string(fpath), NULL) == MUTT_POP);
1207 skip |= (nntp_path_probe(buf_string(fpath), NULL) == MUTT_NNTP);
1208 if (!skip && (stat(buf_string(fpath), &st) == -1) && (errno == ENOENT))
1209 {
1210 char msg2[256] = { 0 };
1211 snprintf(msg2, sizeof(msg2), _("%s does not exist. Create it?"), c_folder);
1212 if (query_yesorno(msg2, MUTT_YES) == MUTT_YES)
1213 {
1214 if ((mkdir(buf_string(fpath), 0700) == -1) && (errno != EEXIST))
1215 mutt_error(_("Can't create %s: %s"), c_folder, strerror(errno)); // TEST21: neomutt -n -F /dev/null (and ~/Mail doesn't exist)
1216 }
1217 }
1218 buf_pool_release(&fpath);
1219 }
1220
1221 StartupComplete = true;
1222
1226
1227 if (cli->tui.start_postponed)
1228 {
1229 if (OptGui)
1230 mutt_flushinp();
1231 if (mutt_send_message(SEND_POSTPONED, NULL, NULL, NULL, NULL, NeoMutt->sub) == 0)
1232 rc = 0;
1233 // TEST23: neomutt -p (postponed message, cancel)
1234 // TEST24: neomutt -p (no postponed message)
1236 repeat_error = true;
1237 goto main_curses;
1238 }
1239 else if (cli->send.is_set)
1240 {
1241 FILE *fp_in = NULL;
1242 FILE *fp_out = NULL;
1243 const char *infile = NULL;
1244 char *bodytext = NULL;
1245 const char *bodyfile = NULL;
1246 int rv = 0;
1247
1248 if (OptGui)
1249 mutt_flushinp();
1250
1251 e = email_new();
1252 e->env = mutt_env_new();
1253
1254 const char **cp = NULL;
1255 ARRAY_FOREACH(cp, &cli->send.bcc_list)
1256 {
1257 mutt_addrlist_parse(&e->env->bcc, *cp);
1258 }
1259
1260 ARRAY_FOREACH(cp, &cli->send.cc_list)
1261 {
1262 mutt_addrlist_parse(&e->env->cc, *cp);
1263 }
1264
1265 ARRAY_FOREACH(cp, &cli->send.addresses)
1266 {
1267 if (url_check_scheme(*cp) == U_MAILTO)
1268 {
1269 if (!mutt_parse_mailto(e->env, &bodytext, *cp))
1270 {
1271 mutt_error(_("Failed to parse mailto: link"));
1272 email_free(&e);
1273 goto main_curses; // TEST25: neomutt mailto:?
1274 }
1275 }
1276 else
1277 {
1278 mutt_addrlist_parse(&e->env->to, *cp);
1279 }
1280 }
1281
1282 const bool c_auto_edit = cs_subset_bool(NeoMutt->sub, "auto_edit");
1283 if (buf_is_empty(&cli->send.draft_file) && c_auto_edit &&
1284 TAILQ_EMPTY(&e->env->to) && TAILQ_EMPTY(&e->env->cc))
1285 {
1286 mutt_error(_("No recipients specified"));
1287 email_free(&e);
1288 goto main_curses; // TEST26: neomutt -s test (with auto_edit=yes)
1289 }
1290
1291 if (!buf_is_empty(&cli->send.subject))
1292 {
1293 /* prevent header injection */
1296 }
1297
1298 if (!buf_is_empty(&cli->send.draft_file))
1299 {
1300 infile = buf_string(&cli->send.draft_file);
1301 }
1302 else if (!buf_is_empty(&cli->send.include_file))
1303 {
1304 infile = buf_string(&cli->send.include_file);
1305 }
1306 else
1307 {
1308 cli->send.edit_infile = false;
1309 }
1310
1311 if (infile || bodytext)
1312 {
1313 /* Prepare fp_in and expanded_infile. */
1314 if (infile)
1315 {
1316 if (mutt_str_equal("-", infile))
1317 {
1318 if (cli->send.edit_infile)
1319 {
1320 mutt_error(_("Can't use -E flag with stdin"));
1321 email_free(&e);
1322 goto main_curses; // TEST27: neomutt -E -H -
1323 }
1324 fp_in = stdin;
1325 }
1326 else
1327 {
1328 buf_strcpy(expanded_infile, infile);
1329 expand_path(expanded_infile, false);
1330 fp_in = mutt_file_fopen(buf_string(expanded_infile), "r");
1331 if (!fp_in)
1332 {
1333 mutt_perror("%s", buf_string(expanded_infile));
1334 email_free(&e);
1335 goto main_curses; // TEST28: neomutt -E -H missing
1336 }
1337 }
1338 }
1339
1340 if (cli->send.edit_infile)
1341 {
1342 /* If editing the infile, keep it around afterwards so
1343 * it doesn't get unlinked, and we can rebuild the draft_file */
1344 sendflags |= SEND_NO_FREE_HEADER;
1345 }
1346 else
1347 {
1348 /* Copy input to a tempfile, and re-point fp_in to the tempfile.
1349 * Note: stdin is always copied to a tempfile, ensuring draft_file
1350 * can stat and get the correct st_size below. */
1351 buf_mktemp_draft(tempfile);
1352
1353 fp_out = mutt_file_fopen(buf_string(tempfile), "w");
1354 if (!fp_out)
1355 {
1356 mutt_file_fclose(&fp_in);
1357 mutt_perror("%s", buf_string(tempfile));
1358 email_free(&e);
1359 goto main_curses; // TEST29: neomutt -H existing-file (where tmpdir=/path/to/FILE blocking tmpdir)
1360 }
1361 if (fp_in)
1362 {
1363 mutt_file_copy_stream(fp_in, fp_out);
1364 if (fp_in == stdin)
1365 sendflags |= SEND_CONSUMED_STDIN;
1366 else
1367 mutt_file_fclose(&fp_in);
1368 }
1369 else if (bodytext)
1370 {
1371 fputs(bodytext, fp_out);
1372 }
1373 mutt_file_fclose(&fp_out);
1374
1375 fp_in = mutt_file_fopen(buf_string(tempfile), "r");
1376 if (!fp_in)
1377 {
1378 mutt_perror("%s", buf_string(tempfile));
1379 email_free(&e);
1380 goto main_curses; // TEST30: can't test
1381 }
1382 }
1383
1384 /* Parse the draft_file into the full Email/Body structure.
1385 * Set SEND_DRAFT_FILE so mutt_send_message doesn't overwrite
1386 * our e->body. */
1387 if (!buf_is_empty(&cli->send.draft_file))
1388 {
1389 struct Envelope *opts_env = e->env;
1390 struct stat st = { 0 };
1391
1392 sendflags |= SEND_DRAFT_FILE;
1393
1394 /* Set up a tmp Email with just enough information so that
1395 * mutt_prepare_template() can parse the message in fp_in. */
1396 struct Email *e_tmp = email_new();
1397 e_tmp->offset = 0;
1398 e_tmp->body = mutt_body_new();
1399 if (fstat(fileno(fp_in), &st) != 0)
1400 {
1401 mutt_perror("%s", buf_string(&cli->send.draft_file));
1402 email_free(&e);
1403 email_free(&e_tmp);
1404 goto main_curses; // TEST31: can't test
1405 }
1406 e_tmp->body->length = st.st_size;
1407
1408 if (mutt_prepare_template(fp_in, NULL, e, e_tmp, false) < 0)
1409 {
1410 mutt_error(_("Can't parse message template: %s"),
1411 buf_string(&cli->send.draft_file));
1412 email_free(&e);
1413 email_free(&e_tmp);
1414 goto main_curses;
1415 }
1416
1417 /* Scan for neomutt header to set `$resume_draft_files` */
1418 struct ListNode *tmp = NULL;
1419 const bool c_resume_edited_draft_files = cs_subset_bool(NeoMutt->sub, "resume_edited_draft_files");
1420 struct ListNode *np = NULL;
1421 STAILQ_FOREACH_SAFE(np, &e->env->userhdrs, entries, tmp)
1422 {
1423 if (mutt_istr_startswith(np->data, "X-Mutt-Resume-Draft:"))
1424 {
1425 if (c_resume_edited_draft_files)
1426 cs_str_native_set(cs, "resume_draft_files", true, NULL);
1427
1428 STAILQ_REMOVE(&e->env->userhdrs, np, ListNode, entries);
1429 FREE(&np->data);
1430 FREE(&np);
1431 }
1432 }
1433
1434 mutt_addrlist_copy(&e->env->to, &opts_env->to, false);
1435 mutt_addrlist_copy(&e->env->cc, &opts_env->cc, false);
1436 mutt_addrlist_copy(&e->env->bcc, &opts_env->bcc, false);
1437 if (opts_env->subject)
1438 mutt_env_set_subject(e->env, opts_env->subject);
1439
1440 mutt_env_free(&opts_env);
1441 email_free(&e_tmp);
1442 }
1443 else if (cli->send.edit_infile)
1444 {
1445 /* Editing the include_file: pass it directly in.
1446 * Note that SEND_NO_FREE_HEADER is set above so it isn't unlinked. */
1447 bodyfile = buf_string(expanded_infile);
1448 }
1449 else
1450 {
1451 // For bodytext and unedited include_file: use the tempfile.
1452 bodyfile = buf_string(tempfile);
1453 }
1454
1455 mutt_file_fclose(&fp_in);
1456 }
1457
1458 FREE(&bodytext);
1459
1460 if (!ARRAY_EMPTY(&cli->send.attach))
1461 {
1462 struct Body *b = e->body;
1463
1464 while (b && b->next)
1465 b = b->next;
1466
1467 ARRAY_FOREACH(cp, &cli->send.attach)
1468 {
1469 if (b)
1470 {
1472 b = b->next;
1473 }
1474 else
1475 {
1477 e->body = b;
1478 }
1479 if (!b)
1480 {
1481 mutt_error(_("%s: unable to attach file"), *cp);
1482 email_free(&e);
1483 goto main_curses; // TEST32: neomutt john@example.com -a missing
1484 }
1485 }
1486 }
1487
1488 rv = mutt_send_message(sendflags, e, bodyfile, NULL, NULL, NeoMutt->sub);
1489 /* We WANT the "Mail sent." and any possible, later error */
1491 if (ErrorBufMessage)
1492 mutt_message("%s", ErrorBuf);
1493
1494 if (cli->send.edit_infile)
1495 {
1496 if (!buf_is_empty(&cli->send.draft_file))
1497 {
1498 if (truncate(buf_string(expanded_infile), 0) == -1)
1499 {
1500 mutt_perror("%s", buf_string(expanded_infile));
1501 email_free(&e);
1502 goto main_curses; // TEST33: neomutt -H read-only -s test john@example.com -E
1503 }
1504 fp_out = mutt_file_fopen(buf_string(expanded_infile), "a");
1505 if (!fp_out)
1506 {
1507 mutt_perror("%s", buf_string(expanded_infile));
1508 email_free(&e);
1509 goto main_curses; // TEST34: can't test
1510 }
1511
1512 /* If the message was sent or postponed, these will already
1513 * have been done. */
1514 if (rv < 0)
1515 {
1516 if (e->body->next)
1517 e->body = mutt_make_multipart(e->body);
1519 mutt_prepare_envelope(e->env, false, NeoMutt->sub);
1520 mutt_env_to_intl(e->env, NULL, NULL);
1521 }
1522
1523 const bool c_crypt_protected_headers_read = cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_read");
1525 c_crypt_protected_headers_read &&
1527 NeoMutt->sub);
1528 const bool c_resume_edited_draft_files = cs_subset_bool(NeoMutt->sub, "resume_edited_draft_files");
1529 if (c_resume_edited_draft_files)
1530 fprintf(fp_out, "X-Mutt-Resume-Draft: 1\n");
1531 fputc('\n', fp_out);
1532 if ((mutt_write_mime_body(e->body, fp_out, NeoMutt->sub) == -1))
1533 {
1534 mutt_file_fclose(&fp_out);
1535 email_free(&e);
1536 goto main_curses; // TEST35: can't test
1537 }
1538 mutt_file_fclose(&fp_out);
1539 }
1540
1541 email_free(&e);
1542 }
1543
1544 /* !edit_infile && draft_file will leave the tempfile around */
1545 if (!buf_is_empty(tempfile))
1546 unlink(buf_string(tempfile));
1547
1549
1550 if (rv != 0)
1551 goto main_curses; // TEST36: neomutt -H existing -s test john@example.com -E (cancel sending)
1552 }
1553 else if (sendflags & SEND_BATCH)
1554 {
1555 /* This guards against invoking `neomutt < /dev/null` and accidentally
1556 * sending an email due to a my-header or other setting. */
1557 mutt_error(_("No recipients specified"));
1558 goto main_curses;
1559 }
1560 else
1561 {
1562 struct Buffer *folder = &cli->tui.folder;
1563 bool explicit_folder = !buf_is_empty(folder);
1564
1565 if (cli->tui.start_new_mail)
1566 {
1567 const bool c_imap_passive = cs_subset_bool(NeoMutt->sub, "imap_passive");
1568 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", false, NULL);
1570 if (mutt_mailbox_check(NULL, csflags) == 0)
1571 {
1572 mutt_message(_("No mailbox with new mail"));
1573 repeat_error = true;
1574 goto main_curses; // TEST37: neomutt -Z (no new mail)
1575 }
1576 buf_reset(folder);
1577 mutt_mailbox_next(NULL, folder);
1578 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", c_imap_passive, NULL);
1579 }
1580 else if (cli->tui.start_nntp || cli->tui.start_browser)
1581 {
1582 if (cli->tui.start_nntp)
1583 {
1584 const char *const c_news_server = cs_subset_string(NeoMutt->sub, "news_server");
1585 OptNews = true;
1586 CurrentNewsSrv = nntp_select_server(NULL, c_news_server, false);
1587 if (!CurrentNewsSrv)
1588 goto main_curses; // TEST38: neomutt -G (unset news_server)
1589 }
1590 else if (ARRAY_EMPTY(&NeoMutt->accounts))
1591 {
1592 mutt_error(_("No incoming mailboxes defined"));
1593 goto main_curses; // TEST39: neomutt -n -F /dev/null -y
1594 }
1595 buf_reset(folder);
1596 dlg_browser(folder, MUTT_SEL_FOLDER | MUTT_SEL_MAILBOX, NULL, NULL, NULL);
1597 if (buf_is_empty(folder))
1598 {
1599 goto main_ok; // TEST40: neomutt -y (quit selection)
1600 }
1601 }
1602
1603 if (buf_is_empty(folder))
1604 {
1605 const char *const c_spool_file = cs_subset_string(NeoMutt->sub, "spool_file");
1606 if (c_spool_file)
1607 {
1608 // Check if `$spool_file` corresponds a mailboxes' description.
1609 struct Mailbox *m_desc = mailbox_find_name(c_spool_file);
1610 if (m_desc)
1611 buf_strcpy(folder, m_desc->realpath);
1612 else
1613 buf_strcpy(folder, c_spool_file);
1614 }
1615 else if (c_folder)
1616 {
1617 buf_strcpy(folder, c_folder);
1618 }
1619 /* else no folder */
1620 }
1621
1622 if (OptNews)
1623 {
1624 OptNews = false;
1625 buf_alloc(folder, PATH_MAX);
1626 nntp_expand_path(folder->data, folder->dsize, &CurrentNewsSrv->conn->account);
1627 }
1628 else
1629 {
1630 expand_path(folder, false);
1631 }
1632
1635
1636 if (cli->tui.start_any_mail || cli->tui.start_new_mail)
1637 {
1638 /* check to see if there are any messages in the folder */
1639 switch (mx_path_is_empty(folder))
1640 {
1641 case -1:
1642 mutt_perror("%s", buf_string(folder));
1643 goto main_curses; // TEST41: neomutt -z -f missing
1644 case 1:
1645 mutt_error(_("Mailbox is empty"));
1646 goto main_curses; // TEST42: neomutt -z -f /dev/null
1647 }
1648 }
1649
1650 struct Mailbox *m_cur = mailbox_find(buf_string(folder));
1651 // Take a copy of the name just in case the hook alters m_cur
1652 const char *name = m_cur ? mutt_str_dup(m_cur->name) : NULL;
1654 FREE(&name);
1656 mutt_debug(LL_NOTIFY, "NT_GLOBAL_STARTUP\n");
1658
1660 window_redraw(NULL);
1661
1662 repeat_error = true;
1663 struct Mailbox *m = mx_resolve(buf_string(folder));
1664 const bool c_read_only = cs_subset_bool(NeoMutt->sub, "read_only");
1665 if (!mx_mbox_open(m, (cli->tui.read_only || c_read_only) ? MUTT_READONLY : MUTT_OPEN_NO_FLAGS))
1666 {
1667 if (m->account)
1669
1670 mailbox_free(&m);
1671 mutt_error(_("Unable to open mailbox %s"), buf_string(folder));
1672 repeat_error = false;
1673 }
1674 if (m || !explicit_folder)
1675 {
1676 struct MuttWindow *dlg = index_pager_init();
1677 dialog_push(dlg);
1678
1680 m = dlg_index(dlg, m);
1682 mailbox_free(&m);
1683
1684 dialog_pop();
1685 mutt_window_free(&dlg);
1687 repeat_error = false;
1688 }
1690#ifdef USE_SASL_CYRUS
1692#endif
1693#ifdef USE_SASL_GNU
1695#endif
1696#ifdef USE_AUTOCRYPT
1698#endif
1699 // TEST43: neomutt (no change to mailbox)
1700 // TEST44: neomutt (change mailbox)
1701 }
1702
1703main_ok:
1704 rc = 0;
1705main_curses:
1706 mutt_endwin();
1707 /* Repeat the last message to the user */
1708 if (repeat_error && ErrorBufMessage)
1709 puts(ErrorBuf);
1710main_exit:
1711 if (NeoMutt && NeoMutt->sub)
1712 {
1716 }
1717
1718 buf_pool_release(&expanded_infile);
1719 buf_pool_release(&tempfile);
1722 if (NeoMutt)
1726 menu_cleanup();
1727 crypt_cleanup();
1729 command_line_free(&cli);
1730
1732
1733 sb_cleanup();
1734
1736
1738 FREE(&LastFolder);
1740
1742
1744
1745 lua_cleanup();
1746 km_cleanup();
1754 mutt_log_stop();
1755 return rc;
1756}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition address.c:774
size_t mutt_addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display)
Write an Address to a buffer.
Definition address.c:1215
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:1302
Email Address Handling.
const struct Module ModuleAddress
Module for the Address library.
Definition module.c:90
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:108
struct AddressList * alias_lookup(const char *name)
Find an Alias.
Definition alias.c:273
#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_keys(struct SubMenu *sm_generic)
Initialise the Attach Keybindings - Implements ::init_keys_api.
Definition functions.c:128
GUI display the mailboxes in a side panel.
const struct Module ModuleAttach
Module for the Attach library.
Definition module.c:108
void autocrypt_init_keys(struct SubMenu *sm_generic)
Initialise the Autocrypt Keybindings - Implements ::init_keys_api.
Definition functions.c:77
Autocrypt end-to-end encryption.
const struct Module ModuleAutocrypt
Module for the Autocrypt library.
Definition module.c:79
void mutt_autocrypt_cleanup(void)
Shutdown Autocrypt.
Definition autocrypt.c:133
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition autocrypt.c:103
const struct Module ModuleBcache
Module for the Bcache library.
Definition module.c:62
void browser_init_keys(struct SubMenu *sm_generic)
Initialise the Browser Keybindings - Implements ::init_keys_api.
Definition functions.c:130
Select a Mailbox from a list.
#define MUTT_SEL_MAILBOX
Select a mailbox.
Definition lib.h:59
#define MUTT_SEL_FOLDER
Select a local directory.
Definition lib.h:61
const struct Module ModuleBrowser
Module for the Browser library.
Definition module.c:73
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:148
Color and attribute parsing.
const struct Module ModuleColor
Module for the Color library.
Definition module.c:62
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:53
@ CMD_MY_HEADER
:my-header
Definition command.h:97
@ CMD_STARTUP_HOOK
:startup-hook
Definition command.h:115
@ CMD_NONE
No Command.
Definition command.h:59
CommandResult
Error codes for command_t parse functions.
Definition command.h:37
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:38
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:39
const struct Command * command_find_by_id(const struct CommandArray *ca, enum CommandId id)
Find a NeoMutt Command by its CommandId.
Definition commands.c:146
NeoMutt Commands.
const struct Module ModuleCommands
Module for the Commands library.
Definition module.c:72
const struct Module ModuleComplete
Module for the Complete library.
Definition module.c:62
const struct Module ModuleCompmbox
Module for the Compmbox library.
Definition module.c:72
void compose_init_keys(struct SubMenu *sm_generic)
Initialise the Compose Keybindings - Implements ::init_keys_api.
Definition functions.c:211
GUI editor for an email's headers.
const struct Module ModuleCompose
Module for the Compose library.
Definition module.c:73
const struct Module ModuleCompress
Module for the Compress library.
Definition module.c:62
bool dump_config(struct ConfigSet *cs, struct HashElemArray *hea, ConfigDumpFlags flags, FILE *fp)
Write all the config to a file.
Definition dump.c:198
#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:99
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:11
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:102
const struct Module ModuleConvert
Module for the Convert library.
Definition module.c:62
void account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition account.c:94
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:213
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition mailbox.h:50
@ MUTT_POP
'POP3' Mailbox type
Definition mailbox.h:51
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition mailbox.h:48
@ MUTT_IMAP
'IMAP' Mailbox type
Definition mailbox.h:49
const struct Module ModuleCore
Module for the Core library.
Definition module.c:63
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
Definition crypt.c:1100
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:173
void mutt_endwin(void)
Shutdown curses.
Definition curs_lib.c:151
Convenience wrapper for the debug headers.
int debug_all_observer(struct NotifyCallback *nc)
Debug observer for all notifications.
Definition notify.c:237
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:1456
void editor_init_keys(struct SubMenu *sm_generic)
Initialise the Editor Keybindings - Implements ::init_keys_api.
Definition functions.c:131
Edit a string.
const struct Module ModuleEditor
Module for the Editor library.
Definition module.c:62
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
Structs that make up an email.
const struct Module ModuleEmail
Module for the Email library.
Definition module.c:132
bool mutt_parse_mailto(struct Envelope *env, char **body, const char *src)
Parse a mailto:// url.
Definition parse.c:1762
void mutt_filter_commandline_header_value(char *header)
Sanitise characters in a header value.
Definition parse.c:92
const struct Module ModuleEnvelope
Module for the Envelope library.
Definition module.c:62
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:350
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
void mutt_delete_hooks(enum CommandId id)
Delete matching hooks.
Definition parse.c:1019
const struct Module ModuleExpando
Module for the Expando library.
Definition module.c:73
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:77
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:224
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:678
char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen)
Read a keyword from a file.
Definition file.c:1298
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
Definition file.c:844
#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:73
const struct Module ModuleParse
Module for the Parse library.
Definition module.c:62
const struct Module ModuleMaildir
Module for the Maildir library.
Definition module.c:80
const struct Module ModulePostpone
Module for the Postpone library.
Definition module.c:62
const struct Module ModuleSidebar
Module for the Sidebar library.
Definition module.c:83
const struct Module ModuleMh
Module for the Mh library.
Definition module.c:73
const struct Module ModuleLua
Module for the Lua library.
Definition module.c:72
const struct Module ModulePager
Module for the Pager library.
Definition module.c:73
const struct Module ModuleGui
Module for the Gui library.
Definition module.c:73
const struct Module ModuleProgress
Module for the Progress library.
Definition module.c:73
const struct Module ModuleMenu
Module for the Menu library.
Definition module.c:73
static const struct Module * Modules[]
All the library Modules.
Definition address.c:32
const struct Module ModuleNcrypt
Module for the Ncrypt library.
Definition module.c:92
const struct Module ModuleMutt
Module for the Mutt library.
Definition module.c:63
const struct Module ModuleHcache
Module for the Hcache library.
Definition module.c:82
const struct Module ModuleSend
Module for the Send library.
Definition module.c:87
const struct Module ModuleQuestion
Module for the Question library.
Definition module.c:62
const struct Module ModuleImap
Module for the Imap library.
Definition module.c:90
const struct Module ModuleMain
Module for the Main library.
Definition module.c:48
const struct Module ModuleStore
Module for the Store library.
Definition module.c:63
const struct Module ModuleMbox
Module for the Mbox library.
Definition module.c:73
const struct Module ModulePattern
Module for the Pattern library.
Definition module.c:73
const struct Module ModuleNntp
Module for the Nntp library.
Definition module.c:73
const struct Module ModuleHelpbar
Module for the Helpbar library.
Definition module.c:73
const struct Module ModuleHistory
Module for the History library.
Definition module.c:73
const struct Module ModuleNotmuch
Module for the Notmuch library.
Definition module.c:89
const struct Module ModuleKey
Module for the Key library.
Definition module.c:72
const struct Module ModuleIndex
Module for the Index library.
Definition module.c:87
const struct Module ModuleHooks
Module for the Hooks library.
Definition module.c:82
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition get.c:65
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:53
char * LastFolder
Previously selected mailbox.
Definition globals.c:39
char * ShortHostname
Short version of the hostname.
Definition globals.c:36
char ErrorBuf[1024]
Copy of the last error message.
Definition globals.c:34
bool ErrorBufMessage
true if the last message was an error
Definition globals.c:33
char * CurrentFolder
Currently selected mailbox.
Definition globals.c:38
bool OptGui
(pseudo) when the gui (and curses) are started
Definition globals.c:48
Global variables.
enum CommandResult parse_my_header(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
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:1118
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:384
#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:427
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:2787
enum MailboxType pop_path_probe(const char *path, const struct stat *st)
Is this a POP Mailbox?
Definition pop.c:1162
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox?
Definition imap.c:2546
int main_hist_observer(struct NotifyCallback *nc)
Notification that a Config Variable has change - Implements observer_t -.
Definition history.c:703
static int main_timeout_observer(struct NotifyCallback *nc)
Notification that a timeout has occurred - Implements observer_t -.
Definition main.c:865
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:195
Convenience wrapper for the gui headers.
Read/write command history from/to a file.
void mutt_hist_read_file(void)
Read the History from a file.
Definition history.c:594
void mutt_hist_init(void)
Create a set of empty History ring buffers.
Definition history.c:466
void mutt_hist_cleanup(void)
Free all the history lists.
Definition history.c:443
void exec_startup_shutdown_hook(enum CommandId id)
Execute any startup/shutdown hooks.
Definition exec.c:410
void exec_folder_hook(const char *path, const char *desc)
Perform a folder hook.
Definition exec.c:64
void exec_timeout_hook(void)
Execute any timeout hooks.
Definition exec.c:372
Hook Commands.
IMAP network mailbox.
void imap_logout_all(void)
Close all open connections.
Definition imap.c:667
void index_init_keys(struct SubMenu *sm_generic)
Initialise the Index Keybindings - Implements ::init_keys_api.
Definition functions.c:326
GUI manage the main index (list of emails)
void km_cleanup(void)
Free the key maps.
Definition init.c:200
void km_init(void)
Initialise all the menu keybindings.
Definition init.c:170
void km_sort(void)
Sort all the menu keybindings.
Definition init.c:192
void km_set_abort_key(void)
Parse the abort_key config string.
Definition init.c:232
Manage keymappings.
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:164
Integrated Lua scripting.
static char * find_cfg(const char *home, const char *xdg_cfg_home)
Find a config file.
Definition main.c:264
static char * getmailname(void)
Try to retrieve the FQDN from mailname files.
Definition main.c:311
static bool init_logging(struct CliShared *shared, struct ConfigSet *cs)
Initialise the Logging.
Definition main.c:930
static void log_translation(void)
Log the translation being used.
Definition main.c:816
static void log_gui(void)
Log info about the GUI.
Definition main.c:842
static void init_nntp(struct Buffer *server, struct ConfigSet *cs)
Initialise the NNTP config.
Definition main.c:959
static bool show_help(struct CliHelp *help)
Show the Help.
Definition main.c:899
static int start_curses(void)
Start the Curses UI.
Definition main.c:741
static bool dump_info(struct CliInfo *ci, struct ConfigSet *cs)
Show config info.
Definition main.c:988
static bool get_user_info(struct ConfigSet *cs)
Find the user's name, home and shell.
Definition main.c:775
void show_cli(enum HelpMode mode, bool use_color)
Show Instructions on how to run NeoMutt.
Definition usage.c:336
static bool get_hostname(struct ConfigSet *cs)
Find the Fully-Qualified Domain Name.
Definition main.c:344
static int get_elem_queries(struct StringArray *queries, struct HashElemArray *hea)
Lookup the HashElems for a set of queries.
Definition main.c:683
static int execute_commands(struct StringArray *sa)
Execute a set of NeoMutt commands.
Definition main.c:225
int main(int argc, char *argv[], char *envp[])
Start NeoMutt.
Definition main.c:1052
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:430
static void init_keys(void)
Initialise the Keybindings.
Definition main.c:713
#define countof(x)
Definition memory.h:49
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
GUI present the user with a selectable list.
void menu_init(void)
Initialise all the Menus.
Definition menu.c:81
void menu_cleanup(void)
Free the saved Menu searches.
Definition menu.c:72
struct Body * mutt_make_multipart(struct Body *b)
Create a multipart email.
Definition multipart.c:107
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:331
void log_queue_set_max_size(int size)
Set a upper limit for the queue length.
Definition logging.c:319
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
Definition logging.c:353
#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
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:808
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition string.c:731
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
Definition string.c:528
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.
@ XDG_CONFIG_DIRS
XDG system dir: /etc/xdg.
Definition mutt.h:68
void mutt_signal_init(void)
Initialise the signal handling.
int mutt_set_xdg_path(enum XdgType type, struct Buffer *buf)
Find an XDG path or its fallback.
Definition muttlib.c:828
#define PATH_MAX
Definition mutt.h:49
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 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:86
char * mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw)
Lookup a user's real name in /etc/passwd.
Definition muttlib.c:321
void expand_path(struct Buffer *buf, bool regex)
Create the canonical path.
Definition muttlib.c:122
Some miscellaneous functions.
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition mx.c:285
struct Mailbox * mx_resolve(const char *path_or_name)
Get a Mailbox from either a path or name.
Definition mx.c:1719
int mx_path_is_empty(struct Buffer *path)
Is the mailbox empty.
Definition mx.c:1254
API for mailboxes.
#define MUTT_READONLY
Open in read-only mode.
Definition mxapi.h:42
#define MUTT_MAILBOX_CHECK_IMMEDIATE
Don't postpone the actual checking.
Definition mxapi.h:52
#define MUTT_OPEN_NO_FLAGS
No flags are set.
Definition mxapi.h:39
uint8_t CheckStatsFlags
Flags for mutt_mailbox_check.
Definition mxapi.h:48
void pgp_init_keys(struct SubMenu *sm_generic)
Initialise the PGP Keybindings - Implements ::init_keys_api.
Definition functions.c:91
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:526
void neomutt_cleanup(struct NeoMutt *n)
Clean up NeoMutt and Modules.
Definition neomutt.c:405
bool neomutt_init(struct NeoMutt *n, char **envp, const struct Module **modules)
Initialise NeoMutt.
Definition neomutt.c:319
struct NeoMutt * neomutt_new(void)
Create the main NeoMutt object.
Definition neomutt.c:307
void neomutt_free(struct NeoMutt **ptr)
Free a NeoMutt.
Definition neomutt.c:418
@ NT_GLOBAL_STARTUP
NeoMutt is initialised.
Definition neomutt.h:70
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:555
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition nntp.c:74
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition newsrc.c:951
@ 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:321
GUI display a file/email/help in a viewport with paging.
Text parsing functions.
void parse_context_free(struct ParseContext **pptr)
Free a ParseContext.
Definition pcontext.c:48
struct ParseContext * parse_context_new(void)
Create a new ParseContext.
Definition pcontext.c:37
void parse_error_free(struct ParseError **pptr)
Free a ParseError.
Definition perror.c:50
struct ParseError * parse_error_new(void)
Create a new ParseError.
Definition perror.c:37
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
void buf_pool_cleanup(void)
Release the Buffer pool.
Definition pool.c:75
POP network mailbox.
void postponed_init_keys(struct SubMenu *sm_generic)
Initialise the Postponed Keybindings - Implements ::init_keys_api.
Definition functions.c:70
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:492
void mutt_prex_cleanup(void)
Cleanup heap memory allocated by compiled regexes.
Definition prex.c:342
@ 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:329
#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 ParseContext *pc, struct ParseError *pe)
Parse a line of user config.
Definition rc.c:45
void rootwin_cleanup(void)
Free all the default Windows.
Definition rootwin.c:209
struct MuttWindow * RootWindow
Parent of all Windows.
Definition rootwin.c:106
void rootwin_new(void)
Create the default Windows.
Definition rootwin.c:221
void mutt_sasl_cleanup(void)
Invoke when processing is complete.
Definition sasl.c:781
int mutt_write_mime_body(struct Body *b, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
Definition body.c:302
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:40
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:1500
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:2045
#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:613
void mutt_prepare_envelope(struct Envelope *env, bool final, struct ConfigSubset *sub)
Prepare an email header.
Definition sendlib.c:746
void sidebar_init_keys(struct SubMenu *sm_generic)
Initialise the Sidebar Keybindings - Implements ::init_keys_api.
Definition functions.c:87
GUI display the mailboxes in a side panel.
void sb_init(void)
Set up the Sidebar.
Definition sidebar.c:214
void sb_cleanup(void)
Clean up the Sidebar.
Definition sidebar.c:228
#define ASSERT(COND)
Definition signal2.h:59
int endwin(void)
void source_stack_cleanup(void)
Free memory from the stack used for the source command.
Definition source.c:274
int source_rc(const char *rcfile_path, struct ParseContext *pc, struct ParseError *pe)
Read an initialization file.
Definition source.c:67
#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 options
Definition objects.h:79
bool dump_changed
-DD Dump the changed config options
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:251
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:78
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:80
char * name
A short name for the Mailbox.
Definition mailbox.h:81
struct Account * account
Account that owns this Mailbox.
Definition mailbox.h:126
struct MuttWindow * focus
Focused Window.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Container for Accounts, Notifications.
Definition neomutt.h:41
struct AccountArray accounts
All Accounts.
Definition neomutt.h:50
struct CommandArray commands
NeoMutt commands.
Definition neomutt.h:53
struct Notify * notify_resize
Window resize notifications handler.
Definition neomutt.h:46
char ** env
Private copy of the environment variables.
Definition neomutt.h:58
char * username
User's login name.
Definition neomutt.h:57
char * home_dir
User's home directory.
Definition neomutt.h:56
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
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
Context for config parsing (history/backtrace)
Definition pcontext.h:34
Detailed error information from config parsing.
Definition perror.h:34
struct Buffer * message
Error message.
Definition perror.h:35
String list.
Definition slist.h:37
Collection of related functions.
Definition menu.h:68
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_draft(buf)
Definition tmp.h:34
#define D_SLIST_SEP_COLON
Slist items are colon-separated.
Definition types.h:112
#define D_INTERNAL_DEPRECATED
Config item shouldn't be used any more.
Definition types.h:88
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:701
bool print_version(FILE *fp, bool use_ansi)
Print system and compile info to a file.
Definition version.c:589
Display version and copyright about NeoMutt.