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/mem.h>
26 typedef struct score_t {
30 int exact; /* if this rule matches, don't evaluate any more */
36 void mutt_check_rescore (CONTEXT * ctx)
40 if (option (OPTNEEDRESCORE) && option (OPTSCORE)) {
41 if ((Sort & SORT_MASK) == SORT_SCORE ||
42 (SortAux & SORT_MASK) == SORT_SCORE) {
43 set_option (OPTNEEDRESORT);
44 if ((Sort & SORT_MASK) == SORT_THREADS)
45 set_option (OPTSORTSUBTHREADS);
48 /* must redraw the index since the user might have %N in it */
49 set_option (OPTFORCEREDRAWINDEX);
50 set_option (OPTFORCEREDRAWPAGER);
52 for (i = 0; ctx && i < ctx->msgcount; i++) {
53 mutt_score_message (ctx, ctx->hdrs[i], 1);
54 ctx->hdrs[i]->pair = 0;
57 unset_option (OPTNEEDRESCORE);
60 int mutt_parse_score (BUFFER * buf, BUFFER * s, unsigned long data,
65 struct pattern_t *pat;
67 mutt_extract_token (buf, s, 0);
69 strfcpy (err->data, _("score: too few arguments"), err->dsize);
73 memset (buf, 0, sizeof (BUFFER));
74 mutt_extract_token (buf, s, 0);
77 strfcpy (err->data, _("score: too many arguments"), err->dsize);
81 /* look for an existing entry and update the value, else add it to the end
83 for (ptr = Score, last = NULL; ptr; last = ptr, ptr = ptr->next)
84 if (str_cmp (pattern, ptr->str) == 0)
87 if ((pat = mutt_pattern_comp (pattern, 0, err)) == NULL) {
91 ptr = p_new(SCORE, 1);
104 ptr->val = atoi (pc);
105 set_option (OPTNEEDRESCORE);
109 void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
113 hdr->score = 0; /* in case of re-scoring */
114 for (tmp = Score; tmp; tmp = tmp->next) {
115 if (mutt_pattern_exec (tmp->pat, M_MATCH_FULL_ADDRESS, NULL, hdr) > 0) {
116 if (tmp->exact || tmp->val == 9999 || tmp->val == -9999) {
117 hdr->score = tmp->val;
120 hdr->score += tmp->val;
126 if (hdr->score <= ScoreThresholdDelete)
127 _mutt_set_flag (ctx, hdr, M_DELETE, 1, upd_ctx);
128 if (hdr->score <= ScoreThresholdRead)
129 _mutt_set_flag (ctx, hdr, M_READ, 1, upd_ctx);
130 if (hdr->score >= ScoreThresholdFlag)
131 _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
134 int mutt_parse_unscore (BUFFER * buf, BUFFER * s, unsigned long data,
137 SCORE *tmp, *last = NULL;
139 while (MoreArgs (s)) {
140 mutt_extract_token (buf, s, 0);
141 if (!str_cmp ("*", buf->data)) {
142 for (tmp = Score; tmp;) {
145 mutt_pattern_free (&last->pat);
151 for (tmp = Score; tmp; last = tmp, tmp = tmp->next) {
152 if (!str_cmp (buf->data, tmp->str)) {
154 last->next = tmp->next;
157 mutt_pattern_free (&tmp->pat);
159 /* there should only be one score per pattern, so we can stop here */
165 set_option (OPTNEEDRESCORE);