]> granicus.if.org Git - neomutt/commitdiff
Add check-stats function to calculate mailbox statistics.
authorAnton Lindqvist <anton@basename.se>
Fri, 29 Jun 2018 03:17:23 +0000 (20:17 -0700)
committerRichard Russon <rich@flatcap.org>
Fri, 29 Jun 2018 11:25:34 +0000 (12:25 +0100)
This allows the statistics to be updated without setting
$mail_check_stats or before $mail_check_stats_interval has passed.

14 files changed:
browser.c
buffy.c
buffy.h
commands.c
curs_main.c
doc/manual.xml.head
functions.h
init.h
main.c
menu.c
opcodes.h
pager.c
protos.h
status.c

index 0c07e55479dfcb8c43207ef0a972f75b84a913ea..0178df3a12f9c732312b1f9abd74f3c949ed8faf 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -774,7 +774,7 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
       return -1;
     }
 
-    mutt_buffy_check(false);
+    mutt_buffy_check(0);
 
     dp = opendir(d);
     if (!dp)
@@ -834,7 +834,7 @@ static int examine_vfolders(struct Menu *menu, struct BrowserState *state)
   if (!tmp)
     return -1;
 
-  mutt_buffy_check(false);
+  mutt_buffy_check(0);
 
   init_state(state, menu);
 
@@ -885,7 +885,7 @@ static int examine_mailboxes(struct Menu *menu, struct BrowserState *state)
 
     if (!Incoming)
       return -1;
-    mutt_buffy_check(false);
+    mutt_buffy_check(0);
 
     do
     {
@@ -1071,7 +1071,7 @@ static void init_menu(struct BrowserState *state, struct Menu *menu,
     if (buffy)
     {
       menu->is_mailbox_list = 1;
-      snprintf(title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check(false));
+      snprintf(title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check(0));
     }
     else
     {
diff --git a/buffy.c b/buffy.c
index 4d063c7a84c3aaded359858bc524a8f600d7a4a4..ab89026f7bd1cc89d84120f154d08435f7520092 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -750,12 +750,16 @@ int mutt_parse_unmailboxes(struct Buffer *path, struct Buffer *s,
 
 /**
  * mutt_buffy_check - Check all Incoming for new mail
- * @param force If true, ignore MailCheck and check for new mail anyway
+ * @param force Force flags, see below
  * @retval num Number of mailboxes with new mail
  *
+ * The force argument may be any combination of the following values:
+ * - MUTT_BUFFY_CHECK_FORCE        ignore BuffyTimeout and check for new mail
+ * - MUTT_BUFFY_CHECK_FORCE_STATS  ignore BuffyTimeout and calculate statistics
+ *
  * Check all Incoming for new mail and total/new/flagged messages
  */
-int mutt_buffy_check(bool force)
+int mutt_buffy_check(int force)
 {
   struct stat contex_sb;
   time_t t;
@@ -765,7 +769,7 @@ int mutt_buffy_check(bool force)
 
 #ifdef USE_IMAP
   /* update postponed count as well, on force */
-  if (force)
+  if (force & MUTT_BUFFY_CHECK_FORCE)
     mutt_update_num_postponed();
 #endif
 
@@ -777,7 +781,8 @@ int mutt_buffy_check(bool force)
   if (!force && (t - BuffyTime < MailCheck))
     return BuffyCount;
 
-  if (MailCheckStats && (t - BuffyStatsTime >= MailCheckStatsInterval))
+  if ((force & MUTT_BUFFY_CHECK_FORCE_STATS) ||
+      (MailCheckStats && ((t - BuffyStatsTime) >= MailCheckStatsInterval)))
   {
     check_stats = true;
     BuffyStatsTime = t;
@@ -889,7 +894,7 @@ void mutt_buffy_setnotified(const char *path)
  */
 bool mutt_buffy_notify(void)
 {
-  if (mutt_buffy_check(false) && BuffyNotify)
+  if (mutt_buffy_check(0) && BuffyNotify)
   {
     return mutt_buffy_list();
   }
@@ -907,7 +912,7 @@ void mutt_buffy(char *s, size_t slen)
 {
   mutt_expand_path(s, slen);
 
-  if (mutt_buffy_check(false))
+  if (mutt_buffy_check(0))
   {
     int found = 0;
     for (int pass = 0; pass < 2; pass++)
@@ -928,7 +933,7 @@ void mutt_buffy(char *s, size_t slen)
       }
     }
 
-    mutt_buffy_check(true); /* buffy was wrong - resync things */
+    mutt_buffy_check(MUTT_BUFFY_CHECK_FORCE); /* buffy was wrong - resync things */
   }
 
   /* no folders with new mail */
@@ -943,7 +948,7 @@ void mutt_buffy(char *s, size_t slen)
  */
 void mutt_buffy_vfolder(char *buf, size_t buflen)
 {
-  if (mutt_buffy_check(false))
+  if (mutt_buffy_check(0))
   {
     bool found = false;
     for (int pass = 0; pass < 2; pass++)
@@ -962,7 +967,7 @@ void mutt_buffy_vfolder(char *buf, size_t buflen)
       }
     }
 
-    mutt_buffy_check(true); /* buffy was wrong - resync things */
+    mutt_buffy_check(MUTT_BUFFY_CHECK_FORCE); /* buffy was wrong - resync things */
   }
 
   /* no folders with new mail */
diff --git a/buffy.h b/buffy.h
index abaff004cb5e190cc6ee2d058afd8c36a26d0884..8368989d1dfa5f0d256b7fecf5c732183a53912b 100644 (file)
--- a/buffy.h
+++ b/buffy.h
@@ -78,6 +78,10 @@ void mutt_buffy_setnotified(const char *path);
 
 bool mh_buffy(struct Buffy *mailbox, bool check_stats);
 
+/* force flags passed to mutt_buffy_check() */
+#define MUTT_BUFFY_CHECK_FORCE       (1 << 0)
+#define MUTT_BUFFY_CHECK_FORCE_STATS (1 << 1)
+
 /* These variables are backing for config items */
 WHERE short MailCheck;
 WHERE short MailCheckStatsInterval;
index 43ba13e038348dd8a0cadd773bea67a51d0ad3ac..23c55e987f9043a203afcb43908afdbb36789b9d 100644 (file)
@@ -648,7 +648,7 @@ void mutt_shell_escape(void)
 
   if ((rc != 0) || WaitKey)
     mutt_any_key_to_continue(NULL);
-  mutt_buffy_check(true);
+  mutt_buffy_check(MUTT_BUFFY_CHECK_FORCE);
 }
 
 /**
@@ -1127,3 +1127,8 @@ int mutt_check_traditional_pgp(struct Header *h, int *redraw)
   }
   return rc;
 }
+
+void mutt_check_stats(void)
+{
+  mutt_buffy_check(MUTT_BUFFY_CHECK_FORCE | MUTT_BUFFY_CHECK_FORCE_STATS);
+}
index caddb7592d8922830b44a5985481b5e64e47a621..1a2ccbb12610cac1ac6a3d00e6e269d3bcbc4299 100644 (file)
@@ -502,7 +502,7 @@ static int main_change_folder(struct Menu *menu, int op, char *buf,
 #endif
 
   mutt_clear_error();
-  mutt_buffy_check(true); /* force the buffy check after we have changed the folder */
+  mutt_buffy_check(MUTT_BUFFY_CHECK_FORCE); /* force the buffy check after we have changed the folder */
   menu->redraw = REDRAW_FULL;
   OptSearchInvalid = true;
 
@@ -852,7 +852,10 @@ int mutt_index_menu(void)
   mutt_menu_push_current(menu);
 
   if (!attach_msg)
-    mutt_buffy_check(true); /* force the buffy check after we enter the folder */
+  {
+    /* force the buffy check after we enter the folder */
+    mutt_buffy_check(MUTT_BUFFY_CHECK_FORCE);
+  }
 
   if (((Sort & SORT_MASK) == SORT_THREADS) && CollapseAll)
   {
@@ -963,7 +966,7 @@ int mutt_index_menu(void)
     {
       /* check for new mail in the incoming folders */
       oldcount = newcount;
-      newcount = mutt_buffy_check(false);
+      newcount = mutt_buffy_check(0);
       if (newcount != oldcount)
         menu->redraw |= REDRAW_STATUS;
       if (do_buffy_notify)
@@ -1961,6 +1964,10 @@ int mutt_index_menu(void)
       case OP_MAIN_CHANGE_VFOLDER:
 #endif
 
+      case OP_CHECK_STATS:
+        mutt_check_stats();
+        break;
+
 #ifdef USE_SIDEBAR
       case OP_SIDEBAR_OPEN:
 #endif
index 798f164164b6043461ec74ab14416af816978911..6a262bd895640e63ed3aa58832db5053b6406d40 100644 (file)
@@ -2161,6 +2161,20 @@ color sidebar_divider   color8  default     <emphasis role="comment"># Dark grey
           <emphasis>pager</emphasis> menus have these interesting functions:
         </para>
         <variablelist>
+          <varlistentry>
+            <term>
+              <literal>&lt;check-stats&gt;</literal>
+              <anchor id="check-stats" />
+            </term>
+            <listitem>
+              <para>
+                Calculate statistics for all monitored mailboxes declared using
+                the <command>mailboxes</command>command. It will calculate
+                statistics despite <link linkend="mail-check-stats">$mail_check_stats</link>
+                being unset.
+              </para>
+            </listitem>
+          </varlistentry>
           <varlistentry>
             <term>
               <literal>&lt;create-alias&gt;</literal> (default: a)
index d3ab8c29203190d41adf77d0c0934920db933fb6..37239b175f4b7048e848d897f4e9574998447ec4 100644 (file)
@@ -56,6 +56,7 @@ const struct Binding OpGeneric[] = { /* map: generic */
   ** </para>
   */
   { "bottom-page",     OP_BOTTOM_PAGE,          "L" },
+  { "check-stats",     OP_CHECK_STATS,          NULL },
   { "current-bottom",  OP_CURRENT_BOTTOM,       NULL },
   { "current-middle",  OP_CURRENT_MIDDLE,       NULL },
   { "current-top",     OP_CURRENT_TOP,          NULL },
@@ -253,6 +254,7 @@ const struct Binding OpPager[] = { /* map: pager */
 #ifdef USE_NOTMUCH
   { "change-vfolder",            OP_MAIN_CHANGE_VFOLDER,          NULL },
 #endif
+  { "check-stats",               OP_CHECK_STATS,                  NULL },
   { "check-traditional-pgp",     OP_CHECK_TRADITIONAL,            "\033P" },
   { "clear-flag",                OP_MAIN_CLEAR_FLAG,              "W" },
   { "compose-to-sender",         OP_COMPOSE_TO_SENDER,            NULL },
diff --git a/init.h b/init.h
index 69024df556c607707dc925e570628d0735950f33..e2623ea9d18e6928f4c99b1da00be8a90271c639 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1704,6 +1704,9 @@ struct Option MuttVars[] = {
   ** 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.
+  ** .pp
+  ** Message statistics can also be explicitly calculated by invoking the
+  ** \fC<check-stats>\fP function.
   */
   { "mail_check_stats_interval", DT_NUMBER, R_NONE, &MailCheckStatsInterval, 60 },
   /*
diff --git a/main.c b/main.c
index 4f59f266a81efaa9da80c5970d4b1385254d3c4b..f7cd9a4930d83b5addde2a84736863e1ed7fbcbb 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1001,7 +1001,7 @@ int main(int argc, char *argv[], char *envp[])
   {
     if (flags & MUTT_BUFFY)
     {
-      if (mutt_buffy_check(false) == 0)
+      if (mutt_buffy_check(0) == 0)
       {
         mutt_message(_("No mailbox with new mail."));
         goto main_curses; // TEST37: neomutt -Z (no new mail)
diff --git a/menu.c b/menu.c
index 1b179cb71ef0ee8e3422bbff9eca71f7193fe448..d46e23be2d7042d3d02d2054040e5f4e2bc3b859 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -1535,6 +1535,10 @@ int mutt_menu_loop(struct Menu *menu)
         mutt_what_key();
         break;
 
+      case OP_CHECK_STATS:
+        mutt_check_stats();
+        break;
+
       case OP_REDRAW:
         clearok(stdscr, true);
         menu->redraw = REDRAW_FULL;
index fa7a79415a331b5ac6f52c52ad738be81fce0c73..cf54cd8401c5c33f906db29c2eab18d50d046edc 100644 (file)
--- a/opcodes.h
+++ b/opcodes.h
@@ -44,6 +44,7 @@
   _fmt(OP_CATCHUP,                        N_("mark all articles in newsgroup as read")) \
   _fmt(OP_CHANGE_DIRECTORY,               N_("change directories")) \
   _fmt(OP_CHECK_NEW,                      N_("check mailboxes for new mail")) \
+  _fmt(OP_CHECK_STATS,                    N_("calculate message statistics for all mailboxes")) \
   _fmt(OP_COMPOSE_ATTACH_FILE,            N_("attach files to this message")) \
   _fmt(OP_COMPOSE_ATTACH_MESSAGE,         N_("attach messages to this message")) \
   _fmt(OP_COMPOSE_ATTACH_NEWS_MESSAGE,    N_("attach news articles to this message")) \
diff --git a/pager.c b/pager.c
index d751b2f5356f0e4a6a3d383ea6be5495957d7a90..dd8dc6a0a451ea0d2d3f18d0e65d8ca2a882a07b 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -3271,6 +3271,10 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e
         mutt_what_key();
         break;
 
+      case OP_CHECK_STATS:
+        mutt_check_stats();
+        break;
+
 #ifdef USE_SIDEBAR
       case OP_SIDEBAR_NEXT:
       case OP_SIDEBAR_NEXT_NEW:
index f8f202659320ff578360caa74db1a76d1e45eeae..b1ec7b16995ffbe3732e13ee83feddcf493e8426 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -146,6 +146,7 @@ void mutt_sig_allow_interrupt(int disposition);
 int mutt_bounce_message(FILE *fp, struct Header *h, struct Address *to);
 void mutt_buffy(char *s, size_t slen);
 bool mutt_buffy_list(void);
+void mutt_check_stats(void);
 int mutt_count_body_parts(struct Context *ctx, struct Header *hdr);
 void mutt_check_rescore(struct Context *ctx);
 void mutt_clear_error(void);
@@ -225,7 +226,7 @@ void mutt_alias_delete_reverse(struct Alias *t);
 int mutt_alloc_color(int fg, int bg);
 int mutt_combine_color(int fg_attr, int bg_attr);
 int mutt_any_key_to_continue(const char *s);
-int mutt_buffy_check(bool force);
+int mutt_buffy_check(int force);
 bool mutt_buffy_notify(void);
 int mutt_builtin_editor(const char *path, struct Header *msg, struct Header *cur);
 int mutt_change_flag(struct Header *h, int bf);
index d6db1fcac4842aa154f40f2f0525d3c16d91d713..bc55cd775d6395c2f69c1f8c34a72245d66af630 100644 (file)
--- a/status.c
+++ b/status.c
@@ -120,9 +120,9 @@ static const char *status_format_str(char *buf, size_t buflen, size_t col, int c
       if (!optional)
       {
         snprintf(fmt, sizeof(fmt), "%%%sd", prec);
-        snprintf(buf, buflen, fmt, mutt_buffy_check(false));
+        snprintf(buf, buflen, fmt, mutt_buffy_check(0));
       }
-      else if (mutt_buffy_check(false) == 0)
+      else if (mutt_buffy_check(0) == 0)
         optional = 0;
       break;