static gchar * mail_tool_get_local_movemail_path (CamelStore *store, GError **error) { const gchar *uid; guchar *safe_uid, *c; const gchar *data_dir; gchar *path, *full; struct stat st; uid = camel_service_get_uid (CAMEL_SERVICE (store)); safe_uid = (guchar *) g_strdup ((const gchar *) uid); for (c = safe_uid; *c; c++) if (strchr ("/:;=|%&#!*^()\\, ", *c) || !isprint ((gint) *c)) *c = '_'; data_dir = mail_session_get_data_dir (); path = g_build_filename (data_dir, "spool", NULL); if (g_stat (path, &st) == -1 && g_mkdir_with_parents (path, 0700) == -1) { g_set_error ( error, G_FILE_ERROR, g_file_error_from_errno (errno), _("Could not create spool directory '%s': %s"), path, g_strerror (errno)); g_free (path); return NULL; } full = g_strdup_printf ("%s/movemail.%s", path, safe_uid); g_free (path); g_free (safe_uid); return full; }
static void import_folders_rec (struct _import_folders_data *m, const gchar *filepath, const gchar *folderparent) { GDir *dir; const gchar *d; struct stat st; const gchar *data_dir; gchar *filefull, *foldersub, *uri, *utf8_filename; const gchar *folder; dir = g_dir_open (filepath, 0, NULL); if (dir == NULL) return; data_dir = mail_session_get_data_dir (); utf8_filename = g_filename_to_utf8 (filepath, -1, NULL, NULL, NULL); camel_operation_push_message (m->cancellable, _("Scanning %s"), utf8_filename); g_free (utf8_filename); while ((d = g_dir_read_name (dir))) { if (d[0] == '.') continue; filefull = g_build_filename (filepath, d, NULL); /* skip non files and directories, and skip directories in mozilla mode */ if (g_stat (filefull, &st) == -1 || !(S_ISREG (st.st_mode) || (m->elmfmt && S_ISDIR (st.st_mode)))) { g_free (filefull); continue; } folder = d; if (folderparent == NULL) { gint i; for (i = 0; m->special_folders[i].orig; i++) if (strcmp (m->special_folders[i].orig, folder) == 0) { folder = m->special_folders[i].new; break; } /* FIXME: need a better way to get default store location */ uri = g_strdup_printf ( "mbox:%s/local#%s", data_dir, folder); } else {
void vfolder_load_storage (EMailBackend *backend) { /* lock for loading storage, it is safe to call it more than once */ G_LOCK_DEFINE_STATIC (vfolder_hash); CamelService *service; const gchar *key; const gchar *data_dir; const gchar *config_dir; gchar *user, *storeuri; EFilterRule *rule; MailFolderCache *folder_cache; EMailSession *session; gchar *xmlfile; GConfClient *client; g_return_if_fail (E_IS_MAIL_BACKEND (backend)); G_LOCK (vfolder_hash); if (vfolder_hash) { /* we have already initialized */ G_UNLOCK (vfolder_hash); return; } vfolder_hash = g_hash_table_new (g_str_hash, g_str_equal); G_UNLOCK (vfolder_hash); data_dir = mail_session_get_data_dir (); config_dir = mail_session_get_config_dir (); session = e_mail_backend_get_session (backend); /* first, create the vfolder store, and set it up */ storeuri = g_strdup_printf("vfolder:%s/vfolder", data_dir); service = camel_session_add_service ( CAMEL_SESSION (session), "vfolder", storeuri, CAMEL_PROVIDER_STORE, NULL); if (service != NULL) { camel_service_set_display_name (service, _("Search Folders")); em_utils_connect_service_sync (service, NULL, NULL); } else { g_warning("Cannot open vfolder store - no vfolders available"); return; } g_return_if_fail (CAMEL_IS_STORE (service)); vfolder_store = CAMEL_STORE (service); g_signal_connect ( service, "folder-deleted", G_CALLBACK (store_folder_deleted_cb), backend); g_signal_connect ( service, "folder-renamed", G_CALLBACK (store_folder_renamed_cb), NULL); /* load our rules */ user = g_build_filename (config_dir, "vfolders.xml", NULL); context = em_vfolder_context_new (backend); xmlfile = g_build_filename (EVOLUTION_PRIVDATADIR, "vfoldertypes.xml", NULL); if (e_rule_context_load ((ERuleContext *) context, xmlfile, user) != 0) { g_warning("cannot load vfolders: %s\n", ((ERuleContext *)context)->error); } g_free (xmlfile); g_free (user); g_signal_connect ( context, "rule_added", G_CALLBACK (context_rule_added), context); g_signal_connect ( context, "rule_removed", G_CALLBACK (context_rule_removed), context); /* load store to mail component */ e_mail_store_add (backend, vfolder_store); /* and setup the rules we have */ rule = NULL; while ((rule = e_rule_context_next_rule ((ERuleContext *) context, rule, NULL))) { if (rule->name) { d(printf("rule added: %s\n", rule->name)); context_rule_added ((ERuleContext *) context, rule); } else { d(printf("invalid rule (%p) encountered: rule->name is NULL\n", rule)); } } g_free (storeuri); /* reenable the feature if required */ client = gconf_client_get_default (); key = "/apps/evolution/mail/display/enable_vfolders"; if (!gconf_client_get_bool (client, key, NULL)) gconf_client_set_bool (client, key, TRUE, NULL); g_object_unref (client); folder_cache = e_mail_session_get_folder_cache (session); g_signal_connect ( folder_cache, "folder-available", G_CALLBACK (folder_available_cb), backend); g_signal_connect ( folder_cache, "folder-unavailable", G_CALLBACK (folder_unavailable_cb), backend); g_signal_connect ( folder_cache, "folder-deleted", G_CALLBACK (folder_deleted_cb), backend); g_signal_connect ( folder_cache, "folder-renamed", G_CALLBACK (folder_renamed_cb), NULL); }