- if (!Context->pattern || strncmp (Context->pattern, "!~R!~D~s", 8) != 0)
- {
- snprintf (buf, sizeof (buf), "!~R!~D~s%s",
- Context->pattern ? Context->pattern : ".*");
- set_option (OPTHIDEREAD);
- }
- else
- {
- strfcpy (buf, Context->pattern + 8, sizeof(buf));
- if (!*buf || strncmp (buf, ".*", 2) == 0)
- snprintf (buf, sizeof(buf), "~A");
- unset_option (OPTHIDEREAD);
- }
- FREE (&Context->pattern);
- Context->pattern = safe_strdup (buf);
- }
- if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
- mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
- {
- if (menu->oldcurrent >= 0)
- {
- /* try to find what used to be the current message */
- menu->current = -1;
- for (i = 0; i < Context->vcount; i++)
- if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent)
- {
- menu->current = i;
- break;
- }
- if (menu->current < 0) menu->current = 0;
- }
- else
+ case OP_MAIN_LIMIT:
+ case OP_TOGGLE_READ:
+
+ CHECK_IN_MAILBOX;
+ menu->oldcurrent = (Context->vcount && menu->current >= 0
+ && menu->current <
+ Context->vcount) ? CURHDR->index : -1;
+ if (op == OP_TOGGLE_READ) {
+ char buffer[LONG_STRING];
+
+ if (!Context->pattern
+ || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
+ snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
+ Context->pattern ? Context->pattern : ".*");
+ set_option (OPTHIDEREAD);
+ }
+ else {
+ m_strcpy(buf, sizeof(buf), Context->pattern + 8);
+ if (!*buf || strncmp (buf, ".*", 2) == 0)
+ snprintf (buf, sizeof (buf), "~A");
+ unset_option (OPTHIDEREAD);
+ }
+ p_delete(&Context->pattern);
+ Context->pattern = m_strdup(buf);
+ }
+ if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
+ mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
+ {
+ if (menu->oldcurrent >= 0) {
+ /* try to find what used to be the current message */
+ menu->current = -1;
+ for (i = 0; i < Context->vcount; i++)
+ if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
+ menu->current = i;
+ break;
+ }
+ if (menu->current < 0)