From: Anton Lindqvist Date: Fri, 29 Jun 2018 03:17:23 +0000 (-0700) Subject: Add check-stats function to calculate mailbox statistics. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e85c735350619990447ea5a8221c0fbdea8c25bd;p=neomutt Add check-stats function to calculate mailbox statistics. This allows the statistics to be updated without setting $mail_check_stats or before $mail_check_stats_interval has passed. --- diff --git a/browser.c b/browser.c index 0c07e5547..0178df3a1 100644 --- 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 4d063c7a8..ab89026f7 100644 --- 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 abaff004c..8368989d1 100644 --- 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; diff --git a/commands.c b/commands.c index 43ba13e03..23c55e987 100644 --- a/commands.c +++ b/commands.c @@ -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); +} diff --git a/curs_main.c b/curs_main.c index caddb7592..1a2ccbb12 100644 --- a/curs_main.c +++ b/curs_main.c @@ -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 diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 798f16416..6a262bd89 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -2161,6 +2161,20 @@ color sidebar_divider color8 default # Dark grey pager menus have these interesting functions: + + + <check-stats> + + + + + Calculate statistics for all monitored mailboxes declared using + the mailboxescommand. It will calculate + statistics despite $mail_check_stats + being unset. + + + <create-alias> (default: a) diff --git a/functions.h b/functions.h index d3ab8c292..37239b175 100644 --- a/functions.h +++ b/functions.h @@ -56,6 +56,7 @@ const struct Binding OpGeneric[] = { /* map: generic */ ** */ { "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 69024df55..e2623ea9d 100644 --- 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\fP function. */ { "mail_check_stats_interval", DT_NUMBER, R_NONE, &MailCheckStatsInterval, 60 }, /* diff --git a/main.c b/main.c index 4f59f266a..f7cd9a493 100644 --- 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 1b179cb71..d46e23be2 100644 --- 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; diff --git a/opcodes.h b/opcodes.h index fa7a79415..cf54cd840 100644 --- 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 d751b2f53..dd8dc6a0a 100644 --- 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: diff --git a/protos.h b/protos.h index f8f202659..b1ec7b169 100644 --- 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); diff --git a/status.c b/status.c index d6db1fcac..bc55cd775 100644 --- 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;