- /* check to see if the folder is the currently selected folder
- * before polling */
- if (!Context || !Context->path || ((0
-#ifdef USE_IMAP
- || tmp->magic == M_IMAP
-#endif
-#ifdef USE_POP
- || tmp->magic == M_POP
-#endif
-#ifdef USE_NNTP
- || tmp->magic == M_NNTP
-#endif
- )? mutt_strcmp (tmp->path,
- Context->path) : (sb.
- st_dev
- !=
- contex_sb.
- st_dev
- ||
- sb.
- st_ino
- !=
- contex_sb.
- st_ino)
- )
- ) {
- switch (tmp->magic) {
- case M_MBOX:
- case M_MMDF:
- /* only check on force or $mail_check reached */
- if (force != 0 || (now - last1 >= BuffyTimeout)) {
- if (SidebarWidth == 0 || !option (OPTMBOXPANE)) {
- if (STAT_CHECK) {
- BuffyCount++;
- tmp->new = 1;
- }
-#ifdef BUFFY_SIZE
- else {
- /* some other program has deleted mail from the folder */
- tmp->size = (long) sb.st_size;
- }
-#endif
- }
- else if (SidebarWidth > 0 && option (OPTMBOXPANE) &&
- (STAT_CHECK || tmp->msgcount == 0)) {
- /* sidebar visible */
- BuffyCount++;
- if ((ctx =
- mx_open_mailbox (tmp->path, M_READONLY | M_QUIET | M_NOSORT,
- 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 != 0 || (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++;
- tmp->new = 1;
- if (SidebarWidth == 0 || !option (OPTMBOXPANE))
- /* if sidebar invisible -> done */
- break;
- }
- tmp->msgcount++;
- tmp->msg_unread++;
- tmp->new++;
- }
- }
- closedir (dirp);
-
- if (SidebarWidth > 0 && option (OPTMBOXPANE)) {
- /* 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 != 0 || (now - last1 >= BuffyTimeout)) {
- if ((tmp->new = mh_buffy (tmp->path)) > 0)
- BuffyCount++;
- if (SidebarWidth > 0 && option (OPTMBOXPANE)) {
- DIR *dp;
- struct dirent *de;
-
- 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;
-
-#ifdef USE_IMAP
- case M_IMAP:
- /* only check on force or $imap_mail_check reached */
- if (force != 0 || (now - last2 >= ImapBuffyTimeout)) {
- tmp->msgcount = imap_mailbox_check (tmp->path, 0);
- if ((tmp->new = imap_mailbox_check (tmp->path, 1)) > 0) {
- BuffyCount++;
- tmp->msg_unread = tmp->new; /* for sidebar; wtf? */
- }
- else {
- tmp->new = 0;
- tmp->msg_unread = 0;
- }