2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2004 Hiroyuki Yamamoto & The Sylpheed-Claws Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "prefs_common.h"
24 #include "folderutils.h"
26 gint folderutils_delete_duplicates(FolderItem *item,
27 DeleteDuplicatesMode mode)
30 GSList *msglist, *cur, *duplist = NULL;
33 if (item->folder->klass->remove_msg == NULL)
36 debug_print("Deleting duplicated messages...\n");
38 msglist = folder_item_get_msg_list(item);
41 table = g_hash_table_new(g_str_hash, g_str_equal);
43 for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
44 MsgInfo *msginfo = (MsgInfo *) cur->data;
45 MsgInfo *msginfo_dup = NULL;
47 if (!msginfo || !msginfo->msgid || !*msginfo->msgid)
50 msginfo_dup = g_hash_table_lookup(table, msginfo->msgid);
51 if (msginfo_dup == NULL)
52 g_hash_table_insert(table, msginfo->msgid, msginfo);
54 if ((MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_UNREAD(msginfo_dup->flags)) ||
55 (MSG_IS_UNREAD(msginfo->flags) == MSG_IS_UNREAD(msginfo_dup->flags))) {
56 duplist = g_slist_append(duplist, msginfo);
58 duplist = g_slist_append(duplist, msginfo_dup);
59 g_hash_table_insert(table, msginfo->msgid, msginfo);
66 case DELETE_DUPLICATES_REMOVE: {
67 FolderItem *trash = item->folder->trash;
69 if (item->stype == F_TRASH || trash == NULL)
70 folder_item_remove_msgs(item, duplist);
72 folder_item_move_msgs(trash, duplist);
75 case DELETE_DUPLICATES_SETFLAG:
76 for (cur = duplist; cur != NULL; cur = g_slist_next(cur)) {
77 MsgInfo *msginfo = (MsgInfo *) cur->data;
79 procmsg_msginfo_set_to_folder(msginfo, NULL);
80 procmsg_msginfo_unset_flags(msginfo, MSG_MARKED, MSG_MOVE | MSG_COPY);
81 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
88 dups = g_slist_length(duplist);
89 g_slist_free(duplist);
91 g_hash_table_destroy(table);
93 for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
94 MsgInfo *msginfo = (MsgInfo *) cur->data;
96 procmsg_msginfo_free(msginfo);
98 g_slist_free(msglist);
100 debug_print("done.\n");
105 void folderutils_mark_all_read(FolderItem *item)
107 MsgInfoList *msglist, *cur;
109 g_return_if_fail(item != NULL);
111 msglist = folder_item_get_msg_list(item);
115 folder_item_update_freeze();
116 for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
117 MsgInfo *msginfo = cur->data;
119 if (msginfo->flags.perm_flags & (MSG_NEW | MSG_UNREAD))
120 procmsg_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
121 procmsg_msginfo_free(msginfo);
123 folder_item_update_thaw();
125 g_slist_free(msglist);