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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 gboolean defer_check_all(void *data)
234 gboolean autochk = GPOINTER_TO_INT(data);
236 inc_all_account_mail(static_mainwindow, autochk,
237 prefs_common.newmail_notify_manu);
242 gboolean defer_check(void *data)
244 inc_mail(static_mainwindow, prefs_common.newmail_notify_manu);
249 int main(int argc, char *argv[])
253 FolderView *folderview;
255 gboolean crash_file_present = FALSE;
257 if (!sylpheed_init(&argc, &argv)) {
261 prog_version = PROG_VERSION;
263 argv0 = g_strdup(argv[0]);
266 parse_cmd_opt(argc, argv);
271 gtk_init(&argc, &argv);
272 crash_main(cmd.crash_params);
275 crash_install_handlers();
277 install_basic_sighandlers();
280 /* check and create unix domain socket for remote operation */
282 lock_socket = prohibit_duplicate_launch();
283 if (lock_socket < 0) {
284 #ifdef HAVE_STARTUP_NOTIFICATION
285 if(gtk_init_check(&argc, &argv))
286 startup_notification_complete(TRUE);
291 if (cmd.status || cmd.status_full) {
292 puts("0 Sylpheed not running.");
293 lock_socket_remove();
298 /* gdk_threads_init(); */
301 gtk_init(&argc, &argv);
304 gtk_widget_set_default_colormap(gdk_rgb_get_colormap());
305 gtk_widget_set_default_visual(gdk_rgb_get_visual());
307 if (!g_thread_supported())
308 g_error(_("g_thread is not supported by glib.\n"));
310 /* parse gtkrc files */
311 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtkrc-2.0",
313 gtk_rc_parse(userrc);
315 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtk",
316 G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
317 gtk_rc_parse(userrc);
319 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
320 gtk_rc_parse(userrc);
323 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
324 gtk_accel_map_load (userrc);
327 gtk_settings_set_long_property(gtk_settings_get_default(),
328 "gtk-can-change-accels",
329 (glong)TRUE, "XProperty");
331 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
333 MAKE_DIR_IF_NOT_EXIST(RC_DIR);
335 CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1);
337 MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
338 MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
339 MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
340 MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
341 MAKE_DIR_IF_NOT_EXIST(UIDL_DIR);
343 crash_file_present = is_file_exist(get_crashfile_name());
344 /* remove temporary files */
345 remove_all_files(get_tmp_dir());
346 remove_all_files(get_mime_tmp_dir());
348 if (is_file_exist("sylpheed.log")) {
349 if (rename_force("sylpheed.log", "sylpheed.log.bak") < 0)
350 FILE_OP_ERROR("sylpheed.log", "rename");
352 set_log_file("sylpheed.log");
354 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
356 folder_system_init();
357 prefs_common_read_config();
361 prefs_ext_prog_init();
362 prefs_wrapping_init();
363 prefs_compose_writing_init();
364 prefs_msg_colors_init();
366 prefs_image_viewer_init();
368 prefs_summaries_init();
369 prefs_message_init();
371 prefs_receive_init();
374 gtkaspell_checkers_init();
375 prefs_spelling_init();
378 sock_set_io_timeout(prefs_common.io_timeout_secs);
380 imap_main_set_timeout(prefs_common.io_timeout_secs);
382 prefs_actions_read_config();
383 prefs_display_header_read_config();
384 /* prefs_filtering_read_config(); */
385 addressbook_read_file();
386 renderer_read_config();
389 stock_pixbuf_gdk(NULL, STOCK_PIXMAP_SYLPHEED_ICON, &icon);
390 gtk_window_set_default_icon(icon);
392 folderview_initialize();
398 mainwin = main_window_create
399 (prefs_common.sep_folder | prefs_common.sep_msg << 1);
400 folderview = mainwin->folderview;
402 gtk_clist_freeze(GTK_CLIST(mainwin->folderview->ctree));
403 folder_item_update_freeze();
405 /* register the callback of unix domain socket input */
407 lock_socket_tag = gdk_input_add(lock_socket,
408 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
409 lock_socket_input_cb,
413 prefs_account_init();
414 account_read_config_all();
416 if (folder_read_list() < 0) {
417 if (!run_wizard(mainwin, TRUE))
422 if (!account_get_list()) {
423 if (!run_wizard(mainwin, FALSE))
425 account_read_config_all();
426 if(!account_get_list())
427 exit_sylpheed(mainwin);
433 account_set_missing_folder();
434 folder_set_missing_folders();
435 folderview_set(folderview);
437 prefs_matcher_read_config();
439 /* make one all-folder processing before using sylpheed */
440 main_window_cursor_wait(mainwin);
441 folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
443 /* if Sylpheed crashed, rebuild caches */
444 if (!cmd.crash && crash_file_present) {
445 debug_print("Sylpheed crashed, checking for new messages in local folders\n");
446 folder_item_update_thaw();
447 folderview_check_new(NULL);
448 folder_clean_cache_memory_force();
449 folder_item_update_freeze();
451 /* make the crash-indicator file */
452 str_write_to_file("foo", get_crashfile_name());
454 addressbook_read_file();
456 inc_autocheck_timer_init(mainwin);
458 /* ignore SIGPIPE signal for preventing sudden death of program */
460 signal(SIGPIPE, SIG_IGN);
462 if (cmd.online_mode == ONLINE_MODE_OFFLINE)
463 main_window_toggle_work_offline(mainwin, TRUE, FALSE);
464 if (cmd.online_mode == ONLINE_MODE_ONLINE)
465 main_window_toggle_work_offline(mainwin, FALSE, FALSE);
467 if (cmd.status_folders) {
468 g_ptr_array_free(cmd.status_folders, TRUE);
469 cmd.status_folders = NULL;
471 if (cmd.status_full_folders) {
472 g_ptr_array_free(cmd.status_full_folders, TRUE);
473 cmd.status_full_folders = NULL;
476 sylpheed_register_idle_function(sylpheed_gtk_idle);
478 prefs_toolbar_init();
480 plugin_load_all("GTK2");
482 static_mainwindow = mainwin;
484 #ifdef HAVE_STARTUP_NOTIFICATION
485 startup_notification_complete(FALSE);
487 folder_item_update_thaw();
488 gtk_clist_thaw(GTK_CLIST(mainwin->folderview->ctree));
489 main_window_cursor_normal(mainwin);
492 g_timeout_add(1000, defer_check_all, GINT_TO_POINTER(FALSE));
493 else if (prefs_common.chk_on_startup)
494 g_timeout_add(1000, defer_check_all, GINT_TO_POINTER(TRUE));
495 else if (cmd.receive)
496 g_timeout_add(1000, defer_check, NULL);
498 gtk_widget_grab_focus(folderview->ctree);
501 open_compose_new(cmd.compose_mailto, cmd.attach_files);
502 if (cmd.attach_files) {
503 ptr_array_free_strings(cmd.attach_files);
504 g_ptr_array_free(cmd.attach_files, TRUE);
505 cmd.attach_files = NULL;
512 exit_sylpheed(mainwin);
517 static void save_all_caches(FolderItem *item, gpointer data)
521 folder_item_write_cache(item);
524 static void exit_sylpheed(MainWindow *mainwin)
528 debug_print("shutting down\n");
529 inc_autocheck_timer_remove();
531 if (prefs_common.clean_on_exit)
532 main_window_empty_trash(mainwin, prefs_common.ask_on_clean);
534 /* save prefs for opened folder */
535 if(mainwin->folderview->opened)
539 item = gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->folderview->ctree), mainwin->folderview->opened);
540 summary_save_prefs_to_folderitem(mainwin->folderview->summaryview, item);
543 /* save all state before exiting */
545 folder_func_to_all_folders(save_all_caches, NULL);
547 main_window_get_size(mainwin);
548 main_window_get_position(mainwin);
549 prefs_common_write_config();
550 account_write_config_all();
551 addressbook_export_to_file();
553 filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
554 gtk_accel_map_save(filename);
557 /* delete temporary files */
558 remove_all_files(get_tmp_dir());
559 remove_all_files(get_mime_tmp_dir());
566 /* delete crashfile */
568 g_unlink(get_crashfile_name());
570 lock_socket_remove();
572 main_window_destroy(mainwin);
574 plugin_unload_all("GTK2");
576 prefs_toolbar_done();
578 addressbook_destroy();
582 prefs_ext_prog_done();
583 prefs_wrapping_done();
584 prefs_compose_writing_done();
585 prefs_msg_colors_done();
586 prefs_image_viewer_done();
589 prefs_summaries_done();
590 prefs_message_done();
592 prefs_receive_done();
595 prefs_spelling_done();
596 gtkaspell_checkers_quit();
602 static void parse_cmd_opt(int argc, char *argv[])
606 for (i = 1; i < argc; i++) {
607 if (!strncmp(argv[i], "--receive-all", 13))
608 cmd.receive_all = TRUE;
609 else if (!strncmp(argv[i], "--receive", 9))
611 else if (!strncmp(argv[i], "--compose", 9)) {
612 const gchar *p = argv[i + 1];
615 cmd.compose_mailto = NULL;
616 if (p && *p != '\0' && *p != '-') {
617 if (!strncmp(p, "mailto:", 7))
618 cmd.compose_mailto = p + 7;
620 cmd.compose_mailto = p;
623 } else if (!strncmp(argv[i], "--attach", 8)) {
624 const gchar *p = argv[i + 1];
627 while (p && *p != '\0' && *p != '-') {
628 if (!cmd.attach_files)
629 cmd.attach_files = g_ptr_array_new();
630 if (*p != G_DIR_SEPARATOR)
631 file = g_strconcat(sylpheed_get_startup_dir(),
636 g_ptr_array_add(cmd.attach_files, file);
640 } else if (!strncmp(argv[i], "--send", 6)) {
642 } else if (!strncmp(argv[i], "--version", 9)) {
643 puts("Sylpheed version " VERSION);
645 } else if (!strncmp(argv[i], "--status-full", 13)) {
646 const gchar *p = argv[i + 1];
648 cmd.status_full = TRUE;
649 while (p && *p != '\0' && *p != '-') {
650 if (!cmd.status_full_folders)
651 cmd.status_full_folders =
653 g_ptr_array_add(cmd.status_full_folders,
658 } else if (!strncmp(argv[i], "--status", 8)) {
659 const gchar *p = argv[i + 1];
662 while (p && *p != '\0' && *p != '-') {
663 if (!cmd.status_folders)
664 cmd.status_folders = g_ptr_array_new();
665 g_ptr_array_add(cmd.status_folders,
670 } else if (!strncmp(argv[i], "--online", 8)) {
671 cmd.online_mode = ONLINE_MODE_ONLINE;
672 } else if (!strncmp(argv[i], "--offline", 9)) {
673 cmd.online_mode = ONLINE_MODE_OFFLINE;
674 } else if (!strncmp(argv[i], "--help", 6)) {
675 gchar *base = g_path_get_basename(argv[0]);
676 g_print(_("Usage: %s [OPTION]...\n"), base);
678 g_print("%s\n", _(" --compose [address] open composition window"));
679 g_print("%s\n", _(" --attach file1 [file2]...\n"
680 " open composition window with specified files\n"
682 g_print("%s\n", _(" --receive receive new messages"));
683 g_print("%s\n", _(" --receive-all receive new messages of all accounts"));
684 g_print("%s\n", _(" --send send all queued messages"));
685 g_print("%s\n", _(" --status [folder]... show the total number of messages"));
686 g_print("%s\n", _(" --status-full [folder]...\n"
687 " show the status of each folder"));
688 g_print("%s\n", _(" --online switch to online mode"));
689 g_print("%s\n", _(" --offline switch to offline mode"));
690 g_print("%s\n", _(" --debug debug mode"));
691 g_print("%s\n", _(" --help display this help and exit"));
692 g_print("%s\n", _(" --version output version information and exit"));
693 g_print("%s\n", _(" --config-dir output configuration directory"));
697 } else if (!strncmp(argv[i], "--crash", 7)) {
699 cmd.crash_params = g_strdup(argv[i + 1]);
701 } else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
708 if (cmd.attach_files && cmd.compose == FALSE) {
710 cmd.compose_mailto = NULL;
714 static gint get_queued_message_num(void)
718 queue = folder_get_default_queue();
719 if (!queue) return -1;
721 folder_item_scan(queue);
722 return queue->total_msgs;
725 static void initial_processing(FolderItem *item, gpointer data)
727 MainWindow *mainwin = (MainWindow *)data;
730 g_return_if_fail(item);
731 buf = g_strdup_printf(_("Processing (%s)..."),
734 : _("top level folder"));
735 debug_print("%s\n", buf);
739 if (item->prefs->enable_processing)
740 folder_item_apply_processing(item);
742 debug_print("done.\n");
743 STATUSBAR_POP(mainwin);
746 static void draft_all_messages(void)
748 GList *compose_list = NULL;
750 while ((compose_list = compose_get_compose_list()) != NULL) {
751 Compose *c = (Compose*)compose_list->data;
756 gboolean clean_quit(gpointer data)
758 static gboolean firstrun = TRUE;
764 /*!< Good idea to have the main window stored in a
765 * static variable so we can check that variable
766 * to see if we're really allowed to do things
767 * that actually the spawner is supposed to
768 * do (like: sending mail, composing messages).
769 * Because, really, if we're the spawnee, and
770 * we touch GTK stuff, we're hosed. See the
773 /* FIXME: Use something else to signal that we're
774 * in the original spawner, and not in a spawned
776 if (!static_mainwindow)
779 draft_all_messages();
781 exit_sylpheed(static_mainwindow);
787 void app_will_exit(GtkWidget *widget, gpointer data)
789 MainWindow *mainwin = data;
791 if (compose_get_compose_list()) {
792 gint val = alertpanel(_("Really quit?"),
793 _("Composing message exists."),
794 _("_Save to Draft"), _("_Discard them"), _("Do_n't quit"));
798 case G_ALERTALTERNATE:
801 draft_all_messages();
804 manage_window_focus_in(mainwin->window, NULL, NULL);
807 if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
808 if (alertpanel(_("Queued messages"),
809 _("Some unsent messages are queued. Exit now?"),
810 GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL)
813 manage_window_focus_in(mainwin->window, NULL, NULL);
822 * CLAWS: want this public so crash dialog can delete the
828 gchar *get_socket_name(void)
830 static gchar *filename = NULL;
832 if (filename == NULL) {
833 filename = g_strdup_printf("%s%csylpheed-claws-%d",
834 g_get_tmp_dir(), G_DIR_SEPARATOR,
845 static gchar *get_crashfile_name(void)
847 static gchar *filename = NULL;
849 if (filename == NULL) {
850 filename = g_strdup_printf("%s%csylpheed-crashed",
851 get_tmp_dir(), G_DIR_SEPARATOR);
857 static gint prohibit_duplicate_launch(void)
862 path = get_socket_name();
863 uxsock = fd_connect_unix(path);
866 return fd_open_unix(path);
869 /* remote command mode */
871 debug_print("another Sylpheed is already running.\n");
874 fd_write_all(uxsock, "receive_all\n", 12);
875 else if (cmd.receive)
876 fd_write_all(uxsock, "receive\n", 8);
877 else if (cmd.compose && cmd.attach_files) {
878 gchar *str, *compose_str;
881 if (cmd.compose_mailto)
882 compose_str = g_strdup_printf("compose_attach %s\n",
885 compose_str = g_strdup("compose_attach\n");
887 fd_write_all(uxsock, compose_str, strlen(compose_str));
890 for (i = 0; i < cmd.attach_files->len; i++) {
891 str = g_ptr_array_index(cmd.attach_files, i);
892 fd_write_all(uxsock, str, strlen(str));
893 fd_write_all(uxsock, "\n", 1);
896 fd_write_all(uxsock, ".\n", 2);
897 } else if (cmd.compose) {
900 if (cmd.compose_mailto)
901 compose_str = g_strdup_printf
902 ("compose %s\n", cmd.compose_mailto);
904 compose_str = g_strdup("compose\n");
906 fd_write_all(uxsock, compose_str, strlen(compose_str));
908 } else if (cmd.send) {
909 fd_write_all(uxsock, "send\n", 5);
910 } else if (cmd.online_mode == ONLINE_MODE_ONLINE) {
911 fd_write(uxsock, "online\n", 6);
912 } else if (cmd.online_mode == ONLINE_MODE_OFFLINE) {
913 fd_write(uxsock, "offline\n", 7);
914 } else if (cmd.status || cmd.status_full) {
917 const gchar *command;
921 command = cmd.status_full ? "status-full\n" : "status\n";
922 folders = cmd.status_full ? cmd.status_full_folders :
925 fd_write_all(uxsock, command, strlen(command));
926 for (i = 0; folders && i < folders->len; ++i) {
927 folder = g_ptr_array_index(folders, i);
928 fd_write_all(uxsock, folder, strlen(folder));
929 fd_write_all(uxsock, "\n", 1);
931 fd_write_all(uxsock, ".\n", 2);
933 fd_gets(uxsock, buf, sizeof(buf));
934 if (!strncmp(buf, ".\n", 2)) break;
938 fd_write_all(uxsock, "popup\n", 6);
944 static gint lock_socket_remove(void)
949 if (lock_socket < 0) return -1;
951 if (lock_socket_tag > 0)
952 gdk_input_remove(lock_socket_tag);
953 fd_close(lock_socket);
954 filename = get_socket_name();
961 static GPtrArray *get_folder_item_list(gint sock)
965 GPtrArray *folders = NULL;
968 fd_gets(sock, buf, sizeof(buf));
969 if (!strncmp(buf, ".\n", 2)) break;
971 if (!folders) folders = g_ptr_array_new();
972 item = folder_find_item_from_identifier(buf);
974 g_ptr_array_add(folders, item);
976 g_warning("no such folder: %s\n", buf);
982 static void lock_socket_input_cb(gpointer data,
984 GdkInputCondition condition)
986 MainWindow *mainwin = (MainWindow *)data;
990 sock = fd_accept(source);
991 fd_gets(sock, buf, sizeof(buf));
993 if (!strncmp(buf, "popup", 5)) {
994 main_window_popup(mainwin);
995 } else if (!strncmp(buf, "receive_all", 11)) {
996 inc_all_account_mail(mainwin, FALSE,
997 prefs_common.newmail_notify_manu);
998 } else if (!strncmp(buf, "receive", 7)) {
999 inc_mail(mainwin, prefs_common.newmail_notify_manu);
1000 } else if (!strncmp(buf, "compose_attach", 14)) {
1004 mailto = g_strdup(buf + strlen("compose_attach") + 1);
1005 files = g_ptr_array_new();
1006 while (fd_gets(sock, buf, sizeof(buf)) > 0) {
1007 if (buf[0] == '.' && buf[1] == '\n') break;
1009 g_ptr_array_add(files, g_strdup(buf));
1011 open_compose_new(mailto, files);
1012 ptr_array_free_strings(files);
1013 g_ptr_array_free(files, TRUE);
1015 } else if (!strncmp(buf, "compose", 7)) {
1016 open_compose_new(buf + strlen("compose") + 1, NULL);
1017 } else if (!strncmp(buf, "send", 4)) {
1019 } else if (!strncmp(buf, "online", 6)) {
1020 main_window_toggle_work_offline(mainwin, FALSE, FALSE);
1021 } else if (!strncmp(buf, "offline", 7)) {
1022 main_window_toggle_work_offline(mainwin, TRUE, FALSE);
1023 } else if (!strncmp(buf, "status-full", 11) ||
1024 !strncmp(buf, "status", 6)) {
1028 folders = get_folder_item_list(sock);
1029 status = folder_get_status
1030 (folders, !strncmp(buf, "status-full", 11));
1031 fd_write_all(sock, status, strlen(status));
1032 fd_write_all(sock, ".\n", 2);
1034 if (folders) g_ptr_array_free(folders, TRUE);
1040 static void open_compose_new(const gchar *address, GPtrArray *attach_files)
1045 Xstrdup_a(addr, address, return);
1049 compose_new(NULL, addr, attach_files);
1052 static void send_queue(void)
1056 for (list = folder_get_list(); list != NULL; list = list->next) {
1057 Folder *folder = list->data;
1059 if (folder->queue) {
1060 gint res = procmsg_send_queue
1061 (folder->queue, prefs_common.savemsg);
1064 alertpanel_error(_("Some errors occurred while sending queued messages."));
1066 folder_item_scan(folder->queue);
1071 static void quit_signal_handler(int sig)
1073 debug_print("Quitting on signal %d\n", sig);
1075 g_timeout_add(0, clean_quit, NULL);
1078 static void install_basic_sighandlers()
1081 struct sigaction act;
1086 sigaddset(&mask, SIGTERM);
1089 sigaddset(&mask, SIGINT);
1092 sigaddset(&mask, SIGHUP);
1095 act.sa_handler = quit_signal_handler;
1100 sigaction(SIGTERM, &act, 0);
1103 sigaction(SIGINT, &act, 0);
1106 sigaction(SIGHUP, &act, 0);
1109 sigprocmask(SIG_UNBLOCK, &mask, 0);