-
- 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);
- break;
+ /* 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++;
+ tmp->new = 1;
+ if (!count)
+ /* if sidebar invisible -> done */
+ 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;