+ /* if unread flag is set */
+ if((perm_flags & MSG_UNREAD) && !MSG_IS_UNREAD(msginfo->flags) &&
+ !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ item->unread++;
+ changed = TRUE;
+ }
+
+ /* 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--;
+ changed = TRUE;
+ }
+ if(MSG_IS_UNREAD(msginfo->flags) || (perm_flags & MSG_UNREAD)) {
+ item->unread--;
+ changed = TRUE;
+ }
+ }
+
+ if (MSG_IS_IMAP(msginfo->flags))
+ imap_msg_set_perm_flags(msginfo, perm_flags);
+
+ msginfo->flags.perm_flags |= perm_flags;
+ msginfo->flags.tmp_flags |= tmp_flags;
+
+ if(changed) {
+ folderview_update_item(item, FALSE);
+ }
+ CHANGE_FLAGS(msginfo);
+ procmsg_msginfo_write_flags(msginfo);
+}
+
+void procmsg_msginfo_unset_flags(MsgInfo *msginfo, MsgPermFlags perm_flags, MsgTmpFlags tmp_flags)
+{
+ gboolean changed = FALSE;
+ FolderItem *item = msginfo->folder;
+
+ 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--;
+ changed = TRUE;
+ }
+
+ /* if unread flag is unset */
+ if((perm_flags & MSG_UNREAD) && MSG_IS_UNREAD(msginfo->flags) &&
+ !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ item->unread--;
+ changed = TRUE;
+ }
+
+ /* 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++;
+ changed = TRUE;
+ }
+ if(MSG_IS_UNREAD(msginfo->flags) && !(perm_flags & MSG_UNREAD)) {
+ item->unread++;
+ changed = TRUE;
+ }
+ }
+
+ if (MSG_IS_IMAP(msginfo->flags))
+ imap_msg_unset_perm_flags(msginfo, perm_flags);
+
+ msginfo->flags.perm_flags &= ~perm_flags;
+ msginfo->flags.tmp_flags &= ~tmp_flags;
+
+ if(changed) {
+ folderview_update_item(item, FALSE);
+ }
+ CHANGE_FLAGS(msginfo);
+ procmsg_msginfo_write_flags(msginfo);
+}
+
+void procmsg_msginfo_write_flags(MsgInfo *msginfo)
+{
+ gchar *destdir;
+ FILE *fp;
+
+ destdir = folder_item_get_path(msginfo->folder);
+ if (!is_dir_exist(destdir))
+ make_dir_hier(destdir);
+
+ if ((fp = procmsg_open_mark_file(destdir, TRUE))) {
+ procmsg_write_flags(msginfo, fp);
+ fclose(fp);
+ } else {
+ g_warning(_("Can't open mark file.\n"));
+ }
+
+ g_free(destdir);