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 */
26 void mutt_check_rescore (CONTEXT * ctx)
30 if (option (OPTNEEDRESCORE) && option (OPTSCORE)) {
31 if ((Sort & SORT_MASK) == SORT_SCORE ||
32 (SortAux & SORT_MASK) == SORT_SCORE) {
33 set_option (OPTNEEDRESORT);
34 if ((Sort & SORT_MASK) == SORT_THREADS)
35 set_option (OPTSORTSUBTHREADS);
38 /* must redraw the index since the user might have %N in it */
39 set_option (OPTFORCEREDRAWINDEX);
40 set_option (OPTFORCEREDRAWPAGER);
42 for (i = 0; ctx && i < ctx->msgcount; i++) {
43 mutt_score_message (ctx, ctx->hdrs[i], 1);
44 ctx->hdrs[i]->pair = 0;
47 unset_option (OPTNEEDRESCORE);
50 int mutt_parse_score (BUFFER * buf, BUFFER * s,
51 unsigned long data __attribute__ ((unused)),
56 struct pattern_t *pat;
58 mutt_extract_token (buf, s, 0);
60 m_strcpy(err->data, err->dsize, _("score: too few arguments"));
65 mutt_extract_token (buf, s, 0);
68 m_strcpy(err->data, err->dsize, _("score: too many arguments"));
72 /* look for an existing entry and update the value, else add it to the end
74 for (ptr = Score, last = NULL; ptr; last = ptr, ptr = ptr->next)
75 if (m_strcmp(pattern, ptr->str) == 0)
78 if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL) {
82 ptr = p_new(SCORE, 1);
96 set_option (OPTNEEDRESCORE);
100 void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
104 hdr->score = 0; /* in case of re-scoring */
105 for (tmp = Score; tmp; tmp = tmp->next) {
106 if (mutt_pattern_exec (tmp->pat, M_MATCH_FULL_ADDRESS, NULL, hdr) > 0) {
107 if (tmp->exact || tmp->val == 9999 || tmp->val == -9999) {
108 hdr->score = tmp->val;
111 hdr->score += tmp->val;
117 if (hdr->score <= ScoreThresholdDelete)
118 _mutt_set_flag (ctx, hdr, M_DELETE, 1, upd_ctx);
119 if (hdr->score <= ScoreThresholdRead)
120 _mutt_set_flag (ctx, hdr, M_READ, 1, upd_ctx);
121 if (hdr->score >= ScoreThresholdFlag)
122 _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
125 int mutt_parse_unscore (BUFFER * buf, BUFFER * s,
126 unsigned long data __attribute__ ((unused)),
127 BUFFER * err __attribute__ ((unused)))
129 SCORE *tmp, *last = NULL;
131 while (MoreArgs (s)) {
132 mutt_extract_token (buf, s, 0);
133 if (!m_strcmp("*", buf->data)) {
134 for (tmp = Score; tmp;) {
137 pattern_list_wipe(&last->pat);
143 for (tmp = Score; tmp; last = tmp, tmp = tmp->next) {
144 if (!m_strcmp(buf->data, tmp->str)) {
146 last->next = tmp->next;
149 pattern_list_wipe(&tmp->pat);
151 /* there should only be one score per pattern, so we can stop here */
157 set_option (OPTNEEDRESCORE);