#include <tny-shared.h>
#include <tny-folder.h>
+#include <tny-folder-store.h>
#include <tny-list.h>
#include <tny-iterator.h>
#include <tny-simple-list.h>
#include "modest-text-utils.h"
-
+#include "modest-account-mgr.h"
+#include "modest-tny-account-store.h"
+#include "modest-tny-account.h"
#include "modest-search.h"
-
+#include "modest-runtime.h"
static GList*
add_header (GList *list, TnyHeader *header, TnyFolder *folder)
{
- gchar *furl = tny_folder_get_url_string (folder);
- const gchar *uid = tny_header_get_uid (header);
- gchar *str = g_strdup_printf ("%s/%s", furl, uid);
- g_free (furl);
- return g_list_prepend (list, str);
+ TnyFolder *f;
+
+ /* TODO: we need this call otherwise it will crash later
+ * when we try to do that call again without having the
+ * folder around, I guess that is a bug in TinyThingy */
+ f = tny_header_get_folder (header);
+
+ return g_list_prepend (list, g_object_ref (header));
}
static gboolean
ogs_text_searcher_reset (search->text_searcher);
} else {
#endif
+ if (what == NULL || where == NULL) {
+ return FALSE;
+ }
+
found = !modest_text_utils_utf8_strcmp (what, where, TRUE);
#ifdef MODEST_HAVE_OGS
}
}
+
/**
* modest_search:
* @folder: a #TnyFolder instance
* It will return a doubly linked list with URIs that point to the message.
**/
GList *
-modest_search (TnyFolder *folder, ModestSearch *search)
+modest_search_folder (TnyFolder *folder, ModestSearch *search)
{
GList *retval = NULL;
TnyIterator *iter;
TnyHeader *cur = (TnyHeader *) tny_iterator_get_current (iter);
time_t t = tny_header_get_date_sent (cur);
gboolean found = FALSE;
-
+
if (search->flags & MODEST_SEARCH_BEFORE)
if (!(t <= search->before))
goto go_next;
goto go_next;
if (search->flags & MODEST_SEARCH_SIZE)
- if (tny_header_get_message_size (cur) < search->minsize)
+ if (tny_header_get_message_size (cur) < search->minsize)
goto go_next;
if (search->flags & MODEST_SEARCH_SUBJECT) {
retval = add_header (retval, cur, folder);
}
}
-
+
if (!found && search->flags & MODEST_SEARCH_BODY) {
TnyHeaderFlags flags;
GError *err = NULL;
g_object_unref (msg);
}
+
go_next:
g_object_unref (cur);
tny_iterator_next (iter);
return retval;
}
+GList *
+modest_search_account (TnyAccount *account, ModestSearch *search)
+{
+ TnyFolderStore *store;
+ TnyIterator *iter;
+ TnyList *folders;
+ GList *hits;
+ GError *error;
+
+ error = NULL;
+ hits = NULL;
+
+ store = TNY_FOLDER_STORE (account);
+
+ folders = tny_simple_list_new ();
+ tny_folder_store_get_folders (store, folders, NULL, &error);
+
+ if (error != NULL) {
+ g_object_unref (folders);
+ return NULL;
+ }
+
+ iter = tny_list_create_iterator (folders);
+ while (!tny_iterator_is_done (iter)) {
+ TnyFolder *folder;
+ GList *res;
+
+ folder = TNY_FOLDER (tny_iterator_get_current (iter));
+
+ 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);
+ tny_iterator_next (iter);
+ }
+
+ g_object_unref (iter);
+ g_object_unref (folders);
+
+ return hits;
+}
+
+GList *
+modest_search_all_accounts (ModestSearch *search)
+{
+ ModestTnyAccountStore *astore;
+ TnyList *accounts;
+ TnyIterator *iter;
+ GList *hits;
+
+ hits = NULL;
+ astore = modest_runtime_get_account_store ();
+
+ accounts = tny_simple_list_new ();
+ tny_account_store_get_accounts (TNY_ACCOUNT_STORE (astore),
+ accounts,
+ TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+
+ iter = tny_list_create_iterator (accounts);
+ while (!tny_iterator_is_done (iter)) {
+ TnyAccount *account;
+ GList *res;
+
+ account = TNY_ACCOUNT (tny_iterator_get_current (iter));
+
+ g_debug ("Searching account %s",
+ tny_account_get_name (account));
+ 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);
+ tny_iterator_next (iter);
+ }
+
+ g_object_unref (accounts);
+
+ return hits;
+}
+
+