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.
22 #include <lib-lib/mem.h>
23 #include <lib-lib/str.h>
24 #include <lib-lib/macros.h>
25 #include <lib-lib/file.h>
28 #include "mutt_curses.h"
31 #include "mutt_crypt.h"
32 #include "mutt_idna.h"
35 #include "lib/debug.h"
43 #include <sys/utsname.h>
53 #include <stringprep.h>
57 #include "nntp/nntp.h"
75 #include <gnutls/gnutls.h>
78 #ifdef CRYPT_BACKEND_GPGME
83 #include <openssl/opensslv.h>
86 static const char *ReachingUs = N_("\
87 To contact the developers, please mail to <mutt-ng-devel@lists.berlios.de>.\n\
88 To visit the Mutt-ng homepage go to http://www.muttng.org.\n\
89 To report a bug, please use the fleang(1) utility.\n");
91 static const char *Notice = N_("\
92 Copyright (C) 1996-2002 Michael R. Elkins and others.\n\
93 Mutt-ng comes with ABSOLUTELY NO WARRANTY; for details type `muttng -vv'.\n\
94 Mutt is free software, and you are welcome to redistribute it\n\
95 under certain conditions; type `muttng -vv' for details.\n");
97 static const char *Copyright_Mutt = N_("\
98 Copyright (C) 1996-2004 Michael R. Elkins <me@mutt.org>\n\
99 Copyright (C) 1996-2002 Brandon Long <blong@fiction.net>\n\
100 Copyright (C) 1997-2005 Thomas Roessler <roessler@does-not-exist.org>\n\
101 Copyright (C) 1998-2005 Werner Koch <wk@isil.d.shuttle.de>\n\
102 Copyright (C) 1999-2005 Brendan Cully <brendan@kublai.com>\n\
103 Copyright (C) 1999-2002 Tommi Komulainen <Tommi.Komulainen@iki.fi>\n\
104 Copyright (C) 2000-2002 Edmund Grimley Evans <edmundo@rano.org>\n");
106 static const char *Copyright_Mutt_NG = N_("\
107 Copyright (C) 2005:\n\
108 Parts were written/modified by:\n\
109 Andreas Krennmair <ak@synflood.at>\n\
110 Nico Golde <nico@ngolde.de>\n\
111 Rocco Rutte <pdmef@cs.tu-berlin.de>\n\
113 Lots of others not mentioned here contributed lots of code,\n\
114 fixes, and suggestions.");
116 static const char* Copyright_GPL_1 = N_("\
118 This program is free software; you can redistribute it and/or modify\n\
119 it under the terms of the GNU General Public License as published by\n\
120 the Free Software Foundation; either version 2 of the License, or\n\
121 (at your option) any later version.\n");
123 static const char* Copyright_GPL_2 = N_("\
124 This program is distributed in the hope that it will be useful,\n\
125 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
126 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
127 GNU General Public License for more details.\n");
129 static const char* Copyright_GPL_3 = N_("\
130 You should have received a copy of the GNU General Public License\n\
131 along with this program; if not, write to the Free Software\n\
132 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n\
135 void mutt_exit (int code)
141 static void mutt_usage (void)
143 puts (mutt_make_version (1));
146 _("usage: muttng [ -nRyzZ ] [ -e <cmd> ] [ -F <file> ] [ -m <type> ] [ -f <file> ]\n\
147 muttng [ -nR ] [ -e <cmd> ] [ -F <file> ] -Q <query> [ -Q <query> ] [...]\n\
148 muttng [ -nR ] [ -e <cmd> ] [ -F <file> ] -A <alias> [ -A <alias> ] [...]\n\
149 muttng [ -nR ] [ -e <cmd> ] [ -F <file> ] -t");
152 muttng [ -nR ] [ -e <cmd> ] [ -F <file> ] -T\n\
153 muttng [ -nx ] [ -e <cmd> ] [ -a <file> ] [ -F <file> ] [ -H <file> ] [ -i <file> ] [ -s <subj> ] [ -b <addr> ] [ -c <addr> ] <addr> [ ... ]\n\
154 muttng [ -n ] [ -e <cmd> ] [ -F <file> ] -p\n\
158 -A <alias>\texpand the given alias\n\
159 -a <file>\tattach a file to the message\n\
160 -b <address>\tspecify a blind carbon-copy (BCC) address\n\
161 -c <address>\tspecify a carbon-copy (CC) address");
163 puts _(" -d <level>\tlog debugging output to ~/.muttngdebug0");
166 -e <command>\tspecify a command to be executed after initialization\n\
167 -f <file>\tspecify which mailbox to read\n\
168 -F <file>\tspecify an alternate muttrngc file\n\
169 -g <server>\tspecify a newsserver (if compiled with NNTP)\n\
170 -G\t\tselect a newsgroup (if compiled with NNTP)\n\
171 -H <file>\tspecify a draft file to read header and body from\n\
172 -i <file>\tspecify a file which Mutt-ng should include in the body");
174 -d <level>\t specify debugging level of Mutt-ng\n\
175 -m <type>\tspecify a default mailbox type\n\
176 -n\t\tcauses Mutt-ng not to read the system Muttngrc\n\
177 -p\t\trecall a postponed message\n\
178 -Q <variable>\tquery a configuration variable\n\
179 -R\t\topen mailbox in read-only mode\n\
180 -s <subj>\tspecify a subject (must be in quotes if it has spaces)");
182 -t\t\tprint the value of all variables to stdout\n\
183 -T\t\tprint the value of all changed variables to stdout\n\
184 -v\t\tshow version and compile-time definitions\n\
185 -x\t\tsimulate the mailx send mode\n\
186 -y\t\tselect a mailbox specified in your `mailboxes' list\n\
187 -z\t\texit immediately if there are no messages in the mailbox\n\
188 -Z\t\topen the first folder with new message, exit immediately if none\n\
189 -h\t\tthis help message");
194 static void show_version (void)
201 puts (mutt_make_version (1));
207 printf ("System:\n %s %s.%s", uts.sysname, uts.version, uts.release);
209 printf ("System:\n SCO %s", uts.release);
211 printf ("System:\n %s %s", uts.sysname, uts.release);
214 printf (" (%s)\nExternal Libraries:\n", uts.machine);
216 #ifdef NCURSES_VERSION
217 printf (" ncurses %s\n", NCURSES_VERSION);
218 #elif defined(USE_SLANG_CURSES)
219 printf (" slang %d\n", SLANG_VERSION);
222 #ifdef _LIBICONV_VERSION
223 printf (" libiconv %d.%d\n", _LIBICONV_VERSION >> 8,
224 _LIBICONV_VERSION & 0xff);
228 printf (" libidn %s (compiled with %s)\n",
229 stringprep_check_version (NULL), STRINGPREP_VERSION);
233 smtp_version (buf, sizeof (buf), 0);
234 printf (" libESMTP %s\n", buf);
239 printf (" qdbm %s\n", dpversion);
241 printf (" gdbm %s\n", gdbm_version);
243 printf (" DB4 %d.%d.%d\n", DB_VERSION_MAJOR, DB_VERSION_MINOR,
249 printf (" gnutls %s\n", LIBGNUTLS_VERSION);
253 printf (" %s\n",OPENSSL_VERSION_TEXT);
256 #ifdef CRYPT_BACKEND_GPGME
257 printf (" gpgme %s\n", GPGME_VERSION);
260 puts (_("Compile Options:"));
363 #ifdef USE_COMPRESSED
374 #ifdef HAVE_START_COLOR
379 #ifdef HAVE_TYPEAHEAD
400 #ifdef HAVE_RESIZETERM
408 #ifdef CRYPT_BACKEND_CLASSIC_PGP
409 " +CRYPT_BACKEND_CLASSIC_PGP "
411 " -CRYPT_BACKEND_CLASSIC_PGP "
413 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
414 "+CRYPT_BACKEND_CLASSIC_SMIME "
416 "-CRYPT_BACKEND_CLASSIC_SMIME "
418 #ifdef CRYPT_BACKEND_GPGME
419 "+CRYPT_BACKEND_GPGME "
421 "-CRYPT_BACKEND_GPGME "
428 #ifdef SUN_ATTACHMENT
449 #ifdef HAVE_LANGINFO_CODESET
450 "+HAVE_LANGINFO_CODESET "
452 "-HAVE_LANGINFO_CODESET "
454 #ifdef HAVE_LANGINFO_YESEXPR
455 "+HAVE_LANGINFO_YESEXPR "
457 "-HAVE_LANGINFO_YESEXPR "
487 puts (_("Built-In Defaults:"));
490 printf (" +DOMAIN=\"%s\"\n", DOMAIN);
496 printf (" +ISPELL=\"%s\"\n", ISPELL);
501 printf (" +SENDMAIL=\"%s\"\n", SENDMAIL);
502 printf (" +MAILPATH=\"%s\"\n", MAILPATH);
503 printf (" +PKGDATADIR=\"%s\"\n", PKGDATADIR);
504 printf (" +PKGDOCDIR=\"%s\"\n", PKGDOCDIR);
505 printf (" +SYSCONFDIR=\"%s\"\n", SYSCONFDIR);
506 printf (" +EXECSHELL=\"%s\"\n", EXECSHELL);
508 printf (" +MIXMASTER=\"%s\"\n\n", MIXMASTER);
510 puts (" -MIXMASTER\n");
513 puts (_(ReachingUs));
515 puts (_("MadMutt is based on Mutt-ng wich was based on Mutt before\n"));
520 static void start_curses (void)
522 km_init (); /* must come before mutt_init */
524 #ifdef USE_SLANG_CURSES
525 SLtt_Ignore_Beep = 1; /* don't do that #*$@^! annoying visual beep! */
526 SLsmg_Display_Eight_Bit = 128; /* characters above this are printable */
527 SLtt_set_color (0, NULL, "default", "default");
529 /* should come before initscr() so that ncurses 4.2 doesn't try to install
530 its own SIGWINCH handler */
533 if (initscr () == NULL) {
534 puts _("Error initializing terminal.");
538 #if 1 /* USE_SLANG_CURSES - commenting out suggested in #455. */
539 /* slang requires the signal handlers to be set after initializing */
543 keypad (stdscr, TRUE);
547 typeahead (-1); /* simulate smooth scrolling */
554 #define M_IGNORE (1<<0) /* -z */
555 #define M_BUFFY (1<<1) /* -Z */
556 #define M_NOSYSRC (1<<2) /* -n */
557 #define M_RO (1<<3) /* -R */
558 #define M_SELECT (1<<4) /* -y */
560 #define M_NEWS (1<<5) /* -g and -G */
563 int main (int argc, char **argv)
565 char folder[_POSIX_PATH_MAX] = "";
566 char *subject = NULL;
567 char *includeFile = NULL;
568 char *draftFile = NULL;
569 char *newMagic = NULL;
572 LIST *commands = NULL;
573 LIST *queries = NULL;
574 LIST *alias_queries = NULL;
579 int explicit_folder = 0;
580 int dump_variables = -1;
582 /* initialize random number for tmp file creation */
583 srand ((unsigned int) time (NULL));
585 /* sanity check against stupid administrators */
587 if (getegid () != getgid ()) {
588 fprintf (stderr, "%s: I don't want to run with privileges!\n", argv[0]);
593 /* FIXME what about init.c:1439 ? */
594 setlocale (LC_ALL, "");
595 bindtextdomain (PACKAGE, MUTTLOCALEDIR);
596 textdomain (PACKAGE);
599 setlocale (LC_CTYPE, "");
601 mutt_error = mutt_nocurses_error;
602 mutt_message = mutt_nocurses_error;
606 p_clear(Options, sizeof(Options));
607 p_clear(QuadOptions, sizeof(QuadOptions));
612 "A:a:b:F:f:c:d:e:g:GH:s:i:hm:npQ:RTtvxyzZ")) != EOF)
615 getopt (argc, argv, "A:a:b:F:f:c:d:e:H:s:i:hm:npQ:RTtvxyzZ")) != EOF)
619 alias_queries = mutt_add_list (alias_queries, optarg);
622 if (strlen(optarg)<=512)
623 attach = mutt_add_list (attach, optarg);
625 printf("too long arguments. exiting ...\n");
631 str_replace (&Muttrc, optarg);
635 m_strcpy(folder, sizeof(folder), optarg);
642 msg = mutt_new_header ();
644 msg->env = mutt_new_envelope ();
646 msg->env->bcc = rfc822_parse_adrlist (msg->env->bcc, optarg);
648 msg->env->cc = rfc822_parse_adrlist (msg->env->cc, optarg);
653 char buf[LONG_STRING];
654 int level = atoi (optarg);
656 snprintf (buf, sizeof (buf), "set debug_level=%d", level);
657 commands = mutt_add_list (commands, buf);
658 debug_setlevel (level);
671 commands = mutt_add_list (commands, optarg);
679 includeFile = optarg;
683 /* should take precedence over .muttrc setting, so save it for later */
692 sendflags |= SENDPOSTPONED;
696 queries = mutt_add_list (queries, optarg);
700 flags |= M_RO; /* read-only mode */
711 case 'x': /* mailx compatible send mode */
712 sendflags |= SENDMAILX;
715 case 'y': /* My special hack mode */
720 case 'g': /* Specify a newsserver */
722 char buf[LONG_STRING];
724 snprintf (buf, sizeof (buf), "set nntp_host=%s", optarg);
725 commands = mutt_add_list (commands, buf);
728 case 'G': /* List of newsgroups */
729 flags |= M_SELECT | M_NEWS;
738 flags |= M_BUFFY | M_IGNORE;
752 puts (mutt_make_version (1));
753 puts (_(Copyright_Mutt));
754 puts (_(Copyright_Mutt_NG));
755 puts (_(Copyright_GPL_1));
756 puts (_(Copyright_GPL_2));
757 puts (_(Copyright_GPL_3));
758 puts (_(ReachingUs));
762 /* Check for a batch send. */
763 if (!isatty (0) || queries || alias_queries || dump_variables > 0) {
764 set_option (OPTNOCURSES);
765 sendflags = SENDBATCH;
768 /* This must come before mutt_init() because curses needs to be started
769 before calling the init_pair() function to set the color scheme. */
770 if (!option (OPTNOCURSES))
773 /* set defaults and read init files */
775 mutt_init (flags & M_NOSYSRC, commands);
776 mutt_free_list (&commands);
778 /* Initialize crypto */
782 return mutt_query_variables (queries);
783 if (dump_variables > 0)
784 return (mutt_dump_variables (dump_variables-1));
790 for (; alias_queries; alias_queries = alias_queries->next) {
791 if ((a = mutt_lookup_alias (alias_queries->data))) {
792 /* output in machine-readable form */
793 mutt_addrlist_to_idna (a, NULL);
794 mutt_write_address_list (a, stdout, 0, 0);
798 printf ("%s\n", alias_queries->data);
805 mx_set_magic (newMagic);
807 if (!option (OPTNOCURSES)) {
808 SETCOLOR (MT_COLOR_NORMAL);
810 mutt_error = mutt_curses_error;
811 mutt_message = mutt_curses_message;
814 /* Create the Maildir directory if it doesn't exist. */
815 if (!option (OPTNOCURSES) && Maildir) {
817 char fpath[_POSIX_PATH_MAX];
820 m_strcpy(fpath, sizeof(fpath), Maildir);
821 mutt_expand_path (fpath, sizeof (fpath));
823 /* we're not connected yet - skip mail folder creation */
824 if (mx_get_magic (fpath) != M_IMAP)
826 if (stat (fpath, &sb) == -1 && errno == ENOENT) {
827 snprintf (msg, sizeof (msg), _("%s does not exist. Create it?"),
829 if (mutt_yesorno (msg, M_YES) == M_YES) {
830 if (mkdir (fpath, 0700) == -1 && errno != EEXIST)
831 mutt_error (_("Can't create %s: %s."), Maildir, strerror (errno));
836 if (sendflags & SENDPOSTPONED) {
837 if (!option (OPTNOCURSES))
839 ci_send_message (SENDPOSTPONED, NULL, NULL, NULL, NULL);
842 else if (subject || msg || sendflags || draftFile || includeFile || attach
845 char buf[LONG_STRING];
846 char *tempfile = NULL, *infile = NULL;
847 char *bodytext = NULL;
849 if (!option (OPTNOCURSES))
853 msg = mutt_new_header ();
859 msg->env = mutt_new_envelope ();
861 for (i = optind; i < argc; i++) {
862 if (url_check_scheme (argv[i]) == U_MAILTO)
863 url_parse_mailto (msg->env, &bodytext, argv[i]);
865 msg->env->to = rfc822_parse_adrlist (msg->env->to, argv[i]);
868 if (option (OPTAUTOEDIT) && !msg->env->to && !msg->env->cc) {
869 if (!option (OPTNOCURSES))
871 fputs (_("No recipients specified.\n"), stderr);
876 msg->env->subject = m_strdup(subject);
879 infile = includeFile;
882 if (infile || bodytext) {
884 if (m_strcmp("-", infile) == 0)
887 char path[_POSIX_PATH_MAX];
889 m_strcpy(path, sizeof(path), infile);
890 mutt_expand_path (path, sizeof (path));
891 if ((fin = fopen (path, "r")) == NULL) {
892 if (!option (OPTNOCURSES))
903 tempfile = m_strdup(buf);
906 msg->env = mutt_read_rfc822_header (fin, NULL, 1, 0);
908 /* is the following if still needed? */
913 if ((fout = safe_fopen (tempfile, "w")) == NULL) {
914 if (!option (OPTNOCURSES))
922 mutt_copy_stream (fin, fout);
924 fputs (bodytext, fout);
926 if (fin && fin != stdin)
939 a->next = mutt_make_file_attach (t->data);
943 msg->content = a = mutt_make_file_attach (t->data);
945 if (!option (OPTNOCURSES))
947 fprintf (stderr, _("%s: unable to attach file.\n"), t->data);
948 mutt_free_list (&attach);
953 mutt_free_list (&attach);
956 ci_send_message (sendflags, msg, tempfile, NULL, NULL);
958 if (!option (OPTNOCURSES))
962 if (flags & M_BUFFY) {
963 if (!buffy_check (0)) {
964 mutt_endwin _("No mailbox with new mail.");
969 buffy_next (folder, sizeof (folder));
971 else if (flags & M_SELECT) {
973 if (flags & M_NEWS) {
974 set_option (OPTNEWS);
975 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer))) {
976 mutt_endwin (Errorbuf);
983 mutt_endwin _("No incoming mailboxes defined.");
988 mutt_select_file (folder, sizeof (folder), M_SEL_FOLDER | M_SEL_BUFFY);
996 m_strcpy(folder, sizeof(folder), NONULL(Spoolfile));
999 if (option (OPTNEWS)) {
1000 unset_option (OPTNEWS);
1001 nntp_expand_path (folder, sizeof (folder),
1002 &CurrentNewsSrv->conn->account);
1006 mutt_expand_path (folder, sizeof (folder));
1008 str_replace (&CurrentFolder, folder);
1009 str_replace (&LastFolder, folder);
1011 if (flags & M_IGNORE) {
1012 /* check to see if there are any messages in the folder */
1013 switch (mx_check_empty (folder)) {
1015 mutt_endwin (strerror (errno));
1018 mutt_endwin _("Mailbox is empty.");
1023 mutt_folder_hook (folder);
1025 if ((Context = mx_open_mailbox (folder, ((flags & M_RO)
1026 || option (OPTREADONLY)) ?
1027 M_READONLY : 0, NULL))
1028 || !explicit_folder) {
1030 if (option (OPTXTERMSETTITLES))
1031 mutt_xterm_set_title (NONULL (XtermLeave));
1035 mutt_endwin (Errorbuf);