2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
27 #include <glib/gi18n.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkrc.h>
38 #include <sys/types.h>
43 #include <X11/SM/SMlib.h>
48 #ifdef HAVE_STARTUP_NOTIFICATION
49 # define SN_API_NOT_YET_FROZEN
50 # include <libsn/sn-launchee.h>
51 # include <gdk/gdkx.h>
56 #include "mainwindow.h"
57 #include "folderview.h"
58 #include "image_viewer.h"
59 #include "summaryview.h"
60 #include "prefs_common.h"
61 #include "prefs_account.h"
62 #include "prefs_actions.h"
63 #include "prefs_ext_prog.h"
64 #include "prefs_fonts.h"
65 #include "prefs_image_viewer.h"
66 #include "prefs_message.h"
67 #include "prefs_receive.h"
68 #include "prefs_msg_colors.h"
69 #include "prefs_quote.h"
70 #include "prefs_spelling.h"
71 #include "prefs_summaries.h"
72 #include "prefs_themes.h"
73 #include "prefs_other.h"
74 #include "prefs_logging.h"
75 #include "prefs_send.h"
76 #include "prefs_wrapping.h"
77 #include "prefs_compose_writing.h"
78 #include "prefs_display_header.h"
83 #include "manage_window.h"
84 #include "alertpanel.h"
85 #include "statusbar.h"
86 #include "addressbook.h"
94 #include "prefs_toolbar.h"
102 #include "imap-thread.h"
104 #include "stock_pixmap.h"
106 #include "valgrind.h"
119 #include <hildon-widgets/hildon-program.h>
120 #include <gtk/gtkmain.h>
122 #include <libgnomevfs/gnome-vfs-volume.h>
123 #include <libgnomevfs/gnome-vfs-volume-monitor.h>
124 #include <libgnomevfs/gnome-vfs-utils.h>
126 #define OSSO_NAME "claws_mail"
127 #define OSSO_SERVICE "com.nokia."OSSO_NAME
128 #define OSSO_OBJECT "/com/nokia/"OSSO_NAME
129 #define OSSO_IFACE "com.nokia."OSSO_NAME
131 typedef struct _AppData AppData;
133 HildonProgram *program;
134 HildonWindow *window;
135 osso_context_t *osso_context;
138 static GnomeVFSVolumeMonitor *volmon;
144 #ifdef HAVE_STARTUP_NOTIFICATION
145 static SnLauncheeContext *sn_context = NULL;
146 static SnDisplay *sn_display = NULL;
149 static gint lock_socket = -1;
150 static gint lock_socket_tag = 0;
151 static gchar *x_display = NULL;
154 ONLINE_MODE_DONT_CHANGE,
159 static struct RemoteCmd {
161 gboolean receive_all;
163 const gchar *compose_mailto;
164 GPtrArray *attach_files;
166 gboolean status_full;
167 GPtrArray *status_folders;
168 GPtrArray *status_full_folders;
175 const gchar *subscribe_uri;
179 static void parse_cmd_opt(int argc, char *argv[]);
181 static gint prohibit_duplicate_launch (void);
182 static gchar * get_crashfile_name (void);
183 static gint lock_socket_remove (void);
184 static void lock_socket_input_cb (gpointer data,
186 GdkInputCondition condition);
188 static void open_compose_new (const gchar *address,
189 GPtrArray *attach_files);
191 static void send_queue (void);
192 static void initial_processing (FolderItem *item, gpointer data);
193 static void quit_signal_handler (int sig);
194 static void install_basic_sighandlers (void);
195 static void exit_claws (MainWindow *mainwin);
197 #define MAKE_DIR_IF_NOT_EXIST(dir) \
199 if (!is_dir_exist(dir)) { \
200 if (is_file_exist(dir)) { \
202 (_("File '%s' already exists.\n" \
203 "Can't create folder."), \
207 if (make_dir(dir) < 0) \
212 static MainWindow *static_mainwindow;
215 static HildonProgram *static_hildonprogram;
216 static osso_context_t *static_osso_context;
218 void exit_event_handler(gboolean die_now, gpointer data)
221 appdata = (AppData *) data;
222 /* Do whatever application needs to do before exiting */
223 exit_claws(static_mainwindow);
224 hildon_banner_show_information(GTK_WIDGET(appdata->window), NULL,
229 /* Callback for normal D-BUS messages */
230 gint dbus_req_handler(const gchar * interface, const gchar * method,
231 GArray * arguments, gpointer data,
235 appdata = (AppData *) data;
237 if (!strcmp(method, "top_application")) {
238 osso_rpc_free_val(retval);
241 osso_system_note_infoprint(appdata->osso_context, method, retval);
242 osso_rpc_free_val(retval);
247 static gboolean emergency_exit = FALSE;
249 #ifdef HAVE_STARTUP_NOTIFICATION
250 static void sn_error_trap_push(SnDisplay *display, Display *xdisplay)
252 gdk_error_trap_push();
255 static void sn_error_trap_pop(SnDisplay *display, Display *xdisplay)
257 gdk_error_trap_pop();
260 static void startup_notification_complete(gboolean with_window)
263 GtkWidget *hack = NULL;
266 /* this is needed to make the startup notification leave,
267 * if we have been launched from a menu.
268 * We have to display a window, so let it be very little */
269 hack = gtk_window_new(GTK_WINDOW_POPUP);
270 gtk_widget_set_uposition(hack, 0, 0);
271 gtk_widget_set_size_request(hack, 1, 1);
272 gtk_widget_show(hack);
275 xdisplay = GDK_DISPLAY();
276 sn_display = sn_display_new(xdisplay,
279 sn_context = sn_launchee_context_new_from_environment(sn_display,
280 DefaultScreen(xdisplay));
282 if (sn_context != NULL) {
283 sn_launchee_context_complete(sn_context);
284 sn_launchee_context_unref(sn_context);
285 sn_display_unref(sn_display);
288 gtk_widget_destroy(hack);
291 #endif /* HAVE_STARTUP_NOTIFICATION */
293 static void claws_gtk_idle(void)
295 while(gtk_events_pending()) {
296 gtk_main_iteration();
301 static gboolean defer_check_all(void *data)
303 gboolean autochk = GPOINTER_TO_INT(data);
305 inc_all_account_mail(static_mainwindow, autochk,
306 prefs_common.newmail_notify_manu);
311 static gboolean defer_check(void *data)
313 inc_mail(static_mainwindow, prefs_common.newmail_notify_manu);
318 static gboolean defer_jump(void *data)
320 if (cmd.receive_all) {
321 defer_check_all(GINT_TO_POINTER(FALSE));
322 } else if (prefs_common.chk_on_startup) {
323 defer_check_all(GINT_TO_POINTER(TRUE));
324 } else if (cmd.receive) {
327 mainwindow_jump_to(data, FALSE);
331 static void chk_update_val(GtkWidget *widget, gpointer data)
333 gboolean *val = (gboolean *)data;
334 *val = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
337 static gboolean migrate_old_config(const gchar *old_cfg_dir, const gchar *new_cfg_dir, const gchar *oldversion)
339 gchar *message = g_strdup_printf(_("Configuration for %s found.\n"
340 "Do you want to migrate this configuration?"), oldversion);
341 gchar *message2 = g_strdup_printf(_("\n\nYour Sylpheed filtering rules can be converted by a\n"
342 "script available at %s."), TOOLS_URI);
344 if (!strcmp(oldversion, "Sylpheed"))
345 message = g_strconcat(message, message2, NULL);
349 GtkWidget *window = NULL;
350 GtkWidget *keep_backup_chk;
351 GtkTooltips *tips = gtk_tooltips_new();
352 gboolean backup = TRUE;
354 keep_backup_chk = gtk_check_button_new_with_label (_("Keep old configuration"));
355 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(keep_backup_chk), TRUE);
356 gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), keep_backup_chk,
357 _("Keeping a backup will allow you to go back to an "
358 "older version, but may take a while if you have "
359 "cached IMAP or News data, and will take some extra "
360 "room on your disk."),
363 g_signal_connect(G_OBJECT(keep_backup_chk), "toggled",
364 G_CALLBACK(chk_update_val), &backup);
366 if (alertpanel_full(_("Migration of configuration"), message,
367 GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL, FALSE,
368 keep_backup_chk, ALERT_QUESTION, G_ALERTDEFAULT) != G_ALERTALTERNATE) {
372 /* we can either do a fast migration requiring not any extra disk
373 * space, or a slow one that copies the old configuration and leaves
377 window = label_window_create(_("Copying configuration... This may take a while..."));
380 r = copy_dir(old_cfg_dir, new_cfg_dir);
381 label_window_destroy(window);
383 /* if copy failed, we'll remove the partially copied
386 alertpanel_error(_("Migration failed!"));
387 remove_dir_recursive(new_cfg_dir);
390 /* fast mode failed, but we don't want backup */
391 remove_dir_recursive(old_cfg_dir);
395 window = label_window_create(_("Migrating configuration..."));
398 r = g_rename(old_cfg_dir, new_cfg_dir);
399 label_window_destroy(window);
401 /* if g_rename failed, we'll try to copy */
403 FILE_OP_ERROR(new_cfg_dir, "g_rename failed, trying copy\n");
410 static void migrate_common_rc(const gchar *old_rc, const gchar *new_rc)
413 gchar *plugin_path, *old_plugin_path, *new_plugin_path;
415 oldfp = g_fopen(old_rc, "r");
418 newfp = g_fopen(new_rc, "w");
424 plugin_path = g_strdup(get_plugin_dir());
425 new_plugin_path = g_strdup(plugin_path);
427 if (strstr(plugin_path, "/claws-mail/")) {
428 gchar *end = g_strdup(strstr(plugin_path, "/claws-mail/")+strlen("/claws-mail/"));
429 *(strstr(plugin_path, "/claws-mail/")) = '\0';
430 old_plugin_path = g_strconcat(plugin_path, "/sylpheed-claws/", end, NULL);
433 old_plugin_path = g_strdup(new_plugin_path);
435 debug_print("replacing %s with %s\n", old_plugin_path, new_plugin_path);
436 while (fgets(buf, sizeof(buf), oldfp)) {
437 if (strncmp(buf, old_plugin_path, strlen(old_plugin_path))) {
440 debug_print("->replacing %s", buf);
441 debug_print(" with %s%s", new_plugin_path, buf+strlen(old_plugin_path));
442 fputs(new_plugin_path, newfp);
443 fputs(buf+strlen(old_plugin_path), newfp);
447 g_free(new_plugin_path);
448 g_free(old_plugin_path);
455 sc_client_set_value (MainWindow *mainwin,
466 prop.num_vals = num_vals;
470 if (mainwin->smc_conn)
471 SmcSetProperties ((SmcConn) mainwin->smc_conn, 1, proplist);
474 static void sc_die_callback (SmcConn smc_conn, SmPointer client_data)
479 static void sc_save_complete_callback(SmcConn smc_conn, SmPointer client_data)
483 static void sc_shutdown_cancelled_callback (SmcConn smc_conn, SmPointer client_data)
485 MainWindow *mainwin = (MainWindow *)client_data;
486 if (mainwin->smc_conn)
487 SmcSaveYourselfDone ((SmcConn) mainwin->smc_conn, TRUE);
490 static void sc_save_yourself_callback (SmcConn smc_conn,
491 SmPointer client_data,
497 MainWindow *mainwin = (MainWindow *)client_data;
498 if (mainwin->smc_conn)
499 SmcSaveYourselfDone ((SmcConn) mainwin->smc_conn, TRUE);
502 static IceIOErrorHandler sc_ice_installed_handler;
504 static void sc_ice_io_error_handler (IceConn connection)
506 if (sc_ice_installed_handler)
507 (*sc_ice_installed_handler) (connection);
509 static gboolean sc_process_ice_messages (GIOChannel *source,
510 GIOCondition condition,
513 IceConn connection = (IceConn) data;
514 IceProcessMessagesStatus status;
516 status = IceProcessMessages (connection, NULL, NULL);
518 if (status == IceProcessMessagesIOError) {
519 IcePointer context = IceGetConnectionContext (connection);
521 if (context && GTK_IS_OBJECT (context)) {
522 guint disconnect_id = g_signal_lookup ("disconnect", G_OBJECT_TYPE (context));
524 if (disconnect_id > 0)
525 g_signal_emit (context, disconnect_id, 0);
527 IceSetShutdownNegotiation (connection, False);
528 IceCloseConnection (connection);
535 static void new_ice_connection (IceConn connection, IcePointer client_data, Bool opening,
536 IcePointer *watch_data)
542 /* Make sure we don't pass on these file descriptors to any
544 fcntl(IceConnectionNumber(connection),F_SETFD,
545 fcntl(IceConnectionNumber(connection),F_GETFD,0) | FD_CLOEXEC);
547 channel = g_io_channel_unix_new (IceConnectionNumber (connection));
548 input_id = g_io_add_watch (channel,
549 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI,
550 sc_process_ice_messages,
552 g_io_channel_unref (channel);
554 *watch_data = (IcePointer) GUINT_TO_POINTER (input_id);
556 input_id = GPOINTER_TO_UINT ((gpointer) *watch_data);
557 g_source_remove (input_id);
561 static void sc_session_manager_connect(MainWindow *mainwin)
563 static gboolean connected = FALSE;
564 SmcCallbacks callbacks;
566 IceIOErrorHandler default_handler;
573 sc_ice_installed_handler = IceSetIOErrorHandler (NULL);
574 default_handler = IceSetIOErrorHandler (sc_ice_io_error_handler);
576 if (sc_ice_installed_handler == default_handler)
577 sc_ice_installed_handler = NULL;
579 IceAddConnectionWatch (new_ice_connection, NULL);
582 callbacks.save_yourself.callback = sc_save_yourself_callback;
583 callbacks.die.callback = sc_die_callback;
584 callbacks.save_complete.callback = sc_save_complete_callback;
585 callbacks.shutdown_cancelled.callback = sc_shutdown_cancelled_callback;
587 callbacks.save_yourself.client_data =
588 callbacks.die.client_data =
589 callbacks.save_complete.client_data =
590 callbacks.shutdown_cancelled.client_data = (SmPointer) mainwin;
591 if (g_getenv ("SESSION_MANAGER")) {
592 gchar error_string_ret[256] = "";
594 mainwin->smc_conn = (gpointer)
595 SmcOpenConnection (NULL, mainwin,
596 SmProtoMajor, SmProtoMinor,
597 SmcSaveYourselfProcMask | SmcDieProcMask |
598 SmcSaveCompleteProcMask |
599 SmcShutdownCancelledProcMask,
602 256, error_string_ret);
604 if (error_string_ret[0] || mainwin->smc_conn == NULL)
605 g_warning ("While connecting to session manager:\n%s.",
609 vals = g_new (SmPropValue, 1);
610 vals[0].length = strlen(argv0);
611 vals[0].value = argv0;
612 sc_client_set_value (mainwin, SmCloneCommand, SmLISTofARRAY8, 1, vals);
613 sc_client_set_value (mainwin, SmRestartCommand, SmLISTofARRAY8, 1, vals);
614 sc_client_set_value (mainwin, SmProgram, SmARRAY8, 1, vals);
616 vals[0].length = strlen(g_get_user_name()?g_get_user_name():"");
617 vals[0].value = g_strdup(g_get_user_name()?g_get_user_name():"");
618 sc_client_set_value (mainwin, SmUserID, SmARRAY8, 1, vals);
624 static gboolean sc_exiting = FALSE;
625 static gboolean sc_starting = FALSE;
626 static gboolean show_at_startup = TRUE;
627 static gboolean claws_crashed_bool = FALSE;
629 gboolean claws_crashed(void) {
630 return claws_crashed_bool;
633 void main_set_show_at_startup(gboolean show)
635 show_at_startup = show;
639 static void main_vol_mount_cb(GnomeVFSVolumeMonitor *vfs, GnomeVFSVolume *vol, MainWindow *mainwin)
641 gchar *uri = gnome_vfs_volume_get_activation_uri (vol);
642 gchar *mount_path = uri?gnome_vfs_get_local_path_from_uri (uri):NULL;
645 if(!strcmp(mount_path, prefs_common.data_root)) {
646 gtk_widget_set_sensitive(mainwin->window, TRUE);
652 static void main_vol_unmount_cb(GnomeVFSVolumeMonitor *vfs, GnomeVFSVolume *vol, MainWindow *mainwin)
654 gchar *uri = gnome_vfs_volume_get_activation_uri (vol);
655 gchar *mount_path = uri?gnome_vfs_get_local_path_from_uri (uri):NULL;
658 if(!strcmp(mount_path, prefs_common.data_root)) {
659 gtk_widget_set_sensitive(mainwin->window, FALSE);
668 static FILE* win32_debug_fp=NULL;
669 static guint win32_log_handler_app_id;
670 static guint win32_log_handler_glib_id;
671 static guint win32_log_handler_gtk_id;
673 static void win32_print_stdout(const gchar *string)
675 if (win32_debug_fp) {
676 fprintf(win32_debug_fp, string);
677 fflush(win32_debug_fp);
681 static void win32_print_stderr(const gchar *string)
683 if (win32_debug_fp) {
684 fprintf(win32_debug_fp, string);
685 fflush(win32_debug_fp);
689 static void win32_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar* message, gpointer user_data)
691 if (win32_debug_fp) {
694 switch(log_level & G_LOG_LEVEL_MASK)
696 case G_LOG_LEVEL_ERROR:
699 case G_LOG_LEVEL_CRITICAL:
702 case G_LOG_LEVEL_WARNING:
705 case G_LOG_LEVEL_MESSAGE:
708 case G_LOG_LEVEL_INFO:
711 case G_LOG_LEVEL_DEBUG:
718 fprintf(win32_debug_fp, "%s: %s: %s", log_domain, type, message);
720 fprintf(win32_debug_fp, "%s: %s", type, message);
721 fflush(win32_debug_fp);
725 static void win32_open_log(void)
727 if (is_file_exist("claws-win32.log")) {
728 if (rename_force("claws-win32.log", "claws-win32.log.bak") < 0)
729 FILE_OP_ERROR("claws-win32.log", "rename");
731 win32_debug_fp = fopen("claws-win32.log", "w");
734 g_set_print_handler(win32_print_stdout);
735 g_set_printerr_handler(win32_print_stdout);
736 win32_log_handler_app_id = g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
737 | G_LOG_FLAG_RECURSION, win32_log, NULL);
738 win32_log_handler_glib_id = g_log_set_handler("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
739 | G_LOG_FLAG_RECURSION, win32_log, NULL);
740 win32_log_handler_gtk_id = g_log_set_handler("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
741 | G_LOG_FLAG_RECURSION, win32_log, NULL);
745 static void win32_close_log(void)
749 g_log_remove_handler("", win32_log_handler_app_id);
750 g_log_remove_handler("GLib", win32_log_handler_glib_id);
751 g_log_remove_handler("Gtk", win32_log_handler_gtk_id);
752 fclose(win32_debug_fp);
758 int main(int argc, char *argv[])
761 osso_context_t *osso_context;
762 osso_return_t result;
766 FolderView *folderview;
768 gboolean crash_file_present = FALSE;
769 gint num_folder_class = 0;
770 gboolean asked_for_migration = FALSE;
772 START_TIMING("startup");
779 if (!claws_init(&argc, &argv)) {
786 prefs_prepare_cache();
787 prog_version = PROG_VERSION;
788 argv0 = g_strdup(argv[0]);
790 parse_cmd_opt(argc, argv);
795 gtk_init(&argc, &argv);
796 crash_main(cmd.crash_params);
802 crash_install_handlers();
804 install_basic_sighandlers();
807 /* check and create unix domain socket for remote operation */
809 lock_socket = prohibit_duplicate_launch();
810 if (lock_socket < 0) {
811 #ifdef HAVE_STARTUP_NOTIFICATION
812 if(gtk_init_check(&argc, &argv))
813 startup_notification_complete(TRUE);
818 if (cmd.status || cmd.status_full) {
819 puts("0 Claws Mail not running.");
820 lock_socket_remove();
827 if (!g_thread_supported())
831 gtk_init(&argc, &argv);
834 osso_context = osso_initialize(OSSO_SERVICE, "2.8.1", TRUE, NULL);
835 if (osso_context == NULL) {
838 static_hildonprogram = HILDON_PROGRAM(hildon_program_get_instance());
839 static_osso_context = osso_context;
842 gtk_widget_set_default_colormap(gdk_rgb_get_colormap());
843 gtk_widget_set_default_visual(gdk_rgb_get_visual());
845 if (!g_thread_supported()) {
846 g_error(_("g_thread is not supported by glib.\n"));
849 /* check that we're not on a too recent/old gtk+ */
850 #if GTK_CHECK_VERSION(2, 9, 0)
851 if (gtk_check_version(2, 9, 0) != NULL) {
852 alertpanel_error(_("Claws Mail has been compiled with "
853 "a more recent GTK+ library than is "
854 "currently available. This will cause "
855 "crashes. You need to upgrade GTK+ or "
856 "recompile Claws Mail."));
863 if (gtk_check_version(2, 9, 0) == NULL) {
864 alertpanel_error(_("Claws Mail has been compiled with "
865 "an older GTK+ library than is "
866 "currently available. This will cause "
867 "crashes. You need to recompile "
875 /* parse gtkrc files */
876 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtkrc-2.0",
878 gtk_rc_parse(userrc);
880 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtk",
881 G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
882 gtk_rc_parse(userrc);
886 CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_home_dir(), 1, win32_close_log(););
888 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
891 /* no config dir exists. See if we can migrate an old config. */
892 if (!is_dir_exist(RC_DIR)) {
893 prefs_destroy_cache();
896 /* if one of the old dirs exist, we'll ask if the user
897 * want to migrates, and r will be TRUE if he said yes
898 * and migration succeeded, and FALSE otherwise.
900 if (is_dir_exist(OLD_GTK2_RC_DIR)) {
901 r = migrate_old_config(OLD_GTK2_RC_DIR, RC_DIR, _("Sylpheed-Claws 2.6.0 (or older)"));
902 asked_for_migration = TRUE;
903 } else if (is_dir_exist(OLDER_GTK2_RC_DIR)) {
904 r = migrate_old_config(OLDER_GTK2_RC_DIR, RC_DIR, _("Sylpheed-Claws 1.9.15 (or older)"));
905 asked_for_migration = TRUE;
906 } else if (is_dir_exist(OLD_GTK1_RC_DIR)) {
907 r = migrate_old_config(OLD_GTK1_RC_DIR, RC_DIR, _("Sylpheed-Claws 1.0.5 (or older)"));
908 asked_for_migration = TRUE;
909 } else if (is_dir_exist(SYLPHEED_RC_DIR)) {
910 r = migrate_old_config(SYLPHEED_RC_DIR, RC_DIR, "Sylpheed");
911 asked_for_migration = TRUE;
914 /* If migration failed or the user didn't want to do it,
915 * we create a new one (and we'll hit wizard later).
917 if (r == FALSE && !is_dir_exist(RC_DIR) && make_dir(RC_DIR) < 0) {
926 if (!is_file_exist(RC_DIR G_DIR_SEPARATOR_S COMMON_RC) &&
927 is_file_exist(RC_DIR G_DIR_SEPARATOR_S OLD_COMMON_RC)) {
928 /* post 2.6 name change */
929 migrate_common_rc(RC_DIR G_DIR_SEPARATOR_S OLD_COMMON_RC,
930 RC_DIR G_DIR_SEPARATOR_S COMMON_RC);
934 plugin_load_all("Common");
936 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
937 gtk_rc_parse(userrc);
940 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
941 gtk_accel_map_load (userrc);
945 CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_rc_dir(), 1, win32_close_log(););
947 CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1);
950 MAKE_DIR_IF_NOT_EXIST(get_mail_base_dir());
951 MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
952 MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
953 MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
954 MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
955 MAKE_DIR_IF_NOT_EXIST(UIDL_DIR);
957 crash_file_present = is_file_exist(get_crashfile_name());
958 /* remove temporary files */
959 remove_all_files(get_tmp_dir());
960 remove_all_files(get_mime_tmp_dir());
962 if (!cmd.crash && crash_file_present)
963 claws_crashed_bool = TRUE;
965 if (is_file_exist("claws.log")) {
966 if (rename_force("claws.log", "claws.log.bak") < 0)
967 FILE_OP_ERROR("claws.log", "rename");
969 set_log_file(LOG_PROTOCOL, "claws.log");
971 if (is_file_exist("filtering.log")) {
972 if (rename_force("filtering.log", "filtering.log.bak") < 0)
973 FILE_OP_ERROR("filtering.log", "rename");
975 set_log_file(LOG_DEBUG_FILTERING, "filtering.log");
978 CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_home_dir(), 1, win32_close_log(););
980 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
983 folder_system_init();
984 prefs_common_read_config();
988 prefs_ext_prog_init();
989 prefs_wrapping_init();
990 prefs_compose_writing_init();
991 prefs_msg_colors_init();
993 prefs_image_viewer_init();
995 prefs_summaries_init();
996 prefs_message_init();
998 prefs_logging_init();
999 prefs_receive_init();
1003 gtkaspell_checkers_init();
1004 prefs_spelling_init();
1007 sock_set_io_timeout(prefs_common.io_timeout_secs);
1008 prefs_actions_read_config();
1009 prefs_display_header_read_config();
1010 /* prefs_filtering_read_config(); */
1011 addressbook_read_file();
1012 renderer_read_config();
1014 gtkut_widget_init();
1015 stock_pixbuf_gdk(NULL, STOCK_PIXMAP_CLAWS_MAIL_ICON, &icon);
1016 gtk_window_set_default_icon(icon);
1018 folderview_initialize();
1024 mainwin = main_window_create();
1027 appdata = g_new0(AppData, 1);
1028 appdata->program = static_hildonprogram;
1029 appdata->window = mainwin->window;
1030 appdata->osso_context = osso_context;
1031 result = osso_rpc_set_cb_f(appdata->osso_context,
1035 dbus_req_handler, appdata);
1036 if (result != OSSO_OK) {
1040 /* Add handler for Exit D-BUS messages */
1041 result = osso_application_set_exit_cb(appdata->osso_context,
1043 (gpointer) appdata);
1044 if (result != OSSO_OK) {
1048 manage_window_focus_in(mainwin->window, NULL, NULL);
1049 folderview = mainwin->folderview;
1051 gtk_clist_freeze(GTK_CLIST(mainwin->folderview->ctree));
1052 folder_item_update_freeze();
1054 /* register the callback of unix domain socket input */
1056 lock_socket_tag = gdk_input_add(lock_socket,
1057 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
1058 lock_socket_input_cb,
1062 prefs_account_init();
1063 account_read_config_all();
1065 /* If we can't read a folder list or don't have accounts,
1066 * it means the configuration's not done. Either this is
1067 * a brand new install, either a failed/refused migration.
1068 * So we'll start the wizard.
1070 if (folder_read_list() < 0) {
1071 prefs_destroy_cache();
1073 /* if run_wizard returns FALSE it's because it's
1074 * been cancelled. We can't do much but exit.
1075 * however, if the user was asked for a migration,
1076 * we remove the newly created directory so that
1077 * he's asked again for migration on next launch.*/
1078 if (!run_wizard(mainwin, TRUE)) {
1079 if (asked_for_migration)
1080 remove_dir_recursive(RC_DIR);
1086 main_window_reflect_prefs_all_now();
1087 folder_write_list();
1090 if (!account_get_list()) {
1091 prefs_destroy_cache();
1092 if (!run_wizard(mainwin, FALSE)) {
1093 if (asked_for_migration)
1094 remove_dir_recursive(RC_DIR);
1100 if(!account_get_list()) {
1101 exit_claws(mainwin);
1110 toolbar_main_set_sensitive(mainwin);
1111 main_window_set_menu_sensitive(mainwin);
1113 /* if crashed, show window early so that the user
1114 * sees what's happening */
1115 if (claws_crashed())
1116 main_window_popup(mainwin);
1118 #ifdef HAVE_LIBETPAN
1119 imap_main_init(prefs_common.skip_ssl_cert_check);
1120 imap_main_set_timeout(prefs_common.io_timeout_secs);
1122 account_set_missing_folder();
1123 folder_set_missing_folders();
1124 folderview_set(folderview);
1126 prefs_matcher_read_config();
1128 /* make one all-folder processing before using claws */
1129 main_window_cursor_wait(mainwin);
1130 folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
1132 /* if claws crashed, rebuild caches */
1133 if (claws_crashed()) {
1135 debug_print("Claws Mail crashed, checking for new messages in local folders\n");
1136 folder_item_update_thaw();
1137 folderview_check_new(NULL);
1138 folder_clean_cache_memory_force();
1139 folder_item_update_freeze();
1141 /* make the crash-indicator file */
1142 str_write_to_file("foo", get_crashfile_name());
1144 inc_autocheck_timer_init(mainwin);
1146 /* ignore SIGPIPE signal for preventing sudden death of program */
1148 signal(SIGPIPE, SIG_IGN);
1150 if (cmd.online_mode == ONLINE_MODE_OFFLINE) {
1151 main_window_toggle_work_offline(mainwin, TRUE, FALSE);
1153 if (cmd.online_mode == ONLINE_MODE_ONLINE) {
1154 main_window_toggle_work_offline(mainwin, FALSE, FALSE);
1157 if (cmd.status_folders) {
1158 g_ptr_array_free(cmd.status_folders, TRUE);
1159 cmd.status_folders = NULL;
1161 if (cmd.status_full_folders) {
1162 g_ptr_array_free(cmd.status_full_folders, TRUE);
1163 cmd.status_full_folders = NULL;
1166 claws_register_idle_function(claws_gtk_idle);
1168 prefs_toolbar_init();
1170 num_folder_class = g_list_length(folder_get_list());
1172 plugin_load_all("GTK2");
1174 if (g_list_length(folder_get_list()) != num_folder_class) {
1175 debug_print("new folders loaded, reloading processing rules\n");
1176 prefs_matcher_read_config();
1179 if (plugin_get_unloaded_list() != NULL) {
1180 main_window_cursor_normal(mainwin);
1181 alertpanel_warning(_("Some plugin(s) failed to load. "
1182 "Check the Plugins configuration "
1183 "for more information."));
1184 main_window_cursor_wait(mainwin);
1187 plugin_load_standard_plugins ();
1189 /* if not crashed, show window now */
1190 if (!claws_crashed()) {
1191 /* apart if something told not to show */
1192 if (show_at_startup)
1193 main_window_popup(mainwin);
1196 if (!folder_have_mailbox()) {
1197 prefs_destroy_cache();
1198 main_window_cursor_normal(mainwin);
1199 if (folder_get_list() != NULL) {
1200 alertpanel_error(_("Claws Mail has detected a configured "
1201 "mailbox, but it is incomplete. It is "
1202 "possibly due to a failing IMAP account. Use "
1203 "\"Rebuild folder tree\" on the mailbox parent "
1204 "folder's context menu to try to fix it."));
1206 alertpanel_error(_("Claws Mail has detected a configured "
1207 "mailbox, but could not load it. It is "
1208 "probably provided by an out-of-date "
1209 "external plugin. Please reinstall the "
1210 "plugin and try again."));
1211 exit_claws(mainwin);
1219 static_mainwindow = mainwin;
1222 if (prefs_common.data_root != NULL && *prefs_common.data_root != '\0') {
1223 GnomeVFSVolume *vol = NULL;
1224 gchar *uri, *mount_path;
1226 volmon = gnome_vfs_get_volume_monitor();
1227 vol = gnome_vfs_volume_monitor_get_volume_for_path(volmon, prefs_common.data_root);
1229 uri = gnome_vfs_volume_get_activation_uri (vol);
1230 mount_path = uri?gnome_vfs_get_local_path_from_uri (uri):NULL;
1233 if (vol == NULL || !gnome_vfs_volume_is_mounted(vol)
1234 || strcmp(mount_path, prefs_common.data_root)) {
1235 alertpanel_error(_("Claws Mail can not start without its data volume (%s)."),
1236 prefs_common.data_root);
1238 gnome_vfs_volume_unref(vol);
1239 exit_claws(mainwin);
1243 gnome_vfs_volume_unref(vol);
1244 g_signal_connect(G_OBJECT(volmon),
1245 "volume-mounted", G_CALLBACK(main_vol_mount_cb), mainwin);
1246 g_signal_connect(G_OBJECT(volmon),
1247 "volume-unmounted", G_CALLBACK(main_vol_unmount_cb), mainwin);
1251 #ifdef HAVE_STARTUP_NOTIFICATION
1252 startup_notification_complete(FALSE);
1255 sc_session_manager_connect(mainwin);
1257 folder_item_update_thaw();
1258 gtk_clist_thaw(GTK_CLIST(mainwin->folderview->ctree));
1259 main_window_cursor_normal(mainwin);
1261 if (!cmd.target && prefs_common.goto_last_folder_on_startup &&
1262 folder_find_item_from_identifier(prefs_common.last_opened_folder) != NULL &&
1264 cmd.target = prefs_common.last_opened_folder;
1267 if (cmd.receive_all && !cmd.target) {
1268 g_timeout_add(1000, defer_check_all, GINT_TO_POINTER(FALSE));
1269 } else if (prefs_common.chk_on_startup && !cmd.target) {
1270 g_timeout_add(1000, defer_check_all, GINT_TO_POINTER(TRUE));
1271 } else if (cmd.receive && !cmd.target) {
1272 g_timeout_add(1000, defer_check, NULL);
1274 gtk_widget_grab_focus(folderview->ctree);
1278 open_compose_new(cmd.compose_mailto, cmd.attach_files);
1280 if (cmd.attach_files) {
1281 ptr_array_free_strings(cmd.attach_files);
1282 g_ptr_array_free(cmd.attach_files, TRUE);
1283 cmd.attach_files = NULL;
1285 if (cmd.subscribe) {
1286 folder_subscribe(cmd.subscribe_uri);
1294 g_timeout_add(500, defer_jump, (gpointer)cmd.target);
1297 prefs_destroy_cache();
1299 compose_reopen_exit_drafts();
1301 sc_starting = FALSE;
1307 osso_deinitialize(osso_context);
1312 exit_claws(mainwin);
1317 static void save_all_caches(FolderItem *item, gpointer data)
1324 folder_item_close(item);
1327 folder_item_free_cache(item, TRUE);
1330 static void exit_claws(MainWindow *mainwin)
1336 debug_print("shutting down\n");
1337 inc_autocheck_timer_remove();
1339 if (prefs_common.clean_on_exit && !emergency_exit) {
1340 main_window_empty_trash(mainwin, prefs_common.ask_on_clean);
1343 /* save prefs for opened folder */
1344 if(mainwin->folderview->opened) {
1347 item = gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->folderview->ctree), mainwin->folderview->opened);
1348 summary_save_prefs_to_folderitem(mainwin->folderview->summaryview, item);
1349 prefs_common.last_opened_folder = folder_item_get_identifier(item);
1352 /* save all state before exiting */
1353 folder_func_to_all_folders(save_all_caches, NULL);
1354 folder_write_list();
1356 main_window_get_size(mainwin);
1357 main_window_get_position(mainwin);
1359 prefs_common_write_config();
1360 account_write_config_all();
1361 addressbook_export_to_file();
1363 filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
1364 gtk_accel_map_save(filename);
1367 /* delete temporary files */
1368 remove_all_files(get_tmp_dir());
1369 remove_all_files(get_mime_tmp_dir());
1371 close_log_file(LOG_PROTOCOL);
1372 close_log_file(LOG_DEBUG_FILTERING);
1374 #ifdef HAVE_LIBETPAN
1377 /* delete crashfile */
1379 g_unlink(get_crashfile_name());
1381 lock_socket_remove();
1384 if (mainwin->smc_conn)
1385 SmcCloseConnection ((SmcConn)mainwin->smc_conn, 0, NULL);
1386 mainwin->smc_conn = NULL;
1389 main_window_destroy_all();
1391 plugin_unload_all("GTK2");
1393 prefs_toolbar_done();
1395 addressbook_destroy();
1397 prefs_themes_done();
1399 prefs_ext_prog_done();
1400 prefs_wrapping_done();
1401 prefs_compose_writing_done();
1402 prefs_msg_colors_done();
1403 prefs_image_viewer_done();
1404 image_viewer_done();
1406 prefs_summaries_done();
1407 prefs_message_done();
1409 prefs_receive_done();
1413 prefs_spelling_done();
1414 gtkaspell_checkers_quit();
1416 plugin_unload_all("Common");
1420 static void parse_cmd_opt(int argc, char *argv[])
1424 for (i = 1; i < argc; i++) {
1425 if (!strncmp(argv[i], "--receive-all", 13)) {
1426 cmd.receive_all = TRUE;
1427 } else if (!strncmp(argv[i], "--receive", 9)) {
1429 } else if (!strncmp(argv[i], "--compose", 9)) {
1430 const gchar *p = argv[i + 1];
1433 cmd.compose_mailto = NULL;
1434 if (p && *p != '\0' && *p != '-') {
1435 if (!strncmp(p, "mailto:", 7)) {
1436 cmd.compose_mailto = p + 7;
1438 cmd.compose_mailto = p;
1442 } else if (!strncmp(argv[i], "--subscribe", 11)) {
1443 const gchar *p = argv[i + 1];
1444 if (p && *p != '\0' && *p != '-') {
1445 cmd.subscribe = TRUE;
1446 cmd.subscribe_uri = p;
1448 } else if (!strncmp(argv[i], "--attach", 8)) {
1449 const gchar *p = argv[i + 1];
1452 while (p && *p != '\0' && *p != '-') {
1453 if (!cmd.attach_files) {
1454 cmd.attach_files = g_ptr_array_new();
1456 if ((file = g_filename_from_uri(p, NULL, NULL)) != NULL) {
1457 if (!is_file_exist(file)) {
1462 if (file == NULL && *p != G_DIR_SEPARATOR) {
1463 file = g_strconcat(claws_get_startup_dir(),
1466 } else if (file == NULL) {
1469 g_ptr_array_add(cmd.attach_files, file);
1473 } else if (!strncmp(argv[i], "--send", 6)) {
1475 } else if (!strncmp(argv[i], "--version", 9) ||
1476 !strncmp(argv[i], "-v", 2)) {
1477 g_print("Claws Mail version " VERSION);
1479 } else if (!strncmp(argv[i], "--status-full", 13)) {
1480 const gchar *p = argv[i + 1];
1482 cmd.status_full = TRUE;
1483 while (p && *p != '\0' && *p != '-') {
1484 if (!cmd.status_full_folders) {
1485 cmd.status_full_folders =
1488 g_ptr_array_add(cmd.status_full_folders,
1493 } else if (!strncmp(argv[i], "--status", 8)) {
1494 const gchar *p = argv[i + 1];
1497 while (p && *p != '\0' && *p != '-') {
1498 if (!cmd.status_folders)
1499 cmd.status_folders = g_ptr_array_new();
1500 g_ptr_array_add(cmd.status_folders,
1505 } else if (!strncmp(argv[i], "--online", 8)) {
1506 cmd.online_mode = ONLINE_MODE_ONLINE;
1507 } else if (!strncmp(argv[i], "--offline", 9)) {
1508 cmd.online_mode = ONLINE_MODE_OFFLINE;
1509 } else if (!strncmp(argv[i], "--help", 6) ||
1510 !strncmp(argv[i], "-h", 2)) {
1511 gchar *base = g_path_get_basename(argv[0]);
1512 g_print(_("Usage: %s [OPTION]...\n"), base);
1514 g_print("%s\n", _(" --compose [address] open composition window"));
1515 g_print("%s\n", _(" --subscribe [uri] subscribe to the given URI if possible"));
1516 g_print("%s\n", _(" --attach file1 [file2]...\n"
1517 " open composition window with specified files\n"
1519 g_print("%s\n", _(" --receive receive new messages"));
1520 g_print("%s\n", _(" --receive-all receive new messages of all accounts"));
1521 g_print("%s\n", _(" --send send all queued messages"));
1522 g_print("%s\n", _(" --status [folder]... show the total number of messages"));
1523 g_print("%s\n", _(" --status-full [folder]...\n"
1524 " show the status of each folder"));
1525 g_print("%s\n", _(" --select folder[/msg] jumps to the specified folder/message\n"
1526 " folder is a folder id like 'folder/sub_folder'"));
1527 g_print("%s\n", _(" --online switch to online mode"));
1528 g_print("%s\n", _(" --offline switch to offline mode"));
1529 g_print("%s\n", _(" --exit --quit -q exit Claws Mail"));
1530 g_print("%s\n", _(" --debug debug mode"));
1531 g_print("%s\n", _(" --help -h display this help and exit"));
1532 g_print("%s\n", _(" --version -v output version information and exit"));
1533 g_print("%s\n", _(" --config-dir output configuration directory"));
1537 } else if (!strncmp(argv[i], "--crash", 7)) {
1539 cmd.crash_params = g_strdup(argv[i + 1]);
1541 } else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
1544 } else if (!strncmp(argv[i], "--exit", 6) ||
1545 !strncmp(argv[i], "--quit", 6) ||
1546 !strncmp(argv[i], "-q", 2)) {
1548 } else if (!strncmp(argv[i], "--select", 8) && i+1 < argc) {
1549 cmd.target = argv[i+1];
1550 } else if (i == 1 && argc == 2) {
1551 /* only one parameter. Do something intelligent about it */
1552 if (strstr(argv[i], "@") && !strstr(argv[i], "://")) {
1553 const gchar *p = argv[i];
1556 cmd.compose_mailto = NULL;
1557 if (p && *p != '\0' && *p != '-') {
1558 if (!strncmp(p, "mailto:", 7)) {
1559 cmd.compose_mailto = p + 7;
1561 cmd.compose_mailto = p;
1564 } else if (strstr(argv[i], "://")) {
1565 const gchar *p = argv[i];
1566 if (p && *p != '\0' && *p != '-') {
1567 cmd.subscribe = TRUE;
1568 cmd.subscribe_uri = p;
1570 } else if (!strcmp(argv[i], "--sync")) {
1573 g_print(_("Unknown option\n"));
1579 if (cmd.attach_files && cmd.compose == FALSE) {
1581 cmd.compose_mailto = NULL;
1585 static void initial_processing(FolderItem *item, gpointer data)
1587 MainWindow *mainwin = (MainWindow *)data;
1590 g_return_if_fail(item);
1591 buf = g_strdup_printf(_("Processing (%s)..."),
1594 : _("top level folder"));
1598 if (item->prefs->enable_processing) {
1599 folder_item_apply_processing(item);
1602 STATUSBAR_POP(mainwin);
1605 static gboolean draft_all_messages(void)
1607 GList *compose_list = NULL;
1609 compose_clear_exit_drafts();
1610 compose_list = compose_get_compose_list();
1611 while (compose_list != NULL) {
1612 Compose *c = (Compose*)compose_list->data;
1613 if (!compose_draft(c, COMPOSE_DRAFT_FOR_EXIT))
1615 compose_list = compose_get_compose_list();
1619 gboolean clean_quit(gpointer data)
1621 static gboolean firstrun = TRUE;
1628 /*!< Good idea to have the main window stored in a
1629 * static variable so we can check that variable
1630 * to see if we're really allowed to do things
1631 * that actually the spawner is supposed to
1632 * do (like: sending mail, composing messages).
1633 * Because, really, if we're the spawnee, and
1634 * we touch GTK stuff, we're hosed. See the
1637 /* FIXME: Use something else to signal that we're
1638 * in the original spawner, and not in a spawned
1640 if (!static_mainwindow) {
1644 draft_all_messages();
1645 emergency_exit = TRUE;
1646 exit_claws(static_mainwindow);
1652 void app_will_exit(GtkWidget *widget, gpointer data)
1654 MainWindow *mainwin = data;
1656 if (sc_exiting == TRUE) {
1657 debug_print("exit pending\n");
1661 debug_print("exiting\n");
1662 if (compose_get_compose_list()) {
1663 if (!draft_all_messages()) {
1664 main_window_popup(mainwin);
1670 if (prefs_common.warn_queued_on_exit && procmsg_have_queued_mails_fast()) {
1671 if (alertpanel(_("Queued messages"),
1672 _("Some unsent messages are queued. Exit now?"),
1673 GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL)
1674 != G_ALERTALTERNATE) {
1675 main_window_popup(mainwin);
1679 manage_window_focus_in(mainwin->window, NULL, NULL);
1683 #ifdef HAVE_VALGRIND
1684 if (RUNNING_ON_VALGRIND) {
1685 summary_clear_list(mainwin->summaryview);
1688 if (folderview_get_selected_item(mainwin->folderview))
1689 folder_item_close(folderview_get_selected_item(mainwin->folderview));
1693 gboolean claws_is_exiting(void)
1698 gboolean claws_is_starting(void)
1704 * CLAWS: want this public so crash dialog can delete the
1707 gchar *claws_get_socket_name(void)
1709 static gchar *filename = NULL;
1711 if (filename == NULL) {
1712 filename = g_strdup_printf("%s%cclaws-mail-%d",
1713 g_get_tmp_dir(), G_DIR_SEPARATOR,
1724 static gchar *get_crashfile_name(void)
1726 static gchar *filename = NULL;
1728 if (filename == NULL) {
1729 filename = g_strdup_printf("%s%cclaws-crashed",
1730 get_tmp_dir(), G_DIR_SEPARATOR);
1736 static gint prohibit_duplicate_launch(void)
1741 path = claws_get_socket_name();
1742 uxsock = fd_connect_unix(path);
1744 if (x_display == NULL)
1745 x_display = g_strdup(g_getenv("DISPLAY"));
1749 return fd_open_unix(path);
1752 /* remote command mode */
1754 debug_print("another Claws Mail instance is already running.\n");
1756 if (cmd.receive_all) {
1757 fd_write_all(uxsock, "receive_all\n", 12);
1758 } else if (cmd.receive) {
1759 fd_write_all(uxsock, "receive\n", 8);
1760 } else if (cmd.compose && cmd.attach_files) {
1761 gchar *str, *compose_str;
1764 if (cmd.compose_mailto) {
1765 compose_str = g_strdup_printf("compose_attach %s\n",
1766 cmd.compose_mailto);
1768 compose_str = g_strdup("compose_attach\n");
1771 fd_write_all(uxsock, compose_str, strlen(compose_str));
1772 g_free(compose_str);
1774 for (i = 0; i < cmd.attach_files->len; i++) {
1775 str = g_ptr_array_index(cmd.attach_files, i);
1776 fd_write_all(uxsock, str, strlen(str));
1777 fd_write_all(uxsock, "\n", 1);
1780 fd_write_all(uxsock, ".\n", 2);
1781 } else if (cmd.compose) {
1784 if (cmd.compose_mailto) {
1785 compose_str = g_strdup_printf
1786 ("compose %s\n", cmd.compose_mailto);
1788 compose_str = g_strdup("compose\n");
1791 fd_write_all(uxsock, compose_str, strlen(compose_str));
1792 g_free(compose_str);
1793 } else if (cmd.subscribe) {
1794 gchar *str = g_strdup_printf("subscribe %s\n", cmd.subscribe_uri);
1795 fd_write_all(uxsock, str, strlen(str));
1797 } else if (cmd.send) {
1798 fd_write_all(uxsock, "send\n", 5);
1799 } else if (cmd.online_mode == ONLINE_MODE_ONLINE) {
1800 fd_write(uxsock, "online\n", 6);
1801 } else if (cmd.online_mode == ONLINE_MODE_OFFLINE) {
1802 fd_write(uxsock, "offline\n", 7);
1803 } else if (cmd.status || cmd.status_full) {
1804 gchar buf[BUFFSIZE];
1806 const gchar *command;
1810 command = cmd.status_full ? "status-full\n" : "status\n";
1811 folders = cmd.status_full ? cmd.status_full_folders :
1814 fd_write_all(uxsock, command, strlen(command));
1815 for (i = 0; folders && i < folders->len; ++i) {
1816 folder = g_ptr_array_index(folders, i);
1817 fd_write_all(uxsock, folder, strlen(folder));
1818 fd_write_all(uxsock, "\n", 1);
1820 fd_write_all(uxsock, ".\n", 2);
1822 fd_gets(uxsock, buf, sizeof(buf));
1823 if (!strncmp(buf, ".\n", 2)) break;
1826 } else if (cmd.exit) {
1827 fd_write_all(uxsock, "exit\n", 5);
1828 } else if (cmd.target) {
1829 gchar *str = g_strdup_printf("select %s\n", cmd.target);
1830 fd_write_all(uxsock, str, strlen(str));
1834 fd_write_all(uxsock, "get_display\n", 12);
1835 memset(buf, 0, sizeof(buf));
1836 fd_gets(uxsock, buf, sizeof(buf));
1837 if (strcmp2(buf, x_display)) {
1838 g_print("Claws Mail is already running on display %s.\n",
1842 uxsock = fd_connect_unix(path);
1843 fd_write_all(uxsock, "popup\n", 6);
1851 static gint lock_socket_remove(void)
1856 if (lock_socket < 0) {
1860 if (lock_socket_tag > 0) {
1861 gdk_input_remove(lock_socket_tag);
1863 fd_close(lock_socket);
1864 filename = claws_get_socket_name();
1871 static GPtrArray *get_folder_item_list(gint sock)
1873 gchar buf[BUFFSIZE];
1875 GPtrArray *folders = NULL;
1878 fd_gets(sock, buf, sizeof(buf));
1879 if (!strncmp(buf, ".\n", 2)) {
1884 folders = g_ptr_array_new();
1886 item = folder_find_item_from_identifier(buf);
1888 g_ptr_array_add(folders, item);
1890 g_warning("no such folder: %s\n", buf);
1897 static void lock_socket_input_cb(gpointer data,
1899 GdkInputCondition condition)
1901 MainWindow *mainwin = (MainWindow *)data;
1903 gchar buf[BUFFSIZE];
1905 sock = fd_accept(source);
1906 fd_gets(sock, buf, sizeof(buf));
1908 if (!strncmp(buf, "popup", 5)) {
1909 main_window_popup(mainwin);
1910 } else if (!strncmp(buf, "get_display", 11)) {
1911 fd_write_all(sock, x_display, strlen(x_display));
1912 } else if (!strncmp(buf, "receive_all", 11)) {
1913 inc_all_account_mail(mainwin, FALSE,
1914 prefs_common.newmail_notify_manu);
1915 } else if (!strncmp(buf, "receive", 7)) {
1916 inc_mail(mainwin, prefs_common.newmail_notify_manu);
1917 } else if (!strncmp(buf, "compose_attach", 14)) {
1921 mailto = g_strdup(buf + strlen("compose_attach") + 1);
1922 files = g_ptr_array_new();
1923 while (fd_gets(sock, buf, sizeof(buf)) > 0) {
1924 if (buf[0] == '.' && buf[1] == '\n') {
1928 g_ptr_array_add(files, g_strdup(buf));
1930 open_compose_new(mailto, files);
1931 ptr_array_free_strings(files);
1932 g_ptr_array_free(files, TRUE);
1934 } else if (!strncmp(buf, "compose", 7)) {
1935 open_compose_new(buf + strlen("compose") + 1, NULL);
1936 } else if (!strncmp(buf, "subscribe", 9)) {
1937 main_window_popup(mainwin);
1938 folder_subscribe(buf + strlen("subscribe") + 1);
1939 } else if (!strncmp(buf, "send", 4)) {
1941 } else if (!strncmp(buf, "online", 6)) {
1942 main_window_toggle_work_offline(mainwin, FALSE, FALSE);
1943 } else if (!strncmp(buf, "offline", 7)) {
1944 main_window_toggle_work_offline(mainwin, TRUE, FALSE);
1945 } else if (!strncmp(buf, "status-full", 11) ||
1946 !strncmp(buf, "status", 6)) {
1950 folders = get_folder_item_list(sock);
1951 status = folder_get_status
1952 (folders, !strncmp(buf, "status-full", 11));
1953 fd_write_all(sock, status, strlen(status));
1954 fd_write_all(sock, ".\n", 2);
1956 if (folders) g_ptr_array_free(folders, TRUE);
1957 } else if (!strncmp(buf, "select ", 7)) {
1958 const gchar *target = buf+7;
1959 mainwindow_jump_to(target, TRUE);
1960 } else if (!strncmp(buf, "exit", 4)) {
1961 app_will_exit(NULL, mainwin);
1967 static void open_compose_new(const gchar *address, GPtrArray *attach_files)
1972 Xstrdup_a(addr, address, return);
1976 compose_new(NULL, addr, attach_files);
1979 static void send_queue(void)
1982 gchar *errstr = NULL;
1983 gboolean error = FALSE;
1984 for (list = folder_get_list(); list != NULL; list = list->next) {
1985 Folder *folder = list->data;
1987 if (folder->queue) {
1988 gint res = procmsg_send_queue
1989 (folder->queue, prefs_common.savemsg,
1993 folder_item_scan(folder->queue);
2001 alertpanel_error_log(_("Some errors occurred "
2002 "while sending queued messages:\n%s"), errstr);
2005 alertpanel_error_log("Some errors occurred "
2006 "while sending queued messages.");
2010 static void quit_signal_handler(int sig)
2012 debug_print("Quitting on signal %d\n", sig);
2014 g_timeout_add(0, clean_quit, NULL);
2017 static void install_basic_sighandlers()
2021 struct sigaction act;
2026 sigaddset(&mask, SIGTERM);
2029 sigaddset(&mask, SIGINT);
2032 sigaddset(&mask, SIGHUP);
2035 act.sa_handler = quit_signal_handler;
2040 sigaction(SIGTERM, &act, 0);
2043 sigaction(SIGINT, &act, 0);
2046 sigaction(SIGHUP, &act, 0);
2049 sigprocmask(SIG_UNBLOCK, &mask, 0);
2050 #endif /* !G_OS_WIN32 */
2054 HildonProgram *hildon_program(void)
2056 return static_hildonprogram;
2058 osso_context_t *get_osso_context(void)
2060 return static_osso_context;