-+ *tmp = b;
-+ tmp->msgcount = msgcount;
-+ tmp->msg_unread = msg_unread;
-+ if(STAT_CHECK) {
-+ tmp->has_new = tmp->new = 1;
-+ BuffyCount++;
-+ }
- }
- else if (option(OPTCHECKMBOXSIZE))
- {
- /* some other program has deleted mail from the folder */
- tmp->size = (long) sb.st_size;
- }
-- if (tmp->newly_created &&
-- (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
-- tmp->newly_created = 0;
--
-- break;
-+ 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;
- if (*de->d_name != '.' &&
- (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')))
- {
-- /* one new and undeleted message is enough */
-- BuffyCount++;
-- tmp->new = 1;
-- 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++;
-+ }
- }
- }
- closedir (dirp);
- 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)))