[evolution-data-server] Bug #645498 - [maildir] Fails to show already read messages again



commit 5525186f73962604cd76576b180ab32d5ec0dc99
Author: Milan Crha <mcrha redhat com>
Date:   Wed Apr 20 17:24:34 2011 +0200

    Bug #645498 - [maildir] Fails to show already read messages again

 camel/providers/local/camel-maildir-folder.c |   43 ++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 9 deletions(-)
---
diff --git a/camel/providers/local/camel-maildir-folder.c b/camel/providers/local/camel-maildir-folder.c
index 990be8e..488e4d0 100644
--- a/camel/providers/local/camel-maildir-folder.c
+++ b/camel/providers/local/camel-maildir-folder.c
@@ -103,17 +103,42 @@ maildir_folder_get_filename (CamelFolder *folder,
 
 	mdi = (CamelMaildirMessageInfo *)info;
 
-	/* what do we do if the message flags (and :info data) changes?  filename mismatch - need to recheck I guess 
-	   If filename is NULL, it means folder_summary_check is not yet executed. */
+	/* If filename is NULL, it means folder_summary_check is not yet executed.
+	   Try to find the file in the folder and use it, otherwise construct its
+	   name based on actual flags.
+	*/
 	if (!camel_maildir_info_filename (mdi)) {
-		gchar *temp;
+		const gchar *uid = camel_message_info_uid (info);
 
-		temp = camel_maildir_summary_info_to_name (mdi);
-		res = g_strdup_printf("%s/cur/%s", lf->folder_path, temp);
+		if (uid) {
+			GDir *dir;
+			gchar *dirname;
 
-		g_free (temp);
-	} else
-		res = g_strdup_printf("%s/cur/%s", lf->folder_path, camel_maildir_info_filename (mdi));
+			dirname = g_strdup_printf ("%s/cur", lf->folder_path);
+			dir = g_dir_open (dirname, 0, NULL);
+			g_free (dirname);
+
+			if (dir) {
+				const gchar *filename;
+				gint uid_len = strlen (uid);
+
+				while (filename = g_dir_read_name (dir), filename) {
+					if (g_str_has_prefix (filename, uid) && (filename[uid_len] == '\0' || filename[uid_len] == ':')) {
+						camel_maildir_info_set_filename (mdi, g_strdup (filename));
+						break;
+					}
+				}
+
+				g_dir_close (dir);
+			}
+		}
+
+		if (!camel_maildir_info_filename (mdi)) {
+			camel_maildir_info_set_filename (mdi, camel_maildir_summary_info_to_name (mdi));
+		}
+	}
+
+	res = g_strdup_printf ("%s/cur/%s", lf->folder_path, camel_maildir_info_filename (mdi));
 
 	camel_message_info_free (info);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]