From: Pierre Habouzit Date: Sat, 19 May 2007 13:51:58 +0000 (+0200) Subject: finish rework of scoring module. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=2e493cf01fc8eae92379422a36400523bba61dd3;p=apps%2Fmadmutt.git finish rework of scoring module. Signed-off-by: Pierre Habouzit --- diff --git a/score.cpkg b/score.cpkg index 2b53377..c6c9f0b 100644 --- a/score.cpkg +++ b/score.cpkg @@ -16,11 +16,11 @@ @import "lib-lua/base.cpkg" typedef struct score_t { - char *str; - pattern_t *pat; - int val; - int exact; /* if this rule matches, don't evaluate any more */ - struct score_t *next; + char *str; + pattern_t *pat; + int val; + int exact; /* if this rule matches, don't evaluate any more */ + struct score_t *next; } score_t; DO_INIT(score_t, score); static void score_wipe(score_t *sc) @@ -111,53 +111,48 @@ static score_t *Score = NULL; }; }; -void mutt_check_rescore (CONTEXT * ctx) +void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx) { - int i; - - if (option (OPTNEEDRESCORE) && mod_score.enable) { - if ((Sort & SORT_MASK) == SORT_SCORE || - (SortAux & SORT_MASK) == SORT_SCORE) { - set_option (OPTNEEDRESORT); - if ((Sort & SORT_MASK) == SORT_THREADS) - set_option (OPTSORTSUBTHREADS); - } - - /* must redraw the index since the user might have %N in it */ - set_option (OPTFORCEREDRAWINDEX); - set_option (OPTFORCEREDRAWPAGER); - - for (i = 0; ctx && i < ctx->msgcount; i++) { - mutt_score_message (ctx, ctx->hdrs[i], 1); - ctx->hdrs[i]->pair = 0; + hdr->score = 0; /* in case of re-scoring */ + for (score_t *tmp = Score; tmp; tmp = tmp->next) { + if (mutt_pattern_exec (tmp->pat, M_MATCH_FULL_ADDRESS, NULL, hdr) > 0) { + if (tmp->exact || tmp->val == 9999 || tmp->val == -9999) { + hdr->score = tmp->val; + break; + } + hdr->score += tmp->val; + } } - } - unset_option (OPTNEEDRESCORE); + if (hdr->score < 0) + hdr->score = 0; + + if (hdr->score <= mod_score.threshold_delete) + _mutt_set_flag(ctx, hdr, M_DELETE, 1, upd_ctx); + if (hdr->score <= mod_score.threshold_flag) + _mutt_set_flag(ctx, hdr, M_READ, 1, upd_ctx); + if (hdr->score >= mod_score.threshold_flag) + _mutt_set_flag(ctx, hdr, M_FLAG, 1, upd_ctx); } -void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx) +void mutt_check_rescore (CONTEXT * ctx) { - score_t *tmp; + if (option(OPTNEEDRESCORE) && mod_score.enable) { + if (((Sort | SortAux) & SORT_MASK) == SORT_SCORE) { + set_option(OPTNEEDRESORT); + if ((Sort & SORT_MASK) == SORT_THREADS) + set_option(OPTSORTSUBTHREADS); + } - hdr->score = 0; /* in case of re-scoring */ - for (tmp = Score; tmp; tmp = tmp->next) { - if (mutt_pattern_exec (tmp->pat, M_MATCH_FULL_ADDRESS, NULL, hdr) > 0) { - if (tmp->exact || tmp->val == 9999 || tmp->val == -9999) { - hdr->score = tmp->val; - break; - } - hdr->score += tmp->val; - } - } - if (hdr->score < 0) - hdr->score = 0; + /* must redraw the index since the user might have %N in it */ + set_option(OPTFORCEREDRAWINDEX); + set_option(OPTFORCEREDRAWPAGER); - if (hdr->score <= mod_score.threshold_delete) - _mutt_set_flag (ctx, hdr, M_DELETE, 1, upd_ctx); - if (hdr->score <= mod_score.threshold_flag) - _mutt_set_flag (ctx, hdr, M_READ, 1, upd_ctx); - if (hdr->score >= mod_score.threshold_flag) - _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx); + for (int i = 0; ctx && i < ctx->msgcount; i++) { + mutt_score_message(ctx, ctx->hdrs[i], 1); + ctx->hdrs[i]->pair = 0; + } + } + unset_option(OPTNEEDRESCORE); } /* vim:set ft=c: */