2001-04-19 14:21:46 +02:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2002-01-16 12:48:36 +01:00
|
|
|
* Copyright (C) 1999-2002 Hiroyuki Yamamoto
|
2001-04-19 14:21:46 +02:00
|
|
|
*
|
|
|
|
* 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 2 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2002-06-30 01:33:42 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2002-06-19 09:31:13 +02:00
|
|
|
#include <stdlib.h>
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
#include "intl.h"
|
|
|
|
#include "folder.h"
|
|
|
|
#include "session.h"
|
|
|
|
#include "imap.h"
|
|
|
|
#include "news.h"
|
|
|
|
#include "mh.h"
|
2001-05-23 14:08:40 +02:00
|
|
|
#include "mbox_folder.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
#include "utils.h"
|
|
|
|
#include "xml.h"
|
|
|
|
#include "codeconv.h"
|
|
|
|
#include "prefs.h"
|
|
|
|
#include "account.h"
|
2002-07-02 21:49:11 +02:00
|
|
|
#include "filtering.h"
|
|
|
|
#include "scoring.h"
|
2001-12-23 15:30:06 +01:00
|
|
|
#include "prefs_folder_item.h"
|
2002-06-30 01:33:42 +02:00
|
|
|
#include "procheader.h"
|
2002-11-09 03:09:58 +01:00
|
|
|
#include "statusbar.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-11-09 17:35:13 +01:00
|
|
|
/* Dependecies to be removed ?! */
|
|
|
|
#include "prefs_common.h"
|
|
|
|
#include "prefs_account.h"
|
|
|
|
#include "prefs_folder_item.h"
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static GList *folder_list = NULL;
|
|
|
|
|
|
|
|
static void folder_init (Folder *folder,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static gboolean folder_read_folder_func (GNode *node,
|
|
|
|
gpointer data);
|
|
|
|
static gchar *folder_get_list_path (void);
|
|
|
|
static void folder_write_list_recursive (GNode *node,
|
|
|
|
gpointer data);
|
2001-07-31 08:17:48 +02:00
|
|
|
static void folder_update_op_count_rec (GNode *node);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
|
2001-12-30 02:27:14 +01:00
|
|
|
static void folder_get_persist_prefs_recursive
|
|
|
|
(GNode *node, GHashTable *pptable);
|
|
|
|
static gboolean persist_prefs_free (gpointer key, gpointer val, gpointer data);
|
2002-06-30 01:33:42 +02:00
|
|
|
void folder_item_read_cache (FolderItem *item);
|
2002-07-02 21:49:11 +02:00
|
|
|
void folder_item_free_cache (FolderItem *item);
|
2001-12-30 02:27:14 +01:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
Folder *folder_new(FolderType type, const gchar *name, const gchar *path)
|
|
|
|
{
|
|
|
|
Folder *folder = NULL;
|
2002-10-14 23:23:12 +02:00
|
|
|
FolderItem *item;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
name = name ? name : path;
|
|
|
|
switch (type) {
|
2001-05-23 14:08:40 +02:00
|
|
|
case F_MBOX:
|
|
|
|
folder = mbox_folder_new(name, path);
|
|
|
|
break;
|
2001-04-19 14:21:46 +02:00
|
|
|
case F_MH:
|
|
|
|
folder = mh_folder_new(name, path);
|
|
|
|
break;
|
|
|
|
case F_IMAP:
|
|
|
|
folder = imap_folder_new(name, path);
|
|
|
|
break;
|
|
|
|
case F_NEWS:
|
|
|
|
folder = news_folder_new(name, path);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-10-14 23:23:12 +02:00
|
|
|
/* Create root folder item */
|
|
|
|
item = folder_item_new(folder, name, NULL);
|
|
|
|
item->folder = folder;
|
|
|
|
folder->node = g_node_new(item);
|
|
|
|
folder->data = NULL;
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
static void folder_init(Folder *folder, const gchar *name)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2002-01-16 12:48:36 +01:00
|
|
|
g_return_if_fail(folder != NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
folder_set_name(folder, name);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
/* Init folder data */
|
2002-01-16 12:48:36 +01:00
|
|
|
folder->account = NULL;
|
|
|
|
folder->inbox = NULL;
|
|
|
|
folder->outbox = NULL;
|
|
|
|
folder->draft = NULL;
|
|
|
|
folder->queue = NULL;
|
|
|
|
folder->trash = NULL;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
/* Init Folder functions */
|
2002-10-14 23:23:12 +02:00
|
|
|
folder->item_new = NULL;
|
|
|
|
folder->item_destroy = NULL;
|
2002-06-30 01:33:42 +02:00
|
|
|
folder->fetch_msg = NULL;
|
|
|
|
folder->fetch_msginfo = NULL;
|
|
|
|
folder->fetch_msginfos = NULL;
|
|
|
|
folder->get_num_list = NULL;
|
2002-01-16 12:48:36 +01:00
|
|
|
folder->ui_func = NULL;
|
|
|
|
folder->ui_func_data = NULL;
|
2002-10-15 00:13:40 +02:00
|
|
|
folder->change_flags = NULL;
|
2002-06-30 01:33:42 +02:00
|
|
|
folder->check_msgnum_validity = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
void folder_local_folder_init(Folder *folder, const gchar *name,
|
|
|
|
const gchar *path)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2002-01-16 12:48:36 +01:00
|
|
|
folder_init(folder, name);
|
2001-05-23 14:08:40 +02:00
|
|
|
LOCAL_FOLDER(folder)->rootpath = g_strdup(path);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
void folder_remote_folder_init(Folder *folder, const gchar *name,
|
|
|
|
const gchar *path)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2002-01-16 12:48:36 +01:00
|
|
|
folder_init(folder, name);
|
|
|
|
REMOTE_FOLDER(folder)->session = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
void folder_destroy(Folder *folder)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2002-01-16 12:48:36 +01:00
|
|
|
g_return_if_fail(folder != NULL);
|
2002-09-02 14:32:43 +02:00
|
|
|
g_return_if_fail(folder->destroy != NULL);
|
|
|
|
|
|
|
|
folder->destroy(folder);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
folder_list = g_list_remove(folder_list, folder);
|
|
|
|
|
|
|
|
folder_tree_destroy(folder);
|
|
|
|
g_free(folder->name);
|
|
|
|
g_free(folder);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
void folder_local_folder_destroy(LocalFolder *lfolder)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2002-01-16 12:48:36 +01:00
|
|
|
g_return_if_fail(lfolder != NULL);
|
|
|
|
|
|
|
|
g_free(lfolder->rootpath);
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
void folder_remote_folder_destroy(RemoteFolder *rfolder)
|
|
|
|
{
|
|
|
|
g_return_if_fail(rfolder != NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
if (rfolder->session)
|
|
|
|
session_destroy(rfolder->session);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
#if 0
|
|
|
|
Folder *mbox_folder_new(const gchar *name, const gchar *path)
|
|
|
|
{
|
|
|
|
/* not yet implemented */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Folder *maildir_folder_new(const gchar *name, const gchar *path)
|
|
|
|
{
|
|
|
|
/* not yet implemented */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-07-25 23:09:10 +02:00
|
|
|
FolderItem *folder_item_new(Folder *folder, const gchar *name, const gchar *path)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2002-07-25 23:09:10 +02:00
|
|
|
FolderItem *item = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-10-14 23:23:12 +02:00
|
|
|
if (folder->item_new) {
|
|
|
|
item = folder->item_new(folder);
|
|
|
|
} else {
|
2002-07-25 23:09:10 +02:00
|
|
|
item = g_new0(FolderItem, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
item->stype = F_NORMAL;
|
|
|
|
item->name = g_strdup(name);
|
|
|
|
item->path = g_strdup(path);
|
|
|
|
item->mtime = 0;
|
|
|
|
item->new = 0;
|
|
|
|
item->unread = 0;
|
|
|
|
item->total = 0;
|
|
|
|
item->last_num = -1;
|
2002-06-30 01:33:42 +02:00
|
|
|
item->cache = NULL;
|
2001-06-28 10:44:31 +02:00
|
|
|
item->no_sub = FALSE;
|
|
|
|
item->no_select = FALSE;
|
2001-07-14 19:21:51 +02:00
|
|
|
item->collapsed = FALSE;
|
2001-09-25 11:12:39 +02:00
|
|
|
item->threaded = TRUE;
|
2001-09-23 03:19:22 +02:00
|
|
|
item->ret_rcpt = FALSE;
|
2002-04-03 10:58:44 +02:00
|
|
|
item->opened = FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
item->parent = NULL;
|
|
|
|
item->folder = NULL;
|
2002-10-13 16:12:29 +02:00
|
|
|
item->account = NULL;
|
|
|
|
item->apply_sub = FALSE;
|
2002-04-03 10:58:44 +02:00
|
|
|
item->mark_queue = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
item->data = NULL;
|
|
|
|
|
2001-05-06 06:27:28 +02:00
|
|
|
item->prefs = prefs_folder_item_new();
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_append(FolderItem *parent, FolderItem *item)
|
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
|
|
|
|
g_return_if_fail(parent != NULL);
|
|
|
|
g_return_if_fail(parent->folder != NULL);
|
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
|
|
|
|
node = parent->folder->node;
|
|
|
|
node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, parent);
|
|
|
|
g_return_if_fail(node != NULL);
|
|
|
|
|
|
|
|
item->parent = parent;
|
|
|
|
item->folder = parent->folder;
|
|
|
|
g_node_append_data(node, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_remove(FolderItem *item)
|
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
|
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
g_return_if_fail(item->folder != NULL);
|
|
|
|
|
|
|
|
node = item->folder->node;
|
|
|
|
node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
|
|
|
|
g_return_if_fail(node != NULL);
|
|
|
|
|
|
|
|
/* TODO: free all FolderItem's first */
|
|
|
|
if (item->folder->node == node)
|
|
|
|
item->folder->node = NULL;
|
|
|
|
g_node_destroy(node);
|
|
|
|
}
|
|
|
|
|
2001-07-01 10:37:50 +02:00
|
|
|
void folder_item_destroy(FolderItem *item)
|
|
|
|
{
|
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("Destroying folder item %s\n", item->path);
|
2002-07-25 23:09:10 +02:00
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->cache)
|
2002-06-30 18:35:20 +02:00
|
|
|
folder_item_free_cache(item);
|
2001-07-01 10:37:50 +02:00
|
|
|
g_free(item->name);
|
|
|
|
g_free(item->path);
|
2002-10-14 23:23:12 +02:00
|
|
|
|
|
|
|
if (item->folder != NULL) {
|
|
|
|
if(item->folder->item_destroy) {
|
|
|
|
item->folder->item_destroy(item->folder, item);
|
|
|
|
} else {
|
|
|
|
g_free(item);
|
|
|
|
}
|
|
|
|
}
|
2001-07-01 10:37:50 +02:00
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
void folder_set_ui_func(Folder *folder, FolderUIFunc func, gpointer data)
|
|
|
|
{
|
|
|
|
g_return_if_fail(folder != NULL);
|
|
|
|
|
|
|
|
folder->ui_func = func;
|
|
|
|
folder->ui_func_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_set_name(Folder *folder, const gchar *name)
|
|
|
|
{
|
|
|
|
g_return_if_fail(folder != NULL);
|
|
|
|
|
|
|
|
g_free(folder->name);
|
|
|
|
folder->name = name ? g_strdup(name) : NULL;
|
|
|
|
if (folder->node && folder->node->data) {
|
|
|
|
FolderItem *item = (FolderItem *)folder->node->data;
|
|
|
|
|
|
|
|
g_free(item->name);
|
|
|
|
item->name = name ? g_strdup(name) : NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-30 18:35:20 +02:00
|
|
|
gboolean folder_tree_destroy_func(GNode *node, gpointer data) {
|
|
|
|
FolderItem *item = (FolderItem *) node->data;
|
|
|
|
|
|
|
|
folder_item_destroy(item);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
void folder_tree_destroy(Folder *folder)
|
|
|
|
{
|
2002-07-26 01:00:59 +02:00
|
|
|
g_return_if_fail(folder != NULL);
|
|
|
|
g_return_if_fail(folder->node != NULL);
|
|
|
|
|
2002-07-02 21:49:11 +02:00
|
|
|
prefs_scoring_clear();
|
|
|
|
prefs_filtering_clear();
|
|
|
|
|
2002-06-30 18:35:20 +02:00
|
|
|
g_node_traverse(folder->node, G_POST_ORDER, G_TRAVERSE_ALL, -1, folder_tree_destroy_func, NULL);
|
2002-09-04 10:12:49 +02:00
|
|
|
if (folder->node)
|
|
|
|
g_node_destroy(folder->node);
|
2001-06-28 10:44:31 +02:00
|
|
|
|
|
|
|
folder->inbox = NULL;
|
|
|
|
folder->outbox = NULL;
|
|
|
|
folder->draft = NULL;
|
|
|
|
folder->queue = NULL;
|
|
|
|
folder->trash = NULL;
|
|
|
|
folder->node = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void folder_add(Folder *folder)
|
|
|
|
{
|
|
|
|
Folder *cur_folder;
|
|
|
|
GList *cur;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_if_fail(folder != NULL);
|
|
|
|
|
|
|
|
for (i = 0, cur = folder_list; cur != NULL; cur = cur->next, i++) {
|
|
|
|
cur_folder = FOLDER(cur->data);
|
|
|
|
if (folder->type == F_MH) {
|
|
|
|
if (cur_folder->type != F_MH) break;
|
2001-05-23 14:08:40 +02:00
|
|
|
} else if (folder->type == F_MBOX) {
|
|
|
|
if (cur_folder->type != F_MH &&
|
|
|
|
cur_folder->type != F_MBOX) break;
|
2001-04-19 14:21:46 +02:00
|
|
|
} else if (folder->type == F_IMAP) {
|
|
|
|
if (cur_folder->type != F_MH &&
|
2001-05-23 14:08:40 +02:00
|
|
|
cur_folder->type != F_MBOX &&
|
2001-04-19 14:21:46 +02:00
|
|
|
cur_folder->type != F_IMAP) break;
|
|
|
|
} else if (folder->type == F_NEWS) {
|
|
|
|
if (cur_folder->type != F_MH &&
|
2001-05-23 14:08:40 +02:00
|
|
|
cur_folder->type != F_MBOX &&
|
2001-04-19 14:21:46 +02:00
|
|
|
cur_folder->type != F_IMAP &&
|
|
|
|
cur_folder->type != F_NEWS) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
folder_list = g_list_insert(folder_list, folder, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *folder_get_list(void)
|
|
|
|
{
|
|
|
|
return folder_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint folder_read_list(void)
|
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
XMLNode *xmlnode;
|
2001-08-01 09:22:54 +02:00
|
|
|
gchar *path;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-08-01 09:22:54 +02:00
|
|
|
path = folder_get_list_path();
|
|
|
|
if (!is_file_exist(path)) return -1;
|
|
|
|
node = xml_parse_file(path);
|
2001-04-19 14:21:46 +02:00
|
|
|
if (!node) return -1;
|
|
|
|
|
|
|
|
xmlnode = node->data;
|
|
|
|
if (strcmp2(xmlnode->tag->tag, "folderlist") != 0) {
|
|
|
|
g_warning("wrong folder list\n");
|
|
|
|
xml_free_tree(node);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, 2,
|
|
|
|
folder_read_folder_func, NULL);
|
|
|
|
|
|
|
|
xml_free_tree(node);
|
|
|
|
if (folder_list)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_write_list(void)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
Folder *folder;
|
|
|
|
gchar *path;
|
|
|
|
PrefFile *pfile;
|
|
|
|
|
|
|
|
path = folder_get_list_path();
|
|
|
|
if ((pfile = prefs_write_open(path)) == NULL) return;
|
|
|
|
|
|
|
|
fprintf(pfile->fp, "<?xml version=\"1.0\" encoding=\"%s\"?>\n",
|
|
|
|
conv_get_current_charset_str());
|
|
|
|
fputs("\n<folderlist>\n", pfile->fp);
|
|
|
|
|
|
|
|
for (list = folder_list; list != NULL; list = list->next) {
|
|
|
|
folder = list->data;
|
|
|
|
folder_write_list_recursive(folder->node, pfile->fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("</folderlist>\n", pfile->fp);
|
|
|
|
|
|
|
|
if (prefs_write_close(pfile) < 0)
|
|
|
|
g_warning("failed to write folder list.\n");
|
|
|
|
}
|
|
|
|
|
2002-07-02 21:49:11 +02:00
|
|
|
gboolean folder_scan_tree_func(GNode *node, gpointer data)
|
|
|
|
{
|
|
|
|
GHashTable *pptable = (GHashTable *)data;
|
|
|
|
FolderItem *item = (FolderItem *)node->data;
|
|
|
|
|
|
|
|
folder_item_restore_persist_prefs(item, pptable);
|
2002-09-29 15:43:33 +02:00
|
|
|
|
|
|
|
return FALSE;
|
2002-07-02 21:49:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void folder_scan_tree(Folder *folder)
|
|
|
|
{
|
|
|
|
GHashTable *pptable;
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (!folder->scan_tree)
|
2002-07-02 21:49:11 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
pptable = folder_persist_prefs_new(folder);
|
|
|
|
folder_tree_destroy(folder);
|
|
|
|
|
|
|
|
folder->scan_tree(folder);
|
2002-07-26 01:00:59 +02:00
|
|
|
|
2002-07-02 21:49:11 +02:00
|
|
|
g_node_traverse(folder->node, G_POST_ORDER, G_TRAVERSE_ALL, -1, folder_scan_tree_func, pptable);
|
|
|
|
folder_persist_prefs_free(pptable);
|
|
|
|
|
|
|
|
prefs_matcher_read_config();
|
2002-11-09 17:35:13 +01:00
|
|
|
|
|
|
|
folder_write_list();
|
2002-07-02 21:49:11 +02:00
|
|
|
}
|
|
|
|
|
2002-10-07 23:47:32 +02:00
|
|
|
FolderItem *folder_create_folder(FolderItem *parent, const gchar *name)
|
|
|
|
{
|
|
|
|
FolderItem *new_item;
|
|
|
|
|
|
|
|
new_item = parent->folder->create_folder(parent->folder, parent, name);
|
2002-11-07 00:56:26 +01:00
|
|
|
if (new_item)
|
|
|
|
new_item->cache = msgcache_new();
|
2002-10-07 23:47:32 +02:00
|
|
|
|
|
|
|
return new_item;
|
|
|
|
}
|
|
|
|
|
2001-12-03 17:04:12 +01:00
|
|
|
struct TotalMsgCount
|
2001-11-26 08:53:20 +01:00
|
|
|
{
|
2001-12-03 17:04:12 +01:00
|
|
|
guint new;
|
|
|
|
guint unread;
|
|
|
|
guint total;
|
|
|
|
};
|
2001-11-26 08:53:20 +01:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
struct FuncToAllFoldersData
|
|
|
|
{
|
|
|
|
FolderItemFunc function;
|
|
|
|
gpointer data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean folder_func_to_all_folders_func(GNode *node, gpointer data)
|
2001-12-03 17:04:12 +01:00
|
|
|
{
|
|
|
|
FolderItem *item;
|
2002-06-30 01:33:42 +02:00
|
|
|
struct FuncToAllFoldersData *function_data = (struct FuncToAllFoldersData *) data;
|
2001-12-03 17:04:12 +01:00
|
|
|
|
|
|
|
g_return_val_if_fail(node->data != NULL, FALSE);
|
2001-11-26 08:53:20 +01:00
|
|
|
|
2001-12-03 17:04:12 +01:00
|
|
|
item = FOLDER_ITEM(node->data);
|
2002-06-30 01:33:42 +02:00
|
|
|
g_return_val_if_fail(item != NULL, FALSE);
|
|
|
|
|
|
|
|
function_data->function(item, function_data->data);
|
2001-12-04 10:10:36 +01:00
|
|
|
|
2001-12-03 17:04:12 +01:00
|
|
|
return FALSE;
|
2001-11-26 08:53:20 +01:00
|
|
|
}
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
void folder_func_to_all_folders(FolderItemFunc function, gpointer data)
|
2001-11-26 08:53:20 +01:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
Folder *folder;
|
2002-06-30 01:33:42 +02:00
|
|
|
struct FuncToAllFoldersData function_data;
|
|
|
|
|
|
|
|
function_data.function = function;
|
|
|
|
function_data.data = data;
|
2001-12-03 17:04:12 +01:00
|
|
|
|
2001-11-26 08:53:20 +01:00
|
|
|
for (list = folder_list; list != NULL; list = list->next) {
|
|
|
|
folder = FOLDER(list->data);
|
2001-12-04 10:10:36 +01:00
|
|
|
if (folder->node)
|
2001-12-03 17:04:12 +01:00
|
|
|
g_node_traverse(folder->node, G_PRE_ORDER,
|
2001-12-04 10:10:36 +01:00
|
|
|
G_TRAVERSE_ALL, -1,
|
2002-06-30 01:33:42 +02:00
|
|
|
folder_func_to_all_folders_func,
|
|
|
|
&function_data);
|
2001-11-26 08:53:20 +01:00
|
|
|
}
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void folder_count_total_msgs_func(FolderItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
struct TotalMsgCount *count = (struct TotalMsgCount *)data;
|
|
|
|
|
|
|
|
count->new += item->new;
|
|
|
|
count->unread += item->unread;
|
|
|
|
count->total += item->total;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_count_total_msgs(guint *new, guint *unread, guint *total)
|
|
|
|
{
|
|
|
|
struct TotalMsgCount count;
|
|
|
|
|
|
|
|
count.new = count.unread = count.total = 0;
|
|
|
|
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("Counting total number of messages...\n");
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
folder_func_to_all_folders(folder_count_total_msgs_func, &count);
|
2001-11-26 08:53:20 +01:00
|
|
|
|
2001-12-04 10:10:36 +01:00
|
|
|
*new = count.new;
|
|
|
|
*unread = count.unread;
|
|
|
|
*total = count.total;
|
2001-11-26 08:53:20 +01:00
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
Folder *folder_find_from_path(const gchar *path)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
Folder *folder;
|
|
|
|
|
|
|
|
for (list = folder_list; list != NULL; list = list->next) {
|
|
|
|
folder = list->data;
|
2001-05-29 02:29:13 +02:00
|
|
|
if ((folder->type == F_MH || folder->type == F_MBOX) &&
|
2001-04-19 14:21:46 +02:00
|
|
|
!path_cmp(LOCAL_FOLDER(folder)->rootpath, path))
|
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-04-05 10:20:10 +02:00
|
|
|
Folder *folder_find_from_name(const gchar *name, FolderType type)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
Folder *folder;
|
|
|
|
|
|
|
|
for (list = folder_list; list != NULL; list = list->next) {
|
|
|
|
folder = list->data;
|
|
|
|
if (folder->type == type && strcmp2(name, folder->name) == 0)
|
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static gboolean folder_item_find_func(GNode *node, gpointer data)
|
|
|
|
{
|
|
|
|
FolderItem *item = node->data;
|
|
|
|
gpointer *d = data;
|
|
|
|
const gchar *path = d[0];
|
|
|
|
|
|
|
|
if (path_cmp(path, item->path) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
d[1] = item;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderItem *folder_find_item_from_path(const gchar *path)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gpointer d[2];
|
|
|
|
|
|
|
|
folder = folder_get_default_folder();
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2002-04-05 10:20:10 +02:00
|
|
|
static const struct {
|
|
|
|
gchar *str;
|
|
|
|
FolderType type;
|
|
|
|
} type_str_table[] = {
|
|
|
|
{"#mh" , F_MH},
|
|
|
|
{"#mbox" , F_MBOX},
|
|
|
|
{"#maildir", F_MAILDIR},
|
|
|
|
{"#imap" , F_IMAP},
|
|
|
|
{"#news" , F_NEWS}
|
|
|
|
};
|
|
|
|
|
|
|
|
static gchar *folder_get_type_string(FolderType type)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(type_str_table) / sizeof(type_str_table[0]);
|
|
|
|
i++) {
|
|
|
|
if (type_str_table[i].type == type)
|
|
|
|
return type_str_table[i].str;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FolderType folder_get_type_from_string(const gchar *str)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(type_str_table) / sizeof(type_str_table[0]);
|
|
|
|
i++) {
|
|
|
|
if (g_strcasecmp(type_str_table[i].str, str) == 0)
|
|
|
|
return type_str_table[i].type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return F_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *folder_get_identifier(Folder *folder)
|
|
|
|
{
|
|
|
|
gchar *type_str;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
|
|
|
|
|
|
|
type_str = folder_get_type_string(folder->type);
|
|
|
|
return g_strconcat(type_str, "/", folder->name, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *folder_item_get_identifier(FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *id;
|
|
|
|
gchar *folder_id;
|
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
g_return_val_if_fail(item->path != NULL, NULL);
|
|
|
|
|
|
|
|
folder_id = folder_get_identifier(item->folder);
|
|
|
|
id = g_strconcat(folder_id, "/", item->path, NULL);
|
|
|
|
g_free(folder_id);
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderItem *folder_find_item_from_identifier(const gchar *identifier)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gpointer d[2];
|
|
|
|
gchar *str;
|
|
|
|
gchar *p;
|
|
|
|
gchar *name;
|
|
|
|
gchar *path;
|
|
|
|
FolderType type;
|
|
|
|
|
|
|
|
g_return_val_if_fail(identifier != NULL, NULL);
|
|
|
|
|
|
|
|
if (*identifier != '#')
|
|
|
|
return folder_find_item_from_path(identifier);
|
|
|
|
|
|
|
|
Xstrdup_a(str, identifier, return NULL);
|
|
|
|
|
|
|
|
p = strchr(str, '/');
|
|
|
|
if (!p)
|
|
|
|
return folder_find_item_from_path(identifier);
|
|
|
|
*p = '\0';
|
|
|
|
p++;
|
|
|
|
type = folder_get_type_from_string(str);
|
|
|
|
if (type == F_UNKNOWN)
|
|
|
|
return folder_find_item_from_path(identifier);
|
|
|
|
|
|
|
|
name = p;
|
|
|
|
p = strchr(p, '/');
|
|
|
|
if (!p)
|
|
|
|
return folder_find_item_from_path(identifier);
|
|
|
|
*p = '\0';
|
|
|
|
p++;
|
|
|
|
|
|
|
|
folder = folder_find_from_name(name, type);
|
|
|
|
if (!folder)
|
|
|
|
return folder_find_item_from_path(identifier);
|
|
|
|
|
|
|
|
path = p;
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
Folder *folder_get_default_folder(void)
|
|
|
|
{
|
2001-07-16 20:18:53 +02:00
|
|
|
return folder_list ? FOLDER(folder_list->data) : NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FolderItem *folder_get_default_inbox(void)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
|
2001-07-16 20:18:53 +02:00
|
|
|
if (!folder_list) return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
folder = FOLDER(folder_list->data);
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
|
|
|
return folder->inbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderItem *folder_get_default_outbox(void)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
|
2001-07-16 20:18:53 +02:00
|
|
|
if (!folder_list) return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
folder = FOLDER(folder_list->data);
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
|
|
|
return folder->outbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderItem *folder_get_default_draft(void)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
|
2001-07-16 20:18:53 +02:00
|
|
|
if (!folder_list) return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
folder = FOLDER(folder_list->data);
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
|
|
|
return folder->draft;
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderItem *folder_get_default_queue(void)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
|
2001-07-16 20:18:53 +02:00
|
|
|
if (!folder_list) return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
folder = FOLDER(folder_list->data);
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
|
|
|
return folder->queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderItem *folder_get_default_trash(void)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
|
2001-07-16 20:18:53 +02:00
|
|
|
if (!folder_list) return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
folder = FOLDER(folder_list->data);
|
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
|
|
|
return folder->trash;
|
|
|
|
}
|
|
|
|
|
2002-07-25 23:09:10 +02:00
|
|
|
#define CREATE_FOLDER_IF_NOT_EXIST(member, dir, type) \
|
|
|
|
{ \
|
|
|
|
if (!folder->member) { \
|
|
|
|
item = folder_item_new(folder, dir, dir); \
|
|
|
|
item->stype = type; \
|
|
|
|
folder_item_append(rootitem, item); \
|
|
|
|
folder->member = item; \
|
|
|
|
} \
|
2002-03-19 09:37:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void folder_set_missing_folders(void)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
FolderItem *rootitem;
|
|
|
|
FolderItem *item;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = folder_list; list != NULL; list = list->next) {
|
|
|
|
folder = list->data;
|
|
|
|
if (folder->type != F_MH) continue;
|
|
|
|
rootitem = FOLDER_ITEM(folder->node->data);
|
|
|
|
g_return_if_fail(rootitem != NULL);
|
|
|
|
|
|
|
|
if (folder->inbox && folder->outbox && folder->draft &&
|
|
|
|
folder->queue && folder->trash)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (folder->create_tree(folder) < 0) {
|
|
|
|
g_warning("%s: can't create the folder tree.\n",
|
|
|
|
LOCAL_FOLDER(folder)->rootpath);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
CREATE_FOLDER_IF_NOT_EXIST(inbox, INBOX_DIR, F_INBOX);
|
2002-06-08 17:52:42 +02:00
|
|
|
CREATE_FOLDER_IF_NOT_EXIST(outbox, OUTBOX_DIR, F_OUTBOX);
|
|
|
|
CREATE_FOLDER_IF_NOT_EXIST(draft, DRAFT_DIR, F_DRAFT);
|
|
|
|
CREATE_FOLDER_IF_NOT_EXIST(queue, QUEUE_DIR, F_QUEUE);
|
|
|
|
CREATE_FOLDER_IF_NOT_EXIST(trash, TRASH_DIR, F_TRASH);
|
2002-03-19 09:37:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-13 17:43:22 +02:00
|
|
|
static gboolean folder_unref_account_func(GNode *node, gpointer data)
|
|
|
|
{
|
|
|
|
FolderItem *item = node->data;
|
|
|
|
PrefsAccount *account = data;
|
|
|
|
|
|
|
|
if (item->account == account)
|
|
|
|
item->account = NULL;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_unref_account_all(PrefsAccount *account)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
if (!account) return;
|
|
|
|
|
|
|
|
for (list = folder_list; list != NULL; list = list->next) {
|
|
|
|
folder = list->data;
|
|
|
|
if (folder->account == account)
|
|
|
|
folder->account = NULL;
|
|
|
|
g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
|
|
|
|
folder_unref_account_func, account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-19 09:37:53 +01:00
|
|
|
#undef CREATE_FOLDER_IF_NOT_EXIST
|
|
|
|
|
2002-08-28 13:54:45 +02:00
|
|
|
gchar *folder_get_path(Folder *folder)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
|
2002-08-28 13:54:45 +02:00
|
|
|
g_return_val_if_fail(folder != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-09-29 15:43:33 +02:00
|
|
|
switch(FOLDER_TYPE(folder)) {
|
2002-08-28 13:54:45 +02:00
|
|
|
|
2002-09-29 15:43:33 +02:00
|
|
|
case F_MH:
|
|
|
|
path = g_strdup(LOCAL_FOLDER(folder)->rootpath);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F_IMAP:
|
|
|
|
g_return_val_if_fail(folder->account != NULL, NULL);
|
|
|
|
path = g_strconcat(get_imap_cache_dir(),
|
|
|
|
G_DIR_SEPARATOR_S,
|
|
|
|
folder->account->recv_server,
|
|
|
|
G_DIR_SEPARATOR_S,
|
|
|
|
folder->account->userid,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F_NEWS:
|
|
|
|
g_return_val_if_fail(folder->account != NULL, NULL);
|
|
|
|
path = g_strconcat(get_news_cache_dir(),
|
|
|
|
G_DIR_SEPARATOR_S,
|
|
|
|
folder->account->nntp_server,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
path = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-08-28 13:54:45 +02:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *folder_item_get_path(FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *folder_path;
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-09-29 15:43:33 +02:00
|
|
|
if(FOLDER_TYPE(item->folder) != F_MBOX) {
|
|
|
|
folder_path = folder_get_path(item->folder);
|
|
|
|
g_return_val_if_fail(folder_path != NULL, NULL);
|
|
|
|
|
|
|
|
if (folder_path[0] == G_DIR_SEPARATOR) {
|
|
|
|
if (item->path)
|
|
|
|
path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
|
|
|
|
item->path, NULL);
|
|
|
|
else
|
|
|
|
path = g_strdup(folder_path);
|
|
|
|
} else {
|
|
|
|
if (item->path)
|
|
|
|
path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
|
|
|
|
folder_path, G_DIR_SEPARATOR_S,
|
|
|
|
item->path, NULL);
|
|
|
|
else
|
|
|
|
path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
|
|
|
|
folder_path, NULL);
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-09-29 15:43:33 +02:00
|
|
|
g_free(folder_path);
|
2001-04-19 14:21:46 +02:00
|
|
|
} else {
|
2002-09-29 15:43:33 +02:00
|
|
|
gchar *itempath;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-09-29 15:43:33 +02:00
|
|
|
itempath = mbox_get_virtual_path(item);
|
|
|
|
if (itempath == NULL)
|
|
|
|
return NULL;
|
|
|
|
path = g_strconcat(get_mbox_cache_dir(),
|
|
|
|
G_DIR_SEPARATOR_S, itempath, NULL);
|
|
|
|
g_free(itempath);
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
void folder_item_set_default_flags(FolderItem *dest, MsgFlags *flags)
|
|
|
|
{
|
|
|
|
if (!(dest->stype == F_OUTBOX ||
|
|
|
|
dest->stype == F_QUEUE ||
|
|
|
|
dest->stype == F_DRAFT ||
|
|
|
|
dest->stype == F_TRASH)) {
|
|
|
|
flags->perm_flags = MSG_NEW|MSG_UNREAD;
|
|
|
|
} else {
|
|
|
|
flags->perm_flags = 0;
|
|
|
|
}
|
|
|
|
flags->tmp_flags = MSG_CACHED;
|
|
|
|
if (dest->folder->type == F_MH) {
|
|
|
|
if (dest->stype == F_QUEUE) {
|
|
|
|
MSG_SET_TMP_FLAGS(*flags, MSG_QUEUED);
|
|
|
|
} else if (dest->stype == F_DRAFT) {
|
|
|
|
MSG_SET_TMP_FLAGS(*flags, MSG_DRAFT);
|
|
|
|
}
|
|
|
|
} else if (dest->folder->type == F_IMAP) {
|
|
|
|
MSG_SET_TMP_FLAGS(*flags, MSG_IMAP);
|
|
|
|
} else if (dest->folder->type == F_NEWS) {
|
|
|
|
MSG_SET_TMP_FLAGS(*flags, MSG_NEWS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
static gint folder_sort_cache_list_by_msgnum(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
MsgInfo *msginfo_a = (MsgInfo *) a;
|
|
|
|
MsgInfo *msginfo_b = (MsgInfo *) b;
|
|
|
|
|
|
|
|
return (msginfo_a->msgnum - msginfo_b->msgnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint folder_sort_folder_list(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
guint gint_a = GPOINTER_TO_INT(a);
|
2002-09-11 00:23:56 +02:00
|
|
|
guint gint_b = GPOINTER_TO_INT(b);
|
2002-09-10 15:06:50 +02:00
|
|
|
|
|
|
|
return (gint_a - gint_b);
|
|
|
|
}
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2002-04-21 00:57:52 +02:00
|
|
|
gint folder_item_scan(FolderItem *item)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
Folder *folder;
|
2002-10-18 12:02:51 +02:00
|
|
|
GSList *folder_list = NULL, *cache_list = NULL, *folder_list_cur, *cache_list_cur, *new_list = NULL;
|
2002-06-30 15:45:59 +02:00
|
|
|
guint newcnt = 0, unreadcnt = 0, totalcnt = 0;
|
2002-09-10 15:25:04 +02:00
|
|
|
guint cache_max_num, folder_max_num, cache_cur_num, folder_cur_num;
|
2002-11-09 17:35:13 +01:00
|
|
|
gboolean contentchange = FALSE;
|
|
|
|
|
2002-04-21 11:24:27 +02:00
|
|
|
g_return_val_if_fail(item != NULL, -1);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->path == NULL) return -1;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
folder = item->folder;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(folder != NULL, -1);
|
|
|
|
g_return_val_if_fail(folder->get_num_list != NULL, -1);
|
|
|
|
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("Scanning folder %s for cache changes.\n", item->path);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
/* Get list of messages for folder and cache */
|
2002-10-18 12:02:51 +02:00
|
|
|
if (folder->get_num_list(item->folder, item, &folder_list) < 0) {
|
|
|
|
debug_print("Error fetching list of message numbers\n");
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (!folder->check_msgnum_validity ||
|
2002-10-18 12:02:51 +02:00
|
|
|
folder->check_msgnum_validity(folder, item)) {
|
2002-08-31 10:26:28 +02:00
|
|
|
if (!item->cache)
|
2002-06-30 01:33:42 +02:00
|
|
|
folder_item_read_cache(item);
|
|
|
|
cache_list = msgcache_get_msg_list(item->cache);
|
|
|
|
} else {
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->cache)
|
2002-06-30 01:33:42 +02:00
|
|
|
msgcache_destroy(item->cache);
|
|
|
|
item->cache = msgcache_new();
|
|
|
|
cache_list = NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
/* Sort both lists */
|
|
|
|
cache_list = g_slist_sort(cache_list, folder_sort_cache_list_by_msgnum);
|
|
|
|
folder_list = g_slist_sort(folder_list, folder_sort_folder_list);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
cache_list_cur = cache_list;
|
|
|
|
folder_list_cur = folder_list;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
if (cache_list_cur != NULL) {
|
|
|
|
GSList *cache_list_last;
|
|
|
|
|
|
|
|
cache_cur_num = ((MsgInfo *)cache_list_cur->data)->msgnum;
|
|
|
|
cache_list_last = g_slist_last(cache_list);
|
|
|
|
cache_max_num = ((MsgInfo *)cache_list_last->data)->msgnum;
|
2002-09-17 14:19:16 +02:00
|
|
|
} else {
|
2002-09-10 15:06:50 +02:00
|
|
|
cache_cur_num = G_MAXINT;
|
2002-09-17 14:19:16 +02:00
|
|
|
cache_max_num = 0;
|
|
|
|
}
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2002-09-10 15:25:04 +02:00
|
|
|
if (folder_list_cur != NULL) {
|
|
|
|
GSList *folder_list_last;
|
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
folder_cur_num = GPOINTER_TO_INT(folder_list_cur->data);
|
2002-09-10 15:25:04 +02:00
|
|
|
folder_list_last = g_slist_last(folder_list);
|
|
|
|
folder_max_num = GPOINTER_TO_INT(folder_list_last->data);
|
2002-09-17 14:19:16 +02:00
|
|
|
} else {
|
2002-09-10 15:06:50 +02:00
|
|
|
folder_cur_num = G_MAXINT;
|
2002-09-17 14:19:16 +02:00
|
|
|
folder_max_num = 0;
|
|
|
|
}
|
2002-09-10 15:06:50 +02:00
|
|
|
|
|
|
|
while ((cache_cur_num != G_MAXINT) || (folder_cur_num != G_MAXINT)) {
|
|
|
|
/*
|
|
|
|
* Message only exists in the folder
|
|
|
|
* Remember message for fetching
|
|
|
|
*/
|
|
|
|
if (folder_cur_num < cache_cur_num) {
|
2002-08-22 15:32:16 +02:00
|
|
|
gboolean add = FALSE;
|
|
|
|
|
|
|
|
switch(folder->type) {
|
|
|
|
case F_NEWS:
|
2002-09-10 15:25:04 +02:00
|
|
|
if (folder_cur_num < cache_max_num)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (prefs_common.max_articles == 0) {
|
|
|
|
add = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (folder_max_num <= prefs_common.max_articles) {
|
|
|
|
add = TRUE;
|
|
|
|
} else if (folder_cur_num > (folder_max_num - prefs_common.max_articles)) {
|
2002-08-22 15:32:16 +02:00
|
|
|
add = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
add = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (add) {
|
2002-09-10 15:06:50 +02:00
|
|
|
new_list = g_slist_prepend(new_list, GINT_TO_POINTER(folder_cur_num));
|
|
|
|
debug_print("Remembered message %d for fetching\n", folder_cur_num);
|
2002-08-22 15:32:16 +02:00
|
|
|
}
|
2002-09-10 15:06:50 +02:00
|
|
|
|
|
|
|
/* Move to next folder number */
|
|
|
|
folder_list_cur = folder_list_cur->next;
|
|
|
|
|
|
|
|
if (folder_list_cur != NULL)
|
|
|
|
folder_cur_num = GPOINTER_TO_INT(folder_list_cur->data);
|
|
|
|
else
|
|
|
|
folder_cur_num = G_MAXINT;
|
|
|
|
|
2002-11-09 17:35:13 +01:00
|
|
|
contentchange = TRUE;
|
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
continue;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2002-09-10 15:06:50 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Message only exists in the cache
|
|
|
|
* Remove the message from the cache
|
|
|
|
*/
|
|
|
|
if (cache_cur_num < folder_cur_num) {
|
|
|
|
msgcache_remove_msg(item->cache, cache_cur_num);
|
|
|
|
debug_print("Removed message %d from cache.\n", cache_cur_num);
|
|
|
|
|
|
|
|
/* Move to next cache number */
|
|
|
|
cache_list_cur = cache_list_cur->next;
|
|
|
|
|
|
|
|
if (cache_list_cur != NULL)
|
|
|
|
cache_cur_num = ((MsgInfo *)cache_list_cur->data)->msgnum;
|
|
|
|
else
|
|
|
|
cache_cur_num = G_MAXINT;
|
|
|
|
|
2002-11-09 17:35:13 +01:00
|
|
|
contentchange = TRUE;
|
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
continue;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2002-09-10 15:06:50 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Message number exists in folder and cache!
|
|
|
|
* Check if the message has been modified
|
|
|
|
*/
|
|
|
|
if (cache_cur_num == folder_cur_num) {
|
2002-06-30 01:33:42 +02:00
|
|
|
MsgInfo *msginfo;
|
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
msginfo = msgcache_get_msg(item->cache, folder_cur_num);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (folder->is_msg_changed && folder->is_msg_changed(folder, item, msginfo)) {
|
2002-06-30 01:33:42 +02:00
|
|
|
MsgInfo *newmsginfo;
|
|
|
|
|
|
|
|
msgcache_remove_msg(item->cache, msginfo->msgnum);
|
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
if (NULL != (newmsginfo = folder->fetch_msginfo(folder, item, folder_cur_num))) {
|
2002-08-31 10:06:06 +02:00
|
|
|
msgcache_add_msg(item->cache, newmsginfo);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (MSG_IS_NEW(newmsginfo->flags) && !MSG_IS_IGNORE_THREAD(newmsginfo->flags))
|
2002-08-31 10:06:06 +02:00
|
|
|
newcnt++;
|
2002-08-31 10:26:28 +02:00
|
|
|
if (MSG_IS_UNREAD(newmsginfo->flags) && !MSG_IS_IGNORE_THREAD(newmsginfo->flags))
|
2002-08-31 10:06:06 +02:00
|
|
|
unreadcnt++;
|
|
|
|
procmsg_msginfo_free(newmsginfo);
|
|
|
|
}
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
debug_print("Updated msginfo for message %d.\n", folder_cur_num);
|
2002-06-30 15:45:59 +02:00
|
|
|
} else {
|
2002-08-31 10:26:28 +02:00
|
|
|
if (MSG_IS_NEW(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
|
2002-06-30 15:45:59 +02:00
|
|
|
newcnt++;
|
2002-08-31 10:26:28 +02:00
|
|
|
if (MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
|
2002-06-30 15:45:59 +02:00
|
|
|
unreadcnt++;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2002-06-30 15:45:59 +02:00
|
|
|
totalcnt++;
|
2002-06-30 01:33:42 +02:00
|
|
|
procmsg_msginfo_free(msginfo);
|
2002-09-10 15:06:50 +02:00
|
|
|
|
|
|
|
/* Move to next folder and cache number */
|
|
|
|
cache_list_cur = cache_list_cur->next;
|
|
|
|
folder_list_cur = folder_list_cur->next;
|
|
|
|
|
|
|
|
if (cache_list_cur != NULL)
|
|
|
|
cache_cur_num = ((MsgInfo *)cache_list_cur->data)->msgnum;
|
|
|
|
else
|
|
|
|
cache_cur_num = G_MAXINT;
|
|
|
|
|
|
|
|
if (folder_list_cur != NULL)
|
|
|
|
folder_cur_num = GPOINTER_TO_INT(folder_list_cur->data);
|
|
|
|
else
|
|
|
|
folder_cur_num = G_MAXINT;
|
|
|
|
|
2002-11-09 17:35:13 +01:00
|
|
|
contentchange = TRUE;
|
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
continue;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
for(cache_list_cur = cache_list; cache_list_cur != NULL; cache_list_cur = g_slist_next(cache_list_cur)) {
|
|
|
|
procmsg_msginfo_free((MsgInfo *) cache_list_cur->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(cache_list);
|
|
|
|
g_slist_free(folder_list);
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (folder->fetch_msginfos) {
|
2002-09-10 15:06:50 +02:00
|
|
|
GSList *elem;
|
2002-06-30 01:33:42 +02:00
|
|
|
GSList *newmsg_list;
|
|
|
|
MsgInfo *msginfo;
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (new_list) {
|
2002-06-30 01:33:42 +02:00
|
|
|
newmsg_list = folder->fetch_msginfos(folder, item, new_list);
|
2002-08-31 10:26:28 +02:00
|
|
|
for (elem = newmsg_list; elem != NULL; elem = g_slist_next(elem)) {
|
2002-06-30 01:33:42 +02:00
|
|
|
msginfo = (MsgInfo *) elem->data;
|
|
|
|
msgcache_add_msg(item->cache, msginfo);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (MSG_IS_NEW(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
|
2002-06-30 15:45:59 +02:00
|
|
|
newcnt++;
|
2002-08-31 10:26:28 +02:00
|
|
|
if (MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
|
2002-06-30 15:45:59 +02:00
|
|
|
unreadcnt++;
|
|
|
|
totalcnt++;
|
2002-06-30 01:33:42 +02:00
|
|
|
procmsg_msginfo_free(msginfo);
|
|
|
|
}
|
|
|
|
g_slist_free(newmsg_list);
|
|
|
|
}
|
|
|
|
} else if (folder->fetch_msginfo) {
|
2002-09-10 15:06:50 +02:00
|
|
|
GSList *elem;
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
for (elem = new_list; elem != NULL; elem = g_slist_next(elem)) {
|
2002-06-30 01:33:42 +02:00
|
|
|
MsgInfo *msginfo;
|
|
|
|
guint num;
|
|
|
|
|
|
|
|
num = GPOINTER_TO_INT(elem->data);
|
|
|
|
msginfo = folder->fetch_msginfo(folder, item, num);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (msginfo != NULL) {
|
2002-06-30 01:33:42 +02:00
|
|
|
msgcache_add_msg(item->cache, msginfo);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (MSG_IS_NEW(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
|
2002-06-30 15:45:59 +02:00
|
|
|
newcnt++;
|
2002-08-31 10:26:28 +02:00
|
|
|
if (MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
|
2002-06-30 15:45:59 +02:00
|
|
|
unreadcnt++;
|
|
|
|
totalcnt++;
|
2002-06-30 01:33:42 +02:00
|
|
|
procmsg_msginfo_free(msginfo);
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("Added newly found message %d to cache.\n", num);
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-30 15:45:59 +02:00
|
|
|
item->new = newcnt;
|
|
|
|
item->unread = unreadcnt;
|
|
|
|
item->total = totalcnt;
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
g_slist_free(new_list);
|
|
|
|
|
2002-11-09 17:35:13 +01:00
|
|
|
folder_update_item(item, contentchange);
|
2002-08-22 15:32:16 +02:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
return 0;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void folder_item_scan_foreach_func(gpointer key, gpointer val,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
folder_item_scan(FOLDER_ITEM(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_scan_foreach(GHashTable *table)
|
|
|
|
{
|
|
|
|
g_hash_table_foreach(table, folder_item_scan_foreach_func, NULL);
|
|
|
|
}
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
void folder_count_total_cache_memusage(FolderItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
gint *memusage = (gint *)data;
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->cache == NULL)
|
2002-06-30 01:33:42 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
*memusage += msgcache_get_memory_usage(item->cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
gint folder_cache_time_compare_func(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
FolderItem *fa = (FolderItem *)a;
|
|
|
|
FolderItem *fb = (FolderItem *)b;
|
|
|
|
|
|
|
|
return (gint) (msgcache_get_last_access_time(fa->cache) - msgcache_get_last_access_time(fb->cache));
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_find_expired_caches(FolderItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
GSList **folder_item_list = (GSList **)data;
|
|
|
|
gint difftime, expiretime;
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->cache == NULL)
|
2002-06-30 01:33:42 +02:00
|
|
|
return;
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->opened > 0)
|
2002-08-01 22:50:31 +02:00
|
|
|
return;
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
difftime = (gint) (time(NULL) - msgcache_get_last_access_time(item->cache));
|
|
|
|
expiretime = prefs_common.cache_min_keep_time * 60;
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("Cache unused time: %d (Expire time: %d)\n", difftime, expiretime);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (difftime > expiretime) {
|
2002-06-30 01:33:42 +02:00
|
|
|
*folder_item_list = g_slist_insert_sorted(*folder_item_list, item, folder_cache_time_compare_func);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_free_cache(FolderItem *item)
|
|
|
|
{
|
|
|
|
g_return_if_fail(item != NULL);
|
2002-07-02 21:49:11 +02:00
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->cache == NULL)
|
2002-07-02 21:49:11 +02:00
|
|
|
return;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->opened > 0)
|
2002-08-01 22:50:31 +02:00
|
|
|
return;
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
folder_item_write_cache(item);
|
|
|
|
msgcache_destroy(item->cache);
|
|
|
|
item->cache = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_clean_cache_memory()
|
|
|
|
{
|
|
|
|
gint memusage = 0;
|
|
|
|
|
|
|
|
folder_func_to_all_folders(folder_count_total_cache_memusage, &memusage);
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("Total cache memory usage: %d\n", memusage);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (memusage > (prefs_common.cache_max_mem_usage * 1024)) {
|
2002-06-30 01:33:42 +02:00
|
|
|
GSList *folder_item_list = NULL, *listitem;
|
|
|
|
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("Trying to free cache memory\n");
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
folder_func_to_all_folders(folder_find_expired_caches, &folder_item_list);
|
|
|
|
listitem = folder_item_list;
|
|
|
|
while((listitem != NULL) && (memusage > (prefs_common.cache_max_mem_usage * 1024))) {
|
|
|
|
FolderItem *item = (FolderItem *)(listitem->data);
|
|
|
|
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("Freeing cache memory for %s\n", item->path);
|
2002-06-30 01:33:42 +02:00
|
|
|
memusage -= msgcache_get_memory_usage(item->cache);
|
2002-08-01 22:50:31 +02:00
|
|
|
folder_item_free_cache(item);
|
2002-06-30 01:33:42 +02:00
|
|
|
listitem = listitem->next;
|
|
|
|
}
|
|
|
|
g_slist_free(folder_item_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_read_cache(FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *cache_file, *mark_file;
|
|
|
|
|
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
|
|
|
|
cache_file = folder_item_get_cache_file(item);
|
|
|
|
mark_file = folder_item_get_mark_file(item);
|
|
|
|
item->cache = msgcache_read_cache(item, cache_file);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (!item->cache) {
|
2002-06-30 01:33:42 +02:00
|
|
|
item->cache = msgcache_new();
|
|
|
|
folder_item_scan(item);
|
|
|
|
}
|
|
|
|
msgcache_read_mark(item->cache, mark_file);
|
|
|
|
g_free(cache_file);
|
|
|
|
g_free(mark_file);
|
|
|
|
|
|
|
|
folder_clean_cache_memory();
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_write_cache(FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *cache_file, *mark_file;
|
|
|
|
PrefsFolderItem *prefs;
|
|
|
|
gint filemode = 0;
|
|
|
|
gchar *id;
|
|
|
|
|
|
|
|
if (!item || !item->path || !item->cache)
|
|
|
|
return;
|
|
|
|
|
|
|
|
id = folder_item_get_identifier(item);
|
2002-08-15 09:38:17 +02:00
|
|
|
debug_print("Save cache for folder %s\n", id);
|
2002-06-30 01:33:42 +02:00
|
|
|
g_free(id);
|
|
|
|
|
|
|
|
cache_file = folder_item_get_cache_file(item);
|
|
|
|
mark_file = folder_item_get_mark_file(item);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (msgcache_write(cache_file, mark_file, item->cache) < 0) {
|
2002-06-30 01:33:42 +02:00
|
|
|
prefs = item->prefs;
|
|
|
|
if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
|
|
|
|
/* for cache file */
|
|
|
|
filemode = prefs->folder_chmod;
|
|
|
|
if (filemode & S_IRGRP) filemode |= S_IWGRP;
|
|
|
|
if (filemode & S_IROTH) filemode |= S_IWOTH;
|
|
|
|
chmod(cache_file, filemode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(cache_file);
|
|
|
|
g_free(mark_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgInfo *folder_item_fetch_msginfo(FolderItem *item, gint num)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
MsgInfo *msginfo;
|
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
|
|
|
|
folder = item->folder;
|
2002-08-31 10:26:28 +02:00
|
|
|
if (!item->cache)
|
2002-06-30 01:33:42 +02:00
|
|
|
folder_item_read_cache(item);
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if ((msginfo = msgcache_get_msg(item->cache, num)) != NULL)
|
2002-06-30 01:33:42 +02:00
|
|
|
return msginfo;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder->fetch_msginfo, NULL);
|
2002-08-31 10:26:28 +02:00
|
|
|
if ((msginfo = folder->fetch_msginfo(folder, item, num)) != NULL) {
|
2002-07-10 15:11:25 +02:00
|
|
|
msgcache_add_msg(item->cache, msginfo);
|
|
|
|
return msginfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgInfo *folder_item_fetch_msginfo_by_id(FolderItem *item, const gchar *msgid)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
MsgInfo *msginfo;
|
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
|
|
|
|
folder = item->folder;
|
2002-08-31 10:26:28 +02:00
|
|
|
if (!item->cache)
|
2002-07-10 15:11:25 +02:00
|
|
|
folder_item_read_cache(item);
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if ((msginfo = msgcache_get_msg_by_id(item->cache, msgid)) != NULL)
|
2002-07-10 15:11:25 +02:00
|
|
|
return msginfo;
|
|
|
|
|
|
|
|
return NULL;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GSList *folder_item_get_msg_list(FolderItem *item)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->cache == 0)
|
2002-06-30 01:33:42 +02:00
|
|
|
folder_item_read_cache(item);
|
|
|
|
|
|
|
|
g_return_val_if_fail(item->cache != NULL, NULL);
|
|
|
|
|
|
|
|
return msgcache_get_msg_list(item->cache);
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
gchar *folder_item_fetch_msg(FolderItem *item, gint num)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
|
|
|
|
folder = item->folder;
|
2001-05-23 14:08:40 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(folder->fetch_msg != NULL, NULL);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
return folder->fetch_msg(folder, item, num);
|
|
|
|
}
|
|
|
|
|
2001-05-17 15:25:31 +02:00
|
|
|
gint folder_item_add_msg(FolderItem *dest, const gchar *file,
|
|
|
|
gboolean remove_source)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gint num;
|
2002-06-30 01:33:42 +02:00
|
|
|
MsgInfo *msginfo;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(dest != NULL, -1);
|
|
|
|
g_return_val_if_fail(file != NULL, -1);
|
|
|
|
|
|
|
|
folder = dest->folder;
|
2001-05-23 14:08:40 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(folder->add_msg != NULL, -1);
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
if (!dest->cache)
|
|
|
|
folder_item_read_cache(dest);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-05-17 15:25:31 +02:00
|
|
|
num = folder->add_msg(folder, dest, file, remove_source);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
if (num > 0) {
|
|
|
|
msginfo = folder->fetch_msginfo(folder, dest, num);
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (msginfo != NULL) {
|
|
|
|
if (MSG_IS_NEW(msginfo->flags))
|
2002-07-28 01:57:07 +02:00
|
|
|
dest->new++;
|
2002-08-31 10:26:28 +02:00
|
|
|
if (MSG_IS_UNREAD(msginfo->flags))
|
2002-07-28 01:57:07 +02:00
|
|
|
dest->unread++;
|
|
|
|
dest->total++;
|
2002-10-26 22:38:01 +02:00
|
|
|
dest->need_update = TRUE;
|
2002-07-28 01:57:07 +02:00
|
|
|
|
|
|
|
msgcache_add_msg(dest->cache, msginfo);
|
|
|
|
|
|
|
|
procmsg_msginfo_free(msginfo);
|
|
|
|
}
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
dest->last_num = num;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2001-05-28 00:40:29 +02:00
|
|
|
/*
|
2001-04-19 14:21:46 +02:00
|
|
|
gint folder_item_move_msg(FolderItem *dest, MsgInfo *msginfo)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gint num;
|
|
|
|
|
|
|
|
g_return_val_if_fail(dest != NULL, -1);
|
|
|
|
g_return_val_if_fail(msginfo != NULL, -1);
|
|
|
|
|
|
|
|
folder = dest->folder;
|
|
|
|
if (dest->last_num < 0) folder->scan(folder, dest);
|
|
|
|
|
|
|
|
num = folder->move_msg(folder, dest, msginfo);
|
|
|
|
if (num > 0) dest->last_num = num;
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
2001-05-28 00:40:29 +02:00
|
|
|
*/
|
2002-11-07 00:56:26 +01:00
|
|
|
|
2002-11-08 16:42:57 +01:00
|
|
|
FolderItem *folder_item_move_recursive (FolderItem *src, FolderItem *dest)
|
2002-11-07 00:56:26 +01:00
|
|
|
{
|
|
|
|
GSList *mlist;
|
|
|
|
GSList *cur;
|
|
|
|
FolderItem *new_item;
|
|
|
|
FolderItem *next_item;
|
|
|
|
GNode *srcnode;
|
2002-11-09 03:09:58 +01:00
|
|
|
int cnt = 0;
|
2002-11-07 00:56:26 +01:00
|
|
|
mlist = folder_item_get_msg_list(src);
|
|
|
|
|
|
|
|
/* move messages */
|
|
|
|
debug_print("Moving %s to %s\n", src->path, dest->path);
|
|
|
|
new_item = folder_create_folder(dest, g_basename(src->path));
|
|
|
|
if (new_item == NULL) {
|
|
|
|
printf("Can't create folder\n");
|
2002-11-08 16:42:57 +01:00
|
|
|
return NULL;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
|
2002-11-09 03:09:58 +01:00
|
|
|
statusbar_print_all(_("Moving %s to %s..."), src->name, new_item->path);
|
|
|
|
|
2002-11-08 16:42:57 +01:00
|
|
|
if (new_item->folder == NULL)
|
|
|
|
new_item->folder = dest->folder;
|
|
|
|
|
|
|
|
/* move messages */
|
2002-11-07 00:56:26 +01:00
|
|
|
for (cur = mlist ; cur != NULL ; cur = cur->next) {
|
|
|
|
MsgInfo * msginfo;
|
2002-11-09 03:09:58 +01:00
|
|
|
cnt++;
|
2002-11-07 00:56:26 +01:00
|
|
|
msginfo = (MsgInfo *) cur->data;
|
|
|
|
folder_item_move_msg(new_item, msginfo);
|
2002-11-09 03:09:58 +01:00
|
|
|
if (cnt%500)
|
|
|
|
statusbar_print_all(_("Moving %s to %s (%d%%)..."), src->name,
|
|
|
|
new_item->path,
|
|
|
|
100*cnt/g_slist_length(mlist));
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
2002-11-08 16:42:57 +01:00
|
|
|
|
|
|
|
/*copy prefs*/
|
|
|
|
prefs_folder_item_copy_prefs(src, new_item);
|
2002-11-08 16:57:21 +01:00
|
|
|
new_item->collapsed = src->collapsed;
|
|
|
|
new_item->threaded = src->threaded;
|
|
|
|
new_item->ret_rcpt = src->ret_rcpt;
|
|
|
|
new_item->hide_read_msgs = src->hide_read_msgs;
|
|
|
|
new_item->sort_key = src->sort_key;
|
|
|
|
new_item->sort_type = src->sort_type;
|
2002-11-08 16:42:57 +01:00
|
|
|
|
|
|
|
/* recurse */
|
2002-11-07 00:56:26 +01:00
|
|
|
srcnode = src->folder->node;
|
|
|
|
srcnode = g_node_find(srcnode, G_PRE_ORDER, G_TRAVERSE_ALL, src);
|
|
|
|
srcnode = srcnode->children;
|
|
|
|
while (srcnode != NULL) {
|
|
|
|
if (srcnode && srcnode->data) {
|
|
|
|
next_item = (FolderItem*) srcnode->data;
|
2002-11-08 16:42:57 +01:00
|
|
|
if (folder_item_move_recursive(next_item, new_item) == NULL)
|
|
|
|
return NULL;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
srcnode = srcnode->next;
|
|
|
|
}
|
2002-11-08 16:42:57 +01:00
|
|
|
return new_item;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
|
2002-11-07 02:00:26 +01:00
|
|
|
FolderItem *folder_item_move_to(FolderItem *src, FolderItem *dest)
|
2002-11-07 00:56:26 +01:00
|
|
|
{
|
|
|
|
FolderItem *tmp = dest->parent;
|
2002-11-09 14:02:30 +01:00
|
|
|
char * src_identifier, * dst_identifier, * new_identifier;
|
2002-11-07 00:56:26 +01:00
|
|
|
char * phys_srcpath, * phys_dstpath;
|
2002-11-08 18:36:53 +01:00
|
|
|
GNode *src_node;
|
|
|
|
|
2002-11-07 00:56:26 +01:00
|
|
|
while (tmp) {
|
|
|
|
if (tmp == src) {
|
|
|
|
alertpanel_error(_("Can't move a folder to one of its children."));
|
2002-11-07 02:00:26 +01:00
|
|
|
return NULL;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
tmp = tmp->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = src->parent;
|
|
|
|
|
2002-11-09 14:02:30 +01:00
|
|
|
src_identifier = folder_item_get_identifier(src);
|
|
|
|
dst_identifier = folder_item_get_identifier(dest);
|
2002-11-07 00:56:26 +01:00
|
|
|
|
2002-11-09 14:02:30 +01:00
|
|
|
if(dst_identifier == NULL && dest->folder && dest->parent == NULL) {
|
2002-11-07 15:22:31 +01:00
|
|
|
/* dest can be a root folder */
|
2002-11-09 14:02:30 +01:00
|
|
|
dst_identifier = folder_get_identifier(dest->folder);
|
2002-11-07 15:22:31 +01:00
|
|
|
}
|
2002-11-09 14:02:30 +01:00
|
|
|
if (src_identifier == NULL || dst_identifier == NULL) {
|
2002-11-07 00:56:26 +01:00
|
|
|
printf("Can't get identifiers\n");
|
2002-11-07 02:00:26 +01:00
|
|
|
return NULL;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
phys_srcpath = folder_item_get_path(src);
|
2002-11-09 14:02:30 +01:00
|
|
|
phys_dstpath = g_strconcat(folder_item_get_path(dest),G_DIR_SEPARATOR_S,g_basename(phys_srcpath),NULL);
|
2002-11-07 15:22:31 +01:00
|
|
|
|
2002-11-07 00:56:26 +01:00
|
|
|
if (src->parent == dest) {
|
|
|
|
alertpanel_error(_("Source and destination are the same."));
|
2002-11-09 14:02:30 +01:00
|
|
|
g_free(src_identifier);
|
|
|
|
g_free(dst_identifier);
|
2002-11-07 00:56:26 +01:00
|
|
|
g_free(phys_srcpath);
|
|
|
|
g_free(phys_dstpath);
|
2002-11-07 02:00:26 +01:00
|
|
|
return NULL;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
debug_print("moving \"%s\" to \"%s\"\n", phys_srcpath, phys_dstpath);
|
2002-11-08 16:42:57 +01:00
|
|
|
if ((tmp = folder_item_move_recursive(src, dest)) == NULL) {
|
2002-11-07 00:56:26 +01:00
|
|
|
alertpanel_error(_("Move failed !"));
|
2002-11-07 02:00:26 +01:00
|
|
|
return NULL;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update rules */
|
|
|
|
src->folder->remove_folder(src->folder, src);
|
2002-11-08 18:36:53 +01:00
|
|
|
src_node = g_node_find(src->folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, src);
|
|
|
|
if (src_node)
|
|
|
|
g_node_destroy(src_node);
|
|
|
|
else
|
2002-11-08 19:05:18 +01:00
|
|
|
debug_print("can't remove node: is null !\n");
|
2002-11-07 00:56:26 +01:00
|
|
|
/* not to much worry if remove fails, move has been done */
|
|
|
|
|
2002-11-09 03:50:10 +01:00
|
|
|
debug_print("updating rules ....\n");
|
2002-11-09 14:02:30 +01:00
|
|
|
new_identifier = g_strconcat(dst_identifier, G_DIR_SEPARATOR_S, g_basename(phys_srcpath), NULL);
|
|
|
|
prefs_filtering_rename_path(src_identifier, new_identifier);
|
2002-11-09 03:50:10 +01:00
|
|
|
|
2002-11-07 00:56:26 +01:00
|
|
|
folder_write_list();
|
|
|
|
|
2002-11-09 14:02:30 +01:00
|
|
|
g_free(src_identifier);
|
|
|
|
g_free(dst_identifier);
|
|
|
|
g_free(new_identifier);
|
2002-11-07 00:56:26 +01:00
|
|
|
g_free(phys_srcpath);
|
|
|
|
g_free(phys_dstpath);
|
2002-11-08 16:42:57 +01:00
|
|
|
|
|
|
|
return tmp;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
gint folder_item_move_msg(FolderItem *dest, MsgInfo *msginfo)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gint num;
|
2002-08-31 10:06:06 +02:00
|
|
|
Folder *src_folder;
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(dest != NULL, -1);
|
|
|
|
g_return_val_if_fail(msginfo != NULL, -1);
|
|
|
|
|
|
|
|
folder = dest->folder;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder->remove_msg != NULL, -1);
|
|
|
|
g_return_val_if_fail(folder->copy_msg != NULL, -1);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
if (!dest->cache) folder_item_read_cache(dest);
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
src_folder = msginfo->folder->folder;
|
|
|
|
|
|
|
|
num = folder->copy_msg(folder, dest, msginfo);
|
2002-01-27 15:32:18 +01:00
|
|
|
|
2001-07-17 22:05:22 +02:00
|
|
|
if (num != -1) {
|
2002-06-30 01:33:42 +02:00
|
|
|
MsgInfo *newmsginfo;
|
2002-10-10 20:21:11 +02:00
|
|
|
|
|
|
|
/* Add new msginfo to dest folder */
|
2002-08-31 10:06:06 +02:00
|
|
|
if (NULL != (newmsginfo = folder->fetch_msginfo(folder, dest, num))) {
|
|
|
|
newmsginfo->flags.perm_flags = msginfo->flags.perm_flags;
|
|
|
|
|
|
|
|
if (dest->stype == F_OUTBOX || dest->stype == F_QUEUE ||
|
|
|
|
dest->stype == F_DRAFT || dest->stype == F_TRASH)
|
|
|
|
MSG_UNSET_PERM_FLAGS(newmsginfo->flags,
|
|
|
|
MSG_NEW|MSG_UNREAD|MSG_DELETED);
|
|
|
|
msgcache_add_msg(dest->cache, newmsginfo);
|
|
|
|
|
|
|
|
if (MSG_IS_NEW(newmsginfo->flags))
|
|
|
|
dest->new++;
|
|
|
|
if (MSG_IS_UNREAD(newmsginfo->flags))
|
|
|
|
dest->unread++;
|
|
|
|
dest->total++;
|
2002-10-10 20:21:11 +02:00
|
|
|
dest->need_update = TRUE;
|
2002-08-31 10:06:06 +02:00
|
|
|
|
|
|
|
procmsg_msginfo_free(newmsginfo);
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2002-10-10 20:21:11 +02:00
|
|
|
|
|
|
|
/* remove source message from it's folder */
|
|
|
|
if (src_folder->remove_msg) {
|
|
|
|
src_folder->remove_msg(src_folder, msginfo->folder,
|
|
|
|
msginfo->msgnum);
|
|
|
|
msgcache_remove_msg(msginfo->folder->cache, msginfo->msgnum);
|
|
|
|
|
|
|
|
if (MSG_IS_NEW(msginfo->flags))
|
|
|
|
msginfo->folder->new--;
|
|
|
|
if (MSG_IS_UNREAD(msginfo->flags))
|
|
|
|
msginfo->folder->unread--;
|
|
|
|
msginfo->folder->total--;
|
|
|
|
msginfo->folder->need_update = TRUE;
|
|
|
|
}
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
if (folder->finished_copy)
|
|
|
|
folder->finished_copy(folder, dest);
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-04-19 14:21:46 +02:00
|
|
|
gint folder_item_move_msgs_with_dest(FolderItem *dest, GSList *msglist)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gint num;
|
|
|
|
|
|
|
|
g_return_val_if_fail(dest != NULL, -1);
|
|
|
|
g_return_val_if_fail(msglist != NULL, -1);
|
|
|
|
|
|
|
|
folder = dest->folder;
|
|
|
|
if (dest->last_num < 0) folder->scan(folder, dest);
|
|
|
|
|
|
|
|
num = folder->move_msgs_with_dest(folder, dest, msglist);
|
|
|
|
if (num > 0) dest->last_num = num;
|
2001-07-31 08:17:48 +02:00
|
|
|
else dest->op_count = 0;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
2001-05-28 00:40:29 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
gint folder_item_move_msgs_with_dest(FolderItem *dest, GSList *msglist)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
2002-07-25 15:24:39 +02:00
|
|
|
FolderItem *item;
|
|
|
|
GSList *newmsgnums = NULL;
|
|
|
|
GSList *l, *l2;
|
2002-06-30 01:33:42 +02:00
|
|
|
gint num;
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(dest != NULL, -1);
|
|
|
|
g_return_val_if_fail(msglist != NULL, -1);
|
|
|
|
|
|
|
|
folder = dest->folder;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder->copy_msg != NULL, -1);
|
|
|
|
g_return_val_if_fail(folder->remove_msg != NULL, -1);
|
|
|
|
|
2002-07-25 15:24:39 +02:00
|
|
|
/*
|
|
|
|
* Copy messages to destination folder and
|
|
|
|
* store new message numbers in newmsgnums
|
|
|
|
*/
|
2001-05-28 00:40:29 +02:00
|
|
|
item = NULL;
|
2002-08-31 10:26:28 +02:00
|
|
|
for (l = msglist ; l != NULL ; l = g_slist_next(l)) {
|
2001-05-28 00:40:29 +02:00
|
|
|
MsgInfo * msginfo = (MsgInfo *) l->data;
|
|
|
|
|
|
|
|
if (!item && msginfo->folder != NULL)
|
|
|
|
item = msginfo->folder;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
num = folder->copy_msg(folder, dest, msginfo);
|
2002-07-25 15:24:39 +02:00
|
|
|
newmsgnums = g_slist_append(newmsgnums, GINT_TO_POINTER(num));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read cache for dest folder */
|
|
|
|
if (!dest->cache) folder_item_read_cache(dest);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fetch new MsgInfos for new messages in dest folder,
|
|
|
|
* add them to the msgcache and update folder message counts
|
|
|
|
*/
|
|
|
|
l2 = newmsgnums;
|
2002-08-31 10:26:28 +02:00
|
|
|
for (l = msglist; l != NULL; l = g_slist_next(l)) {
|
2002-07-25 15:24:39 +02:00
|
|
|
MsgInfo *msginfo = (MsgInfo *) l->data;
|
|
|
|
|
|
|
|
num = GPOINTER_TO_INT(l2->data);
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
if (num != -1) {
|
|
|
|
MsgInfo *newmsginfo;
|
|
|
|
|
|
|
|
newmsginfo = folder->fetch_msginfo(folder, dest, num);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (newmsginfo) {
|
2002-06-30 01:33:42 +02:00
|
|
|
newmsginfo->flags.perm_flags = msginfo->flags.perm_flags;
|
|
|
|
if (dest->stype == F_OUTBOX ||
|
|
|
|
dest->stype == F_QUEUE ||
|
|
|
|
dest->stype == F_DRAFT ||
|
|
|
|
dest->stype == F_TRASH)
|
|
|
|
MSG_UNSET_PERM_FLAGS(newmsginfo->flags,
|
|
|
|
MSG_NEW|MSG_UNREAD|MSG_DELETED);
|
|
|
|
msgcache_add_msg(dest->cache, newmsginfo);
|
|
|
|
|
|
|
|
if (MSG_IS_NEW(newmsginfo->flags))
|
|
|
|
dest->new++;
|
|
|
|
if (MSG_IS_UNREAD(newmsginfo->flags))
|
|
|
|
dest->unread++;
|
|
|
|
dest->total++;
|
2002-10-10 20:21:11 +02:00
|
|
|
dest->need_update = TRUE;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
procmsg_msginfo_free(newmsginfo);
|
|
|
|
}
|
2002-07-25 15:24:39 +02:00
|
|
|
}
|
|
|
|
l2 = g_slist_next(l2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove source messages from their folders if
|
|
|
|
* copying was successfull and update folder
|
|
|
|
* message counts
|
|
|
|
*/
|
|
|
|
l2 = newmsgnums;
|
2002-08-31 10:26:28 +02:00
|
|
|
for (l = msglist; l != NULL; l = g_slist_next(l)) {
|
2002-07-25 15:24:39 +02:00
|
|
|
MsgInfo *msginfo = (MsgInfo *) l->data;
|
|
|
|
|
|
|
|
num = GPOINTER_TO_INT(l2->data);
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (num != -1) {
|
2001-05-28 00:40:29 +02:00
|
|
|
item->folder->remove_msg(item->folder,
|
|
|
|
msginfo->folder,
|
|
|
|
msginfo->msgnum);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (!item->cache)
|
2002-07-25 15:24:39 +02:00
|
|
|
folder_item_read_cache(item);
|
2002-06-30 01:33:42 +02:00
|
|
|
msgcache_remove_msg(item->cache, msginfo->msgnum);
|
2002-07-25 15:24:39 +02:00
|
|
|
|
|
|
|
if (MSG_IS_NEW(msginfo->flags))
|
|
|
|
msginfo->folder->new--;
|
|
|
|
if (MSG_IS_UNREAD(msginfo->flags))
|
|
|
|
msginfo->folder->unread--;
|
|
|
|
msginfo->folder->total--;
|
2002-10-10 20:21:11 +02:00
|
|
|
msginfo->folder->need_update = TRUE;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2002-07-25 15:24:39 +02:00
|
|
|
|
|
|
|
l2 = g_slist_next(l2);
|
|
|
|
}
|
|
|
|
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
if (folder->finished_copy)
|
|
|
|
folder->finished_copy(folder, dest);
|
|
|
|
|
2002-07-25 15:24:39 +02:00
|
|
|
g_slist_free(newmsgnums);
|
2001-05-28 00:40:29 +02:00
|
|
|
return dest->last_num;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-05-28 00:40:29 +02:00
|
|
|
/*
|
2001-04-19 14:21:46 +02:00
|
|
|
gint folder_item_copy_msg(FolderItem *dest, MsgInfo *msginfo)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gint num;
|
|
|
|
|
|
|
|
g_return_val_if_fail(dest != NULL, -1);
|
|
|
|
g_return_val_if_fail(msginfo != NULL, -1);
|
|
|
|
|
|
|
|
folder = dest->folder;
|
|
|
|
if (dest->last_num < 0) folder->scan(folder, dest);
|
|
|
|
|
|
|
|
num = folder->copy_msg(folder, dest, msginfo);
|
|
|
|
if (num > 0) dest->last_num = num;
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
2001-05-28 00:40:29 +02:00
|
|
|
*/
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-05-28 00:40:29 +02:00
|
|
|
gint folder_item_copy_msg(FolderItem *dest, MsgInfo *msginfo)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gint num;
|
|
|
|
|
|
|
|
g_return_val_if_fail(dest != NULL, -1);
|
|
|
|
g_return_val_if_fail(msginfo != NULL, -1);
|
|
|
|
|
|
|
|
folder = dest->folder;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder->copy_msg != NULL, -1);
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
if (!dest->cache) folder_item_read_cache(dest);
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
num = folder->copy_msg(folder, dest, msginfo);
|
2002-06-30 01:33:42 +02:00
|
|
|
if (num != -1) {
|
|
|
|
MsgInfo *newmsginfo;
|
|
|
|
|
2002-08-31 10:06:06 +02:00
|
|
|
if (NULL != (newmsginfo = folder->fetch_msginfo(folder, dest, num))) {
|
|
|
|
newmsginfo->flags.perm_flags = msginfo->flags.perm_flags;
|
|
|
|
if (dest->stype == F_OUTBOX ||
|
|
|
|
dest->stype == F_QUEUE ||
|
|
|
|
dest->stype == F_DRAFT ||
|
|
|
|
dest->stype == F_TRASH)
|
|
|
|
MSG_UNSET_PERM_FLAGS(newmsginfo->flags,
|
|
|
|
MSG_NEW|MSG_UNREAD|MSG_DELETED);
|
|
|
|
msgcache_add_msg(dest->cache, newmsginfo);
|
|
|
|
|
|
|
|
if (MSG_IS_NEW(newmsginfo->flags))
|
|
|
|
dest->new++;
|
|
|
|
if (MSG_IS_UNREAD(newmsginfo->flags))
|
|
|
|
dest->unread++;
|
|
|
|
dest->total++;
|
2002-10-10 20:21:11 +02:00
|
|
|
dest->need_update = TRUE;
|
2002-08-31 10:06:06 +02:00
|
|
|
|
|
|
|
procmsg_msginfo_free(newmsginfo);
|
|
|
|
}
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
if (folder->finished_copy)
|
|
|
|
folder->finished_copy(folder, dest);
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-04-19 14:21:46 +02:00
|
|
|
gint folder_item_copy_msgs_with_dest(FolderItem *dest, GSList *msglist)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gint num;
|
|
|
|
|
|
|
|
g_return_val_if_fail(dest != NULL, -1);
|
|
|
|
g_return_val_if_fail(msglist != NULL, -1);
|
|
|
|
|
|
|
|
folder = dest->folder;
|
|
|
|
if (dest->last_num < 0) folder->scan(folder, dest);
|
|
|
|
|
|
|
|
num = folder->copy_msgs_with_dest(folder, dest, msglist);
|
|
|
|
if (num > 0) dest->last_num = num;
|
2001-07-31 08:17:48 +02:00
|
|
|
else dest->op_count = 0;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
2001-05-28 00:40:29 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
gint folder_item_copy_msgs_with_dest(FolderItem *dest, GSList *msglist)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gint num;
|
2002-07-25 15:24:39 +02:00
|
|
|
GSList *newmsgnums = NULL;
|
|
|
|
GSList *l, *l2;
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(dest != NULL, -1);
|
|
|
|
g_return_val_if_fail(msglist != NULL, -1);
|
|
|
|
|
|
|
|
folder = dest->folder;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder->copy_msg != NULL, -1);
|
|
|
|
|
2002-07-25 15:24:39 +02:00
|
|
|
/*
|
|
|
|
* Copy messages to destination folder and
|
|
|
|
* store new message numbers in newmsgnums
|
|
|
|
*/
|
2002-08-31 10:26:28 +02:00
|
|
|
for (l = msglist ; l != NULL ; l = g_slist_next(l)) {
|
2001-05-28 00:40:29 +02:00
|
|
|
MsgInfo * msginfo = (MsgInfo *) l->data;
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
num = folder->copy_msg(folder, dest, msginfo);
|
2002-07-25 15:24:39 +02:00
|
|
|
newmsgnums = g_slist_append(newmsgnums, GINT_TO_POINTER(num));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read cache for dest folder */
|
|
|
|
if (!dest->cache) folder_item_read_cache(dest);
|
2002-10-07 23:47:32 +02:00
|
|
|
|
2002-07-25 15:24:39 +02:00
|
|
|
/*
|
|
|
|
* Fetch new MsgInfos for new messages in dest folder,
|
|
|
|
* add them to the msgcache and update folder message counts
|
|
|
|
*/
|
|
|
|
l2 = newmsgnums;
|
2002-08-31 10:26:28 +02:00
|
|
|
for (l = msglist; l != NULL; l = g_slist_next(l)) {
|
2002-07-25 15:24:39 +02:00
|
|
|
MsgInfo *msginfo = (MsgInfo *) l->data;
|
|
|
|
|
|
|
|
num = GPOINTER_TO_INT(l2->data);
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
if (num != -1) {
|
|
|
|
MsgInfo *newmsginfo;
|
|
|
|
|
|
|
|
newmsginfo = folder->fetch_msginfo(folder, dest, num);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (newmsginfo) {
|
2002-06-30 01:33:42 +02:00
|
|
|
newmsginfo->flags.perm_flags = msginfo->flags.perm_flags;
|
|
|
|
if (dest->stype == F_OUTBOX ||
|
|
|
|
dest->stype == F_QUEUE ||
|
|
|
|
dest->stype == F_DRAFT ||
|
|
|
|
dest->stype == F_TRASH)
|
|
|
|
MSG_UNSET_PERM_FLAGS(newmsginfo->flags,
|
|
|
|
MSG_NEW|MSG_UNREAD|MSG_DELETED);
|
|
|
|
msgcache_add_msg(dest->cache, newmsginfo);
|
|
|
|
|
|
|
|
if (MSG_IS_NEW(newmsginfo->flags))
|
|
|
|
dest->new++;
|
|
|
|
if (MSG_IS_UNREAD(newmsginfo->flags))
|
|
|
|
dest->unread++;
|
|
|
|
dest->total++;
|
2002-10-10 20:21:11 +02:00
|
|
|
dest->need_update = TRUE;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
procmsg_msginfo_free(newmsginfo);
|
|
|
|
}
|
|
|
|
}
|
2002-07-25 15:24:39 +02:00
|
|
|
l2 = g_slist_next(l2);
|
2001-05-28 00:40:29 +02:00
|
|
|
}
|
2002-07-25 15:24:39 +02:00
|
|
|
|
2001-05-28 00:40:29 +02:00
|
|
|
if (folder->finished_copy)
|
|
|
|
folder->finished_copy(folder, dest);
|
|
|
|
|
2002-07-25 15:24:39 +02:00
|
|
|
g_slist_free(newmsgnums);
|
2001-05-28 00:40:29 +02:00
|
|
|
return dest->last_num;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
gint folder_item_remove_msg(FolderItem *item, gint num)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
2001-08-30 14:59:38 +02:00
|
|
|
gint ret;
|
2002-06-30 01:33:42 +02:00
|
|
|
MsgInfo *msginfo;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, -1);
|
|
|
|
|
|
|
|
folder = item->folder;
|
2002-06-30 01:33:42 +02:00
|
|
|
if (!item->cache) folder_item_read_cache(item);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-08-30 14:59:38 +02:00
|
|
|
ret = folder->remove_msg(folder, item, num);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
msginfo = msgcache_get_msg(item->cache, num);
|
2002-08-31 10:26:28 +02:00
|
|
|
if (msginfo != NULL) {
|
|
|
|
if (MSG_IS_NEW(msginfo->flags))
|
2002-07-31 17:35:26 +02:00
|
|
|
item->new--;
|
2002-08-31 10:26:28 +02:00
|
|
|
if (MSG_IS_UNREAD(msginfo->flags))
|
2002-07-31 17:35:26 +02:00
|
|
|
item->unread--;
|
|
|
|
procmsg_msginfo_free(msginfo);
|
|
|
|
msgcache_remove_msg(item->cache, num);
|
|
|
|
}
|
2002-06-30 01:33:42 +02:00
|
|
|
item->total--;
|
2002-10-10 20:21:11 +02:00
|
|
|
item->need_update = TRUE;
|
2001-05-30 05:05:08 +02:00
|
|
|
|
2001-08-30 14:59:38 +02:00
|
|
|
return ret;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2001-10-07 11:15:06 +02:00
|
|
|
gint folder_item_remove_msgs(FolderItem *item, GSList *msglist)
|
|
|
|
{
|
2002-10-13 18:30:48 +02:00
|
|
|
Folder *folder;
|
2001-10-07 11:15:06 +02:00
|
|
|
gint ret = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, -1);
|
2002-10-13 18:30:48 +02:00
|
|
|
|
|
|
|
folder = item->folder;
|
|
|
|
if (folder->remove_msgs) {
|
|
|
|
ret = folder->remove_msgs(folder, item, msglist);
|
|
|
|
if (ret == 0)
|
|
|
|
folder->scan(folder);
|
|
|
|
return ret;
|
|
|
|
}
|
2001-10-07 11:15:06 +02:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
if (!item->cache) folder_item_read_cache(item);
|
|
|
|
|
2001-10-07 11:15:06 +02:00
|
|
|
while (msglist != NULL) {
|
|
|
|
MsgInfo *msginfo = (MsgInfo *)msglist->data;
|
|
|
|
|
|
|
|
ret = folder_item_remove_msg(item, msginfo->msgnum);
|
|
|
|
if (ret != 0) break;
|
2002-06-30 01:33:42 +02:00
|
|
|
msgcache_remove_msg(item->cache, msginfo->msgnum);
|
2001-10-07 11:15:06 +02:00
|
|
|
msglist = msglist->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
gint folder_item_remove_all_msg(FolderItem *item)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
2001-05-30 05:05:08 +02:00
|
|
|
gint result;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, -1);
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
folder = item->folder;
|
|
|
|
|
2001-05-23 14:08:40 +02:00
|
|
|
g_return_val_if_fail(folder->remove_all_msg != NULL, -1);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2001-05-30 05:05:08 +02:00
|
|
|
result = folder->remove_all_msg(folder, item);
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
if (result == 0) {
|
2001-05-30 05:05:08 +02:00
|
|
|
if (folder->finished_remove)
|
|
|
|
folder->finished_remove(folder, item);
|
2002-07-06 03:07:26 +02:00
|
|
|
|
|
|
|
folder_item_free_cache(item);
|
|
|
|
item->cache = msgcache_new();
|
|
|
|
|
|
|
|
item->new = 0;
|
|
|
|
item->unread = 0;
|
|
|
|
item->total = 0;
|
2002-10-10 20:21:11 +02:00
|
|
|
item->need_update = TRUE;
|
2001-05-30 05:05:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean folder_item_is_msg_changed(FolderItem *item, MsgInfo *msginfo)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, FALSE);
|
|
|
|
|
|
|
|
folder = item->folder;
|
2001-05-23 14:08:40 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(folder->is_msg_changed != NULL, -1);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
return folder->is_msg_changed(folder, item, msginfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *folder_item_get_cache_file(FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
gchar *file;
|
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
g_return_val_if_fail(item->path != NULL, NULL);
|
|
|
|
|
|
|
|
path = folder_item_get_path(item);
|
|
|
|
g_return_val_if_fail(path != NULL, NULL);
|
|
|
|
if (!is_dir_exist(path))
|
|
|
|
make_dir_hier(path);
|
|
|
|
file = g_strconcat(path, G_DIR_SEPARATOR_S, CACHE_FILE, NULL);
|
|
|
|
g_free(path);
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *folder_item_get_mark_file(FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
gchar *file;
|
|
|
|
|
|
|
|
g_return_val_if_fail(item != NULL, NULL);
|
|
|
|
g_return_val_if_fail(item->path != NULL, NULL);
|
|
|
|
|
|
|
|
path = folder_item_get_path(item);
|
|
|
|
g_return_val_if_fail(path != NULL, NULL);
|
|
|
|
if (!is_dir_exist(path))
|
|
|
|
make_dir_hier(path);
|
|
|
|
file = g_strconcat(path, G_DIR_SEPARATOR_S, MARK_FILE, NULL);
|
|
|
|
g_free(path);
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean folder_build_tree(GNode *node, gpointer data)
|
|
|
|
{
|
|
|
|
Folder *folder = FOLDER(data);
|
|
|
|
FolderItem *item;
|
|
|
|
XMLNode *xmlnode;
|
|
|
|
GList *list;
|
|
|
|
SpecialFolderItemType stype = F_NORMAL;
|
|
|
|
const gchar *name = NULL;
|
|
|
|
const gchar *path = NULL;
|
|
|
|
PrefsAccount *account = NULL;
|
2001-09-23 03:19:22 +02:00
|
|
|
gboolean no_sub = FALSE, no_select = FALSE, collapsed = FALSE,
|
2002-10-13 16:12:29 +02:00
|
|
|
threaded = TRUE, apply_sub = FALSE;
|
|
|
|
gboolean ret_rcpt = FALSE, hidereadmsgs = FALSE; /* CLAWS */
|
2002-06-03 08:03:31 +02:00
|
|
|
FolderSortKey sort_key = SORT_BY_NONE;
|
|
|
|
FolderSortType sort_type = SORT_ASCENDING;
|
2002-06-19 09:31:13 +02:00
|
|
|
gint new = 0, unread = 0, total = 0;
|
|
|
|
time_t mtime = 0;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail(node->data != NULL, FALSE);
|
|
|
|
if (!node->parent) return FALSE;
|
|
|
|
|
|
|
|
xmlnode = node->data;
|
|
|
|
if (strcmp2(xmlnode->tag->tag, "folderitem") != 0) {
|
|
|
|
g_warning("tag name != \"folderitem\"\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
list = xmlnode->tag->attr;
|
|
|
|
for (; list != NULL; list = list->next) {
|
|
|
|
XMLAttr *attr = list->data;
|
|
|
|
|
|
|
|
if (!attr || !attr->name || !attr->value) continue;
|
|
|
|
if (!strcmp(attr->name, "type")) {
|
|
|
|
if (!strcasecmp(attr->value, "normal"))
|
|
|
|
stype = F_NORMAL;
|
|
|
|
else if (!strcasecmp(attr->value, "inbox"))
|
|
|
|
stype = F_INBOX;
|
|
|
|
else if (!strcasecmp(attr->value, "outbox"))
|
|
|
|
stype = F_OUTBOX;
|
|
|
|
else if (!strcasecmp(attr->value, "draft"))
|
|
|
|
stype = F_DRAFT;
|
|
|
|
else if (!strcasecmp(attr->value, "queue"))
|
|
|
|
stype = F_QUEUE;
|
|
|
|
else if (!strcasecmp(attr->value, "trash"))
|
|
|
|
stype = F_TRASH;
|
|
|
|
} else if (!strcmp(attr->name, "name"))
|
|
|
|
name = attr->value;
|
|
|
|
else if (!strcmp(attr->name, "path"))
|
|
|
|
path = attr->value;
|
2002-10-13 16:12:29 +02:00
|
|
|
else if (!strcmp(attr->name, "mtime"))
|
2002-06-19 09:31:13 +02:00
|
|
|
mtime = strtoul(attr->value, NULL, 10);
|
2001-04-19 14:21:46 +02:00
|
|
|
else if (!strcmp(attr->name, "new"))
|
|
|
|
new = atoi(attr->value);
|
|
|
|
else if (!strcmp(attr->name, "unread"))
|
|
|
|
unread = atoi(attr->value);
|
|
|
|
else if (!strcmp(attr->name, "total"))
|
|
|
|
total = atoi(attr->value);
|
2001-07-01 10:37:50 +02:00
|
|
|
else if (!strcmp(attr->name, "no_sub"))
|
|
|
|
no_sub = *attr->value == '1' ? TRUE : FALSE;
|
|
|
|
else if (!strcmp(attr->name, "no_select"))
|
|
|
|
no_select = *attr->value == '1' ? TRUE : FALSE;
|
2001-07-10 18:14:23 +02:00
|
|
|
else if (!strcmp(attr->name, "collapsed"))
|
|
|
|
collapsed = *attr->value == '1' ? TRUE : FALSE;
|
2001-09-22 15:24:51 +02:00
|
|
|
else if (!strcmp(attr->name, "threaded"))
|
|
|
|
threaded = *attr->value == '1' ? TRUE : FALSE;
|
2001-12-11 16:06:46 +01:00
|
|
|
else if (!strcmp(attr->name, "hidereadmsgs"))
|
|
|
|
hidereadmsgs = *attr->value == '1' ? TRUE : FALSE;
|
2001-09-23 03:19:22 +02:00
|
|
|
else if (!strcmp(attr->name, "reqretrcpt"))
|
|
|
|
ret_rcpt = *attr->value == '1' ? TRUE : FALSE;
|
2002-06-03 08:03:31 +02:00
|
|
|
else if (!strcmp(attr->name, "sort_key")) {
|
|
|
|
if (!strcmp(attr->value, "none"))
|
|
|
|
sort_key = SORT_BY_NONE;
|
|
|
|
else if (!strcmp(attr->value, "number"))
|
|
|
|
sort_key = SORT_BY_NUMBER;
|
|
|
|
else if (!strcmp(attr->value, "size"))
|
|
|
|
sort_key = SORT_BY_SIZE;
|
|
|
|
else if (!strcmp(attr->value, "date"))
|
|
|
|
sort_key = SORT_BY_DATE;
|
|
|
|
else if (!strcmp(attr->value, "from"))
|
|
|
|
sort_key = SORT_BY_FROM;
|
|
|
|
else if (!strcmp(attr->value, "subject"))
|
|
|
|
sort_key = SORT_BY_SUBJECT;
|
|
|
|
else if (!strcmp(attr->value, "score"))
|
|
|
|
sort_key = SORT_BY_SCORE;
|
|
|
|
else if (!strcmp(attr->value, "label"))
|
|
|
|
sort_key = SORT_BY_LABEL;
|
|
|
|
else if (!strcmp(attr->value, "mark"))
|
|
|
|
sort_key = SORT_BY_MARK;
|
|
|
|
else if (!strcmp(attr->value, "unread"))
|
|
|
|
sort_key = SORT_BY_UNREAD;
|
|
|
|
else if (!strcmp(attr->value, "mime"))
|
|
|
|
sort_key = SORT_BY_MIME;
|
2002-06-16 22:27:31 +02:00
|
|
|
else if (!strcmp(attr->value, "locked"))
|
|
|
|
sort_key = SORT_BY_LOCKED;
|
2002-06-03 08:03:31 +02:00
|
|
|
} else if (!strcmp(attr->name, "sort_type")) {
|
|
|
|
if (!strcmp(attr->value, "ascending"))
|
|
|
|
sort_type = SORT_ASCENDING;
|
|
|
|
else
|
|
|
|
sort_type = SORT_DESCENDING;
|
2002-10-13 16:12:29 +02:00
|
|
|
} else if (!strcmp(attr->name, "account_id")) {
|
|
|
|
account = account_find_from_id(atoi(attr->value));
|
|
|
|
if (!account) g_warning("account_id: %s not found\n",
|
|
|
|
attr->value);
|
|
|
|
} else if (!strcmp(attr->name, "apply_sub"))
|
|
|
|
apply_sub = *attr->value == '1' ? TRUE : FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2002-07-25 23:09:10 +02:00
|
|
|
item = folder_item_new(folder, name, path);
|
2001-04-19 14:21:46 +02:00
|
|
|
item->stype = stype;
|
|
|
|
item->mtime = mtime;
|
|
|
|
item->new = new;
|
|
|
|
item->unread = unread;
|
|
|
|
item->total = total;
|
2001-07-01 10:37:50 +02:00
|
|
|
item->no_sub = no_sub;
|
|
|
|
item->no_select = no_select;
|
2001-07-10 18:14:23 +02:00
|
|
|
item->collapsed = collapsed;
|
2001-09-22 15:24:51 +02:00
|
|
|
item->threaded = threaded;
|
2001-12-11 16:06:46 +01:00
|
|
|
item->hide_read_msgs = hidereadmsgs;
|
2001-09-23 03:19:22 +02:00
|
|
|
item->ret_rcpt = ret_rcpt;
|
2002-06-03 08:03:31 +02:00
|
|
|
item->sort_key = sort_key;
|
|
|
|
item->sort_type = sort_type;
|
2001-04-19 14:21:46 +02:00
|
|
|
item->parent = FOLDER_ITEM(node->parent->data);
|
|
|
|
item->folder = folder;
|
|
|
|
switch (stype) {
|
|
|
|
case F_INBOX: folder->inbox = item; break;
|
|
|
|
case F_OUTBOX: folder->outbox = item; break;
|
|
|
|
case F_DRAFT: folder->draft = item; break;
|
|
|
|
case F_QUEUE: folder->queue = item; break;
|
|
|
|
case F_TRASH: folder->trash = item; break;
|
2002-03-07 14:22:39 +01:00
|
|
|
default: break;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
2002-10-13 16:12:29 +02:00
|
|
|
item->account = account;
|
|
|
|
item->apply_sub = apply_sub;
|
2001-05-06 06:27:28 +02:00
|
|
|
prefs_folder_item_read_config(item);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
node->data = item;
|
|
|
|
xml_free_node(xmlnode);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean folder_read_folder_func(GNode *node, gpointer data)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
XMLNode *xmlnode;
|
|
|
|
GList *list;
|
|
|
|
FolderType type = F_UNKNOWN;
|
|
|
|
const gchar *name = NULL;
|
|
|
|
const gchar *path = NULL;
|
|
|
|
PrefsAccount *account = NULL;
|
2002-10-13 16:12:29 +02:00
|
|
|
gboolean collapsed = FALSE, threaded = TRUE, apply_sub = FALSE;
|
|
|
|
gboolean ret_rcpt = FALSE; /* CLAWS */
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
if (g_node_depth(node) != 2) return FALSE;
|
|
|
|
g_return_val_if_fail(node->data != NULL, FALSE);
|
|
|
|
|
|
|
|
xmlnode = node->data;
|
|
|
|
if (strcmp2(xmlnode->tag->tag, "folder") != 0) {
|
|
|
|
g_warning("tag name != \"folder\"\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
g_node_unlink(node);
|
|
|
|
list = xmlnode->tag->attr;
|
|
|
|
for (; list != NULL; list = list->next) {
|
|
|
|
XMLAttr *attr = list->data;
|
|
|
|
|
|
|
|
if (!attr || !attr->name || !attr->value) continue;
|
|
|
|
if (!strcmp(attr->name, "type")) {
|
|
|
|
if (!strcasecmp(attr->value, "mh"))
|
|
|
|
type = F_MH;
|
|
|
|
else if (!strcasecmp(attr->value, "mbox"))
|
|
|
|
type = F_MBOX;
|
|
|
|
else if (!strcasecmp(attr->value, "maildir"))
|
|
|
|
type = F_MAILDIR;
|
|
|
|
else if (!strcasecmp(attr->value, "imap"))
|
|
|
|
type = F_IMAP;
|
|
|
|
else if (!strcasecmp(attr->value, "news"))
|
|
|
|
type = F_NEWS;
|
|
|
|
} else if (!strcmp(attr->name, "name"))
|
|
|
|
name = attr->value;
|
|
|
|
else if (!strcmp(attr->name, "path"))
|
|
|
|
path = attr->value;
|
2002-10-13 16:12:29 +02:00
|
|
|
else if (!strcmp(attr->name, "collapsed"))
|
|
|
|
collapsed = *attr->value == '1' ? TRUE : FALSE;
|
|
|
|
else if (!strcmp(attr->name, "threaded"))
|
|
|
|
threaded = *attr->value == '1' ? TRUE : FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
else if (!strcmp(attr->name, "account_id")) {
|
|
|
|
account = account_find_from_id(atoi(attr->value));
|
|
|
|
if (!account) g_warning("account_id: %s not found\n",
|
|
|
|
attr->value);
|
2002-10-13 16:12:29 +02:00
|
|
|
} else if (!strcmp(attr->name, "apply_sub"))
|
|
|
|
apply_sub = *attr->value == '1' ? TRUE : FALSE;
|
2001-09-23 03:19:22 +02:00
|
|
|
else if (!strcmp(attr->name, "reqretrcpt"))
|
|
|
|
ret_rcpt = *attr->value == '1' ? TRUE : FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
folder = folder_new(type, name, path);
|
|
|
|
g_return_val_if_fail(folder != NULL, FALSE);
|
|
|
|
folder->account = account;
|
|
|
|
if (account && (type == F_IMAP || type == F_NEWS))
|
|
|
|
account->folder = REMOTE_FOLDER(folder);
|
|
|
|
node->data = folder->node->data;
|
|
|
|
g_node_destroy(folder->node);
|
|
|
|
folder->node = node;
|
|
|
|
folder_add(folder);
|
2001-07-14 19:21:51 +02:00
|
|
|
FOLDER_ITEM(node->data)->collapsed = collapsed;
|
2001-09-22 15:24:51 +02:00
|
|
|
FOLDER_ITEM(node->data)->threaded = threaded;
|
2002-10-13 16:12:29 +02:00
|
|
|
FOLDER_ITEM(node->data)->account = account;
|
|
|
|
FOLDER_ITEM(node->data)->apply_sub = apply_sub;
|
2001-09-23 03:19:22 +02:00
|
|
|
FOLDER_ITEM(node->data)->ret_rcpt = ret_rcpt;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
|
|
|
|
folder_build_tree, folder);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *folder_get_list_path(void)
|
|
|
|
{
|
|
|
|
static gchar *filename = NULL;
|
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
|
|
|
|
FOLDER_LIST, NULL);
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void folder_write_list_recursive(GNode *node, gpointer data)
|
|
|
|
{
|
|
|
|
FILE *fp = (FILE *)data;
|
2002-09-04 10:12:49 +02:00
|
|
|
FolderItem *item;
|
2001-04-19 14:21:46 +02:00
|
|
|
gint i, depth;
|
|
|
|
static gchar *folder_type_str[] = {"mh", "mbox", "maildir", "imap",
|
|
|
|
"news", "unknown"};
|
|
|
|
static gchar *folder_item_stype_str[] = {"normal", "inbox", "outbox",
|
|
|
|
"draft", "queue", "trash"};
|
2002-06-03 08:03:31 +02:00
|
|
|
static gchar *sort_key_str[] = {"none", "number", "size", "date",
|
|
|
|
"from", "subject", "score", "label",
|
2002-06-16 22:27:31 +02:00
|
|
|
"mark", "unread", "mime", "locked" };
|
2002-09-04 10:12:49 +02:00
|
|
|
g_return_if_fail(node != NULL);
|
|
|
|
g_return_if_fail(fp != NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-09-04 10:12:49 +02:00
|
|
|
item = FOLDER_ITEM(node->data);
|
2001-04-19 14:21:46 +02:00
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
|
|
|
|
depth = g_node_depth(node);
|
|
|
|
for (i = 0; i < depth; i++)
|
|
|
|
fputs(" ", fp);
|
|
|
|
if (depth == 1) {
|
|
|
|
Folder *folder = item->folder;
|
|
|
|
|
|
|
|
fprintf(fp, "<folder type=\"%s\"", folder_type_str[folder->type]);
|
|
|
|
if (folder->name) {
|
|
|
|
fputs(" name=\"", fp);
|
|
|
|
xml_file_put_escape_str(fp, folder->name);
|
|
|
|
fputs("\"", fp);
|
|
|
|
}
|
2001-05-28 00:40:29 +02:00
|
|
|
if ((folder->type == F_MH) || (folder->type == F_MBOX)) {
|
2001-04-19 14:21:46 +02:00
|
|
|
fputs(" path=\"", fp);
|
|
|
|
xml_file_put_escape_str
|
|
|
|
(fp, LOCAL_FOLDER(folder)->rootpath);
|
|
|
|
fputs("\"", fp);
|
|
|
|
}
|
2002-10-13 16:12:29 +02:00
|
|
|
if (item->collapsed && node->children)
|
|
|
|
fputs(" collapsed=\"1\"", fp);
|
2001-04-19 14:21:46 +02:00
|
|
|
if (folder->account)
|
|
|
|
fprintf(fp, " account_id=\"%d\"",
|
|
|
|
folder->account->account_id);
|
2002-10-13 16:12:29 +02:00
|
|
|
if (item->apply_sub)
|
|
|
|
fputs(" apply_sub=\"1\"", fp);
|
2001-09-23 03:19:22 +02:00
|
|
|
if (item->ret_rcpt)
|
|
|
|
fputs(" reqretrcpt=\"1\"", fp);
|
2001-04-19 14:21:46 +02:00
|
|
|
} else {
|
|
|
|
fprintf(fp, "<folderitem type=\"%s\"",
|
|
|
|
folder_item_stype_str[item->stype]);
|
|
|
|
if (item->name) {
|
|
|
|
fputs(" name=\"", fp);
|
|
|
|
xml_file_put_escape_str(fp, item->name);
|
|
|
|
fputs("\"", fp);
|
|
|
|
}
|
|
|
|
if (item->path) {
|
|
|
|
fputs(" path=\"", fp);
|
|
|
|
xml_file_put_escape_str(fp, item->path);
|
|
|
|
fputs("\"", fp);
|
|
|
|
}
|
2002-10-13 16:12:29 +02:00
|
|
|
|
2001-07-01 10:37:50 +02:00
|
|
|
if (item->no_sub)
|
|
|
|
fputs(" no_sub=\"1\"", fp);
|
|
|
|
if (item->no_select)
|
|
|
|
fputs(" no_select=\"1\"", fp);
|
2001-07-15 15:42:30 +02:00
|
|
|
if (item->collapsed && node->children)
|
2001-07-10 18:14:23 +02:00
|
|
|
fputs(" collapsed=\"1\"", fp);
|
2001-09-22 15:24:51 +02:00
|
|
|
if (item->threaded)
|
|
|
|
fputs(" threaded=\"1\"", fp);
|
2001-09-27 10:14:23 +02:00
|
|
|
else
|
|
|
|
fputs(" threaded=\"0\"", fp);
|
2001-12-11 16:06:46 +01:00
|
|
|
if (item->hide_read_msgs)
|
|
|
|
fputs(" hidereadmsgs=\"1\"", fp);
|
|
|
|
else
|
|
|
|
fputs(" hidereadmsgs=\"0\"", fp);
|
2001-09-23 03:19:22 +02:00
|
|
|
if (item->ret_rcpt)
|
|
|
|
fputs(" reqretrcpt=\"1\"", fp);
|
2002-06-03 08:03:31 +02:00
|
|
|
|
|
|
|
if (item->sort_key != SORT_BY_NONE) {
|
|
|
|
fprintf(fp, " sort_key=\"%s\"",
|
|
|
|
sort_key_str[item->sort_key]);
|
|
|
|
if (item->sort_type == SORT_ASCENDING)
|
|
|
|
fprintf(fp, " sort_type=\"ascending\"");
|
|
|
|
else
|
|
|
|
fprintf(fp, " sort_type=\"descending\"");
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
fprintf(fp,
|
2001-10-20 09:04:54 +02:00
|
|
|
" mtime=\"%lu\" new=\"%d\" unread=\"%d\" total=\"%d\"",
|
2001-04-19 14:21:46 +02:00
|
|
|
item->mtime, item->new, item->unread, item->total);
|
2002-10-13 16:12:29 +02:00
|
|
|
|
|
|
|
if (item->account)
|
|
|
|
fprintf(fp, " account_id=\"%d\"",
|
|
|
|
item->account->account_id);
|
|
|
|
if (item->apply_sub)
|
|
|
|
fputs(" apply_sub=\"1\"", fp);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (node->children) {
|
|
|
|
GNode *child;
|
|
|
|
fputs(">\n", fp);
|
|
|
|
|
|
|
|
child = node->children;
|
|
|
|
while (child) {
|
|
|
|
GNode *cur;
|
|
|
|
|
|
|
|
cur = child;
|
|
|
|
child = cur->next;
|
|
|
|
folder_write_list_recursive(cur, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < depth; i++)
|
|
|
|
fputs(" ", fp);
|
|
|
|
fprintf(fp, "</%s>\n", depth == 1 ? "folder" : "folderitem");
|
|
|
|
} else
|
|
|
|
fputs(" />\n", fp);
|
|
|
|
}
|
2001-05-29 02:29:13 +02:00
|
|
|
|
2002-11-09 17:35:13 +01:00
|
|
|
static void folder_update_op_count_rec(GNode *node)
|
|
|
|
{
|
2001-07-31 08:17:48 +02:00
|
|
|
FolderItem *fitem = FOLDER_ITEM(node->data);
|
|
|
|
|
|
|
|
if (g_node_depth(node) > 0) {
|
|
|
|
if (fitem->op_count > 0) {
|
|
|
|
fitem->op_count = 0;
|
2002-11-09 17:35:13 +01:00
|
|
|
folder_update_item(fitem, FALSE);
|
2001-07-31 08:17:48 +02:00
|
|
|
}
|
|
|
|
if (node->children) {
|
|
|
|
GNode *child;
|
|
|
|
|
|
|
|
child = node->children;
|
|
|
|
while (child) {
|
|
|
|
GNode *cur;
|
|
|
|
|
|
|
|
cur = child;
|
|
|
|
child = cur->next;
|
|
|
|
folder_update_op_count_rec(cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_update_op_count() {
|
|
|
|
GList *cur;
|
|
|
|
Folder *folder;
|
|
|
|
|
|
|
|
for (cur = folder_list; cur != NULL; cur = cur->next) {
|
|
|
|
folder = cur->data;
|
|
|
|
folder_update_op_count_rec(folder->node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-29 02:29:13 +02:00
|
|
|
typedef struct _type_str {
|
|
|
|
gchar * str;
|
|
|
|
gint type;
|
|
|
|
} type_str;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2001-12-05 23:09:25 +01:00
|
|
|
/* CLAWS: temporary local folder for filtering */
|
|
|
|
static Folder *processing_folder;
|
|
|
|
static FolderItem *processing_folder_item;
|
|
|
|
|
|
|
|
static void folder_create_processing_folder(void)
|
|
|
|
{
|
|
|
|
#define PROCESSING_FOLDER ".processing"
|
|
|
|
Folder *tmpparent;
|
|
|
|
gchar *tmpname;
|
|
|
|
|
|
|
|
tmpparent = folder_get_default_folder();
|
|
|
|
g_assert(tmpparent);
|
|
|
|
debug_print("tmpparentroot %s\n", LOCAL_FOLDER(tmpparent)->rootpath);
|
2001-12-08 18:41:56 +01:00
|
|
|
if (LOCAL_FOLDER(tmpparent)->rootpath[0] == '/')
|
|
|
|
tmpname = g_strconcat(LOCAL_FOLDER(tmpparent)->rootpath,
|
|
|
|
G_DIR_SEPARATOR_S, PROCESSING_FOLDER,
|
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
tmpname = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
|
|
|
|
LOCAL_FOLDER(tmpparent)->rootpath,
|
|
|
|
G_DIR_SEPARATOR_S, PROCESSING_FOLDER,
|
|
|
|
NULL);
|
2001-12-05 23:09:25 +01:00
|
|
|
|
|
|
|
processing_folder = folder_new(F_MH, "PROCESSING", LOCAL_FOLDER(tmpparent)->rootpath);
|
|
|
|
g_assert(processing_folder);
|
2001-12-08 18:41:56 +01:00
|
|
|
|
2001-12-05 23:09:25 +01:00
|
|
|
if (!is_dir_exist(tmpname)) {
|
|
|
|
debug_print("*TMP* creating %s\n", tmpname);
|
|
|
|
processing_folder_item = processing_folder->create_folder(processing_folder,
|
|
|
|
processing_folder->node->data,
|
|
|
|
PROCESSING_FOLDER);
|
|
|
|
g_assert(processing_folder_item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
debug_print("*TMP* already created\n");
|
2002-07-25 23:09:10 +02:00
|
|
|
processing_folder_item = folder_item_new(processing_folder, ".processing", ".processing");
|
2001-12-05 23:09:25 +01:00
|
|
|
g_assert(processing_folder_item);
|
|
|
|
folder_item_append(processing_folder->node->data, processing_folder_item);
|
|
|
|
}
|
|
|
|
g_free(tmpname);
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderItem *folder_get_default_processing(void)
|
|
|
|
{
|
|
|
|
if (!processing_folder_item) {
|
|
|
|
folder_create_processing_folder();
|
|
|
|
}
|
|
|
|
return processing_folder_item;
|
|
|
|
}
|
|
|
|
|
2001-12-30 02:27:14 +01:00
|
|
|
/* folder_persist_prefs_new() - return hash table with persistent
|
|
|
|
* settings (and folder name as key).
|
|
|
|
* (note that in claws other options are in the PREFS_FOLDER_ITEM_RC
|
|
|
|
* file, so those don't need to be included in PersistPref yet)
|
|
|
|
*/
|
|
|
|
GHashTable *folder_persist_prefs_new(Folder *folder)
|
|
|
|
{
|
|
|
|
GHashTable *pptable;
|
|
|
|
|
|
|
|
g_return_val_if_fail(folder, NULL);
|
|
|
|
pptable = g_hash_table_new(g_str_hash, g_str_equal);
|
|
|
|
folder_get_persist_prefs_recursive(folder->node, pptable);
|
|
|
|
return pptable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_persist_prefs_free(GHashTable *pptable)
|
|
|
|
{
|
|
|
|
g_return_if_fail(pptable);
|
|
|
|
g_hash_table_foreach_remove(pptable, persist_prefs_free, NULL);
|
|
|
|
g_hash_table_destroy(pptable);
|
|
|
|
}
|
|
|
|
|
|
|
|
const PersistPrefs *folder_get_persist_prefs(GHashTable *pptable, const char *name)
|
|
|
|
{
|
|
|
|
if (pptable == NULL || name == NULL) return NULL;
|
|
|
|
return g_hash_table_lookup(pptable, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_restore_persist_prefs(FolderItem *item, GHashTable *pptable)
|
|
|
|
{
|
|
|
|
const PersistPrefs *pp;
|
2002-07-26 23:45:22 +02:00
|
|
|
gchar *id = folder_item_get_identifier(item);
|
|
|
|
|
|
|
|
pp = folder_get_persist_prefs(pptable, id);
|
|
|
|
g_free(id);
|
2001-12-30 02:27:14 +01:00
|
|
|
|
|
|
|
if (!pp) return;
|
|
|
|
|
|
|
|
/* CLAWS: since not all folder properties have been migrated to
|
|
|
|
* folderlist.xml, we need to call the old stuff first before
|
|
|
|
* setting things that apply both to Main and Claws. */
|
|
|
|
prefs_folder_item_read_config(item);
|
|
|
|
|
|
|
|
item->collapsed = pp->collapsed;
|
|
|
|
item->threaded = pp->threaded;
|
|
|
|
item->ret_rcpt = pp->ret_rcpt;
|
|
|
|
item->hide_read_msgs = pp->hide_read_msgs;
|
2002-06-16 20:16:57 +02:00
|
|
|
item->sort_key = pp->sort_key;
|
|
|
|
item->sort_type = pp->sort_type;
|
2001-12-30 02:27:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void folder_get_persist_prefs_recursive(GNode *node, GHashTable *pptable)
|
|
|
|
{
|
|
|
|
FolderItem *item = FOLDER_ITEM(node->data);
|
|
|
|
PersistPrefs *pp;
|
|
|
|
GNode *child, *cur;
|
2002-07-26 22:24:58 +02:00
|
|
|
gchar *id;
|
2001-12-30 02:27:14 +01:00
|
|
|
|
|
|
|
g_return_if_fail(node != NULL);
|
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
|
2002-07-26 22:24:58 +02:00
|
|
|
/* NOTE: item->path == NULL means top level folder; not interesting
|
|
|
|
* to store preferences of that one. */
|
2001-12-30 02:27:14 +01:00
|
|
|
if (item->path) {
|
2002-07-26 22:24:58 +02:00
|
|
|
id = folder_item_get_identifier(item);
|
2001-12-30 02:27:14 +01:00
|
|
|
pp = g_new0(PersistPrefs, 1);
|
|
|
|
g_return_if_fail(pp != NULL);
|
|
|
|
pp->collapsed = item->collapsed;
|
|
|
|
pp->threaded = item->threaded;
|
|
|
|
pp->ret_rcpt = item->ret_rcpt;
|
|
|
|
pp->hide_read_msgs = item->hide_read_msgs;
|
2002-06-16 20:16:57 +02:00
|
|
|
pp->sort_key = item->sort_key;
|
|
|
|
pp->sort_type = item->sort_type;
|
2002-07-26 22:24:58 +02:00
|
|
|
g_hash_table_insert(pptable, id, pp);
|
|
|
|
}
|
2001-12-30 02:27:14 +01:00
|
|
|
|
|
|
|
if (node->children) {
|
|
|
|
child = node->children;
|
|
|
|
while (child) {
|
|
|
|
cur = child;
|
|
|
|
child = cur->next;
|
|
|
|
folder_get_persist_prefs_recursive(cur, pptable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean persist_prefs_free(gpointer key, gpointer val, gpointer data)
|
|
|
|
{
|
2002-07-03 21:51:14 +02:00
|
|
|
if (key)
|
|
|
|
g_free(key);
|
2001-12-30 02:27:14 +01:00
|
|
|
if (val)
|
|
|
|
g_free(val);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-07-23 20:18:21 +02:00
|
|
|
void folder_item_apply_processing(FolderItem *item)
|
|
|
|
{
|
|
|
|
GSList *processing_list;
|
|
|
|
GSList *mlist, *cur;
|
|
|
|
|
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
|
|
|
|
processing_list = item->prefs->processing;
|
|
|
|
if (processing_list == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mlist = folder_item_get_msg_list(item);
|
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
for (cur = mlist ; cur != NULL ; cur = cur->next) {
|
2002-07-23 20:18:21 +02:00
|
|
|
MsgInfo * msginfo;
|
|
|
|
|
|
|
|
msginfo = (MsgInfo *) cur->data;
|
2002-10-10 20:21:11 +02:00
|
|
|
filter_message_by_msginfo(processing_list, msginfo);
|
2002-07-23 20:18:21 +02:00
|
|
|
procmsg_msginfo_free(msginfo);
|
|
|
|
}
|
|
|
|
|
2002-11-09 17:35:13 +01:00
|
|
|
folder_update_items_when_required(FALSE);
|
2002-07-23 20:18:21 +02:00
|
|
|
|
|
|
|
g_slist_free(mlist);
|
|
|
|
}
|
2002-11-09 17:35:13 +01:00
|
|
|
|
|
|
|
GSList *folder_item_update_callbacks_list = NULL;
|
|
|
|
gint folder_item_update_callbacks_nextid = 0;
|
|
|
|
|
|
|
|
struct FolderItemUpdateCallback
|
|
|
|
{
|
|
|
|
gint id;
|
|
|
|
FolderItemUpdateFunc func;
|
|
|
|
gpointer data;
|
|
|
|
};
|
|
|
|
|
|
|
|
gint folder_item_update_callback_register(FolderItemUpdateFunc func, gpointer data)
|
|
|
|
{
|
|
|
|
struct FolderItemUpdateCallback *callback;
|
|
|
|
|
|
|
|
g_return_val_if_fail(func != NULL, -1);
|
|
|
|
|
|
|
|
folder_item_update_callbacks_nextid++;
|
|
|
|
|
|
|
|
callback = g_new0(struct FolderItemUpdateCallback, 1);
|
|
|
|
callback->id = folder_item_update_callbacks_nextid;
|
|
|
|
callback->func = func;
|
|
|
|
callback->data = data;
|
|
|
|
|
|
|
|
folder_item_update_callbacks_list =
|
|
|
|
g_slist_append(folder_item_update_callbacks_list, callback);
|
|
|
|
|
|
|
|
return folder_item_update_callbacks_nextid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_update_callback_unregister(gint id)
|
|
|
|
{
|
|
|
|
GSList *list, *next;
|
|
|
|
|
|
|
|
for (list = folder_item_update_callbacks_list; list != NULL; list = next) {
|
|
|
|
struct FolderItemUpdateCallback *callback;
|
|
|
|
|
|
|
|
next = list->next;
|
|
|
|
|
|
|
|
callback = list->data;
|
|
|
|
if (callback->id == id) {
|
|
|
|
folder_item_update_callbacks_list =
|
|
|
|
g_slist_remove(folder_item_update_callbacks_list, callback);
|
|
|
|
g_free(callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void folder_item_update_callback_execute(FolderItem *item, gboolean contentchange)
|
|
|
|
{
|
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
for (list = folder_item_update_callbacks_list; list != NULL; list = list->next) {
|
|
|
|
struct FolderItemUpdateCallback *callback;
|
|
|
|
|
|
|
|
callback = list->data;
|
|
|
|
callback->func(item, contentchange, callback->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_update_item(FolderItem *item, gboolean contentchange)
|
|
|
|
{
|
|
|
|
folder_item_update_callback_execute(item, contentchange);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void folder_update_item_func(FolderItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
gboolean contentchange = GPOINTER_TO_INT(data);
|
|
|
|
|
|
|
|
if (item->need_update) {
|
|
|
|
folder_item_update_callback_execute(item, contentchange);
|
|
|
|
item->need_update = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_update_items_when_required(gboolean contentchange)
|
|
|
|
{
|
|
|
|
folder_func_to_all_folders(folder_update_item_func, GINT_TO_POINTER(contentchange));
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_update_item_recursive(FolderItem *item, gboolean update_summary)
|
|
|
|
{
|
|
|
|
GNode *node = item->folder->node;
|
|
|
|
node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
|
|
|
|
node = node->children;
|
|
|
|
folder_item_update_callback_execute(item, update_summary);
|
|
|
|
while (node != NULL) {
|
|
|
|
if (node && node->data) {
|
|
|
|
FolderItem *next_item = (FolderItem*) node->data;
|
|
|
|
folder_item_update_callback_execute(next_item, update_summary);
|
|
|
|
}
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
}
|