#include <tny-list.h>
#include <tny-iterator.h>
#include <tny-simple-list.h>
-
-#include <libmodest-dbus-client/libmodest-dbus-client.h>
+#include <tny-camel-imap-store-account.h>
+#include <tny-camel-pop-store-account.h>
#include "modest-text-utils.h"
#include "modest-account-mgr.h"
#include "modest-tny-account-store.h"
#include "modest-tny-account.h"
+#include "modest-tny-mime-part.h"
+#include "modest-tny-folder.h"
#include "modest-search.h"
#include "modest-runtime.h"
+#include "modest-platform.h"
+
+typedef struct
+{
+ guint pending_calls;
+ GList *msg_hits;
+ ModestSearch *search;
+ ModestSearchCallback callback;
+ gpointer user_data;
+ TnyList *all_folders;
+} SearchHelper;
+
+static SearchHelper *create_helper (ModestSearchCallback callback,
+ ModestSearch *search,
+ gpointer user_data);
+
+static void _search_folder (TnyFolder *folder,
+ SearchHelper *helper);
static gchar *
g_strdup_or_null (const gchar *str)
return string;
}
-typedef struct
-{
- GMainLoop* loop;
- TnyAccount *account;
- gboolean is_online;
- gint count_tries;
-} UtilIdleData;
-
-#define NUMBER_OF_TRIES 10 /* Try approx every second, ten times. */
-
-static gboolean
-on_timeout_check_account_is_online(gpointer user_data)
-{
- printf ("DEBUG: %s:\n", __FUNCTION__);
- UtilIdleData *data = (UtilIdleData*)user_data;
-
- if (!data) {
- g_warning ("%s: data is NULL.\n", __FUNCTION__);
- }
-
- if (!(data->account)) {
- g_warning ("%s: data->account is NULL.\n", __FUNCTION__);
- }
-
- if (data && data->account) {
- printf ("DEBUG: %s: tny_account_get_connection_status()==%d\n", __FUNCTION__, tny_account_get_connection_status (data->account));
- }
-
- gboolean stop_trying = FALSE;
- if (data && data->account &&
- (tny_account_get_connection_status (data->account) == TNY_CONNECTION_STATUS_CONNECTED) )
- {
- data->is_online = TRUE;
-
- stop_trying = TRUE;
- }
- else {
- /* Give up if we have tried too many times: */
- if (data->count_tries >= NUMBER_OF_TRIES)
- {
- stop_trying = TRUE;
- }
- else {
- /* Wait for another timeout: */
- ++(data->count_tries);
- }
- }
-
- if (stop_trying) {
- /* Allow the function that requested this idle callback to continue: */
- if (data->loop)
- g_main_loop_quit (data->loop);
-
- if (data->account)
- g_object_unref (data->account);
-
- return FALSE; /* Don't call this again. */
- } else {
- return TRUE; /* Call this timeout callback again. */
- }
-}
-
-/* Return TRUE immediately if the account is already online,
- * otherwise check every second for NUMBER_OF_TRIES seconds and return TRUE as
- * soon as the account is online, or FALSE if the account does
- * not become online in the NUMBER_OF_TRIES seconds.
- * This is useful when the D-Bus method was run immediately after
- * the application was started (when using D-Bus activation),
- * because the account usually takes a short time to go online.
- * The return value is maybe not very useful.
- */
-static gboolean
-check_and_wait_for_account_is_online(TnyAccount *account)
-{
- g_return_val_if_fail (account, FALSE);
-
- printf ("DEBUG: %s: account id=%s\n", __FUNCTION__, tny_account_get_id (account));
-
- if (!tny_device_is_online (modest_runtime_get_device())) {
- printf ("DEBUG: %s: device is offline.\n", __FUNCTION__);
- return FALSE;
- }
-
- printf ("DEBUG: %s: tny_account_get_connection_status()==%d\n", __FUNCTION__, tny_account_get_connection_status (account));
-
- /* TODO: The local_folders account never seems to leave TNY_CONNECTION_STATUS_INIT,
- * so we wait unnecessarily,
- * but that enum value isn't enough to get a message list from POP and IMAP. */
- if (tny_account_get_connection_status (account) == TNY_CONNECTION_STATUS_CONNECTED)
- return TRUE;
-
- /* This blocks on the result: */
- UtilIdleData *data = g_slice_new0 (UtilIdleData);
- data->is_online = FALSE;
- data->account = account;
- g_object_ref (data->account);
- data->count_tries = 0;
-
- GMainContext *context = NULL; /* g_main_context_new (); */
- data->loop = g_main_loop_new (context, FALSE /* not running */);
-
- g_timeout_add (1000, &on_timeout_check_account_is_online, data);
-
- /* This main loop will run until the idle handler has stopped it: */
- g_main_loop_run (data->loop);
-
- g_main_loop_unref (data->loop);
- /* g_main_context_unref (context); */
-
- g_slice_free (UtilIdleData, data);
-
- return data->is_online;
-}
-
static GList*
add_hit (GList *list, TnyHeader *header, TnyFolder *folder)
{
- ModestSearchHit *hit;
+ ModestSearchResultHit *hit;
TnyHeaderFlags flags;
char *furl;
char *msg_url;
- const char *uid;
- const char *subject;
- const char *sender;
+ char *uid;
+ char *subject;
+ char *sender;
- hit = g_slice_new0 (ModestSearchHit);
+ hit = g_slice_new0 (ModestSearchResultHit);
furl = tny_folder_get_url_string (folder);
- printf ("DEBUG: %s: folder URL=%s\n", __FUNCTION__, furl);
+ g_debug ("%s: folder URL=%s\n", __FUNCTION__, furl);
if (!furl) {
g_warning ("%s: tny_folder_get_url_string(): returned NULL for folder. Folder name=%s\n", __FUNCTION__, tny_folder_get_name (folder));
}
* and/or find out what UID form is used when finding, in camel_data_cache_get().
* so we can find what we get. Philip is working on this.
*/
- uid = tny_header_get_uid (header);
- if (!furl) {
- g_warning ("%s: tny_header_get_uid(): returned NULL for message with subject=%s\n", __FUNCTION__, tny_header_get_subject (header));
+ uid = tny_header_dup_uid (header);
+ if (!uid) {
+ gchar *subject = tny_header_dup_subject (header);
+ g_warning ("%s: tny_header_get_uid(): returned NULL for message with subject=%s\n", __FUNCTION__, subject);
+ g_free (subject);
}
msg_url = g_strdup_printf ("%s/%s", furl, uid);
g_free (furl);
+ g_free (uid);
- subject = tny_header_get_subject (header);
- sender = tny_header_get_from (header);
+ subject = tny_header_dup_subject (header);
+ sender = tny_header_dup_from (header);
flags = tny_header_get_flags (header);
hit->msgid = msg_url;
- hit->subject = g_strdup_or_null (subject);
- hit->sender = g_strdup_or_null (sender);
+ hit->subject = subject;
+ hit->sender = sender;
hit->folder = g_strdup_or_null (tny_folder_get_name (folder));
hit->msize = tny_header_get_message_size (header);
hit->has_attachment = flags & TNY_HEADER_FLAG_ATTACHMENTS;
hit->is_unread = ! (flags & TNY_HEADER_FLAG_SEEN);
- hit->timestamp = tny_header_get_date_received (header);
+ hit->timestamp = MIN (tny_header_get_date_received (header), tny_header_get_date_sent (header));
return g_list_prepend (list, hit);
}
}
#ifdef MODEST_HAVE_OGS
+/*
+ * This function assumes that the mime part is of type "text / *"
+ */
static gboolean
search_mime_part_ogs (TnyMimePart *part, ModestSearch *search)
{
gboolean is_text_html = FALSE;
gboolean found = FALSE;
gboolean res = FALSE;
-
- gboolean is_text = tny_mime_part_content_type_is (part, "text/*");
- if (!is_text) {
- g_debug ("%s: tny_mime_part_content_type_is() failed to find a "
- "text/* MIME part. Content type is %s",
- __FUNCTION__, "Unknown (calling tny_mime_part_get_content_type(part) causes a deadlock)");
-
- /* Retry with specific MIME types, because the wildcard seems to fail
- * in tinymail.
- * Actually I'm not sure anymore that it fails, so we could probalby
- * remove this later: murrayc */
- is_text = (
- tny_mime_part_content_type_is (part, "text/plain") ||
- tny_mime_part_content_type_is (part, "text/html") );
-
- if (is_text) {
- g_debug ("%s: Retryting with text/plain or text/html succeeded",
- __FUNCTION__);
- }
- }
-
- if (!is_text) {
- return FALSE;
- }
is_text_html = tny_mime_part_content_type_is (part, "text/html");
/* search->text_searcher was instantiated in modest_search_folder(). */
if (is_text_html) {
-
found = ogs_text_searcher_search_html (search->text_searcher,
buffer,
nread,
nread);
}
+ /* HACK: this helps UI refreshes because the search
+ operations could be heavy */
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
if (found) {
break;
}
nread = 0;
res = read_chunk (stream, buffer, len, &nread);
}
+ g_object_unref (stream);
if (!found) {
found = ogs_text_searcher_search_done (search->text_searcher);
}
ogs_text_searcher_reset (search->text_searcher);
-
- /* debug stuff:
- if (!found) {
- buffer[len -1] = 0;
- printf ("DEBUG: %s: query %s was not found in message text: %s\n",
- __FUNCTION__, search->query, buffer);
-
- } else {
- printf ("DEBUG: %s: found.\n", __FUNCTION__);
- }
- */
return found;
}
#else
+/*
+ * This function assumes that the mime part is of type "text / *"
+ */
static gboolean
search_mime_part_strcmp (TnyMimePart *part, ModestSearch *search)
{
gboolean found;
gboolean res;
- if (! tny_mime_part_content_type_is (part, "text/*")) {
- g_debug ("%s: No text MIME part found.\n", __FUNCTION__);
- return FALSE;
- }
-
found = FALSE;
len = (sizeof (buffer) - 1) / 2;
if (strlen (search->body) > len) {
- g_warning ("Search term bigger then chunk."
- "We might not find everything");
+ g_debug ("Search term bigger then chunk."
+ "We might not find everything");
}
stream = tny_mime_part_get_stream (part);
buffer,
TRUE);
- if (found) {
+ /* HACK: this helps UI refreshes because the search
+ operations could be heavy */
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ if ((found)||(nread == 0)) {
break;
}
const char *where,
ModestSearch *search)
{
- gboolean found;
+ gboolean found = FALSE;
#ifdef MODEST_HAVE_OGS
if (search->flags & MODEST_SEARCH_USE_OGS) {
found = ogs_text_searcher_search_text (search->text_searcher,
#ifdef MODEST_HAVE_OGS
}
#endif
+
+ /* HACK: this helps UI refreshes because the search
+ operations could be heavy */
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
return found;
}
-static gboolean search_mime_part_and_child_parts (TnyMimePart *part, ModestSearch *search)
+static gboolean
+search_mime_part_and_child_parts (TnyMimePart *part, ModestSearch *search)
{
gboolean found = FALSE;
+
+ /* Do not search into attachments */
+ if (modest_tny_mime_part_is_attachment_for_modest (part) && !TNY_IS_MSG (part))
+ return FALSE;
+
#ifdef MODEST_HAVE_OGS
found = search_mime_part_ogs (part, search);
#else
return found;
}
-/**
- * modest_search:
- * @folder: a #TnyFolder instance
- * @search: a #ModestSearch query
- *
- * This operation will search @folder for headers that match the query @search,
- * if the folder itself matches the query.
- * It will return a doubly linked list with URIs that point to the message.
- **/
-GList *
-modest_search_folder (TnyFolder *folder, ModestSearch *search)
+static void
+search_next_folder (SearchHelper *helper)
{
- /* Check that we should be searching this folder. */
- /* Note that we don't try to search sub-folders.
- * Maybe we should, but that should be specified. */
- if (search->folder && strlen (search->folder) && (strcmp (tny_folder_get_id (folder), search->folder) != 0))
- return NULL;
+ TnyIterator *iter = tny_list_create_iterator (helper->all_folders);
+ TnyFolder *first = TNY_FOLDER (tny_iterator_get_current (iter));
- GList *retval = NULL;
+ _search_folder (first, helper);
+
+ g_object_unref (first);
+ g_object_unref (iter);
+}
+
+static void
+modest_search_folder_get_headers_cb (TnyFolder *folder,
+ gboolean cancelled,
+ TnyList *headers,
+ GError *err,
+ gpointer user_data)
+{
TnyIterator *iter = NULL;
- TnyList *list = NULL;
-
-#ifdef MODEST_HAVE_OGS
- if (search->flags & MODEST_SEARCH_USE_OGS) {
-
- if (search->text_searcher == NULL && search->query != NULL) {
- OgsTextSearcher *text_searcher;
+ SearchHelper *helper;
- text_searcher = ogs_text_searcher_new (FALSE);
- ogs_text_searcher_parse_query (text_searcher, search->query);
- search->text_searcher = text_searcher;
- }
- }
-#endif
+ helper = (SearchHelper *) user_data;
- list = tny_simple_list_new ();
- GError *error = NULL;
- tny_folder_get_headers (folder, list, FALSE /* don't refresh */, &error);
- if (error) {
- g_warning ("%s: tny_folder_get_headers() failed with error=%s.\n",
- __FUNCTION__, error->message);
- g_error_free (error);
- error = NULL;
+ if (err || cancelled) {
+ goto end;
}
- iter = tny_list_create_iterator (list);
+ iter = tny_list_create_iterator (headers);
while (!tny_iterator_is_done (iter)) {
- TnyHeader *cur = (TnyHeader *) tny_iterator_get_current (iter);
- const time_t t = tny_header_get_date_sent (cur);
- gboolean found = FALSE;
-
+
+ TnyHeader *cur;
+ time_t t;
+ gboolean found;
+
+ cur = (TnyHeader *) tny_iterator_get_current (iter);
+ t = tny_header_get_date_sent (cur);
+ found = FALSE;
+
/* Ignore deleted (not yet expunged) emails: */
if (tny_header_get_flags(cur) & TNY_HEADER_FLAG_DELETED)
goto go_next;
-
- if (search->flags & MODEST_SEARCH_BEFORE)
- if (!(t <= search->end_date))
+
+ if (helper->search->flags & MODEST_SEARCH_BEFORE)
+ if (!(t <= helper->search->end_date))
goto go_next;
- if (search->flags & MODEST_SEARCH_AFTER)
- if (!(t >= search->start_date))
+ if (helper->search->flags & MODEST_SEARCH_AFTER)
+ if (!(t >= helper->search->start_date))
goto go_next;
- if (search->flags & MODEST_SEARCH_SIZE)
- if (tny_header_get_message_size (cur) < search->minsize)
+ if (helper->search->flags & MODEST_SEARCH_SIZE)
+ if (tny_header_get_message_size (cur) < helper->search->minsize)
goto go_next;
- if (search->flags & MODEST_SEARCH_SUBJECT) {
- const char *str = tny_header_get_subject (cur);
+ if (helper->search->flags & MODEST_SEARCH_SUBJECT) {
+ char *str = tny_header_dup_subject (cur);
- if ((found = search_string (search->subject, str, search))) {
- retval = add_hit (retval, cur, folder);
+ if ((found = search_string (helper->search->subject, str, helper->search))) {
+ helper->msg_hits = add_hit (helper->msg_hits, cur, folder);
}
+ g_free (str);
}
- if (!found && search->flags & MODEST_SEARCH_SENDER) {
- char *str = g_strdup (tny_header_get_from (cur));
+ if (!found && helper->search->flags & MODEST_SEARCH_SENDER) {
+ char *str = tny_header_dup_from (cur);
- if ((found = search_string (search->from, (const gchar *) str, search))) {
- retval = add_hit (retval, cur, folder);
+ if ((found = search_string (helper->search->from, (const gchar *) str, helper->search))) {
+ helper->msg_hits = add_hit (helper->msg_hits, cur, folder);
}
g_free (str);
}
- if (!found && search->flags & MODEST_SEARCH_RECIPIENT) {
- const char *str = tny_header_get_to (cur);
+ if (!found && helper->search->flags & MODEST_SEARCH_RECIPIENT) {
+ char *str = tny_header_dup_to (cur);
- if ((found = search_string (search->recipient, str, search))) {
- retval = add_hit (retval, cur, folder);
+ if ((found = search_string (helper->search->recipient, str, helper->search))) {
+ helper->msg_hits = add_hit (helper->msg_hits, cur, folder);
}
+ g_free (str);
}
- if (!found && search->flags & MODEST_SEARCH_BODY) {
+ if (!found && helper->search->flags & MODEST_SEARCH_BODY) {
TnyHeaderFlags flags;
GError *err = NULL;
TnyMsg *msg = NULL;
g_object_unref (msg);
}
} else {
+ gchar *str;
+ str = tny_header_dup_subject (cur);
+ g_debug ("Searching in %s\n", str);
+ g_free (str);
- found = search_mime_part_and_child_parts (TNY_MIME_PART (msg),
- search);
+ found = search_mime_part_and_child_parts (TNY_MIME_PART (msg),
+ helper->search);
if (found) {
- retval = add_hit (retval, cur, folder);
+ helper->msg_hits = add_hit (helper->msg_hits, cur, folder);
}
}
if (msg)
g_object_unref (msg);
}
-
-go_next:
+ go_next:
g_object_unref (cur);
tny_iterator_next (iter);
}
+ /* Frees */
g_object_unref (iter);
- g_object_unref (list);
- return retval;
+ end:
+ if (headers)
+ g_object_unref (headers);
+
+ /* Check search finished */
+ tny_list_remove (helper->all_folders, G_OBJECT (folder));
+ if (tny_list_get_length (helper->all_folders) == 0) {
+ /* callback */
+ helper->callback (helper->msg_hits, helper->user_data);
+
+ /* free helper */
+ g_object_unref (helper->all_folders);
+ g_list_free (helper->msg_hits);
+ g_slice_free (SearchHelper, helper);
+ } else {
+ search_next_folder (helper);
+ }
}
-GList *
-modest_search_account (TnyAccount *account, ModestSearch *search)
+static void
+_search_folder (TnyFolder *folder,
+ SearchHelper *helper)
{
- TnyFolderStore *store;
- TnyIterator *iter;
- TnyList *folders;
- GList *hits;
- GError *error;
+ TnyList *list = NULL;
- error = NULL;
- hits = NULL;
+ g_debug ("%s: searching folder %s.", __FUNCTION__, tny_folder_get_name (folder));
+
+ /* Check that we should be searching this folder. */
+ /* Note that we don't try to search sub-folders.
+ * Maybe we should, but that should be specified. */
+ if (helper->search->folder && strlen (helper->search->folder)) {
+ if (!strcmp (helper->search->folder, "outbox")) {
+ if (modest_tny_folder_guess_folder_type (folder) != TNY_FOLDER_TYPE_OUTBOX) {
+ modest_search_folder_get_headers_cb (folder, TRUE, NULL, NULL, helper);
+ return;
+ }
+ } else if (strcmp (tny_folder_get_id (folder), helper->search->folder) != 0) {
+ modest_search_folder_get_headers_cb (folder, TRUE, NULL, NULL, helper);
+ return;
+ }
+ }
+
+#ifdef MODEST_HAVE_OGS
+ if (helper->search->flags & MODEST_SEARCH_USE_OGS) {
+
+ if (helper->search->text_searcher == NULL && helper->search->query != NULL) {
+ OgsTextSearcher *text_searcher;
+
+ text_searcher = ogs_text_searcher_new (FALSE);
+ ogs_text_searcher_parse_query (text_searcher, helper->search->query);
+ helper->search->text_searcher = text_searcher;
+ }
+ }
+#endif
+ list = tny_simple_list_new ();
+ /* Get the headers */
+ tny_folder_get_headers_async (folder, list, FALSE,
+ modest_search_folder_get_headers_cb,
+ NULL, helper);
+}
- store = TNY_FOLDER_STORE (account);
+void
+modest_search_folder (TnyFolder *folder,
+ ModestSearch *search,
+ ModestSearchCallback callback,
+ gpointer user_data)
+{
+ SearchHelper *helper;
- folders = tny_simple_list_new ();
- tny_folder_store_get_folders (store, folders, NULL, &error);
-
- if (error != NULL) {
- g_object_unref (folders);
- return NULL;
+ /* Create the helper */
+ helper = create_helper (callback, search, user_data);
+
+ /* Search */
+ _search_folder (folder, helper);
+}
+
+static void
+modest_search_account_get_folders_cb (TnyFolderStore *self,
+ gboolean cancelled,
+ TnyList *folders,
+ GError *err,
+ gpointer user_data)
+{
+ TnyIterator *iter;
+ SearchHelper *helper;
+
+ helper = (SearchHelper *) user_data;
+
+ if (err || cancelled) {
+ goto end;
}
+ /* IMPORTANT: We need to get the headers of the folders one by
+ one, because otherwise the get_headers_async calls are
+ often canceled. That's why we firstly retrieve all folders,
+ and then we search inside them one by one. sergio */
iter = tny_list_create_iterator (folders);
while (!tny_iterator_is_done (iter)) {
TnyFolder *folder = NULL;
- GList *res = NULL;
- folder = TNY_FOLDER (tny_iterator_get_current (iter));
- if (folder) {
- /* g_debug ("DEBUG: %s: searching folder %s.",
- __FUNCTION__, tny_folder_get_name (folder)); */
-
- res = modest_search_folder (folder, search);
-
- if (res != NULL) {
- if (hits == NULL) {
- hits = res;
- } else {
- hits = g_list_concat (hits, res);
- }
- }
-
- g_object_unref (folder);
+ /* Search into folder */
+ folder = TNY_FOLDER (tny_iterator_get_current (iter));
+ tny_list_append (helper->all_folders, G_OBJECT (folder));
+
+ /* Search into children. Could be a merge folder */
+ if (TNY_IS_FOLDER_STORE (folder)) {
+ TnyList *children = tny_simple_list_new ();
+ helper->pending_calls++;
+ tny_folder_store_get_folders_async (TNY_FOLDER_STORE (folder), children, NULL,
+ FALSE, modest_search_account_get_folders_cb,
+ NULL, helper);
}
+ g_object_unref (folder);
tny_iterator_next (iter);
}
-
g_object_unref (iter);
- g_object_unref (folders);
+ end:
+ /* Remove the "account" reference */
+ helper->pending_calls--;
+
+ if (folders)
+ g_object_unref (folders);
- /* printf ("DEBUG: %s: hits length = %d\n", __FUNCTION__, g_list_length (hits)); */
- return hits;
+ /* If there are not more folders, begin to search from the first one */
+ if (helper->pending_calls == 0) {
+ TnyIterator *iter = tny_list_create_iterator (helper->all_folders);
+ TnyFolder *first = TNY_FOLDER (tny_iterator_get_current (iter));
+
+ _search_folder (first, helper);
+
+ g_object_unref (first);
+ g_object_unref (iter);
+ }
}
-GList *
-modest_search_all_accounts (ModestSearch *search)
+static void
+_search_account (TnyAccount *account,
+ SearchHelper *helper)
+{
+ TnyList *folders = tny_simple_list_new ();
+
+ g_debug ("%s: Searching account %s", __FUNCTION__, tny_account_get_name (account));
+
+ /* Add a "reference" to the folder total. This allows the code
+ not to finalize the helper if an account is fully refreshed
+ before we get the folders of the others */
+ helper->pending_calls++;
+
+ /* Get folders */
+ tny_folder_store_get_folders_async (TNY_FOLDER_STORE (account), folders, NULL,
+ FALSE, modest_search_account_get_folders_cb,
+ NULL, helper);
+}
+
+void
+modest_search_account (TnyAccount *account,
+ ModestSearch *search,
+ ModestSearchCallback callback,
+ gpointer user_data)
+{
+ SearchHelper *helper;
+
+ /* Create the helper */
+ helper = create_helper (callback, search, user_data);
+
+ /* Search */
+ _search_account (account, helper);
+}
+
+void
+modest_search_all_accounts (ModestSearch *search,
+ ModestSearchCallback callback,
+ gpointer user_data)
{
- /* printf ("DEBUG: %s: query=%s\n", __FUNCTION__, search->query); */
ModestTnyAccountStore *astore;
- TnyList *accounts;
- TnyIterator *iter;
- GList *hits;
+ TnyList *accounts;
+ TnyIterator *iter;
+ GList *hits;
+ SearchHelper *helper;
hits = NULL;
astore = modest_runtime_get_account_store ();
accounts,
TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+ /* Create the helper */
+ helper = create_helper (callback, search, user_data);
+
+ /* Search through all accounts */
iter = tny_list_create_iterator (accounts);
while (!tny_iterator_is_done (iter)) {
TnyAccount *account = NULL;
- GList *res = NULL;
account = TNY_ACCOUNT (tny_iterator_get_current (iter));
- if (account) {
- /* g_debug ("DEBUG: %s: Searching account %s",
- __FUNCTION__, tny_account_get_name (account)); */
-
- /* Give the account time to go online if necessary,
- * for instance if this is immediately after startup,
- * after D-Bus activation: */
- check_and_wait_for_account_is_online (account);
-
- /* Search: */
- res = modest_search_account (account, search);
-
- if (res != NULL) {
- if (hits == NULL) {
- hits = res;
- } else {
- hits = g_list_concat (hits, res);
- }
- }
-
- g_object_unref (account);
- }
+ _search_account (account, helper);
+ g_object_unref (account);
tny_iterator_next (iter);
}
-
- g_object_unref (accounts);
g_object_unref (iter);
+ g_object_unref (accounts);
+}
+
+static SearchHelper *
+create_helper (ModestSearchCallback callback,
+ ModestSearch *search,
+ gpointer user_data)
+{
+ SearchHelper *helper;
- /* printf ("DEBUG: %s: end: hits length=%d\n", __FUNCTION__, g_list_length(hits)); */
- return hits;
+ helper = g_slice_new0 (SearchHelper);
+ helper->pending_calls = 0;
+ helper->search = search;
+ helper->callback = callback;
+ helper->user_data = user_data;
+ helper->msg_hits = NULL;
+ helper->all_folders = tny_simple_list_new ();
+
+ return helper;
}
+void
+modest_search_free (ModestSearch *search)
+{
+ if (search->folder)
+ g_free (search->folder);
+ if (search->subject)
+ g_free (search->subject);
+ if (search->from)
+ g_free (search->from);
+ if (search->recipient)
+ g_free (search->recipient);
+ if (search->body)
+ g_free (search->body);
+#ifdef MODEST_HAVE_OGS
+ if (search->query)
+ g_free (search->query);
+ if (search->text_searcher)
+ ogs_text_searcher_free (search->text_searcher);
+#endif
+}