aboutsummaryrefslogtreecommitdiffstats
path: root/mail/em-migrate.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-11-07 05:54:49 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-11-07 05:54:49 +0800
commit49265bef8d773e845ec967acf6e2c1f1b670c995 (patch)
treebebf284de1b5844d639e489cba0d2d942ac664c5 /mail/em-migrate.c
parent621d5972f4c85456bc51de36fd2dd2c58520c7f4 (diff)
downloadgsoc2013-evolution-49265bef8d773e845ec967acf6e2c1f1b670c995.tar.gz
gsoc2013-evolution-49265bef8d773e845ec967acf6e2c1f1b670c995.tar.zst
gsoc2013-evolution-49265bef8d773e845ec967acf6e2c1f1b670c995.zip
User vfolder rules should be in ${evolution_dir}/mail/vfolders.xml rather
2003-11-06 Jeffrey Stedfast <fejj@ximian.com> * mail-vfolder.c (mail_vfolder_delete_uri): User vfolder rules should be in ${evolution_dir}/mail/vfolders.xml rather than ${evolution_dir}/vfolders.xml (mail_vfolder_rename_uri): Same. (store_folder_deleted): Here too. (store_folder_renamed): And here. (vfolder_load_storage): Again here. (vfolder_editor_response): Same. (edit_rule_response): And here. (new_rule_clicked): Here too. * mail-session.c (main_get_filter_driver): User filter rules should be in ${evolution_dir}/mail/filters.xml rather than ${evolution_dir}/filters.xml * mail-autofilter.c (filter_gui_add_from_message): Same. (mail_filter_rename_uri): And here. (mail_filter_delete_uri): Here too. * em-utils.c (filter_editor_response): Again here. (em_utils_edit_filters): Same. * em-migrate.c (em_migrate_filter_file): Same (also for vfolders.xml) 2003-11-05 Jeffrey Stedfast <fejj@ximian.com> * em-migrate.[c,h]: New source files to migrate from the old mail directory to the new mail directory. * mail-component.c (mail_component_init): Changed to use ~/.evolution and added code to migrate the old mail folders over if ~/.evolution/mail does not yet exist. svn path=/trunk/; revision=23201
Diffstat (limited to 'mail/em-migrate.c')
-rw-r--r--mail/em-migrate.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/mail/em-migrate.c b/mail/em-migrate.c
index 4a4c31f904..d404abd3e0 100644
--- a/mail/em-migrate.c
+++ b/mail/em-migrate.c
@@ -43,6 +43,8 @@
#include <libxml/parser.h>
#include <libxml/xmlmemory.h>
+#include <gal/util/e-xml-utils.h>
+
#include "mail-component.h"
#include "em-migrate.h"
@@ -472,6 +474,130 @@ em_migrate_local_folders (EMMigrateSession *session)
}
+static xmlNodePtr
+xml_find_node (xmlNodePtr parent, const char *name)
+{
+ xmlNodePtr node;
+
+ node = parent->children;
+ while (node != NULL) {
+ if (node->name && !strcmp (node->name, name))
+ return node;
+
+ node = node->next;
+ }
+
+ return NULL;
+}
+
+static int
+em_migrate_filter_file (const char *evolution_dir, const char *filename, CamelException *ex)
+{
+ char *path, *uri, *new;
+ xmlNodePtr node;
+ xmlDocPtr doc;
+ int retval;
+
+ path = g_strdup_printf ("%s/evolution/%s", g_get_home_dir (), filename);
+
+ if (!(doc = xmlParseFile (path))) {
+ /* can't parse - this means nothing to upgrade */
+ g_free (path);
+ return 0;
+ }
+
+ g_free (path);
+
+ if (!(node = xmlDocGetRootElement (doc))) {
+ /* document contains no root node - nothing to upgrade */
+ xmlFreeDoc (doc);
+ return 0;
+ }
+
+ if (!node->name || strcmp (node->name, "filteroptions") != 0) {
+ /* root node is not <filteroptions>, nothing to upgrade */
+ xmlFreeDoc (doc);
+ return 0;
+ }
+
+ if (!(node = xml_find_node (node, "ruleset"))) {
+ /* no ruleset node, nothing to upgrade */
+ xmlFreeDoc (doc);
+ return 0;
+ }
+
+ node = node->children;
+ while (node != NULL) {
+ if (node->name && !strcmp (node->name, "rule")) {
+ xmlNodePtr actionset, part, val, n;
+
+ if ((actionset = xml_find_node (node, "actionset"))) {
+ /* filters.xml */
+ part = actionset->children;
+ while (part != NULL) {
+ if (part->name && !strcmp (part->name, "part")) {
+ val = part->children;
+ while (val != NULL) {
+ if (val->name && !strcmp (val->name, "value")) {
+ char *type;
+
+ type = xmlGetProp (val, "type");
+ if (type && !strcmp (type, "folder")) {
+ if ((n = xml_find_node (val, "folder"))) {
+ uri = xmlGetProp (n, "uri");
+ new = em_uri_from_camel (uri);
+ xmlFree (uri);
+
+ xmlSetProp (n, "uri", new);
+ g_free (new);
+ }
+ }
+
+ xmlFree (type);
+ }
+
+ val = val->next;
+ }
+ }
+
+ part = part->next;
+ }
+ } else if ((actionset = xml_find_node (node, "sources"))) {
+ /* vfolders.xml */
+ n = actionset->children;
+ while (n != NULL) {
+ if (n->name && !strcmp (n->name, "folder")) {
+ uri = xmlGetProp (n, "uri");
+ new = em_uri_from_camel (uri);
+ xmlFree (uri);
+
+ xmlSetProp (n, "uri", new);
+ g_free (new);
+ }
+
+ n = n->next;
+ }
+ }
+ }
+
+ node = node->next;
+ }
+
+ path = g_strdup_printf ("%s/mail/%s", evolution_dir, filename);
+ if ((retval = e_xml_save_file (path, doc)) == -1) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Failed to migrate `%s': %s"),
+ filename, g_strerror (errno));
+ }
+
+ g_free (path);
+
+ xmlFreeDoc (doc);
+
+ return retval;
+}
+
+
int
em_migrate (MailComponent *component, CamelException *ex)
{
@@ -532,5 +658,11 @@ em_migrate (MailComponent *component, CamelException *ex)
camel_object_unref (session);
+ if (em_migrate_filter_file (evolution_dir, "filters.xml", ex) == -1)
+ return -1;
+
+ if (em_migrate_filter_file (evolution_dir, "vfolders.xml", ex) == -1)
+ return -1;
+
return 0;
}