Update to latest madtty.
[apps/madmutt.git] / score.cpkg
index 2b53377..1495ed8 100644 (file)
 @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: */