aboutsummaryrefslogtreecommitdiffstats
path: root/mail/em-migrate.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2004-01-08 06:12:43 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-01-08 06:12:43 +0800
commitfc863cbedf2998f93b1518bac7ce2243a1468372 (patch)
tree40c46b39bea162beaf52b502157a75295eca96f5 /mail/em-migrate.c
parentc18d2cf2ea3fe844dcc4d86558dda949e4d2bd59 (diff)
downloadgsoc2013-evolution-fc863cbedf2998f93b1518bac7ce2243a1468372.tar
gsoc2013-evolution-fc863cbedf2998f93b1518bac7ce2243a1468372.tar.gz
gsoc2013-evolution-fc863cbedf2998f93b1518bac7ce2243a1468372.tar.bz2
gsoc2013-evolution-fc863cbedf2998f93b1518bac7ce2243a1468372.tar.lz
gsoc2013-evolution-fc863cbedf2998f93b1518bac7ce2243a1468372.tar.xz
gsoc2013-evolution-fc863cbedf2998f93b1518bac7ce2243a1468372.tar.zst
gsoc2013-evolution-fc863cbedf2998f93b1518bac7ce2243a1468372.zip
Don't migrate stuff here anymore.
2004-01-07 Jeffrey Stedfast <fejj@ximian.com> * mail-component.c (mail_component_init): Don't migrate stuff here anymore. * mail-ops.c (uid_cachename_hack): Removed a hack that checked for the really old uid cache location and make the uid cache live in a better location (why have mail/pop/<account> and mail/pop3/cache-<account>? simply put the cache file in mail/pop/<account>/uid-cache). * em-migrate.c (em_migrate_dir): When copying over mbox folders, don't abort if we fail to copy over a summary file (big whoop). Also, if indexing was turned on in the evolution 1.4 version of the folder, turn on indexing for that folder in the migrated mbox folder as well. (em_migrate_pop_uid_caches): Migrate the pop3 uid-cache files. Fixes bug #52464. (em_migrate): Call em_migrate_pop_uid_caches(). svn path=/trunk/; revision=24094
Diffstat (limited to 'mail/em-migrate.c')
-rw-r--r--mail/em-migrate.c149
1 files changed, 141 insertions, 8 deletions
diff --git a/mail/em-migrate.c b/mail/em-migrate.c
index a3efe4eb26..10fc9248cf 100644
--- a/mail/em-migrate.c
+++ b/mail/em-migrate.c
@@ -304,7 +304,7 @@ cp (const char *src, const char *dest, gboolean show_progress)
if ((fd[0] = open (src, O_RDONLY)) == -1)
return -1;
- if ((fd[1] = open (dest, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) {
+ if ((fd[1] = open (dest, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1) {
errnosav = errno;
close (fd[0]);
errno = errnosav;
@@ -441,6 +441,7 @@ em_migrate_dir (EMMigrateSession *session, const char *dirname, const char *full
if (!strncmp (uri, "mbox:", 5)) {
GString *src, *dest;
+ size_t slen, dlen;
char *p;
src = g_string_new ("");
@@ -451,6 +452,9 @@ em_migrate_dir (EMMigrateSession *session, const char *dirname, const char *full
p = strrchr (dest->str, '/');
*p = '\0';
+ slen = src->len;
+ dlen = dest->len;
+
if (camel_mkdir (dest->str, 0777) == -1 && errno != EEXIST) {
g_string_free (dest, TRUE);
g_string_free (src, TRUE);
@@ -466,10 +470,64 @@ em_migrate_dir (EMMigrateSession *session, const char *dirname, const char *full
g_string_append (src, ".ev-summary");
g_string_append (dest, ".ev-summary");
- if (cp (src->str, dest->str, FALSE) == -1) {
- g_string_free (dest, TRUE);
- g_string_free (src, TRUE);
- goto try_subdirs;
+ cp (src->str, dest->str, FALSE);
+
+ if (index) {
+ static char *ibex_ext[] = { ".ibex.index", ".ibex.index.data" };
+ FILE *fp;
+ int i;
+
+ /* create a .cmeta file specifying to index the folder */
+ g_string_truncate (dest, dlen);
+ g_string_append (dest, ".cmeta");
+ if ((fp = fopen (dest->str, "w+")) != NULL) {
+ int fd = fileno (fp);
+
+ /* write the magic string */
+ if (fwrite ("CLMD", 4, 1, fp) != 1)
+ goto cmeta_err;
+
+ /* write the version (1) */
+ if (camel_file_util_encode_uint32 (fp, 1) == -1)
+ goto cmeta_err;
+
+ /* write the meta count */
+ if (camel_file_util_encode_uint32 (fp, 0) == -1)
+ goto cmeta_err;
+
+ /* write the prop count (only prop is the index prop) */
+ if (camel_file_util_encode_uint32 (fp, 1) == -1)
+ goto cmeta_err;
+
+ /* write the index prop tag (== CAMEL_FOLDER_ARG_LAST|CAMEL_ARG_BOO) */
+ if (camel_file_util_encode_uint32 (fp, CAMEL_FOLDER_ARG_LAST|CAMEL_ARG_BOO) == -1)
+ goto cmeta_err;
+
+ /* write the index prop value */
+ if (camel_file_util_encode_uint32 (fp, 1) == -1)
+ goto cmeta_err;
+
+ fflush (fp);
+
+ fd = fileno (fp);
+ if (fsync (fd) == -1) {
+ cmeta_err:
+ fclose (fp);
+ unlink (dest->str);
+ } else {
+ fclose (fp);
+ }
+ }
+
+ /* copy over the ibex files */
+ for (i = 0; i < 2; i++) {
+ g_string_truncate (src, slen);
+ g_string_truncate (dest, dlen);
+
+ g_string_append (src, ibex_ext[i]);
+ g_string_append (dest, ibex_ext[i]);
+ cp (src->str, dest->str, FALSE);
+ }
}
g_string_free (dest, TRUE);
@@ -507,7 +565,7 @@ em_migrate_dir (EMMigrateSession *session, const char *dirname, const char *full
/* try subfolders anyway? */
goto try_subdirs;
}
-
+
uids = camel_folder_get_uids (old_folder);
for (i = 0; i < uids->len; i++) {
CamelMimeMessage *message;
@@ -684,7 +742,7 @@ em_migrate_filter_file (const char *evolution_dir, const char *filename, CamelEx
xmlDocPtr doc;
int retval;
- path = g_strdup_printf ("%s/evolution/%s", g_get_home_dir (), filename);
+ path = g_build_filename (g_get_home_dir (), "evolution", filename, NULL);
if (!(doc = xmlParseFile (path))) {
/* can't parse - this means nothing to upgrade */
@@ -769,7 +827,7 @@ em_migrate_filter_file (const char *evolution_dir, const char *filename, CamelEx
node = node->next;
}
- path = g_strdup_printf ("%s/mail/%s", evolution_dir, filename);
+ path = g_build_filename (evolution_dir, "mail", filename, NULL);
if ((retval = e_xml_save_file (path, doc)) == -1) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Failed to migrate `%s': %s"),
@@ -783,6 +841,78 @@ em_migrate_filter_file (const char *evolution_dir, const char *filename, CamelEx
return retval;
}
+static int
+em_migrate_pop_uid_caches (const char *evolution_dir, CamelException *ex)
+{
+ GString *oldpath, *newpath;
+ struct dirent *dent;
+ size_t olen, nlen;
+ char *cache_dir;
+ DIR *dir;
+
+ /* open the old cache dir */
+ cache_dir = g_build_filename (g_get_home_dir (), "evolution", "mail", "pop3", NULL);
+ if (!(dir = opendir (cache_dir))) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Failed to migrate pop3 uid caches: %s"),
+ g_strerror (errno));
+ g_warning ("cannot open `%s': %s", cache_dir, strerror (errno));
+ g_free (cache_dir);
+ return -1;
+ }
+
+ oldpath = g_string_new (cache_dir);
+ g_string_append_c (oldpath, '/');
+ olen = oldpath->len;
+ g_free (cache_dir);
+
+ cache_dir = g_build_filename (evolution_dir, "mail", "pop", NULL);
+ if (camel_mkdir (cache_dir, 0777) == -1) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Failed to migrate pop3 uid caches: %s"),
+ g_strerror (errno));
+ g_warning ("cannot create `%s': %s", cache_dir, strerror (errno));
+ g_string_free (oldpath, TRUE);
+ g_free (cache_dir);
+ closedir (dir);
+ return -1;
+ }
+
+ newpath = g_string_new (cache_dir);
+ g_string_append_c (newpath, '/');
+ nlen = newpath->len;
+ g_free (cache_dir);
+
+ while ((dent = readdir (dir))) {
+ if (strncmp (dent->d_name, "cache-pop:__", 12) != 0)
+ continue;
+
+ g_string_truncate (oldpath, olen);
+ g_string_truncate (newpath, nlen);
+
+ g_string_append (oldpath, dent->d_name);
+ g_string_append (newpath, dent->d_name + 12);
+
+ /* strip the trailing '_' */
+ g_string_truncate (newpath, newpath->len - 1);
+
+ if (camel_mkdir (newpath->str, 0777) == -1) {
+ g_warning ("cannot create `%s': %s", newpath->str, strerror (errno));
+ continue;
+ }
+
+ g_string_append (newpath, "/uid-cache");
+ cp (oldpath->str, newpath->str, FALSE);
+ }
+
+ g_string_free (oldpath, TRUE);
+ g_string_free (newpath, TRUE);
+
+ closedir (dir);
+
+ return 0;
+}
+
int
em_migrate (MailComponent *component, CamelException *ex)
@@ -850,5 +980,8 @@ em_migrate (MailComponent *component, CamelException *ex)
if (em_migrate_filter_file (evolution_dir, "vfolders.xml", ex) == -1)
return -1;
+ if (em_migrate_pop_uid_caches (evolution_dir, ex) == -1)
+ return -1;
+
return 0;
}