X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-search.c;h=761598c5dc9f6117d7b106f1b3e363c56ca1a772;hp=46d5c90fedc5d89dd376a6b0d6c08480f035e55d;hb=78dfa46b5c70991558efdd83b867a792b4b55677;hpb=7de3bb67582c1e534d12efa0a573fb8ca18c1cdb diff --git a/src/modest-search.c b/src/modest-search.c index 46d5c90..761598c 100644 --- a/src/modest-search.c +++ b/src/modest-search.c @@ -43,15 +43,17 @@ #include #include #include - -#include +#include +#include #include "modest-text-utils.h" #include "modest-account-mgr.h" #include "modest-tny-account-store.h" #include "modest-tny-account.h" +#include "modest-tny-folder.h" #include "modest-search.h" #include "modest-runtime.h" +#include "modest-platform.h" static gchar * g_strdup_or_null (const gchar *str) @@ -65,11 +67,10 @@ g_strdup_or_null (const gchar *str) return string; } - static GList* add_hit (GList *list, TnyHeader *header, TnyFolder *folder) { - ModestSearchHit *hit; + ModestSearchResultHit *hit; TnyHeaderFlags flags; char *furl; char *msg_url; @@ -77,7 +78,7 @@ add_hit (GList *list, TnyHeader *header, TnyFolder *folder) const char *subject; const 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); @@ -109,7 +110,7 @@ add_hit (GList *list, TnyHeader *header, TnyFolder *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); } @@ -295,7 +296,7 @@ search_mime_part_strcmp (TnyMimePart *part, ModestSearch *search) buffer, TRUE); - if (found) { + if ((found)||(nread == 0)) { break; } @@ -356,10 +357,12 @@ static gboolean search_mime_part_and_child_parts (TnyMimePart *part, ModestSearc TnyIterator *piter = tny_list_create_iterator (child_parts); while (!found && !tny_iterator_is_done (piter)) { TnyMimePart *pcur = (TnyMimePart *) tny_iterator_get_current (piter); + if (pcur) { + found = search_mime_part_and_child_parts (pcur, search); - found = search_mime_part_and_child_parts (pcur, search); + g_object_unref (pcur); + } - g_object_unref (pcur); tny_iterator_next (piter); } @@ -384,8 +387,15 @@ modest_search_folder (TnyFolder *folder, ModestSearch *search) /* 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; + if (search->folder && strlen (search->folder)) { + if (!strcmp (search->folder, "outbox")) { + if (modest_tny_folder_guess_folder_type (folder) != TNY_FOLDER_TYPE_OUTBOX) { + return NULL; + } + } else if (strcmp (tny_folder_get_id (folder), search->folder) != 0) { + return NULL; + } + } GList *retval = NULL; TnyIterator *iter = NULL; @@ -418,15 +428,19 @@ modest_search_folder (TnyFolder *folder, ModestSearch *search) while (!tny_iterator_is_done (iter)) { TnyHeader *cur = (TnyHeader *) tny_iterator_get_current (iter); - time_t t = tny_header_get_date_sent (cur); + const time_t t = tny_header_get_date_sent (cur); gboolean 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->before)) + if (!(t <= search->end_date)) goto go_next; if (search->flags & MODEST_SEARCH_AFTER) - if (!(t >= search->after)) + if (!(t >= search->start_date)) goto go_next; if (search->flags & MODEST_SEARCH_SIZE) @@ -486,6 +500,7 @@ modest_search_folder (TnyFolder *folder, ModestSearch *search) retval = add_hit (retval, cur, folder); } } + if (msg) g_object_unref (msg); } @@ -524,24 +539,27 @@ modest_search_account (TnyAccount *account, ModestSearch *search) iter = tny_list_create_iterator (folders); while (!tny_iterator_is_done (iter)) { - TnyFolder *folder; - GList *res; + TnyFolder *folder = NULL; + GList *res = NULL; folder = TNY_FOLDER (tny_iterator_get_current (iter)); - /* g_debug ("DEBUG: %s: searching folder %s.", - __FUNCTION__, tny_folder_get_name (folder)); */ + if (folder) { + /* g_debug ("DEBUG: %s: searching folder %s.", + __FUNCTION__, tny_folder_get_name (folder)); */ - res = modest_search_folder (folder, search); + res = modest_search_folder (folder, search); - if (res != NULL) { - if (hits == NULL) { - hits = res; - } else { - hits = g_list_concat (hits, res); + if (res != NULL) { + if (hits == NULL) { + hits = res; + } else { + hits = g_list_concat (hits, res); + } } + + g_object_unref (folder); } - g_object_unref (folder); tny_iterator_next (iter); } @@ -571,26 +589,33 @@ modest_search_all_accounts (ModestSearch *search) iter = tny_list_create_iterator (accounts); while (!tny_iterator_is_done (iter)) { - TnyAccount *account; - GList *res; + TnyAccount *account = NULL; + GList *res = NULL; account = TNY_ACCOUNT (tny_iterator_get_current (iter)); - - - /* g_debug ("DEBUG: %s: Searching account %s", - __FUNCTION__, tny_account_get_name (account)); */ - res = modest_search_account (account, search); + 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: */ + modest_platform_check_and_wait_for_account_is_online (account); - if (res != NULL) { + /* Search: */ + res = modest_search_account (account, search); - if (hits == NULL) { - hits = res; - } else { - hits = g_list_concat (hits, res); + if (res != NULL) { + if (hits == NULL) { + hits = res; + } else { + hits = g_list_concat (hits, res); + } } - } - g_object_unref (account); + g_object_unref (account); + } + tny_iterator_next (iter); }