From c4f6086c2948f3384dd95393f7ea737db6143682 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 10 Apr 2000 14:39:15 +0000 Subject: use camel_movemail when fetching mail from an mbox store. This leaves * mail-ops.c (fetch_mail): use camel_movemail when fetching mail from an mbox store. This leaves behind temp files for now, because CamelMboxFolder::delete is too confused to use, and NotZed is rewriting CamelMboxFolder, so I'm not going to bother to try to fix it. svn path=/trunk/; revision=2359 --- mail/mail-ops.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 14 deletions(-) (limited to 'mail/mail-ops.c') diff --git a/mail/mail-ops.c b/mail/mail-ops.c index 405eddec4b..edb3bf0805 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -24,6 +24,7 @@ */ #include +#include #include #include "camel/camel.h" #include "mail-ops.h" @@ -86,22 +87,83 @@ fetch_mail (GtkWidget *button, gpointer user_data) } ex = camel_exception_new (); - store = camel_session_get_store (default_session->session, url, ex); - if (!store) { - mail_exception_dialog ("Unable to get new mail", ex, window); - goto cleanup; - } - camel_service_connect_with_url (CAMEL_SERVICE (store), url, ex); - if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) { - mail_exception_dialog ("Unable to get new mail", ex, window); - goto cleanup; - } - folder = camel_store_get_folder (store, "inbox", ex); - if (!folder) { - mail_exception_dialog ("Unable to get new mail", ex, window); - goto cleanup; + /* If fetching mail from an mbox store, safely copy it to a + * temporary store first. + */ + if (!strncmp (url, "mbox:", 5)) { + char *tmp_mbox, *source; + int tmpfd; + + tmp_mbox = g_strdup_printf ("%s/movemail.XXXX", + evolution_folders_dir); +#ifdef HAVE_MKSTEMP + tmpfd = mkstemp (tmp_mbox); +#else + if (mktemp (tmp_mbox)) { + tmpfd = open (tmp_mbox, O_RDWR | O_CREAT | O_EXCL, + S_IRUSR | S_IWUSR); + } else + tmpfd = -1; +#endif + if (tmpfd == -1) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + "Couldn't create temporary " + "mbox: %s", g_strerror (errno)); + mail_exception_dialog ("Unable to move mail", ex, + window); + goto cleanup; + } + close (tmpfd); + + /* Skip over "mbox://" plus host part (if any) or url. */ + source = strchr (url + 7, '/'); + + switch (camel_movemail (source, tmp_mbox, ex)) { + case -1: + mail_exception_dialog ("Unable to move mail", ex, + window); + /* FALL THROUGH */ + + case 0: + unlink (tmp_mbox); + g_free (tmp_mbox); + goto cleanup; + } + + folder = camel_store_get_folder (default_session->store, + strrchr (tmp_mbox, '/') + 1, + ex); + if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) { + mail_exception_dialog ("Unable to move mail", ex, + window); + g_free (tmp_mbox); + goto cleanup; + } + } else { + store = camel_session_get_store (default_session->session, + url, ex); + if (!store) { + mail_exception_dialog ("Unable to get new mail", + ex, window); + goto cleanup; + } + camel_service_connect_with_url (CAMEL_SERVICE (store), + url, ex); + if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) { + mail_exception_dialog ("Unable to get new mail", + ex, window); + goto cleanup; + } + + folder = camel_store_get_folder (store, "inbox", ex); + if (!folder) { + mail_exception_dialog ("Unable to get new mail", + ex, window); + goto cleanup; + } } + camel_folder_open (folder, FOLDER_OPEN_READ, ex); if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) { mail_exception_dialog ("Unable to get new mail", ex, window); -- cgit v1.2.3