#include <X11/SM/SMlib.h>
#endif
+#if HAVE_FLOCK
+#include <sys/file.h>
+#endif
+
#include "wizard.h"
#ifdef HAVE_STARTUP_NOTIFICATION
# define SN_API_NOT_YET_FROZEN
#include "account.h"
#include "procmsg.h"
#include "inc.h"
+#include "imap.h"
#include "import.h"
#include "manage_window.h"
#include "alertpanel.h"
#include "hooks.h"
#include "menu.h"
#include "quicksearch.h"
+#include "advsearch.h"
#ifdef HAVE_LIBETPAN
#include "imap-thread.h"
static struct RemoteCmd {
gboolean receive;
gboolean receive_all;
+ gboolean cancel_receiving;
+ gboolean cancel_sending;
gboolean compose;
const gchar *compose_mailto;
GList *attach_files;
inc_all_account_mail(static_mainwindow, autochk,
prefs_common.newmail_notify_manu);
+ /* Accounts using a specific timer need to be checked separately
+ * at startup
+ */
+ inc_all_account_spec_timer_check_mail();
+
if (sc_starting) {
sc_starting = FALSE;
main_window_set_menu_sensitive(static_mainwindow);
if (status == IceProcessMessagesIOError) {
IcePointer context = IceGetConnectionContext (connection);
- if (context && GTK_IS_OBJECT (context)) {
+ if (context && G_IS_OBJECT(context)) {
guint disconnect_id = g_signal_lookup ("disconnect", G_OBJECT_TYPE (context));
if (disconnect_id > 0)
#ifdef CRASH_DIALOG
if (cmd.crash) {
+#if !GTK_CHECK_VERSION(3, 0, 0)
gtk_set_locale();
+#endif
gtk_init(&argc, &argv);
crash_main(cmd.crash_params);
#ifdef G_OS_WIN32
#endif
if (cmd.status || cmd.status_full || cmd.search ||
- cmd.statistics || cmd.reset_statistics) {
+ cmd.statistics || cmd.reset_statistics ||
+ cmd.cancel_receiving || cmd.cancel_sending) {
puts("0 Claws Mail not running.");
lock_socket_remove();
return 0;
reset_statistics();
+#if !GTK_CHECK_VERSION(3, 0, 0)
gtk_set_locale();
+#endif
gtk_init(&argc, &argv);
#ifdef G_OS_WIN32
hildon_program = HILDON_PROGRAM(hildon_program_get_instance());
static_osso_context = osso_context;
#endif
+#if !GTK_CHECK_VERSION(3, 0, 0)
gtk_widget_set_default_colormap(
gdk_screen_get_system_colormap(
gdk_screen_get_default()));
+#endif
gtkut_create_ui_manager();
prefs_receive_init();
prefs_send_init();
tags_read_tags();
+ matcher_init();
#ifdef USE_ENCHANT
gtkaspell_checkers_init();
prefs_spelling_init();
gtk_cmclist_freeze(GTK_CMCLIST(mainwin->folderview->ctree));
folder_item_update_freeze();
- /* register the callback of unix domain socket input */
- lock_socket_tag = claws_input_add(lock_socket,
- G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI,
- lock_socket_input_cb,
- mainwin, TRUE);
-
-
prefs_account_init();
account_read_config_all();
main_window_set_menu_sensitive(mainwin);
toolbar_main_set_sensitive(mainwin);
}
+
+ /* register the callback of unix domain socket input */
+ lock_socket_tag = claws_input_add(lock_socket,
+ G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI,
+ lock_socket_input_cb,
+ mainwin, TRUE);
+
END_TIMING();
gtk_main();
plugin_unload_all("GTK2");
+ matcher_done();
prefs_toolbar_done();
#ifndef USE_NEW_ADDRBOOK
cmd.receive_all = TRUE;
} else if (!strncmp(argv[i], "--receive", 9)) {
cmd.receive = TRUE;
+ } else if (!strncmp(argv[i], "--cancel-receiving", 18)) {
+ cmd.cancel_receiving = TRUE;
+ } else if (!strncmp(argv[i], "--cancel-sending", 16)) {
+ cmd.cancel_sending = TRUE;
} else if (!strncmp(argv[i], "--compose-from-file", 19)) {
const gchar *p = (i+1 < argc)?argv[i+1]:NULL;
" attached"));
g_print("%s\n", _(" --receive receive new messages"));
g_print("%s\n", _(" --receive-all receive new messages of all accounts"));
+ g_print("%s\n", _(" --cancel-receiving cancel receiving of messages"));
+ g_print("%s\n", _(" --cancel-sending cancel sending of messages"));
g_print("%s\n", _(" --search folder type request [recursive]\n"
" searches mail\n"
" folder ex.: \"#mh/Mailbox/inbox\" or \"Mail\"\n"
gchar *path;
path = claws_get_socket_name();
+ /* Try to connect to the control socket */
uxsock = fd_connect_unix(path);
if (x_display == NULL)
x_display = g_strdup(g_getenv("DISPLAY"));
if (uxsock < 0) {
+#if HAVE_FLOCK
+ gchar *socket_lock;
+ gint lock_fd;
+ gint ret;
+ /* If connect failed, no other process is running.
+ * Unlink the potentially existing socket, then
+ * open it. This has to be done locking a temporary
+ * file to avoid the race condition where another
+ * process could have created the socket just in
+ * between.
+ */
+ socket_lock = g_strconcat(path, ".lock",
+ NULL);
+ lock_fd = g_open(socket_lock, O_RDWR|O_CREAT, 0);
+ if (lock_fd < 0) {
+ debug_print("Couldn't open %s: %s (%d)\n", socket_lock,
+ strerror(errno), errno);
+ g_free(socket_lock);
+ return -1;
+ }
+ if (flock(lock_fd, LOCK_EX) < 0) {
+ debug_print("Couldn't lock %s: %s (%d)\n", socket_lock,
+ strerror(errno), errno);
+ close(lock_fd);
+ g_free(socket_lock);
+ return -1;
+ }
+#endif
+
claws_unlink(path);
- return fd_open_unix(path);
+ debug_print("Opening socket %s\n", path);
+ ret = fd_open_unix(path);
+#if HAVE_FLOCK
+ flock(lock_fd, LOCK_UN);
+ claws_unlink(socket_lock);
+ g_free(socket_lock);
+#endif
+ return ret;
}
#else
HANDLE hmutex;
fd_write_all(uxsock, "receive_all\n", 12);
} else if (cmd.receive) {
fd_write_all(uxsock, "receive\n", 8);
+ } else if (cmd.cancel_receiving) {
+ fd_write_all(uxsock, "cancel_receiving\n", 17);
+ } else if (cmd.cancel_sending) {
+ fd_write_all(uxsock, "cancel_sending\n", 15);
} else if (cmd.compose && cmd.attach_files) {
gchar *str, *compose_str;
MainWindow *mainwin = (MainWindow *)data;
gint sock;
gchar buf[BUFFSIZE];
- /* re-use the same quicksearch (& avoid matcher_list mem.leaks) */
- static QuickSearch *quicksearch = NULL;
sock = fd_accept(source);
fd_gets(sock, buf, sizeof(buf));
prefs_common.newmail_notify_manu);
} else if (!strncmp(buf, "receive", 7)) {
inc_mail(mainwin, prefs_common.newmail_notify_manu);
+ } else if (!strncmp(buf, "cancel_receiving", 16)) {
+ inc_cancel_all();
+ imap_cancel_all();
+ } else if (!strncmp(buf, "cancel_sending", 14)) {
+ send_cancel();
} else if (!strncmp(buf, "compose_attach", 14)) {
GList *files = NULL, *curr;
AttachInfo *ainfo;
} else if (!strncmp(buf, "search ", 7)) {
FolderItem* folderItem = NULL;
GSList *messages = NULL;
- gchar *folder_name, *request;
- QuickSearchType searchType = QUICK_SEARCH_EXTENDED;
+ gchar *folder_name = NULL;
+ gchar *request = NULL;
+ AdvancedSearch *search;
gboolean recursive;
-
- if (quicksearch==NULL)
- quicksearch = quicksearch_new_nogui();
+ AdvancedSearchType searchType = ADVANCED_SEARCH_EXTENDED;
+ search = advsearch_new();
+
folder_name = g_strdup(buf+7);
strretchomp(folder_name);
- if (fd_gets(sock, buf, sizeof(buf)) <= 0) {
- g_free(folder_name);
- folder_name=NULL;
- }
- searchType = quicksearch_type(buf);
- if (fd_gets(sock, buf, sizeof(buf)) <= 0) {
- g_free(folder_name);
- folder_name=NULL;
+ if (fd_gets(sock, buf, sizeof(buf)) <= 0)
+ goto search_exit;
+
+ switch (toupper(buf[0])) {
+ case 'S': searchType = ADVANCED_SEARCH_SUBJECT; break;
+ case 'F': searchType = ADVANCED_SEARCH_FROM; break;
+ case 'T': searchType = ADVANCED_SEARCH_TO; break;
+ case 'M': searchType = ADVANCED_SEARCH_MIXED; break;
+ case 'G': searchType = ADVANCED_SEARCH_TAG; break;
+ case 'E': searchType = ADVANCED_SEARCH_EXTENDED; break;
}
+
+ if (fd_gets(sock, buf, sizeof(buf)) <= 0)
+ goto search_exit;
+
request = g_strdup(buf);
strretchomp(request);
recursive = TRUE;
if (fd_gets(sock, buf, sizeof(buf)) > 0)
- if (buf[0]=='0')
- recursive = FALSE;
+ recursive = buf[0] != '0';
- debug_print("search: %s %i %s %i\n",folder_name,searchType,request,recursive);
+ debug_print("search: %s %i %s %i\n", folder_name, searchType, request, recursive);
if (folder_name)
folderItem = folder_find_item_from_identifier(folder_name);
+
if (folder_name && folderItem == NULL) {
debug_print("Unknown folder item : '%s', searching folder\n",folder_name);
Folder* folder = folder_find_from_path(folder_name);
} else {
debug_print("%s %s\n",folderItem->name, folderItem->path);
}
+
if (folderItem != NULL) {
- quicksearch_set(quicksearch, searchType, request);
- quicksearch_set_recursive(quicksearch, recursive);
- search_msgs_in_folders(&messages, quicksearch, folderItem);
+ advsearch_set(search, searchType, request);
+ advsearch_search_msgs_in_folders(search, &messages, folderItem, recursive);
} else {
g_print("Folder '%s' not found.\n'", folder_name);
}
GSList *cur;
- for (cur=messages; cur != NULL; cur = cur->next) {
+ for (cur = messages; cur != NULL; cur = cur->next) {
MsgInfo* msg = (MsgInfo *)cur->data;
gchar *file = procmsg_get_message_file_path(msg);
fd_write_all(sock, file, strlen(file));
}
fd_write_all(sock, ".\n", 2);
- if (messages != NULL)
- procmsg_msg_list_free(messages);
+search_exit:
g_free(folder_name);
g_free(request);
+ advsearch_free(search);
+ if (messages != NULL)
+ procmsg_msg_list_free(messages);
} else if (!strncmp(buf, "exit", 4)) {
if (prefs_common.clean_on_exit && !prefs_common.ask_on_clean) {
procmsg_empty_all_trash();