diff options
author | Iain Holmes <iain@src.gnome.org> | 2001-03-13 10:26:18 +0800 |
---|---|---|
committer | Iain Holmes <iain@src.gnome.org> | 2001-03-13 10:26:18 +0800 |
commit | 8c2f3a00ef98717e4203630c8119f2e84d2bb796 (patch) | |
tree | f4ec43d8f0e79adffebcfe80de345981a3dbf556 /mail | |
parent | c807d96e58f7a4c6c2c306f6da26a63b608f840b (diff) | |
download | gsoc2013-evolution-8c2f3a00ef98717e4203630c8119f2e84d2bb796.tar gsoc2013-evolution-8c2f3a00ef98717e4203630c8119f2e84d2bb796.tar.gz gsoc2013-evolution-8c2f3a00ef98717e4203630c8119f2e84d2bb796.tar.bz2 gsoc2013-evolution-8c2f3a00ef98717e4203630c8119f2e84d2bb796.tar.lz gsoc2013-evolution-8c2f3a00ef98717e4203630c8119f2e84d2bb796.tar.xz gsoc2013-evolution-8c2f3a00ef98717e4203630c8119f2e84d2bb796.tar.zst gsoc2013-evolution-8c2f3a00ef98717e4203630c8119f2e84d2bb796.zip |
All my changes to get the folder creation working, and the magic Netscape
importer.
svn path=/trunk/; revision=8661
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 16 | ||||
-rw-r--r-- | mail/GNOME_Evolution_Mail.oaf.in | 52 | ||||
-rw-r--r-- | mail/Makefile.am | 10 | ||||
-rw-r--r-- | mail/component-factory.c | 3 | ||||
-rw-r--r-- | mail/importers/GNOME_Evolution_Mail_Mbox_Importer.oaf.in | 29 | ||||
-rw-r--r-- | mail/importers/GNOME_Evolution_Mail_Netscape_Intelligent_Importer.oaf.in | 21 | ||||
-rw-r--r-- | mail/importers/GNOME_Evolution_Mail_Outlook_Importer.oaf.in | 29 | ||||
-rw-r--r-- | mail/importers/Makefile.am | 29 | ||||
-rw-r--r-- | mail/importers/evolution-mbox-importer.c | 233 | ||||
-rw-r--r-- | mail/importers/evolution-outlook-importer.c | 307 | ||||
-rw-r--r-- | mail/importers/netscape-importer.c | 465 | ||||
-rw-r--r-- | mail/mail-importer.c | 144 | ||||
-rw-r--r-- | mail/mail-importer.h | 6 | ||||
-rw-r--r-- | mail/netscape-importer.c | 277 |
14 files changed, 1260 insertions, 361 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 130b5df97e..d2b35cfbf7 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,19 @@ +2001-03-13 Iain Holmes <iain@ximian.com> + + * Makefile.am: Removed the importers and created a subdirectory for them to + live happily as plugins. + + * mail-importer.c (mail_importer_create_folder): Modified the function to take + a BonoboListener for the callback. + (get_importer_list): Get a list of importer plugins. + (free_importer_list): Free the list of plugins. + (mail_importer_init): Initalise the list of plugins. + (main_importer_uninit): Unload the modules. + + * GNOME_Evolution_Mail.oaf.in: Remove the oaf_server entries for the importers. + + * importers/*: Copy the importers in here. + 2001-03-12 Jeffrey Stedfast <fejj@ximian.com> * mail-config.c (mail_config_write): Make the transport save diff --git a/mail/GNOME_Evolution_Mail.oaf.in b/mail/GNOME_Evolution_Mail.oaf.in index 5febb74724..a30155258e 100644 --- a/mail/GNOME_Evolution_Mail.oaf.in +++ b/mail/GNOME_Evolution_Mail.oaf.in @@ -102,56 +102,4 @@ _value="Evolution mail composer."/> </oaf_server> -<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory" - type="exe" - location="evolution-mail"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/ObjectFactory:1.0"/> - </oaf_attribute> - - <oaf_attribute name="description" type="string" - _value="Factory to import Outlook Express 4 mails into Evolution"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Outlook_Importer" - type="factory" - location="OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/Importer:1.0"/> - </oaf_attribute> - - <oaf_attribute name="evolution:menu-name" type="string" - value="Outlook Express 4 (.mbx)"/> - <oaf_attribute name="description" type="string" - _value="Imports Outlook Express 4 files into Evolution"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory" - type="exe" - location="evolution-mail"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/ObjectFactory:1.0"/> - </oaf_attribute> - - <oaf_attribute name="description" type="string" - _value="Factory to import mbox into Evolution"/> -</oaf_server> - -<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Mbox_Importer" - type="factory" - location="OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:GNOME/Evolution/Importer:1.0"/> - </oaf_attribute> - - <oaf_attribute name="evolution:menu-name" type="string" - value="MBox (mbox)"/> - <oaf_attribute name="description" type="string" - _value="Imports mbox files into Evolution"/> -</oaf_server> - </oaf_info> diff --git a/mail/Makefile.am b/mail/Makefile.am index 66eb1b858d..84591e5b88 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -1,8 +1,11 @@ +SUBDIRS = importers + bin_PROGRAMS = evolution-mail noinst_PROGRAMS = test-mail #test-thread providerdir = $(libdir)/evolution/camel-providers/$(VERSION) +importerdir = $(libdir)/evolution/evolution-mail-importers/$(VERSION) INCLUDES = \ -I$(top_srcdir)/widgets \ @@ -31,6 +34,7 @@ INCLUDES = \ -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \ -DEVOLUTION_DATADIR=\""$(datadir)"\" \ -DCAMEL_PROVIDERDIR=\""$(providerdir)"\" \ + -DMAIL_IMPORTERSDIR=\""$(importerdir)"\" \ -DG_LOG_DOMAIN=\"evolution-mail\" EVOLUTION_MAIL_CORBA_GENERATED = \ @@ -96,11 +100,7 @@ evolution_mail_SOURCES = \ mail-session.h \ subscribe-dialog.c \ subscribe-dialog.h \ - mail.h \ - evolution-outlook-importer.c \ - evolution-outlook-importer.h \ - evolution-mbox-importer.c \ - evolution-mbox-importer.h + mail.h evolution_mail_LDADD = \ $(top_builddir)/shell/libeshell.a \ diff --git a/mail/component-factory.c b/mail/component-factory.c index 93e8ada015..c1ed7119f4 100644 --- a/mail/component-factory.c +++ b/mail/component-factory.c @@ -145,6 +145,9 @@ create_folder (EvolutionShellComponent *shell_component, if (!strcmp (type, "mail")) { uri = g_strdup_printf ("mbox://%s", physical_uri); mail_create_folder (uri, do_create_folder, CORBA_Object_duplicate (listener, &ev)); + GNOME_Evolution_ShellComponentListener_notifyResult (listener, + GNOME_Evolution_ShellComponentListener_OK, &ev); + } else { GNOME_Evolution_ShellComponentListener_notifyResult ( listener, GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE, &ev); diff --git a/mail/importers/GNOME_Evolution_Mail_Mbox_Importer.oaf.in b/mail/importers/GNOME_Evolution_Mail_Mbox_Importer.oaf.in new file mode 100644 index 0000000000..b9da9ce3c8 --- /dev/null +++ b/mail/importers/GNOME_Evolution_Mail_Mbox_Importer.oaf.in @@ -0,0 +1,29 @@ +<oaf_info> + +<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory" + type="exe" + location="evolution-mail"> + + <oaf_attribute name="repo_ids" type="stringv"> + <item value="IDL:GNOME/ObjectFactory:1.0"/> + </oaf_attribute> + + <oaf_attribute name="description" type="string" + _value="Factory to import mbox into Evolution"/> +</oaf_server> + +<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Mbox_Importer" + type="factory" + location="OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory"> + + <oaf_attribute name="repo_ids" type="stringv"> + <item value="IDL:GNOME/Evolution/Importer:1.0"/> + </oaf_attribute> + + <oaf_attribute name="evolution:menu-name" type="string" + value="MBox (mbox)"/> + <oaf_attribute name="description" type="string" + _value="Imports mbox files into Evolution"/> +</oaf_server> + +</oaf_info> diff --git a/mail/importers/GNOME_Evolution_Mail_Netscape_Intelligent_Importer.oaf.in b/mail/importers/GNOME_Evolution_Mail_Netscape_Intelligent_Importer.oaf.in new file mode 100644 index 0000000000..db3f820d7b --- /dev/null +++ b/mail/importers/GNOME_Evolution_Mail_Netscape_Intelligent_Importer.oaf.in @@ -0,0 +1,21 @@ +<oaf_info> + +<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Netscape_Intelligent_Importer_Factory" + type="exe" + location="evolution-mail"> + + <oaf_attribute name="repo_ids" type="stringv"> + <item value="IDL:GNOME/ObjectFactory:1.0"/> + </oaf_attribute> +</oaf_server> + +<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Netscape_Intelligent_Importer" + type="factory" + location="OAFIID:GNOME_Evolution_Mail_Netscape_Intelligent_Importer_Factory"> + + <oaf_attribute name="repo_ids" type="stringv"> + <item value="IDL:GNOME/Evolution/IntelligentImporter:1.0"/> + </oaf_attribute> + +</oaf_server> +</oaf_info> diff --git a/mail/importers/GNOME_Evolution_Mail_Outlook_Importer.oaf.in b/mail/importers/GNOME_Evolution_Mail_Outlook_Importer.oaf.in new file mode 100644 index 0000000000..66317e3d7a --- /dev/null +++ b/mail/importers/GNOME_Evolution_Mail_Outlook_Importer.oaf.in @@ -0,0 +1,29 @@ +<oaf_info> + +<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory" + type="exe" + location="evolution-mail"> + + <oaf_attribute name="repo_ids" type="stringv"> + <item value="IDL:GNOME/ObjectFactory:1.0"/> + </oaf_attribute> + + <oaf_attribute name="description" type="string" + _value="Factory to import Outlook Express 4 mails into Evolution"/> +</oaf_server> + +<oaf_server iid="OAFIID:GNOME_Evolution_Mail_Outlook_Importer" + type="factory" + location="OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory"> + + <oaf_attribute name="repo_ids" type="stringv"> + <item value="IDL:GNOME/Evolution/Importer:1.0"/> + </oaf_attribute> + + <oaf_attribute name="evolution:menu-name" type="string" + value="Outlook Express 4 (.mbx)"/> + <oaf_attribute name="description" type="string" + _value="Imports Outlook Express 4 files into Evolution"/> +</oaf_server> + +</oaf_info> diff --git a/mail/importers/Makefile.am b/mail/importers/Makefile.am new file mode 100644 index 0000000000..aaefed7672 --- /dev/null +++ b/mail/importers/Makefile.am @@ -0,0 +1,29 @@ +importersdir = $(pkglibdir)/evolution-mail-importers/$(VERSION) + +importers_LTLIBRARIES = liboutlook.la libmbox.la libiinetscape.la + +INCLUDES = -I.. \ + -I$(srcdir)/.. \ + -I$(top_srcdir)/shell \ + -I$(includedir) \ + $(GNOME_INCLUDEDIR) \ + -DG_LOG_DOMAIN=\"evolution-mail-importer\" + +liboutlook_la_SOURCES = \ + evolution-outlook-importer.c +liboutlook_la_LDFLAGS = -version-info 0:0:0 + +libmbox_la_SOURCES = evolution-mbox-importer.c +libmbox_la_LDFLAGS = -version-info 0:0:0 + +libiinetscape_la_SOURCES = netscape-importer.c +libiinetscape_la_LDFLAGS = -version-info 0:0:0 + +oafdir = $(datadir)/oaf +oaf_in_files = GNOME_Evolution_Mail_Mbox_Importer.oaf.in \ + GNOME_Evolution_Mail_Outlook_Importer.oaf.in \ + GNOME_Evolution_Mail_Netscape_Intelligent_Importer.oaf.in + +oaf_DATA = $(oaf_in_files:.oaf.in=.oaf) + +@XML_I18N_MERGE_OAF_RULE@ diff --git a/mail/importers/evolution-mbox-importer.c b/mail/importers/evolution-mbox-importer.c new file mode 100644 index 0000000000..241055cb10 --- /dev/null +++ b/mail/importers/evolution-mbox-importer.c @@ -0,0 +1,233 @@ +/* -*- 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> +#include <camel/camel-mime-parser.h> +#include <camel/camel-mime-part.h> + +#define MBOX_FACTORY_IID "OAFIID:GNOME_Evolution_Mail_Mbox_ImporterFactory" + +typedef struct { + MailImporter importer; /* Parent */ + + char *filename; + int num; + CamelMimeParser *mp; +} 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; + gboolean done = FALSE; + CamelException *ex; + + ex = camel_exception_new (); + if (camel_mime_parser_step (mbi->mp, 0, 0) == HSCAN_FROM) { + /* Import the next message */ + CamelMimeMessage *msg; + CamelMessageInfo *info; + + 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; + } + + /* write the mesg */ + info = g_new0 (CamelMessageInfo, 1); + camel_folder_append_message (importer->folder, msg, info, ex); + g_free (info); + camel_object_unref (CAMEL_OBJECT (msg)); + if (camel_exception_is_set (ex)) { + g_warning ("Failed message %d", mbi->num); + done = TRUE; + } + } else { + /* all messages have now been imported */ + camel_folder_sync (importer->folder, FALSE, ex); + camel_folder_thaw (importer->folder); + importer->frozen = FALSE; + done = TRUE; + } + + camel_exception_free (ex); + GNOME_Evolution_ImporterListener_notifyResult (listener, + GNOME_Evolution_ImporterListener_OK, + !done, ev); + return; +} + +static gboolean +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; + } + + close (fd); + + return ret; +} + +static void +importer_destroy_cb (GtkObject *object, + MboxImporter *mbi) +{ + MailImporter *importer; + + importer = (MailImporter *) mbi; + if (importer->frozen) { + camel_folder_sync (importer->folder, FALSE, NULL); + camel_folder_thaw (importer->folder); + } + + if (importer->folder) + camel_object_unref (CAMEL_OBJECT (importer->folder)); + + g_free (mbi->filename); + if (mbi->mp) + camel_object_unref (CAMEL_OBJECT (mbi->mp)); + + g_free (mbi); +} + +static gboolean +load_file_fn (EvolutionImporter *eimporter, + const char *filename, + void *closure) +{ + MboxImporter *mbi; + MailImporter *importer; + int fd; + + mbi = (MboxImporter *) closure; + importer = (MailImporter *) mbi; + + mbi->filename = g_strdup (filename); + + fd = open (filename, O_RDONLY); + if (fd == -1) { + g_warning ("Cannot open file"); + return FALSE; + } + + 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; + } + + importer->mstream = NULL; + importer->folder = mail_tool_get_local_inbox (NULL); + + if (importer->folder == NULL){ + g_print ("Bad folder\n"); + goto fail; + } + + camel_folder_freeze (importer->folder); + importer->frozen = TRUE; + + g_warning ("Okay, so everything is now ready to import that mbox file!"); + return TRUE; + + fail: + camel_object_unref (CAMEL_OBJECT (mbi->mp)); + mbi->mp = NULL; + + return FALSE; +} + +static 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); +} + +/* Entry point */ +void +mail_importer_module_init (void) +{ + static gboolean initialised = FALSE; + BonoboGenericFactory *factory; + + if (initialised == TRUE) + return; + + factory = bonobo_generic_factory_new (MBOX_FACTORY_IID, + mbox_factory_fn, NULL); + + if (factory == NULL) + g_warning ("Could not initialise Outlook importer factory."); + + initialised = TRUE; +} + diff --git a/mail/importers/evolution-outlook-importer.c b/mail/importers/evolution-outlook-importer.c new file mode 100644 index 0000000000..a92f5086ab --- /dev/null +++ b/mail/importers/evolution-outlook-importer.c @@ -0,0 +1,307 @@ +/* -*- 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> +#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> + +#define OUTLOOK_FACTORY_IID "OAFIID:GNOME_Evolution_Mail_Outlook_ImporterFactory" + +extern char *evolution_dir; +typedef struct { + MailImporter importer; + + char *filename; + gboolean oe4; /* Is file OE4 or not? */ + FILE *handle; + long pos; + off_t size; + + gboolean busy; +} OutlookImporter; + +struct oe_msg_segmentheader { + int self; + int increase; + int include; + int next; + int usenet; +}; + +typedef struct oe_msg_segmentheader oe_msg_segmentheader; + + +/* EvolutionImporter methods */ + +/* 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 *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; + long end_pos = 0; + int i; + + if (oli->busy == TRUE) { + GNOME_Evolution_ImporterListener_notifyResult (listener, + GNOME_Evolution_ImporterListener_BUSY, + more, ev); + return; + } + + oli->busy = TRUE; + header = g_new (oe_msg_segmentheader, 1); + fread (header, 16, 1, oli->handle); + + /* Write a From line */ + 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; + more = FALSE; + } + + oli->pos += 4; + + cb = g_new (char, 4); + sfull = g_new (char, 65536); + s = sfull; + + while (oli->pos < end_pos) { + fread (cb, 1, 4, oli->handle); + for (i = 0; i < 4; i++, oli->pos++) { + if (*(cb + i ) != 0x0d) { + *s++ = *(cb + i); + + if (*(cb + i) == 0x0a) { + *s = '\0'; + mail_importer_add_line (importer, + sfull, FALSE); + s = sfull; + } + } + } + } + + if (s != sfull) { + *s = '\0'; + mail_importer_add_line (importer, sfull, FALSE); + s = sfull; + } + + mail_importer_add_line (importer, "\n", TRUE); + + oli->pos = end_pos; + fseek (oli->handle, oli->pos, SEEK_SET); + + g_free (header); + g_free (sfull); + g_free (cb); + + GNOME_Evolution_ImporterListener_notifyResult (listener, + GNOME_Evolution_ImporterListener_OK, + more, ev); + if (more == FALSE) { + CamelException *ex; + + ex = camel_exception_new (); + camel_folder_thaw (importer->folder); + camel_folder_sync (importer->folder, FALSE, ex); + camel_exception_free (ex); + fclose (oli->handle); + oli->handle = NULL; + } + + oli->busy = FALSE; + return; +} + + +/* EvolutionImporterFactory methods */ + +static gboolean +support_format_fn (EvolutionImporter *importer, + const char *filename, + void *closure) +{ + FILE *handle; + int signature[4]; + + /* Outlook Express sniffer. + Taken from liboe 0.92 (STABLE) + Copyright (C) 2000 Stephan B. Nedregård (stephan@micropop.com) */ + + handle = fopen (filename, "rb"); + if (handle == NULL) + return FALSE; /* Can't open file: Can't support it :) */ + + /* SIGNATURE */ + fread (&signature, 16, 1, handle); + if ((signature[0]!=0xFE12ADCF) || /* OE 5 & OE 5 BETA SIGNATURE */ + (signature[1]!=0x6F74FDC5) || + (signature[2]!=0x11D1E366) || + (signature[3]!=0xC0004E9A)) { + if ((signature[0]==0x36464D4A) && + (signature[1]==0x00010003)) /* OE4 SIGNATURE */ { + fclose (handle); + return TRUE; /* OE 4 */ + } + fclose (handle); + return FALSE; /* Not Outlook 4 or 5 */ + } + + fclose (handle); + return FALSE; /* Can't handle OE 5 yet */ +} + +static void +importer_destroy_cb (GtkObject *object, + OutlookImporter *oli) +{ + 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 *eimporter, + const char *filename, + void *closure) +{ + OutlookImporter *oli; + MailImporter *importer; + struct stat buf; + long 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) { + 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; + } + + oli->size = buf.st_size; + + /* Set the fposition to the begining */ + fseek (oli->handle, pos, SEEK_SET); + oli->pos = pos; + + importer->mstream = NULL; + + importer->folder = mail_tool_get_local_inbox (NULL); + + if (importer->folder == NULL){ + g_warning ("Bad folder"); + return FALSE; + } + + camel_folder_freeze (importer->folder); + oli->busy = FALSE; + return TRUE; +} + +static 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", + GTK_SIGNAL_FUNC (importer_destroy_cb), oli); + + return BONOBO_OBJECT (importer); +} + +/* Entry point */ +void +mail_importer_module_init (void) +{ + static gboolean initialised = FALSE; + BonoboGenericFactory *factory; + + if (initialised == TRUE) + return; + + factory = bonobo_generic_factory_new (OUTLOOK_FACTORY_IID, + outlook_factory_fn, NULL); + + if (factory == NULL) + g_warning ("Could not initialise Outlook importer factory."); + + initialised = TRUE; +} + + diff --git a/mail/importers/netscape-importer.c b/mail/importers/netscape-importer.c new file mode 100644 index 0000000000..281d033536 --- /dev/null +++ b/mail/importers/netscape-importer.c @@ -0,0 +1,465 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* netscape-importer.c + * + * Authors: + * Iain Holmes <iain@ximian.com> + * + * Copyright 2001 Ximian, Inc. (http://www.ximian.com) + * + * 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 <stdio.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <dirent.h> + +#include <glib.h> +#include <gnome.h> + +#include <bonobo/bonobo-object.h> +#include <bonobo/bonobo-generic-factory.h> +#include <camel/camel-mime-message.h> +#include <camel/camel-mime-part.h> +#include <camel/camel-exception.h> + +#include <importer/evolution-intelligent-importer.h> +#include <importer/GNOME_Evolution_Importer.h> +#include "mail-importer.h" +#include "mail-tools.h" + +static char *nsmail_dir = NULL; + +extern char *evolution_dir; + +#define NETSCAPE_INTELLIGENT_IMPORTER_IID "OAFIID:GNOME_Evolution_Mail_Netscape_Intelligent_Importer_Factory" +#define KEY "netscape-mail-imported" + +/*#define SUPER_IMPORTER_DEBUG*/ +#ifdef SUPER_IMPORTER_DEBUG +#define d(x) x +#else +#define d(x) +#endif + +typedef struct { + MailImporter importer; + GList *dir_list; + + int num; + CamelMimeParser *mp; + BonoboListener *listener; +} NetscapeImporter; + +static gboolean +netscape_import_mbox (CamelFolder *folder, + const char *filename) +{ + gboolean done = FALSE; + CamelException *ex; + CamelMimeParser *mp; + int fd, n = 0; + + fd = open (filename, O_RDONLY); + if (fd == -1) { + g_warning ("Cannot open %s", filename); + return FALSE; + } + + camel_object_ref (CAMEL_OBJECT (folder)); + camel_folder_freeze (folder); + + ex = camel_exception_new (); + mp = camel_mime_parser_new (); + camel_mime_parser_scan_from (mp, TRUE); + if (camel_mime_parser_init_with_fd (mp, fd) == -1) { + g_warning ("Unable to process file %s", filename); + camel_object_unref (CAMEL_OBJECT (mp)); + camel_folder_thaw (folder); + camel_object_unref (CAMEL_OBJECT (folder)); + return FALSE; + } + + while (camel_mime_parser_step (mp, 0, 0) == HSCAN_FROM) { + /* Import the next message */ + CamelMimeMessage *msg; + CamelMessageInfo *info; + + msg = camel_mime_message_new (); + if (camel_mime_part_construct_from_parser (CAMEL_MIME_PART (msg), + mp) == -1) { + g_warning ("Failed message %d", n); + camel_object_unref (CAMEL_OBJECT (msg)); + done = TRUE; + } + + info = g_new0 (CamelMessageInfo, 1); + camel_folder_append_message (folder, msg, info, ex); + g_free (info); + camel_object_unref (CAMEL_OBJECT (msg)); + if (camel_exception_is_set (ex)) { + g_warning ("Failed message %d", n); + done = TRUE; + } + + if (!done) { + n++; + camel_mime_parser_step (mp, 0, 0); + } + } + + camel_folder_sync (folder, FALSE, ex); + camel_folder_thaw (folder); + camel_object_unref (CAMEL_OBJECT (folder)); + done = TRUE; + + camel_exception_free (ex); + return done; +} + +static void +netscape_clean_up (void) +{ + g_free (nsmail_dir); + nsmail_dir = NULL; +} + +static gboolean +netscape_can_import (EvolutionIntelligentImporter *ii, + void *closure) +{ + NetscapeImporter *importer = closure; + char *nsprefs; + FILE *prefs_handle; + char *key; + + /* Already imported */ + key = g_strdup_printf ("=%s/config/Mail=/importers/", evolution_dir); + gnome_config_push_prefix (key); + g_free (key); + + if (gnome_config_get_bool (KEY) == TRUE) { + gnome_config_pop_prefix (); + return FALSE; + } + gnome_config_pop_prefix (); + + nsprefs = gnome_util_prepend_user_home (".netscape/preferences.js"); + prefs_handle = fopen (nsprefs, "r"); + g_free (nsprefs); + + if (prefs_handle == NULL) { + d(g_warning ("No .netscape/preferences.js")); + return FALSE; + } + + /* Find the user mail dir */ + while (1) { + char line[4096]; + + fgets (line, 4096, prefs_handle); + if (line == NULL) { + g_warning ("No mail.directory entry"); + fclose (prefs_handle); + return FALSE; + } + + if (strstr (line, "mail.directory") != NULL) { + char *sep, *start, *end; + /* Found the line */ + + sep = strchr (line, ','); + if (sep == NULL) { + g_warning ("Bad line %s", line); + fclose (prefs_handle); + return FALSE; + } + + start = strchr (sep, '\"') + 1; + if (start == NULL) { + g_warning ("Bad line %s", line); + fclose (prefs_handle); + return FALSE; + } + + end = strrchr (sep, '\"'); + if (end == NULL) { + g_warning ("Bad line %s", line); + fclose (prefs_handle); + return FALSE; + } + + nsmail_dir = g_strndup (start, end - start); + d(g_warning ("Got nsmail_dir: %s", nsmail_dir)); + fclose (prefs_handle); + return TRUE; + } + } +} + +static void +netscape_import_file (NetscapeImporter *importer, + const char *parent, + const char *dirname, + const char *filename, + const char *fullpath) +{ + char *summary, *summarypath, *foldername, *path; + char *protocol; + CamelException *ex; + CamelFolder *folder; + + /* Check that the file is a netscape mbox. + It should have an associated .summary file */ + summary = g_strdup_printf (".%s.summary", filename); + summarypath = g_concat_dir_and_file (dirname, summary); + if (!g_file_exists (summarypath)) { + d(g_warning ("%s does not exist.\nIgnoring %s", summary, + filename)); + g_free (summary); + g_free (summarypath); + return; + } + + g_free (summary); + g_free (summarypath); + + /* Do import */ + foldername = g_concat_dir_and_file (parent, filename); + + d(g_warning ("Importing %s as %s\n", filename, fullpath)); + + ex = camel_exception_new (); + protocol = g_strconcat ("file://", fullpath, NULL); + folder = mail_tool_uri_to_folder (protocol, ex); + if (camel_exception_is_set (ex)) { + g_free (protocol); + camel_exception_free (ex); + return; + } + + if (folder == NULL) { + g_warning ("Folder for %s is NULL", fullpath); + camel_exception_free (ex); + return; + } + + camel_exception_free (ex); + + path = g_concat_dir_and_file (dirname, filename); + netscape_import_mbox (folder, path); + g_free (path); +} + +typedef struct { + NetscapeImporter *importer; + char *parent; + char *dirname; + char *filename; +} NetscapeCreateDirectoryData; + +static void +netscape_dir_created (BonoboListener *listener, + const char *event_name, + const BonoboArg *event_data, + CORBA_Environment *ev, + NetscapeImporter *importer) +{ + NetscapeCreateDirectoryData *data; + GList *l; + GNOME_Evolution_Storage_FolderResult *result; + char *fullpath; + + if (strcmp (event_name, "evolution-shell:folder_created") != 0) { + return; /* Unknown event notification */ + } + + result = event_data->_value; + fullpath = result->path; + + l = importer->dir_list; + importer->dir_list = g_list_remove_link (importer->dir_list, l); + data = l->data; + g_list_free_1 (l); + + /* Import the file */ + /* We got the folder, so try to import the file into it. */ + netscape_import_file (data->importer, data->parent, + data->dirname, data->filename, fullpath); + + g_free (data->parent); + g_free (data->dirname); + g_free (data->filename); + g_free (data); + + if (importer->dir_list) { + /* Do the next in the list */ + data = importer->dir_list->data; + mail_importer_create_folder (data->parent, data->filename, NULL, + importer->listener); + } +} + +/* This function basically flattens the tree structure. + It makes a list of all the directories that are to be imported. */ +static void +scan_dir (NetscapeImporter *importer, + const char *orig_parent, + const char *dirname) +{ + DIR *nsmail; + struct stat buf; + struct dirent *current; + + nsmail = opendir (dirname); + if (nsmail == NULL) { + d(g_warning ("Could not open %s\nopendir returned: %s", + dirname, g_strerror (errno))); + return; + } + + current = readdir (nsmail); + while (current) { + char *fullname; + + /* Ignore things which start with . + which should be ., .., and the summaries. */ + if (current->d_name[0] =='.') { + current = readdir (nsmail); + continue; + } + + fullname = g_concat_dir_and_file (dirname, current->d_name); + if (stat (fullname, &buf) == -1) { + d(g_warning ("Could not stat %s\nstat returned:%s", + fullname, g_strerror (errno))); + current = readdir (nsmail); + g_free (fullname); + continue; + } + + if (S_ISREG (buf.st_mode)) { + char *sbd, *dir, *parent; + NetscapeCreateDirectoryData *data; + + d(g_print ("File: %s\n", fullname)); + + data = g_new0 (NetscapeCreateDirectoryData, 1); + data->importer = importer; + data->parent = g_strdup (orig_parent); + data->dirname = g_strdup (dirname); + data->filename = g_strdup (current->d_name); + + importer->dir_list = g_list_append (importer->dir_list, + data); + + + parent = g_concat_dir_and_file (orig_parent, + data->filename); + + /* Check if a .sbd folder exists */ + dir = g_concat_dir_and_file (data->dirname, data->filename); + sbd = g_strconcat (dir, ".sbd", NULL); + g_free (dir); + if (g_file_exists (sbd)) { + scan_dir (importer, parent, sbd); + } + + g_free (parent); + g_free (sbd); + } + + g_free (fullname); + current = readdir (nsmail); + } +} + +static void +netscape_create_structure (EvolutionIntelligentImporter *ii, + void *closure) +{ + NetscapeImporter *importer = closure; + NetscapeCreateDirectoryData *data; + char *key; + + g_return_if_fail (nsmail_dir != NULL); + + scan_dir (importer, "/", nsmail_dir); + + importer->listener = bonobo_listener_new (NULL, NULL); + gtk_signal_connect (GTK_OBJECT (importer->listener), "event_notify", + GTK_SIGNAL_FUNC (netscape_dir_created), importer); + data = importer->dir_list->data; + mail_importer_create_folder (data->parent, data->filename, NULL, + importer->listener); + + key = g_strdup_printf ("=%s/config/Mail=/importers/", evolution_dir); + gnome_config_push_prefix (key); + g_free (key); + + gnome_config_set_bool (KEY, TRUE); + gnome_config_pop_prefix (); + + gnome_config_sync (); + gnome_config_drop_all (); +} + +static BonoboObject * +netscape_factory_fn (BonoboGenericFactory *_factory, + void *closure) +{ + EvolutionIntelligentImporter *importer; + NetscapeImporter *netscape; + char *message = N_("Evolution has found Netscape mail files.\n" + "Would you like them to be imported into Evolution?"); + + netscape = g_new0 (NetscapeImporter, 1); + importer = evolution_intelligent_importer_new (netscape_can_import, + netscape_create_structure, + "Netscape mail", + message, netscape); + return BONOBO_OBJECT (importer); +} + +/* Entry Point */ +void +mail_importer_module_init (void) +{ + static gboolean initialised = FALSE; + BonoboGenericFactory *factory; + + if (initialised == TRUE) + return; + + factory = bonobo_generic_factory_new (NETSCAPE_INTELLIGENT_IMPORTER_IID, + netscape_factory_fn, NULL); + if (factory == NULL) + g_warning ("Could not initialise Netscape Intelligent Mail Importer."); + initialised = TRUE; +} + +/* GModule g_module_unload routine */ +void +g_module_unload (void) +{ + netscape_clean_up (); +} diff --git a/mail/mail-importer.c b/mail/mail-importer.c index 03f2bd374b..85dfe5a57a 100644 --- a/mail/mail-importer.c +++ b/mail/mail-importer.c @@ -36,37 +36,56 @@ #include <camel/camel-stream-mem.h> #include <camel/camel-exception.h> -#include "evolution-outlook-importer.h" -#include "evolution-mbox-importer.h" +#include <dirent.h> +#include <gmodule.h> -static gboolean factory_initialised = FALSE; +static GList *importer_modules = NULL; extern char *evolution_dir; static GNOME_Evolution_LocalStorage local_storage = NULL; +/** + * mail_importer_create_folder: + * parent_path: The path of the parent folder. + * name: The name of the folder to be created. + * description: A description of the folder. + * listener: A BonoboListener for notification. + * + * Attempts to create the folder @parent_path/@name. When the folder has been + * created, or there is an error, the "evolution-shell:folder-created" event is + * emitted on @listener. The BonoboArg that is sent to @listener is a + * GNOME_Evolution_Storage_FolderResult which has two elements: result and path. + * Result contains the error code, or success, and path contains the complete + * physical path to the newly created folder. + */ void mail_importer_create_folder (const char *parent_path, const char *name, - const char *type, - const char *description) + const char *description, + const BonoboListener *listener) { - BonoboListener *listener; Bonobo_Listener corba_listener; CORBA_Environment ev; char *path, *physical; + char *real_description; + + g_return_if_fail (local_storage != NULL); + g_return_if_fail (listener != NULL); + g_return_if_fail (BONOBO_IS_LISTENER (listener)); path = g_concat_dir_and_file (parent_path, name); physical = g_strdup_printf ("file://%s/local/%s", evolution_dir, parent_path); - listener = bonobo_listener_new (NULL, NULL); corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (listener)); + /* Darn CORBA wanting non-NULL values for strings */ + real_description = CORBA_string_dup (description ? description : ""); CORBA_exception_init (&ev); GNOME_Evolution_Storage_asyncCreateFolder (local_storage, - path, "mail", name, - physical, + path, "mail", + real_description, physical, corba_listener, &ev); CORBA_exception_free (&ev); g_free (path); @@ -120,6 +139,45 @@ mail_importer_add_line (MailImporter *importer, g_free (info); } +/* module management */ +static GList * +get_importer_list (void) +{ + DIR *dir; + struct dirent *d; + GList *importers_ret = NULL; + + dir = opendir (MAIL_IMPORTERSDIR); + if (!dir) { + g_warning ("No importers dir: %s", MAIL_IMPORTERSDIR); + return NULL; + } + + while ((d = readdir (dir))) { + char *path, *ext; + + ext = strchr (d->d_name, '.'); + if (!ext || strcmp (ext, ".so") != 0) + continue; + + path = g_concat_dir_and_file (MAIL_IMPORTERSDIR, d->d_name); + importers_ret = g_list_prepend (importers_ret, path); + } + + closedir (dir); + return importers_ret; +} + +static void +free_importer_list (GList *list) +{ + for (; list; list = list->next) { + g_free (list->data); + } + + g_list_free (list); +} + /** * mail_importer_init: * @@ -128,26 +186,64 @@ mail_importer_add_line (MailImporter *importer, void mail_importer_init (EvolutionShellClient *client) { - BonoboGenericFactory *factory; + GList *importers, *l; - if (factory_initialised == TRUE) + if (importer_modules != NULL) { 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."); + local_storage = evolution_shell_client_get_local_storage (client); + + if (!g_module_supported ()) { + g_warning ("Could not initialise the importers as module loading" + " is not supported on this system"); + return; } - factory = bonobo_generic_factory_new (MBOX_FACTORY_IID, - mbox_factory_fn, NULL); - if (factory == NULL) { - g_error ("Unable to create mbox factory."); + importers = get_importer_list (); + if (importers == NULL) + return; + + for (l = importers; l; l = l->next) { + GModule *module; + + module = g_module_open (l->data, 0); + if (!module) { + g_warning ("Could not load: %s: %s", (char *) l->data, + g_module_error ()); + } else { + void *(*mail_importer_module_init) (); + + if (!g_module_symbol (module, "mail_importer_module_init", + (gpointer *)&mail_importer_module_init)) { + g_warning ("Could not load %s: No initialisation", + (char *) l->data); + g_module_close (module); + } + + mail_importer_module_init (); + importer_modules = g_list_prepend (importer_modules, module); + } } - - factory_initialised = TRUE; - local_storage = evolution_shell_client_get_local_storage (client); + + free_importer_list (importers); +} + +/** + * mail_importer_uninit: + * + * Unloads all the modules. + */ +void +mail_importer_uninit (void) +{ + GList *l; + + for (l = importer_modules; l; l = l->next) { + g_module_close (l->data); + } + + g_list_free (importer_modules); + importer_modules = NULL; } diff --git a/mail/mail-importer.h b/mail/mail-importer.h index e50288c6c0..bab2ff5574 100644 --- a/mail/mail-importer.h +++ b/mail/mail-importer.h @@ -26,8 +26,8 @@ #include <camel/camel-folder.h> #include <camel/camel-stream-mem.h> -#include <camel/camel-exception.h> #include <evolution-shell-client.h> +#include <bonobo/bonobo-listener.h> typedef struct _MailImporter MailImporter; struct _MailImporter { @@ -43,6 +43,6 @@ void mail_importer_add_line (MailImporter *importer, gboolean finished); void mail_importer_create_folder (const char *parent_path, const char *name, - const char *type, - const char *description); + const char *description, + const BonoboListener *listener); #endif diff --git a/mail/netscape-importer.c b/mail/netscape-importer.c deleted file mode 100644 index a505c9300f..0000000000 --- a/mail/netscape-importer.c +++ /dev/null @@ -1,277 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* netscape-importer.c - * - * - * Authors: - * Iain Holmes <iain@ximian.com> - * - * Copyright 2001 Ximian, Inc. (http://www.ximian.com) - * - * 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 <stdio.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <dirent.h> - -#include <glib.h> -#include <gnome.h> - -#include "mail-importer.h" -static char *nsmail_dir = NULL; - -/*#define SUPER_IMPORTER_DEBUG*/ -#ifdef SUPER_IMPORTER_DEBUG -#define d(x) x -#else -#define d(x) -#endif - -#if 0 -typedef struct { - MailImporter importer; - - int num; - CamelMimeParser *mp; -} NetscapeImporter; - -static void -netscape_clean_up (void) -{ - g_free (nsmail_dir); - nsmail_dir = NULL; -} - -static gboolean -netscape_can_import (void) -{ - char *nsprefs; - FILE *prefs_handle; - - nsprefs = gnome_util_prepend_user_home (".netscape/preferences.js"); - prefs_handle = fopen (nsprefs, "r"); - g_free (nsprefs); - - if (prefs_handle == NULL) { - d(g_warning ("No .netscape/preferences.js")); - return FALSE; - } - - /* Find the user mail dir */ - while (1) { - char line[4096]; - - fgets (line, 4096, prefs_handle); - if (line == NULL) { - d(g_warning ("No mail.directory entry")); - fclose (prefs_handle); - return FALSE; - } - - if (strstr (line, "mail.directory") != NULL) { - char *sep, *start, *end; - /* Found the line */ - - sep = strchr (line, ','); - if (sep == NULL) { - d(g_warning ("Bad line %s", line)); - fclose (prefs_handle); - return FALSE; - } - - start = strchr (sep, '\"') + 1; - if (start == NULL) { - d(g_warning ("Bad line %s", line)); - fclose (prefs_handle); - return FALSE; - } - - end = strrchr (sep, '\"'); - if (end == NULL) { - d(g_warning ("Bad line %s", line)); - fclose (prefs_handle); - return FALSE; - } - - nsmail_dir = g_strndup (start, end - start); - d(g_warning ("Got nsmail_dir: %s", nsmail_dir)); - fclose (prefs_handle); - return TRUE; - } - } -} - -static void -netscape_import_file (const char *parent, - const char *dirname, - const char *filename) -{ - char *summary, *summarypath; - - /* Check that the file is a netscape mbox. - It should have an associated .summary file */ - summary = g_strdup_printf (".%s.summary", filename); - summarypath = g_concat_dir_and_file (dirname, summary); - if (!g_file_exists (summarypath)) { - d(g_warning ("%s does not exist.\nIgnoring %s", summary, - filename)); - g_free (summary); - g_free (summarypath); - return; - } - - g_free (summary); - g_free (summarypath); - - /* Do import */ - mail_importer_create_folder (parent, filename, "mail", NULL); - g_print ("Importing %s as %s\n", parent, filename); -} - -static void -scan_dir (NetscapeImporter *importer, - char *parent, - const char *dirname) -{ - DIR *nsmail; - struct stat buf; - struct dirent *current; - - nsmail = opendir (dirname); - if (nsmail == NULL) { - d(g_warning ("Could not open %s\nopendir returned: %s", - dirname, g_strerror (errno))); - return; - } - - current = readdir (nsmail); - while (current) { - char *fullname; - - /* Ignore things which start with . - which should be ., .., and the summaries. */ - if (current->d_name[0] =='.') { - current = readdir (nsmail); - continue; - } - - fullname = g_concat_dir_and_file (dirname, current->d_name); - if (stat (fullname, &buf) == -1) { - d(g_warning ("Could not stat %s\nstat returned:%s", - fullname, g_strerror (errno))); - current = readdir (nsmail); - g_free (fullname); - continue; - } - - if (S_ISREG (buf.st_mode)) { - d(g_print ("File: %s\n", fullname)); - netscape_import_file (importer, parent, dirname, - current->d_name); - } else if (S_ISDIR (buf.st_mode)) { - char *ext; - d(g_print ("Directory: %s\n", fullname)); - - ext = strrchr (current->d_name, '.'); - if (ext && strcmp (ext + 1, "sbd") == 0) { - /* Strip the .sbd */ - if (parent == NULL) { - parent = g_strndup (current->d_name, - ext - current->d_name); - } else { - char *part; - char *tmp; - - part = g_strndup (current->d_name, - ext - current->d_name); - tmp = parent; - parent = g_concat_dir_and_file (parent, - part); - g_free (tmp); - g_free (part); - } - - scan_dir (importer, parent, fullname); - } - } - - g_free (fullname); - current = readdir (nsmail); - } -} - -static void -netscape_create_structure (void) -{ - DIR *nsmail; - struct dirent *current; - NetscapeImporter *importer; - - g_return_if_fail (nsmail_dir != NULL); - - importer = g_new0 (NetscapeImporter, 1); - - g_print ("Creating structure\n" - "------------------\n"); - scan_dir (importer, g_strdup ("/"), nsmail_dir); - g_print ("------------------\n"); -} - - -#ifdef STANDALONE -int -main (int argc, - char **argv) -#else -int -netscape_importer(void) -#endif -{ - gboolean found; - - g_print ("ISI - Iain's Super Importer\n"); - g_print ("Checking for Netscape mail:\t"); - found = netscape_can_import (); - g_print ("%s", found ? "Found" : "Not found"); - - if (found) - g_print (" (%s)\n", nsmail_dir); - else - g_print ("\n"); - - netscape_create_structure (); -} - -BonoboObject * -mbox_factory_fn (BonoboGenericFactory *_factory, - void *closure) -{ - EvolutionImporter *importer; - NetscapeImporter *netscape; - - netscape = g_new0 (NetscapeImporter, 1); - importer = evolution_importer_new (support_format_fn, - load_file_fn, - process_item_fn, NULL, netscape); -} -#endif |