+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
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;
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);
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;
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;
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;
}
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;
}
} 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];
+}
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__ */
#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"
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) {
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"))
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);
}
+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;
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);
}
}
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;
}
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;
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);
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;
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);
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;
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);
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;
}
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,