aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog12
-rw-r--r--mail/component-factory.c4
-rw-r--r--mail/evolution-mbox-importer.c217
-rw-r--r--mail/evolution-mbox-importer.h32
-rw-r--r--mail/evolution-outlook-importer.c156
-rw-r--r--mail/evolution-outlook-importer.h32
-rw-r--r--mail/mail-importer.c154
-rw-r--r--mail/mail-importer.h43
-rw-r--r--mail/mail-local.c13
-rw-r--r--mail/mail-local.h2
10 files changed, 578 insertions, 87 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 1bdf341003..b5ab8c1e41 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,15 @@
+2001-01-25 Iain Holmes <iain@ximian.com>
+
+ * component-factory.c (component_factory_init): Init the mail
+ mail importers.
+
+ * mail-local.[ch] (mail_local_lookup_folder): retrieve the local
+ folder given by the name.
+
+ * mail-importer.[ch]: Basic functions for all importers to use.
+
+ * evolution-mbox-importer.[ch]: Mbox importer.
+
2001-01-25 Jeffrey Stedfast <fejj@ximian.com>
The following fixes seem to clear up the problem of new mail not
being shown in the Inbox and/or other folders where mail had been
diff --git a/mail/component-factory.c b/mail/component-factory.c
index 38a71b8596..89c29bc2d3 100644
--- a/mail/component-factory.c
+++ b/mail/component-factory.c
@@ -41,6 +41,7 @@
#include "mail-local.h"
#include "mail-session.h"
#include "mail-mt.h"
+#include "mail-importer.h"
#include "openpgp-utils.h"
#include <gal/widgets/e-gui-utils.h>
@@ -267,6 +268,8 @@ component_fn (BonoboGenericFactory *factory, void *closure)
GTK_SIGNAL_FUNC (owner_set_cb), NULL);
gtk_signal_connect (GTK_OBJECT (shell_component), "owner_unset",
GTK_SIGNAL_FUNC (owner_unset_cb), NULL);
+ gtk_signal_connect (GTK_OBJECT (shell_component), "destroy",
+ GTK_SIGNAL_FUNC (owner_unset_cb), NULL);
return BONOBO_OBJECT (shell_component);
}
@@ -285,6 +288,7 @@ component_factory_init (void)
component_fn, NULL);
summary_factory = bonobo_generic_factory_new (SUMMARY_FACTORY_ID,
summary_fn, NULL);
+ mail_importer_init ();
if (component_factory == NULL || summary_factory == NULL) {
e_notice (NULL, GNOME_MESSAGE_BOX_ERROR,
diff --git a/mail/evolution-mbox-importer.c b/mail/evolution-mbox-importer.c
new file mode 100644
index 0000000000..3556f2b68f
--- /dev/null
+++ b/mail/evolution-mbox-importer.c
@@ -0,0 +1,217 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* evolution-mbox-importer.c
+ *
+ * Authors: Iain Holmes <iain@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bonobo/bonobo-object.h>
+#include <bonobo/bonobo-generic-factory.h>
+
+#include <stdio.h>
+
+#include <importer/evolution-importer.h>
+#include <importer/GNOME_Evolution_Importer.h>
+
+#include "mail-importer.h"
+
+#include <camel/camel-exception.h>
+
+typedef struct {
+ MailImporter importer; /* Parent */
+
+ char *filename;
+ FILE *handle;
+ off_t size;
+} MboxImporter;
+
+
+/* EvolutionImporter methods */
+
+static void
+process_item_fn (EvolutionImporter *eimporter,
+ CORBA_Object listener,
+ void *closure,
+ CORBA_Environment *ev)
+{
+ MboxImporter *mbi = (MboxImporter *) closure;
+ MailImporter *importer = (MailImporter *) mbi;
+ CamelException *ex;
+ static char *line = NULL;
+
+ if (line == NULL)
+ line = g_new0 (char, 4096);
+
+ if (line != NULL) {
+ /* We had a From line the last time
+ so just add it and start again */
+ mail_importer_add_line (importer, line, FALSE);
+ }
+
+ if (fgets (line, 4096, mbi->handle) == NULL) {
+ if (*line != '\0')
+ mail_importer_add_line (importer, line, TRUE);
+ /* Must be the end */
+
+ g_free (line);
+ line = NULL;
+ GNOME_Evolution_ImporterListener_notifyResult (listener,
+ GNOME_Evolution_ImporterListener_OK,
+ FALSE, ev);
+
+ ex = camel_exception_new ();
+ camel_folder_thaw (importer->folder);
+ camel_folder_sync (importer->folder, FALSE, ex);
+ camel_exception_free (ex);
+ fclose (mbi->handle);
+ mbi->handle = NULL;
+ return;
+ }
+
+ mail_importer_add_line (importer, line, FALSE);
+ while (strncmp (line, "From ", 5) != 0) {
+ mail_importer_add_line (importer, line, FALSE);
+
+ if (fgets (line, 4096, mbi->handle) == NULL) {
+ if (*line != '\0')
+ mail_importer_add_line (importer, line, TRUE);
+
+ g_free (line);
+ line = NULL;
+ GNOME_Evolution_ImporterListener_notifyResult (listener,
+ GNOME_Evolution_ImporterListener_OK,
+ FALSE, ev);
+ ex = camel_exception_new ();
+ camel_folder_thaw (importer->folder);
+ camel_folder_sync (importer->folder, FALSE, ex);
+ camel_exception_free (ex);
+ fclose (mbi->handle);
+ mbi->handle = NULL;
+ return;
+ }
+ }
+
+ mail_importer_add_line (importer, "\0", TRUE);
+ GNOME_Evolution_ImporterListener_notifyResult (listener,
+ GNOME_Evolution_ImporterListener_OK,
+ TRUE, ev);
+
+ return;
+}
+
+static gboolean
+support_format_fn (EvolutionImporter *importer,
+ const char *filename,
+ void *closure)
+{
+ FILE *handle;
+ char signature[5];
+
+ handle = fopen (filename, "rb");
+ if (handle == NULL)
+ return FALSE; /* Can't open file: Can't support it :) */
+
+ /* SIGNATURE */
+ fread (&signature, 5, 1, handle);
+ if (strcmp (signature, "From ") == 0) {
+ fclose (handle);
+ return TRUE;
+ }
+
+ fclose (handle);
+ return FALSE;
+}
+
+static void
+importer_destroy_cb (GtkObject *object,
+ MboxImporter *mbi)
+{
+ MailImporter *importer;
+
+ importer = (MailImporter *) mbi;
+ if (importer->folder)
+ camel_object_unref (CAMEL_OBJECT (importer->folder));
+
+ g_free (mbi->filename);
+ if (mbi->handle)
+ fclose (mbi->handle);
+
+ g_free (mbi);
+}
+
+static gboolean
+load_file_fn (EvolutionImporter *eimporter,
+ const char *filename,
+ void *closure)
+{
+ MboxImporter *mbi;
+ MailImporter *importer;
+ struct stat buf;
+
+ mbi = (MboxImporter *) closure;
+ importer = (MailImporter *) mbi;
+
+ mbi->filename = g_strdup (filename);
+
+ mbi->handle = fopen (filename, "rb");
+ if (mbi->handle == NULL) {
+ g_warning ("Cannot open file");
+ return FALSE;
+ }
+
+ /* Get size of file */
+ if (stat (filename, &buf) == -1) {
+ g_warning ("Cannot stat file");
+ return FALSE;
+ }
+
+ mbi->size = buf.st_size;
+
+ importer->mstream = NULL;
+ importer->folder = mail_importer_get_folder ("Inbox", NULL);
+
+ if (importer->folder == NULL){
+ g_print ("Bad folder\n");
+ return FALSE;
+ }
+
+ camel_folder_freeze (importer->folder);
+ return TRUE;
+}
+
+BonoboObject *
+mbox_factory_fn (BonoboGenericFactory *_factory,
+ void *closure)
+{
+ EvolutionImporter *importer;
+ MboxImporter *mbox;
+
+ mbox = g_new0 (MboxImporter, 1);
+ importer = evolution_importer_new (support_format_fn, load_file_fn,
+ process_item_fn, NULL, mbox);
+ gtk_signal_connect (GTK_OBJECT (importer), "destroy",
+ GTK_SIGNAL_FUNC (importer_destroy_cb), mbox);
+
+ return BONOBO_OBJECT (importer);
+}
+
diff --git a/mail/evolution-mbox-importer.h b/mail/evolution-mbox-importer.h
new file mode 100644
index 0000000000..bdf4190150
--- /dev/null
+++ b/mail/evolution-mbox-importer.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* evolution-mbox-importer.h
+ *
+ * Authors: Iain Holmes <iain@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _EVOLUTION_MBOX_IMPORTER_H_
+#define _EVOLUTION_MBOX_IMPORTER_H_
+
+#define MBOX_FACTORY_IID "OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory"
+
+BonoboObject *mbox_factory_fn (BonoboGenericFactory *_factory,
+ void *closure);
+
+#endif
diff --git a/mail/evolution-outlook-importer.c b/mail/evolution-outlook-importer.c
index 105bc7ca83..04b2e8a3b0 100644
--- a/mail/evolution-outlook-importer.c
+++ b/mail/evolution-outlook-importer.c
@@ -1,35 +1,53 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* evolution-outlook-importer.c
+ *
+ * Authors: Iain Holmes <iain@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
#include <config.h>
-#include <bonobo.h>
-#include <gnome.h>
-#include <liboaf/liboaf.h>
+#endif
+
+#include <bonobo/bonobo-object.h>
+#include <bonobo/bonobo-generic-factory.h>
+
#include <stdio.h>
#include <importer/evolution-importer.h>
#include <importer/GNOME_Evolution_Importer.h>
-#include <camel/camel-session.h>
-#include <camel/camel-folder.h>
-#include <camel/camel-store.h>
-#include <camel/camel-mime-message.h>
-#include <camel/camel-stream-mem.h>
-#include <camel/camel-exception.h>
-#include <camel/camel-url.h>
-
-#define COMPONENT_FACTORY_IID "OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory"
+#include "mail-importer.h"
-static BonoboGenericFactory *factory = NULL;
+#include <camel/camel-exception.h>
+extern char *evolution_dir;
typedef struct {
+ MailImporter importer;
+
char *filename;
gboolean oe4; /* Is file OE4 or not? */
FILE *handle;
fpos_t pos;
off_t size;
- CamelStream *mstream;
- CamelFolder *folder;
-
gboolean busy;
} OutlookImporter;
@@ -46,55 +64,19 @@ typedef struct oe_msg_segmentheader oe_msg_segmentheader;
/* EvolutionImporter methods */
-static void
-add_line (OutlookImporter *oli,
- const char *str,
- gboolean finished)
-{
- CamelMimeMessage *msg;
- CamelMessageInfo *info;
- CamelException *ex;
-
- if (oli->mstream == NULL) {
- oli->mstream = camel_stream_mem_new ();
- }
-
- camel_stream_write (oli->mstream, str, strlen (str));
-
- if (finished == FALSE)
- return;
-
- camel_stream_reset (oli->mstream);
- info = g_new0 (CamelMessageInfo, 1);
- info->flags = CAMEL_MESSAGE_SEEN;
-
- msg = camel_mime_message_new ();
- camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg),
- oli->mstream);
-
- camel_object_unref (CAMEL_OBJECT (oli->mstream));
- oli->mstream = NULL;
-
- ex = camel_exception_new ();
- camel_folder_append_message (oli->folder, msg, info, ex);
- camel_object_unref (CAMEL_OBJECT (msg));
-
- camel_exception_free (ex);
- g_free (info);
-}
-
/* Based on code from liboe 0.92 (STABLE)
Copyright (C) 2000 Stephan B. Nedregård (stephan@micropop.com)
Modified 2001 Iain Holmes <iain@ximian.com>
Copyright (C) 2001 Ximian, Inc. */
static void
-process_item_fn (EvolutionImporter *importer,
+process_item_fn (EvolutionImporter *eimporter,
CORBA_Object listener,
void *closure,
CORBA_Environment *ev)
{
OutlookImporter *oli = (OutlookImporter *) closure;
+ MailImporter *importer = (MailImporter *) oli;
oe_msg_segmentheader *header;
gboolean more = TRUE;
char *cb, *sfull, *s;
@@ -113,7 +95,8 @@ process_item_fn (EvolutionImporter *importer,
fread (header, 16, 1, oli->handle);
/* Write a From line */
- add_line (oli, "From evolution-outlook-importer", FALSE);
+ mail_importer_add_line (importer,
+ "From evolution-outlook-importer", FALSE);
end_pos = oli->pos + header->include;
if (end_pos >= oli->size) {
end_pos = oli->size;
@@ -134,7 +117,8 @@ process_item_fn (EvolutionImporter *importer,
if (*(cb + i) == 0x0a) {
*s = '\0';
- add_line (oli, sfull, FALSE);
+ mail_importer_add_line (importer,
+ sfull, FALSE);
s = sfull;
}
}
@@ -143,11 +127,11 @@ process_item_fn (EvolutionImporter *importer,
if (s != sfull) {
*s = '\0';
- add_line (oli, sfull, FALSE);
+ mail_importer_add_line (importer, sfull, FALSE);
s = sfull;
}
- add_line (oli, "\n", TRUE);
+ mail_importer_add_line (importer, "\n", TRUE);
oli->pos = end_pos;
fsetpos (oli->handle, &oli->pos);
@@ -163,8 +147,8 @@ process_item_fn (EvolutionImporter *importer,
CamelException *ex;
ex = camel_exception_new ();
- camel_folder_thaw (oli->folder);
- camel_folder_sync (oli->folder, FALSE, ex);
+ camel_folder_thaw (importer->folder);
+ camel_folder_sync (importer->folder, FALSE, ex);
camel_exception_free (ex);
fclose (oli->handle);
oli->handle = NULL;
@@ -216,38 +200,49 @@ static void
importer_destroy_cb (GtkObject *object,
OutlookImporter *oli)
{
- if (oli->folder)
- camel_object_unref (CAMEL_OBJECT (oli->folder));
+ MailImporter *importer;
+
+ importer = (MailImporter *) oli;
+ if (importer->folder)
+ camel_object_unref (CAMEL_OBJECT (importer->folder));
+
g_free (oli->filename);
if (oli->handle)
fclose (oli->handle);
+
g_free (oli);
}
static gboolean
-load_file_fn (EvolutionImporter *importer,
+load_file_fn (EvolutionImporter *eimporter,
const char *filename,
void *closure)
{
OutlookImporter *oli;
- CamelException *ex;
+ MailImporter *importer;
struct stat buf;
fpos_t pos = 0x54;
oli = (OutlookImporter *) closure;
+ importer = (MailImporter *) oli;
+
oli->filename = g_strdup (filename);
/* Will return TRUE if oe4 format */
oli->oe4 = support_format_fn (NULL, filename, NULL);
- if (oli->oe4 == FALSE)
+ if (oli->oe4 == FALSE) {
+ g_warning ("Not OE4 format");
return FALSE;
+ }
oli->handle = fopen (filename, "rb");
if (oli->handle == NULL) {
+ g_warning ("Cannot open the file");
return FALSE;
}
/* Get size of file */
if (stat (filename, &buf) == -1) {
+ g_warning ("Cannot stat file");
return FALSE;
}
@@ -257,30 +252,29 @@ load_file_fn (EvolutionImporter *importer,
fsetpos (oli->handle, &pos);
oli->pos = pos;
- oli->mstream = NULL;
+ importer->mstream = NULL;
- ex = camel_exception_new ();
- oli->folder = mail_local_lookup_folder ("home/iain/evolution/local/Inbox", ex);
- camel_exception_free (ex);
+ importer->folder = mail_importer_get_folder ("Inbox", NULL);
- if (oli->folder == NULL){
- g_print ("Bad folder\n");
+ if (importer->folder == NULL){
+ g_warning ("Bad folder");
return FALSE;
}
- camel_folder_freeze (oli->folder);
+ camel_folder_freeze (importer->folder);
oli->busy = FALSE;
return TRUE;
}
-static BonoboObject *
-factory_fn (BonoboGenericFactory *_factory,
- void *closure)
+BonoboObject *
+outlook_factory_fn (BonoboGenericFactory *_factory,
+ void *closure)
{
EvolutionImporter *importer;
OutlookImporter *oli;
oli = g_new0 (OutlookImporter, 1);
+
importer = evolution_importer_new (support_format_fn, load_file_fn,
process_item_fn, NULL, oli);
gtk_signal_connect (GTK_OBJECT (importer), "destroy",
@@ -289,17 +283,5 @@ factory_fn (BonoboGenericFactory *_factory,
return BONOBO_OBJECT (importer);
}
-void
-outlook_importer_init (void)
-{
- if (factory != NULL)
- return;
-
- factory = bonobo_generic_factory_new (COMPONENT_FACTORY_IID,
- factory_fn, NULL);
- if (factory == NULL) {
- g_error ("Unable to create factory.");
- }
-}
diff --git a/mail/evolution-outlook-importer.h b/mail/evolution-outlook-importer.h
new file mode 100644
index 0000000000..4a469f0072
--- /dev/null
+++ b/mail/evolution-outlook-importer.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* evolution-outlook-importer.h
+ *
+ * Authors: Iain Holmes <iain@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _EVOLUTION_OUTLOOK_IMPORTER_H_
+#define _EVOLUTION_OUTLOOK_IMPORTER_H_
+
+#define OUTLOOK_FACTORY_IID "OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory"
+
+BonoboObject *outlook_factory_fn (BonoboGenericFactory *_factory,
+ void *closure);
+
+#endif
diff --git a/mail/mail-importer.c b/mail/mail-importer.c
new file mode 100644
index 0000000000..d39fa68ee3
--- /dev/null
+++ b/mail/mail-importer.c
@@ -0,0 +1,154 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* mail-importer.c
+ *
+ * Authors: Iain Holmes <iain@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bonobo.h>
+#include "mail-importer.h"
+#include "mail-local.h"
+
+#include <camel/camel-folder.h>
+#include <camel/camel-mime-message.h>
+#include <camel/camel-stream-mem.h>
+#include <camel/camel-exception.h>
+
+#include "evolution-outlook-importer.h"
+#include "evolution-mbox-importer.h"
+
+static gboolean factory_initialised = FALSE;
+
+extern char *evolution_dir;
+/**
+ * mail_importer_add_line:
+ * importer: A MailImporter structure.
+ * str: Next line of the mbox.
+ * finished: TRUE if @str is the last line of the message.
+ *
+ * Adds lines to the message until it is finished, and then adds
+ * the complete message to the folder.
+ */
+void
+mail_importer_add_line (MailImporter *importer,
+ const char *str,
+ gboolean finished)
+{
+ CamelMimeMessage *msg;
+ CamelMessageInfo *info;
+ CamelException *ex;
+
+ if (importer->mstream == NULL) {
+ importer->mstream = camel_stream_mem_new ();
+ }
+
+ camel_stream_write (CAMEL_STREAM (importer->mstream), str,
+ strlen (str));
+
+ if (finished == FALSE)
+ return;
+
+ camel_stream_reset (CAMEL_STREAM (importer->mstream));
+ info = g_new0 (CamelMessageInfo, 1);
+ info->flags = CAMEL_MESSAGE_SEEN;
+
+ msg = camel_mime_message_new ();
+ camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg),
+ CAMEL_STREAM (importer->mstream));
+
+ camel_object_unref (CAMEL_OBJECT (importer->mstream));
+ importer->mstream = NULL;
+
+ ex = camel_exception_new ();
+ camel_folder_append_message (importer->folder, msg, info, ex);
+ camel_object_unref (CAMEL_OBJECT (msg));
+
+ camel_exception_free (ex);
+ g_free (info);
+}
+
+/**
+ * mail_importer_get_folder:
+ * @name: The folder name.
+ * *opt_ex: A #CamelException, or NULL if you don't care about errors.
+ *
+ * Gets the local folder called @name.
+ *
+ * Returns: A CamelFolder (which needs to be unrefed when you are done with it)
+ * on success, or NULL on fail. A more detailed error is given in @opt_ex, if
+ * @opt_ex is not NULL.
+ */
+CamelFolder *
+mail_importer_get_folder (const char *name,
+ CamelException *opt_ex)
+{
+ CamelFolder *folder;
+ CamelException *real_ex;
+ char *path, *tmp;
+
+ if (opt_ex != NULL)
+ real_ex = opt_ex;
+ else
+ real_ex = camel_exception_new ();
+
+ g_print ("Evolution_dir: %s\n", evolution_dir);
+ tmp = g_concat_dir_and_file (evolution_dir, "local");
+ path = g_concat_dir_and_file (tmp, name);
+ g_free (tmp);
+
+ folder = mail_local_lookup_folder (path + 1, real_ex);
+ if (opt_ex == NULL)
+ camel_exception_free (real_ex);
+
+ return folder;
+}
+
+/**
+ * mail_importer_init:
+ *
+ * Initialises all the importers
+ */
+void
+mail_importer_init (void)
+{
+ BonoboGenericFactory *factory;
+ if (factory_initialised == TRUE)
+ return;
+
+ /* FIXME: Need plugins */
+ factory = bonobo_generic_factory_new (OUTLOOK_FACTORY_IID,
+ outlook_factory_fn,
+ NULL);
+ if (factory == NULL) {
+ g_error ("Unable to create outlook factory.");
+ }
+
+ factory = bonobo_generic_factory_new (MBOX_FACTORY_IID,
+ mbox_factory_fn, NULL);
+ if (factory == NULL) {
+ g_error ("Unable to create mbox factory.");
+ }
+
+ factory_initialised = TRUE;
+}
+
diff --git a/mail/mail-importer.h b/mail/mail-importer.h
new file mode 100644
index 0000000000..5286888287
--- /dev/null
+++ b/mail/mail-importer.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* mail-importer.h
+ *
+ * Authors: Iain Holmes <iain@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __MAIL_IMPORTER_H__
+#define __MAIL_IMPORTER_H__
+
+#include <camel/camel-folder.h>
+#include <camel/camel-stream-mem.h>
+#include <camel/camel-exception.h>
+
+typedef struct _MailImporter MailImporter;
+struct _MailImporter {
+ CamelFolder *folder;
+ CamelStreamMem *mstream;
+};
+
+void mail_importer_init (void);
+void mail_importer_add_line (MailImporter *importer,
+ const char *str,
+ gboolean finished);
+CamelFolder *mail_importer_get_folder (const char *name,
+ CamelException *opt_ex);
+#endif
diff --git a/mail/mail-local.c b/mail/mail-local.c
index aa956edcb8..22df0333d1 100644
--- a/mail/mail-local.c
+++ b/mail/mail-local.c
@@ -942,6 +942,19 @@ non_equal (gconstpointer a, gconstpointer b)
return TRUE;
}
+CamelFolder *
+mail_local_lookup_folder (const char *name,
+ CamelException *ev)
+{
+ MailLocalStore *local_store;
+
+ local_store = (MailLocalStore *)camel_session_get_service (session,
+ "file:/",
+ CAMEL_PROVIDER_STORE, NULL);
+
+ return get_folder (local_store, name, 0, ev);
+}
+
void
mail_local_storage_startup (EvolutionShellClient *shellclient,
const char *evolution_path)
diff --git a/mail/mail-local.h b/mail/mail-local.h
index 254fcbe4f6..808c2cdf18 100644
--- a/mail/mail-local.h
+++ b/mail/mail-local.h
@@ -35,4 +35,6 @@ void mail_local_storage_startup (EvolutionShellClient *shellclient,
void mail_local_reconfigure_folder (FolderBrowser *fb);
+CamelFolder *mail_local_lookup_folder (const char *name,
+ CamelException *ex);
#endif