aboutsummaryrefslogtreecommitdiffstats
path: root/mail/importers/elm-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/elm-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/elm-importer.c')
-rw-r--r--mail/importers/elm-importer.c488
1 files changed, 184 insertions, 304 deletions
diff --git a/mail/importers/elm-importer.c b/mail/importers/elm-importer.c
index 63f282fd48..2793f58f50 100644
--- a/mail/importers/elm-importer.c
+++ b/mail/importers/elm-importer.c
@@ -1,8 +1,8 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* elm-importer.c
*
- * Authors:
- * Iain Holmes <iain@ximian.com>
+ * Authors: Iain Holmes <iain@ximian.com>
+ * Michael Zucchi <notzed@ximian.com>
*
* Copyright 2001 Ximian, Inc. (www.ximian.com)
*
@@ -38,15 +38,10 @@
#include <gconf/gconf.h>
#include <gconf/gconf-client.h>
+#include <camel/camel-operation.h>
+
#include <bonobo/bonobo-object.h>
#include <bonobo/bonobo-control.h>
-#include <bonobo/bonobo-context.h>
-#include <bonobo/bonobo-generic-factory.h>
-#include <bonobo/bonobo-main.h>
-#include <bonobo/bonobo-exception.h>
-#include <bonobo/bonobo-moniker-util.h>
-
-#include <bonobo-activation/bonobo-activation.h>
#include <importer/evolution-intelligent-importer.h>
#include <importer/evolution-importer-client.h>
@@ -54,6 +49,8 @@
#include "mail-importer.h"
+#include "mail/mail-mt.h"
+
#define KEY "elm-mail-imported"
/*#define SUPER_IMPORTER_DEBUG*/
@@ -66,33 +63,23 @@
typedef struct {
EvolutionIntelligentImporter *ii;
- GList *dir_list;
+ GHashTable *prefs;
- int progress_count;
- int more;
- EvolutionImporterResult result;
+ GMutex *status_lock;
+ char *status_what;
+ int status_pc;
+ int status_timeout_id;
+ CamelOperation *cancel; /* cancel/status port */
- GNOME_Evolution_Importer importer;
- EvolutionImporterListener *listener;
-
GtkWidget *mail;
gboolean do_mail;
+ gboolean done_mail;
GtkWidget *dialog;
GtkWidget *label;
GtkWidget *progressbar;
} ElmImporter;
-typedef struct {
- char *parent;
- char *foldername;
- char *path;
-} ElmFolder;
-
-static GHashTable *elm_prefs = NULL;
-
-static void import_next (ElmImporter *importer);
-
static GtkWidget *
create_importer_gui (ElmImporter *importer)
{
@@ -103,7 +90,6 @@ create_importer_gui (ElmImporter *importer)
importer->label = gtk_label_new (_("Please wait"));
importer->progressbar = gtk_progress_bar_new ();
- gtk_progress_set_activity_mode (GTK_PROGRESS (importer->progressbar), TRUE);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), importer->label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), importer->progressbar, FALSE, FALSE, 0);
@@ -116,7 +102,7 @@ elm_store_settings (ElmImporter *importer)
GConfClient *gconf;
gconf = gconf_client_get_default ();
- gconf_client_set_bool (gconf, "/apps/evolution/importer/elm/mail", importer->do_mail, NULL);
+ gconf_client_set_bool (gconf, "/apps/evolution/importer/elm/mail", importer->done_mail, NULL);
g_object_unref(gconf);
}
@@ -125,110 +111,27 @@ elm_restore_settings (ElmImporter *importer)
{
GConfClient *gconf = gconf_client_get_default ();
- importer->do_mail = gconf_client_get_bool (gconf, "/apps/evolution/importer/elm/mail", NULL);
-}
-
-static void
-importer_cb (EvolutionImporterListener *listener,
- EvolutionImporterResult result,
- gboolean more_items,
- void *data)
-{
- ElmImporter *importer = (ElmImporter *) data;
-
- importer->result = result;
- importer->more = more_items;
-}
-
-static gboolean
-elm_import_file (ElmImporter *importer,
- const char *path,
- const char *folderpath)
-{
- CORBA_boolean result;
- CORBA_Environment ev;
- CORBA_Object objref;
- char *str, *uri;
- struct stat st;
-
- str = g_strdup_printf (_("Importing %s as %s"), path, folderpath);
- gtk_label_set_text (GTK_LABEL (importer->label), str);
- g_free (str);
- while (g_main_context_iteration(NULL, FALSE))
- ;
-
- uri = mail_importer_make_local_folder(folderpath);
- if (!uri)
- return FALSE;
-
- /* if its a dir, we just create it, but dont add anything */
- if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
- g_free(uri);
- /* this is ok, we return false to say we haven't launched an async task */
- return FALSE;
- }
-
- CORBA_exception_init(&ev);
-#warning "loadFile needs a destination path"
-
- result = GNOME_Evolution_Importer_loadFile (importer->importer, path, &ev);
- g_free(uri);
- if (ev._major != CORBA_NO_EXCEPTION || result == FALSE) {
- g_warning ("Exception here: %s", CORBA_exception_id (&ev));
- CORBA_exception_free (&ev);
- return FALSE;
- }
-
- /* process all items in a direct loop */
- importer->listener = evolution_importer_listener_new (importer_cb, importer);
- objref = bonobo_object_corba_objref (BONOBO_OBJECT (importer->listener));
- do {
- importer->progress_count++;
- if ((importer->progress_count & 0xf) == 0)
- gtk_progress_bar_pulse(GTK_PROGRESS_BAR(importer->progressbar));
-
- importer->result = -1;
- GNOME_Evolution_Importer_processItem (importer->importer, objref, &ev);
- if (ev._major != CORBA_NO_EXCEPTION) {
- g_warning ("Exception: %s", CORBA_exception_id (&ev));
- break;
- }
-
- while (importer->result == -1 || g_main_context_pending(NULL))
- g_main_context_iteration(NULL, TRUE);
- } while (importer->more);
-
- bonobo_object_unref((BonoboObject *)importer->listener);
-
- CORBA_exception_free (&ev);
-
- return FALSE;
+ importer->done_mail = gconf_client_get_bool (gconf, "/apps/evolution/importer/elm/mail", NULL);
+ g_object_unref(gconf);
}
static void
-parse_elm_rc (const char *elmrc)
+parse_elm_rc(ElmImporter *importer, const char *elmrc)
{
- static gboolean parsed = FALSE;
char line[4096];
FILE *handle;
- gboolean exists;
- if (parsed == TRUE)
+ if (importer->prefs)
return;
- elm_prefs = g_hash_table_new (g_str_hash, g_str_equal);
+ importer->prefs = g_hash_table_new(g_str_hash, g_str_equal);
- exists = g_file_exists (elmrc);
- if (exists == FALSE) {
- parsed = TRUE;
+ if (!g_file_exists(elmrc))
return;
- }
handle = fopen (elmrc, "r");
- if (handle == NULL) {
- parsed = TRUE;
+ if (handle == NULL)
return;
- }
while (fgets (line, 4096, handle) != NULL) {
char *linestart, *end;
@@ -264,183 +167,181 @@ parse_elm_rc (const char *elmrc)
*end = 0;
value = g_strdup (linestart);
- g_hash_table_insert (elm_prefs, key, value);
+ g_hash_table_insert (importer->prefs, key, value);
}
- parsed = TRUE;
fclose (handle);
}
static char *
-elm_get_rc_value (const char *value)
+elm_get_rc_value(ElmImporter *importer, const char *value)
{
- if (elm_prefs == NULL)
- return NULL;
-
- return g_hash_table_lookup (elm_prefs, value);
+ return g_hash_table_lookup(importer->prefs, value);
}
static gboolean
-elm_can_import (EvolutionIntelligentImporter *ii,
- void *closure)
+elm_can_import(EvolutionIntelligentImporter *ii, void *closure)
{
ElmImporter *importer = closure;
- char *elmdir, *maildir, *aliasfile;
- char *elmrc;
- gboolean exists, mailexists, aliasexists;
- gboolean mail;
+ const char *maildir;
+ char *elmdir, *elmrc;
+ gboolean mailexists, exists;
+#if 0
+ char *aliasfile;
+ gboolean aliasexists;
+#endif
struct stat st;
- GConfClient *gconf = gconf_client_get_default();
- mail = gconf_client_get_bool(gconf, "/apps/evolution/importer/elm/mail-imported", NULL);
- if (mail)
- return FALSE;
-
- importer->do_mail = !mail;
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (importer->mail),
- importer->do_mail);
+ elm_restore_settings(importer);
+
+ importer->do_mail = !importer->done_mail;
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (importer->mail), importer->do_mail);
- elmdir = gnome_util_prepend_user_home (".elm");
+ elmdir = g_build_filename(g_get_home_dir(), ".elm", NULL);
exists = lstat(elmdir, &st) == 0 && S_ISDIR(st.st_mode);
-
g_free (elmdir);
- if (exists == FALSE)
+ if (!exists)
return FALSE;
- elmrc = gnome_util_prepend_user_home (".elm/elmrc");
- parse_elm_rc (elmrc);
+ elmrc = g_build_filename(g_get_home_dir(), ".elm/elmrc", NULL);
+ parse_elm_rc (importer, elmrc);
+ g_free(elmrc);
- maildir = elm_get_rc_value ("maildir");
- if (maildir == NULL) {
- maildir = g_strdup ("Mail");
- } else {
- maildir = g_strdup (maildir);
- }
+ maildir = elm_get_rc_value(importer, "maildir");
+ if (maildir == NULL)
+ maildir = "Mail";
- if (!g_path_is_absolute (maildir)) {
- elmdir = gnome_util_prepend_user_home (maildir);
- } else {
+ if (!g_path_is_absolute (maildir))
+ elmdir = g_build_filename(g_get_home_dir(), maildir, NULL);
+ else
elmdir = g_strdup (maildir);
- }
-
- g_free (maildir);
mailexists = lstat(elmdir, &st) == 0 && S_ISDIR(st.st_mode);
g_free (elmdir);
+#if 0
aliasfile = gnome_util_prepend_user_home (".elm/aliases");
aliasexists = lstat(aliasfile, &st) == 0 && S_ISREG(st.st_mode);
g_free (aliasfile);
exists = (aliasexists || mailexists);
+#endif
- return exists;
+ return mailexists;
}
-static void
-import_next (ElmImporter *importer)
+/* Almost all that follows is a direct copy of pine-importer.c with
+ * search and replace run on it */
+struct _elm_import_msg {
+ struct _mail_msg msg;
+
+ ElmImporter *importer;
+};
+
+static char *
+elm_import_describe (struct _mail_msg *mm, int complete)
{
- ElmFolder *data;
+ return g_strdup (_("Importing Elm data"));
+}
-trynext:
- if (importer->dir_list) {
- char *folder;
- GList *l;
- int ok;
+static MailImporterSpecial elm_special_folders[] = {
+ { "received", "Inbox" },
+ { 0 },
+};
- l = importer->dir_list;
- data = l->data;
+static void
+elm_import_import(struct _mail_msg *mm)
+{
+ struct _elm_import_msg *m = (struct _elm_import_msg *) mm;
- folder = g_concat_dir_and_file (data->parent, data->foldername);
+ if (m->importer->do_mail) {
+ const char *maildir;
+ char *elmdir;
- importer->dir_list = l->next;
- g_list_free_1(l);
+ maildir = elm_get_rc_value(m->importer, "maildir");
+ if (maildir == NULL)
+ maildir = "Mail";
- ok = elm_import_file (importer, data->path, folder);
- g_free (folder);
- g_free (data->parent);
- g_free (data->path);
- g_free (data->foldername);
- g_free (data);
- /* its ugly, but so is everything else in this file */
- if (!ok)
- goto trynext;
- } else {
- bonobo_object_unref((BonoboObject *)importer->ii);
+ if (!g_path_is_absolute(maildir))
+ elmdir = g_build_filename(g_get_home_dir(), maildir, NULL);
+ else
+ elmdir = g_strdup(maildir);
+
+ mail_importer_import_folders_sync(elmdir, elm_special_folders, 0, m->importer->cancel);
}
}
static void
-scan_dir (ElmImporter *importer,
- const char *orig_parent,
- const char *dirname)
+elm_import_imported(struct _mail_msg *mm)
{
- DIR *maildir;
- struct stat buf;
- struct dirent *current;
- char *str;
-
- maildir = opendir (dirname);
- if (maildir == NULL) {
- g_warning ("Could not open %s\nopendir returned: %s",
- dirname, g_strerror (errno));
- return;
- }
+}
+
+static void
+elm_import_free(struct _mail_msg *mm)
+{
+ /*struct _elm_import_msg *m = (struct _elm_import_msg *)mm;*/
+}
+
+static struct _mail_msg_op elm_import_op = {
+ elm_import_describe,
+ elm_import_import,
+ elm_import_imported,
+ elm_import_free,
+};
+
+static int
+mail_importer_elm_import(ElmImporter *importer)
+{
+ struct _elm_import_msg *m;
+ int id;
+
+ m = mail_msg_new(&elm_import_op, NULL, sizeof (*m));
+ m->importer = importer;
+
+ id = m->msg.seq;
- str = g_strdup_printf (_("Scanning %s"), dirname);
- gtk_label_set_text (GTK_LABEL (importer->label), str);
- g_free (str);
+ e_thread_put(mail_thread_queued, (EMsg *) m);
- while (gtk_events_pending ()) {
- gtk_main_iteration ();
- }
+ return id;
+}
- current = readdir (maildir);
- while (current) {
- ElmFolder *pf;
- char *fullname;
-
- /* Ignore . and .. */
- if (current->d_name[0] == '.') {
- if (current->d_name[1] == '\0' ||
- (current->d_name[1] == '.' && current->d_name[2] == '\0')) {
- current = readdir (maildir);
- continue;
- }
- }
-
- fullname = g_concat_dir_and_file (dirname, current->d_name);
- if (stat (fullname, &buf) == -1) {
- g_warning ("Could not stat %s\nstat returned: %s",
- fullname, g_strerror (errno));
- current = readdir (maildir);
- g_free (fullname);
- continue;
- }
-
- if (S_ISREG (buf.st_mode)) {
- pf = g_new (ElmFolder, 1);
- pf->path = g_strdup (fullname);
- pf->parent = g_strdup (orig_parent);
- pf->foldername = g_strdup (current->d_name);
- importer->dir_list = g_list_append (importer->dir_list, pf);
- } else if (S_ISDIR (buf.st_mode)) {
- char *subdir;
-
- pf = g_new (ElmFolder, 1);
- pf->path = NULL;
- pf->parent = g_strdup (orig_parent);
- pf->foldername = g_strdup (current->d_name);
- importer->dir_list = g_list_append (importer->dir_list, pf);
-
- subdir = g_concat_dir_and_file (orig_parent, current->d_name);
- scan_dir (importer, subdir, fullname);
- g_free (subdir);
- }
-
- g_free (fullname);
- current = readdir (maildir);
- }
+static void
+elm_status(CamelOperation *op, const char *what, int pc, void *data)
+{
+ ElmImporter *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
+elm_status_timeout(void *data)
+{
+ ElmImporter *importer = data;
+ int pc;
+ char *what;
+
+ if (!importer->status_what)
+ return TRUE;
+
+ g_mutex_lock(importer->status_lock);
+ what = importer->status_what;
+ importer->status_what = NULL;
+ pc = importer->status_pc;
+ g_mutex_unlock(importer->status_lock);
+
+ gtk_progress_bar_set_fraction((GtkProgressBar *)importer->progressbar, (gfloat)(pc/100.0));
+ gtk_progress_bar_set_text((GtkProgressBar *)importer->progressbar, what);
+
+ return TRUE;
}
static void
@@ -448,60 +349,53 @@ elm_create_structure (EvolutionIntelligentImporter *ii,
void *closure)
{
ElmImporter *importer = closure;
- char *maildir;
- /* Reference our object so when the shell release_unrefs us
- we will still exist and not go byebye */
- bonobo_object_ref (BONOBO_OBJECT (ii));
+ if (importer->do_mail) {
+ importer->dialog = create_importer_gui(importer);
+ gtk_widget_show_all(importer->dialog);
+ importer->status_timeout_id = g_timeout_add(100, elm_status_timeout, importer);
+ importer->cancel = camel_operation_new(elm_status, importer);
- elm_store_settings (importer);
-
- if (importer->do_mail == TRUE) {
- char *elmdir;
- GConfClient *gconf = gconf_client_get_default();
+ mail_msg_wait(mail_importer_elm_import(importer));
- importer->dialog = create_importer_gui (importer);
- gtk_widget_show_all (importer->dialog);
- while (gtk_events_pending ()) {
- gtk_main_iteration ();
- }
+ camel_operation_unref(importer->cancel);
+ g_source_remove(importer->status_timeout_id);
+ importer->status_timeout_id = 0;
- gconf_client_set_bool(gconf, "/apps/evolution/importer/elm/mail-imported", TRUE, NULL);
-
- maildir = elm_get_rc_value ("maildir");
- if (maildir == NULL) {
- maildir = g_strdup ("Mail");
- } else {
- maildir = g_strdup (maildir);
- }
-
- if (!g_path_is_absolute (maildir)) {
- elmdir = gnome_util_prepend_user_home (maildir);
- } else {
- elmdir = g_strdup (maildir);
- }
-
- g_free (maildir);
-
- scan_dir (importer, "/", elmdir);
- g_free (elmdir);
-
- /* Import them */
- import_next (importer);
+ importer->done_mail = TRUE;
}
+ elm_store_settings (importer);
+
bonobo_object_unref (BONOBO_OBJECT (ii));
}
static void
+free_pref(void *key, void *value, void *data)
+{
+ g_free(key);
+ g_free(value);
+}
+
+static void
elm_destroy_cb (ElmImporter *importer, GtkObject *object)
{
- elm_store_settings (importer);
+ elm_store_settings(importer);
+
+ if (importer->status_timeout_id)
+ g_source_remove(importer->status_timeout_id);
+ g_free(importer->status_what);
+ g_mutex_free(importer->status_lock);
if (importer->dialog)
gtk_widget_destroy(importer->dialog);
- bonobo_object_release_unref (importer->importer, NULL);
+ if (importer->prefs) {
+ g_hash_table_foreach(importer->prefs, free_pref, NULL);
+ g_hash_table_destroy(importer->prefs);
+ }
+
+ g_free(importer);
}
/* Fun initialisation stuff */
@@ -539,26 +433,12 @@ elm_intelligent_importer_new(void)
EvolutionIntelligentImporter *importer;
BonoboControl *control;
ElmImporter *elm;
- CORBA_Environment ev;
char *message = N_("Evolution has found Elm mail files\n"
"Would you like to import them into Evolution?");
elm = g_new0 (ElmImporter, 1);
-
- CORBA_exception_init (&ev);
-
+ elm->status_lock = g_mutex_new();
elm_restore_settings (elm);
-
- elm->importer = bonobo_activation_activate_from_id (MBOX_IMPORTER_IID, 0, NULL, &ev);
- if (ev._major != CORBA_NO_EXCEPTION) {
- g_free (elm);
- g_warning ("Could not start MBox importer\n%s",
- CORBA_exception_id (&ev));
- CORBA_exception_free (&ev);
- return NULL;
- }
- CORBA_exception_free (&ev);
-
importer = evolution_intelligent_importer_new (elm_can_import,
elm_create_structure,
_("Elm"),
@@ -566,8 +446,8 @@ elm_intelligent_importer_new(void)
g_object_weak_ref(G_OBJECT (importer), (GWeakNotify)elm_destroy_cb, elm);
elm->ii = importer;
- control = create_checkboxes_control (elm);
- bonobo_object_add_interface (BONOBO_OBJECT (importer),
- BONOBO_OBJECT (control));
- return BONOBO_OBJECT (importer);
+ control = create_checkboxes_control(elm);
+ bonobo_object_add_interface(BONOBO_OBJECT(importer), BONOBO_OBJECT(control));
+
+ return BONOBO_OBJECT(importer);
}