Hi, I'm using an external utility to fetch emails which I often invoke from within mutt using the following macro:
macro index G '<shell-escape>mbsync inboxes<Return>' Often, the sidebar new number of messages remains out-of-sync until $mail_check_stats_interval has passed. I known I could set it very low to work-around the sync issue but that feels like a hack. The following patch adds a new function check-stats which is unbound by default. Using this function I'm able to use the following enhanced macro and the sync issue is solved: macro index G '<shell-escape>mbsync inboxes<Return><check-stats>' Don't know if this patch is considered tailored too much for my own needs but any feedback would be much appreciated. -------- >8 -------- --- OPS | 1 + buffy.c | 14 +++++++++----- buffy.h | 4 ++++ commands.c | 6 ++++++ curs_main.c | 15 +++++++++++---- doc/manual.xml.head | 14 ++++++++++++++ functions.h | 2 ++ menu.c | 4 ++++ pager.c | 4 ++++ protos.h | 1 + 10 files changed, 56 insertions(+), 9 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..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) && + (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..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 + #endif /* _BUFFY_H */ 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; + 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..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. +</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/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