2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
23 typedef struct score_t {
27 int exact; /* if this rule matches, don't evaluate any more */
33 void mutt_check_rescore (CONTEXT * ctx)
37 if (option (OPTNEEDRESCORE) && option (OPTSCORE)) {
38 if ((Sort & SORT_MASK) == SORT_SCORE ||
39 (SortAux & SORT_MASK) == SORT_SCORE) {
40 set_option (OPTNEEDRESORT);
41 if ((Sort & SORT_MASK) == SORT_THREADS)
42 set_option (OPTSORTSUBTHREADS);
45 /* must redraw the index since the user might have %N in it */
46 set_option (OPTFORCEREDRAWINDEX);
47 set_option (OPTFORCEREDRAWPAGER);
49 for (i = 0; ctx && i < ctx->msgcount; i++) {
50 mutt_score_message (ctx, ctx->hdrs[i], 1);
51 ctx->hdrs[i]->pair = 0;
54 unset_option (OPTNEEDRESCORE);
57 int mutt_parse_score (BUFFER * buf, BUFFER * s, unsigned long data,
62 struct pattern_t *pat;
64 mutt_extract_token (buf, s, 0);
66 strfcpy (err->data, _("score: too few arguments"), err->dsize);
70 memset (buf, 0, sizeof (BUFFER));
71 mutt_extract_token (buf, s, 0);
74 strfcpy (err->data, _("score: too many arguments"), err->dsize);
78 /* look for an existing entry and update the value, else add it to the end
80 for (ptr = Score, last = NULL; ptr; last = ptr, ptr = ptr->next)
81 if (safe_strcmp (pattern, ptr->str) == 0)
84 if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL) {
88 ptr = safe_calloc (1, sizeof (SCORE));
101 ptr->val = atoi (pc);
102 set_option (OPTNEEDRESCORE);
106 void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
110 hdr->score = 0; /* in case of re-scoring */
111 for (tmp = Score; tmp; tmp = tmp->next) {
112 if (mutt_pattern_exec (tmp->pat, 0, NULL, hdr) > 0) {
113 if (tmp->exact || tmp->val == 9999 || tmp->val == -9999) {
114 hdr->score = tmp->val;
117 hdr->score += tmp->val;
123 if (hdr->score <= ScoreThresholdDelete)
124 _mutt_set_flag (ctx, hdr, M_DELETE, 1, upd_ctx);
125 if (hdr->score <= ScoreThresholdRead)
126 _mutt_set_flag (ctx, hdr, M_READ, 1, upd_ctx);
127 if (hdr->score >= ScoreThresholdFlag)
128 _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
131 int mutt_parse_unscore (BUFFER * buf, BUFFER * s, unsigned long data,
134 SCORE *tmp, *last = NULL;
136 while (MoreArgs (s)) {
137 mutt_extract_token (buf, s, 0);
138 if (!safe_strcmp ("*", buf->data)) {
139 for (tmp = Score; tmp;) {
142 mutt_pattern_free (&last->pat);
148 for (tmp = Score; tmp; last = tmp, tmp = tmp->next) {
149 if (!safe_strcmp (buf->data, tmp->str)) {
151 last->next = tmp->next;
154 mutt_pattern_free (&tmp->pat);
156 /* there should only be one score per pattern, so we can stop here */
162 set_option (OPTNEEDRESCORE);