From: Alain Bench Date: Sun, 4 Sep 2005 05:57:40 +0000 (+0000) Subject: Allow empty limits, and limits in empty mailboxes. Closes: #1853, #1906. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a3d5fb7091ea7aa48ecf7cac2425fef3684afdb2;p=neomutt Allow empty limits, and limits in empty mailboxes. Closes: #1853, #1906. --- diff --git a/curs_main.c b/curs_main.c index 8b1f0b587..635832a9e 100644 --- a/curs_main.c +++ b/curs_main.c @@ -55,6 +55,13 @@ static const char *Mailbox_is_read_only = N_("Mailbox is read-only."); static const char *Function_not_permitted_in_attach_message_mode = N_("Function not permitted in attach-message mode."); static const char *No_visible = N_("No visible messages."); +#define CHECK_IN_MAILBOX if (!Context) \ + { \ + mutt_flushinp (); \ + mutt_error _(No_mailbox_is_open); \ + break; \ + } + #define CHECK_MSGCOUNT if (!Context) \ { \ mutt_flushinp (); \ @@ -286,20 +293,17 @@ static void update_index (MUTTMENU *menu, CONTEXT *ctx, int check, if (Context->pattern) { #define THIS_BODY Context->hdrs[j]->content - if (oldcount || check == M_REOPENED) + for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) { - for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) + if (mutt_pattern_exec (Context->limit_pattern, + M_MATCH_FULL_ADDRESS, + Context, Context->hdrs[j])) { - if (mutt_pattern_exec (Context->limit_pattern, - M_MATCH_FULL_ADDRESS, - Context, Context->hdrs[j])) - { - Context->hdrs[j]->virtual = Context->vcount; - Context->v2r[Context->vcount] = j; - Context->hdrs[j]->limited = 1; - Context->vcount++; - Context->vsize += THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset; - } + Context->hdrs[j]->virtual = Context->vcount; + Context->v2r[Context->vcount] = j; + Context->hdrs[j]->limited = 1; + Context->vcount++; + Context->vsize += THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset; } } #undef THIS_BODY @@ -826,7 +830,7 @@ CHECK_IMAP_ACL(IMAP_ACL_DELETE); break; case OP_MAIN_SHOW_LIMIT: - CHECK_MSGCOUNT; + CHECK_IN_MAILBOX; if (!Context->pattern) mutt_message _("No limit pattern is in effect."); else @@ -840,7 +844,7 @@ CHECK_IMAP_ACL(IMAP_ACL_DELETE); case OP_MAIN_LIMIT: - CHECK_MSGCOUNT; + CHECK_IN_MAILBOX; menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ? CURHDR->index : -1; if (mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0) @@ -860,7 +864,7 @@ CHECK_IMAP_ACL(IMAP_ACL_DELETE); else menu->current = 0; menu->redraw = REDRAW_INDEX | REDRAW_STATUS; - if ((Sort & SORT_MASK) == SORT_THREADS) + if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS) mutt_draw_tree (Context); menu->redraw = REDRAW_FULL; } @@ -1582,7 +1586,7 @@ CHECK_IMAP_ACL(IMAP_ACL_SEEN); case OP_TOGGLE_WRITE: - CHECK_MSGCOUNT; + CHECK_IN_MAILBOX; if (mx_toggle_write (Context) == 0) menu->redraw |= REDRAW_STATUS; break; diff --git a/pattern.c b/pattern.c index bcaaabf26..59a2b6ccb 100644 --- a/pattern.c +++ b/pattern.c @@ -1218,23 +1218,16 @@ int mutt_pattern_func (int op, char *prompt) if (op == M_LIMIT) { + /* drop previous limit pattern */ FREE (&Context->pattern); - if (Context->limit_pattern) + if (Context->limit_pattern) mutt_pattern_free (&Context->limit_pattern); - if (!Context->vcount) - { + + if (Context->msgcount && !Context->vcount) mutt_error _("No messages matched criteria."); -#if 0 - Context->vcount = Context->msgcount; - /* restore full display */ - for (i = 0; i < Context->msgcount; i++) - { - Context->hdrs[i]->virtual = i; - Context->v2r[i] = i; - } -#endif - } - else if (mutt_strncmp (buf, "~A", 2) != 0) + + /* record new limit pattern, unless match all */ + if (mutt_strcmp (buf, "~A") != 0) { Context->pattern = simple; simple = NULL; /* don't clobber it */