2 * Copyright (C) 1996-2007 Michael R. Elkins <me@mutt.org>
3 * Copyright (C) 1999-2007 Thomas Roessler <roessler@does-not-exist.org>
4 * Copyright (C) 2004 g10 Code GmbH
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include "mutt_curses.h"
32 #include "mutt_crypt.h"
33 #include "mutt_idna.h"
36 #include "mutt_sasl.h"
40 #include "imap/imap.h"
53 #include <sys/utsname.h>
60 #include <stringprep.h>
63 static const char *ReachingUs = N_("\
64 To contact the developers, please mail to <mutt-dev@mutt.org>.\n\
65 To report a bug, please visit http://bugs.mutt.org/.\n");
67 static const char *Notice = N_("\
68 Copyright (C) 1996-2008 Michael R. Elkins and others.\n\
69 Mutt comes with ABSOLUTELY NO WARRANTY; for details type `mutt -vv'.\n\
70 Mutt is free software, and you are welcome to redistribute it\n\
71 under certain conditions; type `mutt -vv' for details.\n");
73 static const char *Copyright = N_("\
74 Copyright (C) 1996-2007 Michael R. Elkins <me@mutt.org>\n\
75 Copyright (C) 1996-2002 Brandon Long <blong@fiction.net>\n\
76 Copyright (C) 1997-2007 Thomas Roessler <roessler@does-not-exist.org>\n\
77 Copyright (C) 1998-2005 Werner Koch <wk@isil.d.shuttle.de>\n\
78 Copyright (C) 1999-2008 Brendan Cully <brendan@kublai.com>\n\
79 Copyright (C) 1999-2002 Tommi Komulainen <Tommi.Komulainen@iki.fi>\n\
80 Copyright (C) 2000-2002 Edmund Grimley Evans <edmundo@rano.org>\n\
82 Many others not mentioned here contributed code, fixes,\n\
85 static const char *Licence = N_("\
86 This program is free software; you can redistribute it and/or modify\n\
87 it under the terms of the GNU General Public License as published by\n\
88 the Free Software Foundation; either version 2 of the License, or\n\
89 (at your option) any later version.\n\
91 This program is distributed in the hope that it will be useful,\n\
92 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
93 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
94 GNU General Public License for more details.\n");
95 static const char *Obtaining = N_("\
96 You should have received a copy of the GNU General Public License\n\
97 along with this program; if not, write to the Free Software\n\
98 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n\
101 void mutt_exit (int code)
107 static void mutt_usage (void)
109 puts (mutt_make_version ());
112 "usage: mutt [<options>] [-z] [-f <file> | -yZ]\n\
113 mutt [<options>] [-x] [-Hi <file>] [-s <subj>] [-bc <addr>] [-a <file> [...]] [--] <addr> [...]\n\
114 mutt [<options>] -p\n\
115 mutt [<options>] -A <alias> [...]\n\
116 mutt [<options>] -Q <query> [...]\n\
117 mutt [<options>] -D\n\
122 -A <alias>\texpand the given alias\n\
123 -a <file>\tattach a file to the message\n\
124 -b <address>\tspecify a blind carbon-copy (BCC) address\n\
125 -c <address>\tspecify a carbon-copy (CC) address\n\
126 -D\t\tprint the value of all variables to stdout");
128 puts _(" -d <level>\tlog debugging output to ~/.muttdebug0");
131 " -e <command>\tspecify a command to be executed after initialization\n\
132 -f <file>\tspecify which mailbox to read\n\
133 -F <file>\tspecify an alternate muttrc file\n\
134 -H <file>\tspecify a draft file to read header and body from\n\
135 -i <file>\tspecify a file which Mutt should include in the body\n\
136 -m <type>\tspecify a default mailbox type\n\
137 -n\t\tcauses Mutt not to read the system Muttrc\n\
138 -p\t\trecall a postponed message");
141 -Q <variable>\tquery a configuration variable\n\
142 -R\t\topen mailbox in read-only mode\n\
143 -s <subj>\tspecify a subject (must be in quotes if it has spaces)\n\
144 -v\t\tshow version and compile-time definitions\n\
145 -x\t\tsimulate the mailx send mode\n\
146 -y\t\tselect a mailbox specified in your `mailboxes' list\n\
147 -z\t\texit immediately if there are no messages in the mailbox\n\
148 -Z\t\topen the first folder with new message, exit immediately if none\n\
149 -h\t\tthis help message");
150 puts _(" --\t\ttreat remaining arguments as addr even if starting with a dash\n\
151 \t\twhen using -a with multiple filenames using -- is mandatory");
156 static void show_version (void)
160 puts (mutt_make_version());
166 printf ("System: %s %s.%s", uts.sysname, uts.version, uts.release);
168 printf ("System: SCO %s", uts.release);
170 printf ("System: %s %s", uts.sysname, uts.release);
173 printf (" (%s)", uts.machine);
175 #ifdef NCURSES_VERSION
176 printf ("\nncurses: %s (compiled with %s)", curses_version(), NCURSES_VERSION);
177 #elif defined(USE_SLANG_CURSES)
178 printf ("\nslang: %d", SLANG_VERSION);
181 #ifdef _LIBICONV_VERSION
182 printf ("\nlibiconv: %d.%d", _LIBICONV_VERSION >> 8,
183 _LIBICONV_VERSION & 0xff);
187 printf ("\nlibidn: %s (compiled with %s)", stringprep_check_version (NULL),
192 printf ("\nhcache backend: %s", mutt_hcache_backend ());
195 puts (_("\nCompile options:"));
198 printf ("DOMAIN=\"%s\"\n", DOMAIN);
277 #ifdef USE_SSL_OPENSSL
283 #ifdef USE_SSL_GNUTLS
323 #ifdef HAVE_START_COLOR
329 #ifdef HAVE_TYPEAHEAD
355 #ifdef HAVE_RESIZETERM
363 #ifdef CRYPT_BACKEND_CLASSIC_PGP
364 "+CRYPT_BACKEND_CLASSIC_PGP "
366 "-CRYPT_BACKEND_CLASSIC_PGP "
368 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
369 "+CRYPT_BACKEND_CLASSIC_SMIME "
371 "-CRYPT_BACKEND_CLASSIC_SMIME "
373 #ifdef CRYPT_BACKEND_GPGME
374 "+CRYPT_BACKEND_GPGME "
376 "-CRYPT_BACKEND_GPGME "
387 #ifdef SUN_ATTACHMENT
413 #ifdef HAVE_LANGINFO_CODESET
414 "+HAVE_LANGINFO_CODESET "
416 "-HAVE_LANGINFO_CODESET "
420 #ifdef HAVE_LANGINFO_YESEXPR
421 "+HAVE_LANGINFO_YESEXPR "
423 "-HAVE_LANGINFO_YESEXPR "
461 printf ("ISPELL=\"%s\"\n", ISPELL);
466 printf ("SENDMAIL=\"%s\"\n", SENDMAIL);
467 printf ("MAILPATH=\"%s\"\n", MAILPATH);
468 printf ("PKGDATADIR=\"%s\"\n", PKGDATADIR);
469 printf ("SYSCONFDIR=\"%s\"\n", SYSCONFDIR);
470 printf ("EXECSHELL=\"%s\"\n", EXECSHELL);
472 printf ("MIXMASTER=\"%s\"\n", MIXMASTER);
479 mutt_print_patchlist();
484 static void start_curses (void)
486 km_init (); /* must come before mutt_init */
488 #ifdef USE_SLANG_CURSES
489 SLtt_Ignore_Beep = 1; /* don't do that #*$@^! annoying visual beep! */
490 SLsmg_Display_Eight_Bit = 128; /* characters above this are printable */
491 SLtt_set_color(0, NULL, "default", "default");
492 #if SLANG_VERSION >= 20000
496 /* should come before initscr() so that ncurses 4.2 doesn't try to install
497 its own SIGWINCH handler */
500 if (initscr () == NULL)
502 puts _("Error initializing terminal.");
505 #if 1 /* USE_SLANG_CURSES - commenting out suggested in #455. */
506 /* slang requires the signal handlers to be set after initializing */
510 keypad (stdscr, TRUE);
514 typeahead (-1); /* simulate smooth scrolling */
521 #define M_IGNORE (1<<0) /* -z */
522 #define M_BUFFY (1<<1) /* -Z */
523 #define M_NOSYSRC (1<<2) /* -n */
524 #define M_RO (1<<3) /* -R */
525 #define M_SELECT (1<<4) /* -y */
527 int main (int argc, char **argv)
529 char folder[_POSIX_PATH_MAX] = "";
530 char *subject = NULL;
531 char *includeFile = NULL;
532 char *draftFile = NULL;
533 char *newMagic = NULL;
536 LIST *commands = NULL;
537 LIST *queries = NULL;
538 LIST *alias_queries = NULL;
543 int explicit_folder = 0;
544 int dump_variables = 0;
549 /* sanity check against stupid administrators */
551 if(getegid() != getgid())
553 fprintf(stderr, "%s: I don't want to run with privileges!\n",
559 /* FIXME what about init.c:1439 ? */
560 setlocale (LC_ALL, "");
561 bindtextdomain (PACKAGE, MUTTLOCALEDIR);
562 textdomain (PACKAGE);
565 setlocale (LC_CTYPE, "");
567 mutt_error = mutt_nocurses_error;
568 mutt_message = mutt_nocurses_error;
572 memset (Options, 0, sizeof (Options));
573 memset (QuadOptions, 0, sizeof (QuadOptions));
575 for (i = 1; i < argc; i++)
576 if (!strcmp(argv[i], "--"))
582 while ((i = getopt (argc, argv, "A:a:b:F:f:c:Dd:e:H:s:i:hm:npQ:RvxyzZ")) != EOF)
586 alias_queries = mutt_add_list (alias_queries, optarg);
589 attach = mutt_add_list (attach, optarg);
593 mutt_str_replace (&Muttrc, optarg);
597 strfcpy (folder, optarg, sizeof (folder));
604 msg = mutt_new_header ();
606 msg->env = mutt_new_envelope ();
608 msg->env->bcc = rfc822_parse_adrlist (msg->env->bcc, optarg);
610 msg->env->cc = rfc822_parse_adrlist (msg->env->cc, optarg);
619 debuglevel = atoi (optarg);
620 printf (_("Debugging at level %d.\n"), debuglevel);
622 printf _("DEBUG was not defined during compilation. Ignored.\n");
627 commands = mutt_add_list (commands, optarg);
635 includeFile = optarg;
639 /* should take precedence over .muttrc setting, so save it for later */
648 sendflags |= SENDPOSTPONED;
652 queries = mutt_add_list (queries, optarg);
656 flags |= M_RO; /* read-only mode */
667 case 'x': /* mailx compatible send mode */
668 sendflags |= SENDMAILX;
671 case 'y': /* My special hack mode */
680 flags |= M_BUFFY | M_IGNORE;
695 puts (mutt_make_version ());
699 puts (_(ReachingUs));
703 /* Check for a batch send. */
704 if (!isatty (0) || queries || alias_queries || dump_variables)
706 set_option (OPTNOCURSES);
707 sendflags = SENDBATCH;
710 /* This must come before mutt_init() because curses needs to be started
711 before calling the init_pair() function to set the color scheme. */
712 if (!option (OPTNOCURSES))
715 /* set defaults and read init files */
716 mutt_init (flags & M_NOSYSRC, commands);
717 mutt_free_list (&commands);
719 /* Initialize crypto backends. */
724 for (; optind < argc; optind++)
725 queries = mutt_add_list (queries, argv[optind]);
726 return mutt_query_variables (queries);
729 return mutt_dump_variables();
735 for (; optind < argc; optind++)
736 alias_queries = mutt_add_list (alias_queries, argv[optind]);
737 for (; alias_queries; alias_queries = alias_queries->next)
739 if ((a = mutt_lookup_alias (alias_queries->data)))
741 /* output in machine-readable form */
742 mutt_addrlist_to_idna (a, NULL);
743 mutt_write_address_list (a, stdout, 0, 0);
748 printf ("%s\n", alias_queries->data);
754 /* if an -a option is present, all non-option arguments before -- are considered attachments */
756 for (; optind <= attach_sep; optind++)
757 attach = mutt_add_list (attach, argv[optind]);
760 mx_set_magic (newMagic);
762 if (!option (OPTNOCURSES))
764 SETCOLOR (MT_COLOR_NORMAL);
766 mutt_error = mutt_curses_error;
767 mutt_message = mutt_curses_message;
770 /* Create the Maildir directory if it doesn't exist. */
771 if (!option (OPTNOCURSES) && Maildir)
774 char fpath[_POSIX_PATH_MAX];
777 strfcpy (fpath, Maildir, sizeof (fpath));
778 mutt_expand_path (fpath, sizeof (fpath));
780 /* we're not connected yet - skip mail folder creation */
781 if (!mx_is_imap (fpath))
783 if (stat (fpath, &sb) == -1 && errno == ENOENT)
785 snprintf (msg, sizeof (msg), _("%s does not exist. Create it?"), Maildir);
786 if (mutt_yesorno (msg, M_YES) == M_YES)
788 if (mkdir (fpath, 0700) == -1 && errno != EEXIST)
789 mutt_error ( _("Can't create %s: %s."), Maildir, strerror (errno));
794 if (sendflags & SENDPOSTPONED)
796 if (!option (OPTNOCURSES))
798 ci_send_message (SENDPOSTPONED, NULL, NULL, NULL, NULL);
801 else if (subject || msg || sendflags || draftFile || includeFile || attach ||
805 char buf[LONG_STRING];
806 char *tempfile = NULL, *infile = NULL;
807 char *bodytext = NULL;
810 if (!option (OPTNOCURSES))
814 msg = mutt_new_header ();
821 msg->env = mutt_new_envelope ();
823 for (i = optind; i < argc; i++)
825 if (url_check_scheme (argv[i]) == U_MAILTO)
827 if (url_parse_mailto (msg->env, &bodytext, argv[i]) < 0)
829 if (!option (OPTNOCURSES))
831 fputs (_("Failed to parse mailto: link\n"), stderr);
836 msg->env->to = rfc822_parse_adrlist (msg->env->to, argv[i]);
839 if (option (OPTAUTOEDIT) && !msg->env->to && !msg->env->cc)
841 if (!option (OPTNOCURSES))
843 fputs (_("No recipients specified.\n"), stderr);
848 msg->env->subject = safe_strdup (subject);
851 infile = includeFile;
854 if (infile || bodytext)
858 if (mutt_strcmp ("-", infile) == 0)
862 char path[_POSIX_PATH_MAX];
864 strfcpy (path, infile, sizeof (path));
865 mutt_expand_path (path, sizeof (path));
866 if ((fin = fopen (path, "r")) == NULL)
868 if (!option (OPTNOCURSES))
879 tempfile = safe_strdup (buf);
882 msg->env = mutt_read_rfc822_header (fin, NULL, 1, 0);
884 /* is the following if still needed? */
890 if ((fout = safe_fopen (tempfile, "w")) == NULL)
892 if (!option (OPTNOCURSES))
900 mutt_copy_stream (fin, fout);
902 fputs (bodytext, fout);
904 if (fin && fin != stdin)
920 a->next = mutt_make_file_attach (t->data);
924 msg->content = a = mutt_make_file_attach (t->data);
927 if (!option (OPTNOCURSES))
929 fprintf (stderr, _("%s: unable to attach file.\n"), t->data);
930 mutt_free_list (&attach);
935 mutt_free_list (&attach);
938 rv = ci_send_message (sendflags, msg, tempfile, NULL, NULL);
940 if (!option (OPTNOCURSES))
950 if (!mutt_buffy_check (0))
952 mutt_endwin _("No mailbox with new mail.");
956 mutt_buffy (folder, sizeof (folder));
958 else if (flags & M_SELECT)
961 mutt_endwin _("No incoming mailboxes defined.");
965 mutt_select_file (folder, sizeof (folder), M_SEL_FOLDER | M_SEL_BUFFY);
974 strfcpy (folder, NONULL(Spoolfile), sizeof (folder));
975 mutt_expand_path (folder, sizeof (folder));
977 mutt_str_replace (&CurrentFolder, folder);
978 mutt_str_replace (&LastFolder, folder);
980 if (flags & M_IGNORE)
982 /* check to see if there are any messages in the folder */
983 switch (mx_check_empty (folder))
986 mutt_endwin (strerror (errno));
989 mutt_endwin _("Mailbox is empty.");
994 mutt_folder_hook (folder);
996 if((Context = mx_open_mailbox (folder, ((flags & M_RO) || option (OPTREADONLY)) ? M_READONLY : 0, NULL))
1010 mutt_endwin (Errorbuf);