#endif
#include "alertpanel.h"
#include "news.h"
-#include "imap.h"
#include "hooks.h"
#include "msgcache.h"
if (msginfo->refcnt > 0)
return;
- debug_print("freeing msginfo %d is %s\n", msginfo->msgnum, msginfo->folder ? msginfo->folder->path : "(nil)");
+ debug_print("freeing msginfo %d in %s\n", msginfo->msgnum, msginfo->folder ? msginfo->folder->path : "(nil)");
if (msginfo->to_folder) {
msginfo->to_folder->op_count--;
return (newsval != 0 ? newsval : mailval);
}
-#define CHANGE_FLAGS(msginfo) \
-{ \
-if (msginfo->folder->folder->class->change_flags != NULL) \
-msginfo->folder->folder->class->change_flags(msginfo->folder->folder, \
- msginfo->folder, \
- msginfo); \
-}
-
-void procmsg_msginfo_set_flags(MsgInfo *msginfo, MsgPermFlags perm_flags, MsgTmpFlags tmp_flags)
+static void update_folder_msg_counts(FolderItem *item, MsgInfo *msginfo, MsgPermFlags old)
{
- FolderItem *item;
- MsgInfoUpdate msginfo_update;
-
- g_return_if_fail(msginfo != NULL);
- item = msginfo->folder;
- g_return_if_fail(item != NULL);
-
- debug_print("Setting flags for message %d in folder %s\n", msginfo->msgnum, item->path);
+ MsgPermFlags new = msginfo->flags.perm_flags;
- /* if new flag is set */
- if ((perm_flags & MSG_NEW) && !MSG_IS_NEW(msginfo->flags) &&
- !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ /* NEW flag */
+ if (!(old & MSG_NEW) && (new & MSG_NEW)) {
item->new++;
}
- /* if unread flag is set */
- if ((perm_flags & MSG_UNREAD) && !MSG_IS_UNREAD(msginfo->flags) &&
- !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ if ((old & MSG_NEW) && !(new & MSG_NEW)) {
+ item->new--;
+ }
+
+ /* UNREAD flag */
+ if (!(old & MSG_UNREAD) && (new & MSG_UNREAD)) {
item->unread++;
+ if (procmsg_msg_has_marked_parent(msginfo))
+ item->unreadmarked++;
}
- if (!MSG_IS_UNREAD(msginfo->flags) &&(perm_flags & MSG_UNREAD)
- && procmsg_msg_has_marked_parent(msginfo)) {
- item->unreadmarked++;
+ if ((old & MSG_UNREAD) && !(new & MSG_UNREAD)) {
+ item->unread--;
+ if (procmsg_msg_has_marked_parent(msginfo))
+ item->unreadmarked--;
}
- if (!MSG_IS_MARKED(msginfo->flags) && (perm_flags & MSG_MARKED)) {
+ /* MARK flag */
+ if (!(old & MSG_MARKED) && (new & MSG_MARKED)) {
procmsg_update_unread_children(msginfo, TRUE);
}
+ if ((old & MSG_MARKED) && !(new & MSG_MARKED)) {
+ procmsg_update_unread_children(msginfo, FALSE);
+ }
+}
- /* if ignore thread flag is set */
- if ((perm_flags & MSG_IGNORE_THREAD) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
- if (MSG_IS_NEW(msginfo->flags) || (perm_flags & MSG_NEW)) {
- item->new--;
- }
- if (MSG_IS_UNREAD(msginfo->flags) || (perm_flags & MSG_UNREAD)) {
- item->unread--;
- }
- if ((perm_flags & MSG_UNREAD) || (MSG_IS_UNREAD(msginfo->flags)
- && procmsg_msg_has_marked_parent(msginfo))) {
- item->unreadmarked--;
- }
- if ((perm_flags & MSG_MARKED) || (MSG_IS_MARKED(msginfo->flags)
- && !MSG_IS_IGNORE_THREAD(msginfo->flags))) {
- procmsg_update_unread_children(msginfo, FALSE);
- }
+void procmsg_msginfo_set_flags(MsgInfo *msginfo, MsgPermFlags perm_flags, MsgTmpFlags tmp_flags)
+{
+ FolderItem *item;
+ MsgInfoUpdate msginfo_update;
+ MsgPermFlags perm_flags_new, perm_flags_old;
- }
+ g_return_if_fail(msginfo != NULL);
+ item = msginfo->folder;
+ g_return_if_fail(item != NULL);
+
+ debug_print("Setting flags for message %d in folder %s\n", msginfo->msgnum, item->path);
- if (FOLDER_TYPE(msginfo->folder->folder) == F_IMAP)
- imap_msg_set_perm_flags(msginfo, perm_flags);
+ /* Perm Flags handling */
+ perm_flags_old = msginfo->flags.perm_flags;
+ perm_flags_new = msginfo->flags.perm_flags | perm_flags;
+ if ((perm_flags & MSG_IGNORE_THREAD) || (perm_flags_old & MSG_IGNORE_THREAD)) {
+ perm_flags_new &= ~(MSG_NEW | MSG_UNREAD);
+ }
- msginfo->flags.perm_flags |= perm_flags;
- msginfo->flags.tmp_flags |= tmp_flags;
+ if (perm_flags_old != perm_flags_new) {
+ folder_item_change_msg_flags(msginfo->folder, msginfo, perm_flags_new);
- msginfo_update.msginfo = msginfo;
- hooks_invoke(MSGINFO_UPDATE_HOOKLIST, &msginfo_update);
- folder_item_update(msginfo->folder, F_ITEM_UPDATE_MSGCNT);
+ update_folder_msg_counts(item, msginfo, perm_flags_old);
- CHANGE_FLAGS(msginfo);
+ msginfo_update.msginfo = msginfo;
+ hooks_invoke(MSGINFO_UPDATE_HOOKLIST, &msginfo_update);
+ folder_item_update(msginfo->folder, F_ITEM_UPDATE_MSGCNT);
+ }
}
void procmsg_msginfo_unset_flags(MsgInfo *msginfo, MsgPermFlags perm_flags, MsgTmpFlags tmp_flags)
{
FolderItem *item;
MsgInfoUpdate msginfo_update;
+ MsgPermFlags perm_flags_new, perm_flags_old;
g_return_if_fail(msginfo != NULL);
item = msginfo->folder;
- g_return_if_fail(item != NULL);
+ g_return_if_fail(item != NULL);
debug_print("Unsetting flags for message %d in folder %s\n", msginfo->msgnum, item->path);
- /* if new flag is unset */
- if ((perm_flags & MSG_NEW) && MSG_IS_NEW(msginfo->flags) &&
- !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
- item->new--;
- }
-
- /* if unread flag is unset */
- if ((perm_flags & MSG_UNREAD) && MSG_IS_UNREAD(msginfo->flags) &&
- !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
- item->unread--;
- }
+ /* Perm Flags handling */
+ perm_flags_old = msginfo->flags.perm_flags;
+ perm_flags_new = msginfo->flags.perm_flags & ~perm_flags;
- if (MSG_IS_UNREAD(msginfo->flags) && (perm_flags & MSG_UNREAD)
- && !MSG_IS_IGNORE_THREAD(msginfo->flags)
- && procmsg_msg_has_marked_parent(msginfo)) {
- item->unreadmarked--;
- }
+ if (perm_flags_old != perm_flags_new) {
+ folder_item_change_msg_flags(msginfo->folder, msginfo, perm_flags_new);
- if (MSG_IS_MARKED(msginfo->flags) && (perm_flags & MSG_MARKED)
- && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
- procmsg_update_unread_children(msginfo, FALSE);
- }
-
- /* if ignore thread flag is unset */
- if ((perm_flags & MSG_IGNORE_THREAD) && MSG_IS_IGNORE_THREAD(msginfo->flags)) {
- if (MSG_IS_NEW(msginfo->flags) && !(perm_flags & MSG_NEW)) {
- item->new++;
- }
- if (MSG_IS_UNREAD(msginfo->flags) && !(perm_flags & MSG_UNREAD)) {
- item->unread++;
- }
- if (MSG_IS_UNREAD(msginfo->flags) && !(perm_flags & MSG_UNREAD)
- && procmsg_msg_has_marked_parent(msginfo)) {
- item->unreadmarked++;
- }
- if (MSG_IS_MARKED(msginfo->flags) && !(perm_flags & MSG_MARKED)) {
- procmsg_update_unread_children(msginfo, TRUE);
- }
+ update_folder_msg_counts(item, msginfo, perm_flags_old);
+ msginfo_update.msginfo = msginfo;
+ hooks_invoke(MSGINFO_UPDATE_HOOKLIST, &msginfo_update);
+ folder_item_update(msginfo->folder, F_ITEM_UPDATE_MSGCNT);
}
-
- if (FOLDER_TYPE(msginfo->folder->folder) == F_IMAP)
- imap_msg_unset_perm_flags(msginfo, perm_flags);
-
- msginfo->flags.perm_flags &= ~perm_flags;
- msginfo->flags.tmp_flags &= ~tmp_flags;
-
- msginfo_update.msginfo = msginfo;
- hooks_invoke(MSGINFO_UPDATE_HOOKLIST, &msginfo_update);
- folder_item_update(msginfo->folder, F_ITEM_UPDATE_MSGCNT);
-
- CHANGE_FLAGS(msginfo);
}
/*!