Index: camel/providers/imap/ChangeLog
===================================================================
--- camel/providers/imap/ChangeLog	(revision 9006)
+++ camel/providers/imap/ChangeLog	(working copy)
@@ -1,3 +1,14 @@
+2008-06-19  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #534938
+
+	* camel-imap-private.h: (struct _CamelImapFolderPrivate): New property.
+	* camel-imap-folder.c: (camel_imap_folder_init), (imap_finalize),
+	(imap_folder_add_ignore_recent), (imap_folder_uid_in_ignore_recent),
+	(do_append), (handle_copyuid), (imap_update_summary):
+	Remember which IDs we added to the folder and ignore these in report
+	of recent messages, because we know about them already.
+
 2008-06-05  Milan Crha  <mcrha@redhat.com>
 
 	** Fix for bug #530241
Index: camel/providers/imap/camel-imap-folder.c
===================================================================
--- camel/providers/imap/camel-imap-folder.c	(revision 9006)
+++ camel/providers/imap/camel-imap-folder.c	(working copy)
@@ -204,6 +204,7 @@ camel_imap_folder_init (gpointer object,
 	g_static_mutex_init(&imap_folder->priv->search_lock);
 	g_static_rec_mutex_init(&imap_folder->priv->cache_lock);
 #endif
+	imap_folder->priv->ignore_recent = NULL;
 
 	imap_folder->need_rescan = TRUE;
 }
@@ -444,6 +445,9 @@ imap_finalize (CamelObject *object)
 	g_static_mutex_free(&imap_folder->priv->search_lock);
 	g_static_rec_mutex_free(&imap_folder->priv->cache_lock);
 #endif
+	if (imap_folder->priv->ignore_recent)
+		g_hash_table_unref (imap_folder->priv->ignore_recent);
+
 	g_free(imap_folder->priv);
 }
 
@@ -1543,6 +1547,27 @@ imap_append_offline (CamelFolder *folder
 		g_free (uid);
 }
 
+static void
+imap_folder_add_ignore_recent (CamelImapFolder *imap_folder, const char *uid)
+{
+	g_return_if_fail (imap_folder != NULL);
+	g_return_if_fail (uid != NULL);
+
+	if (!imap_folder->priv->ignore_recent)
+		imap_folder->priv->ignore_recent = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL);
+
+	g_hash_table_insert (imap_folder->priv->ignore_recent, g_strdup (uid), GINT_TO_POINTER (1));
+}
+
+static gboolean
+imap_folder_uid_in_ignore_recent (CamelImapFolder *imap_folder, const char *uid)
+{
+	g_return_val_if_fail (imap_folder != NULL, FALSE);
+	g_return_val_if_fail (uid != NULL, FALSE);
+
+	return imap_folder->priv->ignore_recent && g_hash_table_lookup (imap_folder->priv->ignore_recent, uid);
+}
+
 static CamelImapResponse *
 do_append (CamelFolder *folder, CamelMimeMessage *message,
 	   const CamelMessageInfo *info, char **uid,
@@ -1632,6 +1657,9 @@ retry:
 		}
 	} else
 		*uid = NULL;
+
+	if (*uid)
+		imap_folder_add_ignore_recent (CAMEL_IMAP_FOLDER (folder), *uid);
 	
 	return response2;
 }
@@ -1820,6 +1848,8 @@ handle_copyuid (CamelImapResponse *respo
 			camel_imap_message_cache_copy (scache, src->pdata[i],
 						       dcache, dest->pdata[i],
 						       NULL);
+
+			imap_folder_add_ignore_recent (CAMEL_IMAP_FOLDER (destination), dest->pdata[i]);
 		}
 		CAMEL_IMAP_FOLDER_REC_UNLOCK (source, cache_lock);
 		CAMEL_IMAP_FOLDER_REC_UNLOCK (destination, cache_lock);
@@ -3102,9 +3132,11 @@ imap_update_summary (CamelFolder *folder
 		camel_folder_summary_add (folder->summary, (CamelMessageInfo *)mi);
 		camel_folder_change_info_add_uid (changes, camel_message_info_uid (mi));
 
-		/* report all new messages as recent, even without that flag, thus new
-		   messages will be filtered even after saw by other software earlier */
-		if ((mi->info.flags & CAMEL_IMAP_MESSAGE_RECENT) != 0 || getenv ("FILTER_RECENT") == NULL)
+		/* Report all new messages as recent, even without that flag, thus new
+		   messages will be filtered even after saw by other software earlier.
+		   Only skip those which we added ourself, like after drag&drop to this folder. */
+		if (!imap_folder_uid_in_ignore_recent (imap_folder, camel_message_info_uid (mi))
+		    && ((mi->info.flags & CAMEL_IMAP_MESSAGE_RECENT) != 0 || getenv ("FILTER_RECENT") == NULL))
 			camel_folder_change_info_recent_uid (changes, camel_message_info_uid (mi));
 	}
 
@@ -3114,7 +3146,12 @@ imap_update_summary (CamelFolder *folder
 	}
 	
 	g_ptr_array_free (messages, TRUE);
-	
+
+	if (imap_folder->priv->ignore_recent) {
+		g_hash_table_unref (imap_folder->priv->ignore_recent);
+		imap_folder->priv->ignore_recent = NULL;
+	}
+
 	return;
 	
  lose:
@@ -3132,6 +3169,11 @@ imap_update_summary (CamelFolder *folder
 		}
 		g_ptr_array_free (messages, TRUE);
 	}
+
+	if (imap_folder->priv->ignore_recent) {
+		g_hash_table_unref (imap_folder->priv->ignore_recent);
+		imap_folder->priv->ignore_recent = NULL;
+	}
 }
 
 /* Called with the store's connect_lock locked */
Index: camel/providers/imap/camel-imap-private.h
===================================================================
--- camel/providers/imap/camel-imap-private.h	(revision 9006)
+++ camel/providers/imap/camel-imap-private.h	(working copy)
@@ -15,6 +15,7 @@ struct _CamelImapFolderPrivate {
 	GStaticMutex search_lock;	/* for locking the search object */
 	GStaticRecMutex cache_lock;	/* for locking the cache object */
 #endif
+	GHashTable *ignore_recent;	/* hash table of UIDs to ignore as recent when updating folder */
 };
 
 #ifdef ENABLE_THREADS
