+ debug_print(_("saving sent message...\n"));
+
+ outbox = folder_find_item_from_identifier(savecopyfolder);
+ if(!outbox)
+ outbox = folder_get_default_outbox();
+
+ procmsg_save_to_outbox(outbox, file, TRUE);
+ }
+
+ if(replymessageid != NULL) {
+ gchar **tokens;
+ FolderItem *item;
+
+ tokens = g_strsplit(replymessageid, "\x7f", 0);
+ item = folder_find_item_from_identifier(tokens[0]);
+ if(item != NULL) {
+ MsgInfo *msginfo;
+
+ msginfo = folder_item_fetch_msginfo(item, atoi(tokens[1]));
+ if((msginfo != NULL) && (strcmp(msginfo->msgid, tokens[2]) != 0)) {
+ procmsg_msginfo_free(msginfo);
+ msginfo = NULL;
+ }
+
+ if(msginfo == NULL) {
+ msginfo = folder_item_fetch_msginfo_by_id(item, tokens[2]);
+ }
+
+ if(msginfo != NULL) {
+ procmsg_msginfo_unset_flags(msginfo, MSG_FORWARDED, 0);
+ procmsg_msginfo_set_flags(msginfo, MSG_REPLIED, 0);
+
+ procmsg_msginfo_free(msginfo);
+ }
+ }
+ g_strfreev(tokens);
+ }
+
+ g_free(savecopyfolder);
+ g_free(replymessageid);
+
+ return (newsval != 0 ? newsval : mailval);
+}
+
+#define CHANGE_FLAGS(msginfo) \
+{ \
+if (msginfo->folder->folder->change_flags != NULL) \
+msginfo->folder->folder->change_flags(msginfo->folder->folder, \
+ msginfo->folder, \
+ msginfo); \
+}
+
+void procmsg_msginfo_set_flags(MsgInfo *msginfo, MsgPermFlags perm_flags, MsgTmpFlags tmp_flags)
+{
+ gboolean changed = FALSE;
+ FolderItem *item = msginfo->folder;
+
+ debug_print(_("Setting flags for message %d in folder %s\n"), msginfo->msgnum, item->path);
+
+ /* if new flag is set */
+ if((perm_flags & MSG_NEW) && !MSG_IS_NEW(msginfo->flags) &&
+ !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
+ item->new++;
+ changed = TRUE;
+ }
+
+ /* 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);