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, unsigned long data,
54 struct pattern_t *pat;
56 mutt_extract_token (buf, s, 0);
58 m_strcpy(err->data, err->dsize, _("score: too few arguments"));
63 mutt_extract_token (buf, s, 0);
66 m_strcpy(err->data, err->dsize, _("score: too many arguments"));
70 /* look for an existing entry and update the value, else add it to the end
72 for (ptr = Score, last = NULL; ptr; last = ptr, ptr = ptr->next)
73 if (m_strcmp(pattern, ptr->str) == 0)
76 if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL) {
80 ptr = p_new(SCORE, 1);
94 set_option (OPTNEEDRESCORE);
98 void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
102 hdr->score = 0; /* in case of re-scoring */
103 for (tmp = Score; tmp; tmp = tmp->next) {
104 if (mutt_pattern_exec (tmp->pat, M_MATCH_FULL_ADDRESS, NULL, hdr) > 0) {
105 if (tmp->exact || tmp->val == 9999 || tmp->val == -9999) {
106 hdr->score = tmp->val;
109 hdr->score += tmp->val;
115 if (hdr->score <= ScoreThresholdDelete)
116 _mutt_set_flag (ctx, hdr, M_DELETE, 1, upd_ctx);
117 if (hdr->score <= ScoreThresholdRead)
118 _mutt_set_flag (ctx, hdr, M_READ, 1, upd_ctx);
119 if (hdr->score >= ScoreThresholdFlag)
120 _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
123 int mutt_parse_unscore (BUFFER * buf, BUFFER * s, unsigned long data,
126 SCORE *tmp, *last = NULL;
128 while (MoreArgs (s)) {
129 mutt_extract_token (buf, s, 0);
130 if (!m_strcmp("*", buf->data)) {
131 for (tmp = Score; tmp;) {
134 mutt_pattern_free (&last->pat);
140 for (tmp = Score; tmp; last = tmp, tmp = tmp->next) {
141 if (!m_strcmp(buf->data, tmp->str)) {
143 last->next = tmp->next;
146 mutt_pattern_free (&tmp->pat);
148 /* there should only be one score per pattern, so we can stop here */
154 set_option (OPTNEEDRESCORE);