aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2010-08-06 09:26:12 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2010-08-06 09:26:12 +0000
commit2d01a4712433affe66a398c4769125015cb7691d (patch)
treeed799288cece78496e805e5dfe5723a66e033b90
parenta13c336e4fe1c4b8c370a7b21d595ccf20b3f821 (diff)
win32: implemented automatic import of Outlook Express mail stores on first run.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2661 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog7
-rw-r--r--src/import.c87
-rw-r--r--src/import.h4
-rw-r--r--src/main.c6
-rw-r--r--src/setup.c163
-rw-r--r--src/setup.h3
6 files changed, 268 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 6693ddb9..4dbeb7ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-08-06
+
+ * src/main.c
+ src/setup.[ch]
+ src/import.[ch]: win32: implemented automatic import of Outlook
+ Express mail stores on first run.
+
2010-08-05
* src/import.c: implemented the import feature of Outlook Express
diff --git a/src/import.c b/src/import.c
index b0a4c21c..615ccaf3 100644
--- a/src/import.c
+++ b/src/import.c
@@ -462,6 +462,93 @@ static gint import_dbx(FolderItem *dest, const gchar *file)
return 0;
}
+gint import_dbx_folders(FolderItem *dest, const gchar *path)
+{
+ GDir *dir;
+ const gchar *dir_name, *p;
+ gchar *orig_name, *folder_name, *file;
+ gchar *msg;
+ FolderItem *sub_folder;
+ gint count;
+ gint ok = 0;
+
+ g_return_val_if_fail(dest != NULL, -1);
+ g_return_val_if_fail(dest->folder != NULL, -1);
+ g_return_val_if_fail(path != NULL, -1);
+
+ if ((dir = g_dir_open(path, 0, NULL)) == NULL) {
+ g_warning("failed to open directory: %s", path);
+ return -1;
+ }
+
+ progress = progress_dialog_simple_create();
+ gtk_window_set_title(GTK_WINDOW(progress->window), _("Importing"));
+ progress_dialog_set_label(progress, _("Importing Outlook Express folders"));
+ gtk_window_set_modal(GTK_WINDOW(progress->window), TRUE);
+ manage_window_set_transient(GTK_WINDOW(progress->window));
+ gtk_widget_hide(progress->cancel_btn);
+ g_signal_connect(G_OBJECT(progress->window), "delete_event",
+ G_CALLBACK(gtk_true), NULL);
+ gtk_widget_show(progress->window);
+ ui_update();
+
+ while ((dir_name = g_dir_read_name(dir)) != NULL) {
+ if ((p = strrchr(dir_name, '.')) &&
+ !g_ascii_strcasecmp(p + 1, "dbx")) {
+ file = g_strconcat(path, G_DIR_SEPARATOR_S, dir_name,
+ NULL);
+ orig_name = g_strndup(dir_name, p - dir_name);
+ if (!g_file_test(file, G_FILE_TEST_IS_REGULAR) ||
+ !g_ascii_strcasecmp(orig_name, "Folders") ||
+ !g_ascii_strcasecmp(orig_name, "Offline") ||
+ !g_ascii_strcasecmp(orig_name, "Pop3uidl")) {
+ g_free(orig_name);
+ g_free(file);
+ continue;
+ }
+
+ folder_name = g_strdup(orig_name);
+ count = 1;
+ while (folder_find_child_item_by_name(dest, folder_name)) {
+ g_free(folder_name);
+ folder_name = g_strdup_printf("%s (%d)", orig_name, count++);
+ }
+ g_print("orig_name: %s , folder_name: %s\n", orig_name, folder_name);
+
+ sub_folder = dest->folder->klass->create_folder(dest->folder, dest, folder_name);
+ if (!sub_folder) {
+ alertpanel_error(_("Cannot create the folder '%s'."), folder_name);
+ ok = -1;
+ break;
+ }
+ folderview_append_item(folderview_get(), NULL, sub_folder, TRUE);
+ folder_write_list();
+ msg = g_strdup_printf(_("Importing %s ..."), orig_name);
+ progress_dialog_set_label(progress, msg);
+ g_free(msg);
+ import_dbx(sub_folder, file);
+
+ progress_dialog_set_label(progress, _("Scanning folder..."));
+ ui_update();
+ folder_item_scan(sub_folder);
+ folderview_update_item(sub_folder, TRUE);
+
+ g_free(folder_name);
+ g_free(orig_name);
+ g_free(file);
+ }
+ }
+
+ g_dir_close(dir);
+
+ progress_dialog_destroy(progress);
+ progress = NULL;
+
+ folder_write_list();
+
+ return ok;
+}
+
static void import_create(void)
{
GtkWidget *vbox;
diff --git a/src/import.h b/src/import.h
index ea121c86..c9dd4ef8 100644
--- a/src/import.h
+++ b/src/import.h
@@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2009 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2010 Hiroyuki Yamamoto
*
* 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
@@ -26,4 +26,6 @@
gint import_mail(FolderItem *default_dest);
+gint import_dbx_folders(FolderItem *dest, const gchar *path);
+
#endif /* __IMPORT_H__ */
diff --git a/src/main.c b/src/main.c
index 234c9a0b..81bdfd18 100644
--- a/src/main.c
+++ b/src/main.c
@@ -214,6 +214,7 @@ int main(int argc, char *argv[])
#endif
GObject *syl_app;
PrefsAccount *new_account = NULL;
+ gboolean first_run = FALSE;
app_init();
parse_cmd_opt(argc, argv);
@@ -339,6 +340,7 @@ int main(int argc, char *argv[])
main_window_reflect_prefs_all();
if (folder_read_list() < 0) {
+ first_run = TRUE;
setup_mailbox();
folder_write_list();
}
@@ -367,6 +369,10 @@ int main(int argc, char *argv[])
g_signal_emit_by_name(syl_app, "init-done");
+ if (first_run) {
+ setup_import();
+ }
+
remote_command_exec();
#if USE_UPDATE_CHECK
diff --git a/src/setup.c b/src/setup.c
index 8be0bffd..00cbebe0 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -25,6 +25,12 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#ifdef G_OS_WIN32
+# include <windows.h>
+# include <winreg.h>
+# include <wchar.h>
+#endif
+
#include "inputdialog.h"
#include "alertpanel.h"
#include "mainwindow.h"
@@ -1016,3 +1022,160 @@ PrefsAccount *setup_account(void)
return ac;
}
+
+#ifdef G_OS_WIN32
+struct Identity
+{
+ gchar *name;
+ gchar *path;
+};
+
+static GSList *get_dbx_source(void)
+{
+ HKEY reg_key, hkey, hkey2;
+ wchar_t name[1024];
+ DWORD size, type, i;
+ LPWSTR username, store, path;
+ GSList *src_list = NULL;
+
+ if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Identities", 0, KEY_READ, &reg_key) != ERROR_SUCCESS)
+ return NULL;
+
+ for (i = 0; ; i++) {
+ size = sizeof(name);
+ if (RegEnumKeyExW(reg_key, i, name, &size, 0, 0, 0, 0) != ERROR_SUCCESS)
+ break;
+ if (RegOpenKeyExW(reg_key, name, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
+ continue;
+
+ do {
+ if (RegQueryValueExW(hkey, L"UserName", 0, &type, 0, &size) != ERROR_SUCCESS)
+ break;
+ if (type != REG_SZ)
+ break;
+ ++size;
+ username = g_malloc(size);
+ if (RegQueryValueExW(hkey, L"UserName", 0, &type, (LPBYTE)username, &size) != ERROR_SUCCESS) {
+ g_free(username);
+ break;
+ }
+
+ if (RegOpenKeyExW(hkey, L"Software\\Microsoft\\Outlook Express\\5.0", 0, KEY_READ, &hkey2) != ERROR_SUCCESS) {
+ g_free(username);
+ break;
+ }
+
+ do {
+ if (RegQueryValueExW(hkey2, L"Store Root", 0, &type, 0, &size) != ERROR_SUCCESS)
+ break;
+ if (type != REG_SZ && type != REG_EXPAND_SZ)
+ break;
+
+ ++size;
+ store = g_malloc(size);
+ if (RegQueryValueExW(hkey2, L"Store Root", 0, &type, (LPBYTE)store, &size) != ERROR_SUCCESS) {
+ g_free(store);
+ break;
+ }
+
+ if (type == REG_EXPAND_SZ) {
+ size = MAX_PATH * 2;
+ path = g_malloc(size);
+ if (!ExpandEnvironmentStringsW(store, path, size)) {
+ g_free(path);
+ path = NULL;
+ }
+ } else {
+ path = store;
+ store = NULL;
+ }
+
+ if (path) {
+ struct Identity *ident;
+
+ ident = g_new(struct Identity, 1);
+ ident->name = g_utf16_to_utf8(username, -1, NULL, NULL, NULL);
+ ident->path = g_utf16_to_utf8(path, -1, NULL, NULL, NULL);
+ src_list = g_slist_append(src_list, ident);
+ debug_print("get_dbx_source: username = %s , path = %s\n", ident->name, ident->path);
+ g_free(path);
+ }
+ g_free(store);
+ } while (0);
+ g_free(username);
+ RegCloseKey(hkey2);
+ } while (0);
+ RegCloseKey(hkey);
+ }
+
+ RegCloseKey(reg_key);
+
+ return src_list;
+}
+#endif /* G_OS_WIN32 */
+
+gint setup_import(void)
+{
+#ifdef G_OS_WIN32
+ AlertValue val;
+ GSList *src_list, *cur;
+ struct Identity *ident;
+ gchar *src;
+ Folder *folder;
+ FolderItem *parent, *dest;
+
+ debug_print("setup_import\n");
+
+ src_list = get_dbx_source();
+ if (!src_list)
+ return 0;
+
+ val = alertpanel(_("Importing mail data"), _("The mail store of Outlook Express was found. Do you want to import the mail data of Outlook Express?\n\n(The folder structure will not be reproduced)"), GTK_STOCK_YES, GTK_STOCK_NO, NULL);
+ if (val != G_ALERTDEFAULT) {
+ goto finish;
+ }
+
+ folder = folder_get_default_folder();
+ if (!folder) {
+ g_warning("Cannot get default folder");
+ goto finish;
+ }
+ parent = FOLDER_ITEM(folder->node->data);
+ if (!parent) {
+ g_warning("Cannot get root folder");
+ goto finish;
+ }
+ dest = folder_find_child_item_by_name(parent, "Imported");
+ if (!dest) {
+ dest = folder->klass->create_folder(folder, parent, "Imported");
+ }
+ if (!dest) {
+ g_warning("Cannot create a folder");
+ goto finish;
+ }
+ parent = dest;
+ folderview_append_item(folderview_get(), NULL, parent, TRUE);
+ folder_write_list();
+
+ for (cur = src_list; cur != NULL; cur = cur->next) {
+ ident = (struct Identity *)cur->data;
+ dest = folder->klass->create_folder(folder, parent, ident->name);
+ if (!dest)
+ continue;
+ folderview_append_item(folderview_get(), NULL, dest, TRUE);
+ folder_write_list();
+ import_dbx_folders(dest, ident->path);
+ }
+
+finish:
+ for (cur = src_list; cur != NULL; cur = cur->next) {
+ ident = (struct Identity *)cur->data;
+ g_free(ident->name);
+ g_free(ident->path);
+ g_free(ident);
+ }
+ g_slist_free(src_list);
+#endif /* G_OS_WIN32 */
+
+ return 0;
+}
diff --git a/src/setup.h b/src/setup.h
index fd9af67c..322f2e8c 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2010 Hiroyuki Yamamoto
*
* 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
@@ -26,5 +26,6 @@
void setup_mailbox(void);
PrefsAccount *setup_account(void);
+gint setup_import(void);
#endif /* __SETUP_H__ */