# HG changeset patch # Parent 356b22030d868e34fbc552a358398d068d776a4a fix bug 2421: show number of new mails in Maildir mailboxes
Show number of new mails in Maildir mailboxes. Reuse the st_size value for this purpose. This fixes bug 2421. v2: - fix stale values in local new variable Signed-off-by: Olaf Hering <o...@aepfle.de> diff -r 356b22030d86 browser.c --- a/browser.c Mon May 23 13:22:34 2011 +0200 +++ b/browser.c Mon May 30 10:24:00 2011 +0200 @@ -372,6 +372,25 @@ static void init_state (struct browser_s menu->data = state->entry; } +static unsigned int walk_maildir_new(const char *path) +{ + struct dirent *de; + DIR *d = opendir(path); + unsigned int count = 0; + + if (!d) + return count; + + while ((de = readdir(d))) { + if (de->d_name[0] == '.' && (!de->d_name[1] || (de->d_name[1] == '.' && !de->d_name[2]))) + continue; + count++; + } + closedir(d); + + return count; +} + static int examine_directory (MUTTMENU *menu, struct browser_state *state, char *d, const char *prefix) { @@ -380,6 +399,7 @@ static int examine_directory (MUTTMENU * struct dirent *de; char buffer[_POSIX_PATH_MAX + SHORT_STRING]; BUFFY *tmp; + unsigned int new; while (stat (d, &s) == -1) { @@ -425,6 +445,17 @@ static int examine_directory (MUTTMENU * continue; mutt_concat_path (buffer, d, de->d_name, sizeof (buffer)); + if (mx_is_maildir (buffer)) + { + size_t remaining = sizeof(buffer) - strlen(buffer); + if (snprintf (buffer + strlen(buffer), remaining, "/new") >= remaining) + continue; + if (lstat (buffer, &s) < 0) + continue; + s.st_size = new = walk_maildir_new(buffer); + } + else + { if (lstat (buffer, &s) == -1) continue; @@ -437,7 +468,9 @@ static int examine_directory (MUTTMENU * tmp = Incoming; while (tmp && mutt_strcmp (buffer, tmp->path)) tmp = tmp->next; - add_folder (menu, state, de->d_name, &s, (tmp) ? tmp->new : 0); + new = tmp ? tmp->new : 0; + } + add_folder (menu, state, de->d_name, &s, new); } closedir (dp); browser_sort (state);