+static void get_multi_mailbox_account_folders_cb (TnyFolderStore *self, gboolean cancelled, TnyList *list, GError *err, gpointer user_data)
+{
+ GetUnreadMessagesHelper *helper = (GetUnreadMessagesHelper *) user_data;
+ TnyIterator *iterator;
+
+ /* another request has been finished */
+ helper->folder_requests_done += 1;
+
+ /* analize the folders we got */
+ iterator = tny_list_create_iterator (list);
+ while (!tny_iterator_is_done (iterator)) {
+ TnyFolder *folder;
+
+ folder = TNY_FOLDER (tny_iterator_get_current (iterator));
+ if (tny_folder_get_folder_type (folder) == TNY_FOLDER_TYPE_INBOX) {
+ tny_list_prepend (helper->inboxes_list, G_OBJECT (folder));
+ }
+
+ /* Try to check if we have inbox sub-folders in this folder */
+ if (TNY_IS_FOLDER_STORE (folder)) {
+ TnyFolderStore *folder_store;
+
+ folder_store = TNY_FOLDER_STORE (folder);
+ if (folder_store) {
+ TnyList *folders_list;
+
+ helper->folder_requests_total += 1;
+ folders_list = tny_simple_list_new ();
+ tny_folder_store_get_folders_async (folder_store, folders_list,
+ NULL, FALSE, get_multi_mailbox_account_folders_cb, NULL, helper);
+ g_object_unref (folders_list);
+ }
+ }
+ g_object_unref (folder);
+ tny_iterator_next (iterator);
+ }
+ g_object_unref (iterator);
+
+ /* Check if we have handled all the inbox folders for multi-mailbox accounts */
+ if (helper->folder_requests_done == helper->folder_requests_total) {
+ TnyIterator *inboxes_it;
+ TnyIterator *accounts_it;
+ TnyAccount *account;
+ guint unread_messages;
+ AccountHits* account_hits;
+ ModestProtocol *store_protocol;
+ ModestProtocolType store_protocol_type;
+
+ /* Store the number of unread messages for the handled account */
+ unread_messages = 0;
+ accounts_it = tny_list_create_iterator (helper->accounts_list);
+ account = TNY_ACCOUNT (tny_iterator_get_current (accounts_it));
+ g_object_unref (accounts_it);
+ inboxes_it = tny_list_create_iterator (helper->inboxes_list);
+ while (!tny_iterator_is_done (inboxes_it)) {
+ TnyFolder *folder;
+
+ folder = TNY_FOLDER (tny_iterator_get_current (inboxes_it));
+ if (folder) {
+ unread_messages += tny_folder_get_unread_count (folder);
+ }
+ tny_iterator_next (inboxes_it);
+ }
+ g_object_unref (inboxes_it);
+ g_object_unref (helper->inboxes_list);
+ helper->inboxes_list = NULL;
+ account_hits = g_slice_new (AccountHits);
+ account_hits->account_id = g_strdup (
+ modest_tny_account_get_parent_modest_account_name_for_server_account (account));
+ account_hits->account_name = g_strdup (tny_account_get_name (account));
+ store_protocol_type = modest_tny_account_get_protocol_type (account);
+ store_protocol = modest_protocol_registry_get_protocol_by_type (
+ modest_runtime_get_protocol_registry (), store_protocol_type);
+ account_hits->store_protocol = g_strdup (modest_protocol_get_name (store_protocol));
+ account_hits->mailbox_id = NULL;
+ account_hits->header_list = NULL;
+ account_hits->unread_count = unread_messages;
+ helper->account_hits_list = g_list_prepend (helper->account_hits_list, account_hits);
+
+ /* remove the handled account from the accounts_list */
+ tny_list_remove (helper->accounts_list, G_OBJECT (account));
+ g_object_unref (account);
+
+ get_unread_messages_get_account (helper);
+ }
+}