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 gtk_widget_destroy(hack);
225 #endif /* HAVE_STARTUP_NOTIFICATION */
227 void sylpheed_gtk_idle(void)
229 while(gtk_events_pending())
230 gtk_main_iteration();
234 gboolean defer_check_all(void *data)
236 gboolean autochk = GPOINTER_TO_INT(data);
238 inc_all_account_mail(static_mainwindow, autochk,
239 prefs_common.newmail_notify_manu);
244 gboolean defer_check(void *data)
246 inc_mail(static_mainwindow, prefs_common.newmail_notify_manu);
251 static gboolean migrate_old_config(const gchar *old_cfg_dir, const gchar *new_cfg_dir)
253 gchar *message = g_strdup_printf(_("Configuration for Sylpheed-Claws %s found.\n"
254 "Do you want to migrate this configuration?"),
255 !strcmp(old_cfg_dir, OLD_GTK1_RC_DIR)?
256 _("1.0.5 or previous"):_("1.9.15 or previous"));
258 GtkWidget *window = NULL;
259 if (alertpanel(_("Migration of configuration"),
261 GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
264 window = label_window_create(_("Copying configuration..."));
266 r = copy_dir(old_cfg_dir, new_cfg_dir);
267 gtk_widget_destroy(window);
269 alertpanel_error(_("Migration failed!"));
274 int main(int argc, char *argv[])
278 FolderView *folderview;
280 gboolean crash_file_present = FALSE;
282 if (!sylpheed_init(&argc, &argv)) {
286 prog_version = PROG_VERSION;
288 argv0 = g_strdup(argv[0]);
291 parse_cmd_opt(argc, argv);
296 gtk_init(&argc, &argv);
297 crash_main(cmd.crash_params);
300 crash_install_handlers();
302 install_basic_sighandlers();
305 /* check and create unix domain socket for remote operation */
307 lock_socket = prohibit_duplicate_launch();
308 if (lock_socket < 0) {
309 #ifdef HAVE_STARTUP_NOTIFICATION
310 if(gtk_init_check(&argc, &argv))
311 startup_notification_complete(TRUE);
316 if (cmd.status || cmd.status_full) {
317 puts("0 Sylpheed not running.");
318 lock_socket_remove();
323 /* gdk_threads_init(); */
326 gtk_init(&argc, &argv);
329 gtk_widget_set_default_colormap(gdk_rgb_get_colormap());
330 gtk_widget_set_default_visual(gdk_rgb_get_visual());
332 if (!g_thread_supported())
333 g_error(_("g_thread is not supported by glib.\n"));
335 /* parse gtkrc files */
336 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtkrc-2.0",
338 gtk_rc_parse(userrc);
340 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtk",
341 G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
342 gtk_rc_parse(userrc);
345 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
346 if (!is_dir_exist(RC_DIR)) {
348 if (is_dir_exist(OLD_GTK2_RC_DIR))
349 r = migrate_old_config(OLD_GTK2_RC_DIR, RC_DIR);
350 else if (is_dir_exist(OLD_GTK1_RC_DIR))
351 r = migrate_old_config(OLD_GTK1_RC_DIR, RC_DIR);
352 if (r == FALSE && !is_dir_exist(RC_DIR) && make_dir(RC_DIR) < 0)
356 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
357 gtk_rc_parse(userrc);
360 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
361 gtk_accel_map_load (userrc);
364 gtk_settings_set_long_property(gtk_settings_get_default(),
365 "gtk-can-change-accels",
366 (glong)TRUE, "XProperty");
368 CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1);
370 MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
371 MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
372 MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
373 MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
374 MAKE_DIR_IF_NOT_EXIST(UIDL_DIR);
376 crash_file_present = is_file_exist(get_crashfile_name());
377 /* remove temporary files */
378 remove_all_files(get_tmp_dir());
379 remove_all_files(get_mime_tmp_dir());
381 if (is_file_exist("sylpheed.log")) {
382 if (rename_force("sylpheed.log", "sylpheed.log.bak") < 0)
383 FILE_OP_ERROR("sylpheed.log", "rename");
385 set_log_file("sylpheed.log");
387 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
389 folder_system_init();
390 prefs_common_read_config();
394 prefs_ext_prog_init();
395 prefs_wrapping_init();
396 prefs_compose_writing_init();
397 prefs_msg_colors_init();
399 prefs_image_viewer_init();
401 prefs_summaries_init();
402 prefs_message_init();
404 prefs_receive_init();
407 gtkaspell_checkers_init();
408 prefs_spelling_init();
411 sock_set_io_timeout(prefs_common.io_timeout_secs);
413 imap_main_set_timeout(prefs_common.io_timeout_secs);
415 prefs_actions_read_config();
416 prefs_display_header_read_config();
417 /* prefs_filtering_read_config(); */
418 addressbook_read_file();
419 renderer_read_config();
422 stock_pixbuf_gdk(NULL, STOCK_PIXMAP_SYLPHEED_ICON, &icon);
423 gtk_window_set_default_icon(icon);
425 folderview_initialize();
431 mainwin = main_window_create
432 (prefs_common.sep_folder | prefs_common.sep_msg << 1);
433 folderview = mainwin->folderview;
435 gtk_clist_freeze(GTK_CLIST(mainwin->folderview->ctree));
436 folder_item_update_freeze();
438 /* register the callback of unix domain socket input */
440 lock_socket_tag = gdk_input_add(lock_socket,
441 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
442 lock_socket_input_cb,
446 prefs_account_init();
447 account_read_config_all();
449 if (folder_read_list() < 0) {
450 if (!run_wizard(mainwin, TRUE))
455 if (!account_get_list()) {
456 if (!run_wizard(mainwin, FALSE))
458 account_read_config_all();
459 if(!account_get_list())
460 exit_sylpheed(mainwin);
463 gtk_window_deiconify(mainwin->window);
468 account_set_missing_folder();
469 folder_set_missing_folders();
470 folderview_set(folderview);
472 prefs_matcher_read_config();
474 /* make one all-folder processing before using sylpheed */
475 main_window_cursor_wait(mainwin);
476 folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
478 /* if Sylpheed crashed, rebuild caches */
479 if (!cmd.crash && crash_file_present) {
480 debug_print("Sylpheed crashed, checking for new messages in local folders\n");
481 folder_item_update_thaw();
482 folderview_check_new(NULL);
483 folder_clean_cache_memory_force();
484 folder_item_update_freeze();
486 /* make the crash-indicator file */
487 str_write_to_file("foo", get_crashfile_name());
489 addressbook_read_file();
491 inc_autocheck_timer_init(mainwin);
493 /* ignore SIGPIPE signal for preventing sudden death of program */
495 signal(SIGPIPE, SIG_IGN);
497 if (cmd.online_mode == ONLINE_MODE_OFFLINE)
498 main_window_toggle_work_offline(mainwin, TRUE, FALSE);
499 if (cmd.online_mode == ONLINE_MODE_ONLINE)
500 main_window_toggle_work_offline(mainwin, FALSE, FALSE);
502 if (cmd.status_folders) {
503 g_ptr_array_free(cmd.status_folders, TRUE);
504 cmd.status_folders = NULL;
506 if (cmd.status_full_folders) {
507 g_ptr_array_free(cmd.status_full_folders, TRUE);
508 cmd.status_full_folders = NULL;
511 sylpheed_register_idle_function(sylpheed_gtk_idle);
513 prefs_toolbar_init();
515 plugin_load_all("GTK2");
517 static_mainwindow = mainwin;
519 #ifdef HAVE_STARTUP_NOTIFICATION
520 startup_notification_complete(FALSE);
522 folder_item_update_thaw();
523 gtk_clist_thaw(GTK_CLIST(mainwin->folderview->ctree));
524 main_window_cursor_normal(mainwin);
527 g_timeout_add(1000, defer_check_all, GINT_TO_POINTER(FALSE));
528 else if (prefs_common.chk_on_startup)
529 g_timeout_add(1000, defer_check_all, GINT_TO_POINTER(TRUE));
530 else if (cmd.receive)
531 g_timeout_add(1000, defer_check, NULL);
533 gtk_widget_grab_focus(folderview->ctree);
536 open_compose_new(cmd.compose_mailto, cmd.attach_files);
537 if (cmd.attach_files) {
538 ptr_array_free_strings(cmd.attach_files);
539 g_ptr_array_free(cmd.attach_files, TRUE);
540 cmd.attach_files = NULL;
547 exit_sylpheed(mainwin);
552 static void save_all_caches(FolderItem *item, gpointer data)
556 folder_item_write_cache(item);
559 static void exit_sylpheed(MainWindow *mainwin)
563 debug_print("shutting down\n");
564 inc_autocheck_timer_remove();
566 if (prefs_common.clean_on_exit)
567 main_window_empty_trash(mainwin, prefs_common.ask_on_clean);
569 /* save prefs for opened folder */
570 if(mainwin->folderview->opened)
574 item = gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->folderview->ctree), mainwin->folderview->opened);
575 summary_save_prefs_to_folderitem(mainwin->folderview->summaryview, item);
578 /* save all state before exiting */
580 folder_func_to_all_folders(save_all_caches, NULL);
582 main_window_get_size(mainwin);
583 main_window_get_position(mainwin);
584 prefs_common_write_config();
585 account_write_config_all();
586 addressbook_export_to_file();
588 filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
589 gtk_accel_map_save(filename);
592 /* delete temporary files */
593 remove_all_files(get_tmp_dir());
594 remove_all_files(get_mime_tmp_dir());
601 /* delete crashfile */
603 g_unlink(get_crashfile_name());
605 lock_socket_remove();
607 main_window_destroy(mainwin);
609 plugin_unload_all("GTK2");
611 prefs_toolbar_done();
613 addressbook_destroy();
617 prefs_ext_prog_done();
618 prefs_wrapping_done();
619 prefs_compose_writing_done();
620 prefs_msg_colors_done();
621 prefs_image_viewer_done();
624 prefs_summaries_done();
625 prefs_message_done();
627 prefs_receive_done();
630 prefs_spelling_done();
631 gtkaspell_checkers_quit();
637 static void parse_cmd_opt(int argc, char *argv[])
641 for (i = 1; i < argc; i++) {
642 if (!strncmp(argv[i], "--receive-all", 13))
643 cmd.receive_all = TRUE;
644 else if (!strncmp(argv[i], "--receive", 9))
646 else if (!strncmp(argv[i], "--compose", 9)) {
647 const gchar *p = argv[i + 1];
650 cmd.compose_mailto = NULL;
651 if (p && *p != '\0' && *p != '-') {
652 if (!strncmp(p, "mailto:", 7))
653 cmd.compose_mailto = p + 7;
655 cmd.compose_mailto = p;
658 } else if (!strncmp(argv[i], "--attach", 8)) {
659 const gchar *p = argv[i + 1];
662 while (p && *p != '\0' && *p != '-') {
663 if (!cmd.attach_files)
664 cmd.attach_files = g_ptr_array_new();
665 if (*p != G_DIR_SEPARATOR)
666 file = g_strconcat(sylpheed_get_startup_dir(),
671 g_ptr_array_add(cmd.attach_files, file);
675 } else if (!strncmp(argv[i], "--send", 6)) {
677 } else if (!strncmp(argv[i], "--version", 9)) {
678 puts("Sylpheed version " VERSION);
680 } else if (!strncmp(argv[i], "--status-full", 13)) {
681 const gchar *p = argv[i + 1];
683 cmd.status_full = TRUE;
684 while (p && *p != '\0' && *p != '-') {
685 if (!cmd.status_full_folders)
686 cmd.status_full_folders =
688 g_ptr_array_add(cmd.status_full_folders,
693 } else if (!strncmp(argv[i], "--status", 8)) {
694 const gchar *p = argv[i + 1];
697 while (p && *p != '\0' && *p != '-') {
698 if (!cmd.status_folders)
699 cmd.status_folders = g_ptr_array_new();
700 g_ptr_array_add(cmd.status_folders,
705 } else if (!strncmp(argv[i], "--online", 8)) {
706 cmd.online_mode = ONLINE_MODE_ONLINE;
707 } else if (!strncmp(argv[i], "--offline", 9)) {
708 cmd.online_mode = ONLINE_MODE_OFFLINE;
709 } else if (!strncmp(argv[i], "--help", 6)) {
710 gchar *base = g_path_get_basename(argv[0]);
711 g_print(_("Usage: %s [OPTION]...\n"), base);
713 g_print("%s\n", _(" --compose [address] open composition window"));
714 g_print("%s\n", _(" --attach file1 [file2]...\n"
715 " open composition window with specified files\n"
717 g_print("%s\n", _(" --receive receive new messages"));
718 g_print("%s\n", _(" --receive-all receive new messages of all accounts"));
719 g_print("%s\n", _(" --send send all queued messages"));
720 g_print("%s\n", _(" --status [folder]... show the total number of messages"));
721 g_print("%s\n", _(" --status-full [folder]...\n"
722 " show the status of each folder"));
723 g_print("%s\n", _(" --online switch to online mode"));
724 g_print("%s\n", _(" --offline switch to offline mode"));
725 g_print("%s\n", _(" --debug debug mode"));
726 g_print("%s\n", _(" --help display this help and exit"));
727 g_print("%s\n", _(" --version output version information and exit"));
728 g_print("%s\n", _(" --config-dir output configuration directory"));
732 } else if (!strncmp(argv[i], "--crash", 7)) {
734 cmd.crash_params = g_strdup(argv[i + 1]);
736 } else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
743 if (cmd.attach_files && cmd.compose == FALSE) {
745 cmd.compose_mailto = NULL;
749 static gint get_queued_message_num(void)
753 queue = folder_get_default_queue();
754 if (!queue) return -1;
756 folder_item_scan(queue);
757 return queue->total_msgs;
760 static void initial_processing(FolderItem *item, gpointer data)
762 MainWindow *mainwin = (MainWindow *)data;
765 g_return_if_fail(item);
766 buf = g_strdup_printf(_("Processing (%s)..."),
769 : _("top level folder"));
770 debug_print("%s\n", buf);
774 if (item->prefs->enable_processing)
775 folder_item_apply_processing(item);
777 debug_print("done.\n");
778 STATUSBAR_POP(mainwin);
781 static void draft_all_messages(void)
783 GList *compose_list = NULL;
785 while ((compose_list = compose_get_compose_list()) != NULL) {
786 Compose *c = (Compose*)compose_list->data;
791 gboolean clean_quit(gpointer data)
793 static gboolean firstrun = TRUE;
799 /*!< Good idea to have the main window stored in a
800 * static variable so we can check that variable
801 * to see if we're really allowed to do things
802 * that actually the spawner is supposed to
803 * do (like: sending mail, composing messages).
804 * Because, really, if we're the spawnee, and
805 * we touch GTK stuff, we're hosed. See the
808 /* FIXME: Use something else to signal that we're
809 * in the original spawner, and not in a spawned
811 if (!static_mainwindow)
814 draft_all_messages();
816 exit_sylpheed(static_mainwindow);
822 void app_will_exit(GtkWidget *widget, gpointer data)
824 MainWindow *mainwin = data;
826 if (compose_get_compose_list()) {
827 gint val = alertpanel(_("Really quit?"),
828 _("Composing message exists."),
829 _("_Save to Draft"), _("_Discard them"), _("Do_n't quit"));
833 case G_ALERTALTERNATE:
836 draft_all_messages();
839 manage_window_focus_in(mainwin->window, NULL, NULL);
842 if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
843 if (alertpanel(_("Queued messages"),
844 _("Some unsent messages are queued. Exit now?"),
845 GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL)
848 manage_window_focus_in(mainwin->window, NULL, NULL);
857 * CLAWS: want this public so crash dialog can delete the
863 gchar *get_socket_name(void)
865 static gchar *filename = NULL;
867 if (filename == NULL) {
868 filename = g_strdup_printf("%s%csylpheed-claws-%d",
869 g_get_tmp_dir(), G_DIR_SEPARATOR,
880 static gchar *get_crashfile_name(void)
882 static gchar *filename = NULL;
884 if (filename == NULL) {
885 filename = g_strdup_printf("%s%csylpheed-crashed",
886 get_tmp_dir(), G_DIR_SEPARATOR);
892 static gint prohibit_duplicate_launch(void)
897 path = get_socket_name();
898 uxsock = fd_connect_unix(path);
901 return fd_open_unix(path);
904 /* remote command mode */
906 debug_print("another Sylpheed is already running.\n");
909 fd_write_all(uxsock, "receive_all\n", 12);
910 else if (cmd.receive)
911 fd_write_all(uxsock, "receive\n", 8);
912 else if (cmd.compose && cmd.attach_files) {
913 gchar *str, *compose_str;
916 if (cmd.compose_mailto)
917 compose_str = g_strdup_printf("compose_attach %s\n",
920 compose_str = g_strdup("compose_attach\n");
922 fd_write_all(uxsock, compose_str, strlen(compose_str));
925 for (i = 0; i < cmd.attach_files->len; i++) {
926 str = g_ptr_array_index(cmd.attach_files, i);
927 fd_write_all(uxsock, str, strlen(str));
928 fd_write_all(uxsock, "\n", 1);
931 fd_write_all(uxsock, ".\n", 2);
932 } else if (cmd.compose) {
935 if (cmd.compose_mailto)
936 compose_str = g_strdup_printf
937 ("compose %s\n", cmd.compose_mailto);
939 compose_str = g_strdup("compose\n");
941 fd_write_all(uxsock, compose_str, strlen(compose_str));
943 } else if (cmd.send) {
944 fd_write_all(uxsock, "send\n", 5);
945 } else if (cmd.online_mode == ONLINE_MODE_ONLINE) {
946 fd_write(uxsock, "online\n", 6);
947 } else if (cmd.online_mode == ONLINE_MODE_OFFLINE) {
948 fd_write(uxsock, "offline\n", 7);
949 } else if (cmd.status || cmd.status_full) {
952 const gchar *command;
956 command = cmd.status_full ? "status-full\n" : "status\n";
957 folders = cmd.status_full ? cmd.status_full_folders :
960 fd_write_all(uxsock, command, strlen(command));
961 for (i = 0; folders && i < folders->len; ++i) {
962 folder = g_ptr_array_index(folders, i);
963 fd_write_all(uxsock, folder, strlen(folder));
964 fd_write_all(uxsock, "\n", 1);
966 fd_write_all(uxsock, ".\n", 2);
968 fd_gets(uxsock, buf, sizeof(buf));
969 if (!strncmp(buf, ".\n", 2)) break;
973 fd_write_all(uxsock, "popup\n", 6);
979 static gint lock_socket_remove(void)
984 if (lock_socket < 0) return -1;
986 if (lock_socket_tag > 0)
987 gdk_input_remove(lock_socket_tag);
988 fd_close(lock_socket);
989 filename = get_socket_name();
996 static GPtrArray *get_folder_item_list(gint sock)
1000 GPtrArray *folders = NULL;
1003 fd_gets(sock, buf, sizeof(buf));
1004 if (!strncmp(buf, ".\n", 2)) break;
1006 if (!folders) folders = g_ptr_array_new();
1007 item = folder_find_item_from_identifier(buf);
1009 g_ptr_array_add(folders, item);
1011 g_warning("no such folder: %s\n", buf);
1017 static void lock_socket_input_cb(gpointer data,
1019 GdkInputCondition condition)
1021 MainWindow *mainwin = (MainWindow *)data;
1023 gchar buf[BUFFSIZE];
1025 sock = fd_accept(source);
1026 fd_gets(sock, buf, sizeof(buf));
1028 if (!strncmp(buf, "popup", 5)) {
1029 main_window_popup(mainwin);
1030 } else if (!strncmp(buf, "receive_all", 11)) {
1031 inc_all_account_mail(mainwin, FALSE,
1032 prefs_common.newmail_notify_manu);
1033 } else if (!strncmp(buf, "receive", 7)) {
1034 inc_mail(mainwin, prefs_common.newmail_notify_manu);
1035 } else if (!strncmp(buf, "compose_attach", 14)) {
1039 mailto = g_strdup(buf + strlen("compose_attach") + 1);
1040 files = g_ptr_array_new();
1041 while (fd_gets(sock, buf, sizeof(buf)) > 0) {
1042 if (buf[0] == '.' && buf[1] == '\n') break;
1044 g_ptr_array_add(files, g_strdup(buf));
1046 open_compose_new(mailto, files);
1047 ptr_array_free_strings(files);
1048 g_ptr_array_free(files, TRUE);
1050 } else if (!strncmp(buf, "compose", 7)) {
1051 open_compose_new(buf + strlen("compose") + 1, NULL);
1052 } else if (!strncmp(buf, "send", 4)) {
1054 } else if (!strncmp(buf, "online", 6)) {
1055 main_window_toggle_work_offline(mainwin, FALSE, FALSE);
1056 } else if (!strncmp(buf, "offline", 7)) {
1057 main_window_toggle_work_offline(mainwin, TRUE, FALSE);
1058 } else if (!strncmp(buf, "status-full", 11) ||
1059 !strncmp(buf, "status", 6)) {
1063 folders = get_folder_item_list(sock);
1064 status = folder_get_status
1065 (folders, !strncmp(buf, "status-full", 11));
1066 fd_write_all(sock, status, strlen(status));
1067 fd_write_all(sock, ".\n", 2);
1069 if (folders) g_ptr_array_free(folders, TRUE);
1075 static void open_compose_new(const gchar *address, GPtrArray *attach_files)
1080 Xstrdup_a(addr, address, return);
1084 compose_new(NULL, addr, attach_files);
1087 static void send_queue(void)
1091 for (list = folder_get_list(); list != NULL; list = list->next) {
1092 Folder *folder = list->data;
1094 if (folder->queue) {
1095 gint res = procmsg_send_queue
1096 (folder->queue, prefs_common.savemsg);
1099 alertpanel_error(_("Some errors occurred while sending queued messages."));
1101 folder_item_scan(folder->queue);
1106 static void quit_signal_handler(int sig)
1108 debug_print("Quitting on signal %d\n", sig);
1110 g_timeout_add(0, clean_quit, NULL);
1113 static void install_basic_sighandlers()
1116 struct sigaction act;
1121 sigaddset(&mask, SIGTERM);
1124 sigaddset(&mask, SIGINT);
1127 sigaddset(&mask, SIGHUP);
1130 act.sa_handler = quit_signal_handler;
1135 sigaction(SIGTERM, &act, 0);
1138 sigaction(SIGINT, &act, 0);
1141 sigaction(SIGHUP, &act, 0);
1144 sigprocmask(SIG_UNBLOCK, &mask, 0);