d2430b7728cbd5ef5b4289d705e40fcc0e00cea1
[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 gchar * get_crashfile_name       (void);
117 static void lock_socket_input_cb        (gpointer          data,
118                                          gint              source,
119                                          GdkInputCondition condition);
120 #ifndef CLAWS                                    
121 static 
122 #endif
123 gchar *get_socket_name          (void);
124
125
126 static void open_compose_new            (const gchar    *address,
127                                          GPtrArray      *attach_files);
128
129 static void send_queue                  (void);
130 static void initial_processing          (FolderItem *item, gpointer data);
131
132 #if 0
133 /* for gettext */
134 _("File `%s' already exists.\n"
135   "Can't create folder.")
136 #endif
137
138 #define MAKE_DIR_IF_NOT_EXIST(dir) \
139 { \
140         if (!is_dir_exist(dir)) { \
141                 if (is_file_exist(dir)) { \
142                         alertpanel_warning \
143                                 (_("File `%s' already exists.\n" \
144                                    "Can't create folder."), \
145                                  dir); \
146                         return 1; \
147                 } \
148                 if (make_dir(dir) < 0) \
149                         return 1; \
150         } \
151 }
152
153 int main(int argc, char *argv[])
154 {
155         gchar *userrc;
156         MainWindow *mainwin;
157         FolderView *folderview;
158
159         setlocale(LC_ALL, "");
160         bindtextdomain(PACKAGE, LOCALEDIR);
161         textdomain(PACKAGE);
162
163         prog_version = PROG_VERSION;
164         startup_dir = g_get_current_dir();
165         argv0 = g_strdup(argv[0]);
166
167         parse_cmd_opt(argc, argv);
168
169         gtk_set_locale();
170         gtk_init(&argc, &argv);
171
172         if (cmd.crash) {
173                 crash_main(cmd.crash_params);
174                 return 0;
175         }
176
177         crash_install_handlers();
178
179 #if USE_THREADS || USE_LDAP
180         g_thread_init(NULL);
181         if (!g_thread_supported())
182                 g_error(_("g_thread is not supported by glib.\n"));
183 #endif
184
185 #if HAVE_GDK_IMLIB
186         gdk_imlib_init();
187         gtk_widget_push_visual(gdk_imlib_get_visual());
188         gtk_widget_push_colormap(gdk_imlib_get_colormap());
189 #endif
190
191 #if USE_SSL
192         ssl_init();
193 #endif
194
195         srandom((gint)time(NULL));
196
197         /* parse gtkrc files */
198         userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtkrc",
199                              NULL);
200         gtk_rc_parse(userrc);
201         g_free(userrc);
202         userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtk",
203                              G_DIR_SEPARATOR_S, "gtkrc", NULL);
204         gtk_rc_parse(userrc);
205         g_free(userrc);
206         userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc", NULL);
207         gtk_rc_parse(userrc);
208         g_free(userrc);
209
210         gtk_rc_parse("./gtkrc");
211
212         userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
213         gtk_item_factory_parse_rc(userrc);
214         g_free(userrc);
215
216         CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
217
218         /* check and create unix domain socket */
219         lock_socket = prohibit_duplicate_launch();
220         if (lock_socket < 0) return 0;
221
222         if (cmd.status) {
223                 puts("0 Sylpheed not running.");
224                 return 0;
225         }
226
227         /* backup if old rc file exists */
228         if (is_file_exist(RC_DIR)) {
229                 if (rename(RC_DIR, RC_DIR ".bak") < 0)
230                         FILE_OP_ERROR(RC_DIR, "rename");
231         }
232         MAKE_DIR_IF_NOT_EXIST(RC_DIR);
233         MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
234         MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
235         MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
236         MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
237         MAKE_DIR_IF_NOT_EXIST(RC_DIR G_DIR_SEPARATOR_S "uidl");
238
239         if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log")) {
240                 if (rename(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log",
241                            RC_DIR G_DIR_SEPARATOR_S "sylpheed.log.bak") < 0)
242                         FILE_OP_ERROR("sylpheed.log", "rename");
243         }
244         set_log_file(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log");
245
246         if (is_file_exist(RC_DIR G_DIR_SEPARATOR_S "assortrc") &&
247             !is_file_exist(RC_DIR G_DIR_SEPARATOR_S "filterrc")) {
248                 if (rename(RC_DIR G_DIR_SEPARATOR_S "assortrc",
249                            RC_DIR G_DIR_SEPARATOR_S "filterrc") < 0)
250                         FILE_OP_ERROR(RC_DIR G_DIR_SEPARATOR_S "assortrc",
251                                       "rename");
252         }
253
254         prefs_common_init();
255         prefs_common_read_config();
256
257 #if USE_GPGME
258         if (gpgme_check_engine()) {  /* Also does some gpgme init */
259                 rfc2015_disable_all();
260                 debug_print("gpgme_engine_version:\n%s\n",
261                             gpgme_get_engine_info());
262
263                 if (prefs_common.gpg_warning) {
264                         AlertValue val;
265
266                         val = alertpanel_message_with_disable
267                                 (_("Warning"),
268                                  _("GnuPG is not installed properly, or needs to be upgraded.\n"
269                                    "OpenPGP support disabled."));
270                         if (val & G_ALERTDISABLE)
271                                 prefs_common.gpg_warning = FALSE;
272                 }
273         }
274         gpgme_register_idle(idle_function_for_gpgme);
275 #endif
276
277 #if USE_ASPELL
278         gtkaspellcheckers = gtkaspell_checkers_new();
279 #endif
280         
281
282         prefs_common_save_config();
283         prefs_filter_read_config();
284         prefs_filter_write_config();
285         prefs_actions_read_config();
286         prefs_actions_write_config();
287         prefs_display_header_read_config();
288         prefs_display_header_write_config();
289         /* prefs_filtering_read_config(); */
290         addressbook_read_file();
291         renderer_read_config();
292
293         gtkut_widget_init();
294
295         mainwin = main_window_create
296                 (prefs_common.sep_folder | prefs_common.sep_msg << 1);
297         folderview = mainwin->folderview;
298
299         /* register the callback of unix domain socket input */
300         lock_socket_tag = gdk_input_add(lock_socket,
301                                         GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
302                                         lock_socket_input_cb,
303                                         mainwin);
304
305         account_read_config_all();
306         account_save_config_all();
307
308         if (folder_read_list() < 0) {
309                 setup(mainwin);
310                 folder_write_list();
311         }
312         if (!account_get_list()) {
313                 account_edit_open();
314                 account_add();
315         }
316
317         account_set_missing_folder();
318         folder_set_missing_folders();
319         folderview_set(folderview);
320
321         /* prefs_scoring_read_config(); */
322         prefs_matcher_read_config();
323
324         /* make one all-folder processing before using sylpheed */
325         folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
326
327         /* if Sylpheed crashed, rebuild caches */
328         if (!cmd.crash && is_file_exist(get_crashfile_name())) {
329                 debug_print("Sylpheed crashed, checking for new messages\n");
330                 folderview_check_new_all();
331         }
332         /* make the crash-indicator file */
333         str_write_to_file("foo", get_crashfile_name());
334
335         addressbook_read_file();
336
337         inc_autocheck_timer_init(mainwin);
338
339         /* ignore SIGPIPE signal for preventing sudden death of program */
340         signal(SIGPIPE, SIG_IGN);
341
342         if (cmd.receive_all || prefs_common.chk_on_startup)
343                 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
344         else if (cmd.receive)
345                 inc_mail(mainwin, prefs_common.newmail_notify_manu);
346         else
347                 gtk_widget_grab_focus(folderview->ctree);
348
349         if (cmd.compose)
350                 open_compose_new(cmd.compose_mailto, cmd.attach_files);
351         if (cmd.attach_files) {
352                 ptr_array_free_strings(cmd.attach_files);
353                 g_ptr_array_free(cmd.attach_files, TRUE);
354                 cmd.attach_files = NULL;
355         }
356         if (cmd.send)
357                 send_queue();
358
359         gtk_main();
360
361         addressbook_destroy();
362
363 #if USE_ASPELL       
364         gtkaspell_checkers_delete();
365 #endif
366
367         return 0;
368 }
369
370 static void parse_cmd_opt(int argc, char *argv[])
371 {
372         gint i;
373
374         for (i = 1; i < argc; i++) {
375                 if (!strncmp(argv[i], "--debug", 7))
376                         debug_mode = TRUE;
377                 else if (!strncmp(argv[i], "--receive-all", 13))
378                         cmd.receive_all = TRUE;
379                 else if (!strncmp(argv[i], "--receive", 9))
380                         cmd.receive = TRUE;
381                 else if (!strncmp(argv[i], "--compose", 9)) {
382                         const gchar *p = argv[i + 1];
383
384                         cmd.compose = TRUE;
385                         cmd.compose_mailto = NULL;
386                         if (p && *p != '\0' && *p != '-') {
387                                 if (!strncmp(p, "mailto:", 7))
388                                         cmd.compose_mailto = p + 7;
389                                 else
390                                         cmd.compose_mailto = p;
391                                 i++;
392                         }
393                 } else if (!strncmp(argv[i], "--attach", 8)) {
394                         const gchar *p = argv[i + 1];
395                         gchar *file;
396
397                         while (p && *p != '\0' && *p != '-') {
398                                 if (!cmd.attach_files)
399                                         cmd.attach_files = g_ptr_array_new();
400                                 if (*p != G_DIR_SEPARATOR)
401                                         file = g_strconcat(startup_dir,
402                                                            G_DIR_SEPARATOR_S,
403                                                            p, NULL);
404                                 else
405                                         file = g_strdup(p);
406                                 g_ptr_array_add(cmd.attach_files, file);
407                                 i++;
408                                 p = argv[i + 1];
409                         }
410                 } else if (!strncmp(argv[i], "--send", 6)) {
411                         cmd.send = TRUE;
412                 } else if (!strncmp(argv[i], "--version", 9)) {
413                         puts("Sylpheed version " VERSION);
414                         exit(0);
415                 } else if (!strncmp(argv[i], "--status", 8)) {
416                         cmd.status = TRUE;
417                 } else if (!strncmp(argv[i], "--help", 6)) {
418                         g_print(_("Usage: %s [OPTION]...\n"),
419                                 g_basename(argv[0]));
420
421                         puts(_("  --compose [address]    open composition window"));
422                         puts(_("  --attach file1 [file2]...\n"
423                                "                         open composition window with specified files\n"
424                                "                         attached"));
425                         puts(_("  --receive              receive new messages"));
426                         puts(_("  --receive-all          receive new messages of all accounts"));
427                         puts(_("  --send                 send all queued messages"));
428                         puts(_("  --status               show the total number of messages"));
429                         puts(_("  --debug                debug mode"));
430                         puts(_("  --help                 display this help and exit"));
431                         puts(_("  --version              output version information and exit"));
432
433                         exit(1);
434                 } else if (!strncmp(argv[i], "--crash", 7)) {
435                         cmd.crash = TRUE;
436                         cmd.crash_params = g_strdup(argv[i + 1]);
437                         i++;
438                 }
439                 
440         }
441
442         if (cmd.attach_files && cmd.compose == FALSE) {
443                 cmd.compose = TRUE;
444                 cmd.compose_mailto = NULL;
445         }
446 }
447
448 static gint get_queued_message_num(void)
449 {
450         FolderItem *queue;
451
452         queue = folder_get_default_queue();
453         if (!queue) return -1;
454
455         folder_item_scan(queue);
456         return queue->total;
457 }
458
459 static void save_all_caches(FolderItem *item, gpointer data)
460 {
461         if (!item->cache)
462                 return;
463         folder_item_write_cache(item);
464 }
465
466 static void initial_processing(FolderItem *item, gpointer data)
467 {
468         MainWindow *mainwin = (MainWindow *)data;
469         gchar *buf;
470
471         g_return_if_fail(item);
472         buf = g_strdup_printf(_("Processing (%s)..."), 
473                               item->path 
474                               ? item->path 
475                               : _("top level folder"));
476         debug_print("%s\n", buf);
477         g_free(buf);
478
479         main_window_cursor_wait(mainwin);
480         
481         folder_item_apply_processing(item);
482
483         debug_print("done.\n");
484         STATUSBAR_POP(mainwin);
485         main_window_cursor_normal(mainwin);
486 }
487
488 void app_will_exit(GtkWidget *widget, gpointer data)
489 {
490         MainWindow *mainwin = data;
491         gchar *filename;
492
493         if (compose_get_compose_list()) {
494                 if (alertpanel(_("Notice"),
495                                _("Composing message exists. Really quit?"),
496                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
497                         return;
498                 manage_window_focus_in(mainwin->window, NULL, NULL);
499         }
500
501         if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
502                 if (alertpanel(_("Queued messages"),
503                                _("Some unsent messages are queued. Exit now?"),
504                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
505                         return;
506                 manage_window_focus_in(mainwin->window, NULL, NULL);
507         }
508
509         inc_autocheck_timer_remove();
510
511 #if USE_GPGME
512         gpgmegtk_free_passphrase();
513 #endif
514
515         if (prefs_common.clean_on_exit)
516                 main_window_empty_trash(mainwin, prefs_common.ask_on_clean);
517
518         /* save prefs for opened folder */
519         if(mainwin->folderview->opened)
520         {
521                 FolderItem *item;
522
523                 item = gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->folderview->ctree), mainwin->folderview->opened);
524                 summary_save_prefs_to_folderitem(mainwin->folderview->summaryview, item);
525         }
526
527         /* save all state before exiting */
528         folder_write_list();
529         folder_func_to_all_folders(save_all_caches, NULL);
530
531         main_window_get_size(mainwin);
532         main_window_get_position(mainwin);
533         prefs_common_save_config();
534         prefs_filter_write_config();
535         account_save_config_all();
536         addressbook_export_to_file();
537
538         filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
539         gtk_item_factory_dump_rc(filename, NULL, TRUE);
540         g_free(filename);
541
542         /* delete temporary files */
543         remove_all_files(get_mime_tmp_dir());
544
545         close_log_file();
546
547         /* delete unix domain socket */
548         gdk_input_remove(lock_socket_tag);
549         fd_close(lock_socket);
550         filename = get_socket_name();
551         unlink(filename);
552         
553         /* delete crashfile */
554         if (!cmd.crash)
555                 unlink(get_crashfile_name());
556
557 #if USE_SSL
558         ssl_done();
559 #endif
560
561         gtk_main_quit();
562 }
563
564 #if USE_GPGME
565 static void idle_function_for_gpgme(void)
566 {
567         while (gtk_events_pending())
568                 gtk_main_iteration();
569 }
570 #endif /* USE_GPGME */
571
572 /*
573  * CLAWS: want this public so crash dialog can delete the
574  * lock file too
575  */
576 #ifndef CLAWS
577 static
578 #endif
579 gchar *get_socket_name(void)
580 {
581         static gchar *filename = NULL;
582
583         if (filename == NULL) {
584                 filename = g_strdup_printf("%s%csylpheed-%d",
585                                            g_get_tmp_dir(), G_DIR_SEPARATOR,
586                                            getuid());
587         }
588
589         return filename;
590 }
591
592 static gchar *get_crashfile_name(void)
593 {
594         static gchar *filename = NULL;
595
596         if (filename == NULL) {
597                 filename = g_strdup_printf("%s%csylpheed-crashed",
598                                            get_tmp_dir(), G_DIR_SEPARATOR);
599         }
600
601         return filename;
602 }
603
604 static gint prohibit_duplicate_launch(void)
605 {
606         gint uxsock;
607         gchar *path;
608
609         path = get_socket_name();
610         uxsock = fd_connect_unix(path);
611         if (uxsock < 0) {
612                 unlink(path);
613                 return fd_open_unix(path);
614         }
615
616         /* remote command mode */
617
618         debug_print("another Sylpheed is already running.\n");
619
620         if (cmd.receive_all)
621                 fd_write(uxsock, "receive_all\n", 12);
622         else if (cmd.receive)
623                 fd_write(uxsock, "receive\n", 8);
624         else if (cmd.compose && cmd.attach_files) {
625                 gchar *str, *compose_str;
626                 gint i;
627
628                 if (cmd.compose_mailto)
629                         compose_str = g_strdup_printf("compose_attach %s\n",
630                                                       cmd.compose_mailto);
631                 else
632                         compose_str = g_strdup("compose_attach\n");
633
634                 fd_write(uxsock, compose_str, strlen(compose_str));
635                 g_free(compose_str);
636
637                 for (i = 0; i < cmd.attach_files->len; i++) {
638                         str = g_ptr_array_index(cmd.attach_files, i);
639                         fd_write(uxsock, str, strlen(str));
640                         fd_write(uxsock, "\n", 1);
641                 }
642
643                 fd_write(uxsock, ".\n", 2);
644         } else if (cmd.compose) {
645                 gchar *compose_str;
646
647                 if (cmd.compose_mailto)
648                         compose_str = g_strdup_printf("compose %s\n", cmd.compose_mailto);
649                 else
650                         compose_str = g_strdup("compose\n");
651
652                 fd_write(uxsock, compose_str, strlen(compose_str));
653                 g_free(compose_str);
654         } else if (cmd.send) {
655                 fd_write(uxsock, "send\n", 5);
656         } else if (cmd.status) {
657                 gchar buf[BUFFSIZE];
658
659                 fd_write(uxsock, "status\n", 7);
660                 fd_gets(uxsock, buf, sizeof(buf));
661                 fputs(buf, stdout);
662         } else
663                 fd_write(uxsock, "popup\n", 6);
664
665         fd_close(uxsock);
666         return -1;
667 }
668
669 static void lock_socket_input_cb(gpointer data,
670                                  gint source,
671                                  GdkInputCondition condition)
672 {
673         MainWindow *mainwin = (MainWindow *)data;
674         gint sock;
675         gchar buf[BUFFSIZE];
676
677         sock = fd_accept(source);
678         fd_gets(sock, buf, sizeof(buf));
679
680         if (!strncmp(buf, "popup", 5)) {
681                 main_window_popup(mainwin);
682         } else if (!strncmp(buf, "receive_all", 11)) {
683                 main_window_popup(mainwin);
684                 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
685         } else if (!strncmp(buf, "receive", 7)) {
686                 main_window_popup(mainwin);
687                 inc_mail(mainwin, prefs_common.newmail_notify_manu);
688         } else if (!strncmp(buf, "compose_attach", 14)) {
689                 GPtrArray *files;
690                 gchar *mailto;
691
692                 mailto = g_strdup(buf + strlen("compose_attach") + 1);
693                 files = g_ptr_array_new();
694                 while (fd_gets(sock, buf, sizeof(buf)) > 0) {
695                         if (buf[0] == '.' && buf[1] == '\n') break;
696                         strretchomp(buf);
697                         g_ptr_array_add(files, g_strdup(buf));
698                 }
699                 open_compose_new(mailto, files);
700                 ptr_array_free_strings(files);
701                 g_ptr_array_free(files, TRUE);
702                 g_free(mailto);
703         } else if (!strncmp(buf, "compose", 7)) {
704                 open_compose_new(buf + strlen("compose") + 1, NULL);
705         } else if (!strncmp(buf, "send", 4)) {
706                 send_queue();
707         } else if (!strncmp(buf, "status", 6)) {
708                 guint new, unread, total;
709
710                 folder_count_total_msgs(&new, &unread, &total);
711                 g_snprintf(buf, sizeof(buf), "%d %d %d\n", new, unread, total);
712                 fd_write(sock, buf, strlen(buf));
713         }
714
715         fd_close(sock);
716 }
717
718 static void open_compose_new(const gchar *address, GPtrArray *attach_files)
719 {
720         gchar *addr = NULL;
721
722         if (address) {
723                 Xstrdup_a(addr, address, return);
724                 g_strstrip(addr);
725         }
726
727         compose_new(NULL, addr, attach_files);
728 }
729
730 static void send_queue(void)
731 {
732         GList *list;
733         FolderItem *def_outbox;
734
735         def_outbox = folder_get_default_outbox();
736
737         for (list = folder_get_list(); list != NULL; list = list->next) {
738                 Folder *folder = list->data;
739
740                 if (folder->queue) {
741                         if (procmsg_send_queue
742                                 (folder->queue, prefs_common.savemsg) < 0)
743                                 alertpanel_error(_("Some errors occurred while sending queued messages."));
744                         statusbar_pop_all();
745                         folder_item_scan(folder->queue);
746                         folderview_update_item(folder->queue, TRUE);
747                         if (prefs_common.savemsg && folder->outbox) {
748                                 folderview_update_item(folder->outbox, TRUE);
749                                 if (folder->outbox == def_outbox)
750                                         def_outbox = NULL;
751                         }
752                 }
753         }
754
755         if (prefs_common.savemsg && def_outbox)
756                 folderview_update_item(def_outbox, TRUE);
757 }