9 #include "procheader.h"
13 #define PREFSBUFSIZE 1024
15 GSList * prefs_scoring = NULL;
17 ScoringProp * scoringprop_parse(gchar ** str)
22 ScoringProp * scoring;
24 MatcherList * matchers;
28 matchers = matcherlist_parse(&tmp);
34 key = matcher_parse_keyword(&tmp);
37 matcherlist_free(matchers);
42 if (key != SCORING_SCORE) {
43 matcherlist_free(matchers);
48 score = matcher_parse_number(&tmp);
51 matcherlist_free(matchers);
56 scoring = scoringprop_new(matchers, score);
63 ScoringProp * scoringprop_new(MatcherList * matchers, int score)
65 ScoringProp * scoring;
67 scoring = g_new0(ScoringProp, 1);
68 scoring->matchers = matchers;
69 scoring->score = score;
74 void scoringprop_free(ScoringProp * prop)
76 matcherlist_free(prop->matchers);
80 gint scoringprop_score_message(ScoringProp * scoring, MsgInfo * info)
82 if (matcherlist_match(scoring->matchers, info))
83 return scoring->score;
88 gint score_message(GSList * scoring_list, MsgInfo * info)
94 for(l = scoring_list ; l != NULL ; l = g_slist_next(l)) {
95 ScoringProp * scoring = (ScoringProp *) l->data;
97 add_score = (scoringprop_score_message(scoring, info));
98 if (add_score == MAX_SCORE || add_score == MIN_SCORE) {
108 static void scoringprop_print(ScoringProp * prop)
113 printf("no scoring\n");
117 printf("----- scoring ------\n");
118 for(l = prop->matchers ; l != NULL ; l = g_slist_next(l)) {
119 matcherprop_print((MatcherProp *) l->data);
121 printf("cond: %s\n", prop->bool_and ? "and" : "or");
122 printf("score: %i\n", prop->score);
127 syntax for scoring config
129 file ~/.sylpheed/scoringrc
131 header "x-mailing" match "toto" score -10
132 subject match "regexp" & to regexp "regexp" score 50
133 subject match "regexp" | to regexpcase "regexp" | age_sup 5 score 30
135 if score is = MIN_SCORE (-999), no more match is done in the list
136 if score is = MAX_SCORE (-999), no more match is done in the list
139 void prefs_scoring_read_config(void)
143 gchar buf[PREFSBUFSIZE];
145 debug_print(_("Reading headers configuration...\n"));
147 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, SCORING_RC, NULL);
148 if ((fp = fopen(rcpath, "r")) == NULL) {
149 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
151 prefs_scoring = NULL;
156 /* remove all scoring */
157 while (prefs_scoring != NULL) {
158 ScoringProp * scoring = (ScoringProp *) prefs_scoring->data;
159 scoringprop_free(scoring);
160 prefs_scoring = g_slist_remove(prefs_scoring, scoring);
163 while (fgets(buf, sizeof(buf), fp) != NULL) {
164 ScoringProp * scoring;
169 if ((*buf != '#') && (*buf != '\0')) {
171 scoring = scoringprop_parse(&tmp);
173 prefs_scoring = g_slist_append(prefs_scoring,
178 g_warning(_("syntax error : %s\n"), buf);