/* NB: duplicated in maildir store */ static void fill_fi (CamelStore *store, CamelFolderInfo *fi, guint32 flags) { CamelFolder *folder; fi->unread = -1; fi->total = -1; folder = camel_object_bag_peek (store->folders, fi->full_name); if (folder) { if ((flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0) camel_folder_refresh_info_sync (folder, NULL, NULL); fi->unread = camel_folder_get_unread_message_count (folder); fi->total = camel_folder_get_message_count (folder); g_object_unref (folder); } else { CamelLocalStore *local_store; gchar *folderpath; CamelMboxSummary *mbs; local_store = CAMEL_LOCAL_STORE (store); /* This should be fast enough not * to have to test for INFO_FAST. */ folderpath = camel_local_store_get_full_path ( local_store, fi->full_name); mbs = (CamelMboxSummary *) camel_mbox_summary_new ( NULL, folderpath, NULL); /* FIXME[disk-summary] track exception */ if (camel_folder_summary_header_load_from_db ((CamelFolderSummary *) mbs, store, fi->full_name, NULL)) { fi->unread = camel_folder_summary_get_unread_count ( (CamelFolderSummary *) mbs); fi->total = camel_folder_summary_get_saved_count ( (CamelFolderSummary *) mbs); } g_object_unref (mbs); g_free (folderpath); } if (camel_local_store_is_main_store (CAMEL_LOCAL_STORE (store)) && fi->full_name && (fi->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_NORMAL) fi->flags = (fi->flags & ~CAMEL_FOLDER_TYPE_MASK) | camel_local_store_get_folder_type_by_full_name ( CAMEL_LOCAL_STORE (store), fi->full_name); }
static CamelFolderInfo * vee_store_get_folder_info_sync (CamelStore *store, const gchar *top, CamelStoreGetFolderInfoFlags flags, GCancellable *cancellable, GError **error) { CamelFolderInfo *info, *res = NULL, *tail; GPtrArray *folders; GHashTable *infos_hash; gint i; d (printf ("Get folder info '%s'\n", top ? top:"<null>")); infos_hash = g_hash_table_new (g_str_hash, g_str_equal); folders = camel_object_bag_list (store->folders); qsort (folders->pdata, folders->len, sizeof (folders->pdata[0]), vee_folder_cmp); for (i = 0; i < folders->len; i++) { CamelVeeFolder *folder = folders->pdata[i]; const gchar *full_name; const gchar *display_name; gint add = FALSE; gchar *pname, *tmp; CamelFolderInfo *pinfo; full_name = camel_folder_get_full_name (CAMEL_FOLDER (folder)); display_name = camel_folder_get_display_name (CAMEL_FOLDER (folder)); /* check we have to include this one */ if (top) { gint namelen = strlen (full_name); gint toplen = strlen (top); add = ((namelen == toplen && strcmp (full_name, top) == 0) || ((namelen > toplen) && strncmp (full_name, top, toplen) == 0 && full_name[toplen] == '/' && ((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE) || strchr (full_name + toplen + 1, '/') == NULL))); } else { add = (flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE) || strchr (full_name, '/') == NULL; } if (add) { gint32 unread; unread = camel_folder_get_unread_message_count ( CAMEL_FOLDER (folder)); info = camel_folder_info_new (); info->full_name = g_strdup (full_name); info->display_name = g_strdup (display_name); info->unread = unread; info->flags = CAMEL_FOLDER_NOCHILDREN | CAMEL_FOLDER_VIRTUAL; g_hash_table_insert (infos_hash, info->full_name, info); if (res == NULL) res = info; } else { info = NULL; } /* check for parent, if present, update flags and if adding, update parent linkage */ pname = g_strdup (full_name); d (printf ("looking up parent of '%s'\n", pname)); tmp = strrchr (pname, '/'); if (tmp) { *tmp = 0; pinfo = g_hash_table_lookup (infos_hash, pname); } else pinfo = NULL; if (pinfo) { pinfo->flags = (pinfo->flags & ~(CAMEL_FOLDER_CHILDREN | CAMEL_FOLDER_NOCHILDREN)) | CAMEL_FOLDER_CHILDREN; d (printf ("updating parent flags for children '%s' %08x\n", pinfo->full_name, pinfo->flags)); tail = pinfo->child; if (tail == NULL) pinfo->child = info; } else if (info != res) { tail = res; } else { tail = NULL; } if (info && tail) { while (tail->next) tail = tail->next; tail->next = info; info->parent = pinfo; } g_free (pname); g_object_unref (folder); } g_ptr_array_free (folders, TRUE); g_hash_table_destroy (infos_hash); /* and add UNMATCHED, if scanning from top/etc and it's enabled */ if (camel_vee_store_get_unmatched_enabled (CAMEL_VEE_STORE (store)) && (top == NULL || top[0] == 0 || strncmp (top, CAMEL_UNMATCHED_NAME, strlen (CAMEL_UNMATCHED_NAME)) == 0)) { info = vee_store_create_unmatched_fi (); if (res == NULL) res = info; else { tail = res; while (tail->next) tail = tail->next; tail->next = info; } } return res; }