Fix bug #591676 (MSG_QUEUED lost on restart)
[claws.git] / src / main.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <gtk/gtkmain.h>
28 #include <gtk/gtkrc.h>
29
30 #if HAVE_GDK_IMLIB
31 #  include <gdk_imlib.h>
32 #endif
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <ctype.h>
38 #include <unistd.h>
39 #include <time.h>
40 #include <sys/stat.h>
41 #include <sys/types.h>
42 #include <signal.h>
43
44 #if HAVE_LOCALE_H
45 #  include <locale.h>
46 #endif
47
48 #if USE_GPGME
49 #  include <gpgme.h>
50 #  include "passphrase.h"
51 #endif
52
53 #include "intl.h"
54 #include "main.h"
55 #include "mainwindow.h"
56 #include "folderview.h"
57 #include "summaryview.h"
58 #include "prefs_common.h"
59 #include "prefs_filter.h"
60 #include "prefs_account.h"
61 #include "prefs_actions.h"
62 #include "scoring.h"
63 #include "prefs_display_header.h"
64 #include "account.h"
65 #include "procmsg.h"
66 #include "inc.h"
67 #include "import.h"
68 #include "manage_window.h"
69 #include "alertpanel.h"
70 #include "statusbar.h"
71 #include "addressbook.h"
72 #include "compose.h"
73 #include "folder.h"
74 #include "setup.h"
75 #include "utils.h"
76 #include "gtkutils.h"
77
78 #if USE_GPGME
79 #  include "rfc2015.h"
80 #endif
81 #if USE_SSL
82 #  include "ssl.h"
83 #endif
84
85 #include "version.h"
86
87 #include "crash.h"
88
89 gchar *prog_version;
90 gchar *startup_dir;
91 gchar *argv0;
92 gboolean debug_mode = FALSE;
93
94 static gint lock_socket = -1;
95 static gint lock_socket_tag = 0;
96
97 static struct Cmd {
98         gboolean receive;
99         gboolean receive_all;
100         gboolean compose;
101         const gchar *compose_mailto;
102         GPtrArray *attach_files;
103         gboolean status;
104         gboolean send;
105         gboolean crash;
106         gchar   *crash_params;
107 } cmd;
108
109 static void parse_cmd_opt(int argc, char *argv[]);
110
111 #if USE_GPGME
112 static void idle_function_for_gpgme(void);
113 #endif /* USE_GPGME */
114
115 static gint prohibit_duplicate_launch   (void);
116 static void lock_socket_input_cb        (gpointer          data,
117                                          gint              source,
118                                          GdkInputCondition condition);
119 #ifndef CLAWS                                    
120 static 
121 #endif
122 gchar *get_socket_name          (void);
123
124
125 static void open_compose_new            (const gchar    *address,
126                                          GPtrArray      *attach_files);
127
128 static void send_queue                  (void);
129 static void initial_processing          (FolderItem *item, gpointer data);
130
131 #if 0
132 /* for gettext */
133 _("File `%s' already exists.\n"
134   "Can't create folder.")
135 #endif
136
137 #define MAKE_DIR_IF_NOT_EXIST(dir) \
138 { \
139         if (!is_dir_exist(dir)) { \
140                 if (is_file_exist(dir)) { \
141                         alertpanel_warning \
142                                 (_("File `%s' already exists.\n" \
143                                    "Can't create folder."), \
144                                  dir); \
145                         return 1; \
146                 } \
147                 if (make_dir(dir) < 0) \
148                         return 1; \
149         } \
150 }
151
152 int main(int argc, char *argv[])
153 {
154         gchar *userrc;
155         MainWindow *mainwin;
156         FolderView *folderview;
157
158         setlocale(LC_ALL, "");
159         bindtextdomain(PACKAGE, LOCALEDIR);
160         textdomain(PACKAGE);
161
162         prog_version = PROG_VERSION;
163         startup_dir = g_get_current_dir();
164         argv0 = g_strdup(argv[0]);
165
166         parse_cmd_opt(argc, argv);
167
168         gtk_set_locale();
169         gtk_init(&argc, &argv);
170
171         if (cmd.crash) {
172                 crash_main(cmd.crash_params);
173                 return 0;
174         }
175
176         crash_install_handlers();
177
178 #if USE_THREADS || USE_LDAP
179         g_thread_init(NULL);
180         if (!g_thread_supported())
181                 g_error(_("g_thread is not supported by glib.\n"));
182 #endif
183
184 #if HAVE_GDK_IMLIB
185         gdk_imlib_init();
186         gtk_widget_push_visual(gdk_imlib_get_visual());
187         gtk_widget_push_colormap(gdk_imlib_get_colormap());
188 #endif
189
190 #if USE_SSL
191         ssl_init();
192 #endif
193
194         srandom((gint)time(NULL));
195
196         /* parse gtkrc files */
197         userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtkrc",
198                              NULL);
199         gtk_rc_parse(userrc);
200         g_free(userrc);
201         userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtk",
202                              G_DIR_SEPARATOR_S, "gtkrc", NULL);
203         gtk_rc_parse(userrc);
204         g_free(userrc);
205         userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc", NULL);
206         gtk_rc_parse(userrc);
207         g_free(userrc);
208
209         gtk_rc_parse("./gtkrc");
210
211         userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
212         gtk_item_factory_parse_rc(userrc);
213         g_free(userrc);
214
215         CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
216
217         /* check and create unix domain socket */
218         lock_socket = prohibit_duplicate_launch();
219         if (lock_socket < 0) return 0;
220
221         if (cmd.status) {
222                 puts("0 Sylpheed not running.");
223                 return 0;
224         }
225
226         /* backup if old rc file exists */
227         if (is_file_exist(RC_DIR)) {
228                 if (rename(RC_DIR, RC_DIR ".bak") < 0)
229                         FILE_OP_ERROR(RC_DIR, "rename");
230         }
231         MAKE_DIR_IF_NOT_EXIST(RC_DIR);
232         MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
233         MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
234         MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
235         MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
236         MAKE_DIR_IF_NOT_EXIST(RC_DIR G_DIR_SEPARATOR_S "uidl");
237
238         if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log")) {
239                 if (rename(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log",
240                            RC_DIR G_DIR_SEPARATOR_S "sylpheed.log.bak") < 0)
241                         FILE_OP_ERROR("sylpheed.log", "rename");
242         }
243         set_log_file(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log");
244
245         if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "assortrc") &&
246             !is_file_exist(RC_DIR G_DIR_SEPARATOR_S "filterrc")) {
247                 if (rename(RC_DIR G_DIR_SEPARATOR_S "assortrc",
248                            RC_DIR G_DIR_SEPARATOR_S "filterrc") < 0)
249                         FILE_OP_ERROR(RC_DIR G_DIR_SEPARATOR_S "assortrc",
250                                       "rename");
251         }
252
253         prefs_common_init();
254         prefs_common_read_config();
255
256 #if USE_GPGME
257         if (gpgme_check_engine()) {  /* Also does some gpgme init */
258                 rfc2015_disable_all();
259                 debug_print("gpgme_engine_version:\n%s\n",
260                             gpgme_get_engine_info());
261
262                 if (prefs_common.gpg_warning) {
263                         AlertValue val;
264
265                         val = alertpanel_message_with_disable
266                                 (_("Warning"),
267                                  _("GnuPG is not installed properly, or needs to be upgraded.\n"
268                                    "OpenPGP support disabled."));
269                         if (val & G_ALERTDISABLE)
270                                 prefs_common.gpg_warning = FALSE;
271                 }
272         }
273         gpgme_register_idle(idle_function_for_gpgme);
274 #endif
275
276 #if USE_ASPELL
277         gtkaspellcheckers = gtkaspell_checkers_new();
278 #endif
279         
280
281         prefs_common_save_config();
282         prefs_filter_read_config();
283         prefs_filter_write_config();
284         prefs_actions_read_config();
285         prefs_actions_write_config();
286         prefs_display_header_read_config();
287         prefs_display_header_write_config();
288         /* prefs_filtering_read_config(); */
289         addressbook_read_file();
290         renderer_read_config();
291
292         gtkut_widget_init();
293
294         mainwin = main_window_create
295                 (prefs_common.sep_folder | prefs_common.sep_msg << 1);
296         folderview = mainwin->folderview;
297
298         /* register the callback of unix domain socket input */
299         lock_socket_tag = gdk_input_add(lock_socket,
300                                         GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
301                                         lock_socket_input_cb,
302                                         mainwin);
303
304         account_read_config_all();
305         account_save_config_all();
306
307         if (folder_read_list() < 0) {
308                 setup(mainwin);
309                 folder_write_list();
310         }
311         if (!account_get_list()) {
312                 account_edit_open();
313                 account_add();
314         }
315
316         account_set_missing_folder();
317         folder_set_missing_folders();
318         folderview_set(folderview);
319
320         /* prefs_scoring_read_config(); */
321         prefs_matcher_read_config();
322
323         /* make one all-folder processing before using sylpheed */
324         folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
325
326         addressbook_read_file();
327
328         inc_autocheck_timer_init(mainwin);
329
330         /* ignore SIGPIPE signal for preventing sudden death of program */
331         signal(SIGPIPE, SIG_IGN);
332
333         if (cmd.receive_all || prefs_common.chk_on_startup)
334                 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
335         else if (cmd.receive)
336                 inc_mail(mainwin, prefs_common.newmail_notify_manu);
337         else
338                 gtk_widget_grab_focus(folderview->ctree);
339
340         if (cmd.compose)
341                 open_compose_new(cmd.compose_mailto, cmd.attach_files);
342         if (cmd.attach_files) {
343                 ptr_array_free_strings(cmd.attach_files);
344                 g_ptr_array_free(cmd.attach_files, TRUE);
345                 cmd.attach_files = NULL;
346         }
347         if (cmd.send)
348                 send_queue();
349
350         gtk_main();
351
352         addressbook_destroy();
353
354 #if USE_ASPELL       
355         gtkaspell_checkers_delete();
356 #endif
357
358         return 0;
359 }
360
361 static void parse_cmd_opt(int argc, char *argv[])
362 {
363         gint i;
364
365         for (i = 1; i < argc; i++) {
366                 if (!strncmp(argv[i], "--debug", 7))
367                         debug_mode = TRUE;
368                 else if (!strncmp(argv[i], "--receive-all", 13))
369                         cmd.receive_all = TRUE;
370                 else if (!strncmp(argv[i], "--receive", 9))
371                         cmd.receive = TRUE;
372                 else if (!strncmp(argv[i], "--compose", 9)) {
373                         const gchar *p = argv[i + 1];
374
375                         cmd.compose = TRUE;
376                         cmd.compose_mailto = NULL;
377                         if (p && *p != '\0' && *p != '-') {
378                                 if (!strncmp(p, "mailto:", 7))
379                                         cmd.compose_mailto = p + 7;
380                                 else
381                                         cmd.compose_mailto = p;
382                                 i++;
383                         }
384                 } else if (!strncmp(argv[i], "--attach", 8)) {
385                         const gchar *p = argv[i + 1];
386                         gchar *file;
387
388                         while (p && *p != '\0' && *p != '-') {
389                                 if (!cmd.attach_files)
390                                         cmd.attach_files = g_ptr_array_new();
391                                 if (*p != G_DIR_SEPARATOR)
392                                         file = g_strconcat(startup_dir,
393                                                            G_DIR_SEPARATOR_S,
394                                                            p, NULL);
395                                 else
396                                         file = g_strdup(p);
397                                 g_ptr_array_add(cmd.attach_files, file);
398                                 i++;
399                                 p = argv[i + 1];
400                         }
401                 } else if (!strncmp(argv[i], "--send", 6)) {
402                         cmd.send = TRUE;
403                 } else if (!strncmp(argv[i], "--version", 9)) {
404                         puts("Sylpheed version " VERSION);
405                         exit(0);
406                 } else if (!strncmp(argv[i], "--status", 8)) {
407                         cmd.status = TRUE;
408                 } else if (!strncmp(argv[i], "--help", 6)) {
409                         g_print(_("Usage: %s [OPTION]...\n"),
410                                 g_basename(argv[0]));
411
412                         puts(_("  --compose [address]    open composition window"));
413                         puts(_("  --attach file1 [file2]...\n"
414                                "                         open composition window with specified files\n"
415                                "                         attached"));
416                         puts(_("  --receive              receive new messages"));
417                         puts(_("  --receive-all          receive new messages of all accounts"));
418                         puts(_("  --send                 send all queued messages"));
419                         puts(_("  --status               show the total number of messages"));
420                         puts(_("  --debug                debug mode"));
421                         puts(_("  --help                 display this help and exit"));
422                         puts(_("  --version              output version information and exit"));
423
424                         exit(1);
425                 } else if (!strncmp(argv[i], "--crash", 7)) {
426                         cmd.crash = TRUE;
427                         cmd.crash_params = g_strdup(argv[i + 1]);
428                         i++;
429                 }
430                 
431         }
432
433         if (cmd.attach_files && cmd.compose == FALSE) {
434                 cmd.compose = TRUE;
435                 cmd.compose_mailto = NULL;
436         }
437 }
438
439 static gint get_queued_message_num(void)
440 {
441         FolderItem *queue;
442
443         queue = folder_get_default_queue();
444         if (!queue) return -1;
445
446         folder_item_scan(queue);
447         return queue->total;
448 }
449
450 static void save_all_caches(FolderItem *item, gpointer data)
451 {
452         if (!item->cache)
453                 return;
454         if (!item->stype == F_QUEUE)    
455                 folder_item_write_cache(item);
456 }
457
458 static void initial_processing(FolderItem *item, gpointer data)
459 {
460         MainWindow *mainwin = (MainWindow *)data;
461         gchar *buf;
462
463         g_return_if_fail(item);
464         buf = g_strdup_printf(_("Processing (%s)..."), 
465                               item->path 
466                               ? item->path 
467                               : _("top level folder"));
468         debug_print("%s\n", buf);
469         g_free(buf);
470
471         main_window_cursor_wait(mainwin);
472         
473         folder_item_apply_processing(item);
474
475         if (item->stype == F_QUEUE)
476                 folder_item_scan(item);
477         
478         debug_print("done.\n");
479         STATUSBAR_POP(mainwin);
480         main_window_cursor_normal(mainwin);
481 }
482
483 void app_will_exit(GtkWidget *widget, gpointer data)
484 {
485         MainWindow *mainwin = data;
486         gchar *filename;
487
488         if (compose_get_compose_list()) {
489                 if (alertpanel(_("Notice"),
490                                _("Composing message exists. Really quit?"),
491                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
492                         return;
493                 manage_window_focus_in(mainwin->window, NULL, NULL);
494         }
495
496         if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
497                 if (alertpanel(_("Queued messages"),
498                                _("Some unsent messages are queued. Exit now?"),
499                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
500                         return;
501                 manage_window_focus_in(mainwin->window, NULL, NULL);
502         }
503
504         inc_autocheck_timer_remove();
505
506 #if USE_GPGME
507         gpgmegtk_free_passphrase();
508 #endif
509
510         if (prefs_common.clean_on_exit)
511                 main_window_empty_trash(mainwin, prefs_common.ask_on_clean);
512
513         /* save prefs for opened folder */
514         if(mainwin->folderview->opened)
515         {
516                 FolderItem *item;
517
518                 item = gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->folderview->ctree), mainwin->folderview->opened);
519                 summary_save_prefs_to_folderitem(mainwin->folderview->summaryview, item);
520         }
521
522         /* save all state before exiting */
523         folder_write_list();
524         folder_func_to_all_folders(save_all_caches, NULL);
525
526         main_window_get_size(mainwin);
527         main_window_get_position(mainwin);
528         prefs_common_save_config();
529         prefs_filter_write_config();
530         account_save_config_all();
531         addressbook_export_to_file();
532
533         filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
534         gtk_item_factory_dump_rc(filename, NULL, TRUE);
535         g_free(filename);
536
537         /* delete temporary files */
538         remove_all_files(get_mime_tmp_dir());
539
540         close_log_file();
541
542         /* delete unix domain socket */
543         gdk_input_remove(lock_socket_tag);
544         fd_close(lock_socket);
545         filename = get_socket_name();
546         unlink(filename);
547
548 #if USE_SSL
549         ssl_done();
550 #endif
551
552         gtk_main_quit();
553 }
554
555 #if USE_GPGME
556 static void idle_function_for_gpgme(void)
557 {
558         while (gtk_events_pending())
559                 gtk_main_iteration();
560 }
561 #endif /* USE_GPGME */
562
563 /*
564  * CLAWS: want this public so crash dialog can delete the
565  * lock file too
566  */
567 #ifndef CLAWS
568 static
569 #endif
570 gchar *get_socket_name(void)
571 {
572         static gchar *filename = NULL;
573
574         if (filename == NULL) {
575                 filename = g_strdup_printf("%s%csylpheed-%d",
576                                            g_get_tmp_dir(), G_DIR_SEPARATOR,
577                                            getuid());
578         }
579
580         return filename;
581 }
582
583 static gint prohibit_duplicate_launch(void)
584 {
585         gint uxsock;
586         gchar *path;
587
588         path = get_socket_name();
589         uxsock = fd_connect_unix(path);
590         if (uxsock < 0) {
591                 unlink(path);
592                 return fd_open_unix(path);
593         }
594
595         /* remote command mode */
596
597         debug_print("another Sylpheed is already running.\n");
598
599         if (cmd.receive_all)
600                 fd_write(uxsock, "receive_all\n", 12);
601         else if (cmd.receive)
602                 fd_write(uxsock, "receive\n", 8);
603         else if (cmd.compose && cmd.attach_files) {
604                 gchar *str, *compose_str;
605                 gint i;
606
607                 if (cmd.compose_mailto)
608                         compose_str = g_strdup_printf("compose_attach %s\n",
609                                                       cmd.compose_mailto);
610                 else
611                         compose_str = g_strdup("compose_attach\n");
612
613                 fd_write(uxsock, compose_str, strlen(compose_str));
614                 g_free(compose_str);
615
616                 for (i = 0; i < cmd.attach_files->len; i++) {
617                         str = g_ptr_array_index(cmd.attach_files, i);
618                         fd_write(uxsock, str, strlen(str));
619                         fd_write(uxsock, "\n", 1);
620                 }
621
622                 fd_write(uxsock, ".\n", 2);
623         } else if (cmd.compose) {
624                 gchar *compose_str;
625
626                 if (cmd.compose_mailto)
627                         compose_str = g_strdup_printf("compose %s\n", cmd.compose_mailto);
628                 else
629                         compose_str = g_strdup("compose\n");
630
631                 fd_write(uxsock, compose_str, strlen(compose_str));
632                 g_free(compose_str);
633         } else if (cmd.send) {
634                 fd_write(uxsock, "send\n", 5);
635         } else if (cmd.status) {
636                 gchar buf[BUFFSIZE];
637
638                 fd_write(uxsock, "status\n", 7);
639                 fd_gets(uxsock, buf, sizeof(buf));
640                 fputs(buf, stdout);
641         } else
642                 fd_write(uxsock, "popup\n", 6);
643
644         fd_close(uxsock);
645         return -1;
646 }
647
648 static void lock_socket_input_cb(gpointer data,
649                                  gint source,
650                                  GdkInputCondition condition)
651 {
652         MainWindow *mainwin = (MainWindow *)data;
653         gint sock;
654         gchar buf[BUFFSIZE];
655
656         sock = fd_accept(source);
657         fd_gets(sock, buf, sizeof(buf));
658
659         if (!strncmp(buf, "popup", 5)) {
660                 main_window_popup(mainwin);
661         } else if (!strncmp(buf, "receive_all", 11)) {
662                 main_window_popup(mainwin);
663                 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
664         } else if (!strncmp(buf, "receive", 7)) {
665                 main_window_popup(mainwin);
666                 inc_mail(mainwin, prefs_common.newmail_notify_manu);
667         } else if (!strncmp(buf, "compose_attach", 14)) {
668                 GPtrArray *files;
669                 gchar *mailto;
670
671                 mailto = g_strdup(buf + strlen("compose_attach") + 1);
672                 files = g_ptr_array_new();
673                 while (fd_gets(sock, buf, sizeof(buf)) > 0) {
674                         if (buf[0] == '.' && buf[1] == '\n') break;
675                         strretchomp(buf);
676                         g_ptr_array_add(files, g_strdup(buf));
677                 }
678                 open_compose_new(mailto, files);
679                 ptr_array_free_strings(files);
680                 g_ptr_array_free(files, TRUE);
681                 g_free(mailto);
682         } else if (!strncmp(buf, "compose", 7)) {
683                 open_compose_new(buf + strlen("compose") + 1, NULL);
684         } else if (!strncmp(buf, "send", 4)) {
685                 send_queue();
686         } else if (!strncmp(buf, "status", 6)) {
687                 guint new, unread, total;
688
689                 folder_count_total_msgs(&new, &unread, &total);
690                 g_snprintf(buf, sizeof(buf), "%d %d %d\n", new, unread, total);
691                 fd_write(sock, buf, strlen(buf));
692         }
693
694         fd_close(sock);
695 }
696
697 static void open_compose_new(const gchar *address, GPtrArray *attach_files)
698 {
699         gchar *addr = NULL;
700
701         if (address) {
702                 Xstrdup_a(addr, address, return);
703                 g_strstrip(addr);
704         }
705
706         compose_new(NULL, addr, attach_files);
707 }
708
709 static void send_queue(void)
710 {
711         GList *list;
712         FolderItem *def_outbox;
713
714         def_outbox = folder_get_default_outbox();
715
716         for (list = folder_get_list(); list != NULL; list = list->next) {
717                 Folder *folder = list->data;
718
719                 if (folder->queue) {
720                         if (procmsg_send_queue
721                                 (folder->queue, prefs_common.savemsg) < 0)
722                                 alertpanel_error(_("Some errors occurred while sending queued messages."));
723                         statusbar_pop_all();
724                         folder_item_scan(folder->queue);
725                         folderview_update_item(folder->queue, TRUE);
726                         if (prefs_common.savemsg && folder->outbox) {
727                                 folderview_update_item(folder->outbox, TRUE);
728                                 if (folder->outbox == def_outbox)
729                                         def_outbox = NULL;
730                         }
731                 }
732         }
733
734         if (prefs_common.savemsg && def_outbox)
735                 folderview_update_item(def_outbox, TRUE);
736 }