#include "sort.h"
#include "mutt.h"
-#include "score.h"
#ifndef _MAKEDOC
#define DT_MASK 0x0f
{"macro", mutt_parse_macro, 0},
{"mono", mutt_parse_mono, 0},
{"push", mutt_parse_push, 0},
- {"score", mutt_parse_score, 0},
{"uncolor", mutt_parse_uncolor, 0},
{"unhook", mutt_parse_unhook, 0},
{"unmono", mutt_parse_unmono, 0},
- {"unscore", mutt_parse_unscore, 0},
{"alias", parse_alias, 0},
{"attachments", parse_attachments, 0 },
{"my_hdr", parse_my_hdr, 0},
#include "score.h"
@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;
+} score_t;
+DO_INIT(score_t, score);
+static void score_wipe(score_t *sc)
+{
+ pattern_list_wipe(&sc->pat);
+ p_delete(&sc->str);
+}
+DO_NEW(score_t, score);
+DO_DELETE(score_t, score);
+DO_SLIST(score_t, score, score_delete);
+
+static score_t *Score = NULL;
+
@package mod_score {
bool enable = 1;
/*
** Madmutt scores are always greater than or equal to zero, the default setting
** of this variable will never mark a message read.
*/
-};
-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;
-} score_t;
-DO_INIT(score_t, score);
-static void score_wipe(score_t *sc)
-{
- pattern_list_wipe(&sc->pat);
- p_delete(&sc->str);
-}
-DO_NEW(score_t, score);
-DO_DELETE(score_t, score);
-DO_SLIST(score_t, score, score_delete);
+ void score(string_t pattern, int value) {
+ const char *pc;
+ score_t **last;
-static score_t *Score = NULL;
+ for (last = &Score; *last; last = &(*last)->next) {
+ if (!m_strcmp(pattern, (*last)->str))
+ break;
+ }
+ if (!*last) {
+ /* FIXME need a buffer for error */
+ struct pattern_t *pat = mutt_pattern_comp(pattern, 0, NULL);
+
+ if (!pat) {
+ p_delete(&pattern);
+ RETURN();
+ }
+ *last = score_new();
+ (*last)->pat = pat;
+ (*last)->str = pattern;
+ }
+ pc = pattern;
+ pc += (*last)->exact = (*pc == '=');
+ (*last)->val = value;
+ set_option(OPTNEEDRESCORE);
+ RETURN();
+ };
+
+ void unscore(const string_t pattern) {
+ if (!m_strcmp(pattern, "*")) {
+ score_list_wipe(&Score);
+ set_option(OPTNEEDRESCORE);
+ RETURN();
+ }
+ for (score_t **last = &Score; *last; last = &(*last)->next) {
+ if (!m_strcmp(pattern, (*last)->str)) {
+ score_t *tmp = score_list_pop(last);
+ score_delete(&tmp);
+ set_option(OPTNEEDRESCORE);
+ break;
+ }
+ }
+ RETURN();
+ };
+};
void mutt_check_rescore (CONTEXT * ctx)
{
unset_option (OPTNEEDRESCORE);
}
-int mutt_parse_score (BUFFER * buf, BUFFER * s,
- unsigned long data __attribute__ ((unused)),
- BUFFER * err)
-{
- char *pattern, *pc;
- struct pattern_t *pat;
- score_t **last;
-
- mutt_extract_token (buf, s, 0);
- if (!MoreArgs (s)) {
- m_strcpy(err->data, err->dsize, _("score: too few arguments"));
- return (-1);
- }
- pattern = buf->data;
- p_clear(buf, 1);
- mutt_extract_token (buf, s, 0);
- if (MoreArgs (s)) {
- p_delete(&pattern);
- m_strcpy(err->data, err->dsize, _("score: too many arguments"));
- return (-1);
- }
-
- /* look for an existing entry and update the value, else add it to the end
- of the list */
- for (last = &Score; *last; last = &(*last)->next) {
- if (m_strcmp(pattern, (*last)->str) == 0)
- break;
- }
- if (!*last) {
- if (!(pat = mutt_pattern_comp(pattern, 0, err))) {
- p_delete(&pattern);
- return (-1);
- }
- *last = score_new();
- (*last)->pat = pat;
- (*last)->str = pattern;
- }
- pc = buf->data;
- pc += (*last)->exact = (*pc == '=');
- (*last)->val = atoi(pc);
- set_option(OPTNEEDRESCORE);
- return 0;
-}
-
void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx)
{
score_t *tmp;
_mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx);
}
-int mutt_parse_unscore(BUFFER * buf, BUFFER * s,
- unsigned long data __attribute__ ((unused)),
- BUFFER * err __attribute__ ((unused)))
-{
- while (MoreArgs(s)) {
- mutt_extract_token(buf, s, 0);
- if (!m_strcmp("*", buf->data)) {
- score_list_wipe(&Score);
- } else {
- score_t **last;
-
- for (last = &Score; *last; last = &(*last)->next) {
- if (!m_strcmp(buf->data, (*last)->str)) {
- score_t *tmp = score_list_pop(last);
- score_delete(&tmp);
- break;
- }
- }
- }
- }
- set_option (OPTNEEDRESCORE);
- return 0;
-}
-
/* vim:set ft=c: */