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>
15 typedef struct score_t {
19 int exact; /* if this rule matches, don't evaluate any more */
25 void mutt_check_rescore (CONTEXT * ctx)
29 if (option (OPTNEEDRESCORE) && option (OPTSCORE)) {
30 if ((Sort & SORT_MASK) == SORT_SCORE ||
31 (SortAux & SORT_MASK) == SORT_SCORE) {
32 set_option (OPTNEEDRESORT);
33 if ((Sort & SORT_MASK) == SORT_THREADS)
34 set_option (OPTSORTSUBTHREADS);
37 /* must redraw the index since the user might have %N in it */
38 set_option (OPTFORCEREDRAWINDEX);
39 set_option (OPTFORCEREDRAWPAGER);
41 for (i = 0; ctx && i < ctx->msgcount; i++) {
42 mutt_score_message (ctx, ctx->hdrs[i], 1);
43 ctx->hdrs[i]->pair = 0;
46 unset_option (OPTNEEDRESCORE);
49 int mutt_parse_score (BUFFER * buf, BUFFER * s,
50 unsigned long data __attribute__ ((unused)),
55 struct pattern_t *pat;
57 mutt_extract_token (buf, s, 0);
59 m_strcpy(err->data, err->dsize, _("score: too few arguments"));
64 mutt_extract_token (buf, s, 0);
67 m_strcpy(err->data, err->dsize, _("score: too many arguments"));
71 /* look for an existing entry and update the value, else add it to the end
73 for (ptr = Score, last = NULL; ptr; last = ptr, ptr = ptr->next)
74 if (m_strcmp(pattern, ptr->str) == 0)
77 if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL) {
81 ptr = p_new(SCORE, 1);
95 set_option (OPTNEEDRESCORE);
99 void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
103 hdr->score = 0; /* in case of re-scoring */
104 for (tmp = Score; tmp; tmp = tmp->next) {
105 if (mutt_pattern_exec (tmp->pat, M_MATCH_FULL_ADDRESS, NULL, hdr) > 0) {
106 if (tmp->exact || tmp->val == 9999 || tmp->val == -9999) {
107 hdr->score = tmp->val;
110 hdr->score += tmp->val;
116 if (hdr->score <= ScoreThresholdDelete)
117 _mutt_set_flag (ctx, hdr, M_DELETE, 1, upd_ctx);
118 if (hdr->score <= ScoreThresholdRead)
119 _mutt_set_flag (ctx, hdr, M_READ, 1, upd_ctx);
120 if (hdr->score >= ScoreThresholdFlag)
121 _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
124 int mutt_parse_unscore (BUFFER * buf, BUFFER * s,
125 unsigned long data __attribute__ ((unused)),
126 BUFFER * err __attribute__ ((unused)))
128 SCORE *tmp, *last = NULL;
130 while (MoreArgs (s)) {
131 mutt_extract_token (buf, s, 0);
132 if (!m_strcmp("*", buf->data)) {
133 for (tmp = Score; tmp;) {
136 mutt_pattern_free (&last->pat);
142 for (tmp = Score; tmp; last = tmp, tmp = tmp->next) {
143 if (!m_strcmp(buf->data, tmp->str)) {
145 last->next = tmp->next;
148 mutt_pattern_free (&tmp->pat);
150 /* there should only be one score per pattern, so we can stop here */
156 set_option (OPTNEEDRESCORE);