void mail_filter_rename_folder (CamelStore *store, const gchar *old_folder_name, const gchar *new_folder_name) { CamelSession *session; EMFilterContext *fc; const gchar *config_dir; gchar *user, *system; GList *changed; gchar *old_uri; gchar *new_uri; g_return_if_fail (CAMEL_IS_STORE (store)); g_return_if_fail (old_folder_name != NULL); g_return_if_fail (new_folder_name != NULL); session = camel_service_ref_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); fc = em_filter_context_new (E_MAIL_SESSION (session)); config_dir = mail_session_get_config_dir (); user = g_build_filename (config_dir, "filters.xml", NULL); system = g_build_filename (EVOLUTION_PRIVDATADIR, "filtertypes.xml", NULL); e_rule_context_load ((ERuleContext *) fc, system, user); g_free (system); changed = e_rule_context_rename_uri ( (ERuleContext *) fc, old_uri, new_uri, g_str_equal); if (changed) { if (e_rule_context_save ((ERuleContext *) fc, user) == -1) g_warning ("Could not write out changed filter rules\n"); e_rule_context_free_uri_list ((ERuleContext *) fc, changed); } g_free (user); g_object_unref (fc); g_free (old_uri); g_free (new_uri); g_object_unref (session); }
static void get_folders (CamelStore *store, GPtrArray *folders, CamelFolderInfo *info) { while (info) { if (camel_store_can_refresh_folder (store, info, NULL)) { if ((info->flags & CAMEL_FOLDER_NOSELECT) == 0) { gchar *folder_uri; folder_uri = e_mail_folder_uri_build ( store, info->full_name); g_ptr_array_add (folders, folder_uri); } } get_folders (store, folders, info->child); info = info->next; } }
void mail_filter_delete_folder (EMailBackend *backend, CamelStore *store, const gchar *folder_name) { EMFilterContext *fc; const gchar *config_dir; gchar *user, *system; GList *deleted; gchar *uri; g_return_if_fail (E_IS_MAIL_BACKEND (backend)); g_return_if_fail (CAMEL_IS_STORE (store)); g_return_if_fail (folder_name != NULL); uri = e_mail_folder_uri_build (store, folder_name); fc = em_filter_context_new (backend); config_dir = mail_session_get_config_dir (); user = g_build_filename (config_dir, "filters.xml", NULL); system = g_build_filename (EVOLUTION_PRIVDATADIR, "filtertypes.xml", NULL); e_rule_context_load ((ERuleContext *) fc, system, user); g_free (system); deleted = e_rule_context_delete_uri ( (ERuleContext *) fc, uri, g_str_equal); if (deleted) { GString *s; guint s_count; gchar *info; GList *l; s = g_string_new(""); s_count = 0; for (l = deleted; l; l = l->next) { const gchar *name = (const gchar *) l->data; if (s_count == 0) { g_string_append (s, name); } else { if (s_count == 1) { g_string_prepend (s, " "); g_string_append (s, "\n"); } g_string_append_printf (s, " %s\n", name); } s_count++; } info = g_strdup_printf (ngettext ( /* Translators: The first %s is name of the affected * filter rule(s), the second %s is URI of the removed * folder. For more than one filter rule is each of * them on a separate line, with four spaces in front * of its name, without quotes. */ "The filter rule \"%s\" has been modified to account " "for the deleted folder\n\"%s\".", "The following filter rules\n%s have been modified " "to account for the deleted folder\n\"%s\".", s_count), s->str, folder_name); e_mail_backend_submit_alert ( backend, "mail:filter-updated", info, NULL); g_string_free (s, TRUE); g_free (info); if (e_rule_context_save ((ERuleContext *) fc, user) == -1) g_warning ("Could not write out changed filter rules\n"); e_rule_context_free_uri_list ((ERuleContext *) fc, deleted); } g_free (user); g_object_unref (fc); g_free (uri); }
static void mail_shell_view_update_actions (EShellView *shell_view) { EMailShellView *mail_shell_view; EMailShellContent *mail_shell_content; EMailShellSidebar *mail_shell_sidebar; EShellSidebar *shell_sidebar; EShellWindow *shell_window; EMFolderTree *folder_tree; EMFolderTreeModel *model; EMailReader *reader; EMailView *mail_view; GtkAction *action; CamelStore *store = NULL; GList *list, *link; gchar *folder_name = NULL; gboolean sensitive; guint32 state; /* Be descriptive. */ gboolean folder_allows_children; gboolean folder_can_be_deleted; gboolean folder_is_outbox; gboolean folder_is_selected = FALSE; gboolean folder_is_store; gboolean folder_is_trash; gboolean folder_is_virtual; gboolean folder_has_unread = FALSE; gboolean folder_has_unread_rec = FALSE; gboolean folder_tree_and_message_list_agree = TRUE; gboolean store_is_builtin; gboolean store_is_subscribable; gboolean store_can_be_disabled; gboolean any_store_is_subscribable = FALSE; /* Chain up to parent's update_actions() method. */ E_SHELL_VIEW_CLASS (e_mail_shell_view_parent_class)-> update_actions (shell_view); shell_window = e_shell_view_get_shell_window (shell_view); mail_shell_view = E_MAIL_SHELL_VIEW (shell_view); mail_shell_content = mail_shell_view->priv->mail_shell_content; mail_view = e_mail_shell_content_get_mail_view (mail_shell_content); reader = E_MAIL_READER (mail_view); state = e_mail_reader_check_state (reader); e_mail_reader_update_actions (reader, state); mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar; folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar); shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); state = e_shell_sidebar_check_state (shell_sidebar); model = em_folder_tree_model_get_default (); folder_allows_children = (state & E_MAIL_SIDEBAR_FOLDER_ALLOWS_CHILDREN); folder_can_be_deleted = (state & E_MAIL_SIDEBAR_FOLDER_CAN_DELETE); folder_is_outbox = (state & E_MAIL_SIDEBAR_FOLDER_IS_OUTBOX); folder_is_store = (state & E_MAIL_SIDEBAR_FOLDER_IS_STORE); folder_is_trash = (state & E_MAIL_SIDEBAR_FOLDER_IS_TRASH); folder_is_virtual = (state & E_MAIL_SIDEBAR_FOLDER_IS_VIRTUAL); store_is_builtin = (state & E_MAIL_SIDEBAR_STORE_IS_BUILTIN); store_is_subscribable = (state & E_MAIL_SIDEBAR_STORE_IS_SUBSCRIBABLE); store_can_be_disabled = (state & E_MAIL_SIDEBAR_STORE_CAN_BE_DISABLED); if (em_folder_tree_get_selected (folder_tree, &store, &folder_name)) { GtkTreeRowReference *reference; CamelFolder *folder; folder_is_selected = TRUE; folder = e_mail_reader_ref_folder (reader); /* XXX If the user right-clicks on a folder other than what * the message list is showing, disable folder rename. * Between fetching the CamelFolder asynchronously and * knowing when NOT to move the folder tree selection * back to where it was to avoid cancelling the inline * folder tree editing, it's just too hairy to try to * get right. So we're punting. */ if (folder != NULL) { gchar *uri1, *uri2; uri1 = e_mail_folder_uri_from_folder (folder); uri2 = e_mail_folder_uri_build (store, folder_name); folder_tree_and_message_list_agree = (g_strcmp0 (uri1, uri2) == 0); g_free (uri1); g_free (uri2); g_object_unref (folder); } reference = em_folder_tree_model_get_row_reference ( model, store, folder_name); if (reference != NULL) { GtkTreePath *path; GtkTreeIter iter; path = gtk_tree_row_reference_get_path (reference); gtk_tree_model_get_iter ( GTK_TREE_MODEL (model), &iter, path); has_unread_mail ( GTK_TREE_MODEL (model), &iter, TRUE, &folder_has_unread, &folder_has_unread_rec); gtk_tree_path_free (path); } g_clear_object (&store); g_free (folder_name); folder_name = NULL; } /* Look for a CamelStore that supports subscriptions. */ list = em_folder_tree_model_list_stores (model); for (link = list; link != NULL; link = g_list_next (link)) { CamelStore *store = CAMEL_STORE (link->data); if (CAMEL_IS_SUBSCRIBABLE (store)) { any_store_is_subscribable = TRUE; break; } } g_list_free (list); action = ACTION (MAIL_ACCOUNT_DISABLE); sensitive = folder_is_store && store_can_be_disabled; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_ACCOUNT_EXPUNGE); sensitive = folder_is_trash; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_ACCOUNT_PROPERTIES); sensitive = folder_is_store && !store_is_builtin; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_ACCOUNT_REFRESH); sensitive = folder_is_store; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FLUSH_OUTBOX); sensitive = folder_is_outbox; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_COPY); sensitive = folder_is_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_DELETE); sensitive = folder_is_selected && folder_can_be_deleted; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_EXPUNGE); sensitive = folder_is_selected && !folder_is_virtual; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_MOVE); sensitive = folder_is_selected && folder_can_be_deleted; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_NEW); sensitive = folder_allows_children; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_PROPERTIES); sensitive = folder_is_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_REFRESH); sensitive = folder_is_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_RENAME); sensitive = folder_is_selected && folder_can_be_deleted && folder_tree_and_message_list_agree; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_SELECT_THREAD); sensitive = folder_is_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_SELECT_SUBTHREAD); sensitive = folder_is_selected; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_UNSUBSCRIBE); sensitive = folder_is_selected && store_is_subscribable && !folder_is_virtual; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_FOLDER_MARK_ALL_AS_READ); sensitive = folder_is_selected && folder_has_unread; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_POPUP_FOLDER_MARK_ALL_AS_READ); sensitive = folder_is_selected && folder_has_unread_rec; gtk_action_set_visible (action, sensitive); action = ACTION (MAIL_MANAGE_SUBSCRIPTIONS); sensitive = folder_is_store && store_is_subscribable; gtk_action_set_sensitive (action, sensitive); action = ACTION (MAIL_TOOLS_SUBSCRIPTIONS); sensitive = any_store_is_subscribable; gtk_action_set_sensitive (action, sensitive); /* folder_is_store + folder_is_virtual == "Search Folders" */ action = ACTION (MAIL_VFOLDER_UNMATCHED_ENABLE); gtk_action_set_visible (action, folder_is_store && folder_is_virtual); e_mail_shell_view_update_popup_labels (mail_shell_view); }
static gboolean mail_store_save_setup_key (CamelStore *store, ESource *source, const gchar *extension_name, const gchar *property_name, const gchar *type_id, const gchar *value) { gpointer extension; GObjectClass *klass; g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE); if (source) g_return_val_if_fail (E_IS_SOURCE (source), FALSE); g_return_val_if_fail (extension_name != NULL, FALSE); g_return_val_if_fail (property_name != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); if (!source) return FALSE; extension = e_source_get_extension (source, extension_name); if (!extension) { g_warning ("%s: Cannot find extension '%s'", G_STRFUNC, extension_name); return FALSE; } klass = G_OBJECT_GET_CLASS (extension); g_return_val_if_fail (klass != NULL, FALSE); if (!g_object_class_find_property (klass, property_name)) { g_warning ("%s: Extension '%s' doesn't have property '%s'", G_STRFUNC, extension_name, property_name); return FALSE; } if (!type_id || g_str_equal (type_id, "s")) { g_object_set (extension, property_name, value, NULL); } else if (g_str_equal (type_id, "b")) { gboolean val; val = g_strcmp0 (value, "false") != 0 && g_strcmp0 (value, "0") != 0; g_object_set (extension, property_name, val, NULL); } else if (g_str_equal (type_id, "i")) { gint val; val = (gint) g_ascii_strtoll (value, NULL, 10); g_object_set (extension, property_name, val, NULL); } else if (g_str_equal (type_id, "f")) { gchar *folder_uri; folder_uri = e_mail_folder_uri_build (store, value); g_object_set (extension, property_name, folder_uri, NULL); g_free (folder_uri); } else { g_warning ("%s: Unknown type identifier '%s' provided", G_STRFUNC, type_id); return FALSE; } return TRUE; }
/* 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); }