NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
129#define GNULIB_defined_setlocale
130
131#include "config.h"
132#include <errno.h>
133#include <limits.h>
134#include <locale.h>
135#include <pwd.h>
136#include <stdbool.h>
137#include <stdint.h>
138#include <stdio.h>
139#include <stdlib.h>
140#include <string.h>
141#include <sys/stat.h>
142#include <unistd.h>
143#include "mutt/lib.h"
144#include "address/lib.h"
145#include "config/lib.h"
146#include "email/lib.h"
147#include "core/lib.h"
148#include "alias/lib.h"
149#include "conn/lib.h"
150#include "gui/lib.h"
151#include "attach/lib.h"
152#include "browser/lib.h"
153#include "color/lib.h"
154#include "history/lib.h"
155#include "index/lib.h"
156#include "key/lib.h"
157#include "menu/lib.h"
158#include "ncrypt/lib.h"
159#include "postpone/lib.h"
160#include "question/lib.h"
161#include "send/lib.h"
162#include "alternates.h"
163#include "external.h"
164#include "globals.h" // IWYU pragma: keep
165#include "hook.h"
166#include "init.h"
167#include "mutt_logging.h"
168#include "mutt_mailbox.h"
169#include "muttlib.h"
170#include "mx.h"
171#include "protos.h"
172#include "subjectrx.h"
173#include "version.h"
174#ifdef ENABLE_NLS
175#include <libintl.h>
176#endif
177#ifdef USE_IMAP
178#include "imap/lib.h"
179#endif
180#ifdef USE_POP
181#include "pop/lib.h"
182#endif
183#ifdef USE_NNTP
184#include "nntp/lib.h"
185#include "nntp/adata.h" // IWYU pragma: keep
186#endif
187#ifdef USE_AUTOCRYPT
188#include "autocrypt/lib.h"
189#endif
190#if defined(USE_DEBUG_NOTIFY) || defined(USE_DEBUG_BACKTRACE)
191#include "debug/lib.h"
192#endif
193
194bool StartupComplete = false;
195
196// clang-format off
197typedef uint8_t CliFlags;
198#define MUTT_CLI_NO_FLAGS 0
199#define MUTT_CLI_IGNORE (1 << 0)
200#define MUTT_CLI_MAILBOX (1 << 1)
201#define MUTT_CLI_NOSYSRC (1 << 2)
202#define MUTT_CLI_RO (1 << 3)
203#define MUTT_CLI_SELECT (1 << 4)
204#ifdef USE_NNTP
205#define MUTT_CLI_NEWS (1 << 5)
206#endif
207// clang-format on
208
213static void reset_tilde(struct ConfigSet *cs)
214{
215 static const char *names[] = { "folder", "mbox", "postponed", "record" };
216
217 struct Buffer value = buf_make(256);
218 for (size_t i = 0; i < mutt_array_size(names); i++)
219 {
220 struct HashElem *he = cs_get_elem(cs, names[i]);
221 if (!he)
222 continue;
223 buf_reset(&value);
224 cs_he_initial_get(cs, he, &value);
225 buf_expand_path_regex(&value, false);
226 cs_he_initial_set(cs, he, value.data, NULL);
227 cs_he_reset(cs, he, NULL);
228 }
229 buf_dealloc(&value);
230}
231
236void mutt_exit(int code)
237{
238 mutt_endwin();
239#ifdef USE_DEBUG_BACKTRACE
240 if (code != 0)
242#endif
243 exit(code);
244}
245
250static bool usage(void)
251{
252 puts(mutt_make_version());
253
254 // clang-format off
255 /* L10N: Try to limit to 80 columns */
256 puts(_("usage:"));
257 puts(_(" neomutt [-Enx] [-e <command>] [-F <config>] [-H <draft>] [-i <include>]\n"
258 " [-b <address>] [-c <address>] [-s <subject>] [-a <file> [...] --]\n"
259 " <address> [...]"));
260 puts(_(" neomutt [-nx] [-e <command>] [-F <config>] [-b <address>] [-c <address>]\n"
261 " [-s <subject>] [-a <file> [...] --] <address> [...] < message"));
262 puts(_(" neomutt [-nRy] [-e <command>] [-F <config>] [-f <mailbox>] [-m <type>]"));
263 puts(_(" neomutt [-n] [-e <command>] [-F <config>] -A <alias>"));
264 puts(_(" neomutt [-n] [-e <command>] [-F <config>] -B"));
265 puts(_(" neomutt [-n] [-e <command>] [-F <config>] -D [-S] [-O]"));
266 puts(_(" neomutt [-n] [-e <command>] [-F <config>] -d <level> -l <file>"));
267 puts(_(" neomutt [-n] [-e <command>] [-F <config>] -G"));
268 puts(_(" neomutt [-n] [-e <command>] [-F <config>] -g <server>"));
269 puts(_(" neomutt [-n] [-e <command>] [-F <config>] -p"));
270 puts(_(" neomutt [-n] [-e <command>] [-F <config>] -Q <variable> [-O]"));
271 puts(_(" neomutt [-n] [-e <command>] [-F <config>] -Z"));
272 puts(_(" neomutt [-n] [-e <command>] [-F <config>] -z [-f <mailbox>]"));
273 puts(_(" neomutt -v[v]\n"));
274
275 /* L10N: Try to limit to 80 columns. If more space is needed add an indented line */
276 puts(_("options:"));
277 puts(_(" -- Special argument forces NeoMutt to stop option parsing and treat\n"
278 " remaining arguments as addresses even if they start with a dash"));
279 puts(_(" -A <alias> Print an expanded version of the given alias to stdout and exit"));
280 puts(_(" -a <file> Attach one or more files to a message (must be the last option)\n"
281 " Add any addresses after the '--' argument"));
282 puts(_(" -B Run in batch mode (do not start the ncurses UI)"));
283 puts(_(" -b <address> Specify a blind carbon copy (Bcc) recipient"));
284 puts(_(" -c <address> Specify a carbon copy (Cc) recipient"));
285 puts(_(" -D Dump all config variables as 'name=value' pairs to stdout"));
286 puts(_(" -D -O Like -D, but show one-liner documentation"));
287 puts(_(" -D -S Like -D, but hide the value of sensitive variables"));
288 puts(_(" -d <level> Log debugging output to a file (default is \"~/.neomuttdebug0\")\n"
289 " The level can range from 1-5 and affects verbosity"));
290 puts(_(" -E Edit draft (-H) or include (-i) file during message composition"));
291 puts(_(" -e <command> Specify a command to be run after reading the config files"));
292 puts(_(" -F <config> Specify an alternative initialization file to read"));
293 puts(_(" -f <mailbox> Specify a mailbox (as defined with 'mailboxes' command) to load"));
294 puts(_(" -G Start NeoMutt with a listing of subscribed newsgroups"));
295 puts(_(" -g <server> Like -G, but start at specified news server"));
296 puts(_(" -H <draft> Specify a draft file with header and body for message composing"));
297 puts(_(" -h Print this help message and exit"));
298 puts(_(" -i <include> Specify an include file to be embedded in the body of a message"));
299 puts(_(" -l <file> Specify a file for debugging output (default \"~/.neomuttdebug0\")"));
300 puts(_(" -m <type> Specify a default mailbox format type for newly created folders\n"
301 " The type is either MH, MMDF, Maildir or mbox (case-insensitive)"));
302 puts(_(" -n Do not read the system-wide configuration file"));
303 puts(_(" -p Resume a prior postponed message, if any"));
304 puts(_(" -Q <variable> Query a configuration variable and print its value to stdout\n"
305 " (after the config has been read and any commands executed)\n"
306 " Add -O for one-liner documentation"));
307 puts(_(" -R Open mailbox in read-only mode"));
308 puts(_(" -s <subject> Specify a subject (must be enclosed in quotes if it has spaces)"));
309 puts(_(" -v Print the NeoMutt version and compile-time definitions and exit"));
310 puts(_(" -vv Print the NeoMutt license and copyright information and exit"));
311 puts(_(" -y Start NeoMutt with a listing of all defined mailboxes"));
312 puts(_(" -Z Open the first mailbox with new message or exit immediately with\n"
313 " exit code 1 if none is found in all defined mailboxes"));
314 puts(_(" -z Open the first or specified (-f) mailbox if it holds any message\n"
315 " or exit immediately with exit code 1 otherwise"));
316 // clang-format on
317
318 fflush(stdout);
319 return !ferror(stdout);
320}
321
327static int start_curses(void)
328{
329 km_init(); /* must come before mutt_init */
330
331 /* should come before initscr() so that ncurses 4.2 doesn't try to install
332 * its own SIGWINCH handler */
334
335 if (!initscr())
336 {
337 mutt_error(_("Error initializing terminal"));
338 return 1;
339 }
342 keypad(stdscr, true);
343 cbreak();
344 noecho();
345 nonl();
346 typeahead(-1); /* simulate smooth scrolling */
347 meta(stdscr, true);
349 /* Now that curses is set up, we drop back to normal screen mode.
350 * This simplifies displaying error messages to the user.
351 * The first call to refresh() will swap us back to curses screen mode. */
352 endwin();
353 return 0;
354}
355
359static void init_locale(void)
360{
361 setlocale(LC_ALL, "");
362
363#ifdef ENABLE_NLS
364 const char *domdir = mutt_str_getenv("TEXTDOMAINDIR");
365 if (domdir)
366 bindtextdomain(PACKAGE, domdir);
367 else
368 bindtextdomain(PACKAGE, MUTTLOCALEDIR);
369 textdomain(PACKAGE);
370#endif
371#ifndef LOCALES_HACK
372 /* Do we have a locale definition? */
373 if (mutt_str_getenv("LC_ALL") || mutt_str_getenv("LANG") || mutt_str_getenv("LC_CTYPE"))
374 {
375 OptLocales = true;
376 }
377#endif
378}
379
387static bool get_user_info(struct ConfigSet *cs)
388{
389 const char *shell = mutt_str_getenv("SHELL");
390 if (shell)
391 cs_str_initial_set(cs, "shell", shell, NULL);
392
393 /* Get some information about the user */
394 struct passwd *pw = getpwuid(getuid());
395 if (pw)
396 {
397 if (!Username)
398 Username = mutt_str_dup(pw->pw_name);
399 if (!HomeDir)
400 HomeDir = mutt_str_dup(pw->pw_dir);
401 if (!shell)
402 cs_str_initial_set(cs, "shell", pw->pw_shell, NULL);
403 }
404
405 if (!Username)
406 {
407 mutt_error(_("unable to determine username"));
408 return false; // TEST05: neomutt (unset $USER, delete user from /etc/passwd)
409 }
410
411 if (!HomeDir)
412 {
413 mutt_error(_("unable to determine home directory"));
414 return false; // TEST06: neomutt (unset $HOME, delete user from /etc/passwd)
415 }
416
417 cs_str_reset(cs, "shell", NULL);
418 return true;
419}
420
428static void log_translation(void)
429{
430 const char *header = ""; // Do not merge these two lines
431 header = _(header); // otherwise the .po files will end up badly ordered
432 const char *label = "Language:"; // the start of the lookup/needle
433 const char *lang = mutt_istr_find(header, label);
434 int len = 64;
435 if (lang)
436 {
437 lang += strlen(label); // skip label
438 SKIPWS(lang);
439 char *nl = strchr(lang, '\n');
440 if (nl)
441 len = (nl - lang);
442 }
443 else
444 {
445 lang = "NONE";
446 }
447
448 mutt_debug(LL_DEBUG1, "Translation: %.*s\n", len, lang);
449}
450
455{
456 static time_t last_run = 0;
457
458 if (nc->event_type != NT_TIMEOUT)
459 return 0;
460
461 const short c_timeout = cs_subset_number(NeoMutt->sub, "timeout");
462 if (c_timeout <= 0)
463 goto done;
464
465 time_t now = mutt_date_now();
466 if (now < (last_run + c_timeout))
467 goto done;
468
469 // Limit hook to running under the Index or Pager
471 struct MuttWindow *dlg = dialog_find(focus);
472 if (!dlg || (dlg->type != WT_DLG_INDEX))
473 goto done;
474
475 last_run = now;
477
478done:
479 mutt_debug(LL_DEBUG5, "timeout done\n");
480 return 0;
481}
482
491int
492#ifdef ENABLE_FUZZ_TESTS
493disabled_main
494#else
496#endif
497(int argc, char *argv[], char *envp[])
498{
499 char *subject = NULL;
500 char *include_file = NULL;
501 char *draft_file = NULL;
502 char *new_type = NULL;
503 char *dlevel = NULL;
504 char *dfile = NULL;
505#ifdef USE_NNTP
506 const char *cli_nntp = NULL;
507#endif
508 struct Email *e = NULL;
509 struct ListHead attach = STAILQ_HEAD_INITIALIZER(attach);
510 struct ListHead commands = STAILQ_HEAD_INITIALIZER(commands);
511 struct ListHead queries = STAILQ_HEAD_INITIALIZER(queries);
512 struct ListHead alias_queries = STAILQ_HEAD_INITIALIZER(alias_queries);
513 struct ListHead cc_list = STAILQ_HEAD_INITIALIZER(cc_list);
514 struct ListHead bcc_list = STAILQ_HEAD_INITIALIZER(bcc_list);
515 SendFlags sendflags = SEND_NO_FLAGS;
517 int version = 0;
518 int i;
519 bool explicit_folder = false;
520 bool dump_variables = false;
521 bool one_liner = false;
522 bool hide_sensitive = false;
523 bool batch_mode = false;
524 bool edit_infile = false;
525 int double_dash = argc, nargc = 1;
526 int rc = 1;
527 bool repeat_error = false;
528 struct Buffer folder = buf_make(0);
529 struct Buffer expanded_infile = buf_make(0);
530 struct Buffer tempfile = buf_make(0);
531 struct ConfigSet *cs = NULL;
532
534
535 /* sanity check against stupid administrators */
536 if (getegid() != getgid())
537 {
538 mutt_error("%s: I don't want to run with privileges!", (argc != 0) ? argv[0] : "neomutt");
539 goto main_exit; // TEST01: neomutt (as root, chgrp mail neomutt; chmod +s neomutt)
540 }
541
542 init_locale();
543
544 umask(077);
545
546 EnvList = envlist_init(envp);
547 for (optind = 1; optind < double_dash;)
548 {
549 /* We're getopt'ing POSIXLY, so we'll be here every time getopt()
550 * encounters a non-option. That could be a file to attach
551 * (all non-options between -a and --) or it could be an address
552 * (which gets collapsed to the front of argv). */
553 for (; optind < argc; optind++)
554 {
555 if ((argv[optind][0] == '-') && (argv[optind][1] != '\0'))
556 {
557 if ((argv[optind][1] == '-') && (argv[optind][2] == '\0'))
558 double_dash = optind; /* quit outer loop after getopt */
559 break; /* drop through to getopt */
560 }
561
562 /* non-option, either an attachment or address */
563 if (!STAILQ_EMPTY(&attach))
564 mutt_list_insert_tail(&attach, mutt_str_dup(argv[optind]));
565 else
566 argv[nargc++] = argv[optind];
567 }
568
569 /* USE_NNTP 'g:G' */
570 i = getopt(argc, argv, "+A:a:Bb:F:f:c:Dd:l:Ee:g:GH:i:hm:nOpQ:RSs:TvxyzZ");
571 if (i != EOF)
572 {
573 switch (i)
574 {
575 case 'A':
576 mutt_list_insert_tail(&alias_queries, mutt_str_dup(optarg));
577 break;
578 case 'a':
579 mutt_list_insert_tail(&attach, mutt_str_dup(optarg));
580 break;
581 case 'B':
582 batch_mode = true;
583 break;
584 case 'b':
585 mutt_list_insert_tail(&bcc_list, mutt_str_dup(optarg));
586 break;
587 case 'c':
588 mutt_list_insert_tail(&cc_list, mutt_str_dup(optarg));
589 break;
590 case 'D':
591 dump_variables = true;
592 break;
593 case 'd':
594 dlevel = optarg;
595 break;
596 case 'E':
597 edit_infile = true;
598 break;
599 case 'e':
600 mutt_list_insert_tail(&commands, mutt_str_dup(optarg));
601 break;
602 case 'F':
604 break;
605 case 'f':
606 buf_strcpy(&folder, optarg);
607 explicit_folder = true;
608 break;
609#ifdef USE_NNTP
610 case 'g': /* Specify a news server */
611 cli_nntp = optarg;
612 /* fallthrough */
613 case 'G': /* List of newsgroups */
615 break;
616#endif
617 case 'H':
618 draft_file = optarg;
619 break;
620 case 'i':
621 include_file = optarg;
622 break;
623 case 'l':
624 dfile = optarg;
625 break;
626 case 'm':
627 new_type = optarg;
628 break;
629 case 'n':
630 flags |= MUTT_CLI_NOSYSRC;
631 break;
632 case 'O':
633 one_liner = true;
634 break;
635 case 'p':
636 sendflags |= SEND_POSTPONED;
637 break;
638 case 'Q':
639 mutt_list_insert_tail(&queries, mutt_str_dup(optarg));
640 break;
641 case 'R':
642 flags |= MUTT_CLI_RO; /* read-only mode */
643 break;
644 case 'S':
645 hide_sensitive = true;
646 break;
647 case 's':
648 subject = optarg;
649 break;
650 case 'v':
651 version++;
652 break;
653 case 'y': /* My special hack mode */
654 flags |= MUTT_CLI_SELECT;
655 break;
656 case 'Z':
658 break;
659 case 'z':
660 flags |= MUTT_CLI_IGNORE;
661 break;
662 default:
663 OptNoCurses = true;
664 if (usage())
665 goto main_ok; // TEST03: neomutt -9
666 else
667 goto main_curses;
668 }
669 }
670 }
671
672 /* collapse remaining argv */
673 while (optind < argc)
674 argv[nargc++] = argv[optind++];
675 optind = 1;
676 argc = nargc;
677
678 if (version > 0)
679 {
681 bool done;
682 if (version == 1)
683 done = print_version(stdout);
684 else
685 done = print_copyright();
686 OptNoCurses = true;
687 if (done)
688 goto main_ok; // TEST04: neomutt -v
689 else
690 goto main_curses;
691 }
692
695
696 cs = cs_new(500);
697 if (!cs)
698 goto main_curses;
699
700 NeoMutt = neomutt_new(cs);
701 init_config(cs);
702 subjrx_init();
703 attach_init();
705
706#ifdef USE_DEBUG_NOTIFY
708#endif
709
710 if (!get_user_info(cs))
711 goto main_exit;
712
713 reset_tilde(cs);
714
715 if (dfile)
716 {
717 cs_str_initial_set(cs, "debug_file", dfile, NULL);
718 cs_str_reset(cs, "debug_file", NULL);
719 }
720
721 if (dlevel)
722 {
723 short num = 0;
724 if (!mutt_str_atos_full(dlevel, &num) || (num < LL_MESSAGE) || (num >= LL_MAX))
725 {
726 mutt_error(_("Error: value '%s' is invalid for -d"), dlevel);
727 goto main_exit; // TEST07: neomutt -d xyz
728 }
729 cs_str_initial_set(cs, "debug_level", dlevel, NULL);
730 cs_str_reset(cs, "debug_level", NULL);
731 }
732
736
737 if (!STAILQ_EMPTY(&cc_list) || !STAILQ_EMPTY(&bcc_list))
738 {
739 e = email_new();
740 e->env = mutt_env_new();
741
742 struct ListNode *np = NULL;
743 STAILQ_FOREACH(np, &bcc_list, entries)
744 {
745 mutt_addrlist_parse(&e->env->bcc, np->data);
746 }
747
748 STAILQ_FOREACH(np, &cc_list, entries)
749 {
750 mutt_addrlist_parse(&e->env->cc, np->data);
751 }
752
753 mutt_list_free(&bcc_list);
754 mutt_list_free(&cc_list);
755 }
756
757 /* Check for a batch send. */
758 if (!isatty(0) || !STAILQ_EMPTY(&queries) || !STAILQ_EMPTY(&alias_queries) ||
759 dump_variables || batch_mode)
760 {
761 OptNoCurses = true;
762 sendflags = SEND_BATCH;
765 }
766
767 /* Check to make sure stdout is available in curses mode. */
768 if (!OptNoCurses && !isatty(1))
769 goto main_curses;
770
771 /* Always create the mutt_windows because batch mode has some shared code
772 * paths that end up referencing them. */
773 rootwin_new();
774
775 /* This must come before mutt_init() because curses needs to be started
776 * before calling the init_pair() function to set the color scheme. */
777 if (!OptNoCurses)
778 {
779 int crc = start_curses();
780 if (crc != 0)
781 goto main_curses; // TEST08: can't test -- fake term?
782
783 /* check whether terminal status is supported (must follow curses init) */
786 }
787
788 /* set defaults and read init files */
789 int rc2 = mutt_init(cs, flags & MUTT_CLI_NOSYSRC, &commands);
790 if (rc2 != 0)
791 goto main_curses;
792
794
795 /* The command line overrides the config */
796 if (dlevel)
797 cs_str_reset(cs, "debug_level", NULL);
798 if (dfile)
799 cs_str_reset(cs, "debug_file", NULL);
800
801 if (mutt_log_start() < 0)
802 {
803 mutt_perror("log file");
804 goto main_exit;
805 }
806
807#ifdef USE_NNTP
808 {
809 /* "$news_server" precedence: command line, config file, environment, system file */
810 if (!cli_nntp)
811 cli_nntp = cs_subset_string(NeoMutt->sub, "news_server");
812
813 if (!cli_nntp)
814 cli_nntp = mutt_str_getenv("NNTPSERVER");
815
816 if (!cli_nntp)
817 {
818 char buf[1024] = { 0 };
819 cli_nntp = mutt_file_read_keyword(SYSCONFDIR "/nntpserver", buf, sizeof(buf));
820 }
821
822 if (cli_nntp)
823 {
824 cs_str_initial_set(cs, "news_server", cli_nntp, NULL);
825 cs_str_reset(cs, "news_server", NULL);
826 }
827 }
828#endif
829
830 /* Initialize crypto backends. */
831 crypt_init();
832
833 if (new_type)
834 {
835 struct Buffer err = buf_make(0);
836 int r = cs_str_initial_set(cs, "mbox_type", new_type, &err);
837 if (CSR_RESULT(r) != CSR_SUCCESS)
838 {
839 mutt_error("%s", err.data);
840 buf_dealloc(&err);
841 goto main_curses;
842 }
843 cs_str_reset(cs, "mbox_type", NULL);
844 }
845
846 if (!STAILQ_EMPTY(&queries))
847 {
848 rc = mutt_query_variables(&queries, one_liner);
849 goto main_curses;
850 }
851
852 if (dump_variables)
853 {
855 if (hide_sensitive)
856 cdflags |= CS_DUMP_HIDE_SENSITIVE;
857 if (one_liner)
858 cdflags |= CS_DUMP_SHOW_DOCS;
859 dump_config(cs, cdflags, stdout);
860 goto main_ok; // TEST18: neomutt -D
861 }
862
863 if (!STAILQ_EMPTY(&alias_queries))
864 {
865 rc = 0;
866 for (; optind < argc; optind++)
867 mutt_list_insert_tail(&alias_queries, mutt_str_dup(argv[optind]));
868 struct ListNode *np = NULL;
869 STAILQ_FOREACH(np, &alias_queries, entries)
870 {
871 struct AddressList *al = alias_lookup(np->data);
872 if (al)
873 {
874 /* output in machine-readable form */
875 mutt_addrlist_to_intl(al, NULL);
876 struct Buffer *buf = buf_pool_get();
877 mutt_addrlist_write(al, buf, false);
878 printf("%s\n", buf_string(buf));
879 buf_pool_release(&buf);
880 }
881 else
882 {
883 rc = 1;
884 printf("%s\n", np->data); // TEST19: neomutt -A unknown
885 }
886 }
887 mutt_list_free(&alias_queries);
888 goto main_curses; // TEST20: neomutt -A alias
889 }
890
891 if (!OptNoCurses)
892 {
894 clear();
898 }
899
900#ifdef USE_AUTOCRYPT
901 /* Initialize autocrypt after curses messages are working,
902 * because of the initial account setup screens. */
903 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
904 if (c_autocrypt)
905 mutt_autocrypt_init(!(sendflags & SEND_BATCH));
906#endif
907
908 /* Create the `$folder` directory if it doesn't exist. */
909 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
910 if (!OptNoCurses && c_folder)
911 {
912 struct stat st = { 0 };
913 struct Buffer *fpath = buf_pool_get();
914
915 buf_strcpy(fpath, c_folder);
916 buf_expand_path(fpath);
917 bool skip = false;
918#ifdef USE_IMAP
919 /* we're not connected yet - skip mail folder creation */
920 skip |= (imap_path_probe(buf_string(fpath), NULL) == MUTT_IMAP);
921#endif
922#ifdef USE_POP
923 skip |= (pop_path_probe(buf_string(fpath), NULL) == MUTT_POP);
924#endif
925#ifdef USE_NNTP
926 skip |= (nntp_path_probe(buf_string(fpath), NULL) == MUTT_NNTP);
927#endif
928 if (!skip && (stat(buf_string(fpath), &st) == -1) && (errno == ENOENT))
929 {
930 char msg2[256];
931 snprintf(msg2, sizeof(msg2), _("%s does not exist. Create it?"), c_folder);
932 if (query_yesorno(msg2, MUTT_YES) == MUTT_YES)
933 {
934 if ((mkdir(buf_string(fpath), 0700) == -1) && (errno != EEXIST))
935 mutt_error(_("Can't create %s: %s"), c_folder, strerror(errno)); // TEST21: neomutt -n -F /dev/null (and ~/Mail doesn't exist)
936 }
937 }
938 buf_pool_release(&fpath);
939 }
940
941 if (batch_mode)
942 {
943 goto main_ok; // TEST22: neomutt -B
944 }
945 StartupComplete = true;
946
951
952 if (sendflags & SEND_POSTPONED)
953 {
954 if (!OptNoCurses)
956 if (mutt_send_message(SEND_POSTPONED, NULL, NULL, NULL, NULL, NeoMutt->sub) == 0)
957 rc = 0;
958 // TEST23: neomutt -p (postponed message, cancel)
959 // TEST24: neomutt -p (no postponed message)
961 repeat_error = true;
962 goto main_curses;
963 }
964 else if (subject || e || draft_file || include_file ||
965 !STAILQ_EMPTY(&attach) || (optind < argc))
966 {
967 FILE *fp_in = NULL;
968 FILE *fp_out = NULL;
969 char *infile = NULL;
970 char *bodytext = NULL;
971 const char *bodyfile = NULL;
972 int rv = 0;
973
974 if (!OptNoCurses)
976
977 if (!e)
978 e = email_new();
979 if (!e->env)
980 e->env = mutt_env_new();
981
982 for (i = optind; i < argc; i++)
983 {
984 if (url_check_scheme(argv[i]) == U_MAILTO)
985 {
986 if (!mutt_parse_mailto(e->env, &bodytext, argv[i]))
987 {
988 mutt_error(_("Failed to parse mailto: link"));
989 email_free(&e);
990 goto main_curses; // TEST25: neomutt mailto:?
991 }
992 }
993 else
994 {
995 mutt_addrlist_parse(&e->env->to, argv[i]);
996 }
997 }
998
999 const bool c_auto_edit = cs_subset_bool(NeoMutt->sub, "auto_edit");
1000 if (!draft_file && c_auto_edit && TAILQ_EMPTY(&e->env->to) &&
1001 TAILQ_EMPTY(&e->env->cc))
1002 {
1003 mutt_error(_("No recipients specified"));
1004 email_free(&e);
1005 goto main_curses; // TEST26: neomutt -s test (with auto_edit=yes)
1006 }
1007
1008 if (subject)
1009 {
1010 mutt_str_replace(&e->env->subject, subject);
1011 }
1012
1013 if (draft_file)
1014 {
1015 infile = draft_file;
1016 include_file = NULL;
1017 }
1018 else if (include_file)
1019 {
1020 infile = include_file;
1021 }
1022 else
1023 {
1024 edit_infile = false;
1025 }
1026
1027 if (infile || bodytext)
1028 {
1029 /* Prepare fp_in and expanded_infile. */
1030 if (infile)
1031 {
1032 if (mutt_str_equal("-", infile))
1033 {
1034 if (edit_infile)
1035 {
1036 mutt_error(_("Can't use -E flag with stdin"));
1037 email_free(&e);
1038 goto main_curses; // TEST27: neomutt -E -H -
1039 }
1040 fp_in = stdin;
1041 }
1042 else
1043 {
1044 buf_strcpy(&expanded_infile, infile);
1045 buf_expand_path(&expanded_infile);
1046 fp_in = fopen(buf_string(&expanded_infile), "r");
1047 if (!fp_in)
1048 {
1049 mutt_perror("%s", buf_string(&expanded_infile));
1050 email_free(&e);
1051 goto main_curses; // TEST28: neomutt -E -H missing
1052 }
1053 }
1054 }
1055
1056 if (edit_infile)
1057 {
1058 /* If editing the infile, keep it around afterwards so
1059 * it doesn't get unlinked, and we can rebuild the draft_file */
1060 sendflags |= SEND_NO_FREE_HEADER;
1061 }
1062 else
1063 {
1064 /* Copy input to a tempfile, and re-point fp_in to the tempfile.
1065 * Note: stdin is always copied to a tempfile, ensuring draft_file
1066 * can stat and get the correct st_size below. */
1067 buf_mktemp(&tempfile);
1068
1069 fp_out = mutt_file_fopen(buf_string(&tempfile), "w");
1070 if (!fp_out)
1071 {
1072 mutt_file_fclose(&fp_in);
1073 mutt_perror("%s", buf_string(&tempfile));
1074 email_free(&e);
1075 goto main_curses; // TEST29: neomutt -H existing-file (where tmpdir=/path/to/FILE blocking tmpdir)
1076 }
1077 if (fp_in)
1078 {
1079 mutt_file_copy_stream(fp_in, fp_out);
1080 if (fp_in != stdin)
1081 mutt_file_fclose(&fp_in);
1082 }
1083 else if (bodytext)
1084 {
1085 fputs(bodytext, fp_out);
1086 }
1087 mutt_file_fclose(&fp_out);
1088
1089 fp_in = fopen(buf_string(&tempfile), "r");
1090 if (!fp_in)
1091 {
1092 mutt_perror("%s", buf_string(&tempfile));
1093 email_free(&e);
1094 goto main_curses; // TEST30: can't test
1095 }
1096 }
1097
1098 /* Parse the draft_file into the full Email/Body structure.
1099 * Set SEND_DRAFT_FILE so mutt_send_message doesn't overwrite
1100 * our e->body. */
1101 if (draft_file)
1102 {
1103 struct Envelope *opts_env = e->env;
1104 struct stat st = { 0 };
1105
1106 sendflags |= SEND_DRAFT_FILE;
1107
1108 /* Set up a tmp Email with just enough information so that
1109 * mutt_prepare_template() can parse the message in fp_in. */
1110 struct Email *e_tmp = email_new();
1111 e_tmp->offset = 0;
1112 e_tmp->body = mutt_body_new();
1113 if (fstat(fileno(fp_in), &st) != 0)
1114 {
1115 mutt_perror("%s", draft_file);
1116 email_free(&e);
1117 email_free(&e_tmp);
1118 goto main_curses; // TEST31: can't test
1119 }
1120 e_tmp->body->length = st.st_size;
1121
1122 if (mutt_prepare_template(fp_in, NULL, e, e_tmp, false) < 0)
1123 {
1124 mutt_error(_("Can't parse message template: %s"), draft_file);
1125 email_free(&e);
1126 email_free(&e_tmp);
1127 goto main_curses;
1128 }
1129
1130 /* Scan for neomutt header to set `$resume_draft_files` */
1131 struct ListNode *np = NULL, *tmp = NULL;
1132 const bool c_resume_edited_draft_files = cs_subset_bool(NeoMutt->sub, "resume_edited_draft_files");
1133 STAILQ_FOREACH_SAFE(np, &e->env->userhdrs, entries, tmp)
1134 {
1135 if (mutt_istr_startswith(np->data, "X-Mutt-Resume-Draft:"))
1136 {
1137 if (c_resume_edited_draft_files)
1138 cs_str_native_set(cs, "resume_draft_files", true, NULL);
1139
1140 STAILQ_REMOVE(&e->env->userhdrs, np, ListNode, entries);
1141 FREE(&np->data);
1142 FREE(&np);
1143 }
1144 }
1145
1146 mutt_addrlist_copy(&e->env->to, &opts_env->to, false);
1147 mutt_addrlist_copy(&e->env->cc, &opts_env->cc, false);
1148 mutt_addrlist_copy(&e->env->bcc, &opts_env->bcc, false);
1149 if (opts_env->subject)
1150 mutt_str_replace(&e->env->subject, opts_env->subject);
1151
1152 mutt_env_free(&opts_env);
1153 email_free(&e_tmp);
1154 }
1155 /* Editing the include_file: pass it directly in.
1156 * Note that SEND_NO_FREE_HEADER is set above so it isn't unlinked. */
1157 else if (edit_infile)
1158 bodyfile = buf_string(&expanded_infile);
1159 // For bodytext and unedited include_file: use the tempfile.
1160 else
1161 bodyfile = buf_string(&tempfile);
1162
1163 mutt_file_fclose(&fp_in);
1164 }
1165
1166 FREE(&bodytext);
1167
1168 if (!STAILQ_EMPTY(&attach))
1169 {
1170 struct Body *b = e->body;
1171
1172 while (b && b->next)
1173 b = b->next;
1174
1175 struct ListNode *np = NULL;
1176 STAILQ_FOREACH(np, &attach, entries)
1177 {
1178 if (b)
1179 {
1181 b = b->next;
1182 }
1183 else
1184 {
1186 e->body = b;
1187 }
1188 if (!b)
1189 {
1190 mutt_error(_("%s: unable to attach file"), np->data);
1191 mutt_list_free(&attach);
1192 email_free(&e);
1193 goto main_curses; // TEST32: neomutt john@example.com -a missing
1194 }
1195 }
1196 mutt_list_free(&attach);
1197 }
1198
1199 rv = mutt_send_message(sendflags, e, bodyfile, NULL, NULL, NeoMutt->sub);
1200 /* We WANT the "Mail sent." and any possible, later error */
1202 if (ErrorBufMessage)
1203 mutt_message("%s", ErrorBuf);
1204
1205 if (edit_infile)
1206 {
1207 if (draft_file)
1208 {
1209 if (truncate(buf_string(&expanded_infile), 0) == -1)
1210 {
1211 mutt_perror("%s", buf_string(&expanded_infile));
1212 email_free(&e);
1213 goto main_curses; // TEST33: neomutt -H read-only -s test john@example.com -E
1214 }
1215 fp_out = mutt_file_fopen(buf_string(&expanded_infile), "a");
1216 if (!fp_out)
1217 {
1218 mutt_perror("%s", buf_string(&expanded_infile));
1219 email_free(&e);
1220 goto main_curses; // TEST34: can't test
1221 }
1222
1223 /* If the message was sent or postponed, these will already
1224 * have been done. */
1225 if (rv < 0)
1226 {
1227 if (e->body->next)
1228 e->body = mutt_make_multipart(e->body);
1230 mutt_prepare_envelope(e->env, false, NeoMutt->sub);
1231 mutt_env_to_intl(e->env, NULL, NULL);
1232 }
1233
1234 const bool c_crypt_protected_headers_read = cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_read");
1236 c_crypt_protected_headers_read &&
1238 NeoMutt->sub);
1239 const bool c_resume_edited_draft_files = cs_subset_bool(NeoMutt->sub, "resume_edited_draft_files");
1240 if (c_resume_edited_draft_files)
1241 fprintf(fp_out, "X-Mutt-Resume-Draft: 1\n");
1242 fputc('\n', fp_out);
1243 if ((mutt_write_mime_body(e->body, fp_out, NeoMutt->sub) == -1))
1244 {
1245 mutt_file_fclose(&fp_out);
1246 email_free(&e);
1247 goto main_curses; // TEST35: can't test
1248 }
1249 mutt_file_fclose(&fp_out);
1250 }
1251
1252 email_free(&e);
1253 }
1254
1255 /* !edit_infile && draft_file will leave the tempfile around */
1256 if (!buf_is_empty(&tempfile))
1257 unlink(buf_string(&tempfile));
1258
1260
1261 if (rv != 0)
1262 goto main_curses; // TEST36: neomutt -H existing -s test john@example.com -E (cancel sending)
1263 }
1264 else if (sendflags & SEND_BATCH)
1265 {
1266 /* This guards against invoking `neomutt < /dev/null` and accidentally
1267 * sending an email due to a my_hdr or other setting. */
1268 mutt_error(_("No recipients specified"));
1269 goto main_curses;
1270 }
1271 else
1272 {
1273 if (flags & MUTT_CLI_MAILBOX)
1274 {
1275#ifdef USE_IMAP
1276 const bool c_imap_passive = cs_subset_bool(NeoMutt->sub, "imap_passive");
1277 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", false, NULL);
1278#endif
1280 if (mutt_mailbox_check(NULL, csflags) == 0)
1281 {
1282 mutt_message(_("No mailbox with new mail"));
1283 goto main_curses; // TEST37: neomutt -Z (no new mail)
1284 }
1285 buf_reset(&folder);
1286 mutt_mailbox_next(NULL, &folder);
1287#ifdef USE_IMAP
1288 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", c_imap_passive, NULL);
1289#endif
1290 }
1291 else if (flags & MUTT_CLI_SELECT)
1292 {
1293#ifdef USE_NNTP
1294 if (flags & MUTT_CLI_NEWS)
1295 {
1296 const char *const c_news_server = cs_subset_string(NeoMutt->sub, "news_server");
1297 OptNews = true;
1298 struct Mailbox *m_cur = get_current_mailbox();
1299 CurrentNewsSrv = nntp_select_server(m_cur, c_news_server, false);
1300 if (!CurrentNewsSrv)
1301 goto main_curses; // TEST38: neomutt -G (unset news_server)
1302 }
1303 else
1304#endif
1306 {
1307 mutt_error(_("No incoming mailboxes defined"));
1308 goto main_curses; // TEST39: neomutt -n -F /dev/null -y
1309 }
1310 buf_reset(&folder);
1311 struct Mailbox *m_cur = get_current_mailbox();
1312 dlg_browser(&folder, MUTT_SEL_FOLDER | MUTT_SEL_MAILBOX, m_cur, NULL, NULL);
1313 if (buf_is_empty(&folder))
1314 {
1315 goto main_ok; // TEST40: neomutt -y (quit selection)
1316 }
1317 }
1318
1319 if (buf_is_empty(&folder))
1320 {
1321 const char *const c_spool_file = cs_subset_string(NeoMutt->sub, "spool_file");
1322 if (c_spool_file)
1323 {
1324 // Check if `$spool_file` corresponds a mailboxes' description.
1325 struct Mailbox *m_desc = mailbox_find_name(c_spool_file);
1326 if (m_desc)
1327 buf_strcpy(&folder, m_desc->realpath);
1328 else
1329 buf_strcpy(&folder, c_spool_file);
1330 }
1331 else if (c_folder)
1332 {
1333 buf_strcpy(&folder, c_folder);
1334 }
1335 /* else no folder */
1336 }
1337
1338#ifdef USE_NNTP
1339 if (OptNews)
1340 {
1341 OptNews = false;
1342 buf_alloc(&folder, PATH_MAX);
1344 }
1345 else
1346#endif
1347 buf_expand_path(&folder);
1348
1351
1352 if (flags & MUTT_CLI_IGNORE)
1353 {
1354 /* check to see if there are any messages in the folder */
1355 switch (mx_path_is_empty(&folder))
1356 {
1357 case -1:
1358 mutt_perror("%s", buf_string(&folder));
1359 goto main_curses; // TEST41: neomutt -z -f missing
1360 case 1:
1361 mutt_error(_("Mailbox is empty"));
1362 goto main_curses; // TEST42: neomutt -z -f /dev/null
1363 }
1364 }
1365
1366 mutt_folder_hook(buf_string(&folder), NULL);
1368 mutt_debug(LL_NOTIFY, "NT_GLOBAL_STARTUP\n");
1370
1372 window_redraw(NULL);
1373
1374 repeat_error = true;
1375 struct Mailbox *m = mx_resolve(buf_string(&folder));
1376 const bool c_read_only = cs_subset_bool(NeoMutt->sub, "read_only");
1377 if (!mx_mbox_open(m, ((flags & MUTT_CLI_RO) || c_read_only) ? MUTT_READONLY : MUTT_OPEN_NO_FLAGS))
1378 {
1379 if (m->account)
1381
1382 mailbox_free(&m);
1383 mutt_error(_("Unable to open mailbox %s"), buf_string(&folder));
1384 repeat_error = false;
1385 }
1386 if (m || !explicit_folder)
1387 {
1388 struct MuttWindow *dlg = index_pager_init();
1389 dialog_push(dlg);
1390
1392 m = dlg_index(dlg, m);
1394 mailbox_free(&m);
1395
1396 dialog_pop();
1397 mutt_window_free(&dlg);
1399 repeat_error = false;
1400 }
1401#ifdef USE_IMAP
1403#endif
1404#ifdef USE_SASL_CYRUS
1406#endif
1407#ifdef USE_SASL_GNU
1409#endif
1410#ifdef USE_AUTOCRYPT
1412#endif
1413 // TEST43: neomutt (no change to mailbox)
1414 // TEST44: neomutt (change mailbox)
1415 }
1416
1417main_ok:
1418 rc = 0;
1419main_curses:
1420 mutt_endwin();
1422 /* Repeat the last message to the user */
1423 if (repeat_error && ErrorBufMessage)
1424 puts(ErrorBuf);
1425main_exit:
1426 if (NeoMutt && NeoMutt->sub)
1427 {
1432 }
1433 mutt_list_free(&commands);
1435 buf_dealloc(&folder);
1436 buf_dealloc(&expanded_infile);
1437 buf_dealloc(&tempfile);
1438 mutt_list_free(&queries);
1445 menu_cleanup();
1446 crypt_cleanup();
1456 cs_free(&cs);
1459 mutt_log_stop();
1460 return rc;
1461}
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition: account.c:97
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:762
size_t mutt_addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display)
Write an Address to a buffer.
Definition: address.c:1207
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:478
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1294
Email Address Handling.
Email Aliases.
struct AddressList * alias_lookup(const char *name)
Find an Alias.
Definition: alias.c:280
void alternates_cleanup(void)
Free the alternates lists.
Definition: alternates.c:49
void alternates_init(void)
Set up the alternates lists.
Definition: alternates.c:60
Alternate address handling.
GUI display the mailboxes in a side panel.
void attach_init(void)
Set up the attachments lists.
Definition: attachments.c:105
void attach_cleanup(void)
Free the attachments lists.
Definition: attachments.c:91
Autocrypt end-to-end encryption.
void mutt_autocrypt_cleanup(void)
Shutdown Autocrypt.
Definition: autocrypt.c:129
int mutt_autocrypt_init(bool can_create)
Initialise Autocrypt.
Definition: autocrypt.c:97
void show_backtrace(void)
Log the program's call stack.
Definition: backtrace.c:39
Select a Mailbox from a list.
#define MUTT_SEL_MAILBOX
Select a mailbox.
Definition: lib.h:58
#define MUTT_SEL_FOLDER
Select a local directory.
Definition: lib.h:60
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:389
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:88
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:303
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:70
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:407
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:349
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
Color and attribute parsing.
void mutt_colors_init(void)
Initialize colours.
Definition: color.c:89
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:57
bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)
Write all the config to a file.
Definition: dump.c:165
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
Convenience wrapper for the config headers.
char * HomeDir
User's home directory.
Definition: globals.c:39
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:172
int cs_str_initial_set(const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
Set the initial value of a config item.
Definition: set.c:502
void cs_free(struct ConfigSet **ptr)
Free a Config Set.
Definition: set.c:138
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:437
struct ConfigSet * cs_new(size_t size)
Create a new Config Set.
Definition: set.c:124
int cs_he_reset(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.c:390
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:781
int cs_he_initial_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Set the initial value of a config item.
Definition: set.c:460
int cs_he_initial_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get the initial, or parent, value of a config item.
Definition: set.c:528
#define CSR_RESULT(x)
Definition: set.h:52
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
void config_cache_cleanup(void)
Cleanup the cache of charset config variables.
Definition: config_cache.c:144
Connection Library.
Convenience wrapper for the core headers.
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
Definition: crypt.c:1089
void crypto_module_cleanup(void)
Clean up the crypto modules.
Definition: crypt_mod.c:83
void crypt_cleanup(void)
Clean up backend.
Definition: cryptglue.c:142
void crypt_init(void)
Initialise the crypto backends.
Definition: cryptglue.c:94
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:154
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: get.c:57
Convenience wrapper for the debug headers.
int debug_all_observer(struct NotifyCallback *nc)
Definition: notify.c:205
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.
Definition: dlg_browser.c:159
struct MuttWindow * index_pager_init(void)
Allocate the Windows for the Index/Pager.
Definition: dlg_index.c:1405
#define CS_DUMP_HIDE_SENSITIVE
Obscure sensitive information like passwords.
Definition: dump.h:37
uint16_t ConfigDumpFlags
Flags for dump_config(), e.g. CS_DUMP_ONLY_CHANGED.
Definition: dump.h:34
#define CS_DUMP_NO_FLAGS
No flags are set.
Definition: dump.h:35
#define CS_DUMP_SHOW_DOCS
Show one-liner documentation for the config item.
Definition: dump.h:45
struct Body * mutt_body_new(void)
Create a new Body.
Definition: body.c:43
struct Email * email_new(void)
Create a new Email.
Definition: email.c:78
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:44
Structs that make up an email.
bool mutt_parse_mailto(struct Envelope *env, char **body, const char *src)
Parse a mailto:// url.
Definition: parse.c:1713
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:328
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:97
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition: envelope.c:43
void envlist_free(char ***envp)
Free the private copy of the environment.
Definition: envlist.c:41
char ** envlist_init(char **envp)
Create a copy of the environment.
Definition: envlist.c:57
void external_cleanup(void)
Clean up commands globals.
Definition: external.c:82
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:262
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:636
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen)
Read a keyword from a file.
Definition: file.c:1447
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:76
char * LastFolder
Previously selected mailbox.
Definition: globals.c:45
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:79
char ErrorBuf[1024]
Copy of the last error message.
Definition: globals.c:37
bool ErrorBufMessage
true if the last message was an error
Definition: globals.c:36
char * CurrentFolder
Currently selected mailbox.
Definition: globals.c:44
struct ListHead Muttrc
List of config files to read.
Definition: globals.c:53
char * Username
User's login name.
Definition: globals.c:42
char ** EnvList
Private copy of the environment variables.
Definition: globals.c:85
Global variables.
void dlg_browser(struct Buffer *file, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
Let the user select a file -.
Definition: dlg_browser.c:1248
struct Mailbox * dlg_index(struct MuttWindow *dlg, struct Mailbox *m_init)
Display a list of emails -.
Definition: dlg_index.c:1064
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:397
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:440
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 -.
Definition: mutt_logging.c:87
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
#define mutt_perror(...)
Definition: logging2.h:93
enum MailboxType nntp_path_probe(const char *path, const struct stat *st)
Is this an NNTP Mailbox? - Implements MxOps::path_probe() -.
Definition: nntp.c:2734
enum MailboxType pop_path_probe(const char *path, const struct stat *st)
Is this a POP Mailbox? - Implements MxOps::path_probe() -.
Definition: pop.c:1154
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
Definition: imap.c:2329
int main_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: init.c:265
int main_hist_observer(struct NotifyCallback *nc)
Notification that a Config Variable has change.
Definition: history.c:700
int main_timeout_observer(struct NotifyCallback *nc)
Notification that a timeout has occurred - Implements observer_t -.
Definition: main.c:454
int main_log_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: mutt_logging.c:284
void mutt_gsasl_cleanup(void)
Shutdown GNU SASL library.
Definition: gsasl.c:148
Convenience wrapper for the gui headers.
int mutt_rfc822_write_header(FILE *fp, struct Envelope *env, struct Body *attach, enum MuttWriteHeaderMode mode, bool privacy, bool hide_protected_subject, struct ConfigSubset *sub)
Write out one RFC822 header line.
Definition: header.c:575
@ MUTT_WRITE_HEADER_POSTPONE
A postponed Email, just the envelope info.
Definition: header.h:42
Read/write command history from/to a file.
void mutt_timeout_hook(void)
Execute any timeout hooks.
Definition: hook.c:891
void mutt_startup_shutdown_hook(HookFlags type)
Execute any startup/shutdown hooks.
Definition: hook.c:927
void mutt_folder_hook(const char *path, const char *desc)
Perform a folder hook.
Definition: hook.c:588
Parse and execute user-defined hooks.
#define MUTT_STARTUP_HOOK
startup-hook: run when starting NeoMutt
Definition: hook.h:57
IMAP network mailbox.
void imap_logout_all(void)
Close all open connections.
Definition: imap.c:546
GUI manage the main index (list of emails)
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition: index.c:662
int mutt_query_variables(struct ListHead *queries, bool show_docs)
Implement the -Q command line flag.
Definition: init.c:617
int mutt_init(struct ConfigSet *cs, bool skip_sys_rc, struct ListHead *commands)
Initialise NeoMutt.
Definition: init.c:321
void mutt_opts_cleanup(void)
Clean up before quitting.
Definition: init.c:265
Config/command parsing.
void init_config(struct ConfigSet *cs)
Initialise the config system.
Definition: mutt_config.c:728
void km_init(void)
Initialise all the menu keybindings.
Definition: init.c:180
void mutt_keys_cleanup(void)
Free the key maps.
Definition: init.c:230
void init_extended_keys(void)
Initialise map of ncurses extended keys.
Definition: init.c:137
void mutt_init_abort_key(void)
Parse the abort_key config string.
Definition: init.c:243
Manage keymappings.
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
int(*) log_dispatcher_ MuttLogger)
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
@ LL_MESSAGE
Log informational message.
Definition: logging2.h:42
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
@ LL_MAX
Definition: logging2.h:50
void log_queue_empty(void)
Free the contents of the queue.
Definition: logging.c:323
void log_queue_set_max_size(int size)
Set a upper limit for the queue length.
Definition: logging.c:311
void log_queue_flush(log_dispatcher_t disp)
Replay the log queue.
Definition: logging.c:345
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:180
@ MUTT_POP
'POP3' Mailbox type
Definition: mailbox.h:52
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
#define MUTT_CLI_SELECT
-y Start with a list of all mailboxes
Definition: main.c:203
static void init_locale(void)
Initialise the Locale/NLS settings.
Definition: main.c:359
uint8_t CliFlags
Flags for command line options, e.g. MUTT_CLI_IGNORE.
Definition: main.c:197
static void log_translation(void)
Log the translation being used.
Definition: main.c:428
#define MUTT_CLI_MAILBOX
-Z Open first mailbox if is has new mail
Definition: main.c:200
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:236
static void reset_tilde(struct ConfigSet *cs)
Temporary measure.
Definition: main.c:213
static bool usage(void)
Display NeoMutt command line.
Definition: main.c:250
static int start_curses(void)
Start the Curses UI.
Definition: main.c:327
bool StartupComplete
When the config has been read.
Definition: main.c:194
static bool get_user_info(struct ConfigSet *cs)
Find the user's name, home and shell.
Definition: main.c:387
#define MUTT_CLI_RO
-R Open mailbox in read-only mode
Definition: main.c:202
#define MUTT_CLI_NO_FLAGS
No flags are set.
Definition: main.c:198
int main(int argc, char *argv[], char *envp[])
Start NeoMutt.
Definition: main.c:497
#define MUTT_CLI_IGNORE
-z Open first mailbox if it has mail
Definition: main.c:199
#define MUTT_CLI_NEWS
-g/-G Start with a list of all newsgroups
Definition: main.c:205
#define MUTT_CLI_NOSYSRC
-n Do not read the system-wide config file
Definition: main.c:201
bool OptLocales
(pseudo) set if user has valid locale definition
Definition: mbyte.c:43
#define FREE(x)
Definition: memory.h:45
#define mutt_array_size(x)
Definition: memory.h:38
GUI present the user with a selectable list.
void menu_cleanup(void)
Free the saved Menu searches.
Definition: menu.c:66
struct Body * mutt_make_multipart(struct Body *b)
Create a multipart email.
Definition: multipart.c:100
void mutt_ch_cache_cleanup(void)
Clean up the cached iconv handles and charset strings.
Definition: charset.c:1173
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:446
Convenience wrapper for the library headers.
#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
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:918
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
Definition: string.c:593
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:240
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:327
#define PATH_MAX
Definition: mutt.h:41
void mutt_temp_attachments_cleanup(void)
Delete all temporary attachments.
Definition: mutt_attach.c:1316
enum MuttCursorState mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:96
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:81
void mutt_resize_screen(void)
Update NeoMutt's opinion about the window size.
Definition: resize.c:74
@ MUTT_CURSOR_INVISIBLE
Hide the cursor.
Definition: mutt_curses.h:59
@ MUTT_CURSOR_VISIBLE
Display a normal cursor.
Definition: mutt_curses.h:60
void mutt_log_stop(void)
Close the log file.
Definition: mutt_logging.c:180
int mutt_log_start(void)
Enable file logging.
Definition: mutt_logging.c:247
void mutt_log_prep(void)
Prepare to log.
Definition: mutt_logging.c:170
NeoMutt Logging.
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:165
struct Mailbox * mutt_mailbox_next(struct Mailbox *m_cur, struct Buffer *s)
Incoming folders completion routine.
Definition: mutt_mailbox.c:370
Mailbox helper functions.
void mutt_signal_init(void)
Initialise the signal handling.
Definition: mutt_signal.c:131
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:634
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:202
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
Definition: mutt_window.c:668
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition: mutt_window.h:86
void buf_expand_path_regex(struct Buffer *buf, bool regex)
Create the canonical path (with regex char escaping)
Definition: muttlib.c:138
const char * mutt_make_version(void)
Generate the NeoMutt version string.
Definition: muttlib.c:1443
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:335
Some miscellaneous functions.
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:304
struct Mailbox * mx_resolve(const char *path_or_name)
Get a Mailbox from either a path or name.
Definition: mx.c:1766
int mx_path_is_empty(struct Buffer *path)
Is the mailbox empty.
Definition: mx.c:1274
API for mailboxes.
#define MUTT_READONLY
Open in read-only mode.
Definition: mxapi.h:43
#define MUTT_MAILBOX_CHECK_IMMEDIATE
Don't postpone the actual checking.
Definition: mxapi.h:56
#define MUTT_OPEN_NO_FLAGS
No flags are set.
Definition: mxapi.h:40
#define MUTT_MAILBOX_CHECK_FORCE
Ignore MailboxTime and check for new mail.
Definition: mxapi.h:54
uint8_t CheckStatsFlags
Flags for mutt_mailbox_check.
Definition: mxapi.h:52
API for encryption/signing of emails.
struct NeoMutt * neomutt_new(struct ConfigSet *cs)
Create the main NeoMutt object.
Definition: neomutt.c:44
void neomutt_free(struct NeoMutt **ptr)
Free a NeoMutt.
Definition: neomutt.c:80
@ NT_GLOBAL_STARTUP
NeoMutt is initialised.
Definition: neomutt.h:59
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:564
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
struct NntpAccountData * nntp_select_server(struct Mailbox *m, const char *server, bool leave_lock)
Open a connection to an NNTP server.
Definition: newsrc.c:1021
@ 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 Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
void buf_pool_cleanup(void)
Release the Buffer pool.
Definition: pool.c:67
POP network mailbox.
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:491
void mutt_prex_cleanup(void)
Cleanup heap memory allocated by compiled regexes.
Definition: prex.c:330
Prototypes for many functions.
@ 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:330
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_EMPTY(head)
Definition: queue.h:348
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
#define TAILQ_EMPTY(head)
Definition: queue.h:721
void rootwin_cleanup(void)
Free all the default Windows.
Definition: rootwin.c:202
void rootwin_new(void)
Create the default Windows.
Definition: rootwin.c:212
void mutt_sasl_cleanup(void)
Invoke when processing is complete.
Definition: sasl.c:785
int mutt_write_mime_body(struct Body *a, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
Definition: body.c:301
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:1580
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:2127
#define SEND_BATCH
Send email in batch mode (without user interaction)
Definition: send.h:45
#define SEND_NO_FREE_HEADER
Used by the -E flag.
Definition: send.h:49
#define SEND_DRAFT_FILE
Used by the -H flag.
Definition: send.h:50
#define SEND_POSTPONED
Recall a postponed email.
Definition: send.h:44
#define SEND_NO_FLAGS
No flags are set.
Definition: send.h:39
uint16_t SendFlags
Flags for mutt_send_message(), e.g. SEND_REPLY.
Definition: send.h:38
struct Body * mutt_make_file_attach(const char *path, struct ConfigSubset *sub)
Create a file attachment.
Definition: sendlib.c:605
void mutt_prepare_envelope(struct Envelope *env, bool final, struct ConfigSubset *sub)
Prepare an email header.
Definition: sendlib.c:778
#define SKIPWS(ch)
Definition: string2.h:45
The body of an email.
Definition: body.h:36
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
struct Body * next
next attachment in the list
Definition: body.h:71
String manipulation buffer.
Definition: buffer.h:34
size_t dsize
Length of data.
Definition: buffer.h:37
char * data
Pointer to data.
Definition: buffer.h:35
Container for lots of config items.
Definition: set.h:252
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
The envelope/body of an email.
Definition: email.h:37
struct Envelope * env
Envelope information.
Definition: email.h:66
struct Body * body
List of MIME parts.
Definition: email.h:67
LOFF_T offset
Where in the stream does this message begin?
Definition: email.h:69
The header of an Email.
Definition: envelope.h:57
struct ListHead userhdrs
user defined headers
Definition: envelope.h:87
struct AddressList to
Email's 'To' list.
Definition: envelope.h:60
struct AddressList cc
Email's 'Cc' list.
Definition: envelope.h:61
char * subject
Email's subject.
Definition: envelope.h:70
struct AddressList bcc
Email's 'Bcc' list.
Definition: envelope.h:62
The item stored in a Hash Table.
Definition: hash.h:44
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
A mailbox.
Definition: mailbox.h:79
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:128
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct Notify * notify_resize
Window resize notifications handler.
Definition: neomutt.h:43
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:46
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
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
void subjrx_init(void)
Create new Subject Regex List.
Definition: subjectrx.c:55
void subjrx_cleanup(void)
Free the Subject Regex List.
Definition: subjectrx.c:46
Subject Regex handling.
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:304
bool TsSupported
Terminal Setting is supported.
Definition: terminal.c:41
bool mutt_ts_capability(void)
Check terminal capabilities.
Definition: terminal.c:55
#define buf_mktemp(buf)
Definition: tmp.h:33
enum UrlScheme url_check_scheme(const char *str)
Check the protocol of a URL.
Definition: url.c:225
@ U_MAILTO
Url is mailto://.
Definition: url.h:45
bool print_copyright(void)
Print copyright message.
Definition: version.c:554
bool print_version(FILE *fp)
Print system and compile info to a file.
Definition: version.c:426
Display version and copyright about NeoMutt.