claws-mail/src/folderutils.c
Colin Leroy e8135a04cd 2006-05-24 [colin] 2.2.0cvs54
attention cvs users: if you manage to crash
	Sylpheed-Claws while moving, copying or deleting
	mails, we *are* interested in stack traces and
	valgrind logs. It looks stable, but one never
	knows...

	* src/folder.c
		Add progressbar for cache updates
	* src/folderutils.c
		Optimize Mark all read in the current
		folder
	* src/mh.c
		Add progressbar for copy/move
	* src/procmsg.c
		Optimize O(n^2) in copy/move
	* src/summaryview.c
	* src/gtk/gtksctree.c
		Optimize O(n^2) algos
	* src/common/timing.h
		Display ms instead of us
2006-05-24 18:02:15 +00:00

154 lines
4.2 KiB
C

/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
* Copyright (C) 2004-2006 Hiroyuki Yamamoto & The Sylpheed-Claws Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <glib.h>
#include "utils.h"
#include "prefs_common.h"
#include "folderutils.h"
#include "prefs_account.h"
#include "account.h"
#include "mainwindow.h"
#include "summaryview.h"
gint folderutils_delete_duplicates(FolderItem *item,
DeleteDuplicatesMode mode)
{
GHashTable *table;
GSList *msglist, *cur, *duplist = NULL;
guint dups;
if (item->folder->klass->remove_msg == NULL)
return -1;
debug_print("Deleting duplicated messages...\n");
msglist = folder_item_get_msg_list(item);
if (msglist == NULL)
return 0;
table = g_hash_table_new(g_str_hash, g_str_equal);
folder_item_update_freeze();
for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
MsgInfo *msginfo = (MsgInfo *) cur->data;
MsgInfo *msginfo_dup = NULL;
if (!msginfo || !msginfo->msgid || !*msginfo->msgid)
continue;
msginfo_dup = g_hash_table_lookup(table, msginfo->msgid);
if (msginfo_dup == NULL)
g_hash_table_insert(table, msginfo->msgid, msginfo);
else {
if ((MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_UNREAD(msginfo_dup->flags)) ||
(MSG_IS_UNREAD(msginfo->flags) == MSG_IS_UNREAD(msginfo_dup->flags))) {
duplist = g_slist_append(duplist, msginfo);
} else {
duplist = g_slist_append(duplist, msginfo_dup);
g_hash_table_insert(table, msginfo->msgid, msginfo);
}
}
}
if (duplist) {
switch (mode) {
case DELETE_DUPLICATES_REMOVE: {
FolderItem *trash = NULL;
gboolean in_trash = FALSE;
PrefsAccount *ac;
if (NULL != (ac = account_find_from_item(item))) {
trash = account_get_special_folder(ac, F_TRASH);
in_trash = (trash != NULL && trash == item);
}
if (trash == NULL)
trash = item->folder->trash;
if (folder_has_parent_of_type(item, F_TRASH) || trash == NULL || in_trash)
folder_item_remove_msgs(item, duplist);
else
folder_item_move_msgs(trash, duplist);
break;
}
case DELETE_DUPLICATES_SETFLAG:
for (cur = duplist; cur != NULL; cur = g_slist_next(cur)) {
MsgInfo *msginfo = (MsgInfo *) cur->data;
procmsg_msginfo_set_to_folder(msginfo, NULL);
procmsg_msginfo_unset_flags(msginfo, MSG_MARKED, MSG_MOVE | MSG_COPY);
procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
}
break;
default:
break;
}
}
dups = g_slist_length(duplist);
g_slist_free(duplist);
g_hash_table_destroy(table);
for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
MsgInfo *msginfo = (MsgInfo *) cur->data;
procmsg_msginfo_free(msginfo);
}
g_slist_free(msglist);
folder_item_update_thaw();
debug_print("done.\n");
return dups;
}
void folderutils_mark_all_read(FolderItem *item)
{
MsgInfoList *msglist, *cur;
MainWindow *mainwin = mainwindow_get_mainwindow();
g_return_if_fail(item != NULL);
folder_item_update_freeze();
if (mainwin && mainwin->summaryview &&
mainwin->summaryview->folder_item == item) {
summary_mark_all_read(mainwin->summaryview);
} else {
msglist = folder_item_get_msg_list(item);
if (msglist == NULL) {
folder_item_update_thaw();
return;
}
folder_item_set_batch(item, TRUE);
for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
MsgInfo *msginfo = cur->data;
if (msginfo->flags.perm_flags & (MSG_NEW | MSG_UNREAD))
procmsg_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
procmsg_msginfo_free(msginfo);
}
folder_item_set_batch(item, FALSE);
folder_item_close(item);
g_slist_free(msglist);
}
folder_item_update_thaw();
}