X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..1bab28984d8d360498fe316bf13187c907273b47:/pattern.c?ds=sidebyside diff --git a/pattern.c b/pattern.c index 089499d..489a1d0 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 @@ -46,7 +46,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 +97,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 +118,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) { @@ -193,9 +180,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 +242,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno) if (option (OPTTHOROUGHSRC)) { - fclose (fp); + safe_fclose (&fp); unlink (tempfile); } } @@ -263,7 +250,7 @@ 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; int r; @@ -290,6 +277,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) @@ -713,7 +701,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 @@ -1166,7 +1155,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, @@ -1411,15 +1401,16 @@ int mutt_search_command (int cur, int op) 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); @@ -1430,7 +1421,7 @@ int mutt_search_command (int cur, int op) mutt_check_simple (temp, sizeof (temp), NONULL (SimpleSearch)); if (!SearchPattern || mutt_strcmp (temp, LastSearchExpn)) - { + { set_option (OPTSEARCHINVALID); strfcpy (LastSearch, buf, sizeof (LastSearch)); mutt_message _("Compiling search pattern..."); @@ -1438,18 +1429,13 @@ int mutt_search_command (int cur, int op) err.data = error; err.dsize = sizeof (error); if ((SearchPattern = mutt_pattern_comp (temp, M_FULL_MSG, &err)) == NULL) - { + { mutt_error ("%s", error); return (-1); } mutt_clear_error (); } } - else if (!SearchPattern) - { - mutt_error _("No search pattern."); - return (-1); - } if (option (OPTSEARCHINVALID)) {