static gint uri_is_ignore (EMailBackend *backend, const gchar *uri) { EMailSession *session; CamelSession *camel_session; EAccountList *accounts; EAccount *account; EIterator *iter; const gchar *local_drafts_uri; const gchar *local_outbox_uri; const gchar *local_sent_uri; gint found = FALSE; local_drafts_uri = e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_DRAFTS); local_outbox_uri = e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_OUTBOX); local_sent_uri = e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_SENT); session = e_mail_backend_get_session (backend); camel_session = CAMEL_SESSION (session); if (e_mail_folder_uri_equal (camel_session, local_outbox_uri, uri)) return TRUE; if (e_mail_folder_uri_equal (camel_session, local_sent_uri, uri)) return TRUE; if (e_mail_folder_uri_equal (camel_session, local_drafts_uri, uri)) return TRUE; accounts = e_get_account_list (); iter = e_list_get_iterator (E_LIST (accounts)); while (!found && e_iterator_is_valid (iter)) { /* XXX EIterator misuses const. */ account = (EAccount *) e_iterator_get (iter); if (!found && account->sent_folder_uri != NULL) found = e_mail_folder_uri_equal ( camel_session, uri, account->sent_folder_uri); if (!found && account->drafts_folder_uri != NULL) found = e_mail_folder_uri_equal ( camel_session, uri, account->drafts_folder_uri); e_iterator_next (iter); } g_object_unref (iter); return found; }
/** * em_utils_folder_is_drafts: * @registry: an #ESourceRegistry * @folder: a #CamelFolder * * Decides if @folder is a Drafts folder. * * Returns %TRUE if this is a Drafts folder or %FALSE otherwise. **/ gboolean em_utils_folder_is_drafts (ESourceRegistry *registry, CamelFolder *folder) { CamelFolder *local_drafts_folder; CamelSession *session; CamelStore *store; GList *list, *iter; gchar *folder_uri; gboolean is_drafts = FALSE; const gchar *extension_name; g_return_val_if_fail (CAMEL_IS_FOLDER (folder), FALSE); store = camel_folder_get_parent_store (folder); session = camel_service_ref_session (CAMEL_SERVICE (store)); local_drafts_folder = e_mail_session_get_local_folder ( E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_DRAFTS); if (folder == local_drafts_folder) { is_drafts = TRUE; goto exit; } folder_uri = e_mail_folder_uri_from_folder (folder); store = camel_folder_get_parent_store (folder); extension_name = E_SOURCE_EXTENSION_MAIL_COMPOSITION; list = e_source_registry_list_sources (registry, extension_name); for (iter = list; iter != NULL; iter = g_list_next (iter)) { ESource *source = E_SOURCE (iter->data); ESourceExtension *extension; const gchar *drafts_folder_uri; extension = e_source_get_extension (source, extension_name); drafts_folder_uri = e_source_mail_composition_get_drafts_folder ( E_SOURCE_MAIL_COMPOSITION (extension)); if (drafts_folder_uri != NULL) is_drafts = e_mail_folder_uri_equal ( session, folder_uri, drafts_folder_uri); if (is_drafts) break; } g_list_free_full (list, (GDestroyNotify) g_object_unref); g_free (folder_uri); exit: g_object_unref (session); return is_drafts; }
static GList * mv_find_folder (GQueue *queue, EMailSession *session, const gchar *uri) { CamelSession *camel_session = CAMEL_SESSION (session); GList *head, *link; head = g_queue_peek_head_link (queue); for (link = head; link != NULL; link = g_list_next (link)) { if (e_mail_folder_uri_equal (camel_session, link->data, uri)) break; } return link; }
/* called when a uri is renamed in a store */ static void mail_vfolder_rename_folder (CamelStore *store, const gchar *old_folder_name, const gchar *new_folder_name) { ERuleContext *rule_context; EFilterRule *rule; const gchar *source; CamelVeeFolder *vf; CamelSession *session; gint changed = 0; gchar *old_uri; gchar *new_uri; d(printf("vfolder rename uri: %s to %s\n", cfrom, cto)); if (context == NULL) return; if (folder_is_spethal (store, old_folder_name)) return; if (folder_is_spethal (store, new_folder_name)) return; g_return_if_fail (mail_in_main_thread ()); session = camel_service_get_session (CAMEL_SERVICE (store)); old_uri = e_mail_folder_uri_build (store, old_folder_name); new_uri = e_mail_folder_uri_build (store, new_folder_name); G_LOCK (vfolder); rule_context = E_RULE_CONTEXT (context); /* see if any rules directly reference this removed uri */ rule = NULL; while ((rule = e_rule_context_next_rule (rule_context, rule, NULL))) { EMVFolderRule *vf_rule = EM_VFOLDER_RULE (rule); source = NULL; while ((source = em_vfolder_rule_next_source (vf_rule, source))) { /* Remove all sources that match, ignore changed events though * because the adduri call above does the work async */ if (e_mail_folder_uri_equal (session, old_uri, source)) { vf = g_hash_table_lookup (vfolder_hash, rule->name); if (!vf) { g_warning ("vf is NULL for %s\n", rule->name); continue; } g_signal_handlers_disconnect_matched ( rule, G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, NULL, rule_changed, vf); em_vfolder_rule_remove_source (vf_rule, source); em_vfolder_rule_add_source (vf_rule, new_uri); g_signal_connect ( vf_rule, "changed", G_CALLBACK (rule_changed), vf); changed++; source = NULL; } } } G_UNLOCK (vfolder); if (changed) { const gchar *config_dir; gchar *user; d(printf("Vfolders updated from renamed folder\n")); config_dir = mail_session_get_config_dir (); user = g_build_filename (config_dir, "vfolders.xml", NULL); e_rule_context_save ((ERuleContext *) context, user); g_free (user); } g_free (old_uri); g_free (new_uri); }
/** * mail_vfolder_delete_folder: * @backend: an #EMailBackend * @store: a #CamelStore * @folder_name: a folder name * * Looks through all vfolder rules to see if @folder_name is listed as a * source for any vfolder rules. If the folder is found in the source for * any rule, it is removed and the user is alerted to the fact that the * vfolder rules have been updated. The new vfolder rules are written * to disk. * * XXX: It doesn't appear that the changes to the vfolder rules are sent * down to the camel level, however. So the actual vfolders will not change * behavior until evolution is restarted (?) * * NOTE: This function must be called from the main thread. */ static void mail_vfolder_delete_folder (EMailBackend *backend, CamelStore *store, const gchar *folder_name) { ERuleContext *rule_context; EFilterRule *rule; EMailSession *session; const gchar *source; CamelVeeFolder *vf; GString *changed; GQueue *queue; guint changed_count; gchar *uri; GList *link; g_return_if_fail (E_IS_MAIL_BACKEND (backend)); g_return_if_fail (CAMEL_IS_STORE (store)); g_return_if_fail (folder_name != NULL); if (folder_is_spethal (store, folder_name)) return; d(printf ("Deleting uri to check: %s\n", uri)); g_return_if_fail (mail_in_main_thread ()); session = e_mail_backend_get_session (backend); uri = e_mail_folder_uri_build (store, folder_name); changed_count = 0; changed = g_string_new (""); G_LOCK (vfolder); if (context == NULL) goto done; rule_context = E_RULE_CONTEXT (context); /* see if any rules directly reference this removed uri */ rule = NULL; while ((rule = e_rule_context_next_rule (rule_context, rule, NULL))) { EMVFolderRule *vf_rule = EM_VFOLDER_RULE (rule); if (!rule->name) continue; source = NULL; while ((source = em_vfolder_rule_next_source (vf_rule, source))) { /* Remove all sources that match, ignore changed events though * because the adduri call above does the work async */ if (e_mail_folder_uri_equal (CAMEL_SESSION (session), uri, source)) { vf = g_hash_table_lookup ( vfolder_hash, rule->name); if (!vf) { g_warning ("vf is NULL for %s\n", rule->name); continue; } g_signal_handlers_disconnect_matched ( rule, G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, NULL, rule_changed, vf); em_vfolder_rule_remove_source (vf_rule, source); g_signal_connect ( rule, "changed", G_CALLBACK (rule_changed), vf); if (changed_count == 0) { g_string_append (changed, rule->name); } else { if (changed_count == 1) { g_string_prepend (changed, " "); g_string_append (changed, "\n"); } g_string_append_printf ( changed, " %s\n", rule->name); } changed_count++; source = NULL; } } } done: queue = &source_folders_remote; link = mv_find_folder (queue, session, uri); if (link != NULL) { g_free (link->data); g_queue_delete_link (queue, link); } queue = &source_folders_local; link = mv_find_folder (queue, session, uri); if (link != NULL) { g_free (link->data); g_queue_delete_link (queue, link); } G_UNLOCK (vfolder); if (changed_count > 0) { const gchar *config_dir; gchar *user, *info; info = g_strdup_printf (ngettext ( /* Translators: The first %s is name of the affected * search folder(s), the second %s is the URI of the * removed folder. For more than one search folder is * each of them on a separate line, with four spaces * in front of its name, without quotes. */ "The Search Folder \"%s\" has been modified to " "account for the deleted folder\n\"%s\".", "The following Search Folders\n%s have been modified " "to account for the deleted folder\n\"%s\".", changed_count), changed->str, uri); e_mail_backend_submit_alert ( backend, "mail:vfolder-updated", info, NULL); g_free (info); config_dir = mail_session_get_config_dir (); user = g_build_filename (config_dir, "vfolders.xml", NULL); e_rule_context_save ((ERuleContext *) context, user); g_free (user); } g_string_free (changed, TRUE); g_free (uri); }
/** * 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); }