X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..1f4d55392f3d7e8b03c8c0cee62a38c58650458e:/pattern.c?ds=inline diff --git a/pattern.c b/pattern.c index 089499d..dbd73bd 100644 --- a/pattern.c +++ b/pattern.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1996-2000,2006 Michael R. Elkins , and others + * Copyright (C) 1996-2000,2006-7 Michael R. Elkins , and others * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,6 +35,7 @@ #include "mutt_crypt.h" #include "mutt_curses.h" +#include "group.h" #ifdef USE_IMAP #include "mx.h" @@ -46,7 +47,7 @@ static int eat_date (pattern_t *pat, BUFFER *, BUFFER *); static int eat_range (pattern_t *pat, BUFFER *, BUFFER *); static int patmatch (const pattern_t *pat, const char *buf); -struct pattern_flags +static struct pattern_flags { int tag; /* character used to represent this op */ int op; /* operation to perform */ @@ -97,7 +98,7 @@ Flags[] = { 'z', M_SIZE, 0, eat_range }, { '=', M_DUPLICATED, 0, NULL }, { '$', M_UNREFERENCED, 0, NULL }, - { 0 } + { 0, 0, 0, NULL } }; static pattern_t *SearchPattern = NULL; /* current search pattern */ @@ -118,19 +119,6 @@ static char LastSearchExpn[LONG_STRING] = { 0 }; /* expanded version of #define M_PDR_ERRORDONE (M_PDR_ERROR | M_PDR_DONE) -int mutt_getvaluebychar (char ch, struct mapping_t *table) -{ - int i; - - for (i = 0; table[i].name; i++) - { - if (ch == table[i].name[0]) - return table[i].value; - } - - return (-1); -} - /* if no uppercase letters are given, do a case-insensitive search */ int mutt_which_case (const char *s) { @@ -175,7 +163,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno) memset (&s, 0, sizeof (s)); s.fpin = msg->fp; s.flags = M_CHARCONV; - mutt_mktemp (tempfile); + mutt_mktemp (tempfile, sizeof (tempfile)); if ((s.fpout = safe_fopen (tempfile, "w+")) == NULL) { mutt_perror (tempfile); @@ -193,9 +181,9 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno) && !crypt_valid_passphrase(h->security)) { mx_close_message (&msg); - if (fp) + if (s.fpout) { - fclose (fp); + safe_fclose (&s.fpout); unlink (tempfile); } return (0); @@ -255,7 +243,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno) if (option (OPTTHOROUGHSRC)) { - fclose (fp); + safe_fclose (&fp); unlink (tempfile); } } @@ -263,9 +251,10 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno) return match; } -int eat_regexp (pattern_t *pat, BUFFER *s, BUFFER *err) +static int eat_regexp (pattern_t *pat, BUFFER *s, BUFFER *err) { BUFFER buf; + char errmsg[STRING]; int r; memset (&buf, 0, sizeof (buf)); @@ -290,6 +279,7 @@ int eat_regexp (pattern_t *pat, BUFFER *s, BUFFER *err) if (pat->stringmatch) { pat->p.str = safe_strdup (buf.data); + pat->ign_case = mutt_which_case (buf.data) == REG_ICASE; FREE (&buf.data); } else if (pat->groupmatch) @@ -301,14 +291,15 @@ int eat_regexp (pattern_t *pat, BUFFER *s, BUFFER *err) { pat->p.rx = safe_malloc (sizeof (regex_t)); r = REGCOMP (pat->p.rx, buf.data, REG_NEWLINE | REG_NOSUB | mutt_which_case (buf.data)); - FREE (&buf.data); if (r) { - regerror (r, pat->p.rx, err->data, err->dsize); - regfree (pat->p.rx); + regerror (r, pat->p.rx, errmsg, sizeof (errmsg)); + mutt_buffer_printf (err, "'%s': %s", buf.data, errmsg); + FREE (&buf.data); FREE (&pat->p.rx); return (-1); } + FREE (&buf.data); } return 0; @@ -713,7 +704,8 @@ static int eat_date (pattern_t *pat, BUFFER *s, BUFFER *err) static int patmatch (const pattern_t* pat, const char* buf) { if (pat->stringmatch) - return !strstr (buf, pat->p.str); + return pat->ign_case ? !strcasestr (buf, pat->p.str) : + !strstr (buf, pat->p.str); else if (pat->groupmatch) return !mutt_group_match (pat->p.g, buf); else @@ -833,7 +825,13 @@ pattern_t *mutt_pattern_comp (/* const */ char *s, int flags, BUFFER *err) case '%': case '=': case '~': - if (*(ps.dptr + 1) == '(') + if (!*(ps.dptr + 1)) + { + snprintf (err->data, err->dsize, _("missing pattern: %s"), ps.dptr); + mutt_pattern_free (&curlist); + return NULL; + } + if (*(ps.dptr + 1) == '(') { ps.dptr ++; /* skip ~ */ p = find_matching_paren (ps.dptr + 1); @@ -1166,7 +1164,8 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx, case M_SIZE: return (pat->not ^ (h->content->length >= pat->min && (pat->max == M_MAXRANGE || h->content->length <= pat->max))); case M_REFERENCE: - return (pat->not ^ match_reference (pat, h->env->references)); + return (pat->not ^ (match_reference (pat, h->env->references) || + match_reference (pat, h->env->in_reply_to))); case M_ADDRESS: return (pat->not ^ match_adrlist (pat, flags & M_MATCH_FULL_ADDRESS, 4, h->env->from, h->env->sender, @@ -1303,6 +1302,7 @@ int mutt_pattern_func (int op, char *prompt) simple = safe_strdup (buf); mutt_check_simple (buf, sizeof (buf), NONULL (SimpleSearch)); + memset (&err, 0, sizeof(err)); err.data = error; err.dsize = sizeof (error); if ((pat = mutt_pattern_comp (buf, M_FULL_MSG, &err)) == NULL) @@ -1405,21 +1405,21 @@ int mutt_search_command (int cur, int op) char buf[STRING]; char temp[LONG_STRING]; char error[STRING]; - BUFFER err; int incr; HEADER *h; progress_t progress; const char* msg = NULL; - if (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE) + if (!*LastSearch || (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE)) { - strfcpy (buf, LastSearch, sizeof (buf)); - if (mutt_get_field ((op == OP_SEARCH) ? _("Search for: ") : - _("Reverse search for: "), buf, sizeof (buf), + strfcpy (buf, *LastSearch ? LastSearch : "", sizeof (buf)); + if (mutt_get_field ((op == OP_SEARCH || op == OP_SEARCH_NEXT) ? + _("Search for: ") : _("Reverse search for: "), + buf, sizeof (buf), M_CLEAR | M_PATTERN) != 0 || !buf[0]) return (-1); - if (op == OP_SEARCH) + if (op == OP_SEARCH || op == OP_SEARCH_NEXT) unset_option (OPTSEARCHREVERSE); else set_option (OPTSEARCHREVERSE); @@ -1431,6 +1431,8 @@ int mutt_search_command (int cur, int op) if (!SearchPattern || mutt_strcmp (temp, LastSearchExpn)) { + BUFFER err; + memset(&err, 0, sizeof(err)); set_option (OPTSEARCHINVALID); strfcpy (LastSearch, buf, sizeof (LastSearch)); mutt_message _("Compiling search pattern..."); @@ -1440,16 +1442,12 @@ int mutt_search_command (int cur, int op) if ((SearchPattern = mutt_pattern_comp (temp, M_FULL_MSG, &err)) == NULL) { mutt_error ("%s", error); + LastSearch[0] = '\0'; return (-1); } mutt_clear_error (); } } - else if (!SearchPattern) - { - mutt_error _("No search pattern."); - return (-1); - } if (option (OPTSEARCHINVALID)) {