From 7d17dc2230c4a3b650849ad6e2dcdc5ebf6cb47e Mon Sep 17 00:00:00 2001
From: Michael Zucci <zucchi@src.gnome.org>
Date: Fri, 21 Sep 2001 03:05:03 +0000
Subject: New function to just load the summary. Not much use yet, until unread

	* camel-folder-summary.c (camel_folder_summary_header_load): New
	function to just load the summary.  Not much use yet, until unread
	counts are stored in the summary (which now looks like too much
	work!).

	* camel-mime-utils.c (header_decode_mailbox): Crappy fix for
	stupid mailers.  If we get 'name b. name <foo>' then treat it as
	'"name b. name" <foo>'.  See 8147.
	(header_decode_mailbox): Another fix for really broken mailers
	that have things that look like addresses followed by <address>
	bits.
	(rfc2047_encode_word): Escape ??= to avoid some bizarre warning
	about trigraphs.

	(scan_dir): If we dont have the folder open, then scan the 'new'
	and 'cur' folders for new and unread messages to count instead.

svn path=/trunk/; revision=13040
---
 camel/providers/local/camel-maildir-store.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

(limited to 'camel/providers/local')

diff --git a/camel/providers/local/camel-maildir-store.c b/camel/providers/local/camel-maildir-store.c
index b0d4c072f8..d6392b5ac2 100644
--- a/camel/providers/local/camel-maildir-store.c
+++ b/camel/providers/local/camel-maildir-store.c
@@ -279,6 +279,33 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch
 	else
 		unread = 0;
 	CAMEL_STORE_UNLOCK(store, cache_lock);
+
+	/* if we dont have a folder, then scan the directory and get the unread
+	   count from there, which is reasonably cheap (on decent filesystem) */
+	/* Well we could get this from the summary, but this is more accurate */
+	if (folder == NULL) {
+		unread = 0;
+		dir = opendir(new);
+		if (dir) {
+			/* we assume that all files here are unread ones */
+			while ( (d = readdir(dir)) ) {
+				if (d->d_name[0] != '.')
+					unread++;
+			}
+			closedir(dir);
+		}
+		dir = opendir(cur);
+		if (dir) {
+			/* any files with flags but not the 'S' (seen) flag are unread */
+			while ( (d = readdir(dir)) ) {
+				char *p = strstr(d->d_name, ":2,");
+
+				if (p && strchr(p, 'S') == NULL)
+					unread++;
+			}
+			closedir(dir);
+		}
+	}
 	
 	fi = camel_folder_info_new(uri, path, base, unread);
 	
@@ -294,6 +321,8 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch
 	g_free(cur);
 	g_free(new);
 
+	unread = 0;
+
 	/* always look further if asked */
 	if (((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE) || parent == NULL)) {
 		dir = opendir(name);
-- 
cgit