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>
43 #ifdef HAVE_STARTUP_NOTIFICATION
44 # define SN_API_NOT_YET_FROZEN
45 # include <libsn/sn-launchee.h>
46 # include <gdk/gdkx.h>
51 #include "mainwindow.h"
52 #include "folderview.h"
53 #include "image_viewer.h"
54 #include "summaryview.h"
55 #include "prefs_common.h"
56 #include "prefs_account.h"
57 #include "prefs_actions.h"
58 #include "prefs_ext_prog.h"
59 #include "prefs_fonts.h"
60 #include "prefs_image_viewer.h"
61 #include "prefs_message.h"
62 #include "prefs_receive.h"
63 #include "prefs_msg_colors.h"
64 #include "prefs_quote.h"
65 #include "prefs_spelling.h"
66 #include "prefs_summaries.h"
67 #include "prefs_themes.h"
68 #include "prefs_other.h"
69 #include "prefs_send.h"
70 #include "prefs_wrapping.h"
71 #include "prefs_compose_writing.h"
72 #include "prefs_display_header.h"
77 #include "manage_window.h"
78 #include "alertpanel.h"
79 #include "statusbar.h"
80 #include "addressbook.h"
88 #include "prefs_toolbar.h"
95 #include "imap-thread.h"
97 #include "stock_pixmap.h"
112 #ifdef HAVE_STARTUP_NOTIFICATION
113 static SnLauncheeContext *sn_context = NULL;
114 static SnDisplay *sn_display = NULL;
117 static gint lock_socket = -1;
118 static gint lock_socket_tag = 0;
122 ONLINE_MODE_DONT_CHANGE,
127 static struct RemoteCmd {
129 gboolean receive_all;
131 const gchar *compose_mailto;
132 GPtrArray *attach_files;
134 gboolean status_full;
135 GPtrArray *status_folders;
136 GPtrArray *status_full_folders;
143 static void parse_cmd_opt(int argc, char *argv[]);
145 static gint prohibit_duplicate_launch (void);
146 static gchar * get_crashfile_name (void);
147 static gint lock_socket_remove (void);
148 static void lock_socket_input_cb (gpointer data,
150 GdkInputCondition condition);
154 gchar *get_socket_name (void);
157 static void open_compose_new (const gchar *address,
158 GPtrArray *attach_files);
160 static void send_queue (void);
161 static void initial_processing (FolderItem *item, gpointer data);
162 static void quit_signal_handler (int sig);
163 static void install_basic_sighandlers (void);
164 static void exit_sylpheed (MainWindow *mainwin);
166 #define MAKE_DIR_IF_NOT_EXIST(dir) \
168 if (!is_dir_exist(dir)) { \
169 if (is_file_exist(dir)) { \
171 (_("File '%s' already exists.\n" \
172 "Can't create folder."), \
176 if (make_dir(dir) < 0) \
181 static MainWindow *static_mainwindow;
183 #ifdef HAVE_STARTUP_NOTIFICATION
184 static void sn_error_trap_push(SnDisplay *display, Display *xdisplay)
186 gdk_error_trap_push();
189 static void sn_error_trap_pop(SnDisplay *display, Display *xdisplay)
191 gdk_error_trap_pop();
194 static void startup_notification_complete(gboolean with_window)
197 GtkWidget *hack = NULL;
200 /* this is needed to make the startup notification leave,
201 * if we have been launched from a menu.
202 * We have to display a window, so let it be very little */
203 hack = gtk_window_new(GTK_WINDOW_POPUP);
204 gtk_widget_set_uposition(hack, 0, 0);
205 gtk_widget_set_size_request(hack, 1, 1);
206 gtk_widget_show(hack);
209 xdisplay = GDK_DISPLAY();
210 sn_display = sn_display_new(xdisplay,
213 sn_context = sn_launchee_context_new_from_environment(sn_display,
214 DefaultScreen(xdisplay));
216 if (sn_context != NULL)
218 sn_launchee_context_complete(sn_context);
219 sn_launchee_context_unref(sn_context);
220 sn_display_unref(sn_display);
223 #endif /* HAVE_STARTUP_NOTIFICATION */
225 void sylpheed_gtk_idle(void)
227 while(gtk_events_pending())
228 gtk_main_iteration();
232 int main(int argc, char *argv[])
236 FolderView *folderview;
238 gboolean crash_file_present = FALSE;
240 if (!sylpheed_init(&argc, &argv)) {
244 prog_version = PROG_VERSION;
246 argv0 = g_strdup(argv[0]);
249 parse_cmd_opt(argc, argv);
254 gtk_init(&argc, &argv);
255 crash_main(cmd.crash_params);
258 crash_install_handlers();
260 install_basic_sighandlers();
263 /* check and create unix domain socket for remote operation */
265 lock_socket = prohibit_duplicate_launch();
266 if (lock_socket < 0) {
267 #ifdef HAVE_STARTUP_NOTIFICATION
268 if(gtk_init_check(&argc, &argv))
269 startup_notification_complete(TRUE);
274 if (cmd.status || cmd.status_full) {
275 puts("0 Sylpheed not running.");
276 lock_socket_remove();
281 /* gdk_threads_init(); */
284 gtk_init(&argc, &argv);
287 gtk_widget_set_default_colormap(gdk_rgb_get_colormap());
288 gtk_widget_set_default_visual(gdk_rgb_get_visual());
290 if (!g_thread_supported())
291 g_error(_("g_thread is not supported by glib.\n"));
293 /* parse gtkrc files */
294 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtkrc-2.0",
296 gtk_rc_parse(userrc);
298 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtk",
299 G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
300 gtk_rc_parse(userrc);
302 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
303 gtk_rc_parse(userrc);
306 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
307 gtk_accel_map_load (userrc);
310 gtk_settings_set_long_property(gtk_settings_get_default(),
311 "gtk-can-change-accels",
312 (glong)TRUE, "XProperty");
314 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
316 MAKE_DIR_IF_NOT_EXIST(RC_DIR);
318 CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1);
320 MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
321 MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
322 MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
323 MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
324 MAKE_DIR_IF_NOT_EXIST(UIDL_DIR);
326 crash_file_present = is_file_exist(get_crashfile_name());
327 /* remove temporary files */
328 remove_all_files(get_tmp_dir());
329 remove_all_files(get_mime_tmp_dir());
331 if (is_file_exist("sylpheed.log")) {
332 if (rename_force("sylpheed.log", "sylpheed.log.bak") < 0)
333 FILE_OP_ERROR("sylpheed.log", "rename");
335 set_log_file("sylpheed.log");
337 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
339 folder_system_init();
340 prefs_common_read_config();
344 prefs_ext_prog_init();
345 prefs_wrapping_init();
346 prefs_compose_writing_init();
347 prefs_msg_colors_init();
349 prefs_image_viewer_init();
351 prefs_summaries_init();
352 prefs_message_init();
354 prefs_receive_init();
357 gtkaspell_checkers_init();
358 prefs_spelling_init();
361 sock_set_io_timeout(prefs_common.io_timeout_secs);
363 imap_main_set_timeout(prefs_common.io_timeout_secs);
365 prefs_actions_read_config();
366 prefs_display_header_read_config();
367 /* prefs_filtering_read_config(); */
368 addressbook_read_file();
369 renderer_read_config();
372 stock_pixbuf_gdk(NULL, STOCK_PIXMAP_SYLPHEED_ICON, &icon);
373 gtk_window_set_default_icon(icon);
375 folderview_initialize();
380 mainwin = main_window_create
381 (prefs_common.sep_folder | prefs_common.sep_msg << 1);
382 folderview = mainwin->folderview;
384 /* register the callback of unix domain socket input */
386 lock_socket_tag = gdk_input_add(lock_socket,
387 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
388 lock_socket_input_cb,
392 prefs_account_init();
393 account_read_config_all();
395 if (folder_read_list() < 0) {
396 if (!run_wizard(mainwin, TRUE))
401 if (!account_get_list()) {
402 if (!run_wizard(mainwin, FALSE))
404 account_read_config_all();
405 if(!account_get_list())
406 exit_sylpheed(mainwin);
412 account_set_missing_folder();
413 folder_set_missing_folders();
414 folderview_set(folderview);
416 prefs_matcher_read_config();
418 /* make one all-folder processing before using sylpheed */
419 main_window_cursor_wait(mainwin);
420 folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
421 main_window_cursor_normal(mainwin);
423 /* if Sylpheed crashed, rebuild caches */
424 if (!cmd.crash && crash_file_present) {
425 debug_print("Sylpheed crashed, checking for new messages in local folders\n");
426 folderview_check_new(NULL);
427 folder_clean_cache_memory_force();
429 /* make the crash-indicator file */
430 str_write_to_file("foo", get_crashfile_name());
432 addressbook_read_file();
434 inc_autocheck_timer_init(mainwin);
436 /* ignore SIGPIPE signal for preventing sudden death of program */
438 signal(SIGPIPE, SIG_IGN);
440 if (cmd.online_mode == ONLINE_MODE_OFFLINE)
441 main_window_toggle_work_offline(mainwin, TRUE, FALSE);
442 if (cmd.online_mode == ONLINE_MODE_ONLINE)
443 main_window_toggle_work_offline(mainwin, FALSE, FALSE);
445 if (cmd.status_folders) {
446 g_ptr_array_free(cmd.status_folders, TRUE);
447 cmd.status_folders = NULL;
449 if (cmd.status_full_folders) {
450 g_ptr_array_free(cmd.status_full_folders, TRUE);
451 cmd.status_full_folders = NULL;
454 sylpheed_register_idle_function(sylpheed_gtk_idle);
456 prefs_toolbar_init();
458 plugin_load_all("GTK2");
460 static_mainwindow = mainwin;
462 #ifdef HAVE_STARTUP_NOTIFICATION
463 startup_notification_complete(FALSE);
467 inc_all_account_mail(mainwin, FALSE,
468 prefs_common.newmail_notify_manu);
469 else if (prefs_common.chk_on_startup)
470 inc_all_account_mail(mainwin, TRUE,
471 prefs_common.newmail_notify_manu);
472 else if (cmd.receive)
473 inc_mail(mainwin, prefs_common.newmail_notify_manu);
475 gtk_widget_grab_focus(folderview->ctree);
478 open_compose_new(cmd.compose_mailto, cmd.attach_files);
479 if (cmd.attach_files) {
480 ptr_array_free_strings(cmd.attach_files);
481 g_ptr_array_free(cmd.attach_files, TRUE);
482 cmd.attach_files = NULL;
489 exit_sylpheed(mainwin);
494 static void save_all_caches(FolderItem *item, gpointer data)
498 folder_item_write_cache(item);
501 static void exit_sylpheed(MainWindow *mainwin)
505 debug_print("shutting down\n");
506 inc_autocheck_timer_remove();
508 if (prefs_common.clean_on_exit)
509 main_window_empty_trash(mainwin, prefs_common.ask_on_clean);
511 /* save prefs for opened folder */
512 if(mainwin->folderview->opened)
516 item = gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->folderview->ctree), mainwin->folderview->opened);
517 summary_save_prefs_to_folderitem(mainwin->folderview->summaryview, item);
520 /* save all state before exiting */
522 folder_func_to_all_folders(save_all_caches, NULL);
524 main_window_get_size(mainwin);
525 main_window_get_position(mainwin);
526 prefs_common_write_config();
527 account_write_config_all();
528 addressbook_export_to_file();
530 filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
531 gtk_accel_map_save(filename);
534 /* delete temporary files */
535 remove_all_files(get_tmp_dir());
536 remove_all_files(get_mime_tmp_dir());
543 /* delete crashfile */
545 g_unlink(get_crashfile_name());
547 lock_socket_remove();
549 main_window_destroy(mainwin);
551 plugin_unload_all("GTK2");
553 prefs_toolbar_done();
555 addressbook_destroy();
559 prefs_ext_prog_done();
560 prefs_wrapping_done();
561 prefs_compose_writing_done();
562 prefs_msg_colors_done();
563 prefs_image_viewer_done();
566 prefs_summaries_done();
567 prefs_message_done();
569 prefs_receive_done();
572 prefs_spelling_done();
573 gtkaspell_checkers_quit();
579 static void parse_cmd_opt(int argc, char *argv[])
583 for (i = 1; i < argc; i++) {
584 if (!strncmp(argv[i], "--receive-all", 13))
585 cmd.receive_all = TRUE;
586 else if (!strncmp(argv[i], "--receive", 9))
588 else if (!strncmp(argv[i], "--compose", 9)) {
589 const gchar *p = argv[i + 1];
592 cmd.compose_mailto = NULL;
593 if (p && *p != '\0' && *p != '-') {
594 if (!strncmp(p, "mailto:", 7))
595 cmd.compose_mailto = p + 7;
597 cmd.compose_mailto = p;
600 } else if (!strncmp(argv[i], "--attach", 8)) {
601 const gchar *p = argv[i + 1];
604 while (p && *p != '\0' && *p != '-') {
605 if (!cmd.attach_files)
606 cmd.attach_files = g_ptr_array_new();
607 if (*p != G_DIR_SEPARATOR)
608 file = g_strconcat(sylpheed_get_startup_dir(),
613 g_ptr_array_add(cmd.attach_files, file);
617 } else if (!strncmp(argv[i], "--send", 6)) {
619 } else if (!strncmp(argv[i], "--version", 9)) {
620 puts("Sylpheed version " VERSION);
622 } else if (!strncmp(argv[i], "--status-full", 13)) {
623 const gchar *p = argv[i + 1];
625 cmd.status_full = TRUE;
626 while (p && *p != '\0' && *p != '-') {
627 if (!cmd.status_full_folders)
628 cmd.status_full_folders =
630 g_ptr_array_add(cmd.status_full_folders,
635 } else if (!strncmp(argv[i], "--status", 8)) {
636 const gchar *p = argv[i + 1];
639 while (p && *p != '\0' && *p != '-') {
640 if (!cmd.status_folders)
641 cmd.status_folders = g_ptr_array_new();
642 g_ptr_array_add(cmd.status_folders,
647 } else if (!strncmp(argv[i], "--online", 8)) {
648 cmd.online_mode = ONLINE_MODE_ONLINE;
649 } else if (!strncmp(argv[i], "--offline", 9)) {
650 cmd.online_mode = ONLINE_MODE_OFFLINE;
651 } else if (!strncmp(argv[i], "--help", 6)) {
652 gchar *base = g_path_get_basename(argv[0]);
653 g_print(_("Usage: %s [OPTION]...\n"), base);
655 g_print("%s\n", _(" --compose [address] open composition window"));
656 g_print("%s\n", _(" --attach file1 [file2]...\n"
657 " open composition window with specified files\n"
659 g_print("%s\n", _(" --receive receive new messages"));
660 g_print("%s\n", _(" --receive-all receive new messages of all accounts"));
661 g_print("%s\n", _(" --send send all queued messages"));
662 g_print("%s\n", _(" --status [folder]... show the total number of messages"));
663 g_print("%s\n", _(" --status-full [folder]...\n"
664 " show the status of each folder"));
665 g_print("%s\n", _(" --online switch to online mode"));
666 g_print("%s\n", _(" --offline switch to offline mode"));
667 g_print("%s\n", _(" --debug debug mode"));
668 g_print("%s\n", _(" --help display this help and exit"));
669 g_print("%s\n", _(" --version output version information and exit"));
670 g_print("%s\n", _(" --config-dir output configuration directory"));
674 } else if (!strncmp(argv[i], "--crash", 7)) {
676 cmd.crash_params = g_strdup(argv[i + 1]);
678 } else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
685 if (cmd.attach_files && cmd.compose == FALSE) {
687 cmd.compose_mailto = NULL;
691 static gint get_queued_message_num(void)
695 queue = folder_get_default_queue();
696 if (!queue) return -1;
698 folder_item_scan(queue);
699 return queue->total_msgs;
702 static void initial_processing(FolderItem *item, gpointer data)
704 MainWindow *mainwin = (MainWindow *)data;
707 g_return_if_fail(item);
708 buf = g_strdup_printf(_("Processing (%s)..."),
711 : _("top level folder"));
712 debug_print("%s\n", buf);
716 if (item->prefs->enable_processing)
717 folder_item_apply_processing(item);
719 debug_print("done.\n");
720 STATUSBAR_POP(mainwin);
723 static void draft_all_messages(void)
725 GList *compose_list = NULL;
727 while ((compose_list = compose_get_compose_list()) != NULL) {
728 Compose *c = (Compose*)compose_list->data;
733 gboolean clean_quit(gpointer data)
735 static gboolean firstrun = TRUE;
741 /*!< Good idea to have the main window stored in a
742 * static variable so we can check that variable
743 * to see if we're really allowed to do things
744 * that actually the spawner is supposed to
745 * do (like: sending mail, composing messages).
746 * Because, really, if we're the spawnee, and
747 * we touch GTK stuff, we're hosed. See the
750 /* FIXME: Use something else to signal that we're
751 * in the original spawner, and not in a spawned
753 if (!static_mainwindow)
756 draft_all_messages();
758 exit_sylpheed(static_mainwindow);
764 void app_will_exit(GtkWidget *widget, gpointer data)
766 MainWindow *mainwin = data;
768 if (compose_get_compose_list()) {
769 gint val = alertpanel(_("Really quit?"),
770 _("Composing message exists."),
771 _("Draft them"), _("Discard them"), _("Don't quit"));
775 case G_ALERTALTERNATE:
778 draft_all_messages();
781 manage_window_focus_in(mainwin->window, NULL, NULL);
784 if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
785 if (alertpanel(_("Queued messages"),
786 _("Some unsent messages are queued. Exit now?"),
787 GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL)
790 manage_window_focus_in(mainwin->window, NULL, NULL);
799 * CLAWS: want this public so crash dialog can delete the
805 gchar *get_socket_name(void)
807 static gchar *filename = NULL;
809 if (filename == NULL) {
810 filename = g_strdup_printf("%s%csylpheed-%d",
811 g_get_tmp_dir(), G_DIR_SEPARATOR,
822 static gchar *get_crashfile_name(void)
824 static gchar *filename = NULL;
826 if (filename == NULL) {
827 filename = g_strdup_printf("%s%csylpheed-crashed",
828 get_tmp_dir(), G_DIR_SEPARATOR);
834 static gint prohibit_duplicate_launch(void)
839 path = get_socket_name();
840 uxsock = fd_connect_unix(path);
843 return fd_open_unix(path);
846 /* remote command mode */
848 debug_print("another Sylpheed is already running.\n");
851 fd_write_all(uxsock, "receive_all\n", 12);
852 else if (cmd.receive)
853 fd_write_all(uxsock, "receive\n", 8);
854 else if (cmd.compose && cmd.attach_files) {
855 gchar *str, *compose_str;
858 if (cmd.compose_mailto)
859 compose_str = g_strdup_printf("compose_attach %s\n",
862 compose_str = g_strdup("compose_attach\n");
864 fd_write_all(uxsock, compose_str, strlen(compose_str));
867 for (i = 0; i < cmd.attach_files->len; i++) {
868 str = g_ptr_array_index(cmd.attach_files, i);
869 fd_write_all(uxsock, str, strlen(str));
870 fd_write_all(uxsock, "\n", 1);
873 fd_write_all(uxsock, ".\n", 2);
874 } else if (cmd.compose) {
877 if (cmd.compose_mailto)
878 compose_str = g_strdup_printf
879 ("compose %s\n", cmd.compose_mailto);
881 compose_str = g_strdup("compose\n");
883 fd_write_all(uxsock, compose_str, strlen(compose_str));
885 } else if (cmd.send) {
886 fd_write_all(uxsock, "send\n", 5);
887 } else if (cmd.online_mode == ONLINE_MODE_ONLINE) {
888 fd_write(uxsock, "online\n", 6);
889 } else if (cmd.online_mode == ONLINE_MODE_OFFLINE) {
890 fd_write(uxsock, "offline\n", 7);
891 } else if (cmd.status || cmd.status_full) {
894 const gchar *command;
898 command = cmd.status_full ? "status-full\n" : "status\n";
899 folders = cmd.status_full ? cmd.status_full_folders :
902 fd_write_all(uxsock, command, strlen(command));
903 for (i = 0; folders && i < folders->len; ++i) {
904 folder = g_ptr_array_index(folders, i);
905 fd_write_all(uxsock, folder, strlen(folder));
906 fd_write_all(uxsock, "\n", 1);
908 fd_write_all(uxsock, ".\n", 2);
910 fd_gets(uxsock, buf, sizeof(buf));
911 if (!strncmp(buf, ".\n", 2)) break;
915 fd_write_all(uxsock, "popup\n", 6);
921 static gint lock_socket_remove(void)
926 if (lock_socket < 0) return -1;
928 if (lock_socket_tag > 0)
929 gdk_input_remove(lock_socket_tag);
930 fd_close(lock_socket);
931 filename = get_socket_name();
938 static GPtrArray *get_folder_item_list(gint sock)
942 GPtrArray *folders = NULL;
945 fd_gets(sock, buf, sizeof(buf));
946 if (!strncmp(buf, ".\n", 2)) break;
948 if (!folders) folders = g_ptr_array_new();
949 item = folder_find_item_from_identifier(buf);
951 g_ptr_array_add(folders, item);
953 g_warning("no such folder: %s\n", buf);
959 static void lock_socket_input_cb(gpointer data,
961 GdkInputCondition condition)
963 MainWindow *mainwin = (MainWindow *)data;
967 sock = fd_accept(source);
968 fd_gets(sock, buf, sizeof(buf));
970 if (!strncmp(buf, "popup", 5)) {
971 main_window_popup(mainwin);
972 } else if (!strncmp(buf, "receive_all", 11)) {
973 inc_all_account_mail(mainwin, FALSE,
974 prefs_common.newmail_notify_manu);
975 } else if (!strncmp(buf, "receive", 7)) {
976 inc_mail(mainwin, prefs_common.newmail_notify_manu);
977 } else if (!strncmp(buf, "compose_attach", 14)) {
981 mailto = g_strdup(buf + strlen("compose_attach") + 1);
982 files = g_ptr_array_new();
983 while (fd_gets(sock, buf, sizeof(buf)) > 0) {
984 if (buf[0] == '.' && buf[1] == '\n') break;
986 g_ptr_array_add(files, g_strdup(buf));
988 open_compose_new(mailto, files);
989 ptr_array_free_strings(files);
990 g_ptr_array_free(files, TRUE);
992 } else if (!strncmp(buf, "compose", 7)) {
993 open_compose_new(buf + strlen("compose") + 1, NULL);
994 } else if (!strncmp(buf, "send", 4)) {
996 } else if (!strncmp(buf, "online", 6)) {
997 main_window_toggle_work_offline(mainwin, FALSE, FALSE);
998 } else if (!strncmp(buf, "offline", 7)) {
999 main_window_toggle_work_offline(mainwin, TRUE, FALSE);
1000 } else if (!strncmp(buf, "status-full", 11) ||
1001 !strncmp(buf, "status", 6)) {
1005 folders = get_folder_item_list(sock);
1006 status = folder_get_status
1007 (folders, !strncmp(buf, "status-full", 11));
1008 fd_write_all(sock, status, strlen(status));
1009 fd_write_all(sock, ".\n", 2);
1011 if (folders) g_ptr_array_free(folders, TRUE);
1017 static void open_compose_new(const gchar *address, GPtrArray *attach_files)
1022 Xstrdup_a(addr, address, return);
1026 compose_new(NULL, addr, attach_files);
1029 static void send_queue(void)
1033 for (list = folder_get_list(); list != NULL; list = list->next) {
1034 Folder *folder = list->data;
1036 if (folder->queue) {
1037 gint res = procmsg_send_queue
1038 (folder->queue, prefs_common.savemsg);
1041 alertpanel_error(_("Some errors occurred while sending queued messages."));
1043 folder_item_scan(folder->queue);
1048 static void quit_signal_handler(int sig)
1050 debug_print("Quitting on signal %d\n", sig);
1052 g_timeout_add(0, clean_quit, NULL);
1055 static void install_basic_sighandlers()
1058 struct sigaction act;
1063 sigaddset(&mask, SIGTERM);
1066 sigaddset(&mask, SIGINT);
1069 sigaddset(&mask, SIGHUP);
1072 act.sa_handler = quit_signal_handler;
1077 sigaction(SIGTERM, &act, 0);
1080 sigaction(SIGINT, &act, 0);
1083 sigaction(SIGHUP, &act, 0);
1086 sigprocmask(SIG_UNBLOCK, &mask, 0);