global names for folder / read permission for folders / filtering to mbox
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Tue, 29 May 2001 00:29:13 +0000 (00:29 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Tue, 29 May 2001 00:29:13 +0000 (00:29 +0000)
ChangeLog.claws
src/compose.c
src/filtering.c
src/folder.c
src/folder.h
src/mainwindow.c
src/mbox_folder.c
src/prefs_filtering.c

index 3d807d2..9d3a78a 100644 (file)
@@ -1,3 +1,23 @@
+2001-05-29 [hoa]
+
+       * src/compose.c
+               removed some warnings
+
+       * src/filtering.c
+       * src/folder.[ch]
+       * src/prefs_filtering.c
+               global string to identify any folders           
+               removed some debug info
+               filtering to mbox folders is now possible
+
+       * src/mainwindow.c
+               removed some warnings
+
+       * src/mbox_folder.c
+               permission on files are changed to read/write for user only,
+               nothing for other.
+               creation of subfolder is handled better.
+
 2001-05-28 [alfons]
 
        Verified the sync for src/prefs_common.[ch] and
index 6153a55..9fcbc93 100644 (file)
@@ -442,7 +442,7 @@ Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
        Compose *compose;
 
        if (!account) account = cur_account;
-       g_return_if_fail(account != NULL);
+       g_return_val_if_fail(account != NULL, NULL);
 
        compose = compose_create(account);
        compose->mode = COMPOSE_NEW;
@@ -552,14 +552,14 @@ Compose * compose_forward(PrefsAccount * account, MsgInfo *msginfo,
        FILE *fp;
        gchar buf[BUFFSIZE];
 
-       g_return_if_fail(msginfo != NULL);
-       g_return_if_fail(msginfo->folder != NULL);
+       g_return_val_if_fail(msginfo != NULL, NULL);
+       g_return_val_if_fail(msginfo->folder != NULL, NULL);
 
        if (account == NULL) {
                account = msginfo->folder->folder->account;
                if (!account) account = cur_account;
        }
-       g_return_if_fail(account != NULL);
+       g_return_val_if_fail(account != NULL, NULL);
 
        MSG_UNSET_FLAGS(msginfo->flags, MSG_REPLIED);
        MSG_SET_FLAGS(msginfo->flags, MSG_FORWARDED);
index 48d0188..19aed45 100644 (file)
@@ -222,7 +222,8 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
 
        switch(action->type) {
        case MATCHING_ACTION_MOVE:
-               dest_folder = folder_find_item_from_path(action->destination);
+               dest_folder =
+                       folder_find_item_from_identifier(action->destination);
                if (!dest_folder)
                        return FALSE;
 
@@ -250,7 +251,8 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
                return TRUE;
 
        case MATCHING_ACTION_COPY:
-               dest_folder = folder_find_item_from_path(action->destination);
+               dest_folder =
+                       folder_find_item_from_identifier(action->destination);
                if (!dest_folder)
                        return FALSE;
 
index e1a0400..4c148ad 100644 (file)
@@ -341,7 +341,7 @@ Folder *folder_find_from_path(const gchar *path)
 
        for (list = folder_list; list != NULL; list = list->next) {
                folder = list->data;
-               if (folder->type == F_MH &&
+               if ((folder->type == F_MH || folder->type == F_MBOX) &&
                    !path_cmp(LOCAL_FOLDER(folder)->rootpath, path))
                        return folder;
        }
@@ -666,14 +666,10 @@ gint folder_item_move_msgs_with_dest(FolderItem *dest, GSList *msglist)
        if (folder->finished_copy)
                folder->finished_copy(folder, dest);
 
-       printf("là scan\n");
-
        if (item && item->folder->scan)
                item->folder->scan(item->folder, item);
        folder->scan(folder, dest);
 
-       printf("ici scan\n");
-
        return dest->last_num;
 }
 
@@ -1231,3 +1227,153 @@ static void folder_write_list_recursive(GNode *node, gpointer data)
        } else
                fputs(" />\n", fp);
 }
+
+typedef struct _type_str {
+       gchar * str;
+       gint type;
+} type_str;
+
+
+static type_str type_str_table[] = 
+{
+       {"#mh", F_MH},
+       {"#mbox", F_MBOX},
+       {"#maildir", F_MAILDIR},
+       {"#imap", F_IMAP},
+       {"#news", F_NEWS}
+};
+
+
+static gchar * folder_get_type_string(gint type)
+{
+       gint i;
+
+       for(i = 0 ; i < sizeof(type_str_table) / sizeof(type_str) ; i++) {
+               if (type_str_table[i].type == type)
+                       return type_str_table[i].str;
+       }
+       return NULL;
+}
+
+static gint folder_get_type_from_string(gchar * str)
+{
+       gint i;
+
+       for(i = 0 ; i < sizeof(type_str_table) / sizeof(type_str) ; i++) {
+               if (g_strcasecmp(type_str_table[i].str, str))
+                       return type_str_table[i].type;
+       }
+       return F_UNKNOWN;
+}
+
+gchar * folder_get_identifier(Folder * folder)
+{
+       gchar * type_str;
+       type_str = folder_get_type_string(folder->type);
+
+       return g_strconcat(type_str, "/", folder->name, NULL);
+}
+
+/*
+static gchar * folder_item_get_tree_identifier(FolderItem * item)
+{
+       if (item->parent != NULL) {
+               gchar * path;
+               gchar * id;
+
+               path = folder_item_get_tree_identifier(item->parent);
+               if (path == NULL)
+                       return NULL;
+
+               id = g_strconcat(path, "/", item->name, NULL);
+               g_free(path);
+
+               return id;
+       }
+       else {
+               return g_strconcat("/", item->name, NULL);
+       }
+}
+*/
+
+gchar * folder_item_get_identifier(FolderItem * item)
+{
+       gchar * path;
+       gchar * id;
+       gchar * folder_str;
+
+       folder_str = folder_get_identifier(item->folder);
+
+       if (item->path == NULL) {
+               g_free(folder_str);
+               return NULL;
+       }
+
+       id = g_strconcat(folder_str, "/", item->path, NULL);
+
+       return id;
+}
+
+Folder * folder_find_from_name(const gchar * name)
+{
+       GList *list;
+       Folder *folder;
+
+       for (list = g_list_first(folder_list); list != NULL;
+            list = list->next) {
+               folder = list->data;
+               if (strcmp(name, folder->name) == 0)
+                       return folder;
+       }
+       return NULL;
+}
+
+FolderItem * folder_find_item_from_identifier(const gchar *identifier)
+{
+       Folder *folder;
+       gpointer d[2];
+       gchar * str;
+       gchar * p;
+       gint type;
+       gchar * name;
+       gchar * path;
+
+       Xalloca(str, strlen(identifier) + 1, return NULL);
+       strcpy(str, identifier);
+
+       /* extract box type */
+
+       p = strchr(str, '/');
+
+       if (p == NULL)
+               return NULL;
+
+       *p = '\0';
+
+       type = folder_get_type_from_string(str);
+
+       str = p + 1;
+
+       /* extract box name */
+
+       p = strchr(str, '/');
+
+       if (p == NULL)
+               return NULL;
+
+       *p = '\0';
+
+       name = str;
+
+       folder = folder_find_from_name(name);
+       if (folder == NULL)
+               return;
+
+       path = p + 1;
+
+       d[0] = (gpointer)path;
+       d[1] = NULL;
+       g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+                       folder_item_find_func, d);
+       return d[1];
+}
index 64ea96d..7c7706f 100644 (file)
@@ -281,5 +281,7 @@ gboolean folder_item_is_msg_changed (FolderItem     *item,
                                         MsgInfo        *msginfo);
 gchar *folder_item_get_cache_file      (FolderItem     *item);
 gchar *folder_item_get_mark_file       (FolderItem     *item);
+gchar * folder_item_get_identifier(FolderItem * item);
+FolderItem * folder_find_item_from_identifier(const gchar *identifier);
 
 #endif /* __FOLDER_H__ */
index f419909..d77226a 100644 (file)
@@ -57,6 +57,7 @@
 #include "export.h"
 #include "prefs_common.h"
 #include "prefs_filter.h"
+#include "prefs_filtering.h"
 #include "prefs_scoring.h"
 #include "prefs_account.h"
 #include "prefs_folder_item.h"
@@ -1030,10 +1031,12 @@ void main_window_add_mailbox(MainWindow *mainwin)
                g_free(path);
                return;
        }
+
        if (!strcmp(path, "Mail"))
                folder = folder_new(F_MH, _("Mailbox"), path);
        else
                folder = folder_new(F_MH, g_basename(path), path);
+
        g_free(path);
 
        if (folder->create_tree(folder) < 0) {
@@ -1063,13 +1066,11 @@ void main_window_add_mbox(MainWindow *mainwin)
 
        if (!path) return;
 
-       /*
        if (folder_find_from_path(path)) {
                alertpanel_error(_("The mailbox `%s' already exists."), path);
                g_free(path);
                return;
        }
-       */
 
        /*
        if (!strcmp(path, "Mail"))
@@ -1092,11 +1093,11 @@ void main_window_add_mbox(MainWindow *mainwin)
        item->folder = folder;
        folder->node = g_node_new(item);
 
-       mbox_create_folder(folder, item, "inbox");
-       mbox_create_folder(folder, item, "outbox");
-       mbox_create_folder(folder, item, "queue");
-       mbox_create_folder(folder, item, "draft");
-       mbox_create_folder(folder, item, "trash");
+       folder->create_folder(folder, item, "inbox");
+       folder->create_folder(folder, item, "outbox");
+       folder->create_folder(folder, item, "queue");
+       folder->create_folder(folder, item, "draft");
+       folder->create_folder(folder, item, "trash");
 
        folderview_set(mainwin->folderview);
 }
index bce84b9..d536923 100644 (file)
@@ -25,6 +25,23 @@ static gchar * mbox_get_folderitem_name(gchar * name);
 
 
 
+static gchar * mbox_folder_create_parent(const gchar * path)
+{
+       if (!is_file_exist(path)) {
+               gchar * new_path;
+
+               new_path = g_dirname(path);
+               if (new_path[strlen(new_path) - 1] == G_DIR_SEPARATOR)
+                       new_path[strlen(new_path) - 1] = '\0';
+
+               if (!is_dir_exist(new_path))
+                       make_dir_hier(new_path);
+               g_free(new_path);
+               
+       }
+}
+
+
 static gchar *mbox_folder_get_path(FolderItem *item)
 {
        gchar *folder_path;
@@ -33,6 +50,7 @@ static gchar *mbox_folder_get_path(FolderItem *item)
        g_return_val_if_fail(item != NULL, NULL);
 
        if (item->path && item->path[0] == G_DIR_SEPARATOR) {
+               mbox_folder_create_parent(item->path);
                return g_strdup(item->path);
        }
 
@@ -57,26 +75,8 @@ static gchar *mbox_folder_get_path(FolderItem *item)
        }
 
        g_free(folder_path);
-
-
-       if (!is_file_exist(path) && item->parent != NULL) {
-
-               gchar * parent_path;
-               gchar * new_path;
-
-               parent_path = mbox_folder_get_path(item->parent);
-                       
-               if (item->parent->parent != NULL)
-                       new_path = g_strconcat(parent_path, ".sbd", NULL);
-               else
-                       new_path = g_strdup(parent_path);
-               g_free(parent_path);
-               
-               if (!is_dir_exist(new_path))
-                       make_dir_hier(new_path);
-               g_free(new_path);
-               
-       }
+       
+       mbox_folder_create_parent(path);
 
        return path;
 }
@@ -867,10 +867,6 @@ static void mbox_cache_synchronize_lists(GList * old_msg_list,
        for(l2 = old_msg_list ; l2 != NULL ; l2 = g_list_next(l2)) {
                struct _message * msg2 = l2->data;
 
-               printf("lili %p\n", msg2);
-       
-               printf("lili %p\n", msg2->messageid);
-       
                if ((msg2->messageid == NULL) ||
                    (msg2->fromspace == NULL))
                        continue;
@@ -1343,6 +1339,12 @@ gint mbox_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
                g_free(mbox_path);
                return -1;
        }
+
+       if (change_file_mode_rw(dest_fp, mbox_path) < 0) {
+               FILE_OP_ERROR(mbox_path, "chmod");
+               g_warning(_("can't change file mode\n"));
+       }
+
        old_size = ftell(dest_fp);
 
        mbox_lockwrite_file(dest_fp, mbox_path);
@@ -1904,6 +1906,11 @@ static gboolean mbox_rewrite(gchar * mbox)
        new = g_strconcat(mbox, ".new", NULL);
        new_fp = fopen(new, "w");
 
+       if (change_file_mode_rw(new_fp, new) < 0) {
+               FILE_OP_ERROR(new, "chmod");
+               g_warning(_("can't change file mode\n"));
+       }
+
        mbox_lockwrite_file(new_fp, new);
 
        result = TRUE;
@@ -1930,6 +1937,11 @@ static gboolean mbox_rewrite(gchar * mbox)
                return -1;
        }
 
+       if (change_file_mode_rw(new_fp, mbox) < 0) {
+               FILE_OP_ERROR(new, "chmod");
+               g_warning(_("can't change file mode\n"));
+       }
+
        mbox_unlock_file(new_fp, new);
 
        fclose(new_fp);
@@ -1985,9 +1997,15 @@ static gboolean mbox_purge_deleted(gchar * mbox)
 
        mbox_cache_synchronize_from_file(mbox_fp, mbox, TRUE);
 
+       // better filename should be used
        new = g_strconcat(mbox, ".new", NULL);
        new_fp = fopen(new, "w");
 
+       if (change_file_mode_rw(new_fp, new) < 0) {
+               FILE_OP_ERROR(new, "chmod");
+               g_warning(_("can't change file mode\n"));
+       }
+
        mbox_lockwrite_file(new_fp, new);
 
        result = TRUE;
@@ -2016,6 +2034,11 @@ static gboolean mbox_purge_deleted(gchar * mbox)
                return -1;
        }
 
+       if (change_file_mode_rw(new_fp, mbox) < 0) {
+               FILE_OP_ERROR(new, "chmod");
+               g_warning(_("can't change file mode\n"));
+       }
+
        mbox_unlock_file(new_fp, new);
 
        fclose(new_fp);
@@ -2083,21 +2106,9 @@ static gchar * mbox_get_new_path(FolderItem * parent, gchar * name)
 static gchar * mbox_get_folderitem_name(gchar * name)
 {
        gchar * foldername;
-       gchar * p;
 
-       if ((p = strchr(name, '/')) == NULL)
-               foldername = g_strdup(name);
-       else {
-               gchar * newp = p;
-
-               while (newp != NULL) {
-                       newp = strchr(p, '/');
-                       if (newp != NULL)
-                               p = newp + 1;
-               }
-
-               foldername = g_strdup(p);
-       }
+       foldername = g_strdup(g_basename(name));
+       
        return foldername;
 }
 
index a4f542c..a347044 100644 (file)
@@ -870,11 +870,15 @@ static void prefs_filtering_select(GtkCList *clist, gint row, gint column,
 static void prefs_filtering_select_dest(void)
 {
        FolderItem *dest;
+       gchar * path;
 
        dest = foldersel_folder_sel(NULL);
        if (!dest) return;
 
-       gtk_entry_set_text(GTK_ENTRY(filtering.dest_entry), dest->path);
+       path = folder_item_get_identifier(dest);
+
+       gtk_entry_set_text(GTK_ENTRY(filtering.dest_entry), path);
+       g_free(path);
 }
 
 static void prefs_filtering_action_select(GtkList *list,