aboutsummaryrefslogtreecommitdiffstats
path: root/mail
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
parentc18d2cf2ea3fe844dcc4d86558dda949e4d2bd59 (diff)
downloadgsoc2013-evolution-fc863cbedf2998f93b1518bac7ce2243a1468372.tar.gz
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')
-rw-r--r--mail/ChangeLog18
-rw-r--r--mail/em-migrate.c149
-rw-r--r--mail/mail-component.c23
-rw-r--r--mail/mail-ops.c31
4 files changed, 164 insertions, 57 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index bd0c19b8db..72f1b12eb3 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,5 +1,23 @@
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().
+
* em-format-html.c (efh_format_address): Removed.
(efh_format_header): Handle address formatting a little
differently to address dwmw's complaints. Also now handles other
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;
}
diff --git a/mail/mail-component.c b/mail/mail-component.c
index a764e1b7c6..a05dbd7526 100644
--- a/mail/mail-component.c
+++ b/mail/mail-component.c
@@ -473,8 +473,6 @@ mail_component_init (MailComponent *component)
{
MailComponentPrivate *priv;
EAccountList *accounts;
- struct stat st;
- char *mail_dir;
priv = g_new0 (MailComponentPrivate, 1);
component->priv = priv;
@@ -493,27 +491,6 @@ mail_component_init (MailComponent *component)
priv->async_event = mail_async_event_new();
priv->store_hash = g_hash_table_new (NULL, NULL);
- /* migrate evolution 1.x folders to 2.0's location/format */
- mail_dir = g_strdup_printf ("%s/mail", priv->base_directory);
- if (stat (mail_dir, &st) == -1) {
- CamelException ex;
-
- camel_exception_init (&ex);
- if (em_migrate (component, &ex) == -1) {
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
- _("The following error occured while migrating your mail data:\n%s"),
- camel_exception_get_description (&ex));
-
- g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog);
- gtk_widget_show (dialog);
-
- camel_exception_clear (&ex);
- }
- }
- g_free (mail_dir);
-
setup_local_store (component);
accounts = mail_config_get_accounts ();
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index 1f5e75cb42..32eb68b4f1 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -221,38 +221,17 @@ static char *
uid_cachename_hack (CamelStore *store)
{
CamelURL *url = CAMEL_SERVICE (store)->url;
- char *encoded_url, *filename, *old_location;
- struct stat st;
+ char *encoded_url, *filename;
+ const char *evolution_dir;
- encoded_url = g_strdup_printf ("pop://%s%s%s@%s/", url->user,
+ encoded_url = g_strdup_printf ("%s%s%s@%s", url->user,
url->authmech ? ";auth=" : "",
url->authmech ? url->authmech : "",
url->host);
e_filename_make_safe (encoded_url);
- filename = g_strdup_printf ("%s/mail/pop3/cache-%s",
- mail_component_peek_base_directory (mail_component_peek ()), encoded_url);
-
- /* lame hack, but we can't expect user's to actually migrate
- their cache files - brain power requirements are too
- high. */
- if (stat (filename, &st) == -1) {
- /* This is either the first time the user has checked
- mail with this POP provider or else their cache
- file is in the old location... */
- old_location = g_strdup_printf ("%s/config/cache-%s",
- mail_component_peek_base_directory (mail_component_peek ()),
- encoded_url);
- if (stat (old_location, &st) == -1) {
- /* old location doesn't exist either so use the new location */
- g_free (old_location);
- } else {
- /* old location exists, so I guess we use the old cache file location */
- g_free (filename);
- filename = old_location;
- }
- }
-
+ evolution_dir = mail_component_peek_base_directory (mail_component_peek ());
+ filename = g_build_filename (evolution_dir, "mail", "pop", encoded_url, "uid-cache", NULL);
g_free (encoded_url);
return filename;