static void add_folders_from_store (GList **folders, CamelStore *store, GCancellable *cancellable, GError **error) { CamelFolderInfo *root, *fi; g_return_if_fail (folders != NULL); g_return_if_fail (store != NULL); if (CAMEL_IS_VEE_STORE (store)) return; root = camel_store_get_folder_info_sync ( store, NULL, CAMEL_STORE_FOLDER_INFO_RECURSIVE, cancellable, error); fi = root; while (fi && !g_cancellable_is_cancelled (cancellable)) { CamelFolderInfo *next; if ((fi->flags & CAMEL_FOLDER_NOSELECT) == 0) { CamelFolder *fldr; fldr = camel_store_get_folder_sync ( store, fi->full_name, 0, cancellable, error); if (fldr) { if (CAMEL_IS_VEE_FOLDER (fldr)) { g_object_unref (fldr); } else { *folders = g_list_prepend (*folders, fldr); } } } /* pick the next */ next = fi->child; if (!next) next = fi->next; if (!next) { next = fi->parent; while (next) { if (next->next) { next = next->next; break; } next = next->parent; } } fi = next; } camel_folder_info_free (root); }
static ESource * guess_mail_account_from_folder (ESourceRegistry *registry, CamelFolder *folder, const gchar *message_uid) { ESource *source; CamelStore *store; const gchar *uid; /* Lookup an ESource by CamelStore UID. */ store = camel_folder_get_parent_store (folder); if (message_uid && folder && CAMEL_IS_VEE_STORE (store)) { CamelMessageInfo *mi = camel_folder_get_message_info (folder, message_uid); if (mi) { CamelFolder *location; location = camel_vee_folder_get_location (CAMEL_VEE_FOLDER (folder), (CamelVeeMessageInfo *) mi, NULL); if (location) store = camel_folder_get_parent_store (location); camel_folder_free_message_info (folder, mi); } } uid = camel_service_get_uid (CAMEL_SERVICE (store)); source = e_source_registry_ref_source (registry, uid); /* If we found an ESource, make sure it's a mail account. */ if (source != NULL) { const gchar *extension_name; extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT; if (!e_source_has_extension (source, extension_name)) { g_object_unref (source); source = NULL; } } return source; }
/** * mail_vfolder_add_folder: * @backend: an #EMailBackend * @store: a #CamelStore * @folder: a folder name * @remove: whether the folder should be removed or added * * Called when a new folder becomes (un)available. If @store is not a * CamelVeeStore, the folder is added/removed from the list of cached source * folders. Then each vfolder rule is checked to see if the specified folder * matches a source of the rule. It builds a list of vfolders that use (or * would use) the specified folder as a source. It then adds (or removes) * this folder to (from) those vfolders via camel_vee_folder_add/ * remove_folder() but does not modify the actual filters or write changes * to disk. * * NOTE: This function must be called from the main thread. */ static void mail_vfolder_add_folder (EMailBackend *backend, CamelStore *store, const gchar *folder_name, gint remove) { EMailSession *session; EFilterRule *rule; const gchar *source; CamelVeeFolder *vf; CamelProvider *provider; GList *folders = NULL, *link; GQueue *queue; gint remote; gint is_ignore; gchar *uri; session = e_mail_backend_get_session (backend); provider = camel_service_get_provider (CAMEL_SERVICE (store)); remote = (provider->flags & CAMEL_PROVIDER_IS_REMOTE) != 0; queue = remote ? &source_folders_remote : &source_folders_local; if (folder_is_spethal (store, folder_name)) return; g_return_if_fail (mail_in_main_thread ()); uri = e_mail_folder_uri_build (store, folder_name); is_ignore = uri_is_ignore (backend, uri); G_LOCK (vfolder); /* maintain the source folders lists for changed rules later on */ if (CAMEL_IS_VEE_STORE (store)) { is_ignore = TRUE; } else if (remove) { link = mv_find_folder (queue, session, uri); if (link != NULL) { g_free (link->data); g_queue_delete_link (queue, link); } } else if (!is_ignore) { /* we ignore drafts/sent/outbox here */ if (mv_find_folder (queue, session, uri) == NULL) g_queue_push_tail (queue, g_strdup (uri)); } if (context == NULL) goto done; rule = NULL; while ((rule = e_rule_context_next_rule ((ERuleContext *) context, rule, NULL))) { gint found = FALSE; if (!rule->name) { d(printf("invalid rule (%p): rule->name is set to NULL\n", rule)); continue; } /* Don't auto-add any sent/drafts folders etc, * they must be explictly listed as a source. */ if (rule->source && !is_ignore && ((((EMVFolderRule *) rule)->with == EM_VFOLDER_RULE_WITH_LOCAL && !remote) || (((EMVFolderRule *) rule)->with == EM_VFOLDER_RULE_WITH_REMOTE_ACTIVE && remote) || (((EMVFolderRule *) rule)->with == EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE))) found = TRUE; source = NULL; while (!found && (source = em_vfolder_rule_next_source ( (EMVFolderRule *) rule, source))) { found = e_mail_folder_uri_equal ( CAMEL_SESSION (session), uri, source); } if (found) { vf = g_hash_table_lookup (vfolder_hash, rule->name); if (!vf) { g_warning ("vf is NULL for %s\n", rule->name); continue; } g_object_ref (vf); folders = g_list_prepend (folders, vf); } } done: G_UNLOCK (vfolder); if (folders != NULL) vfolder_adduri (backend, uri, folders, remove); g_free (uri); }