X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-search.c;h=477638f4c79239ca73268b83e3fb12dac7b25d64;hb=2c3715c522851a40f83cb4a7e16a446e23b26071;hp=0b0dbb3ffaf52ab1fc6f61fa7e4fd14c88728b75;hpb=0c5bc44e42151314a5453c80bd432f50dacc31af;p=modest diff --git a/src/modest-search.c b/src/modest-search.c index 0b0dbb3..477638f 100644 --- a/src/modest-search.c +++ b/src/modest-search.c @@ -43,6 +43,8 @@ #include #include #include +#include +#include #include @@ -52,6 +54,7 @@ #include "modest-tny-account.h" #include "modest-search.h" #include "modest-runtime.h" +#include "modest-platform.h" static gchar * g_strdup_or_null (const gchar *str) @@ -65,7 +68,6 @@ g_strdup_or_null (const gchar *str) return string; } - static GList* add_hit (GList *list, TnyHeader *header, TnyFolder *folder) { @@ -356,10 +358,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); } @@ -374,12 +378,19 @@ static gboolean search_mime_part_and_child_parts (TnyMimePart *part, ModestSearc * @folder: a #TnyFolder instance * @search: a #ModestSearch query * - * This operation will search @folder for headers that match the query @search. + * 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) { + /* 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; + GList *retval = NULL; TnyIterator *iter = NULL; TnyList *list = NULL; @@ -411,15 +422,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) @@ -471,16 +486,17 @@ modest_search_folder (TnyFolder *folder, ModestSearch *search) if (msg) { g_object_unref (msg); } - } - - found = search_mime_part_and_child_parts (TNY_MIME_PART (msg), - search); - if (found) { - retval = add_hit (retval, cur, folder); + } else { + + found = search_mime_part_and_child_parts (TNY_MIME_PART (msg), + search); + if (found) { + retval = add_hit (retval, cur, folder); + } } - g_object_unref (msg); - + if (msg) + g_object_unref (msg); } go_next: @@ -517,36 +533,41 @@ 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); } g_object_unref (iter); g_object_unref (folders); + /* printf ("DEBUG: %s: hits length = %d\n", __FUNCTION__, g_list_length (hits)); */ return hits; } GList * modest_search_all_accounts (ModestSearch *search) { + /* printf ("DEBUG: %s: query=%s\n", __FUNCTION__, search->query); */ ModestTnyAccountStore *astore; TnyList *accounts; TnyIterator *iter; @@ -562,31 +583,40 @@ 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 (res != NULL) { - - if (hits == NULL) { - hits = res; - } else { - hits = g_list_concat (hits, res); + 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); + + /* 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); } - g_object_unref (account); tny_iterator_next (iter); } g_object_unref (accounts); g_object_unref (iter); + /* printf ("DEBUG: %s: end: hits length=%d\n", __FUNCTION__, g_list_length(hits)); */ return hits; }