[PATCH] Add check-stats function used to calculate mailbox statistics

Anton Lindqvist anton at basename.se
Thu Jun 28 01:31:05 UTC 2018


On Wed, Jun 27, 2018 at 01:08:20PM -0700, Kevin J. McCarthy wrote:
> Hi Anton,
> 
> I have a few comments inline below.  With those changes, I'm fine with
> the patch.

Great! Comments inline.

> 
> On Tue, Jun 26, 2018 at 05:24:39PM +0900, Anton Lindqvist wrote:
> > diff --git a/buffy.c b/buffy.c
> > index eab17e6e..8f164f7f 100644
> > --- 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) &&
>        ^^
> Nit: I don't think you need the double parenthesis just above here.

Fixed

> 
> > +	(t - BuffyStatsTime >= BuffyCheckStatsInterval))))
>                                                        ^^
> 
> 
> > diff --git a/buffy.h b/buffy.h
> > index c0cfddf4..81f0cc7f 100644
> > --- 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 0x1
> > +#define MUTT_BUFFY_CHECK_FORCE_STATS 0x2
> 
> I'd prefer if this was like the other bit-flag definitions, like in
> mutt.h:
>   #define MUTT_BUFFY_CHECK_FORCE       1
>   #define MUTT_BUFFY_CHECK_FORCE_STATS (1<<1)

Fixed

> 
> > diff --git a/commands.c b/commands.c
> > index 3654fc0d..f5f22cd2 100644
> > --- a/commands.c
> > +++ b/commands.c
> > @@ -1028,4 +1028,10 @@ int mutt_check_traditional_pgp (HEADER *h, int *redraw)
> >    return rv;
> >  }
> >  
> > +void mutt_check_stats (void)
> > +{
> > +  if (!option (OPTMAILCHECKSTATS))
> > +    return;
> 
> Above, you allow the MUTT_BUFFY_CHECK_FORCE_STATS flag to override the
> option(OPTMAILCHECKSTATS) config variable.  I think this makes sense -
> some people may want to *only* manually refresh the stats.  So I would
> suggest removing the option check here.

That does make sense, conditional removed.

> 
> >  
> > +  mutt_buffy_check (MUTT_BUFFY_CHECK_FORCE | MUTT_BUFFY_CHECK_FORCE_STATS);
> > +}
> 
> > diff --git a/doc/manual.xml.head b/doc/manual.xml.head
> > index 8ac8fd9d..e78d9ec5 100644
> > --- a/doc/manual.xml.head
> > +++ b/doc/manual.xml.head
> > @@ -953,6 +953,20 @@ In addition, the <emphasis>index</emphasis> and
> >  
> >  <variablelist>
> >  
> > +<varlistentry>
> > +<term>
> > +<literal><check-stats></literal><anchor id="check-stats"/>
> > +</term>
> > +<listitem>
> > +<para>
> > +Calculate statistics for all monitored mailboxes declared using the
> > +<command>mailboxes</command> command.
> > +This function requires
> > +<link linkend="mail-check-stats">$mail_check_stats</link> to be set.
> 
> So, if we agree on that, we can remove the above sentence saying
> $mail_check_stats is required.  What do you think?

Yes, I did add a reference to <check-stats> in the docs for
$mail_check_stats to ease discoverability of this new function.
Also, the docs are updated to reflect the fact that <check-stats> does
not honor $mail_check_stats.

--- >8 ---

Subject: [PATCH] Add check-stats function used to calculate mailbox statistics

---
 OPS                 |  1 +
 buffy.c             | 14 +++++++++-----
 buffy.h             |  4 ++++
 commands.c          |  5 ++++-
 curs_main.c         | 15 +++++++++++----
 doc/manual.xml.head | 14 ++++++++++++++
 functions.h         |  2 ++
 init.h              |  4 ++++
 menu.c              |  4 ++++
 pager.c             |  4 ++++
 protos.h            |  1 +
 11 files changed, 58 insertions(+), 10 deletions(-)

diff --git a/OPS b/OPS
index 679f5dbd..c0c95806 100644
--- 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 eab17e6e..5ee085de 100644
--- 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 c0cfddf4..aecad530 100644
--- 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 */
diff --git a/commands.c b/commands.c
index 3654fc0d..cd65a0d2 100644
--- a/commands.c
+++ b/commands.c
@@ -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);
+}
diff --git a/curs_main.c b/curs_main.c
index c149d4a9..703a0660 100644
--- a/curs_main.c
+++ b/curs_main.c
@@ -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:
diff --git a/doc/manual.xml.head b/doc/manual.xml.head
index 8ac8fd9d..38ff9425 100644
--- a/doc/manual.xml.head
+++ b/doc/manual.xml.head
@@ -953,6 +953,20 @@ In addition, the <emphasis>index</emphasis> and
 
 <variablelist>
 
+<varlistentry>
+<term>
+<literal><check-stats></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><create-alias></literal><anchor id="create-alias"/>
diff --git a/functions.h b/functions.h
index 95d00d8b..442531ad 100644
--- a/functions.h
+++ b/functions.h
@@ -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 9858a50c..7e29536a 100644
--- a/init.h
+++ b/init.h
@@ -1545,6 +1545,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 dd7fad03..b9031935 100644
--- 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 5419fa27..ab3d4ade 100644
--- 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:
diff --git a/protos.h b/protos.h
index 432304e5..67d3ae80 100644
--- 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);
-- 
2.17.1


More information about the Mutt-dev mailing list