-int mutt_buffy_check (int force)
-{
- BUFFY *tmp;
- struct stat sb;
- struct dirent *de;
- DIR *dirp;
- char path[_POSIX_PATH_MAX];
- struct stat contex_sb;
- time_t t;
- CONTEXT *ctx;
-#ifdef USE_IMAP
- /* update postponed count as well, on force */
- if (force)
- mutt_update_num_postponed ();
-#endif
-
- /* fastest return if there are no mailboxes */
- if (!Incoming)
- return 0;
- t = time (NULL);
- if (!force && (t - BuffyTime < BuffyTimeout))
- return BuffyCount;
-
- BuffyTime = t;
- BuffyCount = 0;
- BuffyNotify = 0;
-
-#ifdef USE_IMAP
- if (!Context || Context->magic != M_IMAP)
-#endif
-#ifdef USE_POP
- if (!Context || Context->magic != M_POP)
-#endif
-#ifdef USE_NNTP
- if (!Context || Context->magic != M_NNTP)
-#endif
- /* check device ID and serial number instead of comparing paths */
- if (!Context || !Context->path || stat (Context->path, &contex_sb) != 0)
- {
- contex_sb.st_dev=0;
- contex_sb.st_ino=0;
- }
-
- for (tmp = Incoming; tmp; tmp = tmp->next)
- {
- if ( tmp->new == 1 )
- tmp->has_new = 1;
- tmp->new = 0;
-
-#ifdef USE_IMAP
- if (mx_is_imap (tmp->path))
- tmp->magic = M_IMAP;
- else
-#endif
-#ifdef USE_POP
- if (mx_is_pop (tmp->path))
- tmp->magic = M_POP;
- else
-#endif
-#ifdef USE_NNTP
- if ((tmp->magic == M_NNTP) || mx_is_nntp (tmp->path))
- tmp->magic = M_NNTP;
- else
-#endif
- if (stat (tmp->path, &sb) != 0 || sb.st_size == 0 ||
- (!tmp->magic && (tmp->magic = mx_get_magic (tmp->path)) <= 0))
- {
- /* if the mailbox still doesn't exist, set the newly created flag to
- * be ready for when it does. */
- tmp->newly_created = 1;
- tmp->magic = 0;
-#ifdef BUFFY_SIZE
- tmp->size = 0;
-#endif
- continue;
- }
-
- /* 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:
-
- {
- if (STAT_CHECK || tmp->msgcount == 0)
- {
- BUFFY b = *tmp;
- int msgcount = 0;
- int msg_unread = 0;
- BuffyCount++;
- /* parse the mailbox, to see how much mail there is */
- ctx = mx_open_mailbox( tmp->path, M_READONLY | M_QUIET | M_NOSORT,
- NULL);
- if(ctx)
- {
- msgcount = ctx->msgcount;
- msg_unread = ctx->unread;
- mx_close_mailbox(ctx, 0);
- }
- *tmp = b;
- tmp->msgcount = msgcount;
- tmp->msg_unread = msg_unread;
- if(STAT_CHECK)
- tmp->has_new = tmp->new = 1;
- }
-#ifdef BUFFY_SIZE
- else
- {
- /* some other program has deleted mail from the folder */
- tmp->size = (long) sb.st_size;
- }
-#endif
- if (tmp->newly_created &&
- (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
- tmp->newly_created = 0;
- }
- break;
-
- case M_MAILDIR:
-
- snprintf (path, sizeof (path), "%s/new", tmp->path);
- if ((dirp = opendir (path)) == NULL)
- {
- tmp->magic = 0;
- break;
- }
- tmp->msgcount = 0;
- tmp->msg_unread = 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 != 1)
- {
- BuffyCount++;
- tmp->has_new = tmp->new = 1;
- }
- tmp->msgcount++;
- tmp->msg_unread++;
- }
- }
- closedir (dirp);
-#if 1
- /* I commented this out because it led to an infite "New mail in ..." loop,
- * and when looking at the code, the check seems to be overly eager.
- * -- ak
- */
- 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')))
- {
- /* one new and undeleted message is enough */
-#if 0
- BuffyCount++;
- /* we're checking for read and not new mail;
- * seems like copy'n'paste error
- */
- tmp->has_new = tmp->new = 1;
-#endif
- tmp->msgcount++;
- }
- }
- closedir (dirp);
-#endif
- break;
-
- case M_MH:
- {
- 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)))
- {
- if (mh_valid_message (de->d_name))
- {
- tmp->msgcount++;
- tmp->has_new = tmp->new = 1;