aboutsummaryrefslogtreecommitdiffstats
path: root/mail/importers/evolution-mbox-importer.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2004-02-13 18:14:30 +0800
committerMichael Zucci <zucchi@src.gnome.org>2004-02-13 18:14:30 +0800
commit39f16a70161b982003faca8b1fea7845a4a4e5fc (patch)
treef757ae0e6cc6957336c07f49781b8bfc50b6f8bc /mail/importers/evolution-mbox-importer.c
parent1f4808666f7070789ada617b9fbb652d4e9512a0 (diff)
downloadgsoc2013-evolution-39f16a70161b982003faca8b1fea7845a4a4e5fc.tar
gsoc2013-evolution-39f16a70161b982003faca8b1fea7845a4a4e5fc.tar.gz
gsoc2013-evolution-39f16a70161b982003faca8b1fea7845a4a4e5fc.tar.bz2
gsoc2013-evolution-39f16a70161b982003faca8b1fea7845a4a4e5fc.tar.lz
gsoc2013-evolution-39f16a70161b982003faca8b1fea7845a4a4e5fc.tar.xz
gsoc2013-evolution-39f16a70161b982003faca8b1fea7845a4a4e5fc.tar.zst
gsoc2013-evolution-39f16a70161b982003faca8b1fea7845a4a4e5fc.zip
use mail-importer to import the mail tree, fix the account stuff to talk
2004-02-13 Not Zed <NotZed@Ximian.com> * importers/netscape-importer.c: use mail-importer to import the mail tree, fix the account stuff to talk directly to mail config. Added cancel button. etc. This is completely untested apart from compiling with no warnings. * importers/mail-importer.c (import_mbox_import): dont re-use the exception for syncing. * importers/evolution-outlook-importer.c: major reworking. Some platform fixes, runs in another thread, simpler/cleaner main loop. This is completely untested apart from compiling with no warnings. * importers/evolution-mbox-importer.c (support_format_fn): we dont want to check the From_ line case insensitive! (create_control_fn): implement this weird api. 2004-02-12 Not Zed <NotZed@Ximian.com> * importers/elm-importer.c: rewrote all importing stuff. * importers/mail-importer.c (mail_importer_import_folders_sync): split out into a recursive function & entry. Now handles mozilla format stuff with a flag. (import_mbox_import): made the cameloperation properly save/restore multiple registrations. svn path=/trunk/; revision=24732
Diffstat (limited to 'mail/importers/evolution-mbox-importer.c')
-rw-r--r--mail/importers/evolution-mbox-importer.c350
1 files changed, 147 insertions, 203 deletions
diff --git a/mail/importers/evolution-mbox-importer.c b/mail/importers/evolution-mbox-importer.c
index a7691b38f0..7e830a207a 100644
--- a/mail/importers/evolution-mbox-importer.c
+++ b/mail/importers/evolution-mbox-importer.c
@@ -2,8 +2,10 @@
/* evolution-mbox-importer.c
*
* Authors: Iain Holmes <iain@ximian.com>
+ * Michael Zucchi <notzed@ximian.com>
*
- * Copyright (C) 2001 Ximian, Inc.
+ * Copyright (C) 2001 Ximian, Inc.
+ * Copyright (C) 2004 Novell, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
@@ -24,25 +26,31 @@
#include <config.h>
#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
#include <stdio.h>
#include <ctype.h>
#include <string.h>
-#include <bonobo/bonobo-object.h>
-#include <bonobo/bonobo-generic-factory.h>
+#include <gtk/gtkhbox.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkmessagedialog.h>
+#include <gtk/gtkprogressbar.h>
+
+#include <bonobo/bonobo-control.h>
#include <camel/camel-exception.h>
-#include <camel/camel-mime-message.h>
-#include <camel/camel-mime-parser.h>
-#include <camel/camel-mime-part.h>
#include <importer/evolution-importer.h>
#include <importer/GNOME_Evolution_Importer.h>
-#include "mail/mail-tools.h"
-#include "mail/mail-component.h"
+#include "mail/em-folder-selection-button.h"
-#include "e-util/e-path.h"
+#include "mail/mail-component.h"
+#include "mail/mail-mt.h"
#include "mail-importer.h"
@@ -56,252 +64,188 @@
#endif
typedef struct {
- MailImporter importer; /* Parent */
+ EvolutionImporter *ii;
- char *filename;
- int num;
+ GMutex *status_lock;
+ char *status_what;
+ int status_pc;
+ int status_timeout_id;
+ CamelOperation *cancel; /* cancel/status port */
- CamelMimeParser *mp;
- gboolean is_folder;
-} MboxImporter;
+ GtkWidget *selector;
+ GtkWidget *label;
+ GtkWidget *progressbar;
+ GtkWidget *dialog;
-/* EvolutionImporter methods */
+ char *uri;
+} MboxImporter;
-static CamelMessageInfo *
-get_info_from_mozilla (const char *mozilla_status,
- gboolean *deleted)
+static void
+process_item_fn(EvolutionImporter *eimporter, CORBA_Object listener, void *data, CORBA_Environment *ev)
{
- unsigned int status;
- CamelMessageInfo *info;
-
- *deleted = FALSE;
-
- status = strtoul (mozilla_status, NULL, 16);
- if (status == 0) {
- return camel_message_info_new ();
- }
-
- if (status & MSG_FLAG_EXPUNGED) {
- *deleted = TRUE;
-
- return NULL;
- }
-
- info = camel_message_info_new ();
-
- if (status & MSG_FLAG_READ)
- info->flags |= CAMEL_MESSAGE_SEEN;
-
- if (status & MSG_FLAG_MARKED)
- info->flags |= CAMEL_MESSAGE_FLAGGED;
-
- if (status & MSG_FLAG_REPLIED)
- info->flags |= CAMEL_MESSAGE_ANSWERED;
-
- return info;
+ /*MboxImporter *importer = data;*/
+ GNOME_Evolution_ImporterListener_ImporterResult result;
+
+ /* This is essentially a NOOP, it merely returns ok/fail and is only called once */
+
+#if 0
+ if (camel_exception_is_set(importer->ex))
+ result = GNOME_Evolution_ImporterListener_BAD_FILE;
+ else
+#endif
+ result = GNOME_Evolution_ImporterListener_OK;
+
+ GNOME_Evolution_ImporterListener_notifyResult(listener, result, FALSE, ev);
}
static void
-process_item_fn (EvolutionImporter *eimporter,
- CORBA_Object listener,
- void *closure,
- CORBA_Environment *ev)
+folder_selected(EMFolderSelectionButton *button, MboxImporter *importer)
{
- MboxImporter *mbi = (MboxImporter *) closure;
- MailImporter *importer = (MailImporter *) mbi;
- gboolean done = FALSE;
- CamelException *ex;
- const char *mozilla_status;
-
- if (importer->folder == NULL) {
- GNOME_Evolution_ImporterListener_notifyResult (listener,
- GNOME_Evolution_ImporterListener_BAD_FILE,
- FALSE, ev);
- }
+ g_free(importer->uri);
+ importer->uri = g_strdup(em_folder_selection_button_get_selection(button));
+}
- if (mbi->is_folder == TRUE) {
- GNOME_Evolution_ImporterListener_notifyResult (listener,
- GNOME_Evolution_ImporterListener_OK,
- FALSE, ev);
- return;
- }
-
- ex = camel_exception_new ();
- if (camel_mime_parser_step (mbi->mp, 0, 0) == CAMEL_MIME_PARSER_STATE_FROM) {
- /* Import the next message */
- CamelMimeMessage *msg;
- CamelMessageInfo *info;
- gboolean deleted;
-
- IN;
- msg = camel_mime_message_new ();
- if (camel_mime_part_construct_from_parser (CAMEL_MIME_PART (msg), mbi->mp) == -1) {
- g_warning ("Failed message %d", mbi->num);
- camel_object_unref (CAMEL_OBJECT (msg));
- done = TRUE;
- } else {
- mozilla_status = camel_medium_get_header (CAMEL_MEDIUM (msg), "X-Mozilla-Status");
- if (mozilla_status != NULL) {
- info = get_info_from_mozilla (mozilla_status, &deleted);
- } else {
- deleted = FALSE;
- info = camel_message_info_new ();
- }
-
- if (deleted == FALSE) {
- /* write the mesg */
- camel_folder_append_message (importer->folder, msg, info, NULL, ex);
- }
-
- if (info)
- camel_message_info_free (info);
-
- camel_object_unref (msg);
- if (camel_exception_is_set (ex)) {
- g_warning ("Failed message %d", mbi->num);
- done = TRUE;
- }
- }
- OUT;
- } else {
- IN;
- /* all messages have now been imported */
- camel_folder_sync (importer->folder, FALSE, ex);
- camel_folder_thaw (importer->folder);
- importer->frozen = FALSE;
- done = TRUE;
- OUT;
- }
-
- if (!done)
- camel_mime_parser_step (mbi->mp, 0, 0);
+static void
+create_control_fn(EvolutionImporter *importer, Bonobo_Control *control, void *data)
+{
+ GtkWidget *hbox, *w;
- camel_exception_free (ex);
+ hbox = gtk_hbox_new(FALSE, FALSE);
+
+ w = gtk_label_new(_("Destination folder:"));
+ gtk_box_pack_start((GtkBox *)hbox, w, FALSE, TRUE, 6);
+
+ w = em_folder_selection_button_new(_("Select folder"), _("Select folder to import into"));
+ /* set selection to Inbox? */
+ g_signal_connect(w, "selected", G_CALLBACK(folder_selected), data);
+ gtk_box_pack_start((GtkBox *)hbox, w, FALSE, TRUE, 6);
+
+ gtk_widget_show_all(hbox);
- GNOME_Evolution_ImporterListener_notifyResult (listener,
- GNOME_Evolution_ImporterListener_OK,
- !done, ev);
- return;
+ /* Another weird-arsed shell api */
+ *control = BONOBO_OBJREF(bonobo_control_new(hbox));
}
static gboolean
-support_format_fn (EvolutionImporter *importer,
- const char *filename,
- void *closure)
+support_format_fn(EvolutionImporter *importer, const char *filename, void *closure)
{
char signature[6];
gboolean ret = FALSE;
int fd, n;
- fd = open (filename, O_RDONLY);
- if (fd == -1)
- return FALSE;
-
- n = read (fd, signature, 5);
- if (n > 0) {
- signature[n] = '\0';
- if (!g_strncasecmp (signature, "From ", 5))
- ret = TRUE;
+ fd = open(filename, O_RDONLY);
+ if (fd != -1) {
+ n = read(fd, signature, 5);
+ ret = n == 5 && memcmp(signature, "From ", 5) == 0;
+ close(fd);
}
- close (fd);
-
return ret;
}
static void
-importer_destroy_cb (void *data, GObject *object)
+importer_destroy_cb(void *data, GObject *object)
{
- MboxImporter *mbi = data;
- MailImporter *importer = data;
+ MboxImporter *importer = data;
- if (importer->folder) {
- if (importer->frozen) {
- camel_folder_sync (importer->folder, FALSE, NULL);
- camel_folder_thaw (importer->folder);
- }
+ if (importer->status_timeout_id)
+ g_source_remove(importer->status_timeout_id);
+ g_free(importer->status_what);
+ g_mutex_free(importer->status_lock);
- camel_object_unref (importer->folder);
- }
+ if (importer->dialog)
+ gtk_widget_destroy(importer->dialog);
- g_free (mbi->filename);
- if (mbi->mp)
- camel_object_unref (mbi->mp);
+ g_free(importer);
+}
- g_free (mbi);
+static void
+mbox_status(CamelOperation *op, const char *what, int pc, void *data)
+{
+ MboxImporter *importer = data;
+
+ if (pc == CAMEL_OPERATION_START)
+ pc = 0;
+ else if (pc == CAMEL_OPERATION_END)
+ pc = 100;
+
+ g_mutex_lock(importer->status_lock);
+ g_free(importer->status_what);
+ importer->status_what = g_strdup(what);
+ importer->status_pc = pc;
+ g_mutex_unlock(importer->status_lock);
}
static gboolean
-load_file_fn (EvolutionImporter *eimporter,
- const char *filename,
- void *closure)
+mbox_status_timeout(void *data)
{
- MboxImporter *mbi;
- MailImporter *importer;
- struct stat buf;
- int fd;
- char *uri;
+ MboxImporter *importer = data;
+ int pc;
+ char *what;
- mbi = (MboxImporter *) closure;
- importer = (MailImporter *) mbi;
+ if (!importer->status_what)
+ return TRUE;
- mbi->filename = g_strdup (filename);
+ g_mutex_lock(importer->status_lock);
+ what = importer->status_what;
+ importer->status_what = NULL;
+ pc = importer->status_pc;
+ g_mutex_unlock(importer->status_lock);
- fd = open (filename, O_RDONLY);
- if (fd == -1) {
- g_warning ("Cannot open file");
- return FALSE;
- }
+ gtk_progress_bar_set_fraction((GtkProgressBar *)importer->progressbar, (gfloat)(pc/100.0));
+ gtk_progress_bar_set_text((GtkProgressBar *)importer->progressbar, what);
+
+ return TRUE;
+}
- fstat (fd, &buf);
- if (S_ISREG (buf.st_mode)) {
- mbi->mp = camel_mime_parser_new ();
- camel_mime_parser_scan_from (mbi->mp, TRUE);
- if (camel_mime_parser_init_with_fd (mbi->mp, fd) == -1) {
- g_warning ("Unable to process spool folder");
- goto fail;
- }
- mbi->is_folder = FALSE;
- } else {
- mbi->is_folder = TRUE;
- }
+static void
+mbox_importer_response(GtkWidget *w, guint button, void *data)
+{
+ MboxImporter *importer = data;
- importer->mstream = NULL;
-#warning "No destination uri"
- uri = NULL;
- if (uri == NULL || *uri == '\0')
- importer->folder = mail_component_get_folder(NULL, MAIL_COMPONENT_FOLDER_INBOX);
- else
- importer->folder = mail_tool_uri_to_folder(uri, 0, NULL);
+ if (button == GTK_RESPONSE_CANCEL
+ && importer->cancel)
+ camel_operation_cancel(importer->cancel);
+}
- if (importer->folder == NULL) {
- g_warning ("Bad folder\n");
- goto fail;
- }
+static gboolean
+load_file_fn(EvolutionImporter *eimporter, const char *filename, void *data)
+{
+ MboxImporter *importer = data;
- if (importer->folder != NULL) {
- camel_folder_freeze (importer->folder);
- importer->frozen = TRUE;
- }
+ importer->dialog = gtk_message_dialog_new(NULL, 0/*GTK_DIALOG_NO_SEPARATOR*/,
+ GTK_MESSAGE_INFO, GTK_BUTTONS_CANCEL,
+ _("Importing `%s'"), filename);
+ gtk_window_set_title (GTK_WINDOW (importer->dialog), _("Importing..."));
- return TRUE;
+ importer->label = gtk_label_new (_("Please wait"));
+ importer->progressbar = gtk_progress_bar_new ();
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (importer->dialog)->vbox), importer->label, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (importer->dialog)->vbox), importer->progressbar, FALSE, FALSE, 0);
+ g_signal_connect(importer->dialog, "response", G_CALLBACK(mbox_importer_response), importer);
+ gtk_widget_show_all(importer->dialog);
- fail:
- camel_object_unref (mbi->mp);
- mbi->mp = NULL;
+ importer->status_timeout_id = g_timeout_add(100, mbox_status_timeout, importer);
+ importer->cancel = camel_operation_new(mbox_status, importer);
- return FALSE;
+ mail_msg_wait(mail_importer_import_mbox(filename, importer->uri, importer->cancel));
+
+ camel_operation_unref(importer->cancel);
+ g_source_remove(importer->status_timeout_id);
+ importer->status_timeout_id = 0;
+
+ return TRUE;
}
BonoboObject *
mbox_importer_new(void)
{
- EvolutionImporter *importer;
MboxImporter *mbox;
mbox = g_new0 (MboxImporter, 1);
- importer = evolution_importer_new(NULL, support_format_fn, load_file_fn, process_item_fn, NULL, mbox);
- g_object_weak_ref(G_OBJECT(importer), importer_destroy_cb, mbox);
+ mbox->status_lock = g_mutex_new();
+ mbox->ii = evolution_importer_new(create_control_fn, support_format_fn, load_file_fn, process_item_fn, NULL, mbox);
+ g_object_weak_ref(G_OBJECT(mbox->ii), importer_destroy_cb, mbox);
- return BONOBO_OBJECT (importer);
+ return BONOBO_OBJECT (mbox->ii);
}