NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
pattern.c File Reference
#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include "private.h"
#include "mutt/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "alias/gui.h"
#include "gui/lib.h"
#include "mutt.h"
#include "lib.h"
#include "context.h"
#include "mutt_globals.h"
#include "mutt_logging.h"
#include "mutt_menu.h"
#include "mx.h"
#include "opcodes.h"
#include "options.h"
#include "progress.h"
#include "protos.h"
#include <sys/stat.h>
#include "imap/lib.h"
+ Include dependency graph for pattern.c:

Go to the source code of this file.

Functions

static void quote_simple (const char *str, struct Buffer *buf)
 Apply simple quoting to a string. More...
 
void mutt_check_simple (struct Buffer *buf, const char *simple)
 Convert a simple search into a real request. More...
 
static struct MuttThreadtop_of_thread (struct Email *e)
 Find the first email in the current thread. More...
 
bool mutt_limit_current_thread (struct Context *ctx, struct Email *e)
 Limit the email view to the current thread. More...
 
int mutt_pattern_alias_func (int op, char *prompt, char *menu_name, struct AliasMenuData *mdata, struct Context *ctx, struct Menu *menu)
 Perform some Pattern matching for Alias. More...
 
int mutt_pattern_func (struct Context *ctx, int op, char *prompt)
 Perform some Pattern matching. More...
 
int mutt_search_command (struct Context *ctx, struct Mailbox *m, int cur, int op)
 Perform a search. More...
 
int mutt_search_alias_command (struct Context *ctx, struct Menu *menu, int cur, int op)
 Perform a search. More...
 

Variables

struct RangeRegex range_regexes []
 Set of Regexes for various range types. More...
 
bool(* eat_arg_t )(struct Pattern *pat, PatternCompFlags flags, struct Buffer *s, struct Buffer *err)
 Function to parse a pattern. More...
 
static struct PatternList * SearchPattern = NULL
 current search pattern More...
 
static char LastSearch [256] = { 0 }
 last pattern searched for More...
 
static char LastSearchExpn [1024] = { 0 }
 expanded version of LastSearch More...
 

Detailed Description

Match patterns to emails

Authors
  • Michael R. Elkins
  • Pietro Cerutti
  • R Primus

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file pattern.c.

Function Documentation

◆ quote_simple()

static void quote_simple ( const char *  str,
struct Buffer buf 
)
static

Apply simple quoting to a string.

Parameters
strString to quote
bufBuffer for the result

Definition at line 93 of file pattern.c.

94 {
95  mutt_buffer_reset(buf);
96  mutt_buffer_addch(buf, '"');
97  while (*str)
98  {
99  if ((*str == '\\') || (*str == '"'))
100  mutt_buffer_addch(buf, '\\');
101  mutt_buffer_addch(buf, *str++);
102  }
103  mutt_buffer_addch(buf, '"');
104 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_check_simple()

void mutt_check_simple ( struct Buffer buf,
const char *  simple 
)

Convert a simple search into a real request.

Parameters
bufBuffer for the result
simpleSearch string to convert

Definition at line 111 of file pattern.c.

112 {
113  bool do_simple = true;
114 
115  for (const char *p = mutt_buffer_string(buf); p && (p[0] != '\0'); p++)
116  {
117  if ((p[0] == '\\') && (p[1] != '\0'))
118  p++;
119  else if ((p[0] == '~') || (p[0] == '=') || (p[0] == '%'))
120  {
121  do_simple = false;
122  break;
123  }
124  }
125 
126  /* XXX - is mutt_istr_cmp() right here, or should we use locale's
127  * equivalences? */
128 
129  if (do_simple) /* yup, so spoof a real request */
130  {
131  /* convert old tokens into the new format */
132  if (mutt_istr_equal("all", mutt_buffer_string(buf)) ||
133  mutt_str_equal("^", mutt_buffer_string(buf)) ||
134  mutt_str_equal(".", mutt_buffer_string(buf))) /* ~A is more efficient */
135  {
136  mutt_buffer_strcpy(buf, "~A");
137  }
138  else if (mutt_istr_equal("del", mutt_buffer_string(buf)))
139  mutt_buffer_strcpy(buf, "~D");
140  else if (mutt_istr_equal("flag", mutt_buffer_string(buf)))
141  mutt_buffer_strcpy(buf, "~F");
142  else if (mutt_istr_equal("new", mutt_buffer_string(buf)))
143  mutt_buffer_strcpy(buf, "~N");
144  else if (mutt_istr_equal("old", mutt_buffer_string(buf)))
145  mutt_buffer_strcpy(buf, "~O");
146  else if (mutt_istr_equal("repl", mutt_buffer_string(buf)))
147  mutt_buffer_strcpy(buf, "~Q");
148  else if (mutt_istr_equal("read", mutt_buffer_string(buf)))
149  mutt_buffer_strcpy(buf, "~R");
150  else if (mutt_istr_equal("tag", mutt_buffer_string(buf)))
151  mutt_buffer_strcpy(buf, "~T");
152  else if (mutt_istr_equal("unread", mutt_buffer_string(buf)))
153  mutt_buffer_strcpy(buf, "~U");
154  else
155  {
156  struct Buffer *tmp = mutt_buffer_pool_get();
157  quote_simple(mutt_buffer_string(buf), tmp);
158  mutt_file_expand_fmt(buf, simple, mutt_buffer_string(tmp));
160  }
161  }
162 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ top_of_thread()

static struct MuttThread* top_of_thread ( struct Email e)
static

Find the first email in the current thread.

Parameters
eCurrent Email
Return values
ptrSuccess, email found
NULLError

Definition at line 170 of file pattern.c.

171 {
172  if (!e)
173  return NULL;
174 
175  struct MuttThread *t = e->thread;
176 
177  while (t && t->parent)
178  t = t->parent;
179 
180  return t;
181 }
+ Here is the caller graph for this function:

◆ mutt_limit_current_thread()

bool mutt_limit_current_thread ( struct Context ctx,
struct Email e 
)

Limit the email view to the current thread.

Parameters
ctxCurrent Mailbox
eCurrent Email
Return values
trueSuccess
falseFailure

Definition at line 190 of file pattern.c.

191 {
192  if (!ctx || !ctx->mailbox || !e)
193  return false;
194 
195  struct Mailbox *m = ctx->mailbox;
196 
197  struct MuttThread *me = top_of_thread(e);
198  if (!me)
199  return false;
200 
201  m->vcount = 0;
202  ctx->vsize = 0;
203  ctx->collapsed = false;
204 
205  for (int i = 0; i < m->msg_count; i++)
206  {
207  e = m->emails[i];
208  if (!e)
209  break;
210 
211  e->vnum = -1;
212  e->visible = false;
213  e->collapsed = false;
214  e->num_hidden = 0;
215 
216  if (top_of_thread(e) == me)
217  {
218  struct Body *body = e->body;
219 
220  e->vnum = m->vcount;
221  e->visible = true;
222  m->v2r[m->vcount] = i;
223  m->vcount++;
224  ctx->vsize += (body->length + body->offset - body->hdr_offset);
225  }
226  }
227  return true;
228 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_pattern_alias_func()

int mutt_pattern_alias_func ( int  op,
char *  prompt,
char *  menu_name,
struct AliasMenuData mdata,
struct Context ctx,
struct Menu menu 
)

Perform some Pattern matching for Alias.

Parameters
opOperation to perform, e.g. MUTT_LIMIT
promptPrompt to show the user
menu_nameName of the current menu, e.g. Aliases, Query
mdataMenu data holding Aliases
ctxCurrent Mailbox
menuCurrent menu
Return values
0Success
-1Failure

Definition at line 241 of file pattern.c.

244 {
245  int rc = -1;
246  struct Progress progress;
247  struct Buffer *buf = mutt_buffer_pool_get();
248 
249  mutt_buffer_strcpy(buf, mdata->str);
250  if (prompt)
251  {
252  if ((mutt_buffer_get_field(prompt, buf, MUTT_PATTERN | MUTT_CLEAR, false,
253  NULL, NULL, NULL) != 0) ||
255  {
257  return -1;
258  }
259  }
260 
261  mutt_message(_("Compiling search pattern..."));
262 
263  bool match_all = false;
264  struct PatternList *pat = NULL;
265  char *simple = mutt_buffer_strdup(buf);
266  if (simple)
267  {
269  const char *pbuf = buf->data;
270  while (*pbuf == ' ')
271  pbuf++;
272  match_all = mutt_str_equal(pbuf, "~A");
273 
274  struct Buffer err = mutt_buffer_make(0);
275  pat = mutt_pattern_comp(ctx, buf->data, MUTT_PC_FULL_MSG, &err);
276  if (!pat)
277  {
278  mutt_error("%s", mutt_buffer_string(&err));
279  mutt_buffer_dealloc(&err);
280  goto bail;
281  }
282  }
283  else
284  {
285  match_all = true;
286  }
287 
288  mutt_progress_init(&progress, _("Executing command on matching messages..."),
289  MUTT_PROGRESS_READ, ARRAY_SIZE(&mdata->ava));
290 
291  int vcounter = 0;
292  struct AliasView *avp = NULL;
293  ARRAY_FOREACH(avp, &mdata->ava)
294  {
295  mutt_progress_update(&progress, ARRAY_FOREACH_IDX, -1);
296 
297  if (match_all ||
299  {
300  avp->is_visible = true;
301  vcounter++;
302  }
303  else
304  {
305  avp->is_visible = false;
306  }
307  }
308 
309  mutt_str_replace(&mdata->str, simple);
310 
311  if (menu)
312  {
313  menu->max = vcounter;
314  menu->current = 0;
315 
316  FREE(&menu->title);
317 
318  if (match_all)
319  menu->title = menu_create_alias_title(menu_name, NULL);
320  else
321  menu->title = menu_create_alias_title(menu_name, simple);
322  }
323 
325 
326  rc = 0;
327 
328 bail:
330  FREE(&simple);
331  mutt_pattern_free(&pat);
332 
333  return rc;
334 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_pattern_func()

int mutt_pattern_func ( struct Context ctx,
int  op,
char *  prompt 
)

Perform some Pattern matching.

Parameters
ctxCurrent Mailbox
opOperation to perform, e.g. MUTT_LIMIT
promptPrompt to show the user
Return values
0Success
-1Failure

Definition at line 344 of file pattern.c.

345 {
346  if (!ctx || !ctx->mailbox)
347  return -1;
348 
349  struct Mailbox *m = ctx->mailbox;
350 
351  struct Buffer err;
352  int rc = -1;
353  struct Progress progress;
354  struct Buffer *buf = mutt_buffer_pool_get();
355 
356  mutt_buffer_strcpy(buf, NONULL(ctx->pattern));
357  if (prompt || (op != MUTT_LIMIT))
358  {
359  if ((mutt_buffer_get_field(prompt, buf, MUTT_PATTERN | MUTT_CLEAR, false,
360  NULL, NULL, NULL) != 0) ||
362  {
364  return -1;
365  }
366  }
367 
368  mutt_message(_("Compiling search pattern..."));
369 
370  char *simple = mutt_buffer_strdup(buf);
372  const char *pbuf = buf->data;
373  while (*pbuf == ' ')
374  pbuf++;
375  const bool match_all = mutt_str_equal(pbuf, "~A");
376 
377  mutt_buffer_init(&err);
378  err.dsize = 256;
379  err.data = mutt_mem_malloc(err.dsize);
380  struct PatternList *pat = mutt_pattern_comp(ctx, buf->data, MUTT_PC_FULL_MSG, &err);
381  if (!pat)
382  {
383  mutt_error("%s", err.data);
384  goto bail;
385  }
386 
387 #ifdef USE_IMAP
388  if ((m->type == MUTT_IMAP) && (!imap_search(m, pat)))
389  goto bail;
390 #endif
391 
392  mutt_progress_init(&progress, _("Executing command on matching messages..."),
393  MUTT_PROGRESS_READ, (op == MUTT_LIMIT) ? m->msg_count : m->vcount);
394 
395  if (op == MUTT_LIMIT)
396  {
397  m->vcount = 0;
398  ctx->vsize = 0;
399  ctx->collapsed = false;
400  int padding = mx_msg_padding_size(m);
401 
402  for (int i = 0; i < m->msg_count; i++)
403  {
404  struct Email *e = m->emails[i];
405  if (!e)
406  break;
407 
408  mutt_progress_update(&progress, i, -1);
409  /* new limit pattern implicitly uncollapses all threads */
410  e->vnum = -1;
411  e->visible = false;
412  e->collapsed = false;
413  e->num_hidden = 0;
414  if (match_all ||
416  {
417  e->vnum = m->vcount;
418  e->visible = true;
419  m->v2r[m->vcount] = i;
420  m->vcount++;
421  struct Body *b = e->body;
422  ctx->vsize += b->length + b->offset - b->hdr_offset + padding;
423  }
424  }
425  }
426  else
427  {
428  for (int i = 0; i < m->vcount; i++)
429  {
430  struct Email *e = mutt_get_virt_email(m, i);
431  if (!e)
432  continue;
433  mutt_progress_update(&progress, i, -1);
435  {
436  switch (op)
437  {
438  case MUTT_UNDELETE:
439  mutt_set_flag(m, e, MUTT_PURGE, false);
440  /* fallthrough */
441  case MUTT_DELETE:
442  mutt_set_flag(m, e, MUTT_DELETE, (op == MUTT_DELETE));
443  break;
444  case MUTT_TAG:
445  case MUTT_UNTAG:
446  mutt_set_flag(m, e, MUTT_TAG, (op == MUTT_TAG));
447  break;
448  }
449  }
450  }
451  }
452 
454 
455  if (op == MUTT_LIMIT)
456  {
457  /* drop previous limit pattern */
458  FREE(&ctx->pattern);
460 
461  if (m->msg_count && !m->vcount)
462  mutt_error(_("No messages matched criteria"));
463 
464  /* record new limit pattern, unless match all */
465  if (!match_all)
466  {
467  ctx->pattern = simple;
468  simple = NULL; /* don't clobber it */
469  ctx->limit_pattern = mutt_pattern_comp(ctx, buf->data, MUTT_PC_FULL_MSG, &err);
470  }
471  }
472 
473  rc = 0;
474 
475 bail:
477  FREE(&simple);
478  mutt_pattern_free(&pat);
479  FREE(&err.data);
480 
481  return rc;
482 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_search_command()

int mutt_search_command ( struct Context ctx,
struct Mailbox m,
int  cur,
int  op 
)

Perform a search.

Parameters
ctxCurrent Mailbox
mMailbox to search through
curIndex number of current email
opOperation to perform, e.g. OP_SEARCH_NEXT
Return values
>=0 Index of matching email
-1No match, or error

Definition at line 493 of file pattern.c.

494 {
495  struct Progress progress;
496 
497  if ((*LastSearch == '\0') || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
498  {
499  char buf[256];
500  mutt_str_copy(buf, (LastSearch[0] != '\0') ? LastSearch : "", sizeof(buf));
501  if ((mutt_get_field(
502  ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ? _("Search for: ") : _("Reverse search for: "),
503  buf, sizeof(buf), MUTT_CLEAR | MUTT_PATTERN, false, NULL, NULL) != 0) ||
504  (buf[0] == '\0'))
505  {
506  return -1;
507  }
508 
509  if ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT))
510  OptSearchReverse = false;
511  else
512  OptSearchReverse = true;
513 
514  /* compare the *expanded* version of the search pattern in case
515  * $simple_search has changed while we were searching */
516  struct Buffer *tmp = mutt_buffer_pool_get();
517  mutt_buffer_strcpy(tmp, buf);
519 
521  {
522  struct Buffer err;
523  mutt_buffer_init(&err);
524  OptSearchInvalid = true;
525  mutt_str_copy(LastSearch, buf, sizeof(LastSearch));
527  mutt_message(_("Compiling search pattern..."));
529  err.dsize = 256;
530  err.data = mutt_mem_malloc(err.dsize);
532  if (!SearchPattern)
533  {
535  mutt_error("%s", err.data);
536  FREE(&err.data);
537  LastSearch[0] = '\0';
538  LastSearchExpn[0] = '\0';
539  return -1;
540  }
541  FREE(&err.data);
543  }
544 
546  }
547 
548  if (OptSearchInvalid)
549  {
550  for (int i = 0; i < m->msg_count; i++)
551  m->emails[i]->searched = false;
552 #ifdef USE_IMAP
553  if ((m->type == MUTT_IMAP) && (!imap_search(m, SearchPattern)))
554  return -1;
555 #endif
556  OptSearchInvalid = false;
557  }
558 
559  int incr = OptSearchReverse ? -1 : 1;
560  if (op == OP_SEARCH_OPPOSITE)
561  incr = -incr;
562 
563  mutt_progress_init(&progress, _("Searching..."), MUTT_PROGRESS_READ, m->vcount);
564 
565  for (int i = cur + incr, j = 0; j != m->vcount; j++)
566  {
567  const char *msg = NULL;
568  mutt_progress_update(&progress, j, -1);
569  if (i > m->vcount - 1)
570  {
571  i = 0;
572  if (C_WrapSearch)
573  msg = _("Search wrapped to top");
574  else
575  {
576  mutt_message(_("Search hit bottom without finding match"));
577  return -1;
578  }
579  }
580  else if (i < 0)
581  {
582  i = m->vcount - 1;
583  if (C_WrapSearch)
584  msg = _("Search wrapped to bottom");
585  else
586  {
587  mutt_message(_("Search hit top without finding match"));
588  return -1;
589  }
590  }
591 
592  struct Email *e = mutt_get_virt_email(m, i);
593  if (e->searched)
594  {
595  /* if we've already evaluated this message, use the cached value */
596  if (e->matched)
597  {
599  if (msg && *msg)
600  mutt_message(msg);
601  return i;
602  }
603  }
604  else
605  {
606  /* remember that we've already searched this message */
607  e->searched = true;
609  MUTT_MATCH_FULL_ADDRESS, m, e, NULL);
610  if (e->matched > 0)
611  {
613  if (msg && *msg)
614  mutt_message(msg);
615  return i;
616  }
617  }
618 
619  if (SigInt)
620  {
621  mutt_error(_("Search interrupted"));
622  SigInt = 0;
623  return -1;
624  }
625 
626  i += incr;
627  }
628 
629  mutt_error(_("Not found"));
630  return -1;
631 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_search_alias_command()

int mutt_search_alias_command ( struct Context ctx,
struct Menu menu,
int  cur,
int  op 
)

Perform a search.

Parameters
ctxCurrent Mailbox
menuMenu to search through
curIndex number of current alias
opOperation to perform, e.g. OP_SEARCH_NEXT
Return values
>=0Index of matching alias
-1No match, or error

Definition at line 642 of file pattern.c.

643 {
644  struct Progress progress;
645 
646  struct AliasViewArray *ava = &((struct AliasMenuData *) menu->mdata)->ava;
647 
648  if ((*LastSearch == '\0') || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
649  {
650  char buf[256];
651  mutt_str_copy(buf, (LastSearch[0] != '\0') ? LastSearch : "", sizeof(buf));
652  if ((mutt_get_field(
653  ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ? _("Search for: ") : _("Reverse search for: "),
654  buf, sizeof(buf), MUTT_CLEAR | MUTT_PATTERN, false, NULL, NULL) != 0) ||
655  (buf[0] == '\0'))
656  {
657  return -1;
658  }
659 
660  if ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT))
661  OptSearchReverse = false;
662  else
663  OptSearchReverse = true;
664 
665  /* compare the *expanded* version of the search pattern in case
666  * $simple_search has changed while we were searching */
667  struct Buffer *tmp = mutt_buffer_pool_get();
668  mutt_buffer_strcpy(tmp, buf);
670 
672  {
673  struct Buffer err;
674  mutt_buffer_init(&err);
675  OptSearchInvalid = true;
676  mutt_str_copy(LastSearch, buf, sizeof(LastSearch));
678  mutt_message(_("Compiling search pattern..."));
680  err.dsize = 256;
681  err.data = mutt_mem_malloc(err.dsize);
683  if (!SearchPattern)
684  {
686  mutt_error("%s", err.data);
687  FREE(&err.data);
688  LastSearch[0] = '\0';
689  LastSearchExpn[0] = '\0';
690  return -1;
691  }
692  FREE(&err.data);
694  }
695 
697  }
698 
699  if (OptSearchInvalid)
700  {
701  struct AliasView *av = NULL;
702  ARRAY_FOREACH(av, ava)
703  {
704  av->is_searched = false;
705  }
706 
707  OptSearchInvalid = false;
708  }
709 
710  int incr = OptSearchReverse ? -1 : 1;
711  if (op == OP_SEARCH_OPPOSITE)
712  incr = -incr;
713 
714  mutt_progress_init(&progress, _("Searching..."), MUTT_PROGRESS_READ, ARRAY_SIZE(ava));
715 
716  for (int i = cur + incr, j = 0; j != ARRAY_SIZE(ava); j++)
717  {
718  const char *msg = NULL;
719  mutt_progress_update(&progress, j, -1);
720  if (i > ARRAY_SIZE(ava) - 1)
721  {
722  i = 0;
723  if (C_WrapSearch)
724  msg = _("Search wrapped to top");
725  else
726  {
727  mutt_message(_("Search hit bottom without finding match"));
728  return -1;
729  }
730  }
731  else if (i < 0)
732  {
733  i = ARRAY_SIZE(ava) - 1;
734  if (C_WrapSearch)
735  msg = _("Search wrapped to bottom");
736  else
737  {
738  mutt_message(_("Search hit top without finding match"));
739  return -1;
740  }
741  }
742 
743  struct AliasView *av = ARRAY_GET(ava, i);
744  if (av->is_searched)
745  {
746  /* if we've already evaluated this message, use the cached value */
747  if (av->is_matched)
748  {
750  if (msg && *msg)
751  mutt_message(msg);
752  return i;
753  }
754  }
755  else
756  {
757  /* remember that we've already searched this message */
758  av->is_searched = true;
760  MUTT_MATCH_FULL_ADDRESS, av, NULL);
761  if (av->is_matched > 0)
762  {
764  if (msg && *msg)
765  mutt_message(msg);
766  return i;
767  }
768  }
769 
770  if (SigInt)
771  {
772  mutt_error(_("Search interrupted"));
773  SigInt = 0;
774  return -1;
775  }
776 
777  i += incr;
778  }
779 
780  mutt_error(_("Not found"));
781  return -1;
782 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ range_regexes

struct RangeRegex range_regexes[]
Initial value:
= {
[RANGE_K_REL] = { RANGE_REL_RX, 1, 3, 0, { 0 } },
[RANGE_K_ABS] = { RANGE_ABS_RX, 1, 3, 0, { 0 } },
[RANGE_K_LT] = { RANGE_LT_RX, 1, 2, 0, { 0 } },
[RANGE_K_GT] = { RANGE_GT_RX, 2, 1, 0, { 0 } },
[RANGE_K_BARE] = { RANGE_BARE_RX, 1, 1, 0, { 0 } },
}

Set of Regexes for various range types.

This array, will also contain the compiled regexes.

Definition at line 64 of file pattern.c.

◆ eat_arg_t

bool(* eat_arg_t) (struct Pattern *pat, PatternCompFlags flags, struct Buffer *s, struct Buffer *err)

Function to parse a pattern.

Parameters
patPattern to store the results in
flagsFlags, e.g. MUTT_PC_PATTERN_DYNAMIC
sString to parse
errBuffer for error messages
Return values
trueIf the pattern was read successfully

Definition at line 81 of file pattern.c.

◆ SearchPattern

struct PatternList* SearchPattern = NULL
static

current search pattern

Definition at line 84 of file pattern.c.

◆ LastSearch

char LastSearch[256] = { 0 }
static

last pattern searched for

Definition at line 85 of file pattern.c.

◆ LastSearchExpn

char LastSearchExpn[1024] = { 0 }
static

expanded version of LastSearch

Definition at line 86 of file pattern.c.

Body::hdr_offset
long hdr_offset
Offset in stream where the headers begin.
Definition: body.h:42
mutt_get_virt_email
struct Email * mutt_get_virt_email(struct Mailbox *m, int vnum)
Get a virtual Email.
Definition: context.c:397
mutt_pattern_comp
struct PatternList * mutt_pattern_comp(struct Context *ctx, const char *s, PatternCompFlags flags, struct Buffer *err)
Create a Pattern.
Definition: compile.c:1082
SigInt
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: mutt_globals.h:74
imap_search
bool imap_search(struct Mailbox *m, const struct PatternList *pat)
Find messages in mailbox matching a pattern.
Definition: search.c:228
_
#define _(a)
Definition: message.h:28
NONULL
#define NONULL(x)
Definition: string2.h:37
AliasView::is_matched
bool is_matched
Search matches this Alias.
Definition: gui.h:41
Mailbox
A mailbox.
Definition: mailbox.h:81
Mailbox::v2r
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:101
Mailbox::emails
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
mutt_pattern_free
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition: compile.c:1029
Email::matched
bool matched
Search matches this Email.
Definition: email.h:68
Buffer
String manipulation buffer.
Definition: buffer.h:33
Email::thread
struct MuttThread * thread
Thread of Emails.
Definition: email.h:95
Body::offset
LOFF_T offset
offset where the actual data begins
Definition: body.h:44
quote_simple
static void quote_simple(const char *str, struct Buffer *buf)
Apply simple quoting to a string.
Definition: pattern.c:93
MUTT_PATTERN
#define MUTT_PATTERN
Pattern mode - only used for history classes.
Definition: mutt.h:64
AliasMenuData::str
char * str
String representing the limit being used.
Definition: gui.h:55
mutt_check_simple
void mutt_check_simple(struct Buffer *buf, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:111
mutt_buffer_is_empty
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
mutt_buffer_dealloc
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
Body
The body of an email.
Definition: body.h:34
Context::vsize
off_t vsize
Size (in bytes) of the messages shown.
Definition: context.h:40
mutt_pattern_exec
int mutt_pattern_exec(struct Pattern *pat, PatternExecFlags flags, struct Mailbox *m, struct Email *e, struct PatternCache *cache)
Match a pattern against an email header.
Definition: exec.c:738
Email::num_hidden
size_t num_hidden
Number of hidden messages in this view (only valid when collapsed is set)
Definition: email.h:75
mutt_buffer_init
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
AliasView::is_visible
bool is_visible
Is visible?
Definition: gui.h:44
FREE
#define FREE(x)
Definition: memory.h:40
MUTT_MATCH_FULL_ADDRESS
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: lib.h:99
mutt_file_expand_fmt
void mutt_file_expand_fmt(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1447
ARRAY_SIZE
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:83
RANGE_BARE_RX
#define RANGE_BARE_RX
Definition: private.h:102
mutt_buffer_reset
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
RANGE_K_REL
@ RANGE_K_REL
Relative range.
Definition: private.h:79
mutt_buffer_pool_release
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
RANGE_ABS_RX
#define RANGE_ABS_RX
Definition: private.h:95
MUTT_LIMIT
@ MUTT_LIMIT
Messages in limited view.
Definition: mutt.h:105
ARRAY_GET
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
Mailbox::vcount
int vcount
The number of virtual messages.
Definition: mailbox.h:102
LastSearch
static char LastSearch[256]
last pattern searched for
Definition: pattern.c:85
AliasView
GUI data wrapping an Alias.
Definition: gui.h:36
mutt_istr_equal
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
MuttThread::parent
struct MuttThread * parent
Parent of this Thread.
Definition: thread.h:45
mutt_str_equal
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
mutt_progress_init
void mutt_progress_init(struct Progress *progress, const char *msg, enum ProgressType type, size_t size)
Set up a progress bar.
Definition: progress.c:153
MUTT_PURGE
@ MUTT_PURGE
Messages to be purged (bypass trash)
Definition: mutt.h:100
mutt_buffer_addch
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
AliasMenuData::ava
struct AliasViewArray ava
Array of AliasView.
Definition: gui.h:57
mutt_buffer_pool_get
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
Mailbox::type
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
ARRAY_FOREACH
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
Email::visible
bool visible
Is this message part of the view?
Definition: email.h:74
MUTT_UNDELETE
@ MUTT_UNDELETE
Messages to be un-deleted.
Definition: mutt.h:99
Progress
A progress bar.
Definition: progress.h:50
Body::length
LOFF_T length
length (in bytes) of attachment
Definition: body.h:45
RANGE_K_ABS
@ RANGE_K_ABS
Absolute range.
Definition: private.h:80
Mailbox::msg_count
int msg_count
Total number of messages.
Definition: mailbox.h:91
AliasView::is_searched
bool is_searched
Alias has been searched.
Definition: gui.h:40
mutt_clear_error
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
MUTT_PC_FULL_MSG
#define MUTT_PC_FULL_MSG
Enable body and header matching.
Definition: lib.h:65
MUTT_IMAP
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:53
MUTT_PROGRESS_READ
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
Definition: progress.h:42
Context::mailbox
struct Mailbox * mailbox
Definition: context.h:50
RANGE_K_BARE
@ RANGE_K_BARE
Single symbol.
Definition: private.h:83
MuttThread
An Email conversation.
Definition: thread.h:34
RANGE_GT_RX
#define RANGE_GT_RX
Definition: private.h:99
Menu::title
const char * title
Title of this menu.
Definition: mutt_menu.h:54
Context::collapsed
bool collapsed
Are all threads collapsed?
Definition: context.h:48
top_of_thread
static struct MuttThread * top_of_thread(struct Email *e)
Find the first email in the current thread.
Definition: pattern.c:170
MUTT_UNTAG
@ MUTT_UNTAG
Messages to be un-tagged.
Definition: mutt.h:104
LastSearchExpn
static char LastSearchExpn[1024]
expanded version of LastSearch
Definition: pattern.c:86
mutt_buffer_get_field
int mutt_buffer_get_field(const char *field, struct Buffer *buf, CompletionFlags complete, bool multiple, struct Mailbox *m, char ***files, int *numfiles)
Ask the user for a string.
Definition: curs_lib.c:260
pbuf
static unsigned char * pbuf
Cache PGP data packet.
Definition: pgppacket.c:38
mutt_buffer_string
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
MUTT_ALIAS_SIMPLESEARCH
#define MUTT_ALIAS_SIMPLESEARCH
Definition: lib.h:58
Email::collapsed
bool collapsed
Is this message part of a collapsed thread?
Definition: email.h:73
SLIST_FIRST
#define SLIST_FIRST(head)
Definition: queue.h:228
C_SimpleSearch
WHERE char * C_SimpleSearch
Config: Pattern to search for when search doesn't contain ~'s.
Definition: mutt_globals.h:107
mutt_str_replace
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
Context::limit_pattern
struct PatternList * limit_pattern
Compiled limit pattern.
Definition: context.h:42
MUTT_DELETE
@ MUTT_DELETE
Messages to be deleted.
Definition: mutt.h:98
Menu::mdata
void * mdata
Extra data for the current menu.
Definition: mutt_menu.h:55
menu_create_alias_title
char * menu_create_alias_title(char *menu_name, char *limit)
Create a title string for the Menu.
Definition: gui.c:84
mutt_mem_malloc
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
OptSearchInvalid
WHERE bool OptSearchInvalid
(pseudo) used to invalidate the search pattern
Definition: options.h:52
Menu::max
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MUTT_TAG
@ MUTT_TAG
Tagged messages.
Definition: mutt.h:103
C_WrapSearch
WHERE bool C_WrapSearch
Config: Wrap around when the search hits the end.
Definition: mutt_globals.h:170
AliasMenuData
AliasMenuData - AliasView array wrapper with Pattern information.
Definition: gui.h:53
RANGE_LT_RX
#define RANGE_LT_RX
Definition: private.h:98
Email::searched
bool searched
Email has been searched.
Definition: email.h:67
Email::vnum
int vnum
Virtual message number.
Definition: email.h:88
RANGE_K_LT
@ RANGE_K_LT
Less-than range.
Definition: private.h:81
mutt_pattern_alias_exec
int mutt_pattern_alias_exec(struct Pattern *pat, PatternExecFlags flags, struct AliasView *av, struct PatternCache *cache)
Match a pattern against an alias.
Definition: exec.c:1041
MUTT_CLEAR
#define MUTT_CLEAR
Clear input if printable character is pressed.
Definition: mutt.h:62
mutt_progress_update
void mutt_progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition: progress.c:212
Context::pattern
char * pattern
Limit pattern string.
Definition: context.h:41
mutt_get_field
int mutt_get_field(const char *field, char *buf, size_t buflen, CompletionFlags complete, bool multiple, char ***files, int *numfiles)
Ask the user for a string.
Definition: curs_lib.c:311
mutt_buffer_strdup
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:432
RANGE_K_GT
@ RANGE_K_GT
Greater-than range.
Definition: private.h:82
Menu::current
int current
Current entry.
Definition: mutt_menu.h:56
RANGE_REL_RX
#define RANGE_REL_RX
Definition: private.h:91
Buffer::data
char * data
Pointer to data.
Definition: buffer.h:35
Email
The envelope/body of an email.
Definition: email.h:37
mutt_message
#define mutt_message(...)
Definition: logging.h:83
mutt_set_flag
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:67
OptSearchReverse
WHERE bool OptSearchReverse
(pseudo) used by ci_search_command
Definition: options.h:53
SearchPattern
static struct PatternList * SearchPattern
current search pattern
Definition: pattern.c:84
mx_msg_padding_size
int mx_msg_padding_size(struct Mailbox *m)
Bytes of padding between messages - Wrapper for MxOps::msg_padding_size()
Definition: mx.c:1554
mutt_buffer_make
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
mutt_buffer_strcpy
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Email::body
struct Body * body
List of MIME parts.
Definition: email.h:91
mutt_error
#define mutt_error(...)
Definition: logging.h:84
mutt_str_copy
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:716