2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
4 * Copyright (C) 1999-2002 Thomas Roessler <roessler@does-not-exist.org>
5 * Copyright (C) 2004 g10 Code GmbH
7 * Parts written/modified by:
8 * Nico Golde <nion@muttng.org>
9 * Andreas Krennmair <ak@synflood.at>
11 * This file is part of mutt-ng, see http://www.muttng.org/.
12 * It's licensed under the GNU General Public License,
13 * please see the file GPL in the top level source directory.
23 #include "mutt_curses.h"
26 #include "mutt_crypt.h"
27 #include "mutt_idna.h"
33 #include "lib/debug.h"
41 #include <sys/utsname.h>
48 #include <stringprep.h>
52 #include "nntp/nntp.h"
70 #include <gnutls/gnutls.h>
73 #ifdef CRYPT_BACKEND_GPGME
74 #include <gpgme/gpgme.h>
77 static const char *ReachingUs = N_("\
78 To contact the developers, please mail to <mutt-ng-devel@lists.berlios.de>.\n\
79 To visit the Mutt-ng homepage go to http://www.muttng.org.\n\
80 To report a bug, please use the fleang(1) utility.\n");
82 static const char *Notice = N_("\
83 Copyright (C) 1996-2002 Michael R. Elkins and others.\n\
84 Mutt-ng comes with ABSOLUTELY NO WARRANTY; for details type `muttng -vv'.\n\
85 Mutt is free software, and you are welcome to redistribute it\n\
86 under certain conditions; type `muttng -vv' for details.\n");
88 static const char *Copyright = N_("\
89 Copyright (C) 1996-2004 Michael R. Elkins <me@mutt.org>\n\
90 Copyright (C) 1996-2002 Brandon Long <blong@fiction.net>\n\
91 Copyright (C) 1997-2005 Thomas Roessler <roessler@does-not-exist.org>\n\
92 Copyright (C) 1998-2005 Werner Koch <wk@isil.d.shuttle.de>\n\
93 Copyright (C) 1999-2005 Brendan Cully <brendan@kublai.com>\n\
94 Copyright (C) 1999-2002 Tommi Komulainen <Tommi.Komulainen@iki.fi>\n\
95 Copyright (C) 2000-2002 Edmund Grimley Evans <edmundo@rano.org>\n\n\
96 Copyright (C) 2005:\n\
97 Parts were written/modified by:\n\
98 Andreas Krennmair <ak@synflood.at>\n\
99 Nico Golde <nico@ngolde.de>\n\
100 Rocco Rutte <pdmef@cs.tu-berlin.de>\n\
102 Lots of others not mentioned here contributed lots of code,\n\
103 fixes, and suggestions.\n\
105 This program is free software; you can redistribute it and/or modify\n\
106 it under the terms of the GNU General Public License as published by\n\
107 the Free Software Foundation; either version 2 of the License, or\n\
108 (at your option) any later version.\n\
110 This program is distributed in the hope that it will be useful,\n\
111 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
112 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
113 GNU General Public License for more details.\n\
115 You should have received a copy of the GNU General Public License\n\
116 along with this program; if not, write to the Free Software\n\
117 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.\n\
120 void mutt_exit (int code)
126 static void mutt_usage (void)
128 puts (mutt_make_version (1));
132 ("usage: muttng [ -nRyzZ ] [ -e <cmd> ] [ -F <file> ] [ -m <type> ] [ -f <file> ]\n\
133 muttng [ -nR ] [ -e <cmd> ] [ -F <file> ] -Q <query> [ -Q <query> ] [...]\n\
134 muttng [ -nR ] [ -e <cmd> ] [ -F <file> ] -A <alias> [ -A <alias> ] [...]\n\
135 muttng [ -nR ] [ -e <cmd> ] [ -F <file> ] -D\n\
136 muttng [ -nx ] [ -e <cmd> ] [ -a <file> ] [ -F <file> ] [ -H <file> ] [ -i <file> ] [ -s <subj> ] [ -b <addr> ] [ -c <addr> ] <addr> [ ... ]\n\
137 muttng [ -n ] [ -e <cmd> ] [ -F <file> ] -p\n\
141 -A <alias>\texpand the given alias\n\
142 -a <file>\tattach a file to the message\n\
143 -b <address>\tspecify a blind carbon-copy (BCC) address\n\
144 -c <address>\tspecify a carbon-copy (CC) address\n\
145 -D\t\tprint the value of all variables to stdout");
147 puts _(" -d <level>\tlog debugging output to ~/.muttngdebug0");
150 -e <command>\tspecify a command to be executed after initialization\n\
151 -f <file>\tspecify which mailbox to read\n\
152 -F <file>\tspecify an alternate muttrngc file\n\
153 -g <server>\tspecify a newsserver (if compiled with NNTP)\n\
154 -G\t\tselect a newsgroup (if compiled with NNTP)\n\
155 -H <file>\tspecify a draft file to read header and body from\n\
156 -i <file>\tspecify a file which Mutt-ng should include in the body\n\
157 -d <level>\t specify debugging level of Mutt-ng\n\
158 -m <type>\tspecify a default mailbox type\n\
159 -n\t\tcauses Mutt-ng not to read the system Muttngrc\n\
160 -p\t\trecall a postponed message\n\
161 -Q <variable>\tquery a configuration variable\n\
162 -R\t\topen mailbox in read-only mode\n\
163 -s <subj>\tspecify a subject (must be in quotes if it has spaces)\n\
164 -v\t\tshow version and compile-time definitions\n\
165 -x\t\tsimulate the mailx send mode\n\
166 -y\t\tselect a mailbox specified in your `mailboxes' list\n\
167 -z\t\texit immediately if there are no messages in the mailbox\n\
168 -Z\t\topen the first folder with new message, exit immediately if none\n\
169 -h\t\tthis help message");
174 static void show_version (void)
181 puts (mutt_make_version (1));
187 printf ("System:\n %s %s.%s", uts.sysname, uts.version, uts.release);
189 printf ("System:\n SCO %s", uts.release);
191 printf ("System:\n %s %s", uts.sysname, uts.release);
194 printf (" (%s)\nExternal Libraries:\n", uts.machine);
196 #ifdef NCURSES_VERSION
197 printf (" ncurses %s\n", NCURSES_VERSION);
198 #elif defined(USE_SLANG_CURSES)
199 printf (" slang %d\n", SLANG_VERSION);
202 #ifdef _LIBICONV_VERSION
203 printf (" libiconv %d.%d\n", _LIBICONV_VERSION >> 8,
204 _LIBICONV_VERSION & 0xff);
208 printf (" libidn %s (compiled with %s)\n",
209 stringprep_check_version (NULL), STRINGPREP_VERSION);
213 smtp_version (buf, sizeof (buf), 0);
214 printf (" libESMTP %s\n", buf);
219 printf (" qdbm %s\n", dpversion);
221 printf (" gdbm %s\n", gdbm_version);
223 printf (" DB4 %d.%d.%d\n", DB_VERSION_MAJOR, DB_VERSION_MINOR,
229 printf (" gnutls %s\n", LIBGNUTLS_VERSION);
232 #ifdef CRYPT_BACKEND_GPGME
233 printf (" gpgme %s\n", GPGME_VERSION);
236 puts (_("Compile Options:"));
344 #ifdef USE_COMPRESSED
355 #ifdef HAVE_START_COLOR
360 #ifdef HAVE_TYPEAHEAD
381 #ifdef HAVE_RESIZETERM
389 #ifdef CRYPT_BACKEND_CLASSIC_PGP
390 " +CRYPT_BACKEND_CLASSIC_PGP "
392 " -CRYPT_BACKEND_CLASSIC_PGP "
394 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
395 "+CRYPT_BACKEND_CLASSIC_SMIME "
397 "-CRYPT_BACKEND_CLASSIC_SMIME "
399 #ifdef CRYPT_BACKEND_GPGME
400 "+CRYPT_BACKEND_GPGME "
402 "-CRYPT_BACKEND_GPGME "
409 #ifdef SUN_ATTACHMENT
430 #ifdef HAVE_LANGINFO_CODESET
431 "+HAVE_LANGINFO_CODESET "
433 "-HAVE_LANGINFO_CODESET "
435 #ifdef HAVE_LANGINFO_YESEXPR
436 "+HAVE_LANGINFO_YESEXPR "
438 "-HAVE_LANGINFO_YESEXPR "
468 puts (_("Built-In Defaults:"));
471 printf (" +DOMAIN=\"%s\"\n", DOMAIN);
477 printf (" +ISPELL=\"%s\"\n", ISPELL);
482 printf (" +SENDMAIL=\"%s\"\n", SENDMAIL);
483 printf (" +MAILPATH=\"%s\"\n", MAILPATH);
484 printf (" +PKGDATADIR=\"%s\"\n", PKGDATADIR);
485 printf (" +SYSCONFDIR=\"%s\"\n", SYSCONFDIR);
486 printf (" +EXECSHELL=\"%s\"\n", EXECSHELL);
488 printf (" +MIXMASTER=\"%s\"\n\n", MIXMASTER);
490 puts (" -MIXMASTER\n");
493 puts (_(ReachingUs));
495 puts (_("Mutt-ng is based on the following patches written for mutt:\n"));
496 mutt_print_patchlist ();
501 static void start_curses (void)
503 km_init (); /* must come before mutt_init */
505 #ifdef USE_SLANG_CURSES
506 SLtt_Ignore_Beep = 1; /* don't do that #*$@^! annoying visual beep! */
507 SLsmg_Display_Eight_Bit = 128; /* characters above this are printable */
508 SLtt_set_color (0, NULL, "default", "default");
510 /* should come before initscr() so that ncurses 4.2 doesn't try to install
511 its own SIGWINCH handler */
514 if (initscr () == NULL) {
515 puts _("Error initializing terminal.");
519 #if 1 /* USE_SLANG_CURSES - commenting out suggested in #455. */
520 /* slang requires the signal handlers to be set after initializing */
524 keypad (stdscr, TRUE);
528 typeahead (-1); /* simulate smooth scrolling */
535 #define M_IGNORE (1<<0) /* -z */
536 #define M_BUFFY (1<<1) /* -Z */
537 #define M_NOSYSRC (1<<2) /* -n */
538 #define M_RO (1<<3) /* -R */
539 #define M_SELECT (1<<4) /* -y */
541 #define M_NEWS (1<<5) /* -g and -G */
544 int main (int argc, char **argv)
546 char folder[_POSIX_PATH_MAX] = "";
547 char *subject = NULL;
548 char *includeFile = NULL;
549 char *draftFile = NULL;
550 char *newMagic = NULL;
553 LIST *commands = NULL;
554 LIST *queries = NULL;
555 LIST *alias_queries = NULL;
560 int explicit_folder = 0;
561 int dump_variables = 0;
565 /* initialize random number for tmp file creation */
566 srand ((unsigned int) time (NULL));
568 /* sanity check against stupid administrators */
570 if (getegid () != getgid ()) {
571 fprintf (stderr, "%s: I don't want to run with privileges!\n", argv[0]);
576 /* FIXME what about init.c:1439 ? */
577 setlocale (LC_ALL, "");
578 bindtextdomain (PACKAGE, MUTTLOCALEDIR);
579 textdomain (PACKAGE);
582 setlocale (LC_CTYPE, "");
584 mutt_error = mutt_nocurses_error;
585 mutt_message = mutt_nocurses_error;
589 memset (Options, 0, sizeof (Options));
590 memset (QuadOptions, 0, sizeof (QuadOptions));
595 "A:a:b:F:f:c:Dd:e:g:GH:s:i:hm:npQ:RvxyzZ")) != EOF)
598 getopt (argc, argv, "A:a:b:F:f:c:Dd:e:H:s:i:hm:npQ:RvxyzZ")) != EOF)
602 alias_queries = mutt_add_list (alias_queries, optarg);
605 if (strlen(optarg)<=512)
606 attach = mutt_add_list (attach, optarg);
608 printf("too long arguments. exiting ...\n");
614 str_replace (&Muttrc, optarg);
618 strfcpy (folder, optarg, sizeof (folder));
625 msg = mutt_new_header ();
627 msg->env = mutt_new_envelope ();
629 msg->env->bcc = rfc822_parse_adrlist (msg->env->bcc, optarg);
631 msg->env->cc = rfc822_parse_adrlist (msg->env->cc, optarg);
635 debug_setlevel(atoi(optarg));
637 if (atoi(optarg) <= DEBUG_MAX_LEVEL && atoi(optarg) >= DEBUG_MIN_LEVEL)
638 printf (_("Debugging at level %d.\n"), atoi(optarg));
640 printf(_("Please specify a valid debugging level ("
641 DEBUG_MIN_LEVEL_S "-" DEBUG_MAX_LEVEL_S ").\n"));
645 printf _("DEBUG was not defined during compilation. Ignored.\n");
654 commands = mutt_add_list (commands, optarg);
662 includeFile = optarg;
666 /* should take precedence over .muttrc setting, so save it for later */
675 sendflags |= SENDPOSTPONED;
679 queries = mutt_add_list (queries, optarg);
683 flags |= M_RO; /* read-only mode */
694 case 'x': /* mailx compatible send mode */
695 sendflags |= SENDMAILX;
698 case 'y': /* My special hack mode */
703 case 'g': /* Specify a newsserver */
705 char buf[LONG_STRING];
707 snprintf (buf, sizeof (buf), "set news_server=%s", optarg);
708 commands = mutt_add_list (commands, buf);
711 case 'G': /* List of newsgroups */
712 flags |= M_SELECT | M_NEWS;
721 flags |= M_BUFFY | M_IGNORE;
735 puts (mutt_make_version (1));
737 puts (_(ReachingUs));
741 /* Check for a batch send. */
742 if (!isatty (0) || queries || alias_queries || dump_variables) {
743 set_option (OPTNOCURSES);
744 sendflags = SENDBATCH;
747 /* This must come before mutt_init() because curses needs to be started
748 before calling the init_pair() function to set the color scheme. */
749 if (!option (OPTNOCURSES))
752 /* set defaults and read init files */
754 mutt_init (flags & M_NOSYSRC, commands);
755 mutt_free_list (&commands);
757 /* Initialize crypto */
761 return mutt_query_variables (queries);
763 return (mutt_dump_variables ());
769 for (; alias_queries; alias_queries = alias_queries->next) {
770 if ((a = mutt_lookup_alias (alias_queries->data))) {
771 /* output in machine-readable form */
772 mutt_addrlist_to_idna (a, NULL);
773 mutt_write_address_list (a, stdout, 0, 0);
777 printf ("%s\n", alias_queries->data);
784 mx_set_magic (newMagic);
786 if (!option (OPTNOCURSES)) {
787 SETCOLOR (MT_COLOR_NORMAL);
789 mutt_error = mutt_curses_error;
790 mutt_message = mutt_curses_message;
793 /* Create the Maildir directory if it doesn't exist. */
794 if (!option (OPTNOCURSES) && Maildir) {
796 char fpath[_POSIX_PATH_MAX];
799 strfcpy (fpath, Maildir, sizeof (fpath));
800 mutt_expand_path (fpath, sizeof (fpath));
802 /* we're not connected yet - skip mail folder creation */
803 if (mx_get_magic (fpath) != M_IMAP)
805 if (stat (fpath, &sb) == -1 && errno == ENOENT) {
806 snprintf (msg, sizeof (msg), _("%s does not exist. Create it?"),
808 if (mutt_yesorno (msg, M_YES) == M_YES) {
809 if (mkdir (fpath, 0700) == -1 && errno != EEXIST)
810 mutt_error (_("Can't create %s: %s."), Maildir, strerror (errno));
815 if (sendflags & SENDPOSTPONED) {
816 if (!option (OPTNOCURSES))
818 ci_send_message (SENDPOSTPONED, NULL, NULL, NULL, NULL);
821 else if (subject || msg || sendflags || draftFile || includeFile || attach
824 char buf[LONG_STRING];
825 char *tempfile = NULL, *infile = NULL;
826 char *bodytext = NULL;
828 if (!option (OPTNOCURSES))
832 msg = mutt_new_header ();
838 msg->env = mutt_new_envelope ();
840 for (i = optind; i < argc; i++) {
841 if (url_check_scheme (argv[i]) == U_MAILTO)
842 url_parse_mailto (msg->env, &bodytext, argv[i]);
844 msg->env->to = rfc822_parse_adrlist (msg->env->to, argv[i]);
847 if (option (OPTAUTOEDIT) && !msg->env->to && !msg->env->cc) {
848 if (!option (OPTNOCURSES))
850 fputs (_("No recipients specified.\n"), stderr);
855 msg->env->subject = str_dup (subject);
858 infile = includeFile;
861 if (infile || bodytext) {
863 if (str_cmp ("-", infile) == 0)
866 char path[_POSIX_PATH_MAX];
868 strfcpy (path, infile, sizeof (path));
869 mutt_expand_path (path, sizeof (path));
870 if ((fin = fopen (path, "r")) == NULL) {
871 if (!option (OPTNOCURSES))
882 tempfile = str_dup (buf);
885 msg->env = mutt_read_rfc822_header (fin, NULL, 1, 0);
887 /* is the following if still needed? */
892 if ((fout = safe_fopen (tempfile, "w")) == NULL) {
893 if (!option (OPTNOCURSES))
897 mem_free (&tempfile);
901 mutt_copy_stream (fin, fout);
903 fputs (bodytext, fout);
905 if (fin && fin != stdin)
910 mem_free (&bodytext);
918 a->next = mutt_make_file_attach (t->data);
922 msg->content = a = mutt_make_file_attach (t->data);
924 if (!option (OPTNOCURSES))
926 fprintf (stderr, _("%s: unable to attach file.\n"), t->data);
927 mutt_free_list (&attach);
932 mutt_free_list (&attach);
935 ci_send_message (sendflags, msg, tempfile, NULL, NULL);
937 if (!option (OPTNOCURSES))
941 if (flags & M_BUFFY) {
942 if (!buffy_check (0)) {
943 mutt_endwin _("No mailbox with new mail.");
948 buffy_next (folder, sizeof (folder));
950 else if (flags & M_SELECT) {
952 if (flags & M_NEWS) {
953 set_option (OPTNEWS);
954 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer))) {
955 mutt_endwin (Errorbuf);
962 mutt_endwin _("No incoming mailboxes defined.");
967 mutt_select_file (folder, sizeof (folder), M_SEL_FOLDER | M_SEL_BUFFY);
975 strfcpy (folder, NONULL (Spoolfile), sizeof (folder));
978 if (option (OPTNEWS)) {
979 unset_option (OPTNEWS);
980 nntp_expand_path (folder, sizeof (folder),
981 &CurrentNewsSrv->conn->account);
985 mutt_expand_path (folder, sizeof (folder));
987 str_replace (&CurrentFolder, folder);
988 str_replace (&LastFolder, folder);
990 if (flags & M_IGNORE) {
991 /* check to see if there are any messages in the folder */
992 switch (mx_check_empty (folder)) {
994 mutt_endwin (strerror (errno));
997 mutt_endwin _("Mailbox is empty.");
1002 mutt_folder_hook (folder);
1004 if ((Context = mx_open_mailbox (folder, ((flags & M_RO)
1005 || option (OPTREADONLY)) ?
1006 M_READONLY : 0, NULL))
1007 || !explicit_folder) {
1009 if (option (OPTXTERMSETTITLES))
1010 mutt_xterm_set_title (NONULL (XtermLeave));
1012 mem_free (&Context);
1014 mutt_endwin (Errorbuf);