2001-04-19 14:21:46 +02:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2009-01-09 18:47:23 +01:00
|
|
|
* Copyright (C) 1999-2009 Hiroyuki Yamamoto and the Claws Mail team
|
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
|
2007-07-11 18:38:12 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-04-19 14:21:46 +02:00
|
|
|
* (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
|
2007-07-11 18:38:12 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2001-04-19 14:21:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
2005-02-10 13:06:07 +01:00
|
|
|
#include <glib/gi18n.h>
|
2001-04-19 14:21:46 +02:00
|
|
|
#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>
|
2005-12-20 18:43:40 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <w32lib.h>
|
|
|
|
#endif
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
#include "folder.h"
|
|
|
|
#include "session.h"
|
2005-06-13 21:37:01 +02:00
|
|
|
#include "inc.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
#include "imap.h"
|
|
|
|
#include "news.h"
|
|
|
|
#include "mh.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "xml.h"
|
|
|
|
#include "codeconv.h"
|
2002-12-25 14:46:41 +01:00
|
|
|
#include "prefs_gtk.h"
|
2001-04-19 14:21:46 +02:00
|
|
|
#include "account.h"
|
2002-07-02 21:49:11 +02:00
|
|
|
#include "filtering.h"
|
2002-06-30 01:33:42 +02:00
|
|
|
#include "procheader.h"
|
2002-12-02 22:50:19 +01:00
|
|
|
#include "hooks.h"
|
2002-12-11 01:56:36 +01:00
|
|
|
#include "log.h"
|
2003-07-20 03:15:54 +02:00
|
|
|
#include "folder_item_prefs.h"
|
2004-01-12 22:28:31 +01:00
|
|
|
#include "remotefolder.h"
|
2004-07-14 12:01:29 +02:00
|
|
|
#include "partial_download.h"
|
2005-06-15 04:19:15 +02:00
|
|
|
#include "statusbar.h"
|
2006-05-24 20:02:15 +02:00
|
|
|
#include "gtkutils.h"
|
2006-05-23 19:42:52 +02:00
|
|
|
#include "timing.h"
|
2006-06-12 19:08:19 +02:00
|
|
|
#include "compose.h"
|
2007-05-15 20:45:52 +02:00
|
|
|
#include "main.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"
|
|
|
|
|
2005-12-20 18:43:40 +01:00
|
|
|
/* Define possible missing constants for Windows. */
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
# ifndef S_IRGRP
|
|
|
|
# define S_IRGRP 0
|
|
|
|
# define S_IWGRP 0
|
|
|
|
# endif
|
|
|
|
# ifndef S_IROTH
|
|
|
|
# define S_IROTH 0
|
|
|
|
# define S_IWOTH 0
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
static GList *folder_list = NULL;
|
2004-02-21 12:01:01 +01:00
|
|
|
static GSList *class_list = NULL;
|
|
|
|
static GSList *folder_unloaded_list = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
void folder_init (Folder *folder,
|
2001-04-19 14:21:46 +02:00
|
|
|
const gchar *name);
|
|
|
|
|
2007-01-21 13:16:52 +01:00
|
|
|
static gchar *folder_item_get_cache_file (FolderItem *item);
|
|
|
|
static gchar *folder_item_get_mark_file (FolderItem *item);
|
2007-07-02 18:35:40 +02:00
|
|
|
static gchar *folder_item_get_tags_file (FolderItem *item);
|
2001-04-19 14:21:46 +02:00
|
|
|
static gchar *folder_get_list_path (void);
|
2004-02-21 12:01:01 +01:00
|
|
|
static GNode *folder_get_xml_node (Folder *folder);
|
|
|
|
static Folder *folder_get_from_xml (GNode *node);
|
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);
|
2007-01-20 20:54:05 +01:00
|
|
|
static void folder_item_read_cache (FolderItem *item);
|
2003-06-18 16:01:40 +02:00
|
|
|
gint folder_item_scan_full (FolderItem *item, gboolean filtering);
|
2004-06-25 10:05:09 +02:00
|
|
|
static void folder_item_update_with_msg (FolderItem *item, FolderItemUpdateFlags update_flags,
|
|
|
|
MsgInfo *msg);
|
2007-01-21 13:16:52 +01:00
|
|
|
static GHashTable *folder_persist_prefs_new (Folder *folder);
|
|
|
|
static void folder_persist_prefs_free (GHashTable *pptable);
|
|
|
|
static void folder_item_restore_persist_prefs (FolderItem *item, GHashTable *pptable);
|
|
|
|
|
2003-05-13 13:54:19 +02:00
|
|
|
void folder_system_init(void)
|
2003-03-12 23:23:54 +01:00
|
|
|
{
|
|
|
|
folder_register_class(mh_get_class());
|
|
|
|
folder_register_class(imap_get_class());
|
|
|
|
folder_register_class(news_get_class());
|
|
|
|
}
|
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static GSList *folder_get_class_list(void)
|
2003-03-12 23:23:54 +01:00
|
|
|
{
|
2004-02-21 12:01:01 +01:00
|
|
|
return class_list;
|
2003-03-12 23:23:54 +01:00
|
|
|
}
|
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
void folder_register_class(FolderClass *klass)
|
2003-03-12 23:23:54 +01:00
|
|
|
{
|
2004-02-21 12:01:01 +01:00
|
|
|
GSList *xmllist, *cur;
|
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
debug_print("registering folder class %s\n", klass->idstr);
|
2004-02-21 12:01:01 +01:00
|
|
|
|
|
|
|
class_list = g_slist_append(class_list, klass);
|
|
|
|
|
|
|
|
xmllist = g_slist_copy(folder_unloaded_list);
|
|
|
|
for (cur = xmllist; cur != NULL; cur = g_slist_next(cur)) {
|
|
|
|
GNode *node = (GNode *) cur->data;
|
|
|
|
XMLNode *xmlnode = (XMLNode *) node->data;
|
|
|
|
GList *cur = xmlnode->tag->attr;
|
|
|
|
|
|
|
|
for (; cur != NULL; cur = g_list_next(cur)) {
|
|
|
|
XMLAttr *attr = (XMLAttr *) cur->data;
|
|
|
|
|
|
|
|
if (!attr || !attr->name || !attr->value) continue;
|
|
|
|
if (!strcmp(attr->name, "type") && !strcmp(attr->value, klass->idstr)) {
|
|
|
|
Folder *folder;
|
|
|
|
|
|
|
|
folder = folder_get_from_xml(node);
|
2008-03-01 14:48:34 +01:00
|
|
|
if (folder) {
|
|
|
|
folder_add(folder);
|
|
|
|
folder_unloaded_list = g_slist_remove(folder_unloaded_list, node);
|
|
|
|
}
|
2004-02-21 12:01:01 +01:00
|
|
|
cur = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_slist_free(xmllist);
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_unregister_class(FolderClass *klass)
|
|
|
|
{
|
|
|
|
GList *folderlist, *cur;
|
|
|
|
|
|
|
|
debug_print("unregistering folder class %s\n", klass->idstr);
|
|
|
|
|
|
|
|
class_list = g_slist_remove(class_list, klass);
|
|
|
|
|
|
|
|
folderlist = g_list_copy(folder_get_list());
|
|
|
|
for (cur = folderlist; cur != NULL; cur = g_list_next(cur)) {
|
|
|
|
Folder *folder = (Folder *) cur->data;
|
|
|
|
|
|
|
|
if (folder->klass == klass) {
|
|
|
|
GNode *xmlnode = folder_get_xml_node(folder);
|
|
|
|
folder_unloaded_list = g_slist_append(folder_unloaded_list, xmlnode);
|
|
|
|
folder_destroy(folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free(folderlist);
|
2003-03-12 23:23:54 +01:00
|
|
|
}
|
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
Folder *folder_new(FolderClass *klass, const gchar *name, const gchar *path)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
Folder *folder = NULL;
|
2002-10-14 23:23:12 +02:00
|
|
|
FolderItem *item;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(klass != NULL, NULL);
|
2003-03-13 16:31:22 +01:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
name = name ? name : path;
|
2003-04-05 22:38:53 +02:00
|
|
|
folder = klass->new_folder(name, path);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-10-14 23:23:12 +02:00
|
|
|
/* Create root folder item */
|
|
|
|
item = folder_item_new(folder, name, NULL);
|
2005-07-06 20:22:55 +02:00
|
|
|
if (item == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-10-14 23:23:12 +02:00
|
|
|
item->folder = folder;
|
2003-08-25 16:14:47 +02:00
|
|
|
folder->node = item->node = g_node_new(item);
|
2002-10-14 23:23:12 +02:00
|
|
|
folder->data = NULL;
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
void folder_init(Folder *folder, const gchar *name)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_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;
|
2004-05-10 12:22:28 +02:00
|
|
|
folder->sort = 0;
|
2002-01-16 12:48:36 +01:00
|
|
|
folder->inbox = NULL;
|
|
|
|
folder->outbox = NULL;
|
|
|
|
folder->draft = NULL;
|
|
|
|
folder->queue = NULL;
|
|
|
|
folder->trash = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2006-06-12 19:08:19 +02:00
|
|
|
static void reset_parent_type(FolderItem *item, gpointer data) {
|
|
|
|
item->parent_stype = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_change_type(FolderItem *item, SpecialFolderItemType newtype)
|
|
|
|
{
|
|
|
|
Folder *folder = NULL;
|
|
|
|
FolderUpdateData hookdata;
|
|
|
|
|
2007-07-17 18:42:31 +02:00
|
|
|
if (item == NULL)
|
|
|
|
return;
|
|
|
|
|
2006-06-12 19:08:19 +02:00
|
|
|
folder = item->folder;
|
|
|
|
/* unset previous root of newtype */
|
|
|
|
switch(newtype) {
|
|
|
|
case F_INBOX:
|
|
|
|
folder_item_change_type(folder->inbox, F_NORMAL);
|
|
|
|
folder->inbox = item;
|
|
|
|
break;
|
|
|
|
case F_OUTBOX:
|
|
|
|
folder_item_change_type(folder->outbox, F_NORMAL);
|
|
|
|
folder->outbox = item;
|
|
|
|
break;
|
|
|
|
case F_QUEUE:
|
|
|
|
folder_item_change_type(folder->queue, F_NORMAL);
|
|
|
|
folder->queue = item;
|
|
|
|
break;
|
|
|
|
case F_DRAFT:
|
|
|
|
folder_item_change_type(folder->draft, F_NORMAL);
|
|
|
|
folder->draft = item;
|
|
|
|
break;
|
|
|
|
case F_TRASH:
|
|
|
|
folder_item_change_type(folder->trash, F_NORMAL);
|
|
|
|
folder->trash = item;
|
|
|
|
break;
|
|
|
|
case F_NORMAL:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* set new type for current folder and sons */
|
|
|
|
item->stype = newtype;
|
|
|
|
folder_func_to_all_folders(reset_parent_type, NULL);
|
|
|
|
|
|
|
|
hookdata.folder = folder;
|
|
|
|
hookdata.update_flags = FOLDER_TREE_CHANGED;
|
|
|
|
hookdata.item = NULL;
|
|
|
|
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
|
|
|
|
}
|
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
void folder_destroy(Folder *folder)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(folder != NULL);
|
|
|
|
cm_return_if_fail(folder->klass->destroy_folder != NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
folder_remove(folder);
|
2004-02-21 12:01:01 +01:00
|
|
|
|
2002-01-16 12:48:36 +01:00
|
|
|
folder_tree_destroy(folder);
|
2003-03-12 16:40:51 +01:00
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
folder->klass->destroy_folder(folder);
|
2003-04-09 20:24:52 +02:00
|
|
|
|
|
|
|
g_free(folder->name);
|
|
|
|
g_free(folder);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
void folder_set_xml(Folder *folder, XMLTag *tag)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2004-01-12 22:28:31 +01:00
|
|
|
GList *cur;
|
2004-02-21 12:01:01 +01:00
|
|
|
FolderItem *rootitem = NULL;
|
|
|
|
|
|
|
|
if ((folder->node != NULL) && (folder->node->data != NULL))
|
|
|
|
rootitem = (FolderItem *) folder->node->data;
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
for (cur = tag->attr; cur != NULL; cur = g_list_next(cur)) {
|
|
|
|
XMLAttr *attr = (XMLAttr *) cur->data;
|
|
|
|
|
|
|
|
if (!attr || !attr->name || !attr->value) continue;
|
|
|
|
if (!strcmp(attr->name, "name")) {
|
2006-04-06 12:58:17 +02:00
|
|
|
g_free(folder->name);
|
2004-01-12 22:28:31 +01:00
|
|
|
folder->name = g_strdup(attr->value);
|
2004-02-21 12:01:01 +01:00
|
|
|
if (rootitem != NULL) {
|
2006-04-06 12:58:17 +02:00
|
|
|
g_free(rootitem->name);
|
2004-02-21 12:01:01 +01:00
|
|
|
rootitem->name = g_strdup(attr->value);
|
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
} else if (!strcmp(attr->name, "account_id")) {
|
|
|
|
PrefsAccount *account;
|
2002-01-16 12:48:36 +01:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
account = account_find_from_id(atoi(attr->value));
|
|
|
|
if (!account)
|
|
|
|
g_warning("account_id: %s not found\n", attr->value);
|
|
|
|
else {
|
|
|
|
folder->account = account;
|
|
|
|
account->folder = folder;
|
|
|
|
}
|
2004-02-21 12:01:01 +01:00
|
|
|
} else if (!strcmp(attr->name, "collapsed")) {
|
|
|
|
if (rootitem != NULL)
|
|
|
|
rootitem->collapsed = *attr->value == '1' ? TRUE : FALSE;
|
2004-05-10 12:22:28 +02:00
|
|
|
} else if (!strcmp(attr->name, "sort")) {
|
|
|
|
folder->sort = atoi(attr->value);
|
2004-01-12 22:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
2002-01-16 12:48:36 +01:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
XMLTag *folder_get_xml(Folder *folder)
|
2002-01-16 12:48:36 +01:00
|
|
|
{
|
2004-01-12 22:28:31 +01:00
|
|
|
XMLTag *tag;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-08-06 13:34:34 +02:00
|
|
|
tag = xml_tag_new("folder");
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
if (folder->name)
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("name", folder->name));
|
2004-01-12 22:28:31 +01:00
|
|
|
if (folder->account)
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("account_id", folder->account->account_id));
|
2004-02-21 12:01:01 +01:00
|
|
|
if (folder->node && folder->node->data) {
|
|
|
|
FolderItem *rootitem = (FolderItem *) folder->node->data;
|
|
|
|
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("collapsed", rootitem->collapsed ? "1" : "0"));
|
2004-02-21 12:01:01 +01:00
|
|
|
}
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("sort", folder->sort));
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
return tag;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2005-07-06 20:22:55 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder != NULL, NULL);
|
2005-07-06 20:22:55 +02:00
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
if (folder->klass->item_new) {
|
|
|
|
item = folder->klass->item_new(folder);
|
2002-10-14 23:23:12 +02:00
|
|
|
} else {
|
2002-07-25 23:09:10 +02:00
|
|
|
item = g_new0(FolderItem, 1);
|
|
|
|
}
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_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;
|
2003-04-05 22:38:53 +02:00
|
|
|
item->new_msgs = 0;
|
|
|
|
item->unread_msgs = 0;
|
|
|
|
item->unreadmarked_msgs = 0;
|
2005-07-01 19:33:02 +02:00
|
|
|
item->marked_msgs = 0;
|
2003-04-05 22:38:53 +02:00
|
|
|
item->total_msgs = 0;
|
2008-03-12 07:22:29 +01:00
|
|
|
item->replied_msgs = 0;
|
|
|
|
item->forwarded_msgs = 0;
|
|
|
|
item->locked_msgs = 0;
|
|
|
|
item->ignored_msgs = 0;
|
|
|
|
item->watched_msgs = 0;
|
2007-03-28 21:51:06 +02:00
|
|
|
item->order = 0;
|
2001-04-19 14:21:46 +02:00
|
|
|
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;
|
2003-01-25 02:30:03 +01:00
|
|
|
item->thread_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;
|
2004-05-10 12:22:28 +02:00
|
|
|
item->node = g_node_new(item);
|
2001-04-19 14:21:46 +02:00
|
|
|
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;
|
2005-08-10 08:20:49 +02:00
|
|
|
item->parent_stype = -1;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-10-03 19:50:14 +02:00
|
|
|
item->sort_key = SORT_BY_DATE;
|
|
|
|
item->sort_type = SORT_ASCENDING;
|
|
|
|
|
2003-07-20 03:15:54 +02:00
|
|
|
item->prefs = folder_item_prefs_new();
|
2001-05-06 06:27:28 +02:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_append(FolderItem *parent, FolderItem *item)
|
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(parent != NULL);
|
|
|
|
cm_return_if_fail(parent->folder != NULL);
|
|
|
|
cm_return_if_fail(parent->node != NULL);
|
|
|
|
cm_return_if_fail(item != NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
item->folder = parent->folder;
|
2004-05-10 12:22:28 +02:00
|
|
|
g_node_append(parent->node, item->node);
|
2003-08-25 16:14:47 +02:00
|
|
|
}
|
|
|
|
|
2005-08-20 20:21:39 +02:00
|
|
|
void folder_item_remove(FolderItem *item)
|
2003-08-25 16:14:47 +02:00
|
|
|
{
|
2005-08-20 20:21:39 +02:00
|
|
|
GNode *node, *start_node;
|
2003-09-08 12:33:11 +02:00
|
|
|
FolderUpdateData hookdata;
|
2008-04-28 08:37:42 +02:00
|
|
|
gchar *tags_file = NULL;
|
2003-08-25 16:14:47 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(item != NULL);
|
|
|
|
cm_return_if_fail(item->folder != NULL);
|
|
|
|
cm_return_if_fail(item->folder->node != NULL);
|
2005-08-20 20:21:39 +02:00
|
|
|
|
|
|
|
start_node = node = item->node;
|
|
|
|
|
|
|
|
node = item->folder->node;
|
|
|
|
|
|
|
|
node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
|
|
|
|
node = node->children;
|
|
|
|
|
|
|
|
/* remove my children */
|
|
|
|
while (node != NULL) {
|
|
|
|
if (node && node->data) {
|
|
|
|
FolderItem *sub_item = (FolderItem*) node->data;
|
|
|
|
node = node->next;
|
|
|
|
folder_item_remove(sub_item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove myself */
|
2003-09-06 20:52:29 +02:00
|
|
|
if (item->cache != NULL) {
|
|
|
|
msgcache_destroy(item->cache);
|
|
|
|
item->cache = NULL;
|
|
|
|
}
|
2008-04-28 08:37:42 +02:00
|
|
|
tags_file = folder_item_get_tags_file(item);
|
|
|
|
if (tags_file)
|
|
|
|
claws_unlink(tags_file);
|
|
|
|
g_free(tags_file);
|
2003-09-06 20:52:29 +02:00
|
|
|
|
2003-09-08 13:41:03 +02:00
|
|
|
hookdata.folder = item->folder;
|
2003-09-08 12:33:11 +02:00
|
|
|
hookdata.update_flags = FOLDER_TREE_CHANGED | FOLDER_REMOVE_FOLDERITEM;
|
|
|
|
hookdata.item = item;
|
|
|
|
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
|
|
|
|
|
2005-08-20 20:21:39 +02:00
|
|
|
node = start_node;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
if (item->folder->node == node)
|
|
|
|
item->folder->node = NULL;
|
2003-08-25 16:14:47 +02:00
|
|
|
|
2005-08-20 20:21:39 +02:00
|
|
|
folder_item_destroy(item);
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
g_node_destroy(node);
|
|
|
|
}
|
|
|
|
|
2003-08-26 09:13:40 +02:00
|
|
|
void folder_item_remove_children(FolderItem *item)
|
|
|
|
{
|
|
|
|
GNode *node, *next;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(item != NULL);
|
|
|
|
cm_return_if_fail(item->folder != NULL);
|
|
|
|
cm_return_if_fail(item->node != NULL);
|
2003-08-26 09:13:40 +02:00
|
|
|
|
|
|
|
node = item->node->children;
|
|
|
|
while (node != NULL) {
|
|
|
|
next = node->next;
|
|
|
|
folder_item_remove(FOLDER_ITEM(node->data));
|
|
|
|
node = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-01 10:37:50 +02:00
|
|
|
void folder_item_destroy(FolderItem *item)
|
|
|
|
{
|
2003-08-25 16:14:47 +02:00
|
|
|
Folder *folder;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(item != NULL);
|
2001-07-01 10:37:50 +02:00
|
|
|
|
2003-08-25 16:14:47 +02:00
|
|
|
folder = item->folder;
|
|
|
|
if (folder) {
|
|
|
|
if (folder->inbox == item)
|
|
|
|
folder->inbox = NULL;
|
|
|
|
else if (folder->outbox == item)
|
|
|
|
folder->outbox = NULL;
|
|
|
|
else if (folder->draft == item)
|
|
|
|
folder->draft = NULL;
|
|
|
|
else if (folder->queue == item)
|
|
|
|
folder->queue = NULL;
|
|
|
|
else if (folder->trash == item)
|
|
|
|
folder->trash = NULL;
|
|
|
|
}
|
2002-07-25 23:09:10 +02:00
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->cache)
|
2006-06-09 16:48:49 +02:00
|
|
|
folder_item_free_cache(item, TRUE);
|
2003-09-09 21:56:37 +02:00
|
|
|
if (item->prefs)
|
|
|
|
folder_item_prefs_free(item->prefs);
|
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) {
|
2003-04-05 22:38:53 +02:00
|
|
|
if(item->folder->klass->item_destroy) {
|
|
|
|
item->folder->klass->item_destroy(item->folder, item);
|
2002-10-14 23:23:12 +02:00
|
|
|
} else {
|
|
|
|
g_free(item);
|
|
|
|
}
|
|
|
|
}
|
2001-07-01 10:37:50 +02:00
|
|
|
}
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
FolderItem *folder_item_parent(FolderItem *item)
|
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
|
|
|
cm_return_val_if_fail(item->node != NULL, NULL);
|
2004-02-21 12:01:01 +01:00
|
|
|
|
|
|
|
if (item->node->parent == NULL)
|
|
|
|
return NULL;
|
|
|
|
return (FolderItem *) item->node->parent->data;
|
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
void folder_item_set_xml(Folder *folder, FolderItem *item, XMLTag *tag)
|
|
|
|
{
|
|
|
|
GList *cur;
|
|
|
|
|
|
|
|
for (cur = tag->attr; cur != NULL; cur = g_list_next(cur)) {
|
|
|
|
XMLAttr *attr = (XMLAttr *) cur->data;
|
|
|
|
|
|
|
|
if (!attr || !attr->name || !attr->value) continue;
|
|
|
|
if (!strcmp(attr->name, "type")) {
|
2004-10-26 12:43:50 +02:00
|
|
|
if (!g_ascii_strcasecmp(attr->value, "normal"))
|
2004-01-12 22:28:31 +01:00
|
|
|
item->stype = F_NORMAL;
|
2004-10-26 12:43:50 +02:00
|
|
|
else if (!g_ascii_strcasecmp(attr->value, "inbox"))
|
2004-01-12 22:28:31 +01:00
|
|
|
item->stype = F_INBOX;
|
2004-10-26 12:43:50 +02:00
|
|
|
else if (!g_ascii_strcasecmp(attr->value, "outbox"))
|
2004-01-12 22:28:31 +01:00
|
|
|
item->stype = F_OUTBOX;
|
2004-10-26 12:43:50 +02:00
|
|
|
else if (!g_ascii_strcasecmp(attr->value, "draft"))
|
2004-01-12 22:28:31 +01:00
|
|
|
item->stype = F_DRAFT;
|
2004-10-26 12:43:50 +02:00
|
|
|
else if (!g_ascii_strcasecmp(attr->value, "queue"))
|
2004-01-12 22:28:31 +01:00
|
|
|
item->stype = F_QUEUE;
|
2004-10-26 12:43:50 +02:00
|
|
|
else if (!g_ascii_strcasecmp(attr->value, "trash"))
|
2004-01-12 22:28:31 +01:00
|
|
|
item->stype = F_TRASH;
|
|
|
|
} else if (!strcmp(attr->name, "name")) {
|
2006-04-06 12:58:17 +02:00
|
|
|
g_free(item->name);
|
2004-01-12 22:28:31 +01:00
|
|
|
item->name = g_strdup(attr->value);
|
|
|
|
} else if (!strcmp(attr->name, "path")) {
|
2006-04-06 12:58:17 +02:00
|
|
|
g_free(item->path);
|
2004-01-12 22:28:31 +01:00
|
|
|
item->path = g_strdup(attr->value);
|
|
|
|
} else if (!strcmp(attr->name, "mtime"))
|
|
|
|
item->mtime = strtoul(attr->value, NULL, 10);
|
|
|
|
else if (!strcmp(attr->name, "new"))
|
|
|
|
item->new_msgs = atoi(attr->value);
|
|
|
|
else if (!strcmp(attr->name, "unread"))
|
|
|
|
item->unread_msgs = atoi(attr->value);
|
|
|
|
else if (!strcmp(attr->name, "unreadmarked"))
|
|
|
|
item->unreadmarked_msgs = atoi(attr->value);
|
2005-07-01 19:33:02 +02:00
|
|
|
else if (!strcmp(attr->name, "marked"))
|
|
|
|
item->marked_msgs = atoi(attr->value);
|
2008-03-12 07:22:29 +01:00
|
|
|
else if (!strcmp(attr->name, "replied"))
|
|
|
|
item->replied_msgs = atoi(attr->value);
|
|
|
|
else if (!strcmp(attr->name, "forwarded"))
|
|
|
|
item->forwarded_msgs = atoi(attr->value);
|
|
|
|
else if (!strcmp(attr->name, "locked"))
|
|
|
|
item->locked_msgs = atoi(attr->value);
|
|
|
|
else if (!strcmp(attr->name, "ignored"))
|
|
|
|
item->ignored_msgs = atoi(attr->value);
|
|
|
|
else if (!strcmp(attr->name, "watched"))
|
|
|
|
item->watched_msgs = atoi(attr->value);
|
2007-03-28 21:51:06 +02:00
|
|
|
else if (!strcmp(attr->name, "order"))
|
|
|
|
item->order = atoi(attr->value);
|
2004-01-12 22:28:31 +01:00
|
|
|
else if (!strcmp(attr->name, "total"))
|
|
|
|
item->total_msgs = atoi(attr->value);
|
|
|
|
else if (!strcmp(attr->name, "no_sub"))
|
|
|
|
item->no_sub = *attr->value == '1' ? TRUE : FALSE;
|
|
|
|
else if (!strcmp(attr->name, "no_select"))
|
|
|
|
item->no_select = *attr->value == '1' ? TRUE : FALSE;
|
|
|
|
else if (!strcmp(attr->name, "collapsed"))
|
|
|
|
item->collapsed = *attr->value == '1' ? TRUE : FALSE;
|
|
|
|
else if (!strcmp(attr->name, "thread_collapsed"))
|
|
|
|
item->thread_collapsed = *attr->value == '1' ? TRUE : FALSE;
|
|
|
|
else if (!strcmp(attr->name, "threaded"))
|
|
|
|
item->threaded = *attr->value == '1' ? TRUE : FALSE;
|
|
|
|
else if (!strcmp(attr->name, "hidereadmsgs"))
|
|
|
|
item->hide_read_msgs = *attr->value == '1' ? TRUE : FALSE;
|
2009-03-30 19:20:02 +02:00
|
|
|
else if (!strcmp(attr->name, "hidedelmsgs"))
|
|
|
|
item->hide_del_msgs = *attr->value == '1' ? TRUE : FALSE;
|
2004-01-12 22:28:31 +01:00
|
|
|
else if (!strcmp(attr->name, "reqretrcpt"))
|
|
|
|
item->ret_rcpt = *attr->value == '1' ? TRUE : FALSE;
|
|
|
|
else if (!strcmp(attr->name, "sort_key")) {
|
|
|
|
if (!strcmp(attr->value, "none"))
|
|
|
|
item->sort_key = SORT_BY_NONE;
|
|
|
|
else if (!strcmp(attr->value, "number"))
|
|
|
|
item->sort_key = SORT_BY_NUMBER;
|
|
|
|
else if (!strcmp(attr->value, "size"))
|
|
|
|
item->sort_key = SORT_BY_SIZE;
|
|
|
|
else if (!strcmp(attr->value, "date"))
|
|
|
|
item->sort_key = SORT_BY_DATE;
|
|
|
|
else if (!strcmp(attr->value, "from"))
|
|
|
|
item->sort_key = SORT_BY_FROM;
|
|
|
|
else if (!strcmp(attr->value, "subject"))
|
|
|
|
item->sort_key = SORT_BY_SUBJECT;
|
|
|
|
else if (!strcmp(attr->value, "score"))
|
|
|
|
item->sort_key = SORT_BY_SCORE;
|
|
|
|
else if (!strcmp(attr->value, "label"))
|
|
|
|
item->sort_key = SORT_BY_LABEL;
|
|
|
|
else if (!strcmp(attr->value, "mark"))
|
|
|
|
item->sort_key = SORT_BY_MARK;
|
|
|
|
else if (!strcmp(attr->value, "unread"))
|
|
|
|
item->sort_key = SORT_BY_STATUS;
|
|
|
|
else if (!strcmp(attr->value, "mime"))
|
|
|
|
item->sort_key = SORT_BY_MIME;
|
|
|
|
else if (!strcmp(attr->value, "to"))
|
|
|
|
item->sort_key = SORT_BY_TO;
|
|
|
|
else if (!strcmp(attr->value, "locked"))
|
|
|
|
item->sort_key = SORT_BY_LOCKED;
|
2007-07-03 19:25:25 +02:00
|
|
|
else if (!strcmp(attr->value, "tags"))
|
|
|
|
item->sort_key = SORT_BY_TAGS;
|
|
|
|
else if (!strcmp(attr->value, "thread_date"))
|
|
|
|
item->sort_key = SORT_BY_THREAD_DATE;
|
2004-01-12 22:28:31 +01:00
|
|
|
} else if (!strcmp(attr->name, "sort_type")) {
|
|
|
|
if (!strcmp(attr->value, "ascending"))
|
|
|
|
item->sort_type = SORT_ASCENDING;
|
|
|
|
else
|
|
|
|
item->sort_type = SORT_DESCENDING;
|
|
|
|
} else if (!strcmp(attr->name, "account_id")) {
|
|
|
|
PrefsAccount *account;
|
|
|
|
|
|
|
|
account = account_find_from_id(atoi(attr->value));
|
|
|
|
if (!account)
|
|
|
|
g_warning("account_id: %s not found\n", attr->value);
|
|
|
|
else
|
|
|
|
item->account = account;
|
2007-05-15 20:45:52 +02:00
|
|
|
} else if (!strcmp(attr->name, "apply_sub")) {
|
2004-01-12 22:28:31 +01:00
|
|
|
item->apply_sub = *attr->value == '1' ? TRUE : FALSE;
|
2007-05-15 20:45:52 +02:00
|
|
|
} else if (!strcmp(attr->name, "last_seen")) {
|
|
|
|
if (!claws_crashed())
|
|
|
|
item->last_seen = atoi(attr->value);
|
|
|
|
else
|
|
|
|
item->last_seen = 0;
|
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLTag *folder_item_get_xml(Folder *folder, FolderItem *item)
|
|
|
|
{
|
|
|
|
static gchar *folder_item_stype_str[] = {"normal", "inbox", "outbox",
|
|
|
|
"draft", "queue", "trash"};
|
|
|
|
static gchar *sort_key_str[] = {"none", "number", "size", "date",
|
|
|
|
"from", "subject", "score", "label",
|
|
|
|
"mark", "unread", "mime", "to",
|
2007-07-03 19:25:25 +02:00
|
|
|
"locked", "tags", "thread_date" };
|
2004-01-12 22:28:31 +01:00
|
|
|
XMLTag *tag;
|
2004-08-06 13:34:34 +02:00
|
|
|
gchar *value;
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2004-08-06 13:34:34 +02:00
|
|
|
tag = xml_tag_new("folderitem");
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("type", folder_item_stype_str[item->stype]));
|
2004-01-12 22:28:31 +01:00
|
|
|
if (item->name)
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("name", item->name));
|
2004-01-12 22:28:31 +01:00
|
|
|
if (item->path)
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("path", item->path));
|
2004-01-12 22:28:31 +01:00
|
|
|
if (item->no_sub)
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("no_sub", "1"));
|
2004-01-12 22:28:31 +01:00
|
|
|
if (item->no_select)
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("no_select", "1"));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new("collapsed", item->collapsed && item->node->children ? "1" : "0"));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new("thread_collapsed", item->thread_collapsed ? "1" : "0"));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new("threaded", item->threaded ? "1" : "0"));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new("hidereadmsgs", item->hide_read_msgs ? "1" : "0"));
|
2009-03-30 19:20:02 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("hidedelmsgs", item->hide_del_msgs ? "1" : "0"));
|
2004-01-12 22:28:31 +01:00
|
|
|
if (item->ret_rcpt)
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("reqretrcpt", "1"));
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
if (item->sort_key != SORT_BY_NONE) {
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("sort_key", sort_key_str[item->sort_key]));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new("sort_type", item->sort_type == SORT_ASCENDING ? "ascending" : "descending"));
|
2004-01-12 22:28:31 +01:00
|
|
|
}
|
|
|
|
|
2004-08-06 13:34:34 +02:00
|
|
|
value = g_strdup_printf("%ld", (unsigned long int) item->mtime);
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new("mtime", value));
|
|
|
|
g_free(value);
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("new", item->new_msgs));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("unread", item->unread_msgs));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("unreadmarked", item->unreadmarked_msgs));
|
2005-07-01 19:33:02 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("marked", item->marked_msgs));
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("total", item->total_msgs));
|
2008-03-12 07:22:29 +01:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("replied", item->replied_msgs));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("forwarded", item->forwarded_msgs));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("locked", item->locked_msgs));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("ignore", item->ignored_msgs));
|
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("watched", item->watched_msgs));
|
2007-03-28 21:51:06 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("order", item->order));
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
if (item->account)
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("account_id", item->account->account_id));
|
2004-01-12 22:28:31 +01:00
|
|
|
if (item->apply_sub)
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("apply_sub", "1"));
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2007-05-15 20:45:52 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new_int("last_seen", item->last_seen));
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
void folder_set_ui_func(Folder *folder, FolderUIFunc func, gpointer data)
|
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(folder != NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
folder->ui_func = func;
|
|
|
|
folder->ui_func_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_set_name(Folder *folder, const gchar *name)
|
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(folder != NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
void folder_set_sort(Folder *folder, guint sort)
|
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(folder != NULL);
|
2004-05-10 12:22:28 +02:00
|
|
|
|
|
|
|
if (folder->sort != sort) {
|
|
|
|
folder_remove(folder);
|
|
|
|
folder->sort = sort;
|
|
|
|
folder_add(folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static gboolean folder_tree_destroy_func(GNode *node, gpointer data) {
|
2002-06-30 18:35:20 +02:00
|
|
|
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)
|
|
|
|
{
|
2003-09-07 01:18:53 +02:00
|
|
|
GNode *node;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(folder != NULL);
|
2003-09-07 01:18:53 +02:00
|
|
|
|
|
|
|
node = folder->node;
|
2002-07-26 01:00:59 +02:00
|
|
|
|
2003-06-10 19:02:05 +02:00
|
|
|
prefs_filtering_clear_folder(folder);
|
2002-07-02 21:49:11 +02:00
|
|
|
|
2003-09-07 01:18:53 +02:00
|
|
|
if (node != NULL) {
|
|
|
|
g_node_traverse(node, G_POST_ORDER, G_TRAVERSE_ALL, -1,
|
|
|
|
folder_tree_destroy_func, NULL);
|
|
|
|
g_node_destroy(node);
|
|
|
|
folder->node = NULL;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void folder_add(Folder *folder)
|
|
|
|
{
|
|
|
|
Folder *cur_folder;
|
|
|
|
GList *cur;
|
|
|
|
gint i;
|
2004-02-21 12:01:01 +01:00
|
|
|
FolderUpdateData hookdata;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(folder != NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2008-03-01 14:48:34 +01:00
|
|
|
if ((FOLDER_TYPE(folder) == F_IMAP ||
|
|
|
|
FOLDER_TYPE(folder) == F_NEWS) &&
|
|
|
|
folder->account == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
for (i = 0, cur = folder_list; cur != NULL; cur = cur->next, i++) {
|
|
|
|
cur_folder = FOLDER(cur->data);
|
2004-05-10 12:22:28 +02:00
|
|
|
if (cur_folder->sort < folder->sort)
|
|
|
|
break;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
folder_list = g_list_insert(folder_list, folder, i);
|
2004-02-21 12:01:01 +01:00
|
|
|
|
|
|
|
hookdata.folder = folder;
|
2004-05-10 12:22:28 +02:00
|
|
|
hookdata.update_flags = FOLDER_ADD_FOLDER;
|
|
|
|
hookdata.item = NULL;
|
|
|
|
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_remove(Folder *folder)
|
|
|
|
{
|
|
|
|
FolderUpdateData hookdata;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(folder != NULL);
|
2004-05-10 12:22:28 +02:00
|
|
|
|
|
|
|
folder_list = g_list_remove(folder_list, folder);
|
|
|
|
|
|
|
|
hookdata.folder = folder;
|
|
|
|
hookdata.update_flags = FOLDER_REMOVE_FOLDER;
|
2004-02-21 12:01:01 +01:00
|
|
|
hookdata.item = NULL;
|
|
|
|
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GList *folder_get_list(void)
|
|
|
|
{
|
|
|
|
return folder_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint folder_read_list(void)
|
|
|
|
{
|
2004-02-21 12:01:01 +01:00
|
|
|
GNode *node, *cur;
|
2001-04-19 14:21:46 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
cur = node->children;
|
|
|
|
while (cur != NULL) {
|
|
|
|
Folder *folder;
|
|
|
|
|
|
|
|
folder = folder_get_from_xml(cur);
|
|
|
|
if (folder != NULL)
|
|
|
|
folder_add(folder);
|
|
|
|
else
|
|
|
|
folder_unloaded_list = g_slist_append(folder_unloaded_list,
|
|
|
|
(gpointer) xml_copy_tree(cur));
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
xml_free_tree(node);
|
2006-01-15 13:59:00 +01:00
|
|
|
if (folder_list || folder_unloaded_list)
|
2001-04-19 14:21:46 +02:00
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_write_list(void)
|
|
|
|
{
|
|
|
|
GList *list;
|
2004-02-21 12:01:01 +01:00
|
|
|
GSList *slist;
|
2001-04-19 14:21:46 +02:00
|
|
|
Folder *folder;
|
|
|
|
gchar *path;
|
|
|
|
PrefFile *pfile;
|
2004-02-21 12:01:01 +01:00
|
|
|
GNode *rootnode;
|
|
|
|
XMLNode *xmlnode;
|
|
|
|
XMLTag *tag;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
path = folder_get_list_path();
|
|
|
|
if ((pfile = prefs_write_open(path)) == NULL) return;
|
|
|
|
|
2007-01-24 18:56:39 +01:00
|
|
|
if (xml_file_put_xml_decl(pfile->fp) < 0) {
|
|
|
|
prefs_file_close_revert(pfile);
|
|
|
|
g_warning("failed to start write folder list.\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-08-06 13:34:34 +02:00
|
|
|
tag = xml_tag_new("folderlist");
|
2004-02-21 12:01:01 +01:00
|
|
|
|
2004-08-06 13:34:34 +02:00
|
|
|
xmlnode = xml_node_new(tag, NULL);
|
2004-02-21 12:01:01 +01:00
|
|
|
|
|
|
|
rootnode = g_node_new(xmlnode);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
for (list = folder_list; list != NULL; list = list->next) {
|
2004-02-21 12:01:01 +01:00
|
|
|
GNode *node;
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
folder = list->data;
|
2004-02-21 12:01:01 +01:00
|
|
|
node = folder_get_xml_node(folder);
|
|
|
|
if (node != NULL)
|
|
|
|
g_node_append(rootnode, node);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
for (slist = folder_unloaded_list; slist != NULL; slist = g_slist_next(slist)) {
|
|
|
|
GNode *node = (GNode *) slist->data;
|
|
|
|
|
|
|
|
g_node_append(rootnode, (gpointer) xml_copy_tree(node));
|
|
|
|
}
|
|
|
|
|
2007-01-24 18:56:39 +01:00
|
|
|
if (xml_write_tree(rootnode, pfile->fp) < 0) {
|
|
|
|
prefs_file_close_revert(pfile);
|
2001-04-19 14:21:46 +02:00
|
|
|
g_warning("failed to write folder list.\n");
|
2007-01-24 18:56:39 +01:00
|
|
|
} else if (prefs_file_close(pfile) < 0) {
|
|
|
|
g_warning("failed to write folder list.\n");
|
|
|
|
}
|
2004-02-21 12:01:01 +01:00
|
|
|
xml_free_tree(rootnode);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static gboolean folder_scan_tree_func(GNode *node, gpointer data)
|
2002-07-02 21:49:11 +02:00
|
|
|
{
|
|
|
|
GHashTable *pptable = (GHashTable *)data;
|
|
|
|
FolderItem *item = (FolderItem *)node->data;
|
|
|
|
|
|
|
|
folder_item_restore_persist_prefs(item, pptable);
|
2003-06-18 16:01:40 +02:00
|
|
|
folder_item_scan_full(item, FALSE);
|
2002-09-29 15:43:33 +02:00
|
|
|
|
|
|
|
return FALSE;
|
2002-07-02 21:49:11 +02:00
|
|
|
}
|
|
|
|
|
2005-10-05 21:26:02 +02:00
|
|
|
void folder_scan_tree(Folder *folder, gboolean rebuild)
|
2002-07-02 21:49:11 +02:00
|
|
|
{
|
|
|
|
GHashTable *pptable;
|
2003-06-22 20:25:59 +02:00
|
|
|
FolderUpdateData hookdata;
|
2006-06-15 09:02:07 +02:00
|
|
|
Folder *old_folder = folder;
|
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
if (!folder->klass->scan_tree)
|
2002-07-02 21:49:11 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
pptable = folder_persist_prefs_new(folder);
|
|
|
|
|
2005-10-05 21:26:02 +02:00
|
|
|
if (rebuild)
|
2006-06-15 09:02:07 +02:00
|
|
|
folder_remove(folder);
|
2005-10-05 21:26:02 +02:00
|
|
|
|
2006-06-15 09:02:07 +02:00
|
|
|
if (folder->klass->scan_tree(folder) < 0) {
|
|
|
|
if (rebuild)
|
|
|
|
folder_add(old_folder);
|
2006-06-15 08:29:48 +02:00
|
|
|
return;
|
2006-06-15 09:02:07 +02:00
|
|
|
} else if (rebuild)
|
|
|
|
folder_add(folder);
|
2002-07-26 01:00:59 +02:00
|
|
|
|
2003-06-22 20:25:59 +02:00
|
|
|
hookdata.folder = folder;
|
|
|
|
hookdata.update_flags = FOLDER_TREE_CHANGED;
|
2003-09-08 12:33:11 +02:00
|
|
|
hookdata.item = NULL;
|
2003-06-22 20:25:59 +02:00
|
|
|
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static gboolean folder_restore_prefs_func(GNode *node, gpointer data)
|
2007-01-17 18:35:04 +01:00
|
|
|
{
|
|
|
|
GHashTable *pptable = (GHashTable *)data;
|
|
|
|
FolderItem *item = (FolderItem *)node->data;
|
|
|
|
|
|
|
|
folder_item_restore_persist_prefs(item, pptable);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_fast_scan_tree(Folder *folder)
|
|
|
|
{
|
|
|
|
GHashTable *pptable;
|
|
|
|
FolderUpdateData hookdata;
|
|
|
|
|
|
|
|
if (!folder->klass->scan_tree)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pptable = folder_persist_prefs_new(folder);
|
|
|
|
|
|
|
|
if (folder->klass->scan_tree(folder) < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hookdata.folder = folder;
|
|
|
|
hookdata.update_flags = FOLDER_TREE_CHANGED;
|
|
|
|
hookdata.item = NULL;
|
|
|
|
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
|
|
|
|
|
|
|
|
g_node_traverse(folder->node, G_POST_ORDER, G_TRAVERSE_ALL, -1, folder_restore_prefs_func, pptable);
|
|
|
|
folder_persist_prefs_free(pptable);
|
|
|
|
|
|
|
|
prefs_matcher_read_config();
|
|
|
|
|
|
|
|
folder_write_list();
|
|
|
|
}
|
|
|
|
|
2002-10-07 23:47:32 +02:00
|
|
|
FolderItem *folder_create_folder(FolderItem *parent, const gchar *name)
|
|
|
|
{
|
|
|
|
FolderItem *new_item;
|
2008-08-14 20:10:53 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(parent != NULL, NULL);
|
2002-10-07 23:47:32 +02:00
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
new_item = parent->folder->klass->create_folder(parent->folder, parent, name);
|
2003-09-09 21:56:37 +02:00
|
|
|
if (new_item) {
|
2004-05-10 12:22:28 +02:00
|
|
|
FolderUpdateData hookdata;
|
|
|
|
|
2002-11-07 00:56:26 +01:00
|
|
|
new_item->cache = msgcache_new();
|
2009-03-27 20:03:29 +01:00
|
|
|
new_item->cache_dirty = TRUE;
|
|
|
|
new_item->mark_dirty = TRUE;
|
|
|
|
new_item->tags_dirty = TRUE;
|
2002-10-07 23:47:32 +02:00
|
|
|
|
2003-09-09 21:56:37 +02:00
|
|
|
hookdata.folder = new_item->folder;
|
2004-05-10 12:22:28 +02:00
|
|
|
hookdata.update_flags = FOLDER_TREE_CHANGED | FOLDER_ADD_FOLDERITEM;
|
2003-09-09 21:56:37 +02:00
|
|
|
hookdata.item = new_item;
|
|
|
|
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
|
|
|
|
}
|
2003-09-08 13:41:03 +02:00
|
|
|
|
2002-10-07 23:47:32 +02:00
|
|
|
return new_item;
|
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
gint folder_item_rename(FolderItem *item, gchar *newname)
|
|
|
|
{
|
|
|
|
gint retval;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, -1);
|
|
|
|
cm_return_val_if_fail(newname != NULL, -1);
|
2004-05-10 12:22:28 +02:00
|
|
|
|
|
|
|
retval = item->folder->klass->rename_folder(item->folder, item, newname);
|
|
|
|
|
|
|
|
if (retval >= 0) {
|
|
|
|
FolderItemUpdateData hookdata;
|
2006-03-07 10:55:13 +01:00
|
|
|
FolderUpdateData hookdata2;
|
2004-05-10 12:22:28 +02:00
|
|
|
|
|
|
|
hookdata.item = item;
|
2004-06-25 10:05:09 +02:00
|
|
|
hookdata.update_flags = F_ITEM_UPDATE_NAME;
|
|
|
|
hookdata.msg = NULL;
|
2004-05-10 12:22:28 +02:00
|
|
|
hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &hookdata);
|
2006-03-07 10:55:13 +01:00
|
|
|
|
|
|
|
hookdata2.folder = item->folder;
|
|
|
|
hookdata2.item = item;
|
|
|
|
hookdata2.update_flags = FOLDER_RENAME_FOLDERITEM;
|
|
|
|
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata2);
|
2004-05-10 12:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2001-12-03 17:04:12 +01:00
|
|
|
struct TotalMsgCount
|
2001-11-26 08:53:20 +01:00
|
|
|
{
|
2003-04-05 22:38:53 +02:00
|
|
|
guint new_msgs;
|
|
|
|
guint unread_msgs;
|
|
|
|
guint unreadmarked_msgs;
|
2005-07-01 19:33:02 +02:00
|
|
|
guint marked_msgs;
|
2003-04-05 22:38:53 +02:00
|
|
|
guint total_msgs;
|
2008-03-12 07:22:29 +01:00
|
|
|
guint replied_msgs;
|
|
|
|
guint forwarded_msgs;
|
|
|
|
guint locked_msgs;
|
|
|
|
guint ignored_msgs;
|
|
|
|
guint watched_msgs;
|
2001-12-03 17:04:12 +01:00
|
|
|
};
|
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
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_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);
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, FALSE);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
count->new_msgs += item->new_msgs;
|
|
|
|
count->unread_msgs += item->unread_msgs;
|
|
|
|
count->unreadmarked_msgs += item->unreadmarked_msgs;
|
2005-07-01 19:33:02 +02:00
|
|
|
count->marked_msgs += item->marked_msgs;
|
2003-04-05 22:38:53 +02:00
|
|
|
count->total_msgs += item->total_msgs;
|
2008-03-12 07:22:29 +01:00
|
|
|
count->replied_msgs += item->replied_msgs;
|
|
|
|
count->forwarded_msgs += item->forwarded_msgs;
|
|
|
|
count->locked_msgs += item->locked_msgs;
|
|
|
|
count->ignored_msgs += item->ignored_msgs;
|
|
|
|
count->watched_msgs += item->watched_msgs;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
2003-07-04 13:59:46 +02:00
|
|
|
struct TotalMsgStatus
|
|
|
|
{
|
|
|
|
guint new;
|
|
|
|
guint unread;
|
|
|
|
guint total;
|
|
|
|
GString *str;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean folder_get_status_full_all_func(GNode *node, gpointer data)
|
|
|
|
{
|
|
|
|
FolderItem *item;
|
|
|
|
struct TotalMsgStatus *status = (struct TotalMsgStatus *)data;
|
|
|
|
gchar *id;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(node->data != NULL, FALSE);
|
2003-07-04 13:59:46 +02:00
|
|
|
|
|
|
|
item = FOLDER_ITEM(node->data);
|
|
|
|
|
|
|
|
if (!item->path) return FALSE;
|
|
|
|
|
|
|
|
status->new += item->new_msgs;
|
|
|
|
status->unread += item->unread_msgs;
|
|
|
|
status->total += item->total_msgs;
|
|
|
|
|
|
|
|
if (status->str) {
|
|
|
|
id = folder_item_get_identifier(item);
|
2004-10-26 12:43:50 +02:00
|
|
|
g_string_append_printf(status->str, "%5d %5d %5d %s\n",
|
2003-07-04 13:59:46 +02:00
|
|
|
item->new_msgs, item->unread_msgs,
|
|
|
|
item->total_msgs, id);
|
|
|
|
g_free(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void folder_get_status_full_all(GString *str, guint *new, guint *unread,
|
|
|
|
guint *total)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
Folder *folder;
|
|
|
|
struct TotalMsgStatus status;
|
|
|
|
|
|
|
|
status.new = status.unread = status.total = 0;
|
|
|
|
status.str = str;
|
|
|
|
|
|
|
|
debug_print("Counting total number of messages...\n");
|
|
|
|
|
|
|
|
for (list = folder_list; list != NULL; list = list->next) {
|
|
|
|
folder = FOLDER(list->data);
|
|
|
|
if (folder->node)
|
|
|
|
g_node_traverse(folder->node, G_PRE_ORDER,
|
|
|
|
G_TRAVERSE_ALL, -1,
|
|
|
|
folder_get_status_full_all_func,
|
|
|
|
&status);
|
|
|
|
}
|
|
|
|
|
|
|
|
*new = status.new;
|
|
|
|
*unread = status.unread;
|
|
|
|
*total = status.total;
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *folder_get_status(GPtrArray *folders, gboolean full)
|
|
|
|
{
|
|
|
|
guint new, unread, total;
|
|
|
|
GString *str;
|
|
|
|
gint i;
|
|
|
|
gchar *ret;
|
|
|
|
|
|
|
|
new = unread = total = 0;
|
|
|
|
|
|
|
|
str = g_string_new(NULL);
|
|
|
|
|
|
|
|
if (folders) {
|
|
|
|
for (i = 0; i < folders->len; i++) {
|
|
|
|
FolderItem *item;
|
|
|
|
|
|
|
|
item = g_ptr_array_index(folders, i);
|
|
|
|
new += item->new_msgs;
|
|
|
|
unread += item->unread_msgs;
|
|
|
|
total += item->total_msgs;
|
|
|
|
|
|
|
|
if (full) {
|
|
|
|
gchar *id;
|
|
|
|
|
|
|
|
id = folder_item_get_identifier(item);
|
2004-10-26 12:43:50 +02:00
|
|
|
g_string_append_printf(str, "%5d %5d %5d %s\n",
|
2003-07-04 13:59:46 +02:00
|
|
|
item->new_msgs, item->unread_msgs,
|
|
|
|
item->total_msgs, id);
|
|
|
|
g_free(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
folder_get_status_full_all(full ? str : NULL,
|
|
|
|
&new, &unread, &total);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (full)
|
2004-10-26 12:43:50 +02:00
|
|
|
g_string_append_printf(str, "%5d %5d %5d\n", new, unread, total);
|
2003-07-04 13:59:46 +02:00
|
|
|
else
|
2004-10-26 12:43:50 +02:00
|
|
|
g_string_append_printf(str, "%d %d %d\n", new, unread, total);
|
2003-07-04 13:59:46 +02:00
|
|
|
|
|
|
|
ret = str->str;
|
|
|
|
g_string_free(str, FALSE);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-07-01 19:33:02 +02:00
|
|
|
void folder_count_total_msgs(guint *new_msgs, guint *unread_msgs,
|
|
|
|
guint *unreadmarked_msgs, guint *marked_msgs,
|
2008-03-12 07:22:29 +01:00
|
|
|
guint *total_msgs, guint *replied_msgs,
|
|
|
|
guint *forwarded_msgs, guint *locked_msgs,
|
|
|
|
guint *ignored_msgs, guint *watched_msgs)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
|
|
|
struct TotalMsgCount count;
|
|
|
|
|
2008-03-12 07:22:29 +01:00
|
|
|
count.new_msgs = count.unread_msgs = count.unreadmarked_msgs = 0;
|
|
|
|
count.total_msgs = count.replied_msgs = count.forwarded_msgs = 0;
|
|
|
|
count.locked_msgs = count.ignored_msgs = count.watched_msgs = 0;
|
|
|
|
count.marked_msgs = 0;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
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
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
*new_msgs = count.new_msgs;
|
|
|
|
*unread_msgs = count.unread_msgs;
|
|
|
|
*unreadmarked_msgs = count.unreadmarked_msgs;
|
2005-07-01 19:33:02 +02:00
|
|
|
*marked_msgs = count.marked_msgs;
|
2003-04-05 22:38:53 +02:00
|
|
|
*total_msgs = count.total_msgs;
|
2008-03-12 07:22:29 +01:00
|
|
|
*replied_msgs = count.replied_msgs;
|
|
|
|
*forwarded_msgs = count.forwarded_msgs;
|
|
|
|
*locked_msgs = count.locked_msgs;
|
|
|
|
*ignored_msgs = count.ignored_msgs;
|
|
|
|
*watched_msgs = count.watched_msgs;
|
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;
|
2004-01-12 22:28:31 +01:00
|
|
|
if ((FOLDER_TYPE(folder) == F_MH ||
|
|
|
|
FOLDER_TYPE(folder) == F_MBOX) &&
|
2001-04-19 14:21:46 +02:00
|
|
|
!path_cmp(LOCAL_FOLDER(folder)->rootpath, path))
|
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
Folder *folder_find_from_name(const gchar *name, FolderClass *klass)
|
2002-04-05 10:20:10 +02:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
Folder *folder;
|
|
|
|
|
|
|
|
for (list = folder_list; list != NULL; list = list->next) {
|
|
|
|
folder = list->data;
|
2004-01-12 22:28:31 +01:00
|
|
|
if (folder->klass == klass &&
|
|
|
|
strcmp2(name, folder->name) == 0)
|
2002-04-05 10:20:10 +02:00
|
|
|
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];
|
2006-12-21 08:58:13 +01:00
|
|
|
GList *list = folder_get_list();
|
|
|
|
|
|
|
|
folder = list ? list->data:NULL;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
d[0] = (gpointer)path;
|
|
|
|
d[1] = NULL;
|
2006-12-21 08:58:13 +01:00
|
|
|
while (d[1] == NULL && list) {
|
|
|
|
folder = FOLDER(list->data);
|
|
|
|
g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
|
2001-04-19 14:21:46 +02:00
|
|
|
folder_item_find_func, d);
|
2006-12-21 08:58:13 +01:00
|
|
|
list = list->next;
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
return d[1];
|
|
|
|
}
|
|
|
|
|
2008-01-23 07:43:15 +01:00
|
|
|
static gboolean folder_item_find_func_real_path(GNode *node, gpointer data)
|
|
|
|
{
|
|
|
|
FolderItem *item = node->data;
|
|
|
|
gpointer *d = data;
|
|
|
|
const gchar *path = d[0];
|
|
|
|
gchar *tmp = folder_item_get_path(item);
|
|
|
|
if (path_cmp(path, tmp) != 0) {
|
|
|
|
g_free(tmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
g_free(tmp);
|
|
|
|
d[1] = item;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
FolderItem *folder_find_item_from_real_path(const gchar *path)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gpointer d[2];
|
|
|
|
GList *list = folder_get_list();
|
|
|
|
|
|
|
|
folder = list ? list->data:NULL;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder != NULL, NULL);
|
2008-01-23 07:43:15 +01:00
|
|
|
|
|
|
|
d[0] = (gpointer)path;
|
|
|
|
d[1] = NULL;
|
|
|
|
while (d[1] == NULL && list) {
|
|
|
|
folder = FOLDER(list->data);
|
|
|
|
g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
|
|
|
|
folder_item_find_func_real_path, d);
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
return d[1];
|
|
|
|
}
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
FolderItem *folder_find_child_item_by_name(FolderItem *item, const gchar *name)
|
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
FolderItem *child;
|
|
|
|
|
|
|
|
for (node = item->node->children; node != NULL; node = node->next) {
|
|
|
|
child = FOLDER_ITEM(node->data);
|
2009-01-11 13:32:51 +01:00
|
|
|
if (strcmp2(child->name, name) == 0) {
|
2004-05-10 12:22:28 +02:00
|
|
|
return child;
|
2004-11-13 14:28:35 +01:00
|
|
|
}
|
2004-05-10 12:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-03-13 16:31:22 +01:00
|
|
|
FolderClass *folder_get_class_from_string(const gchar *str)
|
2002-04-05 10:20:10 +02:00
|
|
|
{
|
2003-03-12 23:23:54 +01:00
|
|
|
GSList *classlist;
|
2002-04-05 10:20:10 +02:00
|
|
|
|
2003-03-12 23:23:54 +01:00
|
|
|
classlist = folder_get_class_list();
|
|
|
|
for (; classlist != NULL; classlist = g_slist_next(classlist)) {
|
|
|
|
FolderClass *class = (FolderClass *) classlist->data;
|
2004-10-26 12:43:50 +02:00
|
|
|
if (g_ascii_strcasecmp(class->idstr, str) == 0)
|
2003-03-12 23:23:54 +01:00
|
|
|
return class;
|
2002-04-05 10:20:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-12 11:44:26 +01:00
|
|
|
gchar *folder_get_identifier(Folder *folder)
|
2002-04-05 10:20:10 +02:00
|
|
|
{
|
|
|
|
gchar *type_str;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder != NULL, NULL);
|
2002-04-05 10:20:10 +02:00
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
type_str = folder->klass->idstr;
|
2003-03-12 23:23:54 +01:00
|
|
|
return g_strconcat("#", type_str, "/", folder->name, NULL);
|
2002-04-05 10:20:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *folder_item_get_identifier(FolderItem *item)
|
|
|
|
{
|
2004-08-07 17:40:13 +02:00
|
|
|
gchar *id = NULL;
|
|
|
|
gchar *folder_id = NULL;
|
2002-04-05 10:20:10 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
2006-09-08 23:00:02 +02:00
|
|
|
|
|
|
|
if (item->path == NULL)
|
|
|
|
return NULL;
|
2002-04-05 10:20:10 +02:00
|
|
|
|
|
|
|
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;
|
2003-03-12 23:23:54 +01:00
|
|
|
FolderClass *class;
|
2002-04-05 10:20:10 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(identifier != NULL, NULL);
|
2002-04-05 10:20:10 +02:00
|
|
|
|
|
|
|
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++;
|
2003-03-13 16:31:22 +01:00
|
|
|
class = folder_get_class_from_string(&str[1]);
|
2003-03-12 23:23:54 +01:00
|
|
|
if (class == NULL)
|
2002-04-05 10:20:10 +02:00
|
|
|
return folder_find_item_from_path(identifier);
|
|
|
|
|
|
|
|
name = p;
|
|
|
|
p = strchr(p, '/');
|
|
|
|
if (!p)
|
|
|
|
return folder_find_item_from_path(identifier);
|
|
|
|
*p = '\0';
|
|
|
|
p++;
|
|
|
|
|
2003-03-12 23:23:54 +01:00
|
|
|
folder = folder_find_from_name(name, class);
|
2002-04-05 10:20:10 +02:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2010-01-19 22:32:04 +01:00
|
|
|
/** Returns the FolderItem from a given identifier
|
|
|
|
*
|
|
|
|
* The FolderItem is created if it doesn't already exist.
|
|
|
|
* If creation failed, the function returns NULL.
|
|
|
|
*
|
|
|
|
* Identifiers are of the form #type/Mailbox/FolderA/FolderB/FolderC
|
|
|
|
*/
|
|
|
|
FolderItem *folder_get_item_from_identifier(const gchar *identifier)
|
|
|
|
{
|
|
|
|
FolderItem *item, *last_parent;
|
|
|
|
Folder *folder;
|
|
|
|
gchar *p1, *p2, *str;
|
|
|
|
size_t len;
|
|
|
|
FolderClass *class;
|
|
|
|
gboolean created_something = FALSE;
|
|
|
|
|
|
|
|
item = folder_find_item_from_identifier(identifier);
|
|
|
|
if(item)
|
|
|
|
return item;
|
|
|
|
|
|
|
|
/* trivial sanity check: need at least # and two slashes */
|
|
|
|
len = strlen(identifier);
|
|
|
|
if(len < 3)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* make sure identifier ends with a slash */
|
|
|
|
if(identifier[len-1] == G_DIR_SEPARATOR) {
|
|
|
|
Xstrdup_a(str, identifier, return NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Xstrndup_a(str, identifier, len+1, return NULL);
|
|
|
|
str[len] = G_DIR_SEPARATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find folder class */
|
|
|
|
p1 = strchr(str, G_DIR_SEPARATOR);
|
|
|
|
if(!p1)
|
|
|
|
return NULL;
|
|
|
|
*p1 = '\0';
|
|
|
|
class = folder_get_class_from_string(&str[1]);
|
|
|
|
if(!class)
|
|
|
|
return NULL;
|
|
|
|
*p1 = G_DIR_SEPARATOR;
|
|
|
|
++p1;
|
|
|
|
|
|
|
|
/* find folder from class and name */
|
|
|
|
p2 = strchr(p1, G_DIR_SEPARATOR);
|
|
|
|
if(!p2)
|
|
|
|
return NULL;
|
|
|
|
*p2 = '\0';
|
|
|
|
folder = folder_find_from_name(p1, class);
|
|
|
|
if(!folder)
|
|
|
|
return NULL;
|
|
|
|
*p2 = G_DIR_SEPARATOR;
|
|
|
|
++p2;
|
|
|
|
p1 = p2;
|
|
|
|
|
|
|
|
/* Now, move forward and make sure all sections in the path exist */
|
|
|
|
last_parent = folder->node->data;
|
|
|
|
while((p1 = strchr(p1, G_DIR_SEPARATOR)) != NULL) {
|
|
|
|
*p1 = '\0';
|
|
|
|
item = folder_find_item_from_identifier(str);
|
|
|
|
if(!item) {
|
|
|
|
item = folder_create_folder(last_parent, p2);
|
|
|
|
if(!item)
|
|
|
|
return NULL;
|
|
|
|
debug_print("Created folder '%s'\n", str);
|
|
|
|
created_something = TRUE;
|
|
|
|
if(prefs_common.inherit_folder_props && (last_parent != item->folder->node->data)) {
|
|
|
|
folder_item_prefs_copy_prefs(last_parent, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last_parent = item;
|
|
|
|
*p1 = G_DIR_SEPARATOR;
|
|
|
|
++p1;
|
|
|
|
p2 = p1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(created_something)
|
|
|
|
folder_write_list();
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-13 22:21:39 +01:00
|
|
|
/**
|
|
|
|
* Get a displayable name for a FolderItem
|
|
|
|
*
|
|
|
|
* \param item FolderItem for that a name should be created
|
|
|
|
* \return Displayable name for item, returned string has to
|
|
|
|
* be freed
|
|
|
|
*/
|
|
|
|
gchar *folder_item_get_name(FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *name = NULL;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, g_strdup(""));
|
2003-09-07 01:18:53 +02:00
|
|
|
|
2003-03-13 22:21:39 +01:00
|
|
|
switch (item->stype) {
|
|
|
|
case F_INBOX:
|
2003-03-27 22:52:32 +01:00
|
|
|
name = g_strdup(!strcmp2(item->name, INBOX_DIR) ? _("Inbox") :
|
2003-03-13 22:21:39 +01:00
|
|
|
item->name);
|
|
|
|
break;
|
|
|
|
case F_OUTBOX:
|
2003-03-27 22:52:32 +01:00
|
|
|
name = g_strdup(!strcmp2(item->name, OUTBOX_DIR) ? _("Sent") :
|
2003-03-13 22:21:39 +01:00
|
|
|
item->name);
|
|
|
|
break;
|
|
|
|
case F_QUEUE:
|
2003-03-27 22:52:32 +01:00
|
|
|
name = g_strdup(!strcmp2(item->name, QUEUE_DIR) ? _("Queue") :
|
2003-03-13 22:21:39 +01:00
|
|
|
item->name);
|
|
|
|
break;
|
|
|
|
case F_TRASH:
|
2003-03-27 22:52:32 +01:00
|
|
|
name = g_strdup(!strcmp2(item->name, TRASH_DIR) ? _("Trash") :
|
2003-03-13 22:21:39 +01:00
|
|
|
item->name);
|
|
|
|
break;
|
|
|
|
case F_DRAFT:
|
2003-03-27 22:52:32 +01:00
|
|
|
name = g_strdup(!strcmp2(item->name, DRAFT_DIR) ? _("Drafts") :
|
2003-03-13 22:21:39 +01:00
|
|
|
item->name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == NULL) {
|
|
|
|
/*
|
|
|
|
* should probably be done by a virtual function,
|
|
|
|
* the folder knows the ui string and how to abbrev
|
|
|
|
*/
|
2004-02-21 12:01:01 +01:00
|
|
|
if (folder_item_parent(item) == NULL) {
|
2003-04-05 22:38:53 +02:00
|
|
|
name = g_strconcat(item->name, " (", item->folder->klass->uistr, ")", NULL);
|
2003-03-13 22:21:39 +01:00
|
|
|
} else {
|
|
|
|
if (FOLDER_CLASS(item->folder) == news_get_class() &&
|
|
|
|
item->path && !strcmp2(item->name, item->path))
|
|
|
|
name = get_abbrev_newsgroup_name
|
|
|
|
(item->path,
|
|
|
|
prefs_common.ng_abbrev_len);
|
|
|
|
else
|
|
|
|
name = g_strdup(item->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
name = g_strdup("");
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2006-01-15 19:05:16 +01:00
|
|
|
gboolean folder_have_mailbox (void)
|
|
|
|
{
|
|
|
|
GList *cur;
|
|
|
|
for (cur = folder_list; cur != NULL; cur = g_list_next(cur)) {
|
|
|
|
Folder *folder = FOLDER(cur->data);
|
|
|
|
if (folder->inbox && folder->outbox)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
FolderItem *folder_get_default_inbox(void)
|
|
|
|
{
|
2004-05-22 09:27:30 +02:00
|
|
|
GList *flist;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-05-22 09:27:30 +02:00
|
|
|
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
|
|
|
|
Folder * folder = FOLDER(flist->data);
|
|
|
|
|
|
|
|
if (folder == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->inbox == NULL)
|
|
|
|
continue;
|
2006-07-07 18:53:55 +02:00
|
|
|
if (folder->klass->type == F_UNKNOWN)
|
|
|
|
continue;
|
2004-05-22 09:27:30 +02:00
|
|
|
|
|
|
|
return folder->inbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2007-03-20 18:39:33 +01:00
|
|
|
FolderItem *folder_get_default_inbox_for_class(FolderType type)
|
|
|
|
{
|
|
|
|
GList *flist;
|
|
|
|
|
|
|
|
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
|
|
|
|
Folder * folder = FOLDER(flist->data);
|
|
|
|
|
|
|
|
if (folder == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->inbox == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->klass->type != type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return folder->inbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
FolderItem *folder_get_default_outbox(void)
|
|
|
|
{
|
2004-05-22 09:27:30 +02:00
|
|
|
GList *flist;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-05-22 09:27:30 +02:00
|
|
|
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
|
|
|
|
Folder * folder = FOLDER(flist->data);
|
|
|
|
|
|
|
|
if (folder == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->outbox == NULL)
|
|
|
|
continue;
|
2006-08-27 16:19:22 +02:00
|
|
|
if (folder->klass->type == F_UNKNOWN)
|
|
|
|
continue;
|
2004-05-22 09:27:30 +02:00
|
|
|
|
|
|
|
return folder->outbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2007-08-24 13:07:45 +02:00
|
|
|
FolderItem *folder_get_default_outbox_for_class(FolderType type)
|
|
|
|
{
|
|
|
|
GList *flist;
|
|
|
|
|
|
|
|
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
|
|
|
|
Folder * folder = FOLDER(flist->data);
|
|
|
|
|
|
|
|
if (folder == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->outbox == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->klass->type != type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return folder->outbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
FolderItem *folder_get_default_draft(void)
|
|
|
|
{
|
2004-05-22 09:27:30 +02:00
|
|
|
GList *flist;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-05-22 09:27:30 +02:00
|
|
|
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
|
|
|
|
Folder * folder = FOLDER(flist->data);
|
|
|
|
|
|
|
|
if (folder == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->draft == NULL)
|
|
|
|
continue;
|
2006-08-27 16:19:22 +02:00
|
|
|
if (folder->klass->type == F_UNKNOWN)
|
|
|
|
continue;
|
2004-05-22 09:27:30 +02:00
|
|
|
|
|
|
|
return folder->draft;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2007-08-24 13:07:45 +02:00
|
|
|
FolderItem *folder_get_default_draft_for_class(FolderType type)
|
|
|
|
{
|
|
|
|
GList *flist;
|
|
|
|
|
|
|
|
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
|
|
|
|
Folder * folder = FOLDER(flist->data);
|
|
|
|
|
|
|
|
if (folder == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->draft == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->klass->type != type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return folder->draft;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
FolderItem *folder_get_default_queue(void)
|
|
|
|
{
|
2004-05-22 09:27:30 +02:00
|
|
|
GList *flist;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-05-22 09:27:30 +02:00
|
|
|
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
|
|
|
|
Folder * folder = FOLDER(flist->data);
|
|
|
|
|
|
|
|
if (folder == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->queue == NULL)
|
|
|
|
continue;
|
2006-08-27 16:19:22 +02:00
|
|
|
if (folder->klass->type == F_UNKNOWN)
|
|
|
|
continue;
|
2004-05-22 09:27:30 +02:00
|
|
|
|
|
|
|
return folder->queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2007-08-24 13:07:45 +02:00
|
|
|
FolderItem *folder_get_default_queue_for_class(FolderType type)
|
|
|
|
{
|
|
|
|
GList *flist;
|
|
|
|
|
|
|
|
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
|
|
|
|
Folder * folder = FOLDER(flist->data);
|
|
|
|
|
|
|
|
if (folder == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->queue == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->klass->type != type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return folder->queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
FolderItem *folder_get_default_trash(void)
|
|
|
|
{
|
2004-05-22 09:27:30 +02:00
|
|
|
GList *flist;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-05-22 09:27:30 +02:00
|
|
|
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
|
|
|
|
Folder * folder = FOLDER(flist->data);
|
|
|
|
|
|
|
|
if (folder == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->trash == NULL)
|
|
|
|
continue;
|
2006-08-27 16:19:22 +02:00
|
|
|
if (folder->klass->type == F_UNKNOWN)
|
|
|
|
continue;
|
2004-05-22 09:27:30 +02:00
|
|
|
|
|
|
|
return folder->trash;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2007-08-24 13:07:45 +02:00
|
|
|
FolderItem *folder_get_default_trash_for_class(FolderType type)
|
|
|
|
{
|
|
|
|
GList *flist;
|
|
|
|
|
|
|
|
for (flist = folder_list; flist != NULL; flist = g_list_next(flist)) {
|
|
|
|
Folder * folder = FOLDER(flist->data);
|
|
|
|
|
|
|
|
if (folder == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->trash == NULL)
|
|
|
|
continue;
|
|
|
|
if (folder->klass->type != type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return folder->trash;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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;
|
2003-03-12 16:40:51 +01:00
|
|
|
if (FOLDER_TYPE(folder) != F_MH) continue;
|
2002-03-19 09:37:53 +01:00
|
|
|
rootitem = FOLDER_ITEM(folder->node->data);
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(rootitem != NULL);
|
2002-03-19 09:37:53 +01:00
|
|
|
|
|
|
|
if (folder->inbox && folder->outbox && folder->draft &&
|
|
|
|
folder->queue && folder->trash)
|
|
|
|
continue;
|
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
if (folder->klass->create_tree(folder) < 0) {
|
2002-03-19 09:37:53 +01:00
|
|
|
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_item_get_path(FolderItem *item)
|
|
|
|
{
|
2003-07-03 22:37:07 +02:00
|
|
|
Folder *folder;
|
2002-08-28 13:54:45 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
2003-07-03 22:37:07 +02:00
|
|
|
folder = item->folder;
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-07-03 22:37:07 +02:00
|
|
|
return folder->klass->item_get_path(folder, item);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2007-10-12 19:03:55 +02:00
|
|
|
static gint syncronize_flags(FolderItem *item, MsgInfoList *msglist)
|
|
|
|
{
|
2010-10-03 13:46:24 +02:00
|
|
|
GHashTable *relation;
|
2007-10-12 19:03:55 +02:00
|
|
|
gint ret = 0;
|
|
|
|
GSList *cur;
|
|
|
|
|
|
|
|
if(msglist == NULL)
|
|
|
|
return 0;
|
|
|
|
if(item->folder->klass->get_flags == NULL)
|
|
|
|
return 0;
|
|
|
|
if (item->no_select)
|
|
|
|
return 0;
|
|
|
|
|
2010-10-03 13:46:24 +02:00
|
|
|
relation = g_hash_table_new(g_direct_hash, g_direct_equal);
|
2007-10-12 19:03:55 +02:00
|
|
|
if ((ret = item->folder->klass->get_flags(
|
|
|
|
item->folder, item, msglist, relation)) == 0) {
|
2010-10-03 13:46:24 +02:00
|
|
|
gpointer data, old_key;
|
2007-10-12 19:03:55 +02:00
|
|
|
MsgInfo *msginfo;
|
|
|
|
MsgPermFlags permflags = 0;
|
|
|
|
|
|
|
|
folder_item_update_freeze();
|
|
|
|
folder_item_set_batch(item, TRUE);
|
|
|
|
for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
|
|
|
|
msginfo = (MsgInfo *) cur->data;
|
|
|
|
|
2010-10-03 13:46:24 +02:00
|
|
|
if (g_hash_table_lookup_extended(relation, msginfo, &old_key, &data)) {
|
|
|
|
permflags = GPOINTER_TO_INT(data);
|
|
|
|
|
|
|
|
if (msginfo->flags.perm_flags != permflags) {
|
|
|
|
procmsg_msginfo_change_flags(msginfo,
|
|
|
|
permflags & ~msginfo->flags.perm_flags, 0,
|
|
|
|
~permflags & msginfo->flags.perm_flags, 0);
|
|
|
|
}
|
2007-10-12 19:03:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
folder_item_set_batch(item, FALSE);
|
|
|
|
folder_item_update_thaw();
|
|
|
|
}
|
2010-10-03 13:46:24 +02:00
|
|
|
g_hash_table_destroy(relation);
|
2007-10-12 19:03:55 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint folder_item_syncronize_flags(FolderItem *item)
|
|
|
|
{
|
|
|
|
MsgInfoList *msglist = NULL;
|
|
|
|
GSList *cur;
|
|
|
|
gint ret = 0;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, -1);
|
|
|
|
cm_return_val_if_fail(item->folder != NULL, -1);
|
|
|
|
cm_return_val_if_fail(item->folder->klass != NULL, -1);
|
2007-10-12 19:03:55 +02:00
|
|
|
if (item->no_select)
|
|
|
|
return -1;
|
|
|
|
|
2007-12-03 18:32:15 +01:00
|
|
|
item->scanning = ITEM_SCANNING_WITH_FLAGS;
|
2007-10-12 19:03:55 +02:00
|
|
|
|
|
|
|
if (item->cache == NULL)
|
|
|
|
folder_item_read_cache(item);
|
|
|
|
|
|
|
|
msglist = msgcache_get_msg_list(item->cache);
|
|
|
|
|
|
|
|
ret = syncronize_flags(item, msglist);
|
|
|
|
|
|
|
|
for (cur = msglist; cur != NULL; cur = g_slist_next(cur))
|
|
|
|
procmsg_msginfo_free((MsgInfo *) cur->data);
|
|
|
|
|
|
|
|
g_slist_free(msglist);
|
|
|
|
|
2007-12-03 18:32:15 +01:00
|
|
|
item->scanning = ITEM_NOT_SCANNING;
|
2007-10-12 19:03:55 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void folder_item_process_open (FolderItem *item,
|
2005-10-08 12:38:28 +02:00
|
|
|
void (*before_proc_func)(gpointer data),
|
|
|
|
void (*after_proc_func)(gpointer data),
|
|
|
|
gpointer data)
|
2002-11-09 23:06:23 +01:00
|
|
|
{
|
2004-05-10 12:22:28 +02:00
|
|
|
gchar *buf;
|
2005-10-04 18:31:25 +02:00
|
|
|
if (item == NULL)
|
|
|
|
return;
|
2005-01-27 22:38:55 +01:00
|
|
|
if((item->folder->klass->scan_required != NULL) &&
|
|
|
|
(item->folder->klass->scan_required(item->folder, item))) {
|
2003-06-18 16:01:40 +02:00
|
|
|
folder_item_scan_full(item, TRUE);
|
2005-10-04 18:31:25 +02:00
|
|
|
} else {
|
|
|
|
folder_item_syncronize_flags(item);
|
2002-11-09 23:06:23 +01:00
|
|
|
}
|
2004-05-10 12:22:28 +02:00
|
|
|
|
2002-11-09 23:06:23 +01:00
|
|
|
/* Processing */
|
2008-01-08 14:45:41 +01:00
|
|
|
if (item->prefs->enable_processing_when_opening) {
|
|
|
|
buf = g_strdup_printf(_("Processing (%s)...\n"),
|
2004-05-10 12:22:28 +02:00
|
|
|
item->path ? item->path : item->name);
|
2008-01-08 14:45:41 +01:00
|
|
|
g_free(buf);
|
2005-10-08 12:38:28 +02:00
|
|
|
|
2008-01-08 14:45:41 +01:00
|
|
|
if (before_proc_func)
|
|
|
|
before_proc_func(data);
|
2005-10-08 12:38:28 +02:00
|
|
|
|
2008-01-08 14:45:41 +01:00
|
|
|
folder_item_apply_processing(item);
|
2005-10-08 12:38:28 +02:00
|
|
|
|
2008-01-08 14:45:41 +01:00
|
|
|
if (after_proc_func)
|
|
|
|
after_proc_func(data);
|
|
|
|
}
|
2005-10-08 12:38:28 +02:00
|
|
|
item->processing_pending = FALSE;
|
2005-10-04 18:31:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint folder_item_open(FolderItem *item)
|
|
|
|
{
|
2006-09-23 15:31:18 +02:00
|
|
|
START_TIMING("");
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return -1;
|
2005-10-04 18:31:25 +02:00
|
|
|
|
2007-12-03 18:32:15 +01:00
|
|
|
if (item->scanning != ITEM_NOT_SCANNING) {
|
2006-05-19 19:09:06 +02:00
|
|
|
debug_print("%s is scanning... \n", item->path ? item->path : item->name);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2005-10-08 12:38:28 +02:00
|
|
|
item->processing_pending = TRUE;
|
2005-10-19 11:17:43 +02:00
|
|
|
folder_item_process_open (item, NULL, NULL, NULL);
|
2005-10-08 12:38:28 +02:00
|
|
|
|
2005-10-04 18:31:25 +02:00
|
|
|
item->opened = TRUE;
|
2006-05-24 20:02:15 +02:00
|
|
|
END_TIMING();
|
2002-11-09 23:06:23 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-26 21:07:16 +02:00
|
|
|
gint folder_item_close(FolderItem *item)
|
2002-11-09 23:06:23 +01:00
|
|
|
{
|
|
|
|
GSList *mlist, *cur;
|
2003-07-26 21:07:16 +02:00
|
|
|
Folder *folder;
|
2002-11-09 23:06:23 +01:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, -1);
|
2006-03-18 09:56:52 +01:00
|
|
|
|
|
|
|
if (item->no_select)
|
|
|
|
return -1;
|
2002-11-13 22:14:05 +01:00
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
if (item->new_msgs) {
|
2003-04-24 20:49:29 +02:00
|
|
|
folder_item_update_freeze();
|
2002-11-13 22:14:05 +01:00
|
|
|
mlist = folder_item_get_msg_list(item);
|
|
|
|
for (cur = mlist ; cur != NULL ; cur = cur->next) {
|
|
|
|
MsgInfo * msginfo;
|
|
|
|
|
|
|
|
msginfo = (MsgInfo *) cur->data;
|
|
|
|
if (MSG_IS_NEW(msginfo->flags))
|
|
|
|
procmsg_msginfo_unset_flags(msginfo, MSG_NEW, 0);
|
|
|
|
procmsg_msginfo_free(msginfo);
|
|
|
|
}
|
|
|
|
g_slist_free(mlist);
|
2003-04-24 20:49:29 +02:00
|
|
|
folder_item_update_thaw();
|
2002-11-13 22:14:05 +01:00
|
|
|
}
|
2002-11-13 14:27:56 +01:00
|
|
|
|
2002-11-13 14:30:55 +01:00
|
|
|
folder_item_write_cache(item);
|
2002-11-09 23:06:23 +01:00
|
|
|
|
2003-01-07 22:49:44 +01:00
|
|
|
folder_item_update(item, F_ITEM_UPDATE_MSGCNT);
|
2003-07-26 21:07:16 +02:00
|
|
|
|
|
|
|
item->opened = FALSE;
|
|
|
|
folder = item->folder;
|
|
|
|
|
|
|
|
if (folder->klass->close == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return folder->klass->close(folder, item);
|
2002-11-09 23:06:23 +01:00
|
|
|
}
|
|
|
|
|
2004-06-25 10:05:09 +02:00
|
|
|
static MsgInfoList *get_msginfos(FolderItem *item, MsgNumberList *numlist)
|
|
|
|
{
|
|
|
|
MsgInfoList *msglist = NULL;
|
|
|
|
Folder *folder = item->folder;
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return NULL;
|
2005-06-21 19:25:18 +02:00
|
|
|
|
2004-06-25 10:05:09 +02:00
|
|
|
if (folder->klass->get_msginfos != NULL)
|
|
|
|
msglist = folder->klass->get_msginfos(folder, item, numlist);
|
|
|
|
else {
|
|
|
|
MsgNumberList *elem;
|
|
|
|
|
|
|
|
for (elem = numlist; elem != NULL; elem = g_slist_next(elem)) {
|
|
|
|
MsgInfo *msginfo;
|
|
|
|
guint num;
|
|
|
|
|
|
|
|
num = GPOINTER_TO_INT(elem->data);
|
|
|
|
msginfo = folder->klass->get_msginfo(folder, item, num);
|
|
|
|
if (msginfo != NULL)
|
|
|
|
msglist = g_slist_prepend(msglist, msginfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return msglist;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MsgInfo *get_msginfo(FolderItem *item, guint num)
|
|
|
|
{
|
|
|
|
MsgNumberList numlist;
|
|
|
|
MsgInfoList *msglist;
|
|
|
|
MsgInfo *msginfo = NULL;
|
|
|
|
|
|
|
|
numlist.data = GINT_TO_POINTER(num);
|
|
|
|
numlist.next = NULL;
|
|
|
|
msglist = get_msginfos(item, &numlist);
|
|
|
|
if (msglist != NULL)
|
|
|
|
msginfo = procmsg_msginfo_new_ref(msglist->data);
|
|
|
|
procmsg_msg_list_free(msglist);
|
|
|
|
|
|
|
|
return msginfo;
|
|
|
|
}
|
|
|
|
|
2003-06-18 16:01:40 +02:00
|
|
|
gint folder_item_scan_full(FolderItem *item, gboolean filtering)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
Folder *folder;
|
2003-02-25 17:28:14 +01:00
|
|
|
GSList *folder_list = NULL, *cache_list = NULL;
|
|
|
|
GSList *folder_list_cur, *cache_list_cur, *new_list = NULL;
|
|
|
|
GSList *exists_list = NULL, *elem;
|
|
|
|
GSList *newmsg_list = NULL;
|
2005-07-01 19:33:02 +02:00
|
|
|
guint newcnt = 0, unreadcnt = 0, totalcnt = 0;
|
|
|
|
guint markedcnt = 0, unreadmarkedcnt = 0;
|
2008-03-12 07:22:29 +01:00
|
|
|
guint repliedcnt = 0, forwardedcnt = 0;
|
|
|
|
guint lockedcnt = 0, ignoredcnt = 0, watchedcnt = 0;
|
|
|
|
|
2002-09-10 15:25:04 +02:00
|
|
|
guint cache_max_num, folder_max_num, cache_cur_num, folder_cur_num;
|
2003-08-21 22:08:27 +02:00
|
|
|
gboolean update_flags = 0, old_uids_valid = FALSE;
|
2006-05-12 19:42:48 +02:00
|
|
|
GHashTable *subject_table = NULL;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, -1);
|
2004-09-08 17:17:26 +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
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder != NULL, -1);
|
|
|
|
cm_return_val_if_fail(folder->klass->get_num_list != NULL, -1);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2007-12-03 18:32:15 +01:00
|
|
|
item->scanning = ITEM_SCANNING_WITH_FLAGS;
|
2006-05-19 19:09:06 +02:00
|
|
|
|
2005-10-27 14:38:11 +02:00
|
|
|
debug_print("Scanning folder %s for cache changes.\n", item->path ? item->path : "(null)");
|
2006-05-12 19:42:48 +02:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
/* Get list of messages for folder and cache */
|
2003-08-21 22:08:27 +02:00
|
|
|
if (folder->klass->get_num_list(item->folder, item, &folder_list, &old_uids_valid) < 0) {
|
2002-10-18 12:02:51 +02:00
|
|
|
debug_print("Error fetching list of message numbers\n");
|
2007-12-03 18:32:15 +01:00
|
|
|
item->scanning = ITEM_NOT_SCANNING;
|
2004-09-08 17:17:26 +02:00
|
|
|
return(-1);
|
2002-10-18 12:02:51 +02:00
|
|
|
}
|
|
|
|
|
2006-05-12 19:42:48 +02:00
|
|
|
if(prefs_common.thread_by_subject) {
|
|
|
|
subject_table = g_hash_table_new(g_str_hash, g_str_equal);
|
|
|
|
}
|
|
|
|
|
2003-08-21 22:08:27 +02:00
|
|
|
if (old_uids_valid) {
|
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();
|
2009-03-27 20:03:29 +01:00
|
|
|
item->cache_dirty = TRUE;
|
|
|
|
item->mark_dirty = TRUE;
|
|
|
|
item->tags_dirty = TRUE;
|
2002-06-30 01:33:42 +02:00
|
|
|
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;
|
|
|
|
|
2003-03-12 16:40:51 +01:00
|
|
|
switch(FOLDER_TYPE(folder)) {
|
2002-08-22 15:32:16 +02:00
|
|
|
case F_NEWS:
|
2002-09-10 15:25:04 +02:00
|
|
|
if (folder_cur_num < cache_max_num)
|
|
|
|
break;
|
|
|
|
|
2003-02-19 16:58:09 +01:00
|
|
|
if (folder->account->max_articles == 0) {
|
2002-09-10 15:25:04 +02:00
|
|
|
add = TRUE;
|
|
|
|
}
|
|
|
|
|
2003-02-19 16:58:09 +01:00
|
|
|
if (folder_max_num <= folder->account->max_articles) {
|
2002-09-10 15:25:04 +02:00
|
|
|
add = TRUE;
|
2003-02-19 16:58:09 +01:00
|
|
|
} else if (folder_cur_num > (folder_max_num - folder->account->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 */
|
2008-06-11 07:48:59 +02:00
|
|
|
if (folder_list_cur)
|
|
|
|
folder_list_cur = folder_list_cur->next;
|
2002-09-10 15:06:50 +02:00
|
|
|
|
|
|
|
if (folder_list_cur != NULL)
|
|
|
|
folder_cur_num = GPOINTER_TO_INT(folder_list_cur->data);
|
|
|
|
else
|
|
|
|
folder_cur_num = G_MAXINT;
|
|
|
|
|
|
|
|
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 */
|
2008-06-11 07:48:59 +02:00
|
|
|
if (cache_list_cur)
|
|
|
|
cache_list_cur = cache_list_cur->next;
|
2002-09-10 15:06:50 +02:00
|
|
|
|
|
|
|
if (cache_list_cur != NULL)
|
|
|
|
cache_cur_num = ((MsgInfo *)cache_list_cur->data)->msgnum;
|
|
|
|
else
|
|
|
|
cache_cur_num = G_MAXINT;
|
|
|
|
|
2003-01-07 22:49:44 +01:00
|
|
|
update_flags |= F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT;
|
2002-11-09 17:35:13 +01:00
|
|
|
|
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);
|
2009-02-22 19:47:11 +01:00
|
|
|
if (msginfo && folder->klass->is_msg_changed && folder->klass->is_msg_changed(folder, item, msginfo)) {
|
2002-06-30 01:33:42 +02:00
|
|
|
msgcache_remove_msg(item->cache, msginfo->msgnum);
|
2003-02-25 17:28:14 +01:00
|
|
|
new_list = g_slist_prepend(new_list, GINT_TO_POINTER(msginfo->msgnum));
|
|
|
|
procmsg_msginfo_free(msginfo);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2003-02-25 17:28:14 +01:00
|
|
|
debug_print("Remembering message %d to update...\n", folder_cur_num);
|
2009-02-22 19:47:11 +01:00
|
|
|
} else if (msginfo) {
|
2003-02-25 17:28:14 +01:00
|
|
|
exists_list = g_slist_prepend(exists_list, msginfo);
|
2002-09-10 15:06:50 +02:00
|
|
|
|
2006-05-12 19:42:48 +02:00
|
|
|
if(prefs_common.thread_by_subject &&
|
|
|
|
MSG_IS_IGNORE_THREAD(msginfo->flags) &&
|
|
|
|
!subject_table_lookup(subject_table, msginfo->subject)) {
|
|
|
|
subject_table_insert(subject_table, msginfo->subject, msginfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-10 15:06:50 +02:00
|
|
|
/* Move to next folder and cache number */
|
2008-06-11 07:48:59 +02:00
|
|
|
if (cache_list_cur)
|
|
|
|
cache_list_cur = cache_list_cur->next;
|
|
|
|
|
|
|
|
if (folder_list_cur)
|
|
|
|
folder_list_cur = folder_list_cur->next;
|
2002-09-10 15:06:50 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
continue;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
}
|
2003-02-25 17:28:14 +01:00
|
|
|
|
|
|
|
for(cache_list_cur = cache_list; cache_list_cur != NULL; cache_list_cur = g_slist_next(cache_list_cur))
|
2002-09-10 15:06:50 +02:00
|
|
|
procmsg_msginfo_free((MsgInfo *) cache_list_cur->data);
|
|
|
|
|
|
|
|
g_slist_free(cache_list);
|
|
|
|
g_slist_free(folder_list);
|
|
|
|
|
2003-02-25 17:28:14 +01:00
|
|
|
if (new_list != NULL) {
|
2005-10-04 18:31:25 +02:00
|
|
|
GSList *tmp_list = NULL;
|
2004-06-25 10:05:09 +02:00
|
|
|
newmsg_list = get_msginfos(item, new_list);
|
2003-02-25 17:28:14 +01:00
|
|
|
g_slist_free(new_list);
|
2005-10-04 18:31:25 +02:00
|
|
|
tmp_list = g_slist_concat(g_slist_copy(exists_list), g_slist_copy(newmsg_list));
|
|
|
|
syncronize_flags(item, tmp_list);
|
|
|
|
g_slist_free(tmp_list);
|
|
|
|
} else {
|
|
|
|
syncronize_flags(item, exists_list);
|
2003-02-25 17:28:14 +01:00
|
|
|
}
|
|
|
|
|
2003-07-16 18:54:16 +02:00
|
|
|
folder_item_update_freeze();
|
2007-12-03 18:32:15 +01:00
|
|
|
|
|
|
|
item->scanning = ITEM_SCANNING;
|
|
|
|
|
2003-02-25 17:28:14 +01:00
|
|
|
if (newmsg_list != NULL) {
|
2006-02-06 19:02:18 +01:00
|
|
|
GSList *elem, *to_filter = NULL;
|
2006-08-30 20:29:32 +02:00
|
|
|
gboolean do_filter = (filtering == TRUE) &&
|
|
|
|
(item->stype == F_INBOX) &&
|
|
|
|
(item->folder->account != NULL) &&
|
|
|
|
(item->folder->account->filter_on_recv);
|
2005-07-10 06:09:06 +02:00
|
|
|
|
2003-04-08 22:47:42 +02:00
|
|
|
for (elem = newmsg_list; elem != NULL; elem = g_slist_next(elem)) {
|
|
|
|
MsgInfo *msginfo = (MsgInfo *) elem->data;
|
|
|
|
|
|
|
|
msgcache_add_msg(item->cache, msginfo);
|
2006-08-30 20:29:32 +02:00
|
|
|
if (!do_filter) {
|
2003-04-08 22:47:42 +02:00
|
|
|
exists_list = g_slist_prepend(exists_list, msginfo);
|
2006-08-30 20:29:32 +02:00
|
|
|
|
2006-05-12 19:42:48 +02:00
|
|
|
if(prefs_common.thread_by_subject &&
|
|
|
|
MSG_IS_IGNORE_THREAD(msginfo->flags) &&
|
|
|
|
!subject_table_lookup(subject_table, msginfo->subject)) {
|
|
|
|
subject_table_insert(subject_table, msginfo->subject, msginfo);
|
2006-08-30 20:29:32 +02:00
|
|
|
}
|
2006-05-12 19:42:48 +02:00
|
|
|
}
|
2003-04-08 22:47:42 +02:00
|
|
|
}
|
2006-02-06 19:02:18 +01:00
|
|
|
|
2006-08-30 20:29:32 +02:00
|
|
|
if (do_filter) {
|
|
|
|
GSList *unfiltered;
|
2007-11-27 19:28:40 +01:00
|
|
|
|
|
|
|
folder_item_set_batch(item, TRUE);
|
2006-08-30 20:29:32 +02:00
|
|
|
procmsg_msglist_filter(newmsg_list, item->folder->account,
|
|
|
|
&to_filter, &unfiltered,
|
|
|
|
TRUE);
|
2007-11-27 19:28:40 +01:00
|
|
|
folder_item_set_batch(item, FALSE);
|
2006-08-30 20:29:32 +02:00
|
|
|
|
2006-10-03 12:19:12 +02:00
|
|
|
filtering_move_and_copy_msgs(newmsg_list);
|
2006-08-30 20:29:32 +02:00
|
|
|
if (to_filter != NULL) {
|
|
|
|
for (elem = to_filter; elem; elem = g_slist_next(elem)) {
|
|
|
|
MsgInfo *msginfo = (MsgInfo *)elem->data;
|
|
|
|
procmsg_msginfo_free(msginfo);
|
|
|
|
}
|
|
|
|
g_slist_free(to_filter);
|
|
|
|
}
|
|
|
|
if (unfiltered != NULL) {
|
|
|
|
for (elem = unfiltered; elem; elem = g_slist_next(elem)) {
|
|
|
|
MsgInfo *msginfo = (MsgInfo *)elem->data;
|
|
|
|
exists_list = g_slist_prepend(exists_list, msginfo);
|
|
|
|
|
|
|
|
if(prefs_common.thread_by_subject &&
|
|
|
|
MSG_IS_IGNORE_THREAD(msginfo->flags) &&
|
|
|
|
!subject_table_lookup(subject_table, msginfo->subject)) {
|
|
|
|
subject_table_insert(subject_table, msginfo->subject, msginfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_slist_free(unfiltered);
|
|
|
|
}
|
2007-04-03 09:08:26 +02:00
|
|
|
if (prefs_common.real_time_sync)
|
|
|
|
folder_item_synchronise(item);
|
|
|
|
} else {
|
|
|
|
if (prefs_common.real_time_sync)
|
|
|
|
folder_item_synchronise(item);
|
|
|
|
}
|
2006-08-30 20:29:32 +02:00
|
|
|
|
2003-04-08 22:47:42 +02:00
|
|
|
g_slist_free(newmsg_list);
|
2003-02-25 17:28:14 +01:00
|
|
|
|
|
|
|
update_flags |= F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
2005-07-21 17:46:34 +02:00
|
|
|
folder_item_set_batch(item, TRUE);
|
2003-02-25 17:28:14 +01:00
|
|
|
for (elem = exists_list; elem != NULL; elem = g_slist_next(elem)) {
|
2006-05-12 19:42:48 +02:00
|
|
|
MsgInfo *msginfo, *parent_msginfo;
|
2003-02-25 17:28:14 +01:00
|
|
|
|
|
|
|
msginfo = elem->data;
|
2003-03-19 19:39:42 +01:00
|
|
|
if (MSG_IS_IGNORE_THREAD(msginfo->flags) && (MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)))
|
|
|
|
procmsg_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
|
|
|
|
if (!MSG_IS_IGNORE_THREAD(msginfo->flags) && procmsg_msg_has_flagged_parent(msginfo, MSG_IGNORE_THREAD)) {
|
2005-08-19 08:06:58 +02:00
|
|
|
procmsg_msginfo_change_flags(msginfo, MSG_IGNORE_THREAD, 0, MSG_NEW | MSG_UNREAD, 0);
|
2003-03-19 19:39:42 +01:00
|
|
|
}
|
2007-07-27 16:19:05 +02:00
|
|
|
if (!MSG_IS_WATCH_THREAD(msginfo->flags) && procmsg_msg_has_flagged_parent(msginfo, MSG_WATCH_THREAD)) {
|
|
|
|
procmsg_msginfo_set_flags(msginfo, MSG_WATCH_THREAD, 0);
|
|
|
|
}
|
2006-05-12 19:42:48 +02:00
|
|
|
if(prefs_common.thread_by_subject && !msginfo->inreplyto &&
|
|
|
|
!msginfo->references && !MSG_IS_IGNORE_THREAD(msginfo->flags) &&
|
|
|
|
(parent_msginfo = subject_table_lookup(subject_table, msginfo->subject)))
|
|
|
|
{
|
|
|
|
if(MSG_IS_IGNORE_THREAD(parent_msginfo->flags)) {
|
|
|
|
procmsg_msginfo_change_flags(msginfo, MSG_IGNORE_THREAD, 0,
|
|
|
|
MSG_NEW | MSG_UNREAD, 0);
|
|
|
|
}
|
|
|
|
}
|
2005-08-07 15:39:27 +02:00
|
|
|
if ((folder_has_parent_of_type(item, F_OUTBOX) ||
|
|
|
|
folder_has_parent_of_type(item, F_QUEUE) ||
|
|
|
|
folder_has_parent_of_type(item, F_DRAFT) ||
|
|
|
|
folder_has_parent_of_type(item, F_TRASH)) &&
|
2003-03-20 15:44:47 +01:00
|
|
|
(MSG_IS_NEW(msginfo->flags) || MSG_IS_UNREAD(msginfo->flags)))
|
|
|
|
procmsg_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
|
2003-03-18 19:24:34 +01:00
|
|
|
if (MSG_IS_NEW(msginfo->flags))
|
2003-02-25 17:28:14 +01:00
|
|
|
newcnt++;
|
2003-03-18 19:24:34 +01:00
|
|
|
if (MSG_IS_UNREAD(msginfo->flags))
|
2003-02-25 17:28:14 +01:00
|
|
|
unreadcnt++;
|
|
|
|
if (MSG_IS_UNREAD(msginfo->flags) && procmsg_msg_has_marked_parent(msginfo))
|
|
|
|
unreadmarkedcnt++;
|
2005-07-01 19:33:02 +02:00
|
|
|
if (MSG_IS_MARKED(msginfo->flags))
|
|
|
|
markedcnt++;
|
2008-03-12 07:22:29 +01:00
|
|
|
if (MSG_IS_REPLIED(msginfo->flags))
|
|
|
|
repliedcnt++;
|
|
|
|
if (MSG_IS_FORWARDED(msginfo->flags))
|
|
|
|
forwardedcnt++;
|
|
|
|
if (MSG_IS_LOCKED(msginfo->flags))
|
|
|
|
lockedcnt++;
|
|
|
|
if (MSG_IS_IGNORE_THREAD(msginfo->flags))
|
|
|
|
ignoredcnt++;
|
|
|
|
if (MSG_IS_WATCH_THREAD(msginfo->flags))
|
|
|
|
watchedcnt++;
|
2005-07-01 19:33:02 +02:00
|
|
|
|
2003-02-25 17:28:14 +01:00
|
|
|
totalcnt++;
|
|
|
|
|
|
|
|
procmsg_msginfo_free(msginfo);
|
|
|
|
}
|
2005-07-21 17:46:34 +02:00
|
|
|
folder_item_set_batch(item, FALSE);
|
2003-02-25 17:28:14 +01:00
|
|
|
g_slist_free(exists_list);
|
2006-05-12 19:42:48 +02:00
|
|
|
|
|
|
|
if(prefs_common.thread_by_subject) {
|
|
|
|
g_hash_table_destroy(subject_table);
|
|
|
|
}
|
|
|
|
|
2006-07-06 18:34:05 +02:00
|
|
|
if (item->new_msgs != newcnt || item->unread_msgs != unreadcnt
|
|
|
|
|| item->total_msgs != totalcnt || item->marked_msgs != markedcnt
|
2008-03-12 07:22:29 +01:00
|
|
|
|| item->unreadmarked_msgs != unreadmarkedcnt
|
|
|
|
|| item->replied_msgs != repliedcnt || item->forwarded_msgs != forwardedcnt
|
|
|
|
|| item->locked_msgs != lockedcnt || item->ignored_msgs != ignoredcnt
|
|
|
|
|| item->watched_msgs != watchedcnt) {
|
2006-07-06 18:34:05 +02:00
|
|
|
update_flags |= F_ITEM_UPDATE_CONTENT;
|
|
|
|
}
|
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
item->new_msgs = newcnt;
|
|
|
|
item->unread_msgs = unreadcnt;
|
|
|
|
item->total_msgs = totalcnt;
|
|
|
|
item->unreadmarked_msgs = unreadmarkedcnt;
|
2005-07-01 19:33:02 +02:00
|
|
|
item->marked_msgs = markedcnt;
|
2008-03-12 07:22:29 +01:00
|
|
|
item->replied_msgs = repliedcnt;
|
|
|
|
item->forwarded_msgs = forwardedcnt;
|
|
|
|
item->locked_msgs = lockedcnt;
|
|
|
|
item->ignored_msgs = ignoredcnt;
|
|
|
|
item->watched_msgs = watchedcnt;
|
2003-02-25 17:28:14 +01:00
|
|
|
|
|
|
|
update_flags |= F_ITEM_UPDATE_MSGCNT;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2003-01-07 22:49:44 +01:00
|
|
|
folder_item_update(item, update_flags);
|
2003-06-26 22:33:05 +02:00
|
|
|
folder_item_update_thaw();
|
2006-05-12 19:42:48 +02:00
|
|
|
|
2007-12-03 18:32:15 +01:00
|
|
|
item->scanning = ITEM_NOT_SCANNING;
|
2006-05-19 19:09:06 +02:00
|
|
|
|
2004-09-08 17:17:26 +02:00
|
|
|
return 0;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2003-06-18 16:01:40 +02:00
|
|
|
gint folder_item_scan(FolderItem *item)
|
|
|
|
{
|
|
|
|
return folder_item_scan_full(item, TRUE);
|
|
|
|
}
|
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static void folder_count_total_cache_memusage(FolderItem *item, gpointer data)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static gint folder_cache_time_compare_func(gconstpointer a, gconstpointer b)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
|
|
|
FolderItem *fa = (FolderItem *)a;
|
|
|
|
FolderItem *fb = (FolderItem *)b;
|
|
|
|
|
|
|
|
return (gint) (msgcache_get_last_access_time(fa->cache) - msgcache_get_last_access_time(fb->cache));
|
|
|
|
}
|
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static void folder_find_expired_caches(FolderItem *item, gpointer data)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
|
|
|
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);
|
2006-06-09 16:48:49 +02:00
|
|
|
|
2006-04-23 20:19:38 +02:00
|
|
|
if (difftime > expiretime && !item->opened && !item->processing_pending) {
|
2002-06-30 01:33:42 +02:00
|
|
|
*folder_item_list = g_slist_insert_sorted(*folder_item_list, item, folder_cache_time_compare_func);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-09 16:48:49 +02:00
|
|
|
gboolean folder_item_free_cache(FolderItem *item, gboolean force)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, TRUE);
|
2002-07-02 21:49:11 +02:00
|
|
|
|
2002-08-31 10:26:28 +02:00
|
|
|
if (item->cache == NULL)
|
2006-06-09 16:48:49 +02:00
|
|
|
return TRUE;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2006-06-09 16:48:49 +02:00
|
|
|
if (item->opened > 0 && !force)
|
|
|
|
return FALSE;
|
2002-08-01 22:50:31 +02:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
folder_item_write_cache(item);
|
|
|
|
msgcache_destroy(item->cache);
|
|
|
|
item->cache = NULL;
|
2006-06-09 16:48:49 +02:00
|
|
|
return TRUE;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
2005-08-02 09:26:13 +02:00
|
|
|
void folder_clean_cache_memory_force(void)
|
|
|
|
{
|
|
|
|
int old_cache_max_mem_usage = prefs_common.cache_max_mem_usage;
|
|
|
|
int old_cache_min_keep_time = prefs_common.cache_min_keep_time;
|
|
|
|
|
|
|
|
prefs_common.cache_max_mem_usage = 0;
|
|
|
|
prefs_common.cache_min_keep_time = 0;
|
|
|
|
|
2006-04-25 10:00:00 +02:00
|
|
|
folder_clean_cache_memory(NULL);
|
2005-08-02 09:26:13 +02:00
|
|
|
|
|
|
|
prefs_common.cache_max_mem_usage = old_cache_max_mem_usage;
|
|
|
|
prefs_common.cache_min_keep_time = old_cache_min_keep_time;
|
|
|
|
}
|
|
|
|
|
2006-04-25 10:00:00 +02:00
|
|
|
void folder_clean_cache_memory(FolderItem *protected_item)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
|
|
|
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);
|
2006-06-09 16:48:49 +02:00
|
|
|
gint cache_size = 0;
|
2006-04-26 00:39:57 +02:00
|
|
|
if (item == protected_item) {
|
|
|
|
listitem = listitem->next;
|
2006-04-25 10:00:00 +02:00
|
|
|
continue;
|
2006-04-26 00:39:57 +02:00
|
|
|
}
|
2005-05-05 19:31:15 +02:00
|
|
|
debug_print("Freeing cache memory for %s\n", item->path ? item->path : item->name);
|
2006-06-09 16:48:49 +02:00
|
|
|
cache_size = msgcache_get_memory_usage(item->cache);
|
|
|
|
if (folder_item_free_cache(item, FALSE))
|
|
|
|
memusage -= cache_size;
|
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
listitem = listitem->next;
|
|
|
|
}
|
|
|
|
g_slist_free(folder_item_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-20 18:20:59 +02:00
|
|
|
static void folder_item_remove_cached_msg(FolderItem *item, MsgInfo *msginfo)
|
|
|
|
{
|
|
|
|
Folder *folder = item->folder;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(folder != NULL);
|
2007-07-20 18:20:59 +02:00
|
|
|
|
|
|
|
if (folder->klass->remove_cached_msg == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
folder->klass->remove_cached_msg(folder, item, msginfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void folder_item_clean_local_files(FolderItem *item, gint days)
|
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(item != NULL);
|
|
|
|
cm_return_if_fail(item->folder != NULL);
|
2007-07-20 18:20:59 +02:00
|
|
|
|
|
|
|
if (FOLDER_TYPE(item->folder) == F_IMAP ||
|
|
|
|
FOLDER_TYPE(item->folder) == F_NEWS) {
|
|
|
|
GSList *msglist = folder_item_get_msg_list(item);
|
|
|
|
GSList *cur;
|
|
|
|
time_t t = time(NULL);
|
|
|
|
for (cur = msglist; cur; cur = cur->next) {
|
|
|
|
MsgInfo *msginfo = (MsgInfo *)cur->data;
|
|
|
|
gint age = (t - msginfo->date_t) / (60*60*24);
|
|
|
|
if (age > days)
|
|
|
|
folder_item_remove_cached_msg(item, msginfo);
|
|
|
|
}
|
|
|
|
procmsg_msg_list_free(msglist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static void folder_item_read_cache(FolderItem *item)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
2007-07-02 18:35:40 +02:00
|
|
|
gchar *cache_file, *mark_file, *tags_file;
|
2006-09-23 15:31:18 +02:00
|
|
|
START_TIMING("");
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(item != NULL);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
if (item->path != NULL) {
|
|
|
|
cache_file = folder_item_get_cache_file(item);
|
|
|
|
mark_file = folder_item_get_mark_file(item);
|
2007-07-02 18:35:40 +02:00
|
|
|
tags_file = folder_item_get_tags_file(item);
|
2004-05-10 12:22:28 +02:00
|
|
|
item->cache = msgcache_read_cache(item, cache_file);
|
2009-03-27 20:03:29 +01:00
|
|
|
item->cache_dirty = FALSE;
|
|
|
|
item->mark_dirty = FALSE;
|
|
|
|
item->tags_dirty = FALSE;
|
2004-05-10 12:22:28 +02:00
|
|
|
if (!item->cache) {
|
2004-08-06 13:34:34 +02:00
|
|
|
MsgInfoList *list, *cur;
|
2005-07-01 19:33:02 +02:00
|
|
|
guint newcnt = 0, unreadcnt = 0;
|
|
|
|
guint markedcnt = 0, unreadmarkedcnt = 0;
|
2008-03-12 07:22:29 +01:00
|
|
|
guint repliedcnt = 0, forwardedcnt = 0;
|
|
|
|
guint lockedcnt = 0, ignoredcnt = 0;
|
|
|
|
guint watchedcnt = 0;
|
2004-08-06 13:34:34 +02:00
|
|
|
MsgInfo *msginfo;
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
item->cache = msgcache_new();
|
2009-03-27 20:03:29 +01:00
|
|
|
item->cache_dirty = TRUE;
|
|
|
|
item->mark_dirty = TRUE;
|
|
|
|
item->tags_dirty = TRUE;
|
2004-05-10 12:22:28 +02:00
|
|
|
folder_item_scan_full(item, TRUE);
|
2004-08-06 13:34:34 +02:00
|
|
|
|
|
|
|
msgcache_read_mark(item->cache, mark_file);
|
|
|
|
|
|
|
|
list = msgcache_get_msg_list(item->cache);
|
|
|
|
for (cur = list; cur != NULL; cur = g_slist_next(cur)) {
|
|
|
|
msginfo = cur->data;
|
|
|
|
|
|
|
|
if (MSG_IS_NEW(msginfo->flags))
|
|
|
|
newcnt++;
|
|
|
|
if (MSG_IS_UNREAD(msginfo->flags))
|
|
|
|
unreadcnt++;
|
|
|
|
if (MSG_IS_UNREAD(msginfo->flags) && procmsg_msg_has_marked_parent(msginfo))
|
|
|
|
unreadmarkedcnt++;
|
2005-07-01 19:33:02 +02:00
|
|
|
if (MSG_IS_MARKED(msginfo->flags))
|
|
|
|
markedcnt++;
|
2008-03-12 07:22:29 +01:00
|
|
|
if (MSG_IS_REPLIED(msginfo->flags))
|
|
|
|
repliedcnt++;
|
|
|
|
if (MSG_IS_FORWARDED(msginfo->flags))
|
|
|
|
forwardedcnt++;
|
|
|
|
if (MSG_IS_LOCKED(msginfo->flags))
|
|
|
|
lockedcnt++;
|
|
|
|
if (MSG_IS_IGNORE_THREAD(msginfo->flags))
|
|
|
|
ignoredcnt++;
|
|
|
|
if (MSG_IS_WATCH_THREAD(msginfo->flags))
|
|
|
|
watchedcnt++;
|
2007-09-22 14:00:27 +02:00
|
|
|
procmsg_msginfo_unset_flags(msginfo, MSG_FULLY_CACHED, 0);
|
2004-08-06 13:34:34 +02:00
|
|
|
}
|
|
|
|
item->new_msgs = newcnt;
|
|
|
|
item->unread_msgs = unreadcnt;
|
|
|
|
item->unreadmarked_msgs = unreadmarkedcnt;
|
2005-07-01 19:33:02 +02:00
|
|
|
item->marked_msgs = markedcnt;
|
2008-03-12 07:22:29 +01:00
|
|
|
item->replied_msgs = repliedcnt;
|
|
|
|
item->forwarded_msgs = forwardedcnt;
|
|
|
|
item->locked_msgs = lockedcnt;
|
|
|
|
item->ignored_msgs = ignoredcnt;
|
|
|
|
item->watched_msgs = watchedcnt;
|
2004-08-06 13:34:34 +02:00
|
|
|
procmsg_msg_list_free(list);
|
|
|
|
} else
|
|
|
|
msgcache_read_mark(item->cache, mark_file);
|
|
|
|
|
2007-07-02 18:35:40 +02:00
|
|
|
msgcache_read_tags(item->cache, tags_file);
|
|
|
|
|
2004-05-10 12:22:28 +02:00
|
|
|
g_free(cache_file);
|
|
|
|
g_free(mark_file);
|
2007-07-02 18:35:40 +02:00
|
|
|
g_free(tags_file);
|
2004-05-10 12:22:28 +02:00
|
|
|
} else {
|
2002-06-30 01:33:42 +02:00
|
|
|
item->cache = msgcache_new();
|
2009-03-27 20:03:29 +01:00
|
|
|
item->cache_dirty = TRUE;
|
|
|
|
item->mark_dirty = TRUE;
|
|
|
|
item->tags_dirty = TRUE;
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
2009-03-16 18:59:26 +01:00
|
|
|
|
2006-05-23 19:42:52 +02:00
|
|
|
END_TIMING();
|
2006-04-25 10:00:00 +02:00
|
|
|
folder_clean_cache_memory(item);
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void folder_item_write_cache(FolderItem *item)
|
|
|
|
{
|
2009-03-16 18:59:26 +01:00
|
|
|
gchar *cache_file = NULL, *mark_file = NULL, *tags_file = NULL;
|
2003-07-20 03:15:54 +02:00
|
|
|
FolderItemPrefs *prefs;
|
2002-06-30 01:33:42 +02:00
|
|
|
gint filemode = 0;
|
|
|
|
gchar *id;
|
2006-08-24 08:34:54 +02:00
|
|
|
time_t last_mtime = (time_t)0;
|
|
|
|
gboolean need_scan = FALSE;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
if (!item || !item->path || !item->cache)
|
|
|
|
return;
|
|
|
|
|
2007-09-26 09:53:13 +02:00
|
|
|
last_mtime = item->mtime;
|
2009-10-27 08:31:54 +01:00
|
|
|
if (item->folder->klass->set_mtime) {
|
|
|
|
if (item->folder->klass->scan_required)
|
|
|
|
need_scan = item->folder->klass->scan_required(item->folder, item);
|
|
|
|
else
|
|
|
|
need_scan = TRUE;
|
|
|
|
}
|
2006-08-24 08:34:54 +02:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
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);
|
|
|
|
|
2009-03-16 18:59:26 +01:00
|
|
|
if (item->cache_dirty)
|
|
|
|
cache_file = folder_item_get_cache_file(item);
|
|
|
|
if (item->cache_dirty || item->mark_dirty)
|
|
|
|
mark_file = folder_item_get_mark_file(item);
|
|
|
|
if (item->cache_dirty || item->tags_dirty)
|
|
|
|
tags_file = folder_item_get_tags_file(item);
|
2007-07-02 18:35:40 +02:00
|
|
|
if (msgcache_write(cache_file, mark_file, tags_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);
|
|
|
|
}
|
2009-03-16 18:59:26 +01:00
|
|
|
} else {
|
|
|
|
item->cache_dirty = FALSE;
|
|
|
|
item->mark_dirty = FALSE;
|
|
|
|
item->tags_dirty = FALSE;
|
|
|
|
}
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2007-09-26 09:53:13 +02:00
|
|
|
if (!need_scan && item->folder->klass->set_mtime) {
|
2006-09-30 21:36:06 +02:00
|
|
|
if (item->mtime == last_mtime) {
|
2007-09-26 09:53:13 +02:00
|
|
|
item->folder->klass->set_mtime(item->folder, item);
|
2006-09-30 21:36:06 +02:00
|
|
|
}
|
2006-08-24 08:34:54 +02:00
|
|
|
}
|
2006-08-22 18:28:00 +02:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
g_free(cache_file);
|
|
|
|
g_free(mark_file);
|
2007-07-02 18:35:40 +02:00
|
|
|
g_free(tags_file);
|
2002-06-30 01:33:42 +02:00
|
|
|
}
|
|
|
|
|
2002-11-16 20:53:47 +01:00
|
|
|
MsgInfo *folder_item_get_msginfo(FolderItem *item, gint num)
|
2002-06-30 01:33:42 +02:00
|
|
|
{
|
|
|
|
Folder *folder;
|
2004-06-25 10:05:09 +02:00
|
|
|
MsgInfo *msginfo = NULL;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return NULL;
|
2002-06-30 01:33:42 +02:00
|
|
|
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;
|
|
|
|
|
2004-06-25 10:05:09 +02:00
|
|
|
msginfo = get_msginfo(item, num);
|
|
|
|
if (msginfo != NULL) {
|
2002-07-10 15:11:25 +02:00
|
|
|
msgcache_add_msg(item->cache, msginfo);
|
|
|
|
return msginfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-11-16 20:53:47 +01:00
|
|
|
MsgInfo *folder_item_get_msginfo_by_msgid(FolderItem *item, const gchar *msgid)
|
2002-07-10 15:11:25 +02:00
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
MsgInfo *msginfo;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
|
|
|
cm_return_val_if_fail(msgid != NULL, NULL);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return FALSE;
|
2002-07-10 15:11:25 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return FALSE;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
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);
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item->cache != NULL, NULL);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
|
|
|
return msgcache_get_msg_list(item->cache);
|
|
|
|
}
|
|
|
|
|
2007-01-20 20:54:05 +01:00
|
|
|
static void msginfo_set_mime_flags(GNode *node, gpointer data)
|
2004-09-08 17:17:26 +02:00
|
|
|
{
|
|
|
|
MsgInfo *msginfo = data;
|
|
|
|
MimeInfo *mimeinfo = node->data;
|
2005-05-26 22:51:15 +02:00
|
|
|
|
2005-10-20 15:31:22 +02:00
|
|
|
if (mimeinfo->disposition == DISPOSITIONTYPE_ATTACHMENT
|
2009-05-06 08:46:58 +02:00
|
|
|
&& (!mimeinfo->subtype || (strcmp(mimeinfo->subtype, "pgp-signature") &&
|
|
|
|
strcmp(mimeinfo->subtype, "x-pkcs7-signature") &&
|
|
|
|
strcmp(mimeinfo->subtype, "pkcs7-signature")))) {
|
2004-09-08 17:17:26 +02:00
|
|
|
procmsg_msginfo_set_flags(msginfo, 0, MSG_HAS_ATTACHMENT);
|
|
|
|
} else if (mimeinfo->disposition == DISPOSITIONTYPE_UNKNOWN &&
|
|
|
|
mimeinfo->type != MIMETYPE_TEXT &&
|
|
|
|
mimeinfo->type != MIMETYPE_MULTIPART) {
|
2005-05-24 18:26:43 +02:00
|
|
|
if (!mimeinfo->subtype
|
2009-05-06 08:46:58 +02:00
|
|
|
|| (strcmp(mimeinfo->subtype, "pgp-signature") &&
|
|
|
|
strcmp(mimeinfo->subtype, "x-pkcs7-signature") &&
|
|
|
|
strcmp(mimeinfo->subtype, "pkcs7-signature")))
|
2005-05-24 18:26:43 +02:00
|
|
|
procmsg_msginfo_set_flags(msginfo, 0, MSG_HAS_ATTACHMENT);
|
2006-06-21 10:51:24 +02:00
|
|
|
} else if (mimeinfo->disposition == DISPOSITIONTYPE_INLINE &&
|
2009-05-06 08:46:58 +02:00
|
|
|
(strcmp(mimeinfo->subtype, "pgp-signature") &&
|
|
|
|
strcmp(mimeinfo->subtype, "x-pkcs7-signature") &&
|
|
|
|
strcmp(mimeinfo->subtype, "pkcs7-signature")) &&
|
2006-06-21 10:51:24 +02:00
|
|
|
(procmime_mimeinfo_get_parameter(mimeinfo, "name") != NULL ||
|
|
|
|
procmime_mimeinfo_get_parameter(mimeinfo, "filename") != NULL)) {
|
|
|
|
procmsg_msginfo_set_flags(msginfo, 0, MSG_HAS_ATTACHMENT);
|
|
|
|
}
|
2004-09-08 17:17:26 +02:00
|
|
|
|
|
|
|
/* don't descend below top level message for signed and encrypted info */
|
|
|
|
if (mimeinfo->type == MIMETYPE_MESSAGE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (privacy_mimeinfo_is_signed(mimeinfo)) {
|
|
|
|
procmsg_msginfo_set_flags(msginfo, 0, MSG_SIGNED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (privacy_mimeinfo_is_encrypted(mimeinfo)) {
|
|
|
|
procmsg_msginfo_set_flags(msginfo, 0, MSG_ENCRYPTED);
|
|
|
|
} else {
|
|
|
|
/* searching inside encrypted parts doesn't really make sense */
|
|
|
|
g_node_children_foreach(mimeinfo->node, G_TRAVERSE_ALL, msginfo_set_mime_flags, msginfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
gchar *folder_item_fetch_msg(FolderItem *item, gint num)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
2004-09-08 17:17:26 +02:00
|
|
|
gchar *msgfile;
|
|
|
|
MsgInfo *msginfo;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
folder = item->folder;
|
2001-05-23 14:08:40 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder->klass->fetch_msg != NULL, NULL);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return NULL;
|
2001-05-23 14:08:40 +02:00
|
|
|
|
2004-09-08 17:17:26 +02:00
|
|
|
msgfile = folder->klass->fetch_msg(folder, item, num);
|
|
|
|
|
2004-09-14 10:51:04 +02:00
|
|
|
if (msgfile != NULL) {
|
|
|
|
msginfo = folder_item_get_msginfo(item, num);
|
|
|
|
if ((msginfo != NULL) && !MSG_IS_SCANNED(msginfo->flags)) {
|
|
|
|
MimeInfo *mimeinfo;
|
|
|
|
|
2005-08-07 15:39:27 +02:00
|
|
|
if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
|
|
|
|
!folder_has_parent_of_type(msginfo->folder, F_DRAFT))
|
2004-09-14 10:51:04 +02:00
|
|
|
mimeinfo = procmime_scan_file(msgfile);
|
|
|
|
else
|
|
|
|
mimeinfo = procmime_scan_queue_file(msgfile);
|
|
|
|
/* check for attachments */
|
|
|
|
if (mimeinfo != NULL) {
|
|
|
|
g_node_children_foreach(mimeinfo->node, G_TRAVERSE_ALL, msginfo_set_mime_flags, msginfo);
|
|
|
|
procmime_mimeinfo_free_all(mimeinfo);
|
2004-09-08 17:17:26 +02:00
|
|
|
|
2004-09-14 10:51:04 +02:00
|
|
|
procmsg_msginfo_set_flags(msginfo, 0, MSG_SCANNED);
|
|
|
|
}
|
|
|
|
}
|
2006-06-02 19:06:33 +02:00
|
|
|
procmsg_msginfo_free(msginfo);
|
2004-09-08 17:17:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return msgfile;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2005-06-13 21:37:01 +02:00
|
|
|
gchar *folder_item_fetch_msg_full(FolderItem *item, gint num, gboolean headers,
|
|
|
|
gboolean body)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gchar *msgfile;
|
|
|
|
MsgInfo *msginfo;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return NULL;
|
2005-06-21 19:25:18 +02:00
|
|
|
|
2005-06-13 21:37:01 +02:00
|
|
|
folder = item->folder;
|
|
|
|
|
|
|
|
if (folder->klass->fetch_msg_full == NULL)
|
|
|
|
return folder_item_fetch_msg(item, num);
|
|
|
|
|
2007-04-26 08:49:39 +02:00
|
|
|
if (item->prefs->offlinesync && prefs_common.real_time_sync)
|
|
|
|
msgfile = folder->klass->fetch_msg_full(folder, item, num,
|
|
|
|
TRUE, TRUE);
|
|
|
|
else
|
|
|
|
msgfile = folder->klass->fetch_msg_full(folder, item, num,
|
2005-06-13 21:37:01 +02:00
|
|
|
headers, body);
|
|
|
|
|
|
|
|
if (msgfile != NULL) {
|
|
|
|
msginfo = folder_item_get_msginfo(item, num);
|
|
|
|
if ((msginfo != NULL) && !MSG_IS_SCANNED(msginfo->flags)) {
|
|
|
|
MimeInfo *mimeinfo;
|
|
|
|
|
2005-08-07 15:39:27 +02:00
|
|
|
if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
|
|
|
|
!folder_has_parent_of_type(msginfo->folder, F_DRAFT))
|
2005-06-13 21:37:01 +02:00
|
|
|
mimeinfo = procmime_scan_file(msgfile);
|
|
|
|
else
|
|
|
|
mimeinfo = procmime_scan_queue_file(msgfile);
|
|
|
|
/* check for attachments */
|
|
|
|
if (mimeinfo != NULL) {
|
|
|
|
g_node_children_foreach(mimeinfo->node, G_TRAVERSE_ALL, msginfo_set_mime_flags, msginfo);
|
|
|
|
procmime_mimeinfo_free_all(mimeinfo);
|
|
|
|
|
|
|
|
procmsg_msginfo_set_flags(msginfo, 0, MSG_SCANNED);
|
|
|
|
}
|
|
|
|
}
|
2006-06-02 19:06:33 +02:00
|
|
|
procmsg_msginfo_free(msginfo);
|
2005-06-13 21:37:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return msgfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-25 02:09:14 +01:00
|
|
|
static gint folder_item_get_msg_num_by_file(FolderItem *dest, const gchar *file)
|
|
|
|
{
|
|
|
|
static HeaderEntry hentry[] = {{"Message-ID:", NULL, TRUE},
|
|
|
|
{NULL, NULL, FALSE}};
|
|
|
|
FILE *fp;
|
|
|
|
MsgInfo *msginfo;
|
|
|
|
gint msgnum = 0;
|
|
|
|
gchar buf[BUFFSIZE];
|
|
|
|
|
2005-08-19 11:30:30 +02:00
|
|
|
if ((fp = g_fopen(file, "rb")) == NULL)
|
2003-01-25 02:09:14 +01:00
|
|
|
return 0;
|
|
|
|
|
2005-08-07 15:39:27 +02:00
|
|
|
if ((folder_has_parent_of_type(dest, F_QUEUE)) ||
|
2005-08-08 18:52:01 +02:00
|
|
|
(folder_has_parent_of_type(dest, F_DRAFT)))
|
2007-08-09 18:18:52 +02:00
|
|
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
|
|
|
/* new way */
|
|
|
|
if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
|
|
|
|
strlen("X-Claws-End-Special-Headers:"))) ||
|
|
|
|
(!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
|
|
|
|
strlen("X-Sylpheed-End-Special-Headers:"))))
|
|
|
|
break;
|
|
|
|
/* old way */
|
2003-01-25 02:09:14 +01:00
|
|
|
if (buf[0] == '\r' || buf[0] == '\n') break;
|
2007-08-09 18:18:52 +02:00
|
|
|
/* from other mailers */
|
|
|
|
if (!strncmp(buf, "Date: ", 6)
|
|
|
|
|| !strncmp(buf, "To: ", 4)
|
|
|
|
|| !strncmp(buf, "From: ", 6)
|
|
|
|
|| !strncmp(buf, "Subject: ", 9)) {
|
|
|
|
rewind(fp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-01-25 02:09:14 +01:00
|
|
|
|
|
|
|
procheader_get_header_fields(fp, hentry);
|
2007-08-09 18:18:52 +02:00
|
|
|
debug_print("looking for %s\n", hentry[0].body);
|
2003-01-25 02:09:14 +01:00
|
|
|
if (hentry[0].body) {
|
|
|
|
extract_parenthesis(hentry[0].body, '<', '>');
|
|
|
|
remove_space(hentry[0].body);
|
|
|
|
if ((msginfo = msgcache_get_msg_by_id(dest->cache, hentry[0].body)) != NULL) {
|
|
|
|
msgnum = msginfo->msgnum;
|
|
|
|
procmsg_msginfo_free(msginfo);
|
|
|
|
|
|
|
|
debug_print("found message as uid %d\n", msgnum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(hentry[0].body);
|
2003-01-27 20:43:29 +01:00
|
|
|
hentry[0].body = NULL;
|
2003-01-25 02:09:14 +01:00
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return msgnum;
|
|
|
|
}
|
|
|
|
|
2003-03-24 22:48:10 +01:00
|
|
|
static void copy_msginfo_flags(MsgInfo *source, MsgInfo *dest)
|
|
|
|
{
|
2003-03-27 13:19:56 +01:00
|
|
|
MsgPermFlags perm_flags = 0;
|
|
|
|
MsgTmpFlags tmp_flags = 0;
|
2003-03-24 22:48:10 +01:00
|
|
|
|
|
|
|
/* create new flags */
|
|
|
|
if (source != NULL) {
|
|
|
|
/* copy original flags */
|
2003-03-27 13:19:56 +01:00
|
|
|
perm_flags = source->flags.perm_flags;
|
|
|
|
tmp_flags = source->flags.tmp_flags;
|
2003-03-24 22:48:10 +01:00
|
|
|
} else {
|
2003-03-27 13:19:56 +01:00
|
|
|
perm_flags = dest->flags.perm_flags;
|
|
|
|
tmp_flags = dest->flags.tmp_flags;
|
2003-03-24 22:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remove new, unread and deleted in special folders */
|
2005-08-07 22:54:59 +02:00
|
|
|
if (folder_has_parent_of_type(dest->folder, F_OUTBOX) ||
|
|
|
|
folder_has_parent_of_type(dest->folder, F_QUEUE) ||
|
|
|
|
folder_has_parent_of_type(dest->folder, F_DRAFT) ||
|
|
|
|
folder_has_parent_of_type(dest->folder, F_TRASH))
|
2003-03-27 13:19:56 +01:00
|
|
|
perm_flags &= ~(MSG_NEW | MSG_UNREAD | MSG_DELETED);
|
2003-03-24 22:48:10 +01:00
|
|
|
|
|
|
|
/* set ignore flag of ignored parent exists */
|
|
|
|
if (procmsg_msg_has_flagged_parent(dest, MSG_IGNORE_THREAD))
|
2003-03-27 13:19:56 +01:00
|
|
|
perm_flags |= MSG_IGNORE_THREAD;
|
|
|
|
|
2007-09-22 14:00:27 +02:00
|
|
|
/* unset FULLY_CACHED flags */
|
|
|
|
perm_flags &= ~MSG_FULLY_CACHED;
|
|
|
|
|
2007-07-27 16:19:05 +02:00
|
|
|
if (procmsg_msg_has_flagged_parent(dest, MSG_WATCH_THREAD))
|
|
|
|
perm_flags |= MSG_WATCH_THREAD;
|
|
|
|
|
2003-03-27 13:19:56 +01:00
|
|
|
/* Unset tmp flags that should not be copied */
|
2006-08-25 19:02:15 +02:00
|
|
|
tmp_flags &= ~(MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
|
2003-03-27 13:19:56 +01:00
|
|
|
|
2003-03-24 22:48:10 +01:00
|
|
|
/* unset flags that are set but should not */
|
2005-08-19 08:06:58 +02:00
|
|
|
/* and set new flags */
|
|
|
|
procmsg_msginfo_change_flags(dest,
|
2003-03-27 13:19:56 +01:00
|
|
|
~dest->flags.perm_flags & perm_flags,
|
2005-08-19 08:06:58 +02:00
|
|
|
~dest->flags.tmp_flags & tmp_flags,
|
|
|
|
dest->flags.perm_flags & ~perm_flags,
|
|
|
|
dest->flags.tmp_flags & ~tmp_flags);
|
2007-07-02 18:35:40 +02:00
|
|
|
|
|
|
|
if (source && source->tags) {
|
|
|
|
g_slist_free(dest->tags);
|
|
|
|
dest->tags = g_slist_copy(source->tags);
|
2007-11-27 08:25:12 +01:00
|
|
|
folder_item_commit_tags(dest->folder, dest, dest->tags, NULL);
|
2007-07-02 18:35:40 +02:00
|
|
|
}
|
2003-03-24 22:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void add_msginfo_to_cache(FolderItem *item, MsgInfo *newmsginfo, MsgInfo *flagsource)
|
|
|
|
{
|
|
|
|
/* update folder stats */
|
|
|
|
if (MSG_IS_NEW(newmsginfo->flags))
|
2003-04-05 22:38:53 +02:00
|
|
|
item->new_msgs++;
|
2003-03-24 22:48:10 +01:00
|
|
|
if (MSG_IS_UNREAD(newmsginfo->flags))
|
2003-04-05 22:38:53 +02:00
|
|
|
item->unread_msgs++;
|
2003-03-24 22:48:10 +01:00
|
|
|
if (MSG_IS_UNREAD(newmsginfo->flags) && procmsg_msg_has_marked_parent(newmsginfo))
|
2003-04-05 22:38:53 +02:00
|
|
|
item->unreadmarked_msgs++;
|
2005-07-01 19:33:02 +02:00
|
|
|
if (MSG_IS_MARKED(newmsginfo->flags))
|
|
|
|
item->marked_msgs++;
|
2008-03-12 07:22:29 +01:00
|
|
|
if (MSG_IS_REPLIED(newmsginfo->flags))
|
|
|
|
item->replied_msgs++;
|
|
|
|
if (MSG_IS_FORWARDED(newmsginfo->flags))
|
|
|
|
item->forwarded_msgs++;
|
|
|
|
if (MSG_IS_LOCKED(newmsginfo->flags))
|
|
|
|
item->locked_msgs++;
|
|
|
|
if (MSG_IS_IGNORE_THREAD(newmsginfo->flags))
|
|
|
|
item->ignored_msgs++;
|
|
|
|
if (MSG_IS_WATCH_THREAD(newmsginfo->flags))
|
|
|
|
item->watched_msgs++;
|
2003-04-05 22:38:53 +02:00
|
|
|
item->total_msgs++;
|
2003-03-24 22:48:10 +01:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
folder_item_update_freeze();
|
2005-12-08 19:06:56 +01:00
|
|
|
|
|
|
|
if (!item->cache)
|
|
|
|
folder_item_read_cache(item);
|
|
|
|
|
2003-03-24 22:48:10 +01:00
|
|
|
msgcache_add_msg(item->cache, newmsginfo);
|
2004-01-12 22:28:31 +01:00
|
|
|
copy_msginfo_flags(flagsource, newmsginfo);
|
2004-06-25 10:05:09 +02:00
|
|
|
folder_item_update_with_msg(item, F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT | F_ITEM_UPDATE_ADDMSG, newmsginfo);
|
2004-01-12 22:28:31 +01:00
|
|
|
folder_item_update_thaw();
|
2003-03-24 22:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_msginfo_from_cache(FolderItem *item, MsgInfo *msginfo)
|
|
|
|
{
|
2003-09-05 23:07:17 +02:00
|
|
|
MsgInfoUpdate msginfo_update;
|
|
|
|
|
2003-03-24 22:48:10 +01:00
|
|
|
if (!item->cache)
|
2003-07-20 20:04:11 +02:00
|
|
|
folder_item_read_cache(item);
|
2003-03-24 22:48:10 +01:00
|
|
|
|
|
|
|
if (MSG_IS_NEW(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
|
2003-04-05 22:38:53 +02:00
|
|
|
msginfo->folder->new_msgs--;
|
2003-03-24 22:48:10 +01:00
|
|
|
if (MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags))
|
2003-04-05 22:38:53 +02:00
|
|
|
msginfo->folder->unread_msgs--;
|
2003-03-24 22:48:10 +01:00
|
|
|
if (MSG_IS_UNREAD(msginfo->flags) && procmsg_msg_has_marked_parent(msginfo))
|
2003-04-05 22:38:53 +02:00
|
|
|
msginfo->folder->unreadmarked_msgs--;
|
2005-07-01 19:33:02 +02:00
|
|
|
if (MSG_IS_MARKED(msginfo->flags))
|
|
|
|
item->marked_msgs--;
|
2008-03-12 07:22:29 +01:00
|
|
|
if (MSG_IS_REPLIED(msginfo->flags))
|
|
|
|
item->replied_msgs--;
|
|
|
|
if (MSG_IS_FORWARDED(msginfo->flags))
|
|
|
|
item->forwarded_msgs--;
|
|
|
|
if (MSG_IS_LOCKED(msginfo->flags))
|
|
|
|
item->locked_msgs--;
|
|
|
|
if (MSG_IS_IGNORE_THREAD(msginfo->flags))
|
|
|
|
item->ignored_msgs--;
|
|
|
|
if (MSG_IS_WATCH_THREAD(msginfo->flags))
|
|
|
|
item->watched_msgs--;
|
2005-07-01 19:33:02 +02:00
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
msginfo->folder->total_msgs--;
|
2003-03-24 22:48:10 +01:00
|
|
|
|
2003-09-05 23:07:17 +02:00
|
|
|
msginfo_update.msginfo = msginfo;
|
|
|
|
msginfo_update.flags = MSGINFO_UPDATE_DELETED;
|
|
|
|
hooks_invoke(MSGINFO_UPDATE_HOOKLIST, &msginfo_update);
|
|
|
|
|
2003-03-24 22:48:10 +01:00
|
|
|
msgcache_remove_msg(item->cache, msginfo->msgnum);
|
2004-06-25 10:05:09 +02:00
|
|
|
folder_item_update_with_msg(msginfo->folder, F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT | F_ITEM_UPDATE_REMOVEMSG, msginfo);
|
2003-03-24 22:48:10 +01:00
|
|
|
}
|
|
|
|
|
2001-05-17 15:25:31 +02:00
|
|
|
gint folder_item_add_msg(FolderItem *dest, const gchar *file,
|
2003-07-26 20:30:25 +02:00
|
|
|
MsgFlags *flags, gboolean remove_source)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2003-07-26 20:30:25 +02:00
|
|
|
GSList file_list;
|
|
|
|
MsgFileInfo fileinfo;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(dest != NULL, -1);
|
|
|
|
cm_return_val_if_fail(file != NULL, -1);
|
2003-07-26 20:30:25 +02:00
|
|
|
|
2003-07-29 00:30:01 +02:00
|
|
|
fileinfo.msginfo = NULL;
|
2003-07-26 20:30:25 +02:00
|
|
|
fileinfo.file = (gchar *)file;
|
|
|
|
fileinfo.flags = flags;
|
|
|
|
file_list.data = &fileinfo;
|
|
|
|
file_list.next = NULL;
|
2001-05-23 14:08:40 +02:00
|
|
|
|
2003-07-25 20:47:43 +02:00
|
|
|
return folder_item_add_msgs(dest, &file_list, remove_source);
|
|
|
|
}
|
2001-05-23 14:08:40 +02:00
|
|
|
|
2003-07-25 20:47:43 +02:00
|
|
|
gint folder_item_add_msgs(FolderItem *dest, GSList *file_list,
|
|
|
|
gboolean remove_source)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
gint ret, num, lastnum = -1;
|
|
|
|
GSList *file_cur;
|
2010-10-03 13:46:24 +02:00
|
|
|
GHashTable *relation;
|
2003-07-26 20:30:25 +02:00
|
|
|
MsgFileInfo *fileinfo = NULL;
|
2003-07-25 20:47:43 +02:00
|
|
|
gboolean folderscan = FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(dest != NULL, -1);
|
|
|
|
cm_return_val_if_fail(file_list != NULL, -1);
|
|
|
|
cm_return_val_if_fail(dest->folder != NULL, -1);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (dest->no_select)
|
|
|
|
return -1;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2003-07-25 20:47:43 +02:00
|
|
|
folder = dest->folder;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2010-10-03 13:46:24 +02:00
|
|
|
relation = g_hash_table_new(g_direct_hash, g_direct_equal);
|
2003-07-28 17:47:24 +02:00
|
|
|
|
2003-07-25 20:47:43 +02:00
|
|
|
if (folder->klass->add_msgs != NULL) {
|
2003-07-28 17:47:24 +02:00
|
|
|
ret = folder->klass->add_msgs(folder, dest, file_list, relation);
|
2003-07-25 20:47:43 +02:00
|
|
|
if (ret < 0) {
|
2010-10-03 13:46:24 +02:00
|
|
|
g_hash_table_destroy(relation);
|
2003-07-25 20:47:43 +02:00
|
|
|
return ret;
|
2002-07-28 01:57:07 +02:00
|
|
|
}
|
2003-07-25 20:47:43 +02:00
|
|
|
} else {
|
|
|
|
for (file_cur = file_list; file_cur != NULL; file_cur = g_slist_next(file_cur)) {
|
2003-07-26 20:30:25 +02:00
|
|
|
fileinfo = (MsgFileInfo *) file_cur->data;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2003-07-26 20:30:25 +02:00
|
|
|
ret = folder->klass->add_msg(folder, dest, fileinfo->file, fileinfo->flags);
|
2003-07-25 20:47:43 +02:00
|
|
|
if (ret < 0) {
|
2010-10-03 13:46:24 +02:00
|
|
|
g_hash_table_destroy(relation);
|
2003-07-25 20:47:43 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2010-10-03 13:46:24 +02:00
|
|
|
g_hash_table_insert(relation, fileinfo, GINT_TO_POINTER(ret));
|
2003-07-25 20:47:43 +02:00
|
|
|
}
|
2003-01-25 02:09:14 +01:00
|
|
|
}
|
|
|
|
|
2003-07-28 17:47:24 +02:00
|
|
|
for (file_cur = file_list; file_cur != NULL; file_cur = g_slist_next(file_cur)) {
|
2010-10-03 13:46:24 +02:00
|
|
|
gpointer data, old_key;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-07-26 20:30:25 +02:00
|
|
|
fileinfo = (MsgFileInfo *) file_cur->data;
|
2010-10-03 13:46:24 +02:00
|
|
|
if (g_hash_table_lookup_extended(relation, fileinfo, &old_key, &data))
|
|
|
|
num = GPOINTER_TO_INT(data);
|
|
|
|
else
|
|
|
|
num = -1;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2003-07-25 20:47:43 +02:00
|
|
|
if (num >= 0) {
|
|
|
|
MsgInfo *newmsginfo;
|
2003-07-23 16:51:47 +02:00
|
|
|
|
2003-07-25 20:47:43 +02:00
|
|
|
if (num == 0) {
|
|
|
|
if (!folderscan) {
|
|
|
|
folder_item_scan_full(dest, FALSE);
|
|
|
|
folderscan = TRUE;
|
|
|
|
}
|
2003-07-26 20:30:25 +02:00
|
|
|
num = folder_item_get_msg_num_by_file(dest, fileinfo->file);
|
2007-08-09 18:18:52 +02:00
|
|
|
debug_print("got num %d\n", num);
|
2003-07-25 20:47:43 +02:00
|
|
|
}
|
2003-07-23 16:51:47 +02:00
|
|
|
|
2003-07-25 20:47:43 +02:00
|
|
|
if (num > lastnum)
|
|
|
|
lastnum = num;
|
2003-07-23 16:51:47 +02:00
|
|
|
|
2003-07-25 20:47:43 +02:00
|
|
|
if (num >= 0 && remove_source) {
|
2008-04-18 18:26:05 +02:00
|
|
|
if (claws_unlink(fileinfo->file) < 0)
|
2003-07-26 20:30:25 +02:00
|
|
|
FILE_OP_ERROR(fileinfo->file, "unlink");
|
2003-07-25 20:47:43 +02:00
|
|
|
}
|
2003-07-23 16:51:47 +02:00
|
|
|
|
2003-07-25 20:47:43 +02:00
|
|
|
if (num == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!folderscan &&
|
2004-06-25 10:05:09 +02:00
|
|
|
((newmsginfo = get_msginfo(dest, num)) != NULL)) {
|
2003-07-25 20:47:43 +02:00
|
|
|
add_msginfo_to_cache(dest, newmsginfo, NULL);
|
|
|
|
procmsg_msginfo_free(newmsginfo);
|
|
|
|
} else if ((newmsginfo = msgcache_get_msg(dest->cache, num)) != NULL) {
|
|
|
|
/* TODO: set default flags */
|
|
|
|
procmsg_msginfo_free(newmsginfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-03 13:46:24 +02:00
|
|
|
g_hash_table_destroy(relation);
|
2003-07-25 20:47:43 +02:00
|
|
|
|
|
|
|
return lastnum;
|
2003-07-23 16:51:47 +02:00
|
|
|
}
|
2006-12-26 23:37:41 +01:00
|
|
|
|
2006-12-26 22:34:00 +01:00
|
|
|
static FolderItem *folder_item_move_recursive(FolderItem *src, FolderItem *dest, gboolean copy)
|
2002-11-07 00:56:26 +01:00
|
|
|
{
|
|
|
|
GSList *mlist;
|
|
|
|
FolderItem *new_item;
|
|
|
|
FolderItem *next_item;
|
|
|
|
GNode *srcnode;
|
2002-11-27 16:06:54 +01:00
|
|
|
gchar *old_id, *new_id;
|
2004-09-08 17:17:26 +02:00
|
|
|
|
2002-11-07 00:56:26 +01:00
|
|
|
/* move messages */
|
2006-12-26 22:34:00 +01:00
|
|
|
debug_print("%s %s to %s\n", copy?"Copying":"Moving", src->path, dest->path);
|
2004-06-25 10:05:09 +02:00
|
|
|
new_item = folder_create_folder(dest, src->name);
|
2002-11-07 00:56:26 +01:00
|
|
|
if (new_item == NULL) {
|
2007-08-21 11:17:38 +02:00
|
|
|
g_print("Can't create folder\n");
|
2004-09-08 17:17:26 +02:00
|
|
|
return NULL;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
|
2002-11-08 16:42:57 +01:00
|
|
|
if (new_item->folder == NULL)
|
|
|
|
new_item->folder = dest->folder;
|
|
|
|
|
|
|
|
/* move messages */
|
2007-03-21 16:00:46 +01:00
|
|
|
log_message(LOG_PROTOCOL, copy ?_("Copying %s to %s...\n"):_("Moving %s to %s...\n"),
|
2003-03-21 18:28:52 +01:00
|
|
|
src->name, new_item->path);
|
2005-08-02 09:26:13 +02:00
|
|
|
|
|
|
|
mlist = folder_item_get_msg_list(src);
|
|
|
|
|
|
|
|
if (mlist != NULL) {
|
2006-12-26 22:34:00 +01:00
|
|
|
if (copy)
|
|
|
|
folder_item_copy_msgs(new_item, mlist);
|
|
|
|
else
|
|
|
|
folder_item_move_msgs(new_item, mlist);
|
2005-08-02 09:26:13 +02:00
|
|
|
procmsg_msg_list_free(mlist);
|
|
|
|
}
|
2002-11-08 16:42:57 +01:00
|
|
|
|
|
|
|
/*copy prefs*/
|
2003-07-20 03:15:54 +02:00
|
|
|
folder_item_prefs_copy_prefs(src, new_item);
|
2006-10-31 19:44:35 +01:00
|
|
|
|
|
|
|
/* copy internal data */
|
|
|
|
if (src->folder->klass == new_item->folder->klass &&
|
|
|
|
src->folder->klass->copy_private_data != NULL)
|
|
|
|
src->folder->klass->copy_private_data(src->folder,
|
|
|
|
src, new_item);
|
2002-11-08 16:57:21 +01:00
|
|
|
new_item->collapsed = src->collapsed;
|
2003-01-25 02:30:03 +01:00
|
|
|
new_item->thread_collapsed = src->thread_collapsed;
|
2002-11-08 16:57:21 +01:00
|
|
|
new_item->threaded = src->threaded;
|
|
|
|
new_item->ret_rcpt = src->ret_rcpt;
|
|
|
|
new_item->hide_read_msgs = src->hide_read_msgs;
|
2009-03-30 19:20:02 +02:00
|
|
|
new_item->hide_del_msgs = src->hide_del_msgs;
|
2002-11-08 16:57:21 +01:00
|
|
|
new_item->sort_key = src->sort_key;
|
|
|
|
new_item->sort_type = src->sort_type;
|
2002-11-08 16:42:57 +01:00
|
|
|
|
2002-11-09 22:43:51 +01:00
|
|
|
prefs_matcher_write_config();
|
|
|
|
|
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-27 14:21:07 +01:00
|
|
|
srcnode = srcnode->next;
|
2006-12-26 22:34:00 +01:00
|
|
|
if (folder_item_move_recursive(next_item, new_item, copy) == NULL) {
|
2004-09-08 17:17:26 +02:00
|
|
|
return NULL;
|
2005-08-02 09:26:13 +02:00
|
|
|
}
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
}
|
2002-11-27 16:06:54 +01:00
|
|
|
old_id = folder_item_get_identifier(src);
|
|
|
|
new_id = folder_item_get_identifier(new_item);
|
2004-06-25 10:05:09 +02:00
|
|
|
|
|
|
|
/* if src supports removing, otherwise only copy folder */
|
2006-12-26 22:34:00 +01:00
|
|
|
if (src->folder->klass->remove_folder != NULL && !copy)
|
2004-06-25 10:05:09 +02:00
|
|
|
src->folder->klass->remove_folder(src->folder, src);
|
2002-11-27 16:06:54 +01:00
|
|
|
folder_write_list();
|
|
|
|
|
2006-12-30 15:22:02 +01:00
|
|
|
if (!copy) {
|
|
|
|
debug_print("updating rules : %s => %s\n", old_id, new_id);
|
|
|
|
if (old_id != NULL && new_id != NULL) {
|
|
|
|
prefs_filtering_rename_path(old_id, new_id);
|
|
|
|
account_rename_path(old_id, new_id);
|
|
|
|
}
|
2006-01-16 11:43:57 +01:00
|
|
|
}
|
2002-11-27 16:06:54 +01:00
|
|
|
g_free(old_id);
|
|
|
|
g_free(new_id);
|
2005-08-02 09:26:13 +02:00
|
|
|
|
2004-09-08 17:17:26 +02:00
|
|
|
return new_item;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
|
2006-12-26 22:34:00 +01:00
|
|
|
gint folder_item_move_to(FolderItem *src, FolderItem *dest, FolderItem **new_item, gboolean copy)
|
2002-11-07 00:56:26 +01:00
|
|
|
{
|
2004-02-21 12:01:01 +01:00
|
|
|
FolderItem *tmp = folder_item_parent(dest);
|
2002-12-02 18:41:39 +01:00
|
|
|
gchar * src_identifier, * dst_identifier;
|
2006-06-02 19:06:33 +02:00
|
|
|
gchar * phys_srcpath, * phys_dstpath, *tmppath;
|
2006-12-26 22:34:00 +01:00
|
|
|
|
2002-11-07 00:56:26 +01:00
|
|
|
while (tmp) {
|
|
|
|
if (tmp == src) {
|
2002-11-15 20:51:25 +01:00
|
|
|
return F_MOVE_FAILED_DEST_IS_CHILD;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
2005-06-21 19:25:18 +02:00
|
|
|
tmp = folder_item_parent(tmp);
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
tmp = folder_item_parent(src);
|
2002-11-07 00:56:26 +01:00
|
|
|
|
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
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
if(dst_identifier == NULL && dest->folder && folder_item_parent(dest) == 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) {
|
2003-03-14 02:38:17 +01:00
|
|
|
debug_print("Can't get identifiers\n");
|
2002-11-15 20:51:25 +01:00
|
|
|
return F_MOVE_FAILED;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
|
2006-12-26 22:34:00 +01:00
|
|
|
if (src->folder != dest->folder && !copy) {
|
2002-12-02 12:35:24 +01:00
|
|
|
return F_MOVE_FAILED_DEST_OUTSIDE_MAILBOX;
|
|
|
|
}
|
|
|
|
|
2002-11-07 00:56:26 +01:00
|
|
|
phys_srcpath = folder_item_get_path(src);
|
2006-06-02 19:06:33 +02:00
|
|
|
tmppath = folder_item_get_path(dest);
|
|
|
|
phys_dstpath = g_strconcat(tmppath,
|
2004-11-13 14:28:35 +01:00
|
|
|
G_DIR_SEPARATOR_S,
|
|
|
|
g_path_get_basename(phys_srcpath),
|
|
|
|
NULL);
|
2006-06-02 19:06:33 +02:00
|
|
|
g_free(tmppath);
|
2002-11-07 15:22:31 +01:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
if (folder_item_parent(src) == dest || src == dest) {
|
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-15 20:51:25 +01:00
|
|
|
return F_MOVE_FAILED_DEST_IS_PARENT;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
debug_print("moving \"%s\" to \"%s\"\n", phys_srcpath, phys_dstpath);
|
2006-12-26 22:34:00 +01:00
|
|
|
if ((tmp = folder_item_move_recursive(src, dest, copy)) == NULL) {
|
2002-11-15 20:51:25 +01:00
|
|
|
return F_MOVE_FAILED;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
|
|
|
|
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-08 16:42:57 +01:00
|
|
|
|
2002-11-15 20:51:25 +01:00
|
|
|
*new_item = tmp;
|
|
|
|
|
|
|
|
return F_MOVE_OK;
|
2002-11-07 00:56:26 +01:00
|
|
|
}
|
2001-05-28 00:40:29 +02:00
|
|
|
|
2010-10-03 13:46:24 +02:00
|
|
|
struct find_data
|
|
|
|
{
|
|
|
|
gboolean found;
|
|
|
|
};
|
|
|
|
static void find_num(gpointer key, gpointer value, gpointer data)
|
|
|
|
{
|
|
|
|
struct find_data *fdata = (struct find_data *)data;
|
|
|
|
if (GPOINTER_TO_INT(value) == 0)
|
|
|
|
fdata->found = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean some_msgs_have_zero_num(GHashTable *hashtable)
|
|
|
|
{
|
|
|
|
struct find_data fdata;
|
|
|
|
|
|
|
|
fdata.found = FALSE;
|
|
|
|
g_hash_table_foreach(hashtable, find_num, &fdata);
|
|
|
|
|
|
|
|
return fdata.found;
|
|
|
|
}
|
|
|
|
|
2003-07-10 11:48:05 +02:00
|
|
|
/**
|
2004-01-12 22:28:31 +01:00
|
|
|
* Copy a list of message to a new folder and remove
|
|
|
|
* source messages if wanted
|
2003-07-10 11:48:05 +02:00
|
|
|
*/
|
2004-01-12 22:28:31 +01:00
|
|
|
static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_source)
|
2001-05-28 00:40:29 +02:00
|
|
|
{
|
|
|
|
Folder *folder;
|
2003-07-28 17:47:24 +02:00
|
|
|
GSList *l;
|
2003-03-04 23:48:28 +01:00
|
|
|
gint num, lastnum = -1;
|
|
|
|
gboolean folderscan = FALSE;
|
2010-10-03 13:46:24 +02:00
|
|
|
GHashTable *relation;
|
2005-06-20 19:32:32 +02:00
|
|
|
GSList *not_moved = NULL;
|
2006-05-24 20:02:15 +02:00
|
|
|
gint total = 0, curmsg = 0;
|
2006-06-12 19:08:19 +02:00
|
|
|
MsgInfo *msginfo = NULL;
|
2001-05-28 00:40:29 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(dest != NULL, -1);
|
|
|
|
cm_return_val_if_fail(msglist != NULL, -1);
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
folder = dest->folder;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder->klass->copy_msg != NULL, -1);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (dest->no_select)
|
|
|
|
return -1;
|
2001-05-28 00:40:29 +02:00
|
|
|
|
2006-06-12 19:08:19 +02:00
|
|
|
msginfo = (MsgInfo *)msglist->data;
|
|
|
|
|
|
|
|
if (!msginfo)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!MSG_IS_QUEUED(msginfo->flags) &&
|
|
|
|
MSG_IS_DRAFT(msginfo->flags) &&
|
|
|
|
folder_has_parent_of_type(dest, F_QUEUE)) {
|
|
|
|
GSList *cur = msglist;
|
|
|
|
gboolean queue_err = FALSE;
|
|
|
|
for (; cur; cur = cur->next) {
|
|
|
|
Compose *compose = NULL;
|
|
|
|
FolderItem *queue = dest;
|
|
|
|
int val = 0;
|
|
|
|
|
|
|
|
msginfo = (MsgInfo *)cur->data;
|
|
|
|
compose = compose_reedit(msginfo, TRUE);
|
|
|
|
if (compose == NULL) {
|
|
|
|
queue_err = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
val = compose_queue(compose, NULL, &queue, NULL,
|
|
|
|
FALSE);
|
|
|
|
if (val < 0) {
|
|
|
|
queue_err = TRUE;
|
|
|
|
} else if (remove_source) {
|
|
|
|
folder_item_remove_msg(msginfo->folder, msginfo->msgnum);
|
|
|
|
}
|
|
|
|
if (val == 0)
|
|
|
|
compose_close(compose);
|
|
|
|
}
|
|
|
|
return queue_err ? -1:0;
|
|
|
|
}
|
|
|
|
|
2010-10-03 13:46:24 +02:00
|
|
|
relation = g_hash_table_new(g_direct_hash, g_direct_equal);
|
2003-07-28 17:47:24 +02:00
|
|
|
|
2004-07-13 13:55:36 +02:00
|
|
|
for (l = msglist ; l != NULL ; l = g_slist_next(l)) {
|
|
|
|
MsgInfo * msginfo = (MsgInfo *) l->data;
|
|
|
|
|
|
|
|
if (msginfo->planned_download != 0) {
|
|
|
|
int old_planned = msginfo->planned_download;
|
2004-07-14 12:01:29 +02:00
|
|
|
partial_unmark(msginfo);
|
2004-07-13 13:55:36 +02:00
|
|
|
/* little hack to reenable after */
|
|
|
|
msginfo->planned_download = old_planned;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-25 15:24:39 +02:00
|
|
|
/*
|
|
|
|
* Copy messages to destination folder and
|
|
|
|
* store new message numbers in newmsgnums
|
|
|
|
*/
|
2003-07-26 20:30:25 +02:00
|
|
|
if (folder->klass->copy_msgs != NULL) {
|
2003-07-28 17:47:24 +02:00
|
|
|
if (folder->klass->copy_msgs(folder, dest, msglist, relation) < 0) {
|
2010-10-03 13:46:24 +02:00
|
|
|
g_hash_table_destroy(relation);
|
2003-07-26 20:30:25 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2005-11-14 09:58:18 +01:00
|
|
|
MsgInfo * msginfo;
|
|
|
|
l = msglist;
|
|
|
|
|
|
|
|
/* immediately stop if src and dest folders are identical */
|
|
|
|
if (l != NULL) {
|
|
|
|
msginfo = (MsgInfo *) l->data;
|
|
|
|
if (msginfo != NULL && msginfo->folder == dest) {
|
2010-10-03 13:46:24 +02:00
|
|
|
g_hash_table_destroy(relation);
|
2005-11-14 09:58:18 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; l != NULL ; l = g_slist_next(l)) {
|
|
|
|
msginfo = (MsgInfo *) l->data;
|
2001-05-28 00:40:29 +02:00
|
|
|
|
2003-07-26 20:30:25 +02:00
|
|
|
num = folder->klass->copy_msg(folder, dest, msginfo);
|
2005-06-20 19:32:32 +02:00
|
|
|
if (num > 0)
|
2010-10-03 13:46:24 +02:00
|
|
|
g_hash_table_insert(relation, msginfo, GINT_TO_POINTER(num));
|
2005-06-20 19:32:32 +02:00
|
|
|
else
|
|
|
|
not_moved = g_slist_prepend(not_moved, msginfo);
|
2003-07-26 20:30:25 +02:00
|
|
|
}
|
2002-07-25 15:24:39 +02:00
|
|
|
}
|
|
|
|
|
2005-10-05 21:26:02 +02:00
|
|
|
if (remove_source) {
|
|
|
|
MsgInfo *msginfo = (MsgInfo *) msglist->data;
|
|
|
|
FolderItem *item = msginfo->folder;
|
|
|
|
/*
|
|
|
|
* Remove source messages from their folders if
|
|
|
|
* copying was successfull and update folder
|
|
|
|
* message counts
|
|
|
|
*/
|
2006-08-29 08:06:19 +02:00
|
|
|
if (not_moved == NULL && item->folder->klass->remove_msgs) {
|
2005-10-05 21:26:02 +02:00
|
|
|
item->folder->klass->remove_msgs(item->folder,
|
|
|
|
msginfo->folder,
|
|
|
|
msglist,
|
|
|
|
relation);
|
|
|
|
}
|
|
|
|
for (l = msglist; l != NULL; l = g_slist_next(l)) {
|
2010-10-03 13:46:24 +02:00
|
|
|
gpointer old_key, data;
|
2005-10-05 21:26:02 +02:00
|
|
|
msginfo = (MsgInfo *) l->data;
|
|
|
|
item = msginfo->folder;
|
|
|
|
|
2010-10-03 13:46:24 +02:00
|
|
|
if (g_hash_table_lookup_extended(relation, msginfo, &old_key, &data))
|
|
|
|
num = GPOINTER_TO_INT(data);
|
|
|
|
else
|
2010-12-17 09:00:10 +01:00
|
|
|
num = 0;
|
2006-10-27 10:54:27 +02:00
|
|
|
|
2005-10-05 21:26:02 +02:00
|
|
|
if (g_slist_find(not_moved, msginfo))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((num >= 0) && (item->folder->klass->remove_msg != NULL)) {
|
|
|
|
if (!item->folder->klass->remove_msgs)
|
|
|
|
item->folder->klass->remove_msg(item->folder,
|
|
|
|
msginfo->folder,
|
|
|
|
msginfo->msgnum);
|
2009-03-30 19:20:02 +02:00
|
|
|
if (!item->folder->account || item->folder->account->imap_use_trash) {
|
|
|
|
remove_msginfo_from_cache(item, msginfo);
|
|
|
|
}
|
2005-10-05 21:26:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-25 15:24:39 +02:00
|
|
|
/* Read cache for dest folder */
|
|
|
|
if (!dest->cache) folder_item_read_cache(dest);
|
2003-03-04 23:48:28 +01: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
|
|
|
|
*/
|
2010-10-03 13:46:24 +02:00
|
|
|
if (some_msgs_have_zero_num(relation)) {
|
2004-01-12 22:28:31 +01:00
|
|
|
folder_item_scan_full(dest, FALSE);
|
|
|
|
folderscan = TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-24 20:02:15 +02:00
|
|
|
statusbar_print_all(_("Updating cache for %s..."), dest->path ? dest->path : "(null)");
|
|
|
|
total = g_slist_length(msglist);
|
2007-12-07 18:10:49 +01:00
|
|
|
|
2008-01-19 16:53:47 +01:00
|
|
|
if (FOLDER_TYPE(dest->folder) == F_IMAP && total > 1) {
|
|
|
|
folder_item_scan_full(dest, FALSE);
|
|
|
|
folderscan = TRUE;
|
|
|
|
}
|
2007-12-07 18:10:49 +01:00
|
|
|
folder_item_set_batch(dest, TRUE);
|
2003-07-28 17:47:24 +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;
|
2010-10-03 13:46:24 +02:00
|
|
|
gpointer data, old_key;
|
2002-07-25 15:24:39 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
if (!msginfo)
|
|
|
|
continue;
|
2010-10-03 13:46:24 +02:00
|
|
|
|
|
|
|
if (g_hash_table_lookup_extended(relation, msginfo, &old_key, &data))
|
|
|
|
num = GPOINTER_TO_INT(data);
|
|
|
|
else
|
2010-12-17 09:00:10 +01:00
|
|
|
num = 0;
|
2010-10-03 13:46:24 +02:00
|
|
|
|
2006-05-24 20:02:15 +02:00
|
|
|
statusbar_progress_all(curmsg++,total, 100);
|
|
|
|
if (curmsg % 100 == 0)
|
|
|
|
GTK_EVENTS_FLUSH();
|
|
|
|
|
2003-03-04 23:48:28 +01:00
|
|
|
if (num >= 0) {
|
2004-08-31 17:07:47 +02:00
|
|
|
MsgInfo *newmsginfo = NULL;
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2007-04-12 18:51:43 +02:00
|
|
|
if (!folderscan && num > 0) {
|
|
|
|
newmsginfo = get_msginfo(dest, num);
|
|
|
|
if (newmsginfo != NULL) {
|
|
|
|
add_msginfo_to_cache(dest, newmsginfo, msginfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newmsginfo == NULL) {
|
|
|
|
if (!folderscan) {
|
|
|
|
folder_item_scan_full(dest, FALSE);
|
|
|
|
folderscan = TRUE;
|
|
|
|
}
|
2004-01-12 22:28:31 +01:00
|
|
|
if (msginfo->msgid != NULL) {
|
|
|
|
newmsginfo = folder_item_get_msginfo_by_msgid(dest, msginfo->msgid);
|
|
|
|
if (newmsginfo != NULL) {
|
|
|
|
copy_msginfo_flags(msginfo, newmsginfo);
|
|
|
|
num = newmsginfo->msgnum;
|
|
|
|
}
|
|
|
|
}
|
2003-03-04 23:48:28 +01:00
|
|
|
}
|
|
|
|
|
2004-07-13 13:55:36 +02:00
|
|
|
if (msginfo->planned_download
|
|
|
|
== POP3_PARTIAL_DLOAD_DELE) {
|
2004-07-14 12:01:29 +02:00
|
|
|
partial_mark_for_delete(newmsginfo);
|
2004-07-13 13:55:36 +02:00
|
|
|
}
|
|
|
|
if (msginfo->planned_download
|
|
|
|
== POP3_PARTIAL_DLOAD_DLOAD) {
|
2004-07-14 12:01:29 +02:00
|
|
|
partial_mark_for_download(newmsginfo);
|
2004-07-13 13:55:36 +02:00
|
|
|
}
|
2006-03-16 19:13:25 +01:00
|
|
|
if (!MSG_IS_POSTFILTERED (msginfo->flags)) {
|
2009-02-23 17:55:51 +01:00
|
|
|
procmsg_msginfo_set_flags ( msginfo, MSG_POSTFILTERED, 0);
|
|
|
|
if (newmsginfo) {
|
|
|
|
procmsg_msginfo_set_flags (newmsginfo, MSG_POSTFILTERED, 0);
|
|
|
|
hooks_invoke (MAIL_POSTFILTERING_HOOKLIST, newmsginfo);
|
|
|
|
}
|
2006-03-16 19:13:25 +01:00
|
|
|
}
|
2004-07-13 13:55:36 +02:00
|
|
|
procmsg_msginfo_free(newmsginfo);
|
|
|
|
|
|
|
|
|
2003-03-04 23:48:28 +01:00
|
|
|
if (num > lastnum)
|
|
|
|
lastnum = num;
|
2002-07-25 15:24:39 +02:00
|
|
|
}
|
|
|
|
}
|
2007-12-07 18:10:49 +01:00
|
|
|
folder_item_set_batch(dest, FALSE);
|
2006-05-24 20:02:15 +02:00
|
|
|
statusbar_progress_all(0,0,0);
|
|
|
|
statusbar_pop_all();
|
2002-07-25 15:24:39 +02:00
|
|
|
|
2010-10-03 13:46:24 +02:00
|
|
|
g_hash_table_destroy(relation);
|
2005-08-27 20:35:43 +02:00
|
|
|
if (not_moved != NULL) {
|
|
|
|
g_slist_free(not_moved);
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
return lastnum;
|
2001-05-28 00:40:29 +02:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Move a message to a new folder.
|
|
|
|
*
|
|
|
|
* \param dest Destination folder
|
|
|
|
* \param msginfo The message
|
|
|
|
*/
|
|
|
|
gint folder_item_move_msg(FolderItem *dest, MsgInfo *msginfo)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2004-01-12 22:28:31 +01:00
|
|
|
GSList list;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(dest != NULL, -1);
|
|
|
|
cm_return_val_if_fail(msginfo != NULL, -1);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
list.data = msginfo;
|
|
|
|
list.next = NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
return do_copy_msgs(dest, &list, TRUE);
|
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Move a list of messages to a new folder.
|
|
|
|
*
|
|
|
|
* \param dest Destination folder
|
|
|
|
* \param msglist List of messages
|
|
|
|
*/
|
|
|
|
gint folder_item_move_msgs(FolderItem *dest, GSList *msglist)
|
|
|
|
{
|
2005-06-12 21:48:04 +02:00
|
|
|
gint result = -1;
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(dest != NULL, -1);
|
|
|
|
cm_return_val_if_fail(msglist != NULL, -1);
|
2005-06-12 21:48:04 +02:00
|
|
|
inc_lock();
|
|
|
|
result = do_copy_msgs(dest, msglist, TRUE);
|
|
|
|
inc_unlock();
|
|
|
|
return result;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Copy a message to a new folder.
|
|
|
|
*
|
|
|
|
* \param dest Destination folder
|
|
|
|
* \param msginfo The message
|
|
|
|
*/
|
2001-05-28 00:40:29 +02:00
|
|
|
gint folder_item_copy_msg(FolderItem *dest, MsgInfo *msginfo)
|
|
|
|
{
|
2004-01-12 22:28:31 +01:00
|
|
|
GSList list;
|
2001-05-28 00:40:29 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(dest != NULL, -1);
|
|
|
|
cm_return_val_if_fail(msginfo != NULL, -1);
|
2003-07-26 19:01:47 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
list.data = msginfo;
|
|
|
|
list.next = NULL;
|
2005-06-12 21:48:04 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
return do_copy_msgs(dest, &list, FALSE);
|
2001-05-28 00:40:29 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/**
|
|
|
|
* Copy a list of messages to a new folder.
|
|
|
|
*
|
|
|
|
* \param dest Destination folder
|
|
|
|
* \param msglist List of messages
|
|
|
|
*/
|
2003-08-05 11:01:01 +02:00
|
|
|
gint folder_item_copy_msgs(FolderItem *dest, GSList *msglist)
|
2001-05-28 00:40:29 +02:00
|
|
|
{
|
2005-06-12 21:48:04 +02:00
|
|
|
gint result;
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(dest != NULL, -1);
|
|
|
|
cm_return_val_if_fail(msglist != NULL, -1);
|
2001-05-28 00:40:29 +02:00
|
|
|
|
2005-06-12 21:48:04 +02:00
|
|
|
inc_lock();
|
|
|
|
result = do_copy_msgs(dest, msglist, FALSE);
|
|
|
|
inc_unlock();
|
|
|
|
|
|
|
|
return result;
|
2001-05-28 00:40:29 +02:00
|
|
|
}
|
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
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, -1);
|
2003-04-26 17:20:03 +02:00
|
|
|
folder = item->folder;
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder->klass->remove_msg != NULL, -1);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return -1;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2002-06-30 01:33:42 +02:00
|
|
|
if (!item->cache) folder_item_read_cache(item);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2007-09-16 08:39:17 +02:00
|
|
|
msginfo = msgcache_get_msg(item->cache, num);
|
2007-09-28 12:56:57 +02:00
|
|
|
if (msginfo && MSG_IS_LOCKED(msginfo->flags)) {
|
2007-09-16 20:36:36 +02:00
|
|
|
procmsg_msginfo_free(msginfo);
|
2007-09-16 08:39:17 +02:00
|
|
|
return -1;
|
2007-09-16 20:36:36 +02:00
|
|
|
}
|
2003-04-05 22:38:53 +02:00
|
|
|
ret = folder->klass->remove_msg(folder, item, num);
|
2002-06-30 01:33:42 +02:00
|
|
|
|
2009-03-30 19:20:02 +02:00
|
|
|
if (!item->folder->account || item->folder->account->imap_use_trash) {
|
|
|
|
if (msginfo != NULL) {
|
|
|
|
remove_msginfo_from_cache(item, msginfo);
|
|
|
|
procmsg_msginfo_free(msginfo);
|
|
|
|
}
|
2002-07-31 17:35:26 +02:00
|
|
|
}
|
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;
|
2008-03-31 09:00:48 +02:00
|
|
|
GSList *real_list = NULL, *cur = NULL;
|
2001-10-07 11:15:06 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, -1);
|
2002-11-14 18:19:17 +01:00
|
|
|
folder = item->folder;
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder != NULL, -1);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return -1;
|
2005-06-12 21:48:04 +02:00
|
|
|
inc_lock();
|
2002-11-14 18:19:17 +01:00
|
|
|
if (!item->cache) folder_item_read_cache(item);
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
folder_item_update_freeze();
|
2008-03-31 09:00:48 +02:00
|
|
|
|
|
|
|
/* filter out locked mails */
|
|
|
|
for (cur = msglist; cur; cur = cur->next) {
|
|
|
|
MsgInfo *info = (MsgInfo *)cur->data;
|
|
|
|
if (!MSG_IS_LOCKED(info->flags))
|
|
|
|
real_list = g_slist_prepend(real_list, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
real_list = g_slist_reverse(real_list);
|
|
|
|
|
2005-06-12 21:35:12 +02:00
|
|
|
if (item->folder->klass->remove_msgs) {
|
|
|
|
ret = item->folder->klass->remove_msgs(item->folder,
|
|
|
|
item,
|
2008-03-31 09:00:48 +02:00
|
|
|
real_list,
|
2005-06-12 21:35:12 +02:00
|
|
|
NULL);
|
|
|
|
}
|
2008-03-31 09:00:48 +02:00
|
|
|
while (ret == 0 && real_list != NULL) {
|
|
|
|
MsgInfo *msginfo = (MsgInfo *)real_list->data;
|
2007-09-28 12:56:57 +02:00
|
|
|
if (msginfo && MSG_IS_LOCKED(msginfo->flags)) {
|
2008-03-31 09:00:48 +02:00
|
|
|
real_list = real_list->next;
|
2005-05-26 21:24:00 +02:00
|
|
|
continue;
|
|
|
|
}
|
2005-06-12 21:35:12 +02:00
|
|
|
if (!item->folder->klass->remove_msgs)
|
|
|
|
ret = folder_item_remove_msg(item, msginfo->msgnum);
|
2001-10-07 11:15:06 +02:00
|
|
|
if (ret != 0) break;
|
2002-06-30 01:33:42 +02:00
|
|
|
msgcache_remove_msg(item->cache, msginfo->msgnum);
|
2008-03-31 09:00:48 +02:00
|
|
|
real_list = real_list->next;
|
2001-10-07 11:15:06 +02:00
|
|
|
}
|
2008-03-31 09:00:48 +02:00
|
|
|
g_slist_free(real_list);
|
2005-06-12 21:35:12 +02:00
|
|
|
folder_item_scan_full(item, FALSE);
|
2004-02-21 12:01:01 +01:00
|
|
|
folder_item_update_thaw();
|
2005-06-12 21:48:04 +02:00
|
|
|
inc_unlock();
|
2001-10-07 11:15:06 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-03-30 19:20:02 +02:00
|
|
|
gint folder_item_expunge(FolderItem *item)
|
|
|
|
{
|
|
|
|
Folder *folder = item->folder;
|
|
|
|
gint result = 0;
|
|
|
|
if (folder == NULL)
|
|
|
|
return -1;
|
|
|
|
if (folder->klass->expunge) {
|
|
|
|
GSList *msglist = folder_item_get_msg_list(item);
|
|
|
|
GSList *cur;
|
|
|
|
result = folder->klass->expunge(folder, item);
|
|
|
|
if (result == 0) {
|
|
|
|
for (cur = msglist; cur; cur = cur->next) {
|
|
|
|
MsgInfo *msginfo = (MsgInfo *)cur->data;
|
|
|
|
if (MSG_IS_DELETED(msginfo->flags)) {
|
|
|
|
remove_msginfo_from_cache(item, msginfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
procmsg_msg_list_free(msglist);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, -1);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return -1;
|
2001-05-28 00:40:29 +02:00
|
|
|
|
|
|
|
folder = item->folder;
|
|
|
|
|
2005-06-12 21:48:04 +02:00
|
|
|
inc_lock();
|
2005-01-27 22:38:55 +01:00
|
|
|
if (folder->klass->remove_all_msg != NULL) {
|
|
|
|
result = folder->klass->remove_all_msg(folder, item);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2005-01-27 22:38:55 +01:00
|
|
|
if (result == 0) {
|
2006-06-09 16:48:49 +02:00
|
|
|
folder_item_free_cache(item, TRUE);
|
2005-01-27 22:38:55 +01:00
|
|
|
item->cache = msgcache_new();
|
2009-03-27 20:03:29 +01:00
|
|
|
item->cache_dirty = TRUE;
|
|
|
|
item->mark_dirty = TRUE;
|
|
|
|
item->tags_dirty = TRUE;
|
2005-01-27 22:38:55 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MsgInfoList *msglist;
|
2001-05-30 05:05:08 +02:00
|
|
|
|
2005-01-27 22:38:55 +01:00
|
|
|
msglist = folder_item_get_msg_list(item);
|
|
|
|
result = folder_item_remove_msgs(item, msglist);
|
|
|
|
procmsg_msg_list_free(msglist);
|
|
|
|
}
|
2002-07-06 03:07:26 +02:00
|
|
|
|
2005-01-27 22:38:55 +01:00
|
|
|
if (result == 0) {
|
2003-04-05 22:38:53 +02:00
|
|
|
item->new_msgs = 0;
|
|
|
|
item->unread_msgs = 0;
|
|
|
|
item->unreadmarked_msgs = 0;
|
2005-07-01 19:33:02 +02:00
|
|
|
item->marked_msgs = 0;
|
2003-04-05 22:38:53 +02:00
|
|
|
item->total_msgs = 0;
|
2008-03-12 07:22:29 +01:00
|
|
|
item->replied_msgs = 0;
|
|
|
|
item->forwarded_msgs = 0;
|
|
|
|
item->locked_msgs = 0;
|
|
|
|
item->ignored_msgs = 0;
|
|
|
|
item->watched_msgs = 0;
|
2003-01-07 22:49:44 +01:00
|
|
|
folder_item_update(item, F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT);
|
2001-05-30 05:05:08 +02:00
|
|
|
}
|
|
|
|
|
2005-06-12 21:48:04 +02:00
|
|
|
inc_unlock();
|
2001-05-30 05:05:08 +02:00
|
|
|
return result;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2003-03-18 19:24:34 +01:00
|
|
|
void folder_item_change_msg_flags(FolderItem *item, MsgInfo *msginfo, MsgPermFlags newflags)
|
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(item != NULL);
|
|
|
|
cm_return_if_fail(msginfo != NULL);
|
2009-03-16 18:59:26 +01:00
|
|
|
|
|
|
|
item->mark_dirty = TRUE;
|
|
|
|
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return;
|
2003-03-18 19:24:34 +01:00
|
|
|
|
2007-12-03 18:32:15 +01:00
|
|
|
if (item->folder->klass->change_flags != NULL && item->scanning != ITEM_SCANNING_WITH_FLAGS) {
|
2003-04-05 22:38:53 +02:00
|
|
|
item->folder->klass->change_flags(item->folder, item, msginfo, newflags);
|
2003-03-18 19:24:34 +01:00
|
|
|
} else {
|
|
|
|
msginfo->flags.perm_flags = newflags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-26 23:30:58 +01:00
|
|
|
void folder_item_commit_tags(FolderItem *item, MsgInfo *msginfo, GSList *tags_set, GSList *tags_unset)
|
|
|
|
{
|
|
|
|
Folder *folder = NULL;
|
|
|
|
|
|
|
|
if (!msginfo)
|
|
|
|
return;
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
if (!tags_set && !tags_unset)
|
|
|
|
return;
|
|
|
|
|
|
|
|
folder = item->folder;
|
|
|
|
if (!folder)
|
|
|
|
return;
|
|
|
|
|
2009-03-16 18:59:26 +01:00
|
|
|
item->tags_dirty = TRUE;
|
|
|
|
|
2007-11-26 23:30:58 +01:00
|
|
|
if (folder->klass->commit_tags == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
folder->klass->commit_tags(item, msginfo, tags_set, tags_unset);
|
|
|
|
}
|
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
gboolean folder_item_is_msg_changed(FolderItem *item, MsgInfo *msginfo)
|
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, FALSE);
|
2006-03-18 09:56:52 +01:00
|
|
|
if (item->no_select)
|
|
|
|
return FALSE;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
folder = item->folder;
|
2001-05-23 14:08:40 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder->klass->is_msg_changed != NULL, -1);
|
2001-05-23 14:08:40 +02:00
|
|
|
|
2003-04-05 22:38:53 +02:00
|
|
|
return folder->klass->is_msg_changed(folder, item, msginfo);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2007-09-22 14:00:27 +02:00
|
|
|
void folder_item_discard_cache(FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *dir;
|
|
|
|
gchar *cache;
|
|
|
|
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (item->cache) {
|
|
|
|
msgcache_destroy(item->cache);
|
|
|
|
item->cache = NULL;
|
|
|
|
}
|
|
|
|
dir = folder_item_get_path(item);
|
|
|
|
if (is_dir_exist(dir))
|
|
|
|
remove_all_numbered_files(dir);
|
|
|
|
g_free(dir);
|
|
|
|
|
|
|
|
cache = folder_item_get_cache_file(item);
|
|
|
|
if (is_file_exist(cache))
|
2008-04-18 18:26:05 +02:00
|
|
|
claws_unlink(cache);
|
2007-09-22 14:00:27 +02:00
|
|
|
g_free(cache);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-01-21 13:16:52 +01:00
|
|
|
static gchar *folder_item_get_cache_file(FolderItem *item)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
gchar *file;
|
2007-05-02 09:47:38 +02:00
|
|
|
gchar *old_file;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
|
|
|
cm_return_val_if_fail(item->path != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
path = folder_item_get_path(item);
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(path != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
if (!is_dir_exist(path))
|
|
|
|
make_dir_hier(path);
|
|
|
|
file = g_strconcat(path, G_DIR_SEPARATOR_S, CACHE_FILE, NULL);
|
2007-05-02 09:47:38 +02:00
|
|
|
old_file = g_strconcat(path, G_DIR_SEPARATOR_S, OLD_CACHE_FILE, NULL);
|
|
|
|
|
|
|
|
if (!is_file_exist(file) && is_file_exist(old_file))
|
|
|
|
move_file(old_file, file, FALSE);
|
|
|
|
g_free(old_file);
|
2001-04-19 14:21:46 +02:00
|
|
|
g_free(path);
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2007-01-21 13:16:52 +01:00
|
|
|
static gchar *folder_item_get_mark_file(FolderItem *item)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
gchar *file;
|
2007-05-02 09:47:38 +02:00
|
|
|
gchar *old_file;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
|
|
|
cm_return_val_if_fail(item->path != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
path = folder_item_get_path(item);
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(path != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
if (!is_dir_exist(path))
|
|
|
|
make_dir_hier(path);
|
|
|
|
file = g_strconcat(path, G_DIR_SEPARATOR_S, MARK_FILE, NULL);
|
2007-05-02 09:47:38 +02:00
|
|
|
old_file = g_strconcat(path, G_DIR_SEPARATOR_S, OLD_MARK_FILE, NULL);
|
|
|
|
|
|
|
|
if (!is_file_exist(file) && is_file_exist(old_file))
|
|
|
|
move_file(old_file, file, FALSE);
|
|
|
|
g_free(old_file);
|
2001-04-19 14:21:46 +02:00
|
|
|
g_free(path);
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2007-07-02 18:35:40 +02:00
|
|
|
static gchar *folder_item_get_tags_file(FolderItem *item)
|
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
gchar *identifier;
|
|
|
|
gchar *file;
|
|
|
|
|
|
|
|
/* we save tags files in rc_dir, because tagsrc is there too,
|
|
|
|
* and storing tags directly in the mailboxes would give strange
|
|
|
|
* result when using another Claws mailbox from another install
|
|
|
|
* with different tags. */
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
2007-07-02 18:35:40 +02:00
|
|
|
|
|
|
|
identifier = folder_item_get_identifier(item);
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(identifier != NULL, NULL);
|
2007-08-09 11:03:54 +02:00
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
while (strchr(identifier, '/'))
|
|
|
|
*strchr(identifier, '/') = '\\';
|
|
|
|
#endif
|
|
|
|
|
2007-07-02 18:35:40 +02:00
|
|
|
path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
|
|
|
|
"tagsdb", G_DIR_SEPARATOR_S,
|
|
|
|
identifier, NULL);
|
|
|
|
|
|
|
|
g_free(identifier);
|
|
|
|
|
|
|
|
if (!is_dir_exist(path))
|
|
|
|
make_dir_hier(path);
|
|
|
|
|
|
|
|
file = g_strconcat(path, G_DIR_SEPARATOR_S, TAGS_FILE, NULL);
|
|
|
|
|
|
|
|
g_free(path);
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
static gpointer xml_to_folder_item(gpointer nodedata, gpointer data)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
2004-02-21 12:01:01 +01:00
|
|
|
XMLNode *xmlnode = (XMLNode *) nodedata;
|
|
|
|
Folder *folder = (Folder *) data;
|
2001-04-19 14:21:46 +02:00
|
|
|
FolderItem *item;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(xmlnode != NULL, NULL);
|
|
|
|
cm_return_val_if_fail(folder != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
if (strcmp2(xmlnode->tag->tag, "folderitem") != 0) {
|
|
|
|
g_warning("tag name != \"folderitem\"\n");
|
2004-02-21 12:01:01 +01:00
|
|
|
return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
item = folder_item_new(folder, "", "");
|
|
|
|
if (folder->klass->item_set_xml != NULL)
|
|
|
|
folder->klass->item_set_xml(folder, item, xmlnode->tag);
|
|
|
|
else
|
|
|
|
folder_item_set_xml(folder, item, xmlnode->tag);
|
2004-02-21 12:01:01 +01:00
|
|
|
|
2001-04-19 14:21:46 +02:00
|
|
|
item->folder = folder;
|
2004-02-21 12:01:01 +01:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
switch (item->stype) {
|
2001-04-19 14:21:46 +02:00
|
|
|
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
|
|
|
}
|
2003-07-20 03:15:54 +02:00
|
|
|
folder_item_prefs_read_config(item);
|
2001-05-06 06:27:28 +02:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean folder_item_set_node(GNode *node, gpointer data)
|
|
|
|
{
|
|
|
|
FolderItem *item = (FolderItem *) node->data;
|
|
|
|
item->node = node;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
static Folder *folder_get_from_xml(GNode *node)
|
2001-04-19 14:21:46 +02:00
|
|
|
{
|
|
|
|
Folder *folder;
|
|
|
|
XMLNode *xmlnode;
|
|
|
|
GList *list;
|
2004-01-12 22:28:31 +01:00
|
|
|
FolderClass *klass = NULL;
|
2004-02-21 12:01:01 +01:00
|
|
|
GNode *cur;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(node->data != NULL, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
|
|
|
xmlnode = node->data;
|
|
|
|
if (strcmp2(xmlnode->tag->tag, "folder") != 0) {
|
|
|
|
g_warning("tag name != \"folder\"\n");
|
2004-02-21 12:01:01 +01:00
|
|
|
return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
list = xmlnode->tag->attr;
|
|
|
|
for (; list != NULL; list = list->next) {
|
|
|
|
XMLAttr *attr = list->data;
|
|
|
|
|
|
|
|
if (!attr || !attr->name || !attr->value) continue;
|
2003-03-13 16:31:22 +01:00
|
|
|
if (!strcmp(attr->name, "type"))
|
2004-01-12 22:28:31 +01:00
|
|
|
klass = folder_get_class_from_string(attr->value);
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
2004-02-21 12:01:01 +01:00
|
|
|
if (klass == NULL)
|
|
|
|
return NULL;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
folder = folder_new(klass, "", "");
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder != NULL, NULL);
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
if (klass->set_xml)
|
|
|
|
klass->set_xml(folder, xmlnode->tag);
|
|
|
|
else
|
|
|
|
folder_set_xml(folder, xmlnode->tag);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
cur = node->children;
|
|
|
|
while (cur != NULL) {
|
|
|
|
GNode *itemnode;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
itemnode = g_node_map(cur, xml_to_folder_item, (gpointer) folder);
|
|
|
|
g_node_append(folder->node, itemnode);
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
g_node_traverse(folder->node, G_IN_ORDER, G_TRAVERSE_ALL, -1, folder_item_set_node, NULL);
|
|
|
|
|
|
|
|
return folder;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
static gpointer folder_item_to_xml(gpointer nodedata, gpointer data)
|
2004-01-12 22:28:31 +01:00
|
|
|
{
|
2004-02-21 12:01:01 +01:00
|
|
|
FolderItem *item = (FolderItem *) nodedata;
|
2004-01-12 22:28:31 +01:00
|
|
|
XMLTag *tag;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(item != NULL, NULL);
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
if (item->folder->klass->item_get_xml != NULL)
|
|
|
|
tag = item->folder->klass->item_get_xml(item->folder, item);
|
|
|
|
else
|
|
|
|
tag = folder_item_get_xml(item->folder, item);
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2005-09-12 11:22:22 +02:00
|
|
|
return xml_node_new(tag, NULL);
|
2004-02-21 12:01:01 +01:00
|
|
|
}
|
2002-06-03 08:03:31 +02:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
static GNode *folder_get_xml_node(Folder *folder)
|
|
|
|
{
|
|
|
|
GNode *node;
|
|
|
|
XMLNode *xmlnode;
|
|
|
|
XMLTag *tag;
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder != NULL, NULL);
|
2002-11-12 10:09:22 +01:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
if (folder->klass->get_xml != NULL)
|
|
|
|
tag = folder->klass->get_xml(folder);
|
|
|
|
else
|
|
|
|
tag = folder_get_xml(folder);
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2004-08-06 13:34:34 +02:00
|
|
|
xml_tag_add_attr(tag, xml_attr_new("type", folder->klass->idstr));
|
2004-01-12 22:28:31 +01:00
|
|
|
|
2004-08-06 13:34:34 +02:00
|
|
|
xmlnode = xml_node_new(tag, NULL);
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
node = g_node_new(xmlnode);
|
2006-06-15 08:29:48 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail (folder->node != NULL, NULL);
|
2006-06-15 08:29:48 +02:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
if (folder->node->children) {
|
|
|
|
GNode *cur;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
cur = folder->node->children;
|
|
|
|
while (cur) {
|
|
|
|
GNode *xmlnode;
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
xmlnode = g_node_map(cur, folder_item_to_xml, (gpointer) folder);
|
|
|
|
g_node_append(node, xmlnode);
|
|
|
|
cur = cur->next;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
2004-02-21 12:01:01 +01:00
|
|
|
}
|
2001-04-19 14:21:46 +02:00
|
|
|
|
2004-02-21 12:01:01 +01:00
|
|
|
return node;
|
2001-04-19 14:21:46 +02:00
|
|
|
}
|
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;
|
2003-01-07 22:49:44 +01:00
|
|
|
folder_item_update(fitem, F_ITEM_UPDATE_MSGCNT);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-13 13:54:19 +02:00
|
|
|
void folder_update_op_count(void)
|
|
|
|
{
|
2001-07-31 08:17:48 +02:00
|
|
|
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 */
|
2003-03-30 16:02:37 +02:00
|
|
|
#define TEMP_FOLDER "TEMP_FOLDER"
|
|
|
|
#define PROCESSING_FOLDER_ITEM "processing"
|
|
|
|
|
2001-12-05 23:09:25 +01:00
|
|
|
static FolderItem *processing_folder_item;
|
|
|
|
|
|
|
|
static void folder_create_processing_folder(void)
|
|
|
|
{
|
2003-03-30 16:02:37 +02:00
|
|
|
Folder *processing_folder;
|
2001-12-05 23:09:25 +01:00
|
|
|
gchar *tmpname;
|
|
|
|
|
2003-03-30 16:02:37 +02:00
|
|
|
if ((processing_folder = folder_find_from_name(TEMP_FOLDER, mh_get_class())) == NULL) {
|
|
|
|
gchar *tmppath;
|
|
|
|
|
|
|
|
tmppath =
|
|
|
|
g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
|
|
|
|
"tempfolder", NULL);
|
|
|
|
processing_folder =
|
|
|
|
folder_new(mh_get_class(), TEMP_FOLDER, tmppath);
|
|
|
|
g_free(tmppath);
|
|
|
|
}
|
|
|
|
g_assert(processing_folder != NULL);
|
|
|
|
|
|
|
|
debug_print("tmpparentroot %s\n", LOCAL_FOLDER(processing_folder)->rootpath);
|
2005-12-23 08:36:23 +01:00
|
|
|
/* FIXME: [W32] The code below does not correctly merge
|
|
|
|
relative filenames; there should be a function to handle
|
|
|
|
this. */
|
|
|
|
if (!is_relative_filename(LOCAL_FOLDER(processing_folder)->rootpath))
|
2003-03-30 16:02:37 +02:00
|
|
|
tmpname = g_strconcat(LOCAL_FOLDER(processing_folder)->rootpath,
|
|
|
|
G_DIR_SEPARATOR_S, PROCESSING_FOLDER_ITEM,
|
2001-12-08 18:41:56 +01:00
|
|
|
NULL);
|
|
|
|
else
|
|
|
|
tmpname = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
|
2003-03-30 16:02:37 +02:00
|
|
|
LOCAL_FOLDER(processing_folder)->rootpath,
|
|
|
|
G_DIR_SEPARATOR_S, PROCESSING_FOLDER_ITEM,
|
2001-12-08 18:41:56 +01:00
|
|
|
NULL);
|
2001-12-05 23:09:25 +01:00
|
|
|
|
|
|
|
if (!is_dir_exist(tmpname)) {
|
|
|
|
debug_print("*TMP* creating %s\n", tmpname);
|
2003-04-05 22:38:53 +02:00
|
|
|
processing_folder_item = processing_folder->klass->create_folder(processing_folder,
|
2003-03-12 16:40:51 +01:00
|
|
|
processing_folder->node->data,
|
2003-03-30 16:02:37 +02:00
|
|
|
PROCESSING_FOLDER_ITEM);
|
|
|
|
} else {
|
2001-12-05 23:09:25 +01:00
|
|
|
debug_print("*TMP* already created\n");
|
2003-03-30 16:48:13 +02:00
|
|
|
processing_folder_item = folder_item_new(processing_folder, PROCESSING_FOLDER_ITEM, PROCESSING_FOLDER_ITEM);
|
2001-12-05 23:09:25 +01:00
|
|
|
g_assert(processing_folder_item);
|
|
|
|
folder_item_append(processing_folder->node->data, processing_folder_item);
|
|
|
|
}
|
2003-03-30 16:02:37 +02:00
|
|
|
g_assert(processing_folder_item != NULL);
|
2001-12-05 23:09:25 +01:00
|
|
|
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).
|
2003-07-20 03:15:54 +02:00
|
|
|
* (note that in claws other options are in the folder_item_prefs_RC
|
2001-12-30 02:27:14 +01:00
|
|
|
* file, so those don't need to be included in PersistPref yet)
|
|
|
|
*/
|
2007-01-21 13:16:52 +01:00
|
|
|
static GHashTable *folder_persist_prefs_new(Folder *folder)
|
2001-12-30 02:27:14 +01:00
|
|
|
{
|
|
|
|
GHashTable *pptable;
|
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_val_if_fail(folder, NULL);
|
2001-12-30 02:27:14 +01:00
|
|
|
pptable = g_hash_table_new(g_str_hash, g_str_equal);
|
|
|
|
folder_get_persist_prefs_recursive(folder->node, pptable);
|
|
|
|
return pptable;
|
|
|
|
}
|
|
|
|
|
2007-01-21 13:16:52 +01:00
|
|
|
static void folder_persist_prefs_free(GHashTable *pptable)
|
2001-12-30 02:27:14 +01:00
|
|
|
{
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(pptable);
|
2001-12-30 02:27:14 +01:00
|
|
|
g_hash_table_foreach_remove(pptable, persist_prefs_free, NULL);
|
|
|
|
g_hash_table_destroy(pptable);
|
|
|
|
}
|
|
|
|
|
2007-01-21 13:16:52 +01:00
|
|
|
static const PersistPrefs *folder_get_persist_prefs(GHashTable *pptable, const char *name)
|
2001-12-30 02:27:14 +01:00
|
|
|
{
|
|
|
|
if (pptable == NULL || name == NULL) return NULL;
|
|
|
|
return g_hash_table_lookup(pptable, name);
|
|
|
|
}
|
|
|
|
|
2007-01-21 13:16:52 +01:00
|
|
|
static void folder_item_restore_persist_prefs(FolderItem *item, GHashTable *pptable)
|
2001-12-30 02:27:14 +01:00
|
|
|
{
|
|
|
|
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. */
|
2003-07-20 03:15:54 +02:00
|
|
|
folder_item_prefs_read_config(item);
|
2004-02-21 12:01:01 +01:00
|
|
|
|
2001-12-30 02:27:14 +01:00
|
|
|
item->collapsed = pp->collapsed;
|
2003-01-25 02:30:03 +01:00
|
|
|
item->thread_collapsed = pp->thread_collapsed;
|
2001-12-30 02:27:14 +01:00
|
|
|
item->threaded = pp->threaded;
|
|
|
|
item->ret_rcpt = pp->ret_rcpt;
|
|
|
|
item->hide_read_msgs = pp->hide_read_msgs;
|
2009-03-30 19:20:02 +02:00
|
|
|
item->hide_del_msgs = pp->hide_del_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
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(node != NULL);
|
|
|
|
cm_return_if_fail(item != NULL);
|
2001-12-30 02:27:14 +01:00
|
|
|
|
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);
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(pp != NULL);
|
2001-12-30 02:27:14 +01:00
|
|
|
pp->collapsed = item->collapsed;
|
2003-01-25 02:30:03 +01:00
|
|
|
pp->thread_collapsed = item->thread_collapsed;
|
2001-12-30 02:27:14 +01:00
|
|
|
pp->threaded = item->threaded;
|
|
|
|
pp->ret_rcpt = item->ret_rcpt;
|
|
|
|
pp->hide_read_msgs = item->hide_read_msgs;
|
2009-03-30 19:20:02 +02:00
|
|
|
pp->hide_del_msgs = item->hide_del_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)
|
|
|
|
{
|
2006-04-06 12:58:17 +02:00
|
|
|
g_free(key);
|
|
|
|
g_free(val);
|
2001-12-30 02:27:14 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-07-23 20:18:21 +02:00
|
|
|
void folder_item_apply_processing(FolderItem *item)
|
|
|
|
{
|
|
|
|
GSList *processing_list;
|
|
|
|
GSList *mlist, *cur;
|
2005-06-15 04:19:15 +02:00
|
|
|
guint total = 0, curmsg = 0;
|
2006-09-02 15:44:12 +02:00
|
|
|
gint last_apply_per_account;
|
2005-06-15 04:19:15 +02:00
|
|
|
|
2009-02-23 17:55:51 +01:00
|
|
|
cm_return_if_fail(item != NULL);
|
2006-03-18 09:56:52 +01:00
|
|
|
|
|
|
|
if (item->no_select)
|
|
|
|
return;
|
|
|
|
|
2002-07-23 20:18:21 +02:00
|
|
|
processing_list = item->prefs->processing;
|
|
|
|
|
2006-02-06 22:45:14 +01:00
|
|
|
if (!pre_global_processing && !processing_list
|
|
|
|
&& !post_global_processing)
|
|
|
|
return;
|
|
|
|
|
2006-09-30 19:26:38 +02:00
|
|
|
debug_print("processing %s\n", item->name);
|
2003-01-07 22:49:44 +01:00
|
|
|
folder_item_update_freeze();
|
|
|
|
|
2007-11-20 11:49:27 +01:00
|
|
|
inc_lock();
|
|
|
|
|
2002-07-23 20:18:21 +02:00
|
|
|
mlist = folder_item_get_msg_list(item);
|
2005-06-15 04:19:15 +02:00
|
|
|
total = g_slist_length(mlist);
|
|
|
|
statusbar_print_all(_("Processing messages..."));
|
2006-09-02 15:44:12 +02:00
|
|
|
|
|
|
|
last_apply_per_account = prefs_common.apply_per_account_filtering_rules;
|
|
|
|
prefs_common.apply_per_account_filtering_rules = FILTERING_ACCOUNT_RULES_SKIP;
|
|
|
|
|
2007-11-27 19:28:40 +01:00
|
|
|
folder_item_set_batch(item, TRUE);
|
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;
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
/* reset parameters that can be modified by processing */
|
|
|
|
msginfo->hidden = 0;
|
|
|
|
msginfo->score = 0;
|
2005-07-10 06:09:06 +02:00
|
|
|
|
|
|
|
statusbar_progress_all(curmsg++,total, 10);
|
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/* apply pre global rules */
|
2007-03-21 16:00:46 +01:00
|
|
|
filter_message_by_msginfo(pre_global_processing, msginfo, NULL,
|
|
|
|
FILTERING_PRE_PROCESSING, NULL);
|
2006-02-06 20:22:08 +01:00
|
|
|
|
2004-01-12 22:28:31 +01:00
|
|
|
/* apply rules of the folder */
|
2007-03-21 16:00:46 +01:00
|
|
|
filter_message_by_msginfo(processing_list, msginfo, NULL,
|
|
|
|
FILTERING_FOLDER_PROCESSING, item->name);
|
2004-01-12 22:28:31 +01:00
|
|
|
|
|
|
|
/* apply post global rules */
|
2007-03-21 16:00:46 +01:00
|
|
|
filter_message_by_msginfo(post_global_processing, msginfo, NULL,
|
|
|
|
FILTERING_POST_PROCESSING, NULL);
|
2007-08-05 10:00:00 +02:00
|
|
|
if (curmsg % 1000 == 0)
|
2007-07-18 14:29:38 +02:00
|
|
|
GTK_EVENTS_FLUSH();
|
2006-02-06 22:30:43 +01:00
|
|
|
}
|
2007-11-27 19:28:40 +01:00
|
|
|
folder_item_set_batch(item, FALSE);
|
|
|
|
|
2006-09-02 15:44:12 +02:00
|
|
|
prefs_common.apply_per_account_filtering_rules = last_apply_per_account;
|
|
|
|
|
2006-02-06 22:30:43 +01:00
|
|
|
if (pre_global_processing || processing_list
|
|
|
|
|| post_global_processing)
|
|
|
|
filtering_move_and_copy_msgs(mlist);
|
|
|
|
for (cur = mlist ; cur != NULL ; cur = cur->next) {
|
2006-02-07 10:02:24 +01:00
|
|
|
MsgInfo * msginfo = (MsgInfo *)cur->data;
|
2002-07-23 20:18:21 +02:00
|
|
|
procmsg_msginfo_free(msginfo);
|
|
|
|
}
|
|
|
|
g_slist_free(mlist);
|
2005-06-15 04:19:15 +02:00
|
|
|
|
2005-07-10 06:09:06 +02:00
|
|
|
statusbar_progress_all(0,0,0);
|
2005-06-15 04:19:15 +02:00
|
|
|
statusbar_pop_all();
|
2003-01-07 22:49:44 +01:00
|
|
|
|
2007-11-20 11:49:27 +01:00
|
|
|
inc_unlock();
|
|
|
|
|
2003-01-07 22:49:44 +01:00
|
|
|
folder_item_update_thaw();
|
2002-07-23 20:18:21 +02:00
|
|
|
}
|
2002-11-09 17:35:13 +01:00
|
|
|
|
2002-11-13 14:16:20 +01:00
|
|
|
/*
|
2003-01-07 22:49:44 +01:00
|
|
|
* functions for handling FolderItem content changes
|
2002-11-13 14:16:20 +01:00
|
|
|
*/
|
2003-01-07 22:49:44 +01:00
|
|
|
static gint folder_item_update_freeze_cnt = 0;
|
2002-11-09 17:35:13 +01:00
|
|
|
|
2004-06-25 10:05:09 +02:00
|
|
|
static void folder_item_update_with_msg(FolderItem *item, FolderItemUpdateFlags update_flags, MsgInfo *msg)
|
|
|
|
{
|
2004-08-08 11:52:16 +02:00
|
|
|
if (folder_item_update_freeze_cnt == 0 /* || (msg != NULL && item->opened) */) {
|
2004-06-25 10:05:09 +02:00
|
|
|
FolderItemUpdateData source;
|
|
|
|
|
|
|
|
source.item = item;
|
|
|
|
source.update_flags = update_flags;
|
|
|
|
source.msg = msg;
|
|
|
|
hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
|
|
|
|
} else {
|
|
|
|
item->update_flags |= update_flags & ~(F_ITEM_UPDATE_ADDMSG | F_ITEM_UPDATE_REMOVEMSG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-07 22:49:44 +01:00
|
|
|
/**
|
|
|
|
* Notify the folder system about changes to a folder. If the
|
|
|
|
* update system is not frozen the FOLDER_ITEM_UPDATE_HOOKLIST will
|
|
|
|
* be invoked, otherwise the changes will be remebered until
|
|
|
|
* the folder system is thawed.
|
|
|
|
*
|
|
|
|
* \param item The FolderItem that was changed
|
|
|
|
* \param update_flags Type of changed that was made
|
|
|
|
*/
|
|
|
|
void folder_item_update(FolderItem *item, FolderItemUpdateFlags update_flags)
|
2002-11-09 17:35:13 +01:00
|
|
|
{
|
2004-06-25 10:05:09 +02:00
|
|
|
folder_item_update_with_msg(item, update_flags, NULL);
|
2002-11-09 17:35:13 +01:00
|
|
|
}
|
|
|
|
|
2003-01-07 22:49:44 +01:00
|
|
|
void folder_item_update_recursive(FolderItem *item, FolderItemUpdateFlags update_flags)
|
2002-11-09 17:35:13 +01:00
|
|
|
{
|
|
|
|
GNode *node = item->folder->node;
|
2002-12-02 22:50:19 +01:00
|
|
|
|
2002-11-09 17:35:13 +01:00
|
|
|
node = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, item);
|
|
|
|
node = node->children;
|
2002-12-02 22:50:19 +01:00
|
|
|
|
2003-01-07 22:49:44 +01:00
|
|
|
folder_item_update(item, update_flags);
|
2002-11-09 17:35:13 +01:00
|
|
|
while (node != NULL) {
|
|
|
|
if (node && node->data) {
|
|
|
|
FolderItem *next_item = (FolderItem*) node->data;
|
2002-12-02 22:50:19 +01:00
|
|
|
|
2003-01-07 22:49:44 +01:00
|
|
|
folder_item_update(next_item, update_flags);
|
2002-11-09 17:35:13 +01:00
|
|
|
}
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
}
|
2002-11-12 10:09:22 +01:00
|
|
|
|
2003-05-13 13:54:19 +02:00
|
|
|
void folder_item_update_freeze(void)
|
2003-01-07 22:49:44 +01:00
|
|
|
{
|
|
|
|
folder_item_update_freeze_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void folder_item_update_func(FolderItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
FolderItemUpdateData source;
|
|
|
|
|
|
|
|
if (item->update_flags) {
|
|
|
|
source.item = item;
|
|
|
|
source.update_flags = item->update_flags;
|
2005-10-26 09:45:50 +02:00
|
|
|
source.msg = NULL;
|
2003-01-07 22:49:44 +01:00
|
|
|
hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &source);
|
|
|
|
item->update_flags = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-13 13:54:19 +02:00
|
|
|
void folder_item_update_thaw(void)
|
2003-01-07 22:49:44 +01:00
|
|
|
{
|
|
|
|
if (folder_item_update_freeze_cnt > 0)
|
|
|
|
folder_item_update_freeze_cnt--;
|
|
|
|
if (folder_item_update_freeze_cnt == 0) {
|
|
|
|
/* Update all folders */
|
|
|
|
folder_func_to_all_folders(folder_item_update_func, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-03 09:08:26 +02:00
|
|
|
void folder_item_synchronise(FolderItem *item)
|
|
|
|
{
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
if (item->prefs->offlinesync && item->folder->klass->synchronise) {
|
2007-09-16 08:30:16 +02:00
|
|
|
statuswindow_print_all(_("Synchronising %s for offline use...\n"), item->path ? item->path : "(null)");
|
2007-07-20 18:20:59 +02:00
|
|
|
item->folder->klass->synchronise(item,
|
|
|
|
item->prefs->offlinesync_days);
|
|
|
|
if (item->prefs->offlinesync_days > 0 &&
|
|
|
|
item->prefs->remove_old_bodies)
|
|
|
|
folder_item_clean_local_files(item, item->prefs->offlinesync_days);
|
2007-09-16 08:30:16 +02:00
|
|
|
statuswindow_pop_all();
|
2007-04-03 09:08:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-08 20:28:36 +02:00
|
|
|
static void folder_item_synchronise_func(FolderItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
Folder *folder = (Folder *)data;
|
|
|
|
if (folder == NULL || item->folder == folder) {
|
2007-04-03 09:08:26 +02:00
|
|
|
folder_item_synchronise(item);
|
2005-09-08 20:28:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void folder_synchronise(Folder *folder)
|
|
|
|
{
|
|
|
|
folder_func_to_all_folders(folder_item_synchronise_func, folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _WantSyncData {
|
|
|
|
Folder *folder;
|
|
|
|
gboolean want_sync;
|
|
|
|
} WantSyncData;
|
|
|
|
|
|
|
|
static void folder_item_want_synchronise_func(FolderItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
WantSyncData *want_sync_data = (WantSyncData *)data;
|
|
|
|
|
|
|
|
if (want_sync_data->folder == NULL || item->folder == want_sync_data->folder) {
|
2006-01-25 19:41:10 +01:00
|
|
|
if (item->prefs->offlinesync && item->folder->klass->synchronise)
|
|
|
|
want_sync_data->want_sync |= TRUE;
|
2005-09-08 20:28:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean folder_want_synchronise(Folder *folder)
|
|
|
|
{
|
|
|
|
WantSyncData *want_sync_data = g_new0(WantSyncData, 1);
|
|
|
|
gboolean result;
|
|
|
|
want_sync_data->folder = folder;
|
2006-01-25 19:41:10 +01:00
|
|
|
want_sync_data->want_sync = FALSE;
|
2005-09-08 20:28:36 +02:00
|
|
|
|
|
|
|
folder_func_to_all_folders(folder_item_want_synchronise_func, want_sync_data);
|
|
|
|
result = want_sync_data->want_sync;
|
|
|
|
g_free(want_sync_data);
|
2007-02-07 12:13:37 +01:00
|
|
|
if (result > 0)
|
|
|
|
debug_print("Folder %s wants sync\n", folder->name);
|
2005-09-08 20:28:36 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-06-13 21:37:01 +02:00
|
|
|
void folder_item_set_batch (FolderItem *item, gboolean batch)
|
|
|
|
{
|
2007-12-10 19:53:01 +01:00
|
|
|
if (!item || !item->folder)
|
|
|
|
return;
|
2005-06-13 21:37:01 +02:00
|
|
|
if (item->folder->klass->set_batch) {
|
|
|
|
item->folder->klass->set_batch(item->folder, item, batch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-07 15:39:27 +02:00
|
|
|
gboolean folder_has_parent_of_type(FolderItem *item,
|
|
|
|
SpecialFolderItemType type)
|
|
|
|
{
|
|
|
|
FolderItem *cur = item;
|
2005-08-10 08:20:49 +02:00
|
|
|
|
2009-01-27 10:08:50 +01:00
|
|
|
if (!item)
|
|
|
|
return FALSE;
|
2005-08-10 08:20:49 +02:00
|
|
|
/* if we already know it, make it short */
|
|
|
|
if (item->parent_stype != -1) {
|
|
|
|
return (item->parent_stype == type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we don't, find the type from the first possible parent,
|
|
|
|
* and set our parent type to be faster next time */
|
2005-08-07 15:39:27 +02:00
|
|
|
while (cur) {
|
2005-08-08 18:45:29 +02:00
|
|
|
if (cur->stype == type || cur->parent_stype == type) {
|
2005-08-08 18:52:01 +02:00
|
|
|
item->parent_stype = type;
|
2005-08-07 15:39:27 +02:00
|
|
|
return TRUE;
|
2005-08-08 18:45:29 +02:00
|
|
|
}
|
2005-08-07 15:39:27 +02:00
|
|
|
cur = folder_item_parent(cur);
|
|
|
|
}
|
2005-08-10 08:20:49 +02:00
|
|
|
|
|
|
|
/* if we didn't match what was asked, we didn't return. If our
|
|
|
|
* parent type is unknown, we may as well find it now to be faster
|
|
|
|
* later. */
|
|
|
|
if (item->parent_stype == -1) {
|
|
|
|
cur = item;
|
|
|
|
while (cur) {
|
|
|
|
/* here's an exception: Inbox subfolders are normal. */
|
|
|
|
if (item->parent_stype == -1 && cur->stype == F_INBOX
|
|
|
|
&& item != cur) {
|
|
|
|
item->parent_stype = F_NORMAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* ah, we know this parent's parent's type, we may as
|
|
|
|
* well copy it instead of going up the full way */
|
|
|
|
if (cur->parent_stype != -1) {
|
|
|
|
item->parent_stype = cur->parent_stype;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* we found a parent that has a special type. That's
|
|
|
|
* our parent type. */
|
|
|
|
if (cur->stype != F_NORMAL) {
|
|
|
|
cur->parent_stype = cur->stype;
|
|
|
|
item->parent_stype = cur->stype;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* if we didn't find anything, go up once more */
|
|
|
|
cur = folder_item_parent(cur);
|
|
|
|
}
|
|
|
|
/* as we still didn't find anything, our parents must all be
|
|
|
|
* normal. */
|
|
|
|
if (item->parent_stype == -1) {
|
|
|
|
item->parent_stype = F_NORMAL;
|
|
|
|
}
|
|
|
|
}
|
2005-08-07 15:39:27 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-12 21:01:48 +01:00
|
|
|
gboolean folder_subscribe (const gchar *uri)
|
|
|
|
{
|
|
|
|
GList *cur;
|
|
|
|
for (cur = folder_get_list(); cur != NULL; cur = g_list_next(cur)) {
|
|
|
|
Folder *folder = (Folder *) cur->data;
|
|
|
|
|
|
|
|
if (folder->klass->subscribe
|
|
|
|
&& folder->klass->subscribe(folder, uri)) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
}
|
2006-10-04 08:18:28 +02:00
|
|
|
|
|
|
|
gboolean folder_get_sort_type (Folder *folder,
|
|
|
|
FolderSortKey *sort_key,
|
|
|
|
FolderSortType *sort_type)
|
|
|
|
{
|
|
|
|
if (!folder || !sort_key || !sort_type)
|
|
|
|
return FALSE;
|
|
|
|
if (folder->klass->get_sort_type == NULL)
|
|
|
|
return FALSE;
|
|
|
|
folder->klass->get_sort_type(folder, sort_key, sort_type);
|
|
|
|
return TRUE;
|
|
|
|
}
|