+
+ /* check to see if the folder is the currently selected folder
+ * before polling */
+ if (!Context || !Context->path || (local ? (sb.st_dev != contex_sb.st_dev ||
+ sb.st_ino != contex_sb.st_ino) :
+ m_strcmp(tmp->path, Context->path))) {
+ switch (tmp->magic) {
+ case M_MBOX:
+ case M_MMDF:
+ /* only check on force or $mail_check reached */
+ if (force == 1 || (now - last1 >= BuffyTimeout)) {
+ if (!count) {
+ if (STAT_CHECK) {
+ BuffyCount++;
+ tmp->new = 1;
+ }
+ }
+ else if (STAT_CHECK || tmp->msgcount == 0) {
+ /* sidebar visible */
+ BuffyCount++;
+ if ((ctx =
+ mx_open_mailbox (tmp->path, M_READONLY | M_QUIET | M_NOSORT | M_COUNT,
+ NULL)) != NULL) {
+ tmp->msgcount = ctx->msgcount;
+ tmp->new = ctx->new;
+ tmp->msg_unread = ctx->new; /* for sidebar, wtf? */
+ tmp->msg_flagged = ctx->flagged;
+ mx_close_mailbox (ctx, 0);
+ }
+ }
+ if (tmp->newly_created &&
+ (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
+ tmp->newly_created = 0;
+ }
+ else if (tmp->new > 0)
+ BuffyCount++;
+ break;
+
+ case M_MAILDIR:
+ /* only check on force or $mail_check reached */
+ if (force == 1 || (now - last1 >= BuffyTimeout)) {
+ snprintf (path, sizeof (path), "%s/new", tmp->path);
+ if ((dirp = opendir (path)) == NULL) {
+ tmp->magic = 0;
+ break;
+ }
+ tmp->new = 0;
+ tmp->msg_unread = 0;
+ tmp->msgcount = 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 */
+ if (tmp->new == 0) {
+ BuffyCount++;
+ if (!count) {
+ /* if sidebar invisible -> done */
+ tmp->new = 1;
+ break;
+ }
+ }
+ tmp->msgcount++;
+ tmp->msg_unread++;
+ tmp->new++;
+ }
+ }
+ closedir (dirp);
+
+ if (count) {
+ /* only count total mail if sidebar visible */
+ snprintf (path, sizeof (path), "%s/cur", tmp->path);
+ if ((dirp = opendir (path)) == NULL) {
+ tmp->magic = 0;
+ break;
+ }
+ tmp->msg_flagged = 0;
+ while ((de = readdir (dirp)) != NULL) {
+ char *p;
+
+ if (*de->d_name != '.'
+ && (p = strstr (de->d_name, ":2,")) != NULL) {
+ if (!strchr (p + 3, 'T'))
+ tmp->msgcount++;
+ if (strchr (p + 3, 'F'))
+ tmp->msg_flagged++;
+ }
+ }
+ closedir (dirp);
+ }
+ }
+ else if (tmp->new > 0)
+ /* keep current stats if !force and !$mail_check reached */
+ BuffyCount++;
+ break;
+
+ case M_MH:
+ /* only check on force or $mail_check reached */
+ if (force == 1 || (now - last1 >= BuffyTimeout)) {
+ if ((tmp->new = mh_buffy (tmp->path)) > 0)
+ BuffyCount++;
+ if (count) {
+ DIR *dp;
+
+ if ((dp = opendir (path)) == NULL)
+ break;
+ tmp->new = 0;
+ tmp->msgcount = 0;
+ tmp->msg_unread = 0;
+ while ((de = readdir (dp))) {
+ if (mh_valid_message (de->d_name)) {
+ tmp->msgcount++;
+ tmp->msg_unread++;
+ tmp->new++;
+ }
+ }
+ closedir (dp);
+ }
+ }
+ else if (tmp->new > 0)
+ /* keep current stats if !force and !$mail_check reached */
+ BuffyCount++;
+ break;
+
+ case M_IMAP:
+ /* only check on force or $imap_mail_check reached */
+ if (force == 1 || (now - last2 >= ImapBuffyTimeout)) {
+ tmp->msgcount = imap_mailbox_check (tmp->path, 0);
+ tmp->new = imap_mailbox_check (tmp->path, 1);
+ tmp->msg_unread = imap_mailbox_check (tmp->path, 2);
+ if (tmp->new > 0)
+ BuffyCount++;
+ else
+ tmp->new = 0;
+ if (tmp->msg_unread < 0)
+ tmp->msg_unread = 0;
+ }
+ else if (tmp->new > 0)
+ /* keep current stats if !force and !$imap_mail_check reached */
+ BuffyCount++;
+ break;
+