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.
10 #include <lib-lib/lib-lib.h>
16 typedef struct score_t {
20 int exact; /* if this rule matches, don't evaluate any more */
24 score_t *Score = NULL;
26 DO_INIT(score_t, score);
27 static void score_wipe(score_t *sc)
29 pattern_list_wipe(&sc->pat);
32 DO_NEW(score_t, score);
33 DO_DELETE(score_t, score);
35 DO_SLIST(score_t, score, score_delete);
37 void mutt_check_rescore (CONTEXT * ctx)
41 if (option (OPTNEEDRESCORE) && option (OPTSCORE)) {
42 if ((Sort & SORT_MASK) == SORT_SCORE ||
43 (SortAux & SORT_MASK) == SORT_SCORE) {
44 set_option (OPTNEEDRESORT);
45 if ((Sort & SORT_MASK) == SORT_THREADS)
46 set_option (OPTSORTSUBTHREADS);
49 /* must redraw the index since the user might have %N in it */
50 set_option (OPTFORCEREDRAWINDEX);
51 set_option (OPTFORCEREDRAWPAGER);
53 for (i = 0; ctx && i < ctx->msgcount; i++) {
54 mutt_score_message (ctx, ctx->hdrs[i], 1);
55 ctx->hdrs[i]->pair = 0;
58 unset_option (OPTNEEDRESCORE);
61 int mutt_parse_score (BUFFER * buf, BUFFER * s,
62 unsigned long data __attribute__ ((unused)),
66 struct pattern_t *pat;
69 mutt_extract_token (buf, s, 0);
71 m_strcpy(err->data, err->dsize, _("score: too few arguments"));
76 mutt_extract_token (buf, s, 0);
79 m_strcpy(err->data, err->dsize, _("score: too many arguments"));
83 /* look for an existing entry and update the value, else add it to the end
85 for (last = &Score; *last; last = &(*last)->next) {
86 if (m_strcmp(pattern, (*last)->str) == 0)
90 if (!(pat = mutt_pattern_comp(pattern, 0, err))) {
96 (*last)->str = pattern;
103 (*last)->val = atoi(pc);
104 set_option(OPTNEEDRESCORE);
108 void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
112 hdr->score = 0; /* in case of re-scoring */
113 for (tmp = Score; tmp; tmp = tmp->next) {
114 if (mutt_pattern_exec (tmp->pat, M_MATCH_FULL_ADDRESS, NULL, hdr) > 0) {
115 if (tmp->exact || tmp->val == 9999 || tmp->val == -9999) {
116 hdr->score = tmp->val;
119 hdr->score += tmp->val;
125 if (hdr->score <= ScoreThresholdDelete)
126 _mutt_set_flag (ctx, hdr, M_DELETE, 1, upd_ctx);
127 if (hdr->score <= ScoreThresholdRead)
128 _mutt_set_flag (ctx, hdr, M_READ, 1, upd_ctx);
129 if (hdr->score >= ScoreThresholdFlag)
130 _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
133 int mutt_parse_unscore(BUFFER * buf, BUFFER * s,
134 unsigned long data __attribute__ ((unused)),
135 BUFFER * err __attribute__ ((unused)))
137 while (MoreArgs(s)) {
138 mutt_extract_token(buf, s, 0);
139 if (!m_strcmp("*", buf->data)) {
140 score_list_wipe(&Score);
144 for (last = &Score; *last; last = &(*last)->next) {
145 if (!m_strcmp(buf->data, (*last)->str)) {
146 score_t *tmp = score_list_pop(last);
153 set_option (OPTNEEDRESCORE);