diff options
author | Iain Holmes <iain@src.gnome.org> | 2001-05-10 09:14:57 +0800 |
---|---|---|
committer | Iain Holmes <iain@src.gnome.org> | 2001-05-10 09:14:57 +0800 |
commit | 8972ac5507406a9697e69b4b42734f62e5f60b07 (patch) | |
tree | 506aec439731bc9d712c5d9a43f9c36449b855bd | |
parent | 72be879a2786d992936b8195b328dfca75b22919 (diff) | |
download | gsoc2013-evolution-8972ac5507406a9697e69b4b42734f62e5f60b07.tar gsoc2013-evolution-8972ac5507406a9697e69b4b42734f62e5f60b07.tar.gz gsoc2013-evolution-8972ac5507406a9697e69b4b42734f62e5f60b07.tar.bz2 gsoc2013-evolution-8972ac5507406a9697e69b4b42734f62e5f60b07.tar.lz gsoc2013-evolution-8972ac5507406a9697e69b4b42734f62e5f60b07.tar.xz gsoc2013-evolution-8972ac5507406a9697e69b4b42734f62e5f60b07.tar.zst gsoc2013-evolution-8972ac5507406a9697e69b4b42734f62e5f60b07.zip |
Use a better method of elm detection
svn path=/trunk/; revision=9740
-rw-r--r-- | importers/ChangeLog | 7 | ||||
-rw-r--r-- | importers/elm-importer.c | 163 |
2 files changed, 120 insertions, 50 deletions
diff --git a/importers/ChangeLog b/importers/ChangeLog index fb4a7f7e80..0c41190527 100644 --- a/importers/ChangeLog +++ b/importers/ChangeLog @@ -1,3 +1,10 @@ +2001-05-09 Iain Holmes <iain@ximian.com> + + * elm-importer.c (elm_can_import): Check the elm rc file for the mail dir. + Handle if the aliases file exists too. + (parse_elm_rc): Parse the elmrc file into a hash table. + (elm_get_rc_value): Get the value out of the hash table. + 2001-05-09 Christopher James Lahey <clahey@ximian.com> * .cvsignore: Added .cvsignore. diff --git a/importers/elm-importer.c b/importers/elm-importer.c index 33c0487953..bda86d72d3 100644 --- a/importers/elm-importer.c +++ b/importers/elm-importer.c @@ -77,6 +77,8 @@ typedef struct { char *path; } ElmFolder; +static GHashTable *elm_prefs = NULL; + static void import_next (ElmImporter *importer); static void @@ -144,47 +146,90 @@ elm_import_file (ElmImporter *importer, return TRUE; } -static gboolean -is_kmail (const char *maildir) +static void +parse_elm_rc (const char *elmrc) { - char *names[5] = - { - "inbox", - "outbox", - "sent-mail", - "trash", - "drafts" - }; - int i; - - for (i = 0; i < 5; i++) { - char *file, *index, *tmp; - - file = g_concat_dir_and_file (maildir, names[i]); - tmp = g_strdup_printf (".%s.index", names[i]); - index = g_concat_dir_and_file (maildir, tmp); - g_free (tmp); - - if (!g_file_exists (file) || - !g_file_exists (index)) { - g_free (index); - g_free (file); - return FALSE; + static gboolean parsed = FALSE; + char line[4096]; + FILE *handle; + gboolean exists; + + if (parsed == TRUE) + return; + + elm_prefs = g_hash_table_new (g_str_hash, g_str_equal); + + exists = g_file_exists (elmrc); + if (exists == FALSE) { + parsed = TRUE; + return; + } + + handle = fopen (elmrc, "r"); + if (handle == NULL) { + parsed = TRUE; + return; + } + + while (fgets (line, 4096, handle) != NULL) { + char *linestart, *end; + char *key, *value; + if (*line == '#' && + (line[1] != '#' && line[2] != '#')) { + continue; + } else if (*line == '\n') { + continue; + } else if (*line == '#' && line[1] == '#' && line[2] == '#') { + linestart = line + 4; + } else { + linestart = line; + } + + g_print ("linestart = '%s'", linestart); + end = strstr (linestart, " = "); + if (end == NULL) { + g_warning ("Broken line"); + continue; + } + + *end = 0; + key = g_strdup (linestart); + + linestart = end + 3; + end = strchr (linestart, '\n'); + if (end == NULL) { + g_warning ("Broken line"); + g_free (key); + continue; } - g_free (index); - g_free (file); + *end = 0; + value = g_strdup (linestart); + + g_hash_table_insert (elm_prefs, key, value); } - return TRUE; + parsed = TRUE; + fclose (handle); +} + +static char * +elm_get_rc_value (const char *value) +{ + if (elm_prefs == NULL) + return NULL; + + return g_hash_table_lookup (elm_prefs, value); } static gboolean elm_can_import (EvolutionIntelligentImporter *ii, void *closure) { - char *key, *maildir, *evolution_dir; - gboolean exists; + ElmImporter *importer = closure; + char *key, *elmdir, *maildir, *evolution_dir, *alias; + char *elmrc; + gboolean exists, mailexists, aliasexists; evolution_dir = gnome_util_prepend_user_home ("evolution"); /* Already imported */ @@ -200,35 +245,53 @@ elm_can_import (EvolutionIntelligentImporter *ii, } gnome_config_pop_prefix (); - /* Elm uses ~/Mail - Alas so does MH and KMail. */ - maildir = gnome_util_prepend_user_home ("Mail"); - exists = g_file_exists (maildir); + elmdir = gnome_util_prepend_user_home (".elm"); + exists = g_file_exists (elmdir); - if (exists) { - char *mh, *mhdir; + g_free (elmdir); + if (exists == FALSE) + return FALSE; - /* Check for some other files to work out what it is. */ + elmrc = gnome_util_prepend_user_home (".elm/elmrc"); + parse_elm_rc (elmrc); - /* MH? */ - mh = g_concat_dir_and_file (maildir, "context"); - mhdir = g_concat_dir_and_file (maildir, "inbox"); - if (g_file_exists (mh) && - g_file_test (mhdir, G_FILE_TEST_ISDIR)) { - exists = FALSE; /* Probably MH */ - } - - g_free (mh); - g_free (mhdir); + maildir = elm_get_rc_value ("maildir"); + if (maildir == NULL) { + maildir = g_strdup ("Mail"); + } else { + maildir = g_strdup (maildir); } - if (exists) { - /* Check for KMail stuff */ - exists = !is_kmail (maildir); + if (!g_path_is_absolute (maildir)) { + elmdir = gnome_util_prepend_user_home (maildir); + } else { + elmdir = g_strdup (maildir); } g_free (maildir); + g_print ("\nChecking for %s\n", elmdir); + mailexists = g_file_exists (elmdir); + g_free (elmdir); + + importer->do_mail = mailexists; + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (importer->mail), + importer->do_mail); + gtk_widget_set_sensitive (importer->mail, mailexists); + + alias = gnome_util_prepend_user_home (".elm/aliases"); + aliasexists = g_file_exists (alias); + g_free (alias); + + importer->do_alias = aliasexists; + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (importer->alias), + importer->do_alias); +#ifdef WE_HAVE_WORKING_ALIAS_IMPORTING + gtk_widget_set_sensitive (importer->alias, aliasexists); +#endif + + exists = (aliasexists || mailexists); + return exists; } |