X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=score.cpkg;h=1495ed8b0100bc785496dc4132c952d5e36b1cf2;hp=2b53377cc22d3dd4d93e0bfccb167ba9e7655d0f;hb=819c071fa7efc8dffb4dd92f36f0111227ff692f;hpb=3a6261dd05abe2c2c3da12f6c337a397f612ceac diff --git a/score.cpkg b/score.cpkg index 2b53377..1495ed8 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_read) + _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: */