NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
29
81
87
88#define GNULIB_defined_setlocale
89
90#include "config.h"
91#include <errno.h>
92#include <limits.h>
93#include <pwd.h>
94#include <stdbool.h>
95#include <stdio.h>
96#include <string.h>
97#include <sys/stat.h>
98#include <sys/utsname.h>
99#include <time.h>
100#include <unistd.h>
101#include "mutt/lib.h"
102#include "address/lib.h"
103#include "config/lib.h"
104#include "email/lib.h"
105#include "core/lib.h"
106#include "alias/lib.h"
107#include "conn/lib.h"
108#include "gui/lib.h"
109#include "mutt.h"
110#include "attach/lib.h"
111#include "browser/lib.h"
112#include "cli/lib.h"
113#include "color/lib.h"
114#include "commands/lib.h"
115#include "compose/lib.h"
116#include "editor/lib.h"
117#include "history/lib.h"
118#include "hooks/lib.h"
119#include "imap/lib.h"
120#include "index/lib.h"
121#include "key/lib.h"
122#include "ncrypt/lib.h"
123#include "nntp/lib.h"
124#include "pager/lib.h"
125#include "parse/lib.h"
126#include "pop/lib.h"
127#include "postpone/lib.h"
128#include "question/lib.h"
129#include "send/lib.h"
130#include "sidebar/lib.h"
131#include "color/module_data.h"
132#include "external.h"
133#include "globals.h"
134#include "key/module_data.h"
135#include "mutt_logging.h"
136#include "mutt_mailbox.h"
137#include "muttlib.h"
138#include "mx.h"
139#include "nntp/adata.h" // IWYU pragma: keep
140#include "version.h"
141#ifdef ENABLE_NLS
142#include <libintl.h>
143#endif
144#ifdef USE_AUTOCRYPT
145#include "autocrypt/lib.h"
146#endif
147#if defined(USE_DEBUG_NOTIFY) || defined(USE_DEBUG_BACKTRACE)
148#include "debug/lib.h"
149#endif
150#ifndef DOMAIN
151#include "conn/lib.h"
152#endif
153
154bool StartupComplete = false;
155
156void show_cli(enum HelpMode mode, bool use_color);
157
158// clang-format off
159extern const struct Module ModuleMain;
160extern const struct Module ModuleAddress; extern const struct Module ModuleAlias; extern const struct Module ModuleAttach; extern const struct Module ModuleAutocrypt;
161extern const struct Module ModuleBcache; extern const struct Module ModuleBrowser; extern const struct Module ModuleColor; extern const struct Module ModuleCommands;
162extern const struct Module ModuleComplete; extern const struct Module ModuleCompmbox; extern const struct Module ModuleCompose; extern const struct Module ModuleCompress;
163extern const struct Module ModuleConfig; extern const struct Module ModuleConn; extern const struct Module ModuleConvert; extern const struct Module ModuleCore;
164extern const struct Module ModuleEditor; extern const struct Module ModuleEmail; extern const struct Module ModuleEnvelope; extern const struct Module ModuleExpando;
165extern const struct Module ModuleGui; extern const struct Module ModuleHcache; extern const struct Module ModuleHelpbar; extern const struct Module ModuleHistory;
166extern const struct Module ModuleHooks; extern const struct Module ModuleImap; extern const struct Module ModuleIndex; extern const struct Module ModuleKey;
167extern const struct Module ModuleLua; extern const struct Module ModuleMaildir; extern const struct Module ModuleMbox; extern const struct Module ModuleMenu;
168extern const struct Module ModuleMh; extern const struct Module ModuleMutt; extern const struct Module ModuleNcrypt; extern const struct Module ModuleNntp;
169extern const struct Module ModuleNotmuch; extern const struct Module ModulePager; extern const struct Module ModuleParse; extern const struct Module ModulePattern;
170extern const struct Module ModulePop; extern const struct Module ModulePostpone; extern const struct Module ModuleProgress; extern const struct Module ModuleQuestion;
171extern const struct Module ModuleSend; extern const struct Module ModuleSidebar; extern const struct Module ModuleStore;
172// clang-format on
173
177static const struct Module *Modules[] = {
178 // clang-format off
179 &ModuleMain, &ModuleGui, // These two have priority
188// clang-format on
189#ifdef USE_AUTOCRYPT
191#endif
192#ifdef USE_HCACHE_COMPRESSION
194#endif
195#ifdef USE_HCACHE
197#endif
198#ifdef USE_LUA
199 &ModuleLua,
200#endif
201#ifdef USE_NOTMUCH
203#endif
204#ifdef USE_HCACHE
206#endif
207 NULL,
208};
209
216static int execute_commands(struct StringArray *sa)
217{
218 int rc = 0;
219 struct Buffer *line = buf_pool_get();
220 struct ParseContext *pc = parse_context_new();
221 struct ParseError *pe = parse_error_new();
222
223 const char **cp = NULL;
224 ARRAY_FOREACH(cp, sa)
225 {
226 buf_strcpy(line, *cp);
227 enum CommandResult rc2 = parse_rc_line(line, pc, pe);
228 if (rc2 == MUTT_CMD_ERROR)
229 mutt_error(_("Error in command line: %s"), buf_string(pe->message));
230 else if (rc2 == MUTT_CMD_WARNING)
231 mutt_warning(_("Warning in command line: %s"), buf_string(pe->message));
232
233 if ((rc2 == MUTT_CMD_ERROR) || (rc2 == MUTT_CMD_WARNING))
234 {
235 rc = -1;
236 goto done;
237 }
238 }
239
240done:
241 buf_pool_release(&line);
243 parse_error_free(&pe);
244
245 return rc;
246}
247
255static char *find_cfg(const char *home, const char *xdg_cfg_home)
256{
257 const char *names[] = {
258 "neomuttrc",
259 "muttrc",
260 NULL,
261 };
262
263 const char *locations[][2] = {
264 { xdg_cfg_home, "neomutt/" },
265 { xdg_cfg_home, "mutt/" },
266 { home, ".neomutt/" },
267 { home, ".mutt/" },
268 { home, "." },
269 { NULL, NULL },
270 };
271
272 struct Buffer *buf = buf_pool_get();
273 char *cfg = NULL;
274
275 for (int i = 0; locations[i][0] || locations[i][1]; i++)
276 {
277 if (!locations[i][0])
278 continue;
279
280 for (int j = 0; names[j]; j++)
281 {
282 buf_printf(buf, "%s/%s%s", locations[i][0], locations[i][1], names[j]);
283 if (access(buf_string(buf), F_OK) == 0)
284 {
285 cfg = buf_strdup(buf);
286 goto done;
287 }
288 }
289 }
290
291done:
292 buf_pool_release(&buf);
293 return cfg;
294}
295
296#ifndef DOMAIN
302static char *getmailname(void)
303{
304 char *mailname = NULL;
305 static const char *mn_files[] = { "/etc/mailname", "/etc/mail/mailname" };
306
307 for (size_t i = 0; i < countof(mn_files); i++)
308 {
309 FILE *fp = mutt_file_fopen(mn_files[i], "r");
310 if (!fp)
311 continue;
312
313 size_t len = 0;
314 mailname = mutt_file_read_line(NULL, &len, fp, NULL, MUTT_RL_NONE);
315 mutt_file_fclose(&fp);
316 if (mailname && *mailname)
317 break;
318
319 FREE(&mailname);
320 }
321
322 return mailname;
323}
324#endif
325
335static bool get_hostname(struct ConfigSet *cs)
336{
337 const char *short_host = NULL;
338 struct utsname utsname = { 0 };
339
340 const char *const c_hostname = cs_subset_string(NeoMutt->sub, "hostname");
341 if (c_hostname)
342 {
343 short_host = c_hostname;
344 }
345 else
346 {
347 /* The call to uname() shouldn't fail, but if it does, the system is horribly
348 * broken, and the system's networking configuration is in an unreliable
349 * state. We should bail. */
350 if ((uname(&utsname)) == -1)
351 {
352 mutt_perror(_("unable to determine nodename via uname()"));
353 return false; // TEST09: can't test
354 }
355
356 short_host = utsname.nodename;
357 }
358
359 /* some systems report the FQDN instead of just the hostname */
360 const char *dot = strchr(short_host, '.');
361 if (dot)
362 ShortHostname = mutt_strn_dup(short_host, dot - short_host);
363 else
364 ShortHostname = mutt_str_dup(short_host);
365
366 // All the code paths from here alloc memory for the fqdn
367 char *fqdn = mutt_str_dup(c_hostname);
368 if (!fqdn)
369 {
370 mutt_debug(LL_DEBUG1, "Setting $hostname\n");
371 /* now get FQDN. Use configured domain first, DNS next, then uname */
372#ifdef DOMAIN
373 /* we have a compile-time domain name, use that for `$hostname` */
374 mutt_str_asprintf(&fqdn, "%s.%s", NONULL(ShortHostname), DOMAIN);
375#else
376 fqdn = getmailname();
377 if (!fqdn)
378 {
379 struct Buffer *domain = buf_pool_get();
380 if (getdnsdomainname(domain) == 0)
381 {
382 mutt_str_asprintf(&fqdn, "%s.%s", NONULL(ShortHostname), buf_string(domain));
383 }
384 else
385 {
386 /* DNS failed, use the nodename. Whether or not the nodename had a '.'
387 * in it, we can use the nodename as the FQDN. On hosts where DNS is
388 * not being used, e.g. small network that relies on hosts files, a
389 * short host name is all that is required for SMTP to work correctly.
390 * It could be wrong, but we've done the best we can, at this point the
391 * onus is on the user to provide the correct hostname if the nodename
392 * won't work in their network. */
393 fqdn = mutt_str_dup(utsname.nodename);
394 }
395 buf_pool_release(&domain);
396 mutt_debug(LL_DEBUG1, "Hostname: %s\n", NONULL(fqdn));
397 }
398#endif
399 }
400
401 if (fqdn)
402 {
403 config_str_set_initial(cs, "hostname", fqdn);
404 FREE(&fqdn);
405 }
406
407 return true;
408}
409
421static int mutt_init(struct ConfigSet *cs, struct Buffer *dlevel,
422 struct Buffer *dfile, bool skip_sys_rc,
423 struct StringArray *user_files, struct StringArray *commands)
424{
425 bool need_pause = false;
426 int rc = 1;
427 struct Buffer *buf = buf_pool_get();
428 struct ParseContext *pc = parse_context_new();
429 struct ParseError *pe = parse_error_new();
430 const char **cp = NULL;
431
432#ifdef NEOMUTT_DIRECT_COLORS
433 /* Test if we run in a terminal which supports direct colours.
434 *
435 * The user/terminal can indicate their capability independent of the
436 * terminfo file by setting the COLORTERM environment variable to "truecolor"
437 * or "24bit" (case sensitive).
438 *
439 * Note: This is to test is less about whether the terminal understands
440 * direct color commands but more about whether ncurses believes it can send
441 * them to the terminal, e.g. ncurses ignores COLORTERM.
442 */
443 if (COLORS == 16777216) // 2^24
444 {
445 /* Ncurses believes the Terminal supports it check the environment variable
446 * to respect the user's choice */
447 const char *env_colorterm = mutt_str_getenv("COLORTERM");
448 if (env_colorterm && (mutt_str_equal(env_colorterm, "truecolor") ||
449 mutt_str_equal(env_colorterm, "24bit")))
450 {
451 config_str_set_initial(cs, "color_directcolor", "yes");
452 }
453 }
454#endif
455
456 /* "$spool_file" precedence: config file, environment */
457 const char *p = mutt_str_getenv("MAIL");
458 if (!p)
459 p = mutt_str_getenv("MAILDIR");
460 if (!p)
461 {
462#ifdef HOMESPOOL
463 buf_concat_path(buf, NONULL(NeoMutt->home_dir), MAILPATH);
464#else
465 buf_concat_path(buf, MAILPATH, NONULL(NeoMutt->username));
466#endif
467 p = buf_string(buf);
468 }
469 config_str_set_initial(cs, "spool_file", p);
470
471 p = mutt_str_getenv("REPLYTO");
472 if (p)
473 {
474 buf_printf(buf, "Reply-To: %s", p);
475 buf_seek(buf, 0);
476
478 ASSERT(cmd);
479 parse_my_header(cmd, buf, pc, pe);
480 }
481
482 p = mutt_str_getenv("EMAIL");
483 if (p)
484 config_str_set_initial(cs, "from", p);
485
486 /* "$mailcap_path" precedence: config file, environment, code */
487 struct Buffer *mc = buf_pool_get();
488 struct Slist *sl_mc = NULL;
489 const char *env_mc = mutt_str_getenv("MAILCAPS");
490 if (env_mc)
491 {
492 sl_mc = slist_parse(env_mc, D_SLIST_SEP_COLON);
493 }
494 else
495 {
496 cs_str_initial_get(cs, "mailcap_path", mc);
498 buf_reset(mc);
499 }
500 slist_to_buffer(sl_mc, mc);
501 config_str_set_initial(cs, "mailcap_path", buf_string(mc));
502 slist_free(&sl_mc);
503 buf_pool_release(&mc);
504
505 /* "$tmp_dir" precedence: config file, environment, code */
506 const char *env_tmp = mutt_str_getenv("TMPDIR");
507 if (env_tmp)
508 {
509 config_str_set_initial(cs, "tmp_dir", env_tmp);
510 config_str_set_initial(cs, "tmp_draft_dir", env_tmp);
511 }
512
513 /* "$visual", "$editor" precedence: config file, environment, code */
514 const char *env_ed = mutt_str_getenv("VISUAL");
515 if (!env_ed)
516 env_ed = mutt_str_getenv("EDITOR");
517 if (!env_ed)
518 env_ed = "vi";
519 config_str_set_initial(cs, "editor", env_ed);
520
521 const char *charset = mutt_ch_get_langinfo_charset();
522 config_str_set_initial(cs, "charset", charset);
523 mutt_ch_set_charset(charset);
524 FREE(&charset);
525
526 char name[256] = { 0 };
527 const char *c_real_name = cs_subset_string(NeoMutt->sub, "real_name");
528 if (!c_real_name)
529 {
530 struct passwd *pw = getpwuid(getuid());
531 if (pw)
532 {
533 c_real_name = mutt_gecos_name(name, sizeof(name), pw);
534 }
535 }
536 config_str_set_initial(cs, "real_name", c_real_name);
537
538 if (ARRAY_EMPTY(user_files))
539 {
540 const char *xdg_cfg_home = mutt_str_getenv("XDG_CONFIG_HOME");
541
542 if (!xdg_cfg_home && NeoMutt->home_dir)
543 {
544 buf_printf(buf, "%s/.config", NeoMutt->home_dir);
545 xdg_cfg_home = buf_string(buf);
546 }
547
548 char *config = find_cfg(NeoMutt->home_dir, xdg_cfg_home);
549 if (config)
550 {
551 ARRAY_ADD(user_files, config);
552 }
553 }
554 else
555 {
556 ARRAY_FOREACH(cp, user_files)
557 {
558 buf_strcpy(buf, *cp);
559 FREE(cp);
560 expand_path(buf, false);
561 ARRAY_SET(user_files, ARRAY_FOREACH_IDX_cp, buf_strdup(buf));
562 if (access(buf_string(buf), F_OK))
563 {
564 mutt_perror("%s", buf_string(buf));
565 goto done; // TEST10: neomutt -F missing
566 }
567 }
568 }
569
570 ARRAY_FOREACH(cp, user_files)
571 {
572 if (*cp && !mutt_str_equal(*cp, "/dev/null"))
573 {
574 cs_str_string_set(cs, "alias_file", *cp, NULL);
575 break;
576 }
577 }
578
579 /* Process the global rc file if it exists and the user hasn't explicitly
580 * requested not to via "-n". */
581 if (!skip_sys_rc)
582 {
583 do
584 {
586 break;
587
588 buf_printf(buf, "%s/neomuttrc", SYSCONFDIR);
589 if (access(buf_string(buf), F_OK) == 0)
590 break;
591
592 buf_printf(buf, "%s/Muttrc", SYSCONFDIR);
593 if (access(buf_string(buf), F_OK) == 0)
594 break;
595
596 buf_printf(buf, "%s/neomuttrc", PKGDATADIR);
597 if (access(buf_string(buf), F_OK) == 0)
598 break;
599
600 buf_printf(buf, "%s/Muttrc", PKGDATADIR);
601 } while (false);
602
603 if (access(buf_string(buf), F_OK) == 0)
604 {
605 if (source_rc(buf_string(buf), pc, pe) != 0)
606 {
607 mutt_error("%s", buf_string(pe->message));
608 need_pause = true; // TEST11: neomutt (error in /etc/neomuttrc)
609 }
610 }
611 }
612
613 /* Read the user's initialization file. */
614 ARRAY_FOREACH(cp, user_files)
615 {
616 if (*cp)
617 {
618 if (source_rc(*cp, pc, pe) != 0)
619 {
620 mutt_error("%s", buf_string(pe->message));
621 need_pause = true; // TEST12: neomutt (error in ~/.neomuttrc)
622 }
623 }
624 }
625
626 if (execute_commands(commands) != 0)
627 need_pause = true; // TEST13: neomutt -e broken
628
629 if (!get_hostname(cs))
630 goto done;
631
632 /* The command line overrides the config */
633 if (!buf_is_empty(dlevel))
634 cs_str_reset(cs, "debug_level", NULL);
635 if (!buf_is_empty(dfile))
636 cs_str_reset(cs, "debug_file", NULL);
637
638 if (mutt_log_start() < 0)
639 {
640 mutt_perror("log file");
641 goto done;
642 }
643
644 if (need_pause && OptGui)
645 {
647 if (mutt_any_key_to_continue(NULL) == 'q')
648 goto done; // TEST14: neomutt -e broken (press 'q')
649 }
650
651 const char *const c_tmp_dir = cs_subset_path(NeoMutt->sub, "tmp_dir");
652 if (mutt_file_mkdir(c_tmp_dir, S_IRWXU) < 0)
653 {
654 mutt_error(_("Can't create %s: %s"), c_tmp_dir, strerror(errno));
655 goto done;
656 }
657
658 rc = 0;
659
660done:
662 parse_error_free(&pe);
663 buf_pool_release(&buf);
664 return rc;
665}
666
674static int get_elem_queries(struct StringArray *queries, struct HashElemArray *hea)
675{
676 int rc = 0;
677 const char **cp = NULL;
678 ARRAY_FOREACH(cp, queries)
679 {
680 struct HashElem *he = cs_subset_lookup(NeoMutt->sub, *cp);
681 if (!he)
682 {
683 mutt_warning(_("Unknown option %s"), *cp);
684 rc = 1;
685 continue;
686 }
687
688 if (he->type & D_INTERNAL_DEPRECATED)
689 {
690 mutt_warning(_("Option %s is deprecated"), *cp);
691 rc = 1;
692 continue;
693 }
694
695 ARRAY_ADD(hea, he);
696 }
697
698 return rc; // TEST16: neomutt -Q charset
699}
700
704static void init_keys(struct NeoMutt *n)
705{
706 struct SubMenu *sm_generic = generic_init_keys(n);
707
708 alias_init_keys(n, sm_generic);
709 attach_init_keys(n, sm_generic);
710#ifdef USE_AUTOCRYPT
711 autocrypt_init_keys(n, sm_generic);
712#endif
713 browser_init_keys(n, sm_generic);
714 compose_init_keys(n, sm_generic);
715 editor_init_keys(n, sm_generic);
716 sidebar_init_keys(n, sm_generic);
717 index_init_keys(n, sm_generic);
718 pager_init_keys(n, sm_generic);
719 pgp_init_keys(n, sm_generic);
720 postponed_init_keys(n, sm_generic);
721
722 km_sort();
723}
724
730static int start_curses(void)
731{
732 /* should come before initscr() so that ncurses 4.2 doesn't try to install
733 * its own SIGWINCH handler */
735
736 if (!initscr())
737 {
738 mutt_error(_("Error initializing terminal"));
739 return 1;
740 }
741
743 colors_init(color_mod_data);
744 keypad(stdscr, true);
745 cbreak();
746 noecho();
747 nonl();
748 typeahead(-1); /* simulate smooth scrolling */
749 meta(stdscr, true);
751 ext_keys_init(mod_data->key_names);
752
753 /* Now that curses is set up, we drop back to normal screen mode.
754 * This simplifies displaying error messages to the user.
755 * The first call to refresh() will swap us back to curses screen mode. */
756 endwin();
757 return 0;
758}
759
767static bool get_user_info(struct ConfigSet *cs)
768{
769 const char *shell = mutt_str_getenv("SHELL");
770
771 /* Get some information about the user */
772 struct passwd *pw = getpwuid(getuid());
773 if (pw)
774 {
775 if (!NeoMutt->username)
776 NeoMutt->username = mutt_str_dup(pw->pw_name);
777 if (!NeoMutt->home_dir)
778 NeoMutt->home_dir = mutt_str_dup(pw->pw_dir);
779 if (!shell)
780 shell = pw->pw_shell;
781 }
782
783 if (!NeoMutt->username)
784 {
785 mutt_error(_("unable to determine username"));
786 return false; // TEST05: neomutt (unset $USER, delete user from /etc/passwd)
787 }
788
789 if (!NeoMutt->home_dir)
790 {
791 mutt_error(_("unable to determine home directory"));
792 return false; // TEST06: neomutt (unset $HOME, delete user from /etc/passwd)
793 }
794
795 if (shell)
796 config_str_set_initial(cs, "shell", shell);
797
798 return true;
799}
800
808static void log_translation(void)
809{
810 const char *header = ""; // Do not merge these two lines
811 header = _(header); // otherwise the .po files will end up badly ordered
812 const char *label = "Language:"; // the start of the lookup/needle
813 const char *lang = mutt_istr_find(header, label);
814 int len = 64;
815 if (lang)
816 {
817 lang += strlen(label); // skip label
818 SKIPWS(lang);
819 const char *nl = strchr(lang, '\n');
820 if (nl)
821 len = (nl - lang);
822 }
823 else
824 {
825 lang = "NONE";
826 }
827
828 mutt_debug(LL_DEBUG1, "Translation: %.*s\n", len, lang);
829}
830
835{
836 static time_t last_run = 0;
837
838 if (nc->event_type != NT_TIMEOUT)
839 return 0;
840
841 const short c_timeout = cs_subset_number(NeoMutt->sub, "timeout");
842 if (c_timeout <= 0)
843 goto done;
844
845 time_t now = mutt_date_now();
846 if (now < (last_run + c_timeout))
847 goto done;
848
849 // Limit hook to running under the Index or Pager
851 struct MuttWindow *dlg = dialog_find(focus);
852 if (!dlg || (dlg->type != WT_DLG_INDEX))
853 goto done;
854
855 last_run = now;
857
858done:
859 mutt_debug(LL_DEBUG5, "timeout done\n");
860 return 0;
861}
862
868static bool show_help(struct CliHelp *help)
869{
870 if (!help->is_set)
871 return true;
872
874
875 const bool tty = isatty(STDOUT_FILENO);
876
877 if (help->help)
878 {
879 show_cli(help->mode, tty);
880 }
881 else if (help->license)
882 {
884 }
885 else
886 {
887 print_version(stdout, tty);
888 }
889
890 return false; // Stop
891}
892
899static bool init_logging(struct CliShared *shared, struct ConfigSet *cs)
900{
901 if (!shared->is_set)
902 return true;
903
904 if (!buf_is_empty(&shared->log_file))
905 config_str_set_initial(cs, "debug_file", buf_string(&shared->log_file));
906
907 if (!buf_is_empty(&shared->log_level))
908 {
909 const char *dlevel = buf_string(&shared->log_level);
910 short num = 0;
911 if (!mutt_str_atos_full(dlevel, &num) || (num < LL_MESSAGE) || (num >= LL_MAX))
912 {
913 mutt_error(_("Error: value '%s' is invalid for -d"), dlevel);
914 return false;
915 }
916
917 config_str_set_initial(cs, "debug_level", dlevel);
918 }
919
920 return true;
921}
922
928static void init_nntp(struct Buffer *server, struct ConfigSet *cs)
929{
930 const char *cli_nntp = NULL;
931 if (!buf_is_empty(server))
932 cli_nntp = buf_string(server);
933
934 /* "$news_server" precedence: command line, config file, environment, system file */
935 if (!cli_nntp)
936 cli_nntp = cs_subset_string(NeoMutt->sub, "news_server");
937
938 if (!cli_nntp)
939 cli_nntp = mutt_str_getenv("NNTPSERVER");
940
941 if (!cli_nntp)
942 {
943 char buf[1024] = { 0 };
944 cli_nntp = mutt_file_read_keyword(SYSCONFDIR "/nntpserver", buf, sizeof(buf));
945 }
946
947 if (cli_nntp)
948 config_str_set_initial(cs, "news_server", cli_nntp);
949}
950
957static bool dump_info(struct CliInfo *ci, struct ConfigSet *cs)
958{
959 if (!ci->is_set)
960 return true;
961
962 if (ci->dump_config || !ARRAY_EMPTY(&ci->queries))
963 {
964 const bool tty = isatty(STDOUT_FILENO);
965
967 if (tty)
968 cdflags |= CS_DUMP_LINK_DOCS;
969 if (ci->hide_sensitive)
970 cdflags |= CS_DUMP_HIDE_SENSITIVE;
971 if (ci->show_help)
972 cdflags |= CS_DUMP_SHOW_DOCS;
973
974 struct HashElemArray hea = ARRAY_HEAD_INITIALIZER;
975 if (ci->dump_config)
976 {
978 hea = get_elem_list(cs, gel_flags);
979 }
980 else
981 {
982 get_elem_queries(&ci->queries, &hea);
983 }
984
985 dump_config(cs, &hea, cdflags, stdout);
986 ARRAY_FREE(&hea);
987 }
988 else if (!ARRAY_EMPTY(&ci->alias_queries))
989 {
990 const char **cp = NULL;
992 {
993 struct AddressList *al = alias_lookup(*cp);
994 if (al)
995 {
996 /* output in machine-readable form */
997 mutt_addrlist_to_intl(al, NULL);
998 struct Buffer *buf = buf_pool_get();
999 mutt_addrlist_write(al, buf, false);
1000 printf("%s\n", buf_string(buf));
1001 buf_pool_release(&buf);
1002 }
1003 else
1004 {
1005 printf("%s\n", NONULL(*cp)); // TEST19: neomutt -A unknown
1006 }
1007 }
1008 }
1009
1010 return false; // Stop
1011}
1012
1021int main(int argc, char *argv[], char *envp[])
1022{
1024
1025 struct Email *e = NULL;
1026 SendFlags sendflags = SEND_NONE;
1027 int rc = 1;
1028 bool repeat_error = false;
1029 struct Buffer *expanded_infile = buf_pool_get();
1030 struct Buffer *tempfile = buf_pool_get();
1031 struct ConfigSet *cs = NULL;
1032 struct CommandLine *cli = command_line_new();
1033
1034 /* sanity check against stupid administrators */
1035 if (getegid() != getgid())
1036 {
1037 mutt_error("%s: I don't want to run with privileges!", (argc != 0) ? argv[0] : "neomutt");
1038 goto done; // TEST01: neomutt (as root, chgrp mail neomutt; chmod +s neomutt)
1039 }
1040
1041 OptGui = true;
1042
1043 NeoMutt = neomutt_new();
1044 if (!neomutt_init(NeoMutt, envp, Modules))
1045 goto done;
1046
1047 cli_parse(argc, argv, cli);
1048
1049 if (!show_help(&cli->help))
1050 {
1051 rc = 0;
1052 goto done;
1053 }
1054
1056
1057#ifdef USE_DEBUG_NOTIFY
1059#endif
1060
1061 cs = NeoMutt->sub->cs;
1062 if (!get_user_info(cs))
1063 goto done;
1064
1065 if (!init_logging(&cli->shared, cs))
1066 goto done;
1067
1068 mutt_log_prep();
1070
1071 /* Check for a batch send. */
1072 if (!isatty(STDIN_FILENO) || !ARRAY_EMPTY(&cli->info.queries) ||
1074 {
1075 OptGui = false;
1076 sendflags |= SEND_BATCH;
1079 }
1080
1081 /* Check to make sure stdout is available in curses mode. */
1082 if (OptGui && !isatty(STDOUT_FILENO))
1083 goto done;
1084
1085 /* This must come before mutt_init() because curses needs to be started
1086 * before calling the init_pair() function to set the color scheme. */
1087 if (OptGui)
1088 {
1089 int crc = start_curses();
1090 if (crc != 0)
1091 goto done; // TEST08: can't test -- fake term?
1092 }
1093
1094 /* Always create the mutt_windows because batch mode has some shared code
1095 * paths that end up referencing them. */
1097 rootwin_new(gui_mod_data);
1098
1099 /* set defaults and read init files */
1100 int rc2 = mutt_init(cs, &cli->shared.log_level, &cli->shared.log_file,
1102 &cli->shared.commands);
1103 if (rc2 != 0)
1104 goto done;
1105
1106 if (OptGui)
1108
1109 init_nntp(&cli->tui.nntp_server, cs);
1110
1111 /* Initialize crypto backends. */
1112 crypt_init();
1113
1114 if (!buf_is_empty(&cli->shared.mbox_type) &&
1115 !config_str_set_initial(cs, "mbox_type", buf_string(&cli->shared.mbox_type)))
1116 {
1117 goto done;
1118 }
1119
1120 if (!dump_info(&cli->info, cs))
1121 {
1122 rc = 0;
1123 goto done;
1124 }
1125
1126#ifdef USE_AUTOCRYPT
1127 /* Initialize autocrypt after curses messages are working,
1128 * because of the initial account setup screens. */
1129 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
1130 if (c_autocrypt)
1131 (void) mutt_autocrypt_init(!(sendflags & SEND_BATCH));
1132#endif
1133
1134 /* Create the `$folder` directory if it doesn't exist. */
1135 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
1136 if (OptGui && c_folder)
1137 {
1138 struct stat st = { 0 };
1139 struct Buffer *fpath = buf_pool_get();
1140
1141 buf_strcpy(fpath, c_folder);
1142 expand_path(fpath, false);
1143 bool skip = false;
1144 /* we're not connected yet - skip mail folder creation */
1145 skip |= (imap_path_probe(buf_string(fpath), NULL) == MUTT_IMAP);
1146 skip |= (pop_path_probe(buf_string(fpath), NULL) == MUTT_POP);
1147 skip |= (nntp_path_probe(buf_string(fpath), NULL) == MUTT_NNTP);
1148 if (!skip && (stat(buf_string(fpath), &st) == -1) && (errno == ENOENT))
1149 {
1150 char msg2[256] = { 0 };
1151 snprintf(msg2, sizeof(msg2), _("%s does not exist. Create it?"), c_folder);
1152 if (query_yesorno(msg2, MUTT_YES) == MUTT_YES)
1153 {
1154 if ((mkdir(buf_string(fpath), 0700) == -1) && (errno != EEXIST))
1155 mutt_error(_("Can't create %s: %s"), c_folder, strerror(errno)); // TEST21: neomutt -n -F /dev/null (and ~/Mail doesn't exist)
1156 }
1157 }
1158 buf_pool_release(&fpath);
1159 }
1160
1161 StartupComplete = true;
1162
1166
1167 if (cli->tui.start_postponed)
1168 {
1169 if (OptGui)
1170 mutt_flushinp();
1171 if (mutt_send_message(SEND_POSTPONED, NULL, NULL, NULL, NULL, NeoMutt->sub) == 0)
1172 rc = 0;
1173 // TEST23: neomutt -p (postponed message, cancel)
1174 // TEST24: neomutt -p (no postponed message)
1176 repeat_error = true;
1177 goto done;
1178 }
1179 else if (cli->send.is_set)
1180 {
1181 FILE *fp_in = NULL;
1182 FILE *fp_out = NULL;
1183 const char *infile = NULL;
1184 char *bodytext = NULL;
1185 const char *bodyfile = NULL;
1186 int rv = 0;
1187
1188 if (OptGui)
1189 mutt_flushinp();
1190
1191 if (cli->send.use_crypto)
1192 sendflags |= SEND_CLI_CRYPTO;
1193
1194 e = email_new();
1195 e->env = mutt_env_new();
1196
1197 const char **cp = NULL;
1198 ARRAY_FOREACH(cp, &cli->send.bcc_list)
1199 {
1200 mutt_addrlist_parse(&e->env->bcc, *cp);
1201 }
1202
1203 ARRAY_FOREACH(cp, &cli->send.cc_list)
1204 {
1205 mutt_addrlist_parse(&e->env->cc, *cp);
1206 }
1207
1208 ARRAY_FOREACH(cp, &cli->send.addresses)
1209 {
1210 if (url_check_scheme(*cp) == U_MAILTO)
1211 {
1212 if (!mutt_parse_mailto(e->env, &bodytext, *cp))
1213 {
1214 mutt_error(_("Failed to parse mailto: link"));
1215 email_free(&e);
1216 goto done; // TEST25: neomutt mailto:?
1217 }
1218 }
1219 else
1220 {
1221 mutt_addrlist_parse(&e->env->to, *cp);
1222 }
1223 }
1224
1225 const bool c_auto_edit = cs_subset_bool(NeoMutt->sub, "auto_edit");
1226 if (buf_is_empty(&cli->send.draft_file) && c_auto_edit &&
1227 TAILQ_EMPTY(&e->env->to) && TAILQ_EMPTY(&e->env->cc))
1228 {
1229 mutt_error(_("No recipients specified"));
1230 email_free(&e);
1231 goto done; // TEST26: neomutt -s test (with auto_edit=yes)
1232 }
1233
1234 if (!buf_is_empty(&cli->send.subject))
1235 {
1236 /* prevent header injection */
1239 }
1240
1241 if (!buf_is_empty(&cli->send.draft_file))
1242 {
1243 infile = buf_string(&cli->send.draft_file);
1244 }
1245 else if (!buf_is_empty(&cli->send.include_file))
1246 {
1247 infile = buf_string(&cli->send.include_file);
1248 }
1249 else
1250 {
1251 cli->send.edit_infile = false;
1252 }
1253
1254 if (infile || bodytext)
1255 {
1256 /* Prepare fp_in and expanded_infile. */
1257 if (infile)
1258 {
1259 if (mutt_str_equal("-", infile))
1260 {
1261 if (cli->send.edit_infile)
1262 {
1263 mutt_error(_("Can't use -E flag with stdin"));
1264 email_free(&e);
1265 goto done; // TEST27: neomutt -E -H -
1266 }
1267 fp_in = stdin;
1268 }
1269 else
1270 {
1271 buf_strcpy(expanded_infile, infile);
1272 expand_path(expanded_infile, false);
1273 fp_in = mutt_file_fopen(buf_string(expanded_infile), "r");
1274 if (!fp_in)
1275 {
1276 mutt_perror("%s", buf_string(expanded_infile));
1277 email_free(&e);
1278 goto done; // TEST28: neomutt -E -H missing
1279 }
1280 }
1281 }
1282
1283 if (cli->send.edit_infile)
1284 {
1285 /* If editing the infile, keep it around afterwards so
1286 * it doesn't get unlinked, and we can rebuild the draft_file */
1287 sendflags |= SEND_NO_FREE_HEADER;
1288 }
1289 else
1290 {
1291 /* Copy input to a tempfile, and re-point fp_in to the tempfile.
1292 * Note: stdin is always copied to a tempfile, ensuring draft_file
1293 * can stat and get the correct st_size below. */
1294 buf_mktemp_draft(tempfile);
1295
1296 fp_out = mutt_file_fopen(buf_string(tempfile), "w");
1297 if (!fp_out)
1298 {
1299 mutt_file_fclose(&fp_in);
1300 mutt_perror("%s", buf_string(tempfile));
1301 email_free(&e);
1302 goto done; // TEST29: neomutt -H existing-file (where tmpdir=/path/to/FILE blocking tmpdir)
1303 }
1304 if (fp_in)
1305 {
1306 mutt_file_copy_stream(fp_in, fp_out);
1307 if (fp_in == stdin)
1308 sendflags |= SEND_CONSUMED_STDIN;
1309 else
1310 mutt_file_fclose(&fp_in);
1311 }
1312 else if (bodytext)
1313 {
1314 fputs(bodytext, fp_out);
1315 }
1316 mutt_file_fclose(&fp_out);
1317
1318 fp_in = mutt_file_fopen(buf_string(tempfile), "r");
1319 if (!fp_in)
1320 {
1321 mutt_perror("%s", buf_string(tempfile));
1322 email_free(&e);
1323 goto done; // TEST30: can't test
1324 }
1325 }
1326
1327 /* Parse the draft_file into the full Email/Body structure.
1328 * Set SEND_DRAFT_FILE so mutt_send_message doesn't overwrite
1329 * our e->body. */
1330 if (!buf_is_empty(&cli->send.draft_file))
1331 {
1332 struct Envelope *opts_env = e->env;
1333 struct stat st = { 0 };
1334
1335 sendflags |= SEND_DRAFT_FILE;
1336
1337 /* Set up a tmp Email with just enough information so that
1338 * mutt_prepare_template() can parse the message in fp_in. */
1339 struct Email *e_tmp = email_new();
1340 e_tmp->offset = 0;
1341 e_tmp->body = mutt_body_new();
1342 if (fstat(fileno(fp_in), &st) != 0)
1343 {
1344 mutt_perror("%s", buf_string(&cli->send.draft_file));
1345 email_free(&e);
1346 email_free(&e_tmp);
1347 goto done; // TEST31: can't test
1348 }
1349 e_tmp->body->length = st.st_size;
1350
1351 if (mutt_prepare_template(fp_in, NULL, e, e_tmp, false) < 0)
1352 {
1353 mutt_error(_("Can't parse message template: %s"),
1354 buf_string(&cli->send.draft_file));
1355 email_free(&e);
1356 email_free(&e_tmp);
1357 goto done;
1358 }
1359
1360 /* Scan for neomutt header to set `$resume_draft_files` */
1361 struct ListNode *tmp = NULL;
1362 const bool c_resume_edited_draft_files = cs_subset_bool(NeoMutt->sub, "resume_edited_draft_files");
1363 struct ListNode *np = NULL;
1364 STAILQ_FOREACH_SAFE(np, &e->env->userhdrs, entries, tmp)
1365 {
1366 if (mutt_istr_startswith(np->data, "X-Mutt-Resume-Draft:"))
1367 {
1368 if (c_resume_edited_draft_files)
1369 cs_str_native_set(cs, "resume_draft_files", true, NULL);
1370
1371 STAILQ_REMOVE(&e->env->userhdrs, np, ListNode, entries);
1372 FREE(&np->data);
1373 FREE(&np);
1374 }
1375 }
1376
1377 mutt_addrlist_copy(&e->env->to, &opts_env->to, false);
1378 mutt_addrlist_copy(&e->env->cc, &opts_env->cc, false);
1379 mutt_addrlist_copy(&e->env->bcc, &opts_env->bcc, false);
1380 if (opts_env->subject)
1381 mutt_env_set_subject(e->env, opts_env->subject);
1382
1383 mutt_env_free(&opts_env);
1384 email_free(&e_tmp);
1385 }
1386 else if (cli->send.edit_infile)
1387 {
1388 /* Editing the include_file: pass it directly in.
1389 * Note that SEND_NO_FREE_HEADER is set above so it isn't unlinked. */
1390 bodyfile = buf_string(expanded_infile);
1391 }
1392 else
1393 {
1394 // For bodytext and unedited include_file: use the tempfile.
1395 bodyfile = buf_string(tempfile);
1396 }
1397
1398 mutt_file_fclose(&fp_in);
1399 }
1400
1401 FREE(&bodytext);
1402
1403 if (!ARRAY_EMPTY(&cli->send.attach))
1404 {
1405 struct Body *b = e->body;
1406
1407 while (b && b->next)
1408 b = b->next;
1409
1410 ARRAY_FOREACH(cp, &cli->send.attach)
1411 {
1412 if (b)
1413 {
1415 b = b->next;
1416 }
1417 else
1418 {
1420 e->body = b;
1421 }
1422 if (!b)
1423 {
1424 mutt_error(_("%s: unable to attach file"), *cp);
1425 email_free(&e);
1426 goto done; // TEST32: neomutt john@example.com -a missing
1427 }
1428 }
1429 }
1430
1431 rv = mutt_send_message(sendflags, e, bodyfile, NULL, NULL, NeoMutt->sub);
1432 /* We WANT the "Mail sent." and any possible, later error */
1434 if (ErrorBufMessage)
1435 mutt_message("%s", ErrorBuf);
1436
1437 if (cli->send.edit_infile)
1438 {
1439 if (!buf_is_empty(&cli->send.draft_file))
1440 {
1441 if (truncate(buf_string(expanded_infile), 0) == -1)
1442 {
1443 mutt_perror("%s", buf_string(expanded_infile));
1444 email_free(&e);
1445 goto done; // TEST33: neomutt -H read-only -s test john@example.com -E
1446 }
1447 fp_out = mutt_file_fopen(buf_string(expanded_infile), "a");
1448 if (!fp_out)
1449 {
1450 mutt_perror("%s", buf_string(expanded_infile));
1451 email_free(&e);
1452 goto done; // TEST34: can't test
1453 }
1454
1455 /* If the message was sent or postponed, these will already
1456 * have been done. */
1457 if (rv < 0)
1458 {
1459 if (e->body->next)
1460 e->body = mutt_make_multipart(e->body);
1462 mutt_prepare_envelope(e->env, false, NeoMutt->sub);
1463 mutt_env_to_intl(e->env, NULL, NULL);
1464 }
1465
1466 const bool c_crypt_protected_headers_read = cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_read");
1468 c_crypt_protected_headers_read &&
1470 NeoMutt->sub);
1471 const bool c_resume_edited_draft_files = cs_subset_bool(NeoMutt->sub, "resume_edited_draft_files");
1472 if (c_resume_edited_draft_files)
1473 fprintf(fp_out, "X-Mutt-Resume-Draft: 1\n");
1474 fputc('\n', fp_out);
1475 if ((mutt_write_mime_body(e->body, fp_out, NeoMutt->sub) == -1))
1476 {
1477 mutt_file_fclose(&fp_out);
1478 email_free(&e);
1479 goto done; // TEST35: can't test
1480 }
1481 mutt_file_fclose(&fp_out);
1482 }
1483
1484 email_free(&e);
1485 }
1486
1487 /* !edit_infile && draft_file will leave the tempfile around */
1488 if (!buf_is_empty(tempfile))
1489 unlink(buf_string(tempfile));
1490
1491 rootwin_cleanup(gui_mod_data);
1492
1493 if (rv != 0)
1494 goto done; // TEST36: neomutt -H existing -s test john@example.com -E (cancel sending)
1495 }
1496 else if (sendflags & SEND_BATCH)
1497 {
1498 /* This guards against invoking `neomutt < /dev/null` and accidentally
1499 * sending an email due to a my-header or other setting. */
1500 mutt_error(_("No recipients specified"));
1501 goto done;
1502 }
1503 else
1504 {
1505 struct Buffer *folder = &cli->tui.folder;
1506 bool explicit_folder = !buf_is_empty(folder);
1507
1508 if (cli->tui.start_new_mail)
1509 {
1510 const bool c_imap_passive = cs_subset_bool(NeoMutt->sub, "imap_passive");
1511 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", false, NULL);
1513 if (mutt_mailbox_check(NULL, csflags) == 0)
1514 {
1515 mutt_message(_("No mailbox with new mail"));
1516 goto done; // TEST37: neomutt -Z (no new mail)
1517 }
1518 buf_reset(folder);
1519 mutt_mailbox_next(NULL, folder);
1520 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", c_imap_passive, NULL);
1521 }
1522 else if (cli->tui.start_nntp || cli->tui.start_browser)
1523 {
1524 if (cli->tui.start_nntp)
1525 {
1527 const char *const c_news_server = cs_subset_string(NeoMutt->sub, "news_server");
1528 OptNews = true;
1529 mod_data->current_news_srv = nntp_select_server(NULL, c_news_server, false);
1530 if (!mod_data->current_news_srv)
1531 goto done; // TEST38: neomutt -G (unset news_server)
1532 }
1533 else if (ARRAY_EMPTY(&NeoMutt->accounts))
1534 {
1535 mutt_error(_("No incoming mailboxes defined"));
1536 goto done; // TEST39: neomutt -n -F /dev/null -y
1537 }
1538 buf_reset(folder);
1539 dlg_browser(folder, MUTT_SEL_FOLDER | MUTT_SEL_MAILBOX, NULL, NULL, NULL);
1540 if (buf_is_empty(folder))
1541 {
1542 rc = 0;
1543 goto done; // TEST40: neomutt -y (quit selection)
1544 }
1545 }
1546
1547 if (buf_is_empty(folder))
1548 {
1549 const char *const c_spool_file = cs_subset_string(NeoMutt->sub, "spool_file");
1550 if (c_spool_file)
1551 {
1552 // Check if `$spool_file` corresponds a mailboxes' description.
1553 struct Mailbox *m_desc = mailbox_find_name(c_spool_file);
1554 if (m_desc)
1555 buf_strcpy(folder, m_desc->realpath);
1556 else
1557 buf_strcpy(folder, c_spool_file);
1558 }
1559 else if (c_folder)
1560 {
1561 buf_strcpy(folder, c_folder);
1562 }
1563 /* else no folder */
1564 }
1565
1566 if (OptNews)
1567 {
1569 OptNews = false;
1570 buf_alloc(folder, PATH_MAX);
1571 nntp_expand_path(folder->data, folder->dsize,
1572 &mod_data->current_news_srv->conn->account);
1573 }
1574 else
1575 {
1576 expand_path(folder, false);
1577 }
1578
1581
1582 if (cli->tui.start_any_mail || cli->tui.start_new_mail)
1583 {
1584 /* check to see if there are any messages in the folder */
1585 switch (mx_path_is_empty(folder))
1586 {
1587 case -1:
1588 mutt_perror("%s", buf_string(folder));
1589 goto done; // TEST41: neomutt -z -f missing
1590 case 1:
1591 mutt_error(_("Mailbox is empty"));
1592 goto done; // TEST42: neomutt -z -f /dev/null
1593 }
1594 }
1595
1596 struct Mailbox *m_cur = mailbox_find(buf_string(folder));
1597 // Take a copy of the name just in case the hook alters m_cur
1598 const char *name = m_cur ? mutt_str_dup(m_cur->name) : NULL;
1600 FREE(&name);
1602 mutt_debug(LL_NOTIFY, "NT_GLOBAL_STARTUP\n");
1604
1606 window_redraw(NULL);
1607
1608 repeat_error = true;
1609 struct Mailbox *m = mx_resolve(buf_string(folder));
1610 const bool c_read_only = cs_subset_bool(NeoMutt->sub, "read_only");
1611 if (!mx_mbox_open(m, (cli->tui.read_only || c_read_only) ? MUTT_READONLY : MUTT_OPEN_NONE))
1612 {
1613 if (m->account)
1615
1616 mailbox_free(&m);
1617 mutt_error(_("Unable to open mailbox %s"), buf_string(folder));
1618 repeat_error = false;
1619 }
1620 if (m || !explicit_folder)
1621 {
1622 struct MuttWindow *dlg = index_pager_init();
1623 dialog_push(dlg);
1624
1626 m = dlg_index(dlg, m);
1628 mailbox_free(&m);
1629
1630 dialog_pop();
1631 mutt_window_free(&dlg);
1633 repeat_error = false;
1634 }
1636 // TEST43: neomutt (no change to mailbox)
1637 // TEST44: neomutt (change mailbox)
1638 }
1639 rc = 0;
1640
1641done:
1643 /* Repeat the last message to the user */
1644 if (repeat_error && ErrorBufMessage)
1645 puts(ErrorBuf);
1646
1647 if (NeoMutt && NeoMutt->sub)
1648 {
1652 }
1653
1654 buf_pool_release(&expanded_infile);
1655 buf_pool_release(&tempfile);
1656 if (NeoMutt)
1660 command_line_free(&cli);
1661
1663
1665 FREE(&LastFolder);
1667
1675 mutt_log_stop();
1676 return rc;
1677}
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:94
void alias_init_keys(struct NeoMutt *n, struct SubMenu *sm_generic)
Initialise the Alias Keybindings - Implements ::init_keys_api.
Definition functions.c:124
Email Aliases.
const struct Module ModuleAlias
Module for the Alias library.
Definition module.c:128
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_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 NeoMutt *n, struct SubMenu *sm_generic)
Initialise the Attach Keybindings - Implements ::init_keys_api.
Definition functions.c:126
GUI display the mailboxes in a side panel.
const struct Module ModuleAttach
Module for the Attach library.
Definition module.c:111
void autocrypt_init_keys(struct NeoMutt *n, struct SubMenu *sm_generic)
Initialise the Autocrypt Keybindings - Implements ::init_keys_api.
Definition functions.c:75
Autocrypt end-to-end encryption.
const struct Module ModuleAutocrypt
Module for the Autocrypt library.
Definition module.c:91
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition autocrypt.c:104
const struct Module ModuleBcache
Module for the Bcache library.
Definition module.c:66
void browser_init_keys(struct NeoMutt *n, struct SubMenu *sm_generic)
Initialise the Browser Keybindings - Implements ::init_keys_api.
Definition functions.c:129
Select a Mailbox from a list.
@ MUTT_SEL_MAILBOX
Select a mailbox.
Definition lib.h:60
@ MUTT_SEL_FOLDER
Select a local directory.
Definition lib.h:62
const struct Module ModuleBrowser
Module for the Browser library.
Definition module.c:91
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:104
Color private Module data.
void colors_init(struct ColorModuleData *mod_data)
Initialize colours.
Definition color.c:51
@ CMD_MY_HEADER
:my-header
Definition command.h:100
@ CMD_STARTUP_HOOK
:startup-hook
Definition command.h:118
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:120
NeoMutt Commands.
const struct Module ModuleCommands
Module for the Commands library.
Definition module.c:78
const struct Module ModuleComplete
Module for the Complete library.
Definition module.c:66
const struct Module ModuleCompmbox
Module for the Compmbox library.
Definition module.c:76
void compose_init_keys(struct NeoMutt *n, struct SubMenu *sm_generic)
Initialise the Compose Keybindings - Implements ::init_keys_api.
Definition functions.c:209
GUI editor for an email's headers.
const struct Module ModuleCompose
Module for the Compose library.
Definition module.c:77
const struct Module ModuleCompress
Module for the Compress library.
Definition module.c:66
bool dump_config(struct ConfigSet *cs, struct HashElemArray *hea, ConfigDumpFlags flags, FILE *fp)
Write all the config to a file.
Definition dump.c:198
@ CS_DUMP_SHOW_DOCS
Show one-liner documentation for the config item.
Definition dump.h:50
@ CS_DUMP_NONE
No flags are set.
Definition dump.h:40
@ CS_DUMP_LINK_DOCS
Link to the online docs.
Definition dump.h:51
@ CS_DUMP_HIDE_SENSITIVE
Obscure sensitive information like passwords.
Definition dump.h:42
uint16_t ConfigDumpFlags
Definition dump.h:53
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:103
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:618
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:693
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:813
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:128
const struct Module ModuleConvert
Module for the Convert library.
Definition module.c:66
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
@ 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:67
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
Definition crypt.c:1105
void crypt_init(void)
Initialise the crypto backends.
Definition cryptglue.c:99
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition curs_lib.c:175
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:148
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition dialog.c:89
struct MuttWindow * index_pager_init(void)
Allocate the Windows for the Index/Pager.
Definition dlg_index.c:1462
void editor_init_keys(struct NeoMutt *n, struct SubMenu *sm_generic)
Initialise the Editor Keybindings - Implements ::init_keys_api.
Definition functions.c:127
Edit a string.
const struct Module ModuleEditor
Module for the Editor library.
Definition module.c:66
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:127
bool mutt_parse_mailto(struct Envelope *env, char **body, const char *src)
Parse a mailto:// url.
Definition parse.c:1812
void mutt_filter_commandline_header_value(char *header)
Sanitise characters in a header value.
Definition parse.c:93
const struct Module ModuleEnvelope
Module for the Envelope library.
Definition module.c:66
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
const struct Module ModuleExpando
Module for the Expando library.
Definition module.c:77
void ext_keys_init(struct Mapping *key_names)
Initialise map of ncurses extended keys.
Definition extended.c:116
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:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
@ MUTT_RL_NONE
No flags are set.
Definition file.h:43
const struct Module ModulePop
Module for the Pop library.
Definition module.c:77
const struct Module ModuleParse
Module for the Parse library.
Definition module.c:66
const struct Module ModuleMaildir
Module for the Maildir library.
Definition module.c:84
const struct Module ModulePostpone
Module for the Postpone library.
Definition module.c:66
const struct Module ModuleSidebar
Module for the Sidebar library.
Definition module.c:111
const struct Module ModuleMh
Module for the Mh library.
Definition module.c:77
const struct Module ModuleLua
Module for the Lua library.
Definition module.c:84
const struct Module ModulePager
Module for the Pager library.
Definition module.c:80
const struct Module ModuleGui
Module for the Gui library.
Definition module.c:145
const struct Module ModuleProgress
Module for the Progress library.
Definition module.c:77
const struct Module ModuleMenu
Module for the Menu library.
Definition module.c:101
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:105
const struct Module ModuleMutt
Module for the Mutt library.
Definition module.c:68
const struct Module ModuleHcache
Module for the Hcache library.
Definition module.c:86
const struct Module ModuleSend
Module for the Send library.
Definition module.c:91
const struct Module ModuleQuestion
Module for the Question library.
Definition module.c:66
const struct Module ModuleImap
Module for the Imap library.
Definition module.c:96
const struct Module ModuleMain
Module for the Main library.
Definition module.c:63
const struct Module ModuleStore
Module for the Store library.
Definition module.c:66
const struct Module ModuleMbox
Module for the Mbox library.
Definition module.c:77
const struct Module ModulePattern
Module for the Pattern library.
Definition module.c:93
const struct Module ModuleNntp
Module for the Nntp library.
Definition module.c:77
const struct Module ModuleHelpbar
Module for the Helpbar library.
Definition module.c:77
const struct Module ModuleHistory
Module for the History library.
Definition module.c:98
const struct Module ModuleNotmuch
Module for the Notmuch library.
Definition module.c:118
const struct Module ModuleKey
Module for the Key library.
Definition module.c:99
const struct Module ModuleIndex
Module for the Index library.
Definition module.c:91
const struct Module ModuleHooks
Module for the Hooks library.
Definition module.c:92
void mutt_flushinp(void)
MacroEvents moved to KeyModuleData UngetKeyEvents moved to KeyModuleData.
Definition get.c:81
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:1121
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
#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:1170
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox?
Definition imap.c:2681
int main_hist_observer(struct NotifyCallback *nc)
Notification that a Config Variable has change - Implements observer_t -.
Definition history.c:688
static int main_timeout_observer(struct NotifyCallback *nc)
Notification that a timeout has occurred - Implements observer_t -.
Definition main.c:834
int main_log_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
struct SubMenu * generic_init_keys(struct NeoMutt *n)
Initialise the Generic Keybindings.
Definition functions.c:168
Convenience wrapper for the gui headers.
Read/write command history from/to a file.
void exec_startup_shutdown_hook(enum CommandId id)
Execute any startup/shutdown hooks.
Definition exec.c:418
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:378
Hook Commands.
IMAP network mailbox.
void imap_logout_all(void)
Close all open connections.
Definition imap.c:667
void index_init_keys(struct NeoMutt *n, struct SubMenu *sm_generic)
Initialise the Index Keybindings - Implements ::init_keys_api.
Definition functions.c:358
GUI manage the main index (list of emails)
void km_sort(void)
Sort all the menu keybindings.
Definition init.c:193
Manage keymappings.
Key private Module data.
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
static char * find_cfg(const char *home, const char *xdg_cfg_home)
Find a config file.
Definition main.c:255
static char * getmailname(void)
Try to retrieve the FQDN from mailname files.
Definition main.c:302
static bool init_logging(struct CliShared *shared, struct ConfigSet *cs)
Initialise the Logging.
Definition main.c:899
static void log_translation(void)
Log the translation being used.
Definition main.c:808
static void init_nntp(struct Buffer *server, struct ConfigSet *cs)
Initialise the NNTP config.
Definition main.c:928
static bool show_help(struct CliHelp *help)
Show the Help.
Definition main.c:868
static int start_curses(void)
Start the Curses UI.
Definition main.c:730
static bool dump_info(struct CliInfo *ci, struct ConfigSet *cs)
Show config info.
Definition main.c:957
static void init_keys(struct NeoMutt *n)
Initialise the Keybindings.
Definition main.c:704
static bool get_user_info(struct ConfigSet *cs)
Find the user's name, home and shell.
Definition main.c:767
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:335
static int get_elem_queries(struct StringArray *queries, struct HashElemArray *hea)
Lookup the HashElems for a set of queries.
Definition main.c:674
static int execute_commands(struct StringArray *sa)
Execute a set of NeoMutt commands.
Definition main.c:216
int main(int argc, char *argv[], char *envp[])
Start NeoMutt.
Definition main.c:1021
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:421
#define countof(x)
Definition memory.h:49
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
@ MODULE_ID_COLOR
ModuleColor, Color
Definition module_api.h:53
@ MODULE_ID_GUI
ModuleGui, Graphical code
Definition module_api.h:45
@ MODULE_ID_KEY
ModuleKey, Key mappings
Definition module_api.h:73
@ MODULE_ID_NNTP
ModuleNntp, Nntp
Definition module_api.h:81
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_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
@ 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.
@ MUTT_READONLY
Open in read-only mode.
Definition mxapi.h:45
@ MUTT_OPEN_NONE
No flags are set.
Definition mxapi.h:42
@ MUTT_MAILBOX_CHECK_IMMEDIATE
Don't postpone the actual checking.
Definition mxapi.h:61
uint8_t CheckStatsFlags
Definition mxapi.h:63
void pgp_init_keys(struct NeoMutt *n, struct SubMenu *sm_generic)
Initialise the PGP Keybindings - Implements ::init_keys_api.
Definition functions.c:88
API for encryption/signing of emails.
void neomutt_cleanup(struct NeoMutt *n)
Clean up NeoMutt and Modules.
Definition neomutt.c:471
bool neomutt_init(struct NeoMutt *n, char **envp, const struct Module **modules)
Initialise NeoMutt.
Definition neomutt.c:347
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
void neomutt_gui_cleanup(struct NeoMutt *n)
Clean up the GUI Modules.
Definition neomutt.c:486
struct NeoMutt * neomutt_new(void)
Create the main NeoMutt object.
Definition neomutt.c:335
void neomutt_free(struct NeoMutt **ptr)
Free a NeoMutt.
Definition neomutt.c:498
bool neomutt_gui_init(struct NeoMutt *n)
Initialise the GUI Modules.
Definition neomutt.c:397
@ NT_GLOBAL_STARTUP
NeoMutt is initialised.
Definition neomutt.h:69
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:557
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition newsrc.c:953
@ NT_TIMEOUT
Timeout has occurred.
Definition notify_type.h:57
@ 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:53
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 NeoMutt *n, struct SubMenu *sm_generic)
Initialise the Pager Keybindings - Implements ::init_keys_api.
Definition functions.c:302
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 NeoMutt *n, struct SubMenu *sm_generic)
Initialise the Postponed Keybindings - Implements ::init_keys_api.
Definition functions.c:72
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:490
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_new(struct GuiModuleData *mod_data)
Create the default Windows.
Definition rootwin.c:229
void rootwin_cleanup(struct GuiModuleData *mod_data)
Free all the default Windows.
Definition rootwin.c:211
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:2030
uint32_t SendFlags
Definition send.h:64
@ SEND_CONSUMED_STDIN
stdin has been read; don't read it twice
Definition send.h:61
@ SEND_NO_FREE_HEADER
Used by the -E flag.
Definition send.h:55
@ SEND_NONE
No flags are set.
Definition send.h:45
@ SEND_BATCH
Send email in batch mode (without user interaction)
Definition send.h:51
@ SEND_CLI_CRYPTO
Enable message security in modes that by default don't enable it.
Definition send.h:62
@ SEND_DRAFT_FILE
Used by the -H flag.
Definition send.h:56
@ SEND_POSTPONED
Recall a postponed email.
Definition send.h:50
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 NeoMutt *n, struct SubMenu *sm_generic)
Initialise the Sidebar Keybindings - Implements ::init_keys_api.
Definition functions.c:82
GUI display the mailboxes in a side panel.
#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:272
int source_rc(const char *rcfile_path, struct ParseContext *pc, struct ParseError *pe)
Read an initialization file.
Definition source.c:64
#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 use_crypto
-C Use CLI crypto
Definition objects.h:94
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
Color private Module data.
Definition module_data.h:35
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
struct ConnAccount account
Account details: username, password, etc.
Definition connection.h:49
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
Gui private Module data.
Definition module_data.h:32
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
Key private Module data.
Definition module_data.h:34
struct Mapping * key_names
Key name lookup table.
Definition module_data.h:41
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
A mailbox.
Definition mailbox.h:81
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:83
char * name
A short name for the Mailbox.
Definition mailbox.h:84
struct Account * account
Account that owns this Mailbox.
Definition mailbox.h:129
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:57
char * username
User's login name.
Definition neomutt.h:56
char * home_dir
User's home directory.
Definition neomutt.h:55
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
struct Connection * conn
Connection to NNTP Server.
Definition adata.h:63
Nntp private Module data.
Definition module_data.h:30
struct NntpAccountData * current_news_srv
Current NNTP news server.
Definition module_data.h:32
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:65
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
Filtering modes 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
#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:229
@ 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.