Add new boolean option $mail_check_stats (default off) and
$mail_check_stats_interval.  The first turns extended buffy on.  The
second sets the amount of time in between extended buffy checks
(defaulting to 60 seconds).

Remove the option $sidebar_refresh_time.

Change mutt_buffy_check() to only notify the sidebar to redraw if a
mailbox buffy value changes.

Remove the #ifdefs around the extended buffy functions.  The next
patch will merge these functions with the basic functions and pass a
parameter instead.

Imap is a special case, because it sends out the status in one batch.
Change this to perform the comparisons inside cmd_parse_status() and
flag the sidebar there.  It was previously directly assigning the
status counters (unsigned int) to the buffy->new (short).  Change this
to assign 1/0.

(Part 4 of this series, which I'm still working on, will combine the
extended and basic buffy functions).

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
# HG changeset patch
# User Kevin McCarthy <[email protected]>
# Date 1465336978 25200
#      Tue Jun 07 15:02:58 2016 -0700
# Node ID 16f789353b94efd2a5725ba1045528b414cef1cf
# Parent  a96c517365599cb9796463a0c5e8d24bd8507fdb
Make extended buffy independent of the sidebar.

Add new boolean option $mail_check_stats (default off) and
$mail_check_stats_interval.  The first turns extended buffy on.  The
second sets the amount of time in between extended buffy checks
(defaulting to 60 seconds).

Remove the option $sidebar_refresh_time.

Change mutt_buffy_check() to only notify the sidebar to redraw if a
mailbox buffy value changes.

Remove the #ifdefs around the extended buffy functions.  The next
patch will merge these functions with the basic functions and pass a
parameter instead.

Imap is a special case, because it sends out the status in one batch.
Change this to perform the comparisons inside cmd_parse_status() and
flag the sidebar there.  It was previously directly assigning the
status counters (unsigned int) to the buffy->new (short).  Change this
to assign 1/0.

diff --git a/buffy.c b/buffy.c
--- a/buffy.c
+++ b/buffy.c
@@ -40,16 +40,17 @@
 #include <dirent.h>
 #include <utime.h>
 #include <ctype.h>
 #include <unistd.h>
 
 #include <stdio.h>
 
 static time_t BuffyTime = 0;   /* last time we started checking for mail */
+static time_t BuffyStatsTime = 0; /* last time we check performed 
mail_check_stats */
 time_t BuffyDoneTime = 0;      /* last time we knew for sure how much mail 
there was. */
 static short BuffyCount = 0;   /* how many boxes with new mail */
 static short BuffyNotify = 0;  /* # of unnotified new boxes */
 
 static BUFFY* buffy_get (const char *path);
 
 /* Find the last message in the file. 
  * upon success return 0. If no message found - return -1 */
@@ -383,17 +384,16 @@
 
   if (buffy_maildir_dir_hasnew(mailbox, "cur")) {
       return 1;
   }
 
   return 0;
 }
 
-#ifdef USE_SIDEBAR
 /**
  * buffy_maildir_update_dir - Update counts for one directory
  * @mailbox: BUFFY representing a maildir mailbox
  * @dir:     Which directory to search
  *
  * Look through one directory of a maildir mailbox.  The directory could
  * be either "new" or "cur".
  *
@@ -446,34 +446,27 @@
  * @mailbox: BUFFY representing a maildir mailbox
  *
  * Open a mailbox directories and update our record of how many new, or
  * flagged, messages there are.
  */
 void
 buffy_maildir_update (BUFFY *mailbox)
 {
-       if (!option (OPTSIDEBAR))
-               return;
-
        mailbox->msg_count   = 0;
        mailbox->msg_unread  = 0;
        mailbox->msg_flagged = 0;
 
        buffy_maildir_update_dir (mailbox, "new");
        if (mailbox->msg_count) {
                mailbox->new = 1;
        }
        buffy_maildir_update_dir (mailbox, "cur");
-
-       mailbox->sb_last_checked = time (NULL);
 }
 
-#endif
-
 /* returns 1 if mailbox has new mail */ 
 static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
 {
   int rc = 0;
   int statcheck;
 
   if (option (OPTCHECKMBOXSIZE))
     statcheck = sb->st_size > mailbox->size;
@@ -495,54 +488,55 @@
   }
   if (mailbox->newly_created &&
       (sb->st_ctime != sb->st_mtime || sb->st_ctime != sb->st_atime))
     mailbox->newly_created = 0;
 
   return rc;
 }
 
-#ifdef USE_SIDEBAR
 /**
  * buffy_mbox_update - Update messages counts for an mbox mailbox
  * @mailbox: BUFFY representing an mbox mailbox
  * @sb:      stat(2) infomation about the mailbox file
  *
  * Open a mbox file and update our record of how many new, or flagged,
  * messages there are. If the mailbox hasn't changed since the last call,
  * the function does nothing.
  */
 void
 buffy_mbox_update (BUFFY *mailbox, struct stat *sb)
 {
   CONTEXT *ctx = NULL;
 
-  if (!option (OPTSIDEBAR))
-    return;
-  if ((mailbox->sb_last_checked > sb->st_mtime) && (mailbox->msg_count != 0))
+  if ((mailbox->stats_last_checked > sb->st_mtime) && (mailbox->msg_count != 
0))
     return; /* no check necessary */
 
   ctx = mx_open_mailbox (mailbox->path, MUTT_READONLY | MUTT_QUIET | 
MUTT_NOSORT | MUTT_PEEK, NULL);
   if (ctx)
   {
     mailbox->msg_count       = ctx->msgcount;
     mailbox->msg_unread      = ctx->unread;
     mailbox->msg_flagged     = ctx->flagged;
-    mailbox->sb_last_checked = time (NULL);
+    mailbox->stats_last_checked = time (NULL);
     mx_close_mailbox (ctx, 0);
   }
 }
-#endif
 
 int mutt_buffy_check (int force)
 {
   BUFFY *tmp;
   struct stat sb;
   struct stat contex_sb;
   time_t t;
+  int check_stats = 0;
+#ifdef USE_SIDEBAR
+  short orig_new;
+  int orig_count, orig_unread, orig_flagged;
+#endif
 
   sb.st_size=0;
   contex_sb.st_dev=0;
   contex_sb.st_ino=0;
 
 #ifdef USE_IMAP
   /* update postponed count as well, on force */
   if (force)
@@ -550,36 +544,40 @@
 #endif
 
   /* fastest return if there are no mailboxes */
   if (!Incoming)
     return 0;
   t = time (NULL);
   if (!force && (t - BuffyTime < BuffyTimeout))
     return BuffyCount;
- 
+
+  if (option (OPTMAILCHECKSTATS) &&
+      (t - BuffyStatsTime >= BuffyCheckStatsInterval))
+  {
+    check_stats = 1;
+    BuffyStatsTime = t;
+  }
+
   BuffyTime = t;
   BuffyCount = 0;
   BuffyNotify = 0;
 
 #ifdef USE_IMAP
-  BuffyCount += imap_buffy_check (force);
+  BuffyCount += imap_buffy_check (force, check_stats);
 #endif
 
   /* check device ID and serial number instead of comparing paths */
   if (!Context || Context->magic == MUTT_IMAP || Context->magic == MUTT_POP
       || stat (Context->path, &contex_sb) != 0)
   {
     contex_sb.st_dev=0;
     contex_sb.st_ino=0;
   }
   
-#ifdef USE_SIDEBAR
-  int should_refresh = mutt_sb_should_refresh();
-#endif
   for (tmp = Incoming; tmp; tmp = tmp->next)
   {
     if (tmp->magic != MUTT_IMAP)
     {
       tmp->new = 0;
 #ifdef USE_POP
       if (mx_is_pop (tmp->path))
        tmp->magic = MUTT_POP;
@@ -592,70 +590,72 @@
         * be ready for when it does. */
        tmp->newly_created = 1;
        tmp->magic = 0;
        tmp->size = 0;
        continue;
       }
     }
 
+#ifdef USE_SIDEBAR
+    orig_new = tmp->new;
+    orig_count = tmp->msg_count;
+    orig_unread = tmp->msg_unread;
+    orig_flagged = tmp->msg_flagged;
+#endif
+
     /* check to see if the folder is the currently selected folder
      * before polling */
     if (!Context || !Context->path ||
        (( tmp->magic == MUTT_IMAP || tmp->magic == MUTT_POP )
            ? mutt_strcmp (tmp->path, Context->path) :
              (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino)))
     {
       switch (tmp->magic)
       {
       case MUTT_MBOX:
       case MUTT_MMDF:
-#ifdef USE_SIDEBAR
-       if (should_refresh)
+       if (check_stats)
          buffy_mbox_update (tmp, &sb);
-#endif
        if (buffy_mbox_hasnew (tmp, &sb) > 0)
          BuffyCount++;
        break;
 
       case MUTT_MAILDIR:
-#ifdef USE_SIDEBAR
-       if (should_refresh)
+       if (check_stats)
          buffy_maildir_update (tmp);
-#endif
        if (buffy_maildir_hasnew (tmp) > 0)
          BuffyCount++;
        break;
 
       case MUTT_MH:
-#ifdef USE_SIDEBAR
-       if (should_refresh)
+       if (check_stats)
          mh_buffy_update (tmp);
-#endif
        mh_buffy(tmp);
        if (tmp->new)
          BuffyCount++;
        break;
       }
     }
     else if (option(OPTCHECKMBOXSIZE) && Context && Context->path)
       tmp->size = (off_t) sb.st_size;  /* update the size of current folder */
 
+#ifdef USE_SIDEBAR
+    if ((orig_new != tmp->new) ||
+        (orig_count != tmp->msg_count) ||
+        (orig_unread != tmp->msg_unread) ||
+        (orig_flagged != tmp->msg_flagged))
+      SidebarNeedsRedraw = 1;
+#endif
+
     if (!tmp->new)
       tmp->notified = 0;
     else if (!tmp->notified)
       BuffyNotify++;
   }
-#ifdef USE_SIDEBAR
-  if (should_refresh)
-  {
-    SidebarNeedsRedraw = 1;
-    mutt_sb_set_update_time();
-  }
-#endif
 
   BuffyDoneTime = BuffyTime;
   return (BuffyCount);
 }
 
 int mutt_buffy_list (void)
 {
   BUFFY *tmp;
diff --git a/buffy.h b/buffy.h
--- a/buffy.h
+++ b/buffy.h
@@ -30,34 +30,36 @@
   char realpath[_POSIX_PATH_MAX];
 #endif
   off_t size;
   struct buffy_t *next;
 #ifdef USE_SIDEBAR
   struct buffy_t *prev;
 #endif
   short new;                   /* mailbox has new mail */
-#ifdef USE_SIDEBAR
+
+  /* These next three are only set when OPTMAILCHECKSTATS is set */
   int msg_count;               /* total number of messages */
   int msg_unread;              /* number of unread messages */
   int msg_flagged;             /* number of flagged messages */
+
+#ifdef USE_SIDEBAR
   short is_hidden;             /* is hidden from the sidebar */
 #endif
   short notified;              /* user has been notified */
   short magic;                 /* mailbox type */
   short newly_created;         /* mbox or mmdf just popped into existence */
   time_t last_visited;         /* time of last exit from this mailbox */
-#ifdef USE_SIDEBAR
-  time_t sb_last_checked;      /* time of last buffy check from sidebar */
-#endif
+  time_t stats_last_checked;   /* time of last mail_check_stats calculation */
 }
 BUFFY;
 
 WHERE BUFFY *Incoming INITVAL (0);
 WHERE short BuffyTimeout INITVAL (3);
+WHERE short BuffyCheckStatsInterval INITVAL (60);
 
 extern time_t BuffyDoneTime;   /* last time we knew for sure how much mail 
there was */
 
 BUFFY *mutt_find_mailbox (const char *path);
 void mutt_update_mailbox (BUFFY * b);
 
 /* fixes up atime + mtime after mbox/mmdf mailbox was modified
    according to stat() info taken before a modification */
diff --git a/contrib/sample.muttrc-sidebar b/contrib/sample.muttrc-sidebar
--- a/contrib/sample.muttrc-sidebar
+++ b/contrib/sample.muttrc-sidebar
@@ -38,16 +38,20 @@
 # around when it reaches the end of the list?
 set sidebar_next_new_wrap = no
 
 # The character to use as the divider between the Sidebar and the other Mutt
 # panels.
 # Note: Only the first character of this string is used.
 set sidebar_divider_char = '|'
 
+# Enable extended buffy mode to calculate total, new, and flagged
+# message counts for each mailbox.
+set mail_check_stats
+
 # Display the Sidebar mailboxes using this format string.
 set sidebar_format = '%B%?F? [%F]?%* %?N?%N/?%S'
 
 # Sidebar will not refresh its list of mailboxes any more frequently than
 # this number of seconds.  This will help reduce disk/network traffic.
 set sidebar_refresh_time = 60
 
 # Sort the mailboxes in the Sidebar using this method:
diff --git a/globals.h b/globals.h
--- a/globals.h
+++ b/globals.h
@@ -217,17 +217,16 @@
 WHERE short WriteInc;
 
 WHERE short ScoreThresholdDelete;
 WHERE short ScoreThresholdRead;
 WHERE short ScoreThresholdFlag;
 
 #ifdef USE_SIDEBAR
 WHERE short SidebarWidth;
-WHERE short SidebarRefreshTime;
 WHERE LIST *SidebarWhitelist INITVAL(0);
 WHERE int SidebarNeedsRedraw INITVAL (0);
 #endif
 
 #ifdef USE_IMAP
 WHERE short ImapKeepalive;
 WHERE short ImapPipelineDepth;
 #endif
diff --git a/imap/command.c b/imap/command.c
--- a/imap/command.c
+++ b/imap/command.c
@@ -895,16 +895,17 @@
   char* mailbox;
   char* value;
   BUFFY* inc;
   IMAP_MBOX mx;
   int count;
   IMAP_STATUS *status;
   unsigned int olduv, oldun;
   long litlen;
+  short new = 0;
 
   mailbox = imap_next_word (s);
 
   /* We need a real tokenizer. */
   if (!imap_get_literal_count (mailbox, &litlen))
   {
     if (imap_cmd_step (idata) != IMAP_CMD_CONTINUE)
     {
@@ -995,40 +996,42 @@
         dprint (3, (debugfile, "Found %s in buffy list (OV: %d ON: %d U: 
%d)\n",
                     mailbox, olduv, oldun, status->unseen));
         
        if (option(OPTMAILCHECKRECENT))
        {
          if (olduv && olduv == status->uidvalidity)
          {
            if (oldun < status->uidnext)
-             inc->new = status->unseen;
+             new = (status->unseen > 0);
          }
          else if (!olduv && !oldun)
            /* first check per session, use recent. might need a flag for this. 
*/
-           inc->new = status->recent;
+           new = (status->recent > 0);
          else
-           inc->new = status->unseen;
+           new = (status->unseen > 0);
        }
        else
-          inc->new = status->unseen;
+          new = (status->unseen > 0);
+
+#ifdef USE_SIDEBAR
+        if ((inc->new != new) ||
+            (inc->msg_count != status->messages) ||
+            (inc->msg_unread != status->unseen))
+          SidebarNeedsRedraw = 1;
+#endif
+        inc->new = new;
+        inc->msg_count  = status->messages;
+        inc->msg_unread = status->unseen;
 
        if (inc->new)
          /* force back to keep detecting new mail until the mailbox is
             opened */
          status->uidnext = oldun;
 
-#ifdef USE_SIDEBAR
-       /* Make the sidebar show the correct numbers */
-       if (status->messages) {
-         inc->msg_count  = status->messages;
-         inc->msg_unread = status->unseen;
-       }
-#endif
-
         FREE (&value);
         return;
       }
 
       FREE (&value);
     }
 
     FREE (&mx.mbox);
diff --git a/imap/imap.c b/imap/imap.c
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -1498,17 +1498,17 @@
   FREE (&mx.mbox);
 
   return 0;
 }
 
 /* check for new mail in any subscribed mailboxes. Given a list of mailboxes
  * rather than called once for each so that it can batch the commands and
  * save on round trips. Returns number of mailboxes with new mail. */
-int imap_buffy_check (int force)
+int imap_buffy_check (int force, int check_stats)
 {
   IMAP_DATA* idata;
   IMAP_DATA* lastdata = NULL;
   BUFFY* mailbox;
   char name[LONG_STRING];
   char command[LONG_STRING];
   char munged[LONG_STRING];
   int buffies = 0;
@@ -1520,18 +1520,16 @@
     {
       if (mx_is_imap (mailbox->path))
         mailbox->magic = MUTT_IMAP;
     }
 
     if (mailbox->magic != MUTT_IMAP)
       continue;
 
-    mailbox->new = 0;
-
     if (imap_get_mailbox (mailbox->path, &idata, name, sizeof (name)) < 0)
       continue;
 
     /* Don't issue STATUS on the selected mailbox, it will be NOOPed or
      * IDLEd elsewhere.
      * idata->mailbox may be NULL for connections other than the current
      * mailbox's, and shouldn't expand to INBOX in that case. #3216. */
     if (idata->mailbox && !imap_mxcmp (name, idata->mailbox))
@@ -1553,22 +1551,22 @@
 
       lastdata = NULL;
     }
 
     if (!lastdata)
       lastdata = idata;
 
     imap_munge_mbox_name (idata, munged, sizeof (munged), name);
-    snprintf (command, sizeof (command),
-#ifdef USE_SIDEBAR
+    if (check_stats)
+      snprintf (command, sizeof (command),
              "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
-#else
+    else
+      snprintf (command, sizeof (command),
              "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
-#endif
 
     if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0)
     {
       dprint (1, (debugfile, "Error queueing command\n"));
       return 0;
     }
   }
 
diff --git a/imap/imap.h b/imap/imap.h
--- a/imap/imap.h
+++ b/imap/imap.h
@@ -33,17 +33,17 @@
 
 /* imap.c */
 int imap_access (const char*, int);
 int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force);
 int imap_delete_mailbox (CONTEXT* idata, IMAP_MBOX mx);
 int imap_open_mailbox_append (CONTEXT *ctx);
 int imap_sync_mailbox (CONTEXT *ctx, int expunge, int *index_hint);
 int imap_close_mailbox (CONTEXT *ctx);
-int imap_buffy_check (int force);
+int imap_buffy_check (int force, int check_stats);
 int imap_status (char *path, int queue);
 int imap_search (CONTEXT* ctx, const pattern_t* pat);
 int imap_subscribe (char *path, int subscribe);
 int imap_complete (char* dest, size_t dlen, char* path);
 
 void imap_allow_reopen (CONTEXT *ctx);
 void imap_disallow_reopen (CONTEXT *ctx);
 
diff --git a/init.h b/init.h
--- a/init.h
+++ b/init.h
@@ -1404,16 +1404,32 @@
   ** When \fIset\fP, Mutt will only notify you about new mail that has been 
received
   ** since the last time you opened the mailbox.  When \fIunset\fP, Mutt will 
notify you
   ** if any new mail exists in the mailbox, regardless of whether you have 
visited it
   ** recently.
   ** .pp
   ** When \fI$$mark_old\fP is set, Mutt does not consider the mailbox to 
contain new
   ** mail if only old messages exist.
   */
+  { "mail_check_stats", DT_BOOL, R_NONE, OPTMAILCHECKSTATS, 0 },
+  /*
+  ** .pp
+  ** When \fIset\fP, mutt will periodically calculate message
+  ** statistics of a mailbox while polling for new mail.  It will
+  ** check for unread, flagged, and total message counts.  Because
+  ** this operation is more performance intensive, it defaults to
+  ** \fIunset\fP, and has a separate option, $$mail_check_stats_interval, to
+  ** control how often to update these counts.
+  */
+  { "mail_check_stats_interval", DT_NUM, R_NONE, UL &BuffyCheckStatsInterval, 
60 },
+  /*
+  ** .pp
+  ** When $$mail_check_stats is \fIset\fP, this variable configures
+  ** how often (in seconds) mutt will update message counts.
+  */
   { "mailcap_path",    DT_STR,  R_NONE, UL &MailcapPath, 0 },
   /*
   ** .pp
   ** This variable specifies which files to consult when attempting to
   ** display MIME bodies not directly supported by Mutt.
   */
   { "mailcap_sanitize",        DT_BOOL, R_NONE, OPTMAILCAPSANITIZE, 1 },
   /*
@@ -2722,17 +2738,19 @@
   ** .dt %>X .dd right justify the rest of the string and pad with ``X''
   ** .dt %|X .dd pad to the end of the line with ``X''
   ** .dt %*X .dd soft-fill with character ``X'' as pad
   ** .de
   ** .pp
   ** * = Can be optionally printed if nonzero
   ** @ = Only applicable to the current folder
   ** .pp
-  ** A useful value for this is "%B%?F? [%F]?%* %?N?%N/?%S".
+  ** In order to use %S, %N, %F, and %!, $$mail_check_stats must
+  ** be \fIset\fP.  When set, a useful value for this setting is
+  ** "%B%?F? [%F]?%* %?N?%N/?%S".
   */
   { "sidebar_indent_string", DT_STR, R_BOTH, UL &SidebarIndentString, UL "  " 
},
   /*
   ** .pp
   ** This specifies the string that is used to indent mailboxes in the sidebar.
   ** It defaults to two spaces.
   ** .pp
   ** \fBSee also:\fP $$sidebar_short_path, $$sidebar_folder_indent, 
$$sidebar_delim_chars.
@@ -2748,24 +2766,16 @@
   { "sidebar_next_new_wrap", DT_BOOL, R_BOTH, UL OPTSIDEBARNEXTNEWWRAP, 0 },
   /*
   ** .pp
   ** When set, the \fC<sidebar-next-new>\fP command will not stop and the end 
of
   ** the list of mailboxes, but wrap around to the beginning. The
   ** \fC<sidebar-prev-new>\fP command is similarly affected, wrapping around to
   ** the end of the list.
   */
-  { "sidebar_refresh_time", DT_NUM, R_BOTH, UL &SidebarRefreshTime, 60 },
-  /*
-  ** .pp
-  ** Set sidebar_refresh_time to the minimum number of seconds between 
refreshes.
-  ** This will reduced network traffic.
-  ** .pp
-  ** \fBNote:\fP Set to 0 to disable refreshing.
-  */
   { "sidebar_short_path", DT_BOOL, R_BOTH, OPTSIDEBARSHORTPATH, 0 },
   /*
   ** .pp
   ** By default the sidebar will show the mailbox's path, relative to the
   ** $$folder variable. Setting \fCsidebar_shortpath=yes\fP will shorten the
   ** names relative to the previous name. Here's an example:
   ** .dl
   ** .dt \fBshortpath=no\fP .dd \fBshortpath=yes\fP .dd \fBshortpath=yes, 
folderindent=yes, indentstr=".."\fP
diff --git a/mailbox.h b/mailbox.h
--- a/mailbox.h
+++ b/mailbox.h
@@ -20,21 +20,18 @@
 #define _MAILBOX_H
 
 /* flags for mutt_open_mailbox() */
 #define MUTT_NOSORT     (1<<0) /* do not sort the mailbox after opening it */
 #define MUTT_APPEND     (1<<1) /* open mailbox for appending messages */
 #define MUTT_READONLY   (1<<2) /* open in read-only mode */
 #define MUTT_QUIET      (1<<3) /* do not print any messages */
 #define MUTT_NEWFOLDER  (1<<4) /* create a new folder - same as MUTT_APPEND, 
but uses
-                                * safe_fopen() for mbox-style folders.
-                                */
-#ifdef USE_SIDEBAR
+                                * safe_fopen() for mbox-style folders. */
 #define MUTT_PEEK       (1<<5) /* revert atime back after taking a look (if 
applicable) */
-#endif
 
 /* mx_open_new_message() */
 #define MUTT_ADD_FROM   (1<<0)  /* add a From_ line */
 #define MUTT_SET_DRAFT  (1<<1)  /* set the message draft flag */
 
 /* return values from mx_check_mailbox() */
 enum
 {
diff --git a/mh.c b/mh.c
--- a/mh.c
+++ b/mh.c
@@ -293,36 +293,32 @@
       if (!option(OPTMAILCHECKRECENT) || mh_already_notified(b, i) == 0)
        b->new = 1;
       break;
     }
   }
   mhs_free_sequences (&mhs);
 }
 
-#ifdef USE_SIDEBAR
 /**
  * mh_buffy_update - Update messages counts for an mh mailbox
  * @mailbox: BUFFY representing a maildir mailbox
  *
  * Read through an mh mailbox and count messages.  Save the number of new,
  * flagged messages and a timestamp for now.
  */
 void
 mh_buffy_update (BUFFY *mailbox)
 {
   int i;
   struct mh_sequences mhs;
 
   if (!mailbox)
     return;
 
-  if (!option (OPTSIDEBAR))
-    return;
-
   memset (&mhs, 0, sizeof (mhs));
 
   if (mh_read_sequences (&mhs, mailbox->path) < 0)
     return;
 
   mailbox->msg_count   = 0;
   mailbox->msg_unread  = 0;
   mailbox->msg_flagged = 0;
@@ -331,19 +327,17 @@
   {
     mailbox->msg_count++;
     if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN)
       mailbox->msg_unread++;
     if (mhs_check (&mhs, i) & MH_SEQ_FLAGGED)
       mailbox->msg_flagged++;
   }
   mhs_free_sequences (&mhs);
-  mailbox->sb_last_checked = time (NULL);
 }
-#endif
 
 static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt)
 {
   int fd;
   char path[_POSIX_PATH_MAX];
   mode_t omask;
 
   omask = umask (mh_umask (dest));
diff --git a/mutt.h b/mutt.h
--- a/mutt.h
+++ b/mutt.h
@@ -383,16 +383,17 @@
   OPTSSLVERIFYDATES,
   OPTSSLVERIFYHOST,
 #endif /* defined(USE_SSL) */
   OPTIMPLICITAUTOVIEW,
   OPTINCLUDEONLYFIRST,
   OPTKEEPFLAGGED,
   OPTMAILCAPSANITIZE,
   OPTMAILCHECKRECENT,
+  OPTMAILCHECKSTATS,
   OPTMAILDIRTRASH,
   OPTMAILDIRCHECKCUR,
   OPTMARKERS,
   OPTMARKOLD,
   OPTMENUSCROLL,       /* scroll menu instead of implicit next-page */
   OPTMENUMOVEOFF,      /* allow menu to scroll past last entry */
 #if defined(USE_IMAP) || defined(USE_POP)
   OPTMESSAGECACHECLEAN,
@@ -895,19 +896,17 @@
   int (*check) (struct _context *ctx, int *index_hint);
   int (*open_new_msg) (struct _message *, struct _context *, HEADER *);
 };
 
 typedef struct _context
 {
   char *path;
   FILE *fp;
-#ifdef USE_SIDEBAR
   time_t atime;
-#endif
   time_t mtime;
   off_t size;
   off_t vsize;
   char *pattern;                /* limit pattern string */
   pattern_t *limit_pattern;     /* compiled limit pattern */
   HEADER **hdrs;
   HEADER *last_tag;            /* last tagged msg. used to link threads */
   THREAD *tree;                        /* top of thread tree */
@@ -932,19 +931,17 @@
   unsigned int locked : 1;     /* is the mailbox locked? */
   unsigned int changed : 1;    /* mailbox has been modified */
   unsigned int readonly : 1;    /* don't allow changes to the mailbox */
   unsigned int dontwrite : 1;   /* don't write the mailbox on close */
   unsigned int append : 1;     /* mailbox is opened in append mode */
   unsigned int quiet : 1;      /* inhibit status messages? */
   unsigned int collapsed : 1;   /* are all threads collapsed? */
   unsigned int closing : 1;    /* mailbox is being closed */
-#ifdef USE_SIDEBAR
   unsigned int peekonly : 1;   /* just taking a glance, revert atime */
-#endif
 
   /* driver hooks */
   void *data;                  /* driver specific data */
   struct mx_ops *mx_ops;
 } CONTEXT;
 
 typedef struct
 {
diff --git a/mx.c b/mx.c
--- a/mx.c
+++ b/mx.c
@@ -634,20 +634,18 @@
 
   for (rc=0; rc < RIGHTSMAX; rc++)
     mutt_bit_set(ctx->rights,rc);
 
   if (flags & MUTT_QUIET)
     ctx->quiet = 1;
   if (flags & MUTT_READONLY)
     ctx->readonly = 1;
-#ifdef USE_SIDEBAR
   if (flags & MUTT_PEEK)
     ctx->peekonly = 1;
-#endif
 
   if (flags & (MUTT_APPEND|MUTT_NEWFOLDER))
   {
     if (mx_open_mailbox_append (ctx, flags) != 0)
     {
       mx_fastclose_mailbox (ctx);
       if (!pctx)
        FREE (&ctx);
@@ -707,36 +705,32 @@
   unset_option (OPTFORCEREFRESH);
   return (ctx);
 }
 
 /* free up memory associated with the mailbox context */
 void mx_fastclose_mailbox (CONTEXT *ctx)
 {
   int i;
+  struct utimbuf ut;
 
   if(!ctx) 
     return;
 
-#ifdef USE_SIDEBAR
   /* fix up the times so buffy won't get confused */
-  struct utimbuf ut;
   if (ctx->peekonly && ctx->path && (ctx->mtime > ctx->atime)) {
     ut.actime  = ctx->atime;
     ut.modtime = ctx->mtime;
     utime (ctx->path, &ut);
   }
-#endif
 
   /* never announce that a mailbox we've just left has new mail. #3290
    * XXX: really belongs in mx_close_mailbox, but this is a nice hook point */
-#ifdef USE_SIDEBAR
   if (!ctx->peekonly)
-#endif
-  mutt_buffy_setnotified(ctx->path);
+    mutt_buffy_setnotified(ctx->path);
 
   if (ctx->mx_ops)
     ctx->mx_ops->close (ctx);
 
   if (ctx->subj_hash)
     hash_destroy (&ctx->subj_hash, NULL);
   if (ctx->id_hash)
     hash_destroy (&ctx->id_hash, NULL);
diff --git a/mx.h b/mx.h
--- a/mx.h
+++ b/mx.h
@@ -48,19 +48,17 @@
 int mbox_lock_mailbox (CONTEXT *, int, int);
 int mbox_parse_mailbox (CONTEXT *);
 int mmdf_parse_mailbox (CONTEXT *);
 void mbox_unlock_mailbox (CONTEXT *);
 int mbox_check_empty (const char *);
 void mbox_reset_atime (CONTEXT *, struct stat *);
 
 int mh_sync_mailbox (CONTEXT *, int *);
-#ifdef USE_SIDEBAR
 void mh_buffy_update (BUFFY *mailbox);
-#endif
 int mh_check_empty (const char *);
 
 int maildir_check_empty (const char *);
 
 int maildir_commit_message (CONTEXT *, MESSAGE *, HEADER *);
 int mh_commit_message (CONTEXT *, MESSAGE *, HEADER *);
 
 FILE *maildir_open_find_message (const char *, const char *);
diff --git a/sidebar.c b/sidebar.c
--- a/sidebar.c
+++ b/sidebar.c
@@ -25,17 +25,16 @@
 #include "buffy.h"
 #include "keymap.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
 #include "sort.h"
 
 /* Previous values for some sidebar config */
 static short  PreviousSort;    /* sidebar_sort_method */
-static time_t LastRefresh;     /* Time of last refresh */
 
 /* Keep track of various BUFFYs */
 static BUFFY *TopBuffy;                /* First mailbox visible in sidebar */
 static BUFFY *OpnBuffy;                /* Current (open) mailbox */
 static BUFFY *HilBuffy;                /* Highlighted mailbox */
 static BUFFY *BotBuffy;                /* Last mailbox visible in sidebar */
 static BUFFY *Outgoing;                /* Last mailbox in the linked list */
 
@@ -754,39 +753,16 @@
 
   if (!prepare_sidebar (num_rows))
     return;
 
   draw_sidebar (num_rows, num_cols, div_width);
 }
 
 /**
- * mutt_sb_should_refresh - Check if the sidebar is due to be refreshed
- *
- * The "sidebar_refresh_time" config option allows the user to limit the 
frequency
- * with which the sidebar is refreshed.
- *
- * Returns:
- *     1  Yes, refresh is due
- *     0  No,  refresh happened recently
- */
-int mutt_sb_should_refresh (void)
-{
-  if (!option (OPTSIDEBAR))
-    return 0;
-
-  if (SidebarRefreshTime == 0)
-    return 0;
-
-  time_t diff = (time (NULL) - LastRefresh);
-
-  return (diff >= SidebarRefreshTime);
-}
-
-/**
  * mutt_sb_change_mailbox - Change the selected mailbox
  * @op: Operation code
  *
  * Change the selected mailbox, e.g. "Next mailbox", "Previous Mailbox
  * with new mail". The operations are listed OPS.SIDEBAR which is built
  * into an enum in keymap_defs.h.
  *
  * If the operation is successful, HilBuffy will be set to the new mailbox.
@@ -926,29 +902,16 @@
       break;
     }
   }
 
   return OpnBuffy;
 }
 
 /**
- * mutt_sb_set_update_time - Note the time that the sidebar was updated
- *
- * Update the timestamp representing the last sidebar update.  If the user
- * configures "sidebar_refresh_time", this will help to reduce traffic.
- */
-void mutt_sb_set_update_time (void)
-{
-  /* XXX - should this be public? */
-
-  LastRefresh = time (NULL);
-}
-
-/**
  * mutt_sb_notify_mailbox - The state of a BUFFY is about to change
  *
  * We receive a notification:
  *     After a new BUFFY has been created
  *     Before a BUFFY is deleted
  *
  * Before a deletion, check that our pointers won't be invalidated.
  */
diff --git a/sidebar.h b/sidebar.h
--- a/sidebar.h
+++ b/sidebar.h
@@ -24,12 +24,10 @@
 #include "buffy.h"
 
 void         mutt_sb_change_mailbox (int op);
 void         mutt_sb_draw (void);
 const char * mutt_sb_get_highlight (void);
 void         mutt_sb_notify_mailbox (BUFFY *b, int created);
 void         mutt_sb_set_buffystats (const CONTEXT *ctx);
 BUFFY *      mutt_sb_set_open_buffy (const char *path);
-void         mutt_sb_set_update_time (void);
-int          mutt_sb_should_refresh (void);
 
 #endif /* SIDEBAR_H */

Attachment: signature.asc
Description: PGP signature

Reply via email to