we don't really need md5 for hcache at all.
[apps/madmutt.git] / main.c
1 /*
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
6  *
7  * Parts written/modified by:
8  * Nico Golde <nion@muttng.org>
9  * Andreas Krennmair <ak@synflood.at>
10  *
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.
14  */
15
16 #define MAIN_C 1
17
18 #include <lib-lib/lib-lib.h>
19
20 #include <sys/utsname.h>
21
22 #include <lib-lua/lib-lua.h>
23 #include <lib-sys/mutt_signal.h>
24 #include <lib-mime/mime.h>
25 #include <lib-ui/curses.h>
26 #include <lib-mx/mx.h>
27
28 #include "mutt.h"
29 #include "crypt.h"
30 #include "alias.h"
31 #include "buffy.h"
32 #include "sort.h"
33 #include "keymap.h"
34 #include "mutt_idna.h"
35
36 #ifdef HAVE_GETOPT_H
37 #include <getopt.h>
38 #else
39 extern char *optarg;
40 extern int optind;
41 #endif
42
43 #ifdef HAVE_LIBIDN
44 #include <stringprep.h>
45 #endif
46
47 #ifdef USE_NNTP
48 #include <nntp/nntp.h>
49 #endif
50
51 #ifdef USE_LIBESMTP
52 #include <libesmtp.h>
53 #endif
54
55 #ifdef USE_HCACHE
56 #if defined(HAVE_QDBM)
57 #include <depot.h>
58 #elif defined(HAVE_GDBM)
59 #include <gdbm.h>
60 #endif
61 #endif
62
63 #include <gnutls/gnutls.h>
64 #include <gpgme.h>
65
66 static const char *Notice = N_("\
67 Copyright (C) 1996-2002 Michael R. Elkins and others.\n\
68 Copyright (C) 2005 The Mutt-ng Team\n\
69 Copyright (C) 2006 Pierre Habouzit undation, Inc.\n\
70 This is free software.  You may redistribute copies of it under the terms of\n\
71 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n\
72 There is NO WARRANTY, to the extent permitted by law.\n");
73
74 void mutt_exit (int code)
75 {
76   mutt_endwin (NULL);
77   exit (code);
78 }
79
80 static void mutt_usage (void)
81 {
82   puts (mutt_make_version());
83
84   puts
85     _("usage: madmutt [ -nRyzZ ] [ -e <cmd> ] [ -F <file> ] [ -m <type> ] [ -f <file> ]\n\
86        madmutt [ -nR ] [ -e <cmd> ] [ -F <file> ] -Q <query> [ -Q <query> ] [...]\n\
87        madmutt [ -nR ] [ -e <cmd> ] [ -F <file> ] -A <alias> [ -A <alias> ] [...]\n\
88        madmutt [ -nR ] [ -e <cmd> ] [ -F <file> ] -t");
89   puts
90     _("\
91        madmutt [ -nR ] [ -e <cmd> ] [ -F <file> ] -T\n\
92        madmutt [ -nx ] [ -e <cmd> ] [ -a <file> ] [ -F <file> ] [ -H <file> ] [ -i <file> ] [ -s <subj> ] [ -b <addr> ] [ -c <addr> ] <addr> [ ... ]\n\
93        madmutt [ -n ] [ -e <cmd> ] [ -F <file> ] -p\n\
94        madmutt -v\n\
95 \n\
96 options:\n\
97   -A <alias>\texpand the given alias\n\
98   -a <file>\tattach a file to the message\n\
99   -b <address>\tspecify a blind carbon-copy (BCC) address\n\
100   -c <address>\tspecify a carbon-copy (CC) address");
101   puts _("\
102   -e <command>\tspecify a command to be executed after initialization\n\
103   -f <file>\tspecify which mailbox to read\n\
104   -F <file>\tspecify an alternate muttrngc file\n\
105   -g <server>\tspecify a newsserver (if compiled with NNTP)\n\
106   -G\t\tselect a newsgroup (if compiled with NNTP)\n\
107   -H <file>\tspecify a draft file to read header and body from\n\
108   -i <file>\tspecify a file which Madmutt should include in the body");
109   puts _("\
110   -d <level>\t specify debugging level of Madmutt\n\
111   -m <type>\tspecify a default mailbox type\n\
112   -n\t\tcauses Madmutt not to read the system Madmuttrc\n\
113   -p\t\trecall a postponed message\n\
114   -Q <variable>\tquery a configuration variable\n\
115   -R\t\topen mailbox in read-only mode\n\
116   -s <subj>\tspecify a subject (must be in quotes if it has spaces)");
117   puts _("\
118   -t\t\tprint the value of all variables to stdout\n\
119   -T\t\tprint the value of all changed variables to stdout\n\
120   -v\t\tshow version and compile-time definitions\n\
121   -y\t\tselect a mailbox specified in your `mailboxes' list\n\
122   -z\t\texit immediately if there are no messages in the mailbox\n\
123   -Z\t\topen the first folder with new message, exit immediately if none\n\
124   -h\t\tthis help message");
125
126   exit (0);
127 }
128
129 static void show_version (void)
130 {
131   struct utsname uts;
132 #ifdef USE_LIBESMTP
133   char buf[STRING];
134 #endif
135
136   puts (mutt_make_version());
137   puts (_(Notice));
138
139   uname (&uts);
140
141 #ifdef _AIX
142   printf ("System:\n  %s %s.%s", uts.sysname, uts.version, uts.release);
143 #elif defined (SCO)
144   printf ("System:\n  SCO %s", uts.release);
145 #else
146   printf ("System:\n  %s %s", uts.sysname, uts.release);
147 #endif
148
149   printf (" (%s)\nExternal Libraries:\n", uts.machine);
150
151 #ifdef NCURSES_VERSION
152   printf ("  ncurses %s\n", NCURSES_VERSION);
153 #elif defined(USE_SLANG_CURSES)
154   printf ("  slang %d\n", SLANG_VERSION);
155 #endif
156
157 #ifdef _LIBICONV_VERSION
158   printf ("  libiconv %d.%d\n", _LIBICONV_VERSION >> 8,
159           _LIBICONV_VERSION & 0xff);
160 #endif
161
162 #ifdef HAVE_LIBIDN
163   printf ("  libidn %s (compiled with %s)\n",
164           stringprep_check_version (NULL), STRINGPREP_VERSION);
165 #endif
166
167 #ifdef USE_LIBESMTP
168   smtp_version (buf, sizeof (buf), 0);
169   printf ("  libESMTP %s\n", buf);
170 #endif
171
172 #ifdef USE_HCACHE
173 #if defined(HAVE_QDBM)
174   printf ("  qdbm %s\n", dpversion);
175 #elif defined(HAVE_GDBM)
176   printf ("  gdbm %s\n", gdbm_version);
177 #endif
178 #endif
179
180   printf ("  gnutls %s\n", LIBGNUTLS_VERSION);
181   printf ("  gpgme %s\n", GPGME_VERSION);
182   puts (_("Compile Options:"));
183
184   puts (
185 #ifdef HOMESPOOL
186          "  +HOMESPOOL  "
187 #else
188          "  -HOMESPOOL  "
189 #endif
190 #ifdef USE_SETGID
191          "+USE_SETGID  "
192 #else
193          "-USE_SETGID  "
194 #endif
195 #ifdef USE_FCNTL
196          "+USE_FCNTL  "
197 #else
198          "-USE_FCNTL  "
199 #endif
200 #ifdef USE_FLOCK
201          "+USE_FLOCK   "
202 #else
203          "-USE_FLOCK   "
204 #endif
205 #ifdef USE_HCACHE
206          "+USE_HCACHE  "
207 #else
208          "-USE_HCACHE  "
209 #endif
210     );
211   puts (
212 #ifdef USE_NNTP
213          "+USE_NNTP  "
214 #else
215          "-USE_NNTP  "
216 #endif
217 #ifdef USE_LIBESMTP
218          "+USE_LIBESMTP  "
219 #else
220          "-USE_LIBESMTP  "
221 #endif
222          "\n  "
223 #ifdef HAVE_REGCOMP
224          "+HAVE_REGCOMP  "
225 #else
226          "-HAVE_REGCOMP  "
227 #endif
228          "\n  "
229 #ifdef HAVE_START_COLOR
230          "+HAVE_START_COLOR  "
231 #else
232          "-HAVE_START_COLOR  "
233 #endif
234 #ifdef HAVE_TYPEAHEAD
235          "+HAVE_TYPEAHEAD  "
236 #else
237          "-HAVE_TYPEAHEAD  "
238 #endif
239 #ifdef HAVE_BKGDSET
240          "+HAVE_BKGDSET  "
241 #else
242          "-HAVE_BKGDSET  "
243 #endif
244          "\n  "
245 #ifdef HAVE_CURS_SET
246          "+HAVE_CURS_SET  "
247 #else
248          "-HAVE_CURS_SET  "
249 #endif
250 #ifdef HAVE_META
251          "+HAVE_META  "
252 #else
253          "-HAVE_META  "
254 #endif
255 #ifdef HAVE_RESIZETERM
256          "+HAVE_RESIZETERM  "
257 #else
258          "-HAVE_RESIZETERM  "
259 #endif
260     );
261
262   puts (
263          "+CRYPT_BACKEND_GPGME  "
264          "\n  "
265 #ifdef ENABLE_NLS
266          "+ENABLE_NLS  "
267 #else
268          "-ENABLE_NLS  "
269 #endif
270 #ifdef HAVE_WC_FUNCS
271          "+HAVE_WC_FUNCS  "
272 #else
273          "-HAVE_WC_FUNCS  "
274 #endif
275 #ifdef HAVE_LANGINFO_CODESET
276          "+HAVE_LANGINFO_CODESET  "
277 #else
278          "-HAVE_LANGINFO_CODESET  "
279 #endif
280 #ifdef HAVE_LANGINFO_YESEXPR
281          "+HAVE_LANGINFO_YESEXPR  "
282 #else
283          "-HAVE_LANGINFO_YESEXPR  "
284 #endif
285          "\n  "
286 #ifdef HAVE_ICONV
287          "+HAVE_ICONV  "
288 #else
289          "-HAVE_ICONV  "
290 #endif
291 #ifdef HAVE_LIBIDN
292          "+HAVE_LIBIDN  "
293 #else
294          "-HAVE_LIBIDN  "
295 #endif
296 #ifdef HAVE_GETSID
297          "+HAVE_GETSID  "
298 #else
299          "-HAVE_GETSID  "
300 #endif
301     );
302
303   puts (_("Built-In Defaults:"));
304   printf ("  +SENDMAIL=\"%s\"\n", SENDMAIL);
305   printf ("  +MAILPATH=\"%s\"\n", MAILPATH);
306   printf ("  +PKGDATADIR=\"%s\"\n", PKGDATADIR);
307   printf ("  +PKGDOCDIR=\"%s\"\n", PKGDOCDIR);
308   printf ("  +SYSCONFDIR=\"%s\"\n", SYSCONFDIR);
309   printf ("  +MIXMASTER=\"%s\"\n\n", MIXMASTER);
310
311   puts (_("MadMutt is based on Madmutt wich was based on Mutt before\n"));
312
313   exit (0);
314 }
315
316 static void start_curses (void)
317 {
318   km_init ();                   /* must come before mutt_init */
319
320 #ifdef USE_SLANG_CURSES
321   SLtt_Ignore_Beep = 1;         /* don't do that #*$@^! annoying visual beep! */
322   SLsmg_Display_Eight_Bit = 128;        /* characters above this are printable */
323   SLtt_set_color (0, NULL, "default", "default");
324 #else
325   /* should come before initscr() so that ncurses 4.2 doesn't try to install
326      its own SIGWINCH handler */
327   mutt_signal_initialize ();
328 #endif
329   if (initscr () == NULL) {
330     puts _("Error initializing terminal.");
331
332     exit (1);
333   }
334   mutt_signal_initialize ();
335   ci_start_color ();
336   keypad (stdscr, TRUE);
337   cbreak ();
338   noecho ();
339 #ifdef HAVE_TYPEAHEAD
340   typeahead (-1);               /* simulate smooth scrolling */
341 #endif
342 #ifdef HAVE_META
343   meta (stdscr, TRUE);
344 #endif
345 }
346
347 #define M_IGNORE  (1<<0)        /* -z */
348 #define M_BUFFY   (1<<1)        /* -Z */
349 #define M_NOSYSRC (1<<2)        /* -n */
350 #define M_RO      (1<<3)        /* -R */
351 #define M_SELECT  (1<<4)        /* -y */
352 #ifdef USE_NNTP
353 #define M_NEWS    (1<<5)        /* -g and -G */
354 #endif
355
356 __attribute__((format(printf, 1, 0)))
357 static void mutt_nocurses_error (const char *fmt, ...)
358 {
359     va_list ap;
360
361     va_start(ap, fmt);
362     vfprintf(stderr, fmt, ap);
363     va_end(ap);
364     fputc('\n', stderr);
365 }
366
367 int main (int argc, char **argv)
368 {
369   char folder[_POSIX_PATH_MAX] = "";
370   char *subject = NULL;
371   char *includeFile = NULL;
372   char *draftFile = NULL;
373   char *newMagic = NULL;
374   HEADER *msg = NULL;
375   string_list_t *attach = NULL;
376   string_list_t *commands = NULL;
377   string_list_t *queries = NULL;
378   string_list_t *alias_queries = NULL;
379   int sendflags = 0;
380   int flags = 0;
381   int version = 0;
382   int i;
383   int explicit_folder = 0;
384   int dump_variables = -1;
385
386   /* initialize random number for tmp file creation */ 
387   srand48((unsigned int) time (NULL));
388   
389   /* sanity check against stupid administrators */
390   
391   if (getegid () != getgid ()) {
392     fprintf (stderr, "%s: I don't want to run with privileges!\n", argv[0]);
393     exit (1);
394   }
395
396 #ifdef ENABLE_NLS
397   /* FIXME what about init.c:1439 ? */
398   setlocale (LC_ALL, "");
399   bindtextdomain (PACKAGE, MUTTLOCALEDIR);
400   textdomain (PACKAGE);
401 #endif
402
403   setlocale (LC_CTYPE, "");
404
405   mutt_error = mutt_message = mutt_nocurses_error;
406   srand48 (time (NULL));
407   umask (077);
408
409   p_clear(Options, countof(Options));
410   p_clear(QuadOptions, countof(QuadOptions));
411
412   while ((i = getopt(argc, argv, "A:a:b:F:f:c:e:H:s:i:hm:npQ:RTtvyzZ"
413 #ifdef USE_NNTP
414                                                                     "g:G"
415 #endif
416                     )) >= 0)
417     switch (i) {
418     case 'A':
419       alias_queries = mutt_add_list (alias_queries, optarg);
420       break;
421     case 'a':
422       if (strlen(optarg)<=512)
423         attach = mutt_add_list (attach, optarg);
424       else{
425         printf("too long arguments. exiting ...\n");
426         exit(1);
427       }
428       break;
429
430     case 'F':
431       m_strreplace(&Muttrc, optarg);
432       break;
433
434     case 'f':
435       m_strcpy(folder, sizeof(folder), optarg);
436       explicit_folder = 1;
437       break;
438
439     case 'b':
440     case 'c':
441       if (!msg)
442         msg = header_new();
443       if (!msg->env)
444         msg->env = envelope_new();
445       if (i == 'b')
446         msg->env->bcc = rfc822_parse_adrlist (msg->env->bcc, optarg);
447       else
448         msg->env->cc = rfc822_parse_adrlist (msg->env->cc, optarg);
449       break;
450
451     case 't':
452       dump_variables = 2;
453       break;
454
455     case 'T':
456       dump_variables = 1;
457       break;
458
459     case 'e':
460       commands = mutt_add_list (commands, optarg);
461       break;
462
463     case 'H':
464       draftFile = optarg;
465       break;
466
467     case 'i':
468       includeFile = optarg;
469       break;
470
471     case 'm':
472       /* should take precedence over .muttrc setting, so save it for later */
473       newMagic = optarg;
474       break;
475
476     case 'n':
477       flags |= M_NOSYSRC;
478       break;
479
480     case 'p':
481       sendflags |= SENDPOSTPONED;
482       break;
483
484     case 'Q':
485       queries = mutt_add_list (queries, optarg);
486       break;
487
488     case 'R':
489       flags |= M_RO;            /* read-only mode */
490       break;
491
492     case 's':
493       subject = optarg;
494       break;
495
496     case 'v':
497       version++;
498       break;
499
500     case 'y':                  /* My special hack mode */
501       flags |= M_SELECT;
502       break;
503
504 #ifdef USE_NNTP
505     case 'g':                  /* Specify a newsserver */
506       {
507         char buf[LONG_STRING];
508
509         snprintf (buf, sizeof (buf), "set nntp_host=%s", optarg);
510         commands = mutt_add_list (commands, buf);
511       }
512
513     case 'G':                  /* List of newsgroups */
514       flags |= M_SELECT | M_NEWS;
515       break;
516 #endif
517
518     case 'z':
519       flags |= M_IGNORE;
520       break;
521
522     case 'Z':
523       flags |= M_BUFFY | M_IGNORE;
524       break;
525
526     default:
527       mutt_usage ();
528     }
529
530   if (version) {
531     show_version ();
532   }
533
534   /* Check for a batch send. */
535   if (!isatty (0) || queries || alias_queries || dump_variables > 0) {
536     set_option (OPTNOCURSES);
537     sendflags = SENDBATCH;
538   }
539
540   /* This must come before mutt_init() because curses needs to be started
541      before calling the init_pair() function to set the color scheme.  */
542   if (!option (OPTNOCURSES))
543     start_curses ();
544
545   /* set defaults and read init files */
546   mutt_init (flags & M_NOSYSRC, commands);
547   string_list_wipe(&commands);
548
549   if (queries)
550     return mutt_query_variables (queries);
551   if (dump_variables > 0)
552     return (mutt_dump_variables (dump_variables-1));
553
554   if (alias_queries) {
555     int rv = 0;
556     address_t *a;
557
558     for (; alias_queries; alias_queries = alias_queries->next) {
559       if ((a = address_list_dup(alias_lookup(alias_queries->data)))) {
560         /* output in machine-readable form */
561         mutt_addrlist_to_idna (a, NULL);
562         mutt_write_address_list (a, stdout, 0, 0);
563         address_list_wipe(&a);
564       } else {
565         rv = 1;
566         printf ("%s\n", alias_queries->data);
567       }
568     }
569     return rv;
570   }
571
572   if (newMagic)
573     mx_set_magic (newMagic);
574
575   if (!option (OPTNOCURSES)) {
576     SETCOLOR (MT_COLOR_NORMAL);
577     clear ();
578     mutt_error = mutt_curses_error;
579     mutt_message = mutt_curses_message;
580   }
581
582   /* Create the Maildir directory if it doesn't exist. */
583   if (!option (OPTNOCURSES) && Maildir) {
584     struct stat sb;
585     char fpath[_POSIX_PATH_MAX];
586     char mesg[STRING];
587
588     m_strcpy(fpath, sizeof(fpath), Maildir);
589     mutt_expand_path (fpath, sizeof (fpath));
590     /* we're not connected yet - skip mail folder creation */
591     if (mx_get_magic (fpath) != M_IMAP)
592       if (stat (fpath, &sb) == -1 && errno == ENOENT) {
593         snprintf (mesg, sizeof (mesg), _("%s does not exist. Create it?"),
594                   Maildir);
595         if (mutt_yesorno (mesg, M_YES) == M_YES) {
596           if (mkdir (fpath, 0700) == -1 && errno != EEXIST)
597             mutt_error (_("Can't create %s: %s."), Maildir, strerror (errno));
598         }
599       }
600   }
601
602   if (sendflags & SENDPOSTPONED) {
603     if (!option (OPTNOCURSES))
604       mutt_flushinp ();
605     ci_send_message (SENDPOSTPONED, NULL, NULL, NULL, NULL);
606     mutt_endwin (NULL);
607   }
608   else if (subject || msg || sendflags || draftFile || includeFile || attach
609            || optind < argc) {
610     FILE *fin = NULL;
611     char buf[LONG_STRING];
612     char *tempfile = NULL, *infile = NULL;
613     char *bodytext = NULL;
614     FILE *fout;
615
616     if (!option (OPTNOCURSES))
617       mutt_flushinp ();
618
619     if (!msg)
620       msg = header_new();
621
622     if (draftFile)
623       infile = draftFile;
624     else {
625       if (!msg->env)
626         msg->env = envelope_new();
627
628       for (i = optind; i < argc; i++) {
629         if (url_check_scheme (argv[i]) == U_MAILTO)
630           url_parse_mailto (msg->env, &bodytext, argv[i]);
631         else
632           msg->env->to = rfc822_parse_adrlist (msg->env->to, argv[i]);
633       }
634
635       if (option (OPTAUTOEDIT) && !msg->env->to && !msg->env->cc) {
636         if (!option (OPTNOCURSES))
637           mutt_endwin (NULL);
638         fputs (_("No recipients specified.\n"), stderr);
639         exit (1);
640       }
641
642       if (subject)
643         msg->env->subject = m_strdup(subject);
644
645       if (includeFile)
646         infile = includeFile;
647     }
648
649     if (infile || bodytext) {
650       if (infile) {
651         if (m_strcmp("-", infile) == 0)
652           fin = stdin;
653         else {
654           char path[_POSIX_PATH_MAX];
655
656           m_strcpy(path, sizeof(path), infile);
657           mutt_expand_path (path, sizeof (path));
658           if ((fin = fopen (path, "r")) == NULL) {
659             if (!option (OPTNOCURSES))
660               mutt_endwin (NULL);
661             perror (path);
662             exit (1);
663           }
664         }
665       }
666       else
667         fin = NULL;
668
669       if (draftFile)
670         msg->env = mutt_read_rfc822_header (fin, NULL, 1, 0);
671
672       /* is the following if still needed? */
673
674       fout = m_tempfile(buf, sizeof(buf), NONULL(MCore.tmpdir), NULL);
675       tempfile = m_strdup(buf);
676
677       if (tempfile) {
678         if (!fout) {
679           if (!option (OPTNOCURSES))
680             mutt_endwin (NULL);
681           perror (tempfile);
682           m_fclose(&fin);
683           p_delete(&tempfile);
684           exit (1);
685         }
686         if (fin)
687           mutt_copy_stream (fin, fout);
688         else if (bodytext)
689           fputs (bodytext, fout);
690         m_fclose(&fout);
691         if (fin && fin != stdin)
692           m_fclose(&fin);
693       }
694     }
695
696     p_delete(&bodytext);
697
698     if (attach) {
699       string_list_t *t = attach;
700       BODY *a = NULL;
701
702       while (t) {
703         if (a) {
704           a->next = mutt_make_file_attach (t->data);
705           a = a->next;
706         }
707         else
708           msg->content = a = mutt_make_file_attach (t->data);
709         if (!a) {
710           if (!option (OPTNOCURSES))
711             mutt_endwin (NULL);
712           fprintf (stderr, _("%s: unable to attach file.\n"), t->data);
713           string_list_wipe(&attach);
714           exit (1);
715         }
716         t = t->next;
717       }
718       string_list_wipe(&attach);
719     }
720
721     ci_send_message (sendflags, msg, tempfile, NULL, NULL);
722
723     if (!option (OPTNOCURSES))
724       mutt_endwin (NULL);
725   }
726   else {
727     if (flags & M_BUFFY) {
728       if (!buffy_check (0)) {
729         mutt_endwin _("No mailbox with new mail.");
730
731         exit (1);
732       }
733       folder[0] = 0;
734       buffy_next (folder, sizeof (folder));
735     }
736     else if (flags & M_SELECT) {
737 #ifdef USE_NNTP
738       if (flags & M_NEWS) {
739         set_option (OPTNEWS);
740         if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer))) {
741           mutt_endwin (Errorbuf);
742           exit (1);
743         }
744       } else
745 #endif
746       if (!Incoming.len) {
747         mutt_endwin _("No incoming mailboxes defined.");
748
749         exit (1);
750       }
751       folder[0] = 0;
752       mutt_select_file (folder, sizeof (folder), M_SEL_FOLDER | M_SEL_BUFFY);
753       if (!folder[0]) {
754         mutt_endwin (NULL);
755         exit (0);
756       }
757     }
758
759     if (!folder[0])
760       m_strcpy(folder, sizeof(folder), NONULL(Spoolfile));
761
762 #ifdef USE_NNTP
763     if (option (OPTNEWS)) {
764       unset_option (OPTNEWS);
765       nntp_expand_path (folder, sizeof (folder),
766                         &CurrentNewsSrv->conn->account);
767     } else
768 #endif
769       mutt_expand_path (folder, sizeof (folder));
770
771     m_strreplace(&CurrentFolder, folder);
772     m_strreplace(&LastFolder, folder);
773
774     if (flags & M_IGNORE) {
775       /* check to see if there are any messages in the folder */
776       switch (mx_check_empty (folder)) {
777       case -1:
778         mutt_endwin (strerror (errno));
779         exit (1);
780       case 1:
781         mutt_endwin _("Mailbox is empty.");
782         exit (1);
783       }
784     }
785
786     mutt_folder_hook (folder);
787
788     if ((Context = mx_open_mailbox (folder, ((flags & M_RO)
789                                              || option (OPTREADONLY)) ?
790                                     M_READONLY : 0, NULL))
791         || !explicit_folder) {
792       mutt_index_menu ();
793       if (option (OPTXTERMSETTITLES))
794         printf("\033]2;%s\007", NONULL(XtermLeave));
795       if (Context)
796         p_delete(&Context);
797     }
798     mutt_endwin (Errorbuf);
799   }
800
801   luaM_shutdown();
802   mutt_sasl_shutdown();
803   exit (0);
804 }