-+ *tmp = b;
-+ tmp->msgcount = msgcount;
-+ tmp->msg_unread = msg_unread;
-+ if(STAT_CHECK) {
-+ tmp->has_new = tmp->new = 1;
-+ BuffyCount++;
-+ }
- }
- else if (option(OPTCHECKMBOXSIZE))
- {
-@@ -366,17 +385,21 @@ int mutt_buffy_check (int force)
- if (tmp->newly_created &&
- (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
- tmp->newly_created = 0;
--
-+ }
- break;
-
- case M_MAILDIR:
-
-+ /* count new message */
- snprintf (path, sizeof (path), "%s/new", tmp->path);
- if ((dirp = opendir (path)) == NULL)
- {
- tmp->magic = 0;
- break;
- }
-+ tmp->msgcount = 0;
-+ tmp->msg_unread = 0;
-+ tmp->msg_flagged = 0;
- while ((de = readdir (dirp)) != NULL)
- {
- char *p;
-@@ -385,12 +408,36 @@ int mutt_buffy_check (int force)
- {
- if (!tmp->new)
- {
-- /* one new and undeleted message is enough */
-- BuffyCount++;
-- tmp->new = 1;
--
-- if (! option (OPTMAILDIRMTIME)) /* prevent stat calls */
-- break;
-+ tmp->has_new = tmp->new = 1;
-+ tmp->msgcount++;
-+ tmp->msg_unread++;
-+ }
-+ }
-+ if(tmp->msg_unread)
-+ BuffyCount++;
-+
-+ closedir (dirp);
-+
-+ /*
-+ * count read messages (for folderlist (sidebar) we also need to count
-+ * messages in cur so that we the total number of messages
-+ */
-+ snprintf (path, sizeof (path), "%s/cur", tmp->path);
-+ if ((dirp = opendir (path)) == NULL)
-+ {
-+ tmp->magic = 0;
-+ break;
-+ }
-+ while ((de = readdir (dirp)) != NULL)
-+ {
-+ char *p;
-+ if (*de->d_name != '.' &&
-+ (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')))
-+ {
-+ tmp->msgcount++;
-+ if (p && strchr(p + 3, 'F')) {
-+ tmp->msg_flagged++;
-+ }
- }
- snprintf (path, sizeof (path), "%s/new/%s", tmp->path, de->d_name);
- if (!stat (path, &smd) && smd.st_mtime > tmp->mtime)
-@@ -403,8 +450,25 @@ int mutt_buffy_check (int force)
- break;
-
- case M_MH:
-- if ((tmp->new = mh_buffy (tmp->path)) > 0)
-- BuffyCount++;
-+ {
-+ DIR *dp;
-+ struct dirent *de;
-+ if ((tmp->new = mh_buffy (tmp->path)) > 0)
-+ BuffyCount++;
-+
-+ if ((dp = opendir (path)) == NULL)
-+ break;
-+ tmp->msgcount = 0;
-+ while ((de = readdir (dp)))