Disallow folder names to begin or end with a dot on Windows.
authorAndrej Kacian <ticho@claws-mail.org>
Wed, 1 Jul 2015 18:37:00 +0000 (20:37 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Wed, 1 Jul 2015 18:37:00 +0000 (20:37 +0200)
I fixed the most obvious locations - MH, RSSyl, mbox. There
may be more.

src/alertpanel.h
src/folder.c
src/folder.h
src/foldersel.c
src/mh_gtk.c
src/plugins/mailmbox/plugin_gtk.c
src/plugins/rssyl/rssyl_cb_menu.c
src/plugins/rssyl/rssyl_subscribe.c

index 800c48e..4a461ad 100644 (file)
@@ -21,6 +21,7 @@
 #define __ALERTPANEL_H__
 
 #include <glib.h>
+#include <gtk/gtk.h>
 
 typedef enum
 {
index 4bd2447..06f12cb 100644 (file)
@@ -36,6 +36,7 @@
 #include <w32lib.h>
 #endif
 
+#include "alertpanel.h"
 #include "folder.h"
 #include "session.h"
 #include "inc.h"
@@ -4811,3 +4812,15 @@ gint folder_item_search_msgs_local       (Folder                 *folder,
        return matched_count;
 }
 
+/* Tests if a local (on disk) folder name is acceptable. */
+gboolean folder_local_name_ok(const gchar *name)
+{
+#ifdef G_OS_WIN32
+       if (name[0] == '.' || new_folder[strlen(name) - 1]) {
+               alertpanel_error(_("A folder name cannot begin or end with a dot.");
+               return FALSE;
+       }
+#endif
+
+       return TRUE;
+}
index e0ad21a..69c0538 100644 (file)
@@ -1005,4 +1005,6 @@ gint folder_item_search_msgs_local        (Folder                 *folder,
                                         gpointer               progress_data);
 
 gchar *folder_get_list_path    (void);
+gboolean folder_local_name_ok(const gchar *name);
+
 #endif /* __FOLDER_H__ */
index ac3cdf1..e618d41 100644 (file)
@@ -597,6 +597,11 @@ static void foldersel_new_folder(GtkButton *button, gpointer data)
                return;
        }
 
+       if (FOLDER_TYPE(selected_item->folder) != F_IMAP &&
+                       FOLDER_TYPE(selected_item->folder) != F_NEWS &&
+                       !folder_local_name_ok(new_folder))
+               return;
+
        disp_name = trim_string(new_folder, 32);
        AUTORELEASE_STR(disp_name, {g_free(disp_name); return;});
 
index 2995f01..d5f0fd5 100644 (file)
@@ -157,6 +157,9 @@ static void new_folder_cb(GtkAction *action, gpointer data)
                return;
        }
 
+       if (!folder_local_name_ok(new_folder))
+               return;
+
        name = trim_string(new_folder, 32);
        AUTORELEASE_STR(name, {g_free(name); return;});
 
@@ -263,6 +266,9 @@ static void rename_folder_cb(GtkAction *action, gpointer data)
                return;
        }
 
+       if (!folder_local_name_ok(new_folder))
+               return;
+
        if (folder_find_child_item_by_name(folder_item_parent(item), new_folder)) {
                name = trim_string(new_folder, 32);
                alertpanel_error(_("The folder '%s' already exists."), name);
index e6b30f5..0ca7336 100644 (file)
@@ -198,13 +198,19 @@ static void add_mailbox(GtkAction *action, gpointer callback_data)
                return;
        }
        basename = g_path_get_basename(path);
+
+       if (!folder_local_name_ok(basename)) {
+               g_free(path);
+               g_free(basename);
+               return;
+       }
+
        folder = folder_new(folder_get_class_from_string("mailmbox"), 
                            !strcmp(path, "Mail") ? _("Mailbox") : basename,
                            path);
-       g_free(basename);                           
+       g_free(basename);
        g_free(path);
 
-
        if (folder->klass->create_tree(folder) < 0) {
                alertpanel_error(_("Creation of the mailbox failed.\n"
                                   "Maybe some files already exist, or you don't have the permission to write there."));
@@ -251,6 +257,9 @@ static void new_folder_cb(GtkAction *action, gpointer data)
                return;
        }
 
+       if (!folder_local_name_ok(new_folder))
+               return;
+
        name = trim_string(new_folder, 32);
        AUTORELEASE_STR(name, {g_free(name); return;});
 
@@ -418,6 +427,9 @@ static void rename_folder_cb(GtkAction *action, gpointer data)
                return;
        }
 
+       if (!folder_local_name_ok(new_folder))
+               return;
+
        parent = folder_item_parent(item);
        p = g_strconcat(parent->path ? parent->path : "", ".", new_folder, NULL);
        if (folder_find_child_item_by_name(parent, p)) {
index 1a30f04..771791b 100644 (file)
@@ -103,6 +103,11 @@ void rssyl_new_folder_cb(GtkAction *action,
                return;
        }
 
+       if (!folder_local_name_ok(new_folder)) {
+               g_free(new_folder);
+               return;
+       }
+
        /* Find an unused name for new folder */
        /* TODO: Perhaps stop after X attempts? */
        tmp = g_strdup(new_folder);
@@ -198,11 +203,16 @@ void rssyl_rename_cb(GtkAction *action,
        g_free(message);
        g_free(name);
        if (!new_folder) return;
-       AUTORELEASE_STR(new_folder, {g_free(new_folder); return;});
 
        if (strchr(new_folder, G_DIR_SEPARATOR) != NULL) {
                alertpanel_error(_("'%c' can't be included in folder name."),
                                 G_DIR_SEPARATOR);
+               g_free(new_folder);
+               return;
+       }
+
+       if (!folder_local_name_ok(new_folder)) {
+               g_free(new_folder);
                return;
        }
 
@@ -210,14 +220,17 @@ void rssyl_rename_cb(GtkAction *action,
                name = trim_string(new_folder, 32);
                alertpanel_error(_("The folder '%s' already exists."), name);
                g_free(name);
+               g_free(new_folder);
                return;
        }
 
        if (folder_item_rename(item, new_folder) < 0) {
                alertpanel_error(_("The folder could not be renamed.\n"
                                   "The new folder name is not allowed."));
+               g_free(new_folder);
                return;
        }
+       g_free(new_folder);
 
        folder_item_prefs_save_config(item);
        folder_write_list();
index 7cc30e9..b9dbc43 100644 (file)
@@ -127,6 +127,15 @@ gboolean rssyl_subscribe(FolderItem *parent, const gchar *url,
        /* Create a folder for it. */
        tmpname = rssyl_format_string(ctx->feed->title, TRUE, TRUE);
        tmpname2 = g_strdup(tmpname);
+
+#ifdef G_OS_WIN32
+       /* Windows does not allow its filenames to start or end with a dot. */
+       if (tmpname2[0] == '.')
+               tmpname2[0] = "_";
+       if (tmpname2[strlen(tmpname2) - 1] == '.')
+               tmpname2[strlen(tmpname2) - 1] == '_';
+#endif
+
        while (folder_find_child_item_by_name(parent, tmpname2) != 0 && i < 20) {
                debug_print("RSSyl: Folder '%s' already exists, trying another name\n",
                                tmpname2);