aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--importers/ChangeLog6
-rw-r--r--importers/netscape-importer.c57
2 files changed, 60 insertions, 3 deletions
diff --git a/importers/ChangeLog b/importers/ChangeLog
index af648d6f94..2b574641ab 100644
--- a/importers/ChangeLog
+++ b/importers/ChangeLog
@@ -1,3 +1,9 @@
+2001-07-16 Iain Holmes <iain@ximian.com>
+
+ * netscape-importer.c (is_dir_empty): Find out if a dir is either empty
+ or contains only 0 length files.
+ (netscape_can_import): Only import a file if the dir isn't empty.
+
2001-07-12 Iain Holmes <iain@ximian.com>
* netscape-importer.c (netscape_init_prefs): Ignore comments.
diff --git a/importers/netscape-importer.c b/importers/netscape-importer.c
index b900642241..e8827e1bb1 100644
--- a/importers/netscape-importer.c
+++ b/importers/netscape-importer.c
@@ -444,7 +444,57 @@ netscape_import_accounts (NetscapeImporter *importer)
CORBA_exception_free (&ev);
}
+
+static gboolean
+is_dir_empty (const char *path)
+{
+ DIR *base;
+ struct stat buf;
+ struct dirent *contents;
+
+ base = opendir (path);
+ if (base == NULL) {
+ return TRUE; /* Can't open dir */
+ }
+ contents = readdir (base);
+ while (contents != NULL) {
+ char *fullpath;
+
+ if (strcmp (contents->d_name, ".") == 0 ||
+ strcmp (contents->d_name, "..") == 0) {
+ contents = readdir (base);
+ continue;
+ }
+
+ fullpath = g_concat_dir_and_file (path, contents->d_name);
+ stat (fullpath, &buf);
+ if (S_ISDIR (buf.st_mode)) {
+ gboolean sub;
+
+ sub = is_dir_empty (fullpath);
+ if (sub == FALSE) {
+ g_free (fullpath);
+ closedir (base);
+ return FALSE;
+ }
+ } else {
+ /* File */
+ if (buf.st_size != 0) {
+ g_free (fullpath);
+ closedir (base);
+ return FALSE;
+ }
+ }
+
+ g_free (fullpath);
+ contents = readdir (base);
+ }
+
+ closedir (base);
+ return TRUE;
+}
+
static gboolean
netscape_can_import (EvolutionIntelligentImporter *ii,
void *closure)
@@ -477,10 +527,11 @@ netscape_can_import (EvolutionIntelligentImporter *ii,
}
nsmail_dir = g_hash_table_lookup (user_prefs, "mail.directory");
- if (nsmail_dir == NULL)
+ if (nsmail_dir == NULL) {
return FALSE;
- else
- return TRUE;
+ } else {
+ return is_dir_empty (nsmail_dir);
+ }
}
static void