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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "prefs_common.h"
24 #include "folderutils.h"
25 #include "prefs_account.h"
28 gint folderutils_delete_duplicates(FolderItem *item,
29 DeleteDuplicatesMode mode)
32 GSList *msglist, *cur, *duplist = NULL;
35 if (item->folder->klass->remove_msg == NULL)
38 debug_print("Deleting duplicated messages...\n");
40 msglist = folder_item_get_msg_list(item);
43 table = g_hash_table_new(g_str_hash, g_str_equal);
45 folder_item_update_freeze();
46 for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
47 MsgInfo *msginfo = (MsgInfo *) cur->data;
48 MsgInfo *msginfo_dup = NULL;
50 if (!msginfo || !msginfo->msgid || !*msginfo->msgid)
53 msginfo_dup = g_hash_table_lookup(table, msginfo->msgid);
54 if (msginfo_dup == NULL)
55 g_hash_table_insert(table, msginfo->msgid, msginfo);
57 if ((MSG_IS_UNREAD(msginfo->flags) && !MSG_IS_UNREAD(msginfo_dup->flags)) ||
58 (MSG_IS_UNREAD(msginfo->flags) == MSG_IS_UNREAD(msginfo_dup->flags))) {
59 duplist = g_slist_append(duplist, msginfo);
61 duplist = g_slist_append(duplist, msginfo_dup);
62 g_hash_table_insert(table, msginfo->msgid, msginfo);
69 case DELETE_DUPLICATES_REMOVE: {
70 FolderItem *trash = NULL;
71 gboolean in_trash = FALSE;
74 if (NULL != (ac = account_find_from_item(item))) {
75 trash = account_get_special_folder(ac, F_TRASH);
76 in_trash = (trash != NULL && trash == item);
79 trash = item->folder->trash;
81 if (folder_has_parent_of_type(item, F_TRASH) || trash == NULL || in_trash)
82 folder_item_remove_msgs(item, duplist);
84 folder_item_move_msgs(trash, duplist);
87 case DELETE_DUPLICATES_SETFLAG:
88 for (cur = duplist; cur != NULL; cur = g_slist_next(cur)) {
89 MsgInfo *msginfo = (MsgInfo *) cur->data;
91 procmsg_msginfo_set_to_folder(msginfo, NULL);
92 procmsg_msginfo_unset_flags(msginfo, MSG_MARKED, MSG_MOVE | MSG_COPY);
93 procmsg_msginfo_set_flags(msginfo, MSG_DELETED, 0);
100 dups = g_slist_length(duplist);
101 g_slist_free(duplist);
103 g_hash_table_destroy(table);
105 for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
106 MsgInfo *msginfo = (MsgInfo *) cur->data;
108 procmsg_msginfo_free(msginfo);
110 g_slist_free(msglist);
112 folder_item_update_thaw();
114 debug_print("done.\n");
119 void folderutils_mark_all_read(FolderItem *item)
121 MsgInfoList *msglist, *cur;
123 g_return_if_fail(item != NULL);
125 msglist = folder_item_get_msg_list(item);
129 folder_item_update_freeze();
130 folder_item_set_batch(item, TRUE);
131 for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
132 MsgInfo *msginfo = cur->data;
134 if (msginfo->flags.perm_flags & (MSG_NEW | MSG_UNREAD))
135 procmsg_msginfo_unset_flags(msginfo, MSG_NEW | MSG_UNREAD, 0);
136 procmsg_msginfo_free(msginfo);
138 folder_item_set_batch(item, FALSE);
139 folder_item_update_thaw();
141 g_slist_free(msglist);