fix bug 2979, 'claws fails to load (empty) folderlist.xml and shows account wizard'
authorPaul <paul@claws-mail.org>
Tue, 27 Aug 2013 08:45:42 +0000 (09:45 +0100)
committerPaul <paul@claws-mail.org>
Tue, 27 Aug 2013 08:45:42 +0000 (09:45 +0100)
po/POTFILES.in
src/Makefile.am
src/file_checker.c [new file with mode: 0644]
src/file_checker.h [new file with mode: 0644]
src/folder.c
src/folder.h
src/main.c

index 2599a27..9d7a8a3 100644 (file)
@@ -36,6 +36,7 @@ src/expldifdlg.c
 src/export.c
 src/exporthtml.c
 src/exportldif.c
 src/export.c
 src/exporthtml.c
 src/exportldif.c
+src/file_checker.c
 src/folder.c
 src/foldersel.c
 src/folderview.c
 src/folder.c
 src/foldersel.c
 src/folderview.c
index 1a173ee..08bc2b3 100644 (file)
@@ -54,6 +54,7 @@ old_abook_source = \
        expldifdlg.c \
        exporthtml.c \
        exportldif.c \
        expldifdlg.c \
        exporthtml.c \
        exportldif.c \
+       file_checker.c \
        importldif.c \
        importmutt.c \
        importpine.c \
        importldif.c \
        importmutt.c \
        importpine.c \
@@ -102,6 +103,7 @@ abook_headers = \
        expldifdlg.h \
        exporthtml.h \
        exportldif.h \
        expldifdlg.h \
        exporthtml.h \
        exportldif.h \
+       file_checker.h \
        importldif.h \
        importmutt.h \
        importpine.h \
        importldif.h \
        importmutt.h \
        importpine.h \
diff --git a/src/file_checker.c b/src/file_checker.c
new file mode 100644 (file)
index 0000000..5205070
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2013 Paul Mangan <paul@claws-mail.org> 
+ * and the Claws Mail team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#include "claws-features.h"
+#endif
+
+#include "defs.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "utils.h"
+#include "alertpanel.h"
+#include "folder.h"
+
+static gboolean verify_folderlist_xml();
+
+gboolean check_file_integrity() {
+       if (verify_folderlist_xml() != TRUE)
+               return FALSE;
+
+       return TRUE;
+}
+
+static gboolean verify_folderlist_xml() {
+       GNode *node;
+       static gchar *filename = NULL;
+       static gchar *bak = NULL;
+       time_t date;
+       struct tm *ts;
+       gchar buf[BUFFSIZE];
+
+       filename = folder_get_list_path();
+       bak = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                         FOLDER_LIST, ".bak", NULL);
+       
+       if (is_file_exist(bak)) {
+               date = get_file_mtime(bak);
+               ts = localtime(&date);
+               strftime(buf, sizeof(buf), "%a %d-%b-%Y %H:%M %Z", ts);
+       }
+       
+       if (!is_file_exist(filename) && is_file_exist(bak)) {
+               AlertValue aval;
+               gchar *msg;
+
+               msg = g_strdup_printf
+                       (_("The file %s is missing! "
+                          "Do you want to use the backup file from %s?"), FOLDER_LIST,buf);
+               aval = alertpanel(_("Warning"), msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL);
+               g_free(msg);
+               if (aval != G_ALERTALTERNATE)
+                       return FALSE;
+               else {
+                       if (copy_file(bak,filename,FALSE) < 0) {
+                               alertpanel_warning(_("Could not copy %s to %s"),bak,filename);
+                               return FALSE;
+                       }
+                       g_free(bak);
+                       return TRUE;
+               }
+
+       }
+       node = xml_parse_file(filename);
+       if (!node && is_file_exist(bak)) {
+               AlertValue aval;
+               gchar *msg;
+
+               msg = g_strdup_printf
+                       (_("The file %s is empty or corrupted! "
+                          "Do you want to use the backup file from %s?"), FOLDER_LIST,buf);
+               aval = alertpanel(_("Warning"), msg, GTK_STOCK_NO, GTK_STOCK_YES, NULL);
+               g_free(msg);
+               if (aval != G_ALERTALTERNATE)
+                       return FALSE;
+               else {
+                       if (copy_file(bak,filename,FALSE) < 0) {
+                               alertpanel_warning(_("Could not copy %s to %s"),bak,filename);
+                               return FALSE;
+                       }
+                       g_free(bak);    
+               }
+       }
+
+       return TRUE;    
+}
diff --git a/src/file_checker.h b/src/file_checker.h
new file mode 100644 (file)
index 0000000..e08ffe1
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2013 Paul Mangan <paul@claws-mail.org> 
+ * and the Claws Mail team
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+#ifndef __FILE_CHECKER_H__
+#define __FILE_CHECKER_H__
+
+#include <glib.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+
+gboolean check_file_integrity();
+
+#endif
index 39ba0e4..1b4ec03 100644 (file)
@@ -88,7 +88,6 @@ void folder_init              (Folder         *folder,
 static gchar *folder_item_get_cache_file       (FolderItem     *item);
 static gchar *folder_item_get_mark_file        (FolderItem     *item);
 static gchar *folder_item_get_tags_file        (FolderItem     *item);
 static gchar *folder_item_get_cache_file       (FolderItem     *item);
 static gchar *folder_item_get_mark_file        (FolderItem     *item);
 static gchar *folder_item_get_tags_file        (FolderItem     *item);
-static gchar *folder_get_list_path     (void);
 static GNode *folder_get_xml_node      (Folder         *folder);
 static Folder *folder_get_from_xml     (GNode          *node);
 static void folder_update_op_count_rec (GNode          *node);
 static GNode *folder_get_xml_node      (Folder         *folder);
 static Folder *folder_get_from_xml     (GNode          *node);
 static void folder_update_op_count_rec (GNode          *node);
@@ -4122,7 +4121,7 @@ static Folder *folder_get_from_xml(GNode *node)
        return folder;
 }
 
        return folder;
 }
 
-static gchar *folder_get_list_path(void)
+gchar *folder_get_list_path(void)
 {
        static gchar *filename = NULL;
 
 {
        static gchar *filename = NULL;
 
index d87eb0c..44f69bb 100644 (file)
@@ -998,4 +998,5 @@ gint folder_item_search_msgs_local  (Folder                 *folder,
                                         SearchProgressNotify   progress_cb,
                                         gpointer               progress_data);
 
                                         SearchProgressNotify   progress_cb,
                                         gpointer               progress_data);
 
+gchar *folder_get_list_path    (void);
 #endif /* __FOLDER_H__ */
 #endif /* __FOLDER_H__ */
index f7a2eaa..c7d3eac 100644 (file)
@@ -49,6 +49,7 @@
 #include <sys/file.h>
 #endif
 
 #include <sys/file.h>
 #endif
 
+#include "file_checker.h"
 #include "wizard.h"
 #ifdef HAVE_STARTUP_NOTIFICATION
 # define SN_API_NOT_YET_FROZEN
 #include "wizard.h"
 #ifdef HAVE_STARTUP_NOTIFICATION
 # define SN_API_NOT_YET_FROZEN
@@ -1277,6 +1278,9 @@ int main(int argc, char *argv[])
 
        mainwin = main_window_create();
 
 
        mainwin = main_window_create();
 
+       if (!check_file_integrity())
+               exit(1);
+
 #ifdef HAVE_NETWORKMANAGER_SUPPORT
        networkmanager_state_change_cb(nm_proxy,NULL,mainwin);
 #endif
 #ifdef HAVE_NETWORKMANAGER_SUPPORT
        networkmanager_state_change_cb(nm_proxy,NULL,mainwin);
 #endif