2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
28 typedef struct score_t {
32 int exact; /* if this rule matches, don't evaluate any more */
38 void mutt_check_rescore (CONTEXT * ctx)
42 if (option (OPTNEEDRESCORE) && option (OPTSCORE)) {
43 if ((Sort & SORT_MASK) == SORT_SCORE ||
44 (SortAux & SORT_MASK) == SORT_SCORE) {
45 set_option (OPTNEEDRESORT);
46 if ((Sort & SORT_MASK) == SORT_THREADS)
47 set_option (OPTSORTSUBTHREADS);
50 /* must redraw the index since the user might have %N in it */
51 set_option (OPTFORCEREDRAWINDEX);
52 set_option (OPTFORCEREDRAWPAGER);
54 for (i = 0; ctx && i < ctx->msgcount; i++) {
55 mutt_score_message (ctx, ctx->hdrs[i], 1);
56 ctx->hdrs[i]->pair = 0;
59 unset_option (OPTNEEDRESCORE);
62 int mutt_parse_score (BUFFER * buf, BUFFER * s, unsigned long data,
67 struct pattern_t *pat;
69 mutt_extract_token (buf, s, 0);
71 strfcpy (err->data, _("score: too few arguments"), err->dsize);
75 memset (buf, 0, sizeof (BUFFER));
76 mutt_extract_token (buf, s, 0);
79 strfcpy (err->data, _("score: too many arguments"), err->dsize);
83 /* look for an existing entry and update the value, else add it to the end
85 for (ptr = Score, last = NULL; ptr; last = ptr, ptr = ptr->next)
86 if (mutt_strcmp (pattern, ptr->str) == 0)
89 if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL) {
93 ptr = safe_calloc (1, sizeof (SCORE));
106 ptr->val = atoi (pc);
107 set_option (OPTNEEDRESCORE);
111 void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
115 hdr->score = 0; /* in case of re-scoring */
116 for (tmp = Score; tmp; tmp = tmp->next) {
117 if (mutt_pattern_exec (tmp->pat, 0, NULL, hdr) > 0) {
118 if (tmp->exact || tmp->val == 9999 || tmp->val == -9999) {
119 hdr->score = tmp->val;
122 hdr->score += tmp->val;
128 if (hdr->score <= ScoreThresholdDelete)
129 _mutt_set_flag (ctx, hdr, M_DELETE, 1, upd_ctx);
130 if (hdr->score <= ScoreThresholdRead)
131 _mutt_set_flag (ctx, hdr, M_READ, 1, upd_ctx);
132 if (hdr->score >= ScoreThresholdFlag)
133 _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
136 int mutt_parse_unscore (BUFFER * buf, BUFFER * s, unsigned long data,
139 SCORE *tmp, *last = NULL;
141 while (MoreArgs (s)) {
142 mutt_extract_token (buf, s, 0);
143 if (!mutt_strcmp ("*", buf->data)) {
144 for (tmp = Score; tmp;) {
147 mutt_pattern_free (&last->pat);
153 for (tmp = Score; tmp; last = tmp, tmp = tmp->next) {
154 if (!mutt_strcmp (buf->data, tmp->str)) {
156 last->next = tmp->next;
159 mutt_pattern_free (&tmp->pat);
161 /* there should only be one score per pattern, so we can stop here */
167 set_option (OPTNEEDRESCORE);