]> granicus.if.org Git - mutt/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)
committerKevin McCarthy <kevin@8t8.us>
Fri, 29 Jun 2018 03:17:23 +0000 (20:17 -0700)
This allows the statistics to be updated without setting
$mail_check_stats or before $mail_check_stats_interval has passed.

OPS
buffy.c
buffy.h
commands.c
curs_main.c
doc/manual.xml.head
functions.h
init.h
menu.c
pager.c
protos.h

diff --git a/OPS b/OPS
index 679f5dbd922262465be439719e5fc55716e19af4..c0c95806a92fb067441e202c78b8fd038ed2b667 100644 (file)
--- a/OPS
+++ b/OPS
@@ -181,6 +181,7 @@ OP_VERSION "show the Mutt version number and date"
 OP_VIEW_ATTACH "view attachment using mailcap entry if necessary"
 OP_VIEW_ATTACHMENTS "show MIME attachments"
 OP_WHAT_KEY "display the keycode for a key press"
+OP_CHECK_STATS "calculate message statistics for all mailboxes"
 OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
 OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
 OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
diff --git a/buffy.c b/buffy.c
index eab17e6e88e81974c34d275f99d601a8f4587fd5..6d7fbe56734c65bbef548a772948c8eab4a74ebe 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -505,7 +505,9 @@ static int buffy_mbox_check (BUFFY* mailbox, struct stat *sb, int check_stats)
 }
 
 /* Check all Incoming for new mail and total/new/flagged messages
- * force: if true, ignore BuffyTimeout and check for new mail anyway
+ * 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
  */
 int mutt_buffy_check (int force)
 {
@@ -525,7 +527,7 @@ int mutt_buffy_check (int force)
 
 #ifdef USE_IMAP
   /* update postponed count as well, on force */
-  if (force)
+  if (force & MUTT_BUFFY_CHECK_FORCE)
     mutt_update_num_postponed ();
 #endif
 
@@ -536,8 +538,9 @@ int mutt_buffy_check (int force)
   if (!force && (t - BuffyTime < BuffyTimeout))
     return BuffyCount;
 
-  if (option (OPTMAILCHECKSTATS) &&
-      (t - BuffyStatsTime >= BuffyCheckStatsInterval))
+  if ((force & MUTT_BUFFY_CHECK_FORCE_STATS) ||
+      (option (OPTMAILCHECKSTATS) &&
+       (t - BuffyStatsTime >= BuffyCheckStatsInterval)))
   {
     check_stats = 1;
     BuffyStatsTime = t;
@@ -744,7 +747,8 @@ void mutt_buffy (char *s, size_t slen)
          found = 1;
       }
 
-    mutt_buffy_check (1); /* 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 c0cfddf4dea77fea97172a43a6a4bcf595c7b7e6..aecad53051beebc39da646c67463eee4d2168281 100644 (file)
--- a/buffy.h
+++ b/buffy.h
@@ -63,4 +63,8 @@ void mutt_buffy_setnotified (const char *path);
 
 int mh_buffy (BUFFY *, int);
 
+/* force flags passed to mutt_buffy_check() */
+#define MUTT_BUFFY_CHECK_FORCE       1
+#define MUTT_BUFFY_CHECK_FORCE_STATS (1<<1)
+
 #endif /* _BUFFY_H */
index 3654fc0d93d18d48daa681cb29dbbf95f2ae7719..cd65a0d2185f800db2b7a88c467219c750b9c490 100644 (file)
@@ -1028,4 +1028,7 @@ int mutt_check_traditional_pgp (HEADER *h, int *redraw)
   return rv;
 }
 
-
+void mutt_check_stats (void)
+{
+  mutt_buffy_check (MUTT_BUFFY_CHECK_FORCE | MUTT_BUFFY_CHECK_FORCE_STATS);
+}
index c149d4a934306ddd8878cc661b10112c04570b68..703a0660488c81a36b32dc977344a64c5ef6476f 100644 (file)
@@ -579,8 +579,10 @@ int mutt_index_menu (void)
   menu->custom_menu_redraw = index_menu_redraw;
   mutt_push_current_menu (menu);
 
-  if (!attach_msg)
-    mutt_buffy_check(1); /* force the buffy check after we enter the folder */
+  if (!attach_msg) {
+    mutt_buffy_check(MUTT_BUFFY_CHECK_FORCE); /* force the buffy check after we
+                                                enter the folder */
+  }
 #ifdef USE_INOTIFY
   mutt_monitor_add (NULL);
 #endif
@@ -1339,8 +1341,9 @@ int mutt_index_menu (void)
 #endif
 
        mutt_clear_error ();
-       mutt_buffy_check(1); /* 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;
        set_option (OPTSEARCHINVALID);
        break;
@@ -2467,6 +2470,10 @@ int mutt_index_menu (void)
        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 8ac8fd9dcca2f97bce67186efa008d076721320d..38ff94255360c453ed2c0f501a4d86dd27468f75 100644 (file)
@@ -953,6 +953,20 @@ In addition, the <emphasis>index</emphasis> and
 
 <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><anchor id="create-alias"/>
index 95d00d8bf75e25794a6866e63fdd81a525f4f97c..442531adfedfd4559ff44961ffb61765447b83c1 100644 (file)
@@ -80,6 +80,7 @@ const struct binding_t OpGeneric[] = { /* map: generic */
   { "current-bottom",   OP_CURRENT_BOTTOM,     NULL },
   { "error-history",    OP_ERROR_HISTORY,      NULL },
   { "what-key",                OP_WHAT_KEY,            NULL },
+  { "check-stats",     OP_CHECK_STATS,         NULL },
   { NULL,              0,                      NULL }
 };
 
@@ -290,6 +291,7 @@ const struct binding_t OpPager[] = { /* map: pager */
   { "decrypt-save",            OP_DECRYPT_SAVE,                NULL },
 
   { "what-key",                OP_WHAT_KEY,            NULL },
+  { "check-stats",     OP_CHECK_STATS,         NULL },
 
 #ifdef USE_SIDEBAR
   { "sidebar-next",            OP_SIDEBAR_NEXT,                NULL },
diff --git a/init.h b/init.h
index 9fcae45df682bab3cbca3262cde7878199edf1b3..a2ac91aac4e07af14bd2934c9f18f7c719fc1d69 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1546,6 +1546,10 @@ struct option_t 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_NUM, R_NONE, UL &BuffyCheckStatsInterval, 60 },
   /*
diff --git a/menu.c b/menu.c
index dd7fad03e3ceb08b1de8e235c6f4ef9682cc4af2..b90319358fbab6511ddaf5fe1482f877ab5b4348 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -1195,6 +1195,10 @@ int mutt_menuLoop (MUTTMENU *menu)
        mutt_what_key ();
        break;
 
+      case OP_CHECK_STATS:
+       mutt_check_stats ();
+       break;
+
       case OP_REDRAW:
        clearok (stdscr, TRUE);
        menu->redraw = REDRAW_FULL;
diff --git a/pager.c b/pager.c
index 5419fa27d063734c6e569c3b95aa719f4e3eb607..ab3d4ade4088018e81e76efd2be4ecd7e6cf14d6 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -2884,6 +2884,10 @@ search_next:
        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 432304e57d2e07bd2d3b299dfec914feeb3445b7..67d3ae80c516a969309d400fe647733e344dbb92 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -178,6 +178,7 @@ void mutt_break_thread (HEADER *);
 void mutt_buffy (char *, size_t);
 int  mutt_buffy_list (void);
 void mutt_canonical_charset (char *, size_t, const char *);
+void mutt_check_stats(void);
 int mutt_count_body_parts (CONTEXT *, HEADER *);
 void mutt_check_rescore (CONTEXT *);
 void mutt_clear_error (void);