diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2004-01-22 05:22:57 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2004-01-22 05:22:57 +0800 |
commit | 69c5b58a835f3a39916e9d6441acd60f6944fb79 (patch) | |
tree | d4e4894f3cc4811e40c193d38cdde2f6d83c0657 /mail | |
parent | 5f7fc13ef6592a55df8ec0b34c6bbab5fa727d51 (diff) | |
download | gsoc2013-evolution-69c5b58a835f3a39916e9d6441acd60f6944fb79.tar.gz gsoc2013-evolution-69c5b58a835f3a39916e9d6441acd60f6944fb79.tar.zst gsoc2013-evolution-69c5b58a835f3a39916e9d6441acd60f6944fb79.zip |
Migrate the ETree expanded state files as well as the GalView files.
2004-01-21 Jeffrey Stedfast <fejj@ximian.com>
* em-migrate.c (em_migrate_1_4): Migrate the ETree expanded state
files as well as the GalView files.
* message-list.c: s/hide_save_state/save_hide_state/g and
s/hide_load_state/load_hide_state/g to be more consistant with the
other state saving function names.
svn path=/trunk/; revision=24356
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 9 | ||||
-rw-r--r-- | mail/em-migrate.c | 296 | ||||
-rw-r--r-- | mail/message-list.c | 20 |
3 files changed, 283 insertions, 42 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index d4b869f5e5..a0f304c295 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,12 @@ +2004-01-21 Jeffrey Stedfast <fejj@ximian.com> + + * em-migrate.c (em_migrate_1_4): Migrate the ETree expanded state + files as well as the GalView files. + + * message-list.c: s/hide_save_state/save_hide_state/g and + s/hide_load_state/load_hide_state/g to be more consistant with the + other state saving function names. + 2004-01-21 Not Zed <NotZed@Ximian.com> * em-migrate.c (cp_r): use camel_mkdir(0777) rather than 0777 & diff --git a/mail/em-migrate.c b/mail/em-migrate.c index 999708ad54..2961c049a1 100644 --- a/mail/em-migrate.c +++ b/mail/em-migrate.c @@ -49,6 +49,8 @@ #include <libxml/parser.h> #include <libxml/xmlmemory.h> +#include <gal/util/e-util.h> +#include <gal/util/e-iconv.h> #include <gal/util/e-xml-utils.h> #include "e-util/e-bconf-map.h" @@ -1245,35 +1247,35 @@ cp (const char *src, const char *dest, gboolean show_progress) size_t total = 0; struct stat st; struct utimbuf ut; - + /* if the dest file exists and has content, abort - we don't * want to corrupt their existing data */ - if (stat(dest, &st) == 0 && st.st_size > 0) { - printf("destination exists, not copying '%s' to '%s'\n", src, dest); + if (stat (dest, &st) == 0 && st.st_size > 0) { + printf ("destination exists, not copying '%s' to '%s'\n", src, dest); return -1; } - if (stat(src, &st) == -1) { - printf("source doesn't exist '%s'\n", src); + if (stat (src, &st) == -1) { + printf ("source doesn't exist '%s'\n", src); return -1; } - if ((readfd = open(src, O_RDONLY)) == -1) { - printf("source cannot be opened '%s'\n", src); + if ((readfd = open (src, O_RDONLY)) == -1) { + printf ("source cannot be opened '%s'\n", src); return -1; } - if ((writefd = open(dest, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1) { - printf("cannot open dest '%s' '%s'\n", dest, strerror(errno)); + if ((writefd = open (dest, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1) { + printf ("cannot open dest '%s' '%s'\n", dest, strerror(errno)); errnosav = errno; - close(readfd); + close (readfd); errno = errnosav; return -1; } - + do { do { - nread = read(readfd, readbuf, sizeof(readbuf)); + nread = read (readfd, readbuf, sizeof (readbuf)); } while (nread == -1 && errno == EINTR); if (nread == 0) @@ -1282,7 +1284,7 @@ cp (const char *src, const char *dest, gboolean show_progress) goto exception; do { - nwritten = write(writefd, readbuf, nread); + nwritten = write (writefd, readbuf, nread); } while (nwritten == -1 && errno == EINTR); if (nwritten < nread) @@ -1291,36 +1293,34 @@ cp (const char *src, const char *dest, gboolean show_progress) total += nwritten; if (show_progress) - em_migrate_set_progress(((double) total) / ((double) st.st_size)); + em_migrate_set_progress (((double) total) / ((double) st.st_size)); } while (total < st.st_size); - if (fsync(writefd) == -1) + if (fsync (writefd) == -1) goto exception; - close(readfd); - if (close(writefd) == -1) - goto failwrite; - + close (readfd); + if (close (writefd) == -1) + goto failclose; + ut.actime = st.st_atime; ut.modtime = st.st_mtime; - utime(dest, &ut); - chmod(dest, st.st_mode); - + utime (dest, &ut); + chmod (dest, st.st_mode); + return 0; exception: errnosav = errno; - - close(readfd); - close(writefd); - + close (readfd); + close (writefd); errno = errnosav; -failwrite: - errnosav = errno; - - unlink(dest); + failclose: + + errnosav = errno; + unlink (dest); errno = errnosav; return -1; @@ -1759,7 +1759,7 @@ em_migrate_pop_uid_caches_1_4 (const char *evolution_dir, CamelException *ex) g_free(cache_dir); return 0; } - + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Failed to migrate pop3 uid caches: %s"), g_strerror (errno)); @@ -1844,6 +1844,232 @@ em_migrate_imap_caches_1_4 (const char *evolution_dir, CamelException *ex) } static int +em_migrate_folder_expand_state_1_4 (const char *evolution_dir, CamelException *ex) +{ + GString *srcpath, *destpath; + size_t slen, dlen, rlen; + char *evo14_mbox_root; + struct dirent *dent; + struct stat st; + DIR *dir; + + srcpath = g_string_new (g_get_home_dir ()); + g_string_append (srcpath, "/evolution/config"); + if (stat (srcpath->str, &st) == -1 || !S_ISDIR (st.st_mode)) { + g_string_free (srcpath, TRUE); + return 0; + } + + destpath = g_string_new (evolution_dir); + g_string_append (destpath, "/mail/config"); + if (camel_mkdir (destpath->str, 0777) == -1 || !(dir = opendir (srcpath->str))) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Failed to migrate folder expand state: %s"), g_strerror (errno)); + g_warning ("Failed to migrate folder expand state: %s", g_strerror (errno)); + g_string_free (destpath, TRUE); + g_string_free (srcpath, TRUE); + return -1; + } + + g_string_append (srcpath, "/et-expanded-"); + slen = srcpath->len; + g_string_append (destpath, "/et-expanded-"); + dlen = destpath->len; + + evo14_mbox_root = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); + e_filename_make_safe (evo14_mbox_root); + rlen = strlen (evo14_mbox_root); + evo14_mbox_root = g_realloc (evo14_mbox_root, rlen + 2); + evo14_mbox_root[rlen++] = '_'; + evo14_mbox_root[rlen] = '\0'; + + while ((dent = readdir (dir))) { + char *full_name, *inptr, *buf = NULL; + const char *filename; + GString *new; + + if (strncmp (dent->d_name, "et-expanded-", 12) != 0) + continue; + + if (!strncmp (dent->d_name + 12, "file:", 5)) { + /* need to munge the filename */ + inptr = dent->d_name + 17; + + if (!strncmp (inptr, evo14_mbox_root, rlen)) { + /* this should always be the case afaik... */ + inptr += rlen; + new = g_string_new ("mbox:"); + g_string_append_printf (new, "%s/mail/local#", evolution_dir); + + full_name = g_strdup (inptr); + inptr = full_name + strlen (full_name) - 12; + while (inptr > full_name) { + if (!strncmp (inptr, "_subfolders_", 12)) + memmove (inptr, inptr + 11, strlen (inptr + 11) + 1); + + inptr--; + } + + g_string_append (new, full_name); + g_free (full_name); + + filename = buf = new->str; + g_string_free (new, FALSE); + e_filename_make_safe (buf); + } else { + /* but just in case... */ + filename = dent->d_name + 12; + } + } else { + /* no munging needed */ + filename = dent->d_name + 12; + } + + g_string_append (srcpath, dent->d_name + 12); + g_string_append (destpath, filename); + g_free (buf); + + cp (srcpath->str, destpath->str, FALSE); + + g_string_truncate (srcpath, slen); + g_string_truncate (destpath, dlen); + } + + closedir (dir); + + g_free (evo14_mbox_root); + g_string_free (destpath, TRUE); + g_string_free (srcpath, TRUE); + + return 0; +} + +static int +em_migrate_folder_view_settings_1_4 (const char *evolution_dir, CamelException *ex) +{ + GString *srcpath, *destpath; + size_t slen, dlen, rlen; + char *evo14_mbox_root; + struct dirent *dent; + struct stat st; + DIR *dir; + + srcpath = g_string_new (g_get_home_dir ()); + g_string_append (srcpath, "/evolution/views/mail"); + if (stat (srcpath->str, &st) == -1 || !S_ISDIR (st.st_mode)) { + g_string_free (srcpath, TRUE); + return 0; + } + + destpath = g_string_new (evolution_dir); + g_string_append (destpath, "/mail/views"); + if (camel_mkdir (destpath->str, 0777) == -1 || !(dir = opendir (srcpath->str))) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Failed to migrate folder expand state: %s"), g_strerror (errno)); + g_warning ("Failed to migrate folder expand state: %s", g_strerror (errno)); + g_string_free (destpath, TRUE); + g_string_free (srcpath, TRUE); + return -1; + } + + g_string_append_c (srcpath, '/'); + slen = srcpath->len; + g_string_append_c (destpath, '/'); + dlen = destpath->len; + + evo14_mbox_root = g_build_filename (g_get_home_dir (), "evolution", "local", NULL); + e_filename_make_safe (evo14_mbox_root); + rlen = strlen (evo14_mbox_root); + evo14_mbox_root = g_realloc (evo14_mbox_root, rlen + 2); + evo14_mbox_root[rlen++] = '_'; + evo14_mbox_root[rlen] = '\0'; + + while ((dent = readdir (dir))) { + char *full_name, *inptr, *buf = NULL; + const char *filename, *ext; + size_t prelen = 0; + GString *new; + + if (dent->d_name[0] == '.') + continue; + + if (!(ext = strrchr (dent->d_name, '.'))) + continue; + + if (!strcmp (ext, ".galview") || !strcmp (dent->d_name, "galview.xml")) { + /* just copy the file */ + filename = dent->d_name; + goto copy; + } else if (strcmp (ext, ".xml") != 0) { + continue; + } + + if (!strncmp (dent->d_name, "current_view-", 13)) { + prelen = 13; + } else if (!strncmp (dent->d_name, "custom_view-", 12)) { + prelen = 12; + } else { + /* huh? wtf is this file? */ + continue; + } + + if (!strncmp (dent->d_name + prelen, "file:", 5)) { + /* need to munge the filename */ + inptr = dent->d_name + prelen + 5; + + if (!strncmp (inptr, evo14_mbox_root, rlen)) { + /* this should always be the case afaik... */ + inptr += rlen; + new = g_string_new ("mbox:"); + g_string_append_printf (new, "%s/mail/local#", evolution_dir); + + full_name = g_strdup (inptr); + inptr = full_name + strlen (full_name) - 12; + while (inptr > full_name) { + if (!strncmp (inptr, "_subfolders_", 12)) + memmove (inptr, inptr + 11, strlen (inptr + 11) + 1); + + inptr--; + } + + g_string_append (new, full_name); + g_free (full_name); + + filename = buf = new->str; + g_string_free (new, FALSE); + e_filename_make_safe (buf); + } else { + /* but just in case... */ + filename = dent->d_name + prelen; + } + } else { + /* no munging needed */ + filename = dent->d_name + prelen; + } + + copy: + g_string_append (srcpath, dent->d_name); + if (prelen > 0) + g_string_append_len (destpath, dent->d_name, prelen); + g_string_append (destpath, filename); + g_free (buf); + + cp (srcpath->str, destpath->str, FALSE); + + g_string_truncate (srcpath, slen); + g_string_truncate (destpath, dlen); + } + + closedir (dir); + + g_free (evo14_mbox_root); + g_string_free (destpath, TRUE); + g_string_free (srcpath, TRUE); + + return 0; +} + +static int em_migrate_1_4 (const char *evolution_dir, xmlDocPtr filters, xmlDocPtr vfolders, CamelException *ex) { EMMigrateSession *session; @@ -1914,6 +2140,12 @@ em_migrate_1_4 (const char *evolution_dir, xmlDocPtr filters, xmlDocPtr vfolders if (em_migrate_imap_caches_1_4 (evolution_dir, ex) == -1) return -1; + if (em_migrate_folder_expand_state_1_4 (evolution_dir, ex) == -1) + return -1; + + if (em_migrate_folder_view_settings_1_4 (evolution_dir, ex) == -1) + return -1; + return 0; } @@ -1960,7 +2192,7 @@ emm_setup_initial(const char *evolution_dir) /* special-case - this means brand new install of evolution */ /* FIXME: create default folders and stuff... */ - base = e_iconv_locale_language(); + base = (char *) e_iconv_locale_language (); if (base) { lang = g_alloca(strlen(base)+1); strcpy(lang, base); diff --git a/mail/message-list.c b/mail/message-list.c index c239f21cc5..745b637fd8 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -148,8 +148,8 @@ static char *filter_size (int size); static void folder_changed (CamelObject *o, gpointer event_data, gpointer user_data); static void message_changed (CamelObject *o, gpointer event_data, gpointer user_data); -static void hide_save_state(MessageList *ml); -static void hide_load_state(MessageList *ml); +static void save_hide_state(MessageList *ml); +static void load_hide_state(MessageList *ml); /* note: @changes is owned/freed by the caller */ /*static void mail_do_regenerate_messagelist (MessageList *list, const char *search, const char *hideexpr, CamelFolderChangeInfo *changes);*/ @@ -1365,10 +1365,10 @@ static void save_tree_state(MessageList *ml) { char *filename; - + if (ml->folder == NULL || ml->tree == NULL) return; - + filename = mail_config_folder_to_cachename(ml->folder, "et-expanded-"); e_tree_save_expanded_state(ml->tree, filename); g_free(filename); @@ -1392,7 +1392,7 @@ void message_list_save_state (MessageList *ml) { save_tree_state (ml); - hide_save_state (ml); + save_hide_state (ml); } static void @@ -1627,7 +1627,7 @@ message_list_destroy(GtkObject *object) } save_tree_state(message_list); - hide_save_state(message_list); + save_hide_state(message_list); camel_object_unhook_event(message_list->folder, "folder_changed", folder_changed, message_list); camel_object_unhook_event(message_list->folder, "message_changed", message_changed, message_list); camel_object_unref (message_list->folder); @@ -2547,7 +2547,7 @@ message_list_set_folder (MessageList *message_list, CamelFolder *folder, const c clear_tree (message_list); if (message_list->folder) { - hide_save_state(message_list); + save_hide_state(message_list); camel_object_unhook_event((CamelObject *)message_list->folder, "folder_changed", folder_changed, message_list); camel_object_unhook_event((CamelObject *)message_list->folder, "message_changed", @@ -2608,7 +2608,7 @@ message_list_set_folder (MessageList *message_list, CamelFolder *folder, const c message_list->hidedeleted = hide_deleted && !(folder->folder_flags & CAMEL_FOLDER_IS_TRASH); message_list->hidejunk = junk_folder && !(folder->folder_flags & CAMEL_FOLDER_IS_JUNK) && !(folder->folder_flags & CAMEL_FOLDER_IS_TRASH); - hide_load_state (message_list); + load_hide_state (message_list); mail_regen_list (message_list, message_list->search, NULL, NULL); } } @@ -2985,7 +2985,7 @@ message_list_hide_clear (MessageList *ml) */ static void -hide_load_state (MessageList *ml) +load_hide_state (MessageList *ml) { char *filename; FILE *in; @@ -3038,7 +3038,7 @@ hide_save_1 (char *uid, char *keydata, FILE *out) /* save the hide state. Note that messages are hidden by uid, if the uid's change, then this will become invalid, but is easy to reset in the ui */ static void -hide_save_state (MessageList *ml) +save_hide_state (MessageList *ml) { char *filename; FILE *out; |