diff options
author | Not Zed <NotZed@Ximian.com> | 2004-02-13 18:14:30 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-02-13 18:14:30 +0800 |
commit | 39f16a70161b982003faca8b1fea7845a4a4e5fc (patch) | |
tree | f757ae0e6cc6957336c07f49781b8bfc50b6f8bc /mail/importers/mail-importer.c | |
parent | 1f4808666f7070789ada617b9fbb652d4e9512a0 (diff) | |
download | gsoc2013-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/mail-importer.c')
-rw-r--r-- | mail/importers/mail-importer.c | 87 |
1 files changed, 71 insertions, 16 deletions
diff --git a/mail/importers/mail-importer.c b/mail/importers/mail-importer.c index 0cfeb3b56a..ea28ff3a7b 100644 --- a/mail/importers/mail-importer.c +++ b/mail/importers/mail-importer.c @@ -200,6 +200,8 @@ import_mbox_import(struct _mail_msg *mm) return; if (S_ISREG(st.st_mode)) { + CamelOperation *oldcancel = NULL; + fd = open(m->path, O_RDONLY); if (fd == -1) { g_warning("cannot find source file to import '%s': %s", m->path, g_strerror(errno)); @@ -213,7 +215,7 @@ import_mbox_import(struct _mail_msg *mm) } if (m->cancel) - camel_operation_register(m->cancel); + oldcancel = camel_operation_register(m->cancel); camel_operation_start(NULL, _("Importing `%s'"), folder->full_name); camel_folder_freeze(folder); @@ -254,16 +256,17 @@ import_mbox_import(struct _mail_msg *mm) camel_mime_parser_step(mp, 0, 0); } - camel_folder_sync(folder, FALSE, &mm->ex); + camel_folder_sync(folder, FALSE, NULL); camel_folder_thaw(folder); camel_operation_end(NULL); + /* TODO: these api's are a bit weird, registering the old is the same as deregistering */ if (m->cancel) - camel_operation_unregister(m->cancel); + camel_operation_register(oldcancel); fail2: camel_object_unref(mp); } fail1: - camel_folder_sync(folder, FALSE, &mm->ex); + camel_folder_sync(folder, FALSE, NULL); camel_object_unref(folder); } @@ -328,11 +331,15 @@ mail_importer_import_mbox_sync(const char *path, const char *folderuri, CamelOpe mail_msg_free(&m->msg); } -/* This should probably take a list of all folders, otherwise we need to duplicate it for netscape folders */ +struct _import_folders_data { + MailImporterSpecial *special_folders; + CamelOperation *cancel; -/* pass folderparent = NULL first time */ -void -mail_importer_import_folders_sync(const char *filepath, const char *folderparent, MailImporterSpecial special_folders[], CamelOperation *cancel) + int elmfmt:1; +}; + +static void +import_folders_rec(struct _import_folders_data *m, const char *filepath, const char *folderparent) { DIR *dir; struct dirent *d; @@ -347,13 +354,15 @@ mail_importer_import_folders_sync(const char *filepath, const char *folderparent camel_operation_start(NULL, _("Scanning %s"), filepath); while ( (d=readdir(dir)) ) { - if (strcmp(d->d_name, ".") == 0 - || strcmp(d->d_name, "..") == 0) + if (d->d_name[0] == '.') continue; filefull = g_build_filename(filepath, d->d_name, NULL); + + /* skip non files and directories, and skip directories in mozilla mode */ if (stat(filefull, &st) == -1 - || !(S_ISREG(st.st_mode) || S_ISDIR(st.st_mode))) { + || !(S_ISREG(st.st_mode) + || (m->elmfmt && S_ISDIR(st.st_mode)))) { g_free(filefull); continue; } @@ -362,9 +371,9 @@ mail_importer_import_folders_sync(const char *filepath, const char *folderparent if (folderparent == NULL) { int i; - for (i=0;special_folders[i].orig;i++) - if (strcmp(special_folders[i].orig, folder) == 0) { - folder = special_folders[i].new; + for (i=0;m->special_folders[i].orig;i++) + if (strcmp(m->special_folders[i].orig, folder) == 0) { + folder = m->special_folders[i].new; break; } /* FIXME: need a better way to get default store location */ @@ -374,12 +383,24 @@ mail_importer_import_folders_sync(const char *filepath, const char *folderparent } printf("importing to uri %s\n", uri); - mail_importer_import_mbox_sync(filefull, uri, cancel); + mail_importer_import_mbox_sync(filefull, uri, m->cancel); g_free(uri); + /* This little gem re-uses the stat buffer and filefull to automagically scan mozilla-format folders */ + if (!m->elmfmt) { + char *tmp = g_strdup_printf("%s.sbd", filefull); + + g_free(filefull); + filefull = tmp; + if (stat(filefull, &st) == -1) { + g_free(filefull); + continue; + } + } + if (S_ISDIR(st.st_mode)) { foldersub = folderparent?g_strdup_printf("%s/%s", folderparent, folder):g_strdup(folder); - mail_importer_import_folders_sync(filefull, foldersub, special_folders, cancel); + import_folders_rec(m, filefull, foldersub); g_free(foldersub); } @@ -388,3 +409,37 @@ mail_importer_import_folders_sync(const char *filepath, const char *folderparent camel_operation_end(NULL); } + +/** + * mail_importer_import_folders_sync: + * @filepath: + * @: + * @flags: + * @cancel: + * + * import from a base path @filepath into the root local folder tree, + * scanning all sub-folders. + * + * if @flags is MAIL_IMPORTER_MOZFMT, then subfolders are assumed to + * be in mozilla/evolutoin 1.5 format, appending '.sbd' to the + * directory name. Otherwise they are in elm/mutt/pine format, using + * standard unix directories. + **/ +void +mail_importer_import_folders_sync(const char *filepath, MailImporterSpecial special_folders[], int flags, CamelOperation *cancel) +{ + struct _import_folders_data m; + CamelOperation *oldcancel = NULL; + + m.special_folders = special_folders; + m.elmfmt = (flags & MAIL_IMPORTER_MOZFMT) == 0; + m.cancel = cancel; + + if (cancel) + oldcancel = camel_operation_register(cancel); + + import_folders_rec(&m, filepath, NULL); + + if (cancel) + camel_operation_register(oldcancel); +} |