--- a/buffy.c +++ b/buffy.c @@ -394,22 +394,15 @@ static int buffy_maildir_hasnew (BUFFY* mailbox) } /* update message counts for the sidebar */ -void buffy_maildir_update (BUFFY* mailbox) +static void buffy_maildir_update_dir (BUFFY* mailbox, const char *dir) { char path[_POSIX_PATH_MAX]; DIR *dirp; struct dirent *de; char *p; + int read; - if(!option(OPTSIDEBAR)) - return; - - mailbox->msgcount = 0; - mailbox->msg_unread = 0; - mailbox->msg_flagged = 0; - - snprintf (path, sizeof (path), "%s/new", mailbox->path); - + snprintf (path, sizeof (path), "%s/%s", mailbox->path, dir); if ((dirp = opendir (path)) == NULL) { mailbox->magic = 0; @@ -421,42 +414,37 @@ void buffy_maildir_update (BUFFY* mailbox) if (*de->d_name == '.') continue; - if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) { - mailbox->new = 1; - mailbox->msgcount++; - mailbox->msg_unread++; + /* Matches maildir_parse_flags logic */ + read = 0; + mailbox->msgcount++; + if ((p = strstr (de->d_name, ":2,"))) { + p += 3; + if (strchr (p, 'S')) + read = 1; + if (strchr (p, 'F')) + mailbox->msg_flagged++; } + if (!read) + mailbox->msg_unread++; } closedir (dirp); - snprintf (path, sizeof (path), "%s/cur", mailbox->path); - - if ((dirp = opendir (path)) == NULL) - { - mailbox->magic = 0; - return; - } - - while ((de = readdir (dirp)) != NULL) - { - if (*de->d_name == '.') - continue; +} +void buffy_maildir_update (BUFFY* mailbox) +{ + if (!option(OPTSIDEBAR)) + return; - if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) { - mailbox->msgcount++; - if ((p = strstr (de->d_name, ":2,"))) { - if (!strchr (p + 3, 'T')) { - if (!strchr (p + 3, 'S')) - mailbox->msg_unread++; - if (strchr(p + 3, 'F')) - mailbox->msg_flagged++; - } - } - } - } + mailbox->msgcount = 0; + mailbox->msg_unread = 0; + mailbox->msg_flagged = 0; + + buffy_maildir_update_dir (mailbox, "new"); + if (mailbox->msgcount) + mailbox->new = 1; + buffy_maildir_update_dir (mailbox, "cur"); mailbox->sb_last_checked = time(NULL); - closedir (dirp); } /* returns 1 if mailbox has new mail */