2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
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.
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.
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.
27 #include <glib/gi18n.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkrc.h>
38 #include <sys/types.h>
41 #ifdef HAVE_STARTUP_NOTIFICATION
42 # define SN_API_NOT_YET_FROZEN
43 # include <libsn/sn-launchee.h>
44 # include <gdk/gdkx.h>
49 #include "mainwindow.h"
50 #include "folderview.h"
51 #include "image_viewer.h"
52 #include "summaryview.h"
53 #include "prefs_common.h"
54 #include "prefs_account.h"
55 #include "prefs_actions.h"
56 #include "prefs_ext_prog.h"
57 #include "prefs_fonts.h"
58 #include "prefs_image_viewer.h"
59 #include "prefs_message.h"
60 #include "prefs_receive.h"
61 #include "prefs_msg_colors.h"
62 #include "prefs_quote.h"
63 #include "prefs_spelling.h"
64 #include "prefs_summaries.h"
65 #include "prefs_themes.h"
66 #include "prefs_other.h"
67 #include "prefs_send.h"
68 #include "prefs_wrapping.h"
69 #include "prefs_compose_writing.h"
70 #include "prefs_display_header.h"
75 #include "manage_window.h"
76 #include "alertpanel.h"
77 #include "statusbar.h"
78 #include "addressbook.h"
86 #include "prefs_toolbar.h"
93 #include "imap-thread.h"
95 #include "stock_pixmap.h"
110 #ifdef HAVE_STARTUP_NOTIFICATION
111 static SnLauncheeContext *sn_context = NULL;
112 static SnDisplay *sn_display = NULL;
115 static gint lock_socket = -1;
116 static gint lock_socket_tag = 0;
120 ONLINE_MODE_DONT_CHANGE,
125 static struct RemoteCmd {
127 gboolean receive_all;
129 const gchar *compose_mailto;
130 GPtrArray *attach_files;
132 gboolean status_full;
133 GPtrArray *status_folders;
134 GPtrArray *status_full_folders;
141 static void parse_cmd_opt(int argc, char *argv[]);
143 static gint prohibit_duplicate_launch (void);
144 static gchar * get_crashfile_name (void);
145 static gint lock_socket_remove (void);
146 static void lock_socket_input_cb (gpointer data,
148 GdkInputCondition condition);
152 gchar *get_socket_name (void);
155 static void open_compose_new (const gchar *address,
156 GPtrArray *attach_files);
158 static void send_queue (void);
159 static void initial_processing (FolderItem *item, gpointer data);
160 static void quit_signal_handler (int sig);
161 static void install_basic_sighandlers (void);
162 static void exit_sylpheed (MainWindow *mainwin);
164 #define MAKE_DIR_IF_NOT_EXIST(dir) \
166 if (!is_dir_exist(dir)) { \
167 if (is_file_exist(dir)) { \
169 (_("File `%s' already exists.\n" \
170 "Can't create folder."), \
174 if (make_dir(dir) < 0) \
179 static MainWindow *static_mainwindow;
181 #ifdef HAVE_STARTUP_NOTIFICATION
182 static void sn_error_trap_push(SnDisplay *display, Display *xdisplay)
184 gdk_error_trap_push();
187 static void sn_error_trap_pop(SnDisplay *display, Display *xdisplay)
189 gdk_error_trap_pop();
192 static void startup_notification_complete(gboolean with_window)
195 GtkWidget *hack = NULL;
198 /* this is needed to make the startup notification leave,
199 * if we have been launched from a menu.
200 * We have to display a window, so let it be very little */
201 hack = gtk_window_new(GTK_WINDOW_POPUP);
202 gtk_widget_set_uposition(hack, 0, 0);
203 gtk_widget_set_size_request(hack, 1, 1);
204 gtk_widget_show(hack);
207 xdisplay = GDK_DISPLAY();
208 sn_display = sn_display_new(xdisplay,
211 sn_context = sn_launchee_context_new_from_environment(sn_display,
212 DefaultScreen(xdisplay));
214 if (sn_context != NULL)
216 sn_launchee_context_complete(sn_context);
217 sn_launchee_context_unref(sn_context);
218 sn_display_unref(sn_display);
221 #endif /* HAVE_STARTUP_NOTIFICATION */
223 void sylpheed_gtk_idle(void)
225 while(gtk_events_pending())
226 gtk_main_iteration();
229 int main(int argc, char *argv[])
233 FolderView *folderview;
236 if (!sylpheed_init(&argc, &argv)) {
240 prog_version = PROG_VERSION;
242 argv0 = g_strdup(argv[0]);
245 parse_cmd_opt(argc, argv);
250 gtk_init(&argc, &argv);
251 crash_main(cmd.crash_params);
254 crash_install_handlers();
256 install_basic_sighandlers();
258 /* check and create unix domain socket */
259 lock_socket = prohibit_duplicate_launch();
260 if (lock_socket < 0) {
261 #ifdef HAVE_STARTUP_NOTIFICATION
262 if(gtk_init_check(&argc, &argv))
263 startup_notification_complete(TRUE);
268 if (cmd.status || cmd.status_full) {
269 puts("0 Sylpheed not running.");
270 lock_socket_remove();
275 /* gdk_threads_init(); */
278 gtk_init(&argc, &argv);
281 gtk_widget_set_default_colormap(gdk_rgb_get_cmap());
282 gtk_widget_set_default_visual(gdk_rgb_get_visual());
284 if (!g_thread_supported())
285 g_error(_("g_thread is not supported by glib.\n"));
287 /* parse gtkrc files */
288 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtkrc-2.0",
290 gtk_rc_parse(userrc);
292 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtk",
293 G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
294 gtk_rc_parse(userrc);
296 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
297 gtk_rc_parse(userrc);
300 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
301 gtk_accel_map_load (userrc);
304 gtk_settings_set_long_property(gtk_settings_get_default(),
305 "gtk-can-change-accels",
306 (glong)TRUE, "XProperty");
308 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
310 MAKE_DIR_IF_NOT_EXIST(RC_DIR);
311 MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
312 MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
313 MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
314 MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
315 MAKE_DIR_IF_NOT_EXIST(RC_DIR G_DIR_SEPARATOR_S "uidl");
317 set_log_file(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log");
319 folder_system_init();
320 prefs_common_read_config();
324 prefs_ext_prog_init();
325 prefs_wrapping_init();
326 prefs_compose_writing_init();
327 prefs_msg_colors_init();
329 prefs_image_viewer_init();
331 prefs_summaries_init();
332 prefs_message_init();
334 prefs_receive_init();
337 gtkaspell_checkers_init();
338 prefs_spelling_init();
341 sock_set_io_timeout(prefs_common.io_timeout_secs);
343 imap_main_set_timeout(prefs_common.io_timeout_secs);
345 prefs_actions_read_config();
346 prefs_display_header_read_config();
347 /* prefs_filtering_read_config(); */
348 addressbook_read_file();
349 renderer_read_config();
352 stock_pixbuf_gdk(NULL, STOCK_PIXMAP_SYLPHEED_ICON, &icon);
353 gtk_window_set_default_icon(icon);
355 folderview_initialize();
360 mainwin = main_window_create
361 (prefs_common.sep_folder | prefs_common.sep_msg << 1);
362 folderview = mainwin->folderview;
364 /* register the callback of unix domain socket input */
365 lock_socket_tag = gdk_input_add(lock_socket,
366 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
367 lock_socket_input_cb,
370 prefs_account_init();
371 account_read_config_all();
373 if (folder_read_list() < 0) {
374 if (!run_wizard(mainwin, TRUE))
379 if (!account_get_list()) {
380 if (!run_wizard(mainwin, FALSE))
382 account_read_config_all();
383 if(!account_get_list())
384 exit_sylpheed(mainwin);
390 account_set_missing_folder();
391 folder_set_missing_folders();
392 folderview_set(folderview);
394 prefs_matcher_read_config();
396 /* make one all-folder processing before using sylpheed */
397 main_window_cursor_wait(mainwin);
398 folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
399 main_window_cursor_normal(mainwin);
401 /* if Sylpheed crashed, rebuild caches */
402 if (!cmd.crash && is_file_exist(get_crashfile_name())) {
403 debug_print("Sylpheed crashed, checking for new messages in local folders\n");
404 folderview_check_new(NULL);
406 /* make the crash-indicator file */
407 str_write_to_file("foo", get_crashfile_name());
409 addressbook_read_file();
411 inc_autocheck_timer_init(mainwin);
413 /* ignore SIGPIPE signal for preventing sudden death of program */
414 signal(SIGPIPE, SIG_IGN);
416 if (cmd.online_mode == ONLINE_MODE_OFFLINE)
417 main_window_toggle_work_offline(mainwin, TRUE);
418 if (cmd.online_mode == ONLINE_MODE_ONLINE)
419 main_window_toggle_work_offline(mainwin, FALSE);
421 if (cmd.status_folders) {
422 g_ptr_array_free(cmd.status_folders, TRUE);
423 cmd.status_folders = NULL;
425 if (cmd.status_full_folders) {
426 g_ptr_array_free(cmd.status_full_folders, TRUE);
427 cmd.status_full_folders = NULL;
430 sylpheed_register_idle_function(sylpheed_gtk_idle);
432 prefs_toolbar_init();
434 plugin_load_all("GTK2");
436 static_mainwindow = mainwin;
438 #ifdef HAVE_STARTUP_NOTIFICATION
439 startup_notification_complete(FALSE);
443 inc_all_account_mail(mainwin, FALSE,
444 prefs_common.newmail_notify_manu);
445 else if (prefs_common.chk_on_startup)
446 inc_all_account_mail(mainwin, TRUE,
447 prefs_common.newmail_notify_manu);
448 else if (cmd.receive)
449 inc_mail(mainwin, prefs_common.newmail_notify_manu);
451 gtk_widget_grab_focus(folderview->ctree);
454 open_compose_new(cmd.compose_mailto, cmd.attach_files);
455 if (cmd.attach_files) {
456 ptr_array_free_strings(cmd.attach_files);
457 g_ptr_array_free(cmd.attach_files, TRUE);
458 cmd.attach_files = NULL;
465 exit_sylpheed(mainwin);
470 static void save_all_caches(FolderItem *item, gpointer data)
474 folder_item_write_cache(item);
477 static void exit_sylpheed(MainWindow *mainwin)
481 debug_print("shutting down\n");
485 inc_autocheck_timer_remove();
487 if (prefs_common.clean_on_exit)
488 main_window_empty_trash(mainwin, prefs_common.ask_on_clean);
490 /* save prefs for opened folder */
491 if(mainwin->folderview->opened)
495 item = gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->folderview->ctree), mainwin->folderview->opened);
496 summary_save_prefs_to_folderitem(mainwin->folderview->summaryview, item);
499 /* save all state before exiting */
501 folder_func_to_all_folders(save_all_caches, NULL);
503 main_window_get_size(mainwin);
504 main_window_get_position(mainwin);
505 prefs_common_write_config();
506 account_write_config_all();
507 addressbook_export_to_file();
509 filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
510 gtk_accel_map_save(filename);
513 /* delete temporary files */
514 remove_all_files(get_tmp_dir());
515 remove_all_files(get_mime_tmp_dir());
519 /* delete crashfile */
521 unlink(get_crashfile_name());
523 lock_socket_remove();
525 main_window_destroy(mainwin);
527 plugin_unload_all("GTK2");
529 prefs_toolbar_done();
531 addressbook_destroy();
535 prefs_ext_prog_done();
536 prefs_wrapping_done();
537 prefs_compose_writing_done();
538 prefs_msg_colors_done();
539 prefs_image_viewer_done();
542 prefs_summaries_done();
543 prefs_message_done();
545 prefs_receive_done();
548 prefs_spelling_done();
549 gtkaspell_checkers_quit();
555 static void parse_cmd_opt(int argc, char *argv[])
559 for (i = 1; i < argc; i++) {
560 if (!strncmp(argv[i], "--receive-all", 13))
561 cmd.receive_all = TRUE;
562 else if (!strncmp(argv[i], "--receive", 9))
564 else if (!strncmp(argv[i], "--compose", 9)) {
565 const gchar *p = argv[i + 1];
568 cmd.compose_mailto = NULL;
569 if (p && *p != '\0' && *p != '-') {
570 if (!strncmp(p, "mailto:", 7))
571 cmd.compose_mailto = p + 7;
573 cmd.compose_mailto = p;
576 } else if (!strncmp(argv[i], "--attach", 8)) {
577 const gchar *p = argv[i + 1];
580 while (p && *p != '\0' && *p != '-') {
581 if (!cmd.attach_files)
582 cmd.attach_files = g_ptr_array_new();
583 if (*p != G_DIR_SEPARATOR)
584 file = g_strconcat(sylpheed_get_startup_dir(),
589 g_ptr_array_add(cmd.attach_files, file);
593 } else if (!strncmp(argv[i], "--send", 6)) {
595 } else if (!strncmp(argv[i], "--version", 9)) {
596 puts("Sylpheed version " VERSION);
598 } else if (!strncmp(argv[i], "--status-full", 13)) {
599 const gchar *p = argv[i + 1];
601 cmd.status_full = TRUE;
602 while (p && *p != '\0' && *p != '-') {
603 if (!cmd.status_full_folders)
604 cmd.status_full_folders =
606 g_ptr_array_add(cmd.status_full_folders,
611 } else if (!strncmp(argv[i], "--status", 8)) {
612 const gchar *p = argv[i + 1];
615 while (p && *p != '\0' && *p != '-') {
616 if (!cmd.status_folders)
617 cmd.status_folders = g_ptr_array_new();
618 g_ptr_array_add(cmd.status_folders,
623 } else if (!strncmp(argv[i], "--online", 8)) {
624 cmd.online_mode = ONLINE_MODE_ONLINE;
625 } else if (!strncmp(argv[i], "--offline", 9)) {
626 cmd.online_mode = ONLINE_MODE_OFFLINE;
627 } else if (!strncmp(argv[i], "--help", 6)) {
628 gchar *base = g_path_get_basename(argv[0]);
629 g_print(_("Usage: %s [OPTION]...\n"), base);
631 g_print("%s\n", _(" --compose [address] open composition window"));
632 g_print("%s\n", _(" --attach file1 [file2]...\n"
633 " open composition window with specified files\n"
635 g_print("%s\n", _(" --receive receive new messages"));
636 g_print("%s\n", _(" --receive-all receive new messages of all accounts"));
637 g_print("%s\n", _(" --send send all queued messages"));
638 g_print("%s\n", _(" --status [folder]... show the total number of messages"));
639 g_print("%s\n", _(" --status-full [folder]...\n"
640 " show the status of each folder"));
641 g_print("%s\n", _(" --online switch to online mode"));
642 g_print("%s\n", _(" --offline switch to offline mode"));
643 g_print("%s\n", _(" --debug debug mode"));
644 g_print("%s\n", _(" --help display this help and exit"));
645 g_print("%s\n", _(" --version output version information and exit"));
646 g_print("%s\n", _(" --config-dir output configuration directory"));
650 } else if (!strncmp(argv[i], "--crash", 7)) {
652 cmd.crash_params = g_strdup(argv[i + 1]);
654 } else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
661 if (cmd.attach_files && cmd.compose == FALSE) {
663 cmd.compose_mailto = NULL;
667 static gint get_queued_message_num(void)
671 queue = folder_get_default_queue();
672 if (!queue) return -1;
674 folder_item_scan(queue);
675 return queue->total_msgs;
678 static void initial_processing(FolderItem *item, gpointer data)
680 MainWindow *mainwin = (MainWindow *)data;
683 g_return_if_fail(item);
684 buf = g_strdup_printf(_("Processing (%s)..."),
687 : _("top level folder"));
688 debug_print("%s\n", buf);
692 if (item->prefs->enable_processing)
693 folder_item_apply_processing(item);
695 debug_print("done.\n");
696 STATUSBAR_POP(mainwin);
699 static void draft_all_messages(void)
701 GList *compose_list = NULL;
703 while ((compose_list = compose_get_compose_list()) != NULL) {
704 Compose *c = (Compose*)compose_list->data;
709 gboolean clean_quit(gpointer data)
711 static gboolean firstrun = TRUE;
717 /*!< Good idea to have the main window stored in a
718 * static variable so we can check that variable
719 * to see if we're really allowed to do things
720 * that actually the spawner is supposed to
721 * do (like: sending mail, composing messages).
722 * Because, really, if we're the spawnee, and
723 * we touch GTK stuff, we're hosed. See the
726 /* FIXME: Use something else to signal that we're
727 * in the original spawner, and not in a spawned
729 if (!static_mainwindow)
732 draft_all_messages();
734 exit_sylpheed(static_mainwindow);
740 void app_will_exit(GtkWidget *widget, gpointer data)
742 MainWindow *mainwin = data;
744 if (compose_get_compose_list()) {
745 gint val = alertpanel(_("Really quit?"),
746 _("Composing message exists."),
747 _("Draft them"), _("Discard them"), _("Don't quit"));
751 case G_ALERTALTERNATE:
754 draft_all_messages();
757 manage_window_focus_in(mainwin->window, NULL, NULL);
760 if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
761 if (alertpanel(_("Queued messages"),
762 _("Some unsent messages are queued. Exit now?"),
763 GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL)
766 manage_window_focus_in(mainwin->window, NULL, NULL);
772 * CLAWS: want this public so crash dialog can delete the
778 gchar *get_socket_name(void)
780 static gchar *filename = NULL;
782 if (filename == NULL) {
783 filename = g_strdup_printf("%s%csylpheed-%d",
784 g_get_tmp_dir(), G_DIR_SEPARATOR,
791 static gchar *get_crashfile_name(void)
793 static gchar *filename = NULL;
795 if (filename == NULL) {
796 filename = g_strdup_printf("%s%csylpheed-crashed",
797 get_tmp_dir(), G_DIR_SEPARATOR);
803 static gint prohibit_duplicate_launch(void)
808 path = get_socket_name();
809 uxsock = fd_connect_unix(path);
812 return fd_open_unix(path);
815 /* remote command mode */
817 debug_print("another Sylpheed is already running.\n");
820 fd_write_all(uxsock, "receive_all\n", 12);
821 else if (cmd.receive)
822 fd_write_all(uxsock, "receive\n", 8);
823 else if (cmd.compose && cmd.attach_files) {
824 gchar *str, *compose_str;
827 if (cmd.compose_mailto)
828 compose_str = g_strdup_printf("compose_attach %s\n",
831 compose_str = g_strdup("compose_attach\n");
833 fd_write_all(uxsock, compose_str, strlen(compose_str));
836 for (i = 0; i < cmd.attach_files->len; i++) {
837 str = g_ptr_array_index(cmd.attach_files, i);
838 fd_write_all(uxsock, str, strlen(str));
839 fd_write_all(uxsock, "\n", 1);
842 fd_write_all(uxsock, ".\n", 2);
843 } else if (cmd.compose) {
846 if (cmd.compose_mailto)
847 compose_str = g_strdup_printf
848 ("compose %s\n", cmd.compose_mailto);
850 compose_str = g_strdup("compose\n");
852 fd_write_all(uxsock, compose_str, strlen(compose_str));
854 } else if (cmd.send) {
855 fd_write_all(uxsock, "send\n", 5);
856 } else if (cmd.online_mode == ONLINE_MODE_ONLINE) {
857 fd_write(uxsock, "online\n", 6);
858 } else if (cmd.online_mode == ONLINE_MODE_OFFLINE) {
859 fd_write(uxsock, "offline\n", 7);
860 } else if (cmd.status || cmd.status_full) {
863 const gchar *command;
867 command = cmd.status_full ? "status-full\n" : "status\n";
868 folders = cmd.status_full ? cmd.status_full_folders :
871 fd_write_all(uxsock, command, strlen(command));
872 for (i = 0; folders && i < folders->len; ++i) {
873 folder = g_ptr_array_index(folders, i);
874 fd_write_all(uxsock, folder, strlen(folder));
875 fd_write_all(uxsock, "\n", 1);
877 fd_write_all(uxsock, ".\n", 2);
879 fd_gets(uxsock, buf, sizeof(buf));
880 if (!strncmp(buf, ".\n", 2)) break;
884 fd_write_all(uxsock, "popup\n", 6);
890 static gint lock_socket_remove(void)
894 if (lock_socket < 0) return -1;
896 if (lock_socket_tag > 0)
897 gdk_input_remove(lock_socket_tag);
898 fd_close(lock_socket);
899 filename = get_socket_name();
905 static GPtrArray *get_folder_item_list(gint sock)
909 GPtrArray *folders = NULL;
912 fd_gets(sock, buf, sizeof(buf));
913 if (!strncmp(buf, ".\n", 2)) break;
915 if (!folders) folders = g_ptr_array_new();
916 item = folder_find_item_from_identifier(buf);
918 g_ptr_array_add(folders, item);
920 g_warning("no such folder: %s\n", buf);
926 static void lock_socket_input_cb(gpointer data,
928 GdkInputCondition condition)
930 MainWindow *mainwin = (MainWindow *)data;
934 sock = fd_accept(source);
935 fd_gets(sock, buf, sizeof(buf));
937 if (!strncmp(buf, "popup", 5)) {
938 main_window_popup(mainwin);
939 } else if (!strncmp(buf, "receive_all", 11)) {
940 inc_all_account_mail(mainwin, FALSE,
941 prefs_common.newmail_notify_manu);
942 } else if (!strncmp(buf, "receive", 7)) {
943 inc_mail(mainwin, prefs_common.newmail_notify_manu);
944 } else if (!strncmp(buf, "compose_attach", 14)) {
948 mailto = g_strdup(buf + strlen("compose_attach") + 1);
949 files = g_ptr_array_new();
950 while (fd_gets(sock, buf, sizeof(buf)) > 0) {
951 if (buf[0] == '.' && buf[1] == '\n') break;
953 g_ptr_array_add(files, g_strdup(buf));
955 open_compose_new(mailto, files);
956 ptr_array_free_strings(files);
957 g_ptr_array_free(files, TRUE);
959 } else if (!strncmp(buf, "compose", 7)) {
960 open_compose_new(buf + strlen("compose") + 1, NULL);
961 } else if (!strncmp(buf, "send", 4)) {
963 } else if (!strncmp(buf, "online", 6)) {
964 main_window_toggle_work_offline(mainwin, FALSE);
965 } else if (!strncmp(buf, "offline", 7)) {
966 main_window_toggle_work_offline(mainwin, TRUE);
967 } else if (!strncmp(buf, "status-full", 11) ||
968 !strncmp(buf, "status", 6)) {
972 folders = get_folder_item_list(sock);
973 status = folder_get_status
974 (folders, !strncmp(buf, "status-full", 11));
975 fd_write_all(sock, status, strlen(status));
976 fd_write_all(sock, ".\n", 2);
978 if (folders) g_ptr_array_free(folders, TRUE);
984 static void open_compose_new(const gchar *address, GPtrArray *attach_files)
989 Xstrdup_a(addr, address, return);
993 compose_new(NULL, addr, attach_files);
996 static void send_queue(void)
1000 for (list = folder_get_list(); list != NULL; list = list->next) {
1001 Folder *folder = list->data;
1003 if (folder->queue) {
1004 gint res = procmsg_send_queue
1005 (folder->queue, prefs_common.savemsg);
1008 alertpanel_error(_("Some errors occurred while sending queued messages."));
1010 folder_item_scan(folder->queue);
1015 static void quit_signal_handler(int sig)
1017 debug_print("Quitting on signal %d\n", sig);
1019 g_timeout_add(0, clean_quit, NULL);
1022 static void install_basic_sighandlers()
1025 struct sigaction act;
1030 sigaddset(&mask, SIGTERM);
1033 sigaddset(&mask, SIGINT);
1036 sigaddset(&mask, SIGHUP);
1039 act.sa_handler = quit_signal_handler;
1044 sigaction(SIGTERM, &act, 0);
1047 sigaction(SIGINT, &act, 0);
1050 sigaction(SIGHUP, &act, 0);
1053 sigprocmask(SIG_UNBLOCK, &mask, 0);