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.
14 #include <lib-lib/lib-lib.h>
22 typedef struct score_t {
26 int exact; /* if this rule matches, don't evaluate any more */
32 void mutt_check_rescore (CONTEXT * ctx)
36 if (option (OPTNEEDRESCORE) && option (OPTSCORE)) {
37 if ((Sort & SORT_MASK) == SORT_SCORE ||
38 (SortAux & SORT_MASK) == SORT_SCORE) {
39 set_option (OPTNEEDRESORT);
40 if ((Sort & SORT_MASK) == SORT_THREADS)
41 set_option (OPTSORTSUBTHREADS);
44 /* must redraw the index since the user might have %N in it */
45 set_option (OPTFORCEREDRAWINDEX);
46 set_option (OPTFORCEREDRAWPAGER);
48 for (i = 0; ctx && i < ctx->msgcount; i++) {
49 mutt_score_message (ctx, ctx->hdrs[i], 1);
50 ctx->hdrs[i]->pair = 0;
53 unset_option (OPTNEEDRESCORE);
56 int mutt_parse_score (BUFFER * buf, BUFFER * s, unsigned long data,
61 struct pattern_t *pat;
63 mutt_extract_token (buf, s, 0);
65 m_strcpy(err->data, err->dsize, _("score: too few arguments"));
70 mutt_extract_token (buf, s, 0);
73 m_strcpy(err->data, err->dsize, _("score: too many arguments"));
77 /* look for an existing entry and update the value, else add it to the end
79 for (ptr = Score, last = NULL; ptr; last = ptr, ptr = ptr->next)
80 if (m_strcmp(pattern, ptr->str) == 0)
83 if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL) {
87 ptr = p_new(SCORE, 1);
100 ptr->val = atoi (pc);
101 set_option (OPTNEEDRESCORE);
105 void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
109 hdr->score = 0; /* in case of re-scoring */
110 for (tmp = Score; tmp; tmp = tmp->next) {
111 if (mutt_pattern_exec (tmp->pat, M_MATCH_FULL_ADDRESS, NULL, hdr) > 0) {
112 if (tmp->exact || tmp->val == 9999 || tmp->val == -9999) {
113 hdr->score = tmp->val;
116 hdr->score += tmp->val;
122 if (hdr->score <= ScoreThresholdDelete)
123 _mutt_set_flag (ctx, hdr, M_DELETE, 1, upd_ctx);
124 if (hdr->score <= ScoreThresholdRead)
125 _mutt_set_flag (ctx, hdr, M_READ, 1, upd_ctx);
126 if (hdr->score >= ScoreThresholdFlag)
127 _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
130 int mutt_parse_unscore (BUFFER * buf, BUFFER * s, unsigned long data,
133 SCORE *tmp, *last = NULL;
135 while (MoreArgs (s)) {
136 mutt_extract_token (buf, s, 0);
137 if (!m_strcmp("*", buf->data)) {
138 for (tmp = Score; tmp;) {
141 mutt_pattern_free (&last->pat);
147 for (tmp = Score; tmp; last = tmp, tmp = tmp->next) {
148 if (!m_strcmp(buf->data, tmp->str)) {
150 last->next = tmp->next;
153 mutt_pattern_free (&tmp->pat);
155 /* there should only be one score per pattern, so we can stop here */
161 set_option (OPTNEEDRESCORE);