9 #include "procheader.h"
15 #define PREFSBUFSIZE 1024
18 GSList * global_scoring = NULL;
20 ScoringProp * scoringprop_new(MatcherList * matchers, int score)
22 ScoringProp * scoring;
24 scoring = g_new0(ScoringProp, 1);
25 scoring->matchers = matchers;
26 scoring->score = score;
31 ScoringProp * scoringprop_copy(ScoringProp *src)
36 new = g_new0(ScoringProp, 1);
37 new->matchers = g_new0(MatcherList, 1);
38 for (tmp = src->matchers->matchers; tmp != NULL && tmp->data != NULL;) {
39 MatcherProp *matcher = (MatcherProp *)tmp->data;
41 new->matchers->matchers = g_slist_append(new->matchers->matchers,
42 matcherprop_copy(matcher));
45 new->matchers->bool_and = src->matchers->bool_and;
46 new->score = src->score;
51 void scoringprop_free(ScoringProp * prop)
53 matcherlist_free(prop->matchers);
57 gint scoringprop_score_message(ScoringProp * scoring, MsgInfo * info)
59 if (matcherlist_match(scoring->matchers, info))
60 return scoring->score;
65 gint score_message(GSList * scoring_list, MsgInfo * info)
71 for(l = scoring_list ; l != NULL ; l = g_slist_next(l)) {
72 ScoringProp * scoring = (ScoringProp *) l->data;
74 add_score = (scoringprop_score_message(scoring, info));
75 if (add_score == MAX_SCORE || add_score == MIN_SCORE) {
85 syntax for scoring config
87 file ~/.sylpheed/scoringrc
89 header "x-mailing" match "toto" score -10
90 subject match "regexp" & to regexp "regexp" score 50
91 subject match "regexp" | to regexpcase "regexp" | age_sup 5 score 30
93 if score is = MIN_SCORE (-999), no more match is done in the list
94 if score is = MAX_SCORE (-999), no more match is done in the list
98 gchar * scoringprop_to_string(ScoringProp * prop)
104 list_str = matcherlist_to_string(prop->matchers);
106 if (list_str == NULL)
109 score_str = itos(prop->score);
110 scoring_str = g_strconcat(list_str, " score ", score_str, NULL);
116 void prefs_scoring_free(GSList * prefs_scoring)
118 while (prefs_scoring != NULL) {
119 ScoringProp * scoring = (ScoringProp *) prefs_scoring->data;
120 scoringprop_free(scoring);
121 prefs_scoring = g_slist_remove(prefs_scoring, scoring);
125 static gboolean prefs_scoring_free_func(GNode *node, gpointer data)
127 FolderItem *item = node->data;
132 prefs_scoring_free(item->prefs->scoring);
133 item->prefs->scoring = NULL;
138 void prefs_scoring_clear()
142 for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
145 folder = (Folder *) cur->data;
146 g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
147 prefs_scoring_free_func, NULL);
150 prefs_scoring_free(global_scoring);
151 global_scoring = NULL;