11 #define PREFSBUFSIZE 1024
14 GSList * global_scoring = NULL;
16 ScoringProp * scoringprop_new(MatcherList * matchers, int score)
18 ScoringProp * scoring;
20 scoring = g_new0(ScoringProp, 1);
21 scoring->matchers = matchers;
22 scoring->score = score;
27 ScoringProp * scoringprop_copy(ScoringProp *src)
32 new = g_new0(ScoringProp, 1);
33 new->matchers = g_new0(MatcherList, 1);
34 for (tmp = src->matchers->matchers; tmp != NULL && tmp->data != NULL;) {
35 MatcherProp *matcher = (MatcherProp *)tmp->data;
37 new->matchers->matchers = g_slist_append(new->matchers->matchers,
38 matcherprop_copy(matcher));
41 new->matchers->bool_and = src->matchers->bool_and;
42 new->score = src->score;
47 void scoringprop_free(ScoringProp * prop)
49 matcherlist_free(prop->matchers);
53 gint scoringprop_score_message(ScoringProp * scoring, MsgInfo * info)
55 if (matcherlist_match(scoring->matchers, info))
56 return scoring->score;
61 gint score_message(GSList * scoring_list, MsgInfo * info)
67 for(l = scoring_list ; l != NULL ; l = g_slist_next(l)) {
68 ScoringProp * scoring = (ScoringProp *) l->data;
70 add_score = (scoringprop_score_message(scoring, info));
71 if (add_score == MAX_SCORE || add_score == MIN_SCORE) {
81 syntax for scoring config
83 file ~/.sylpheed/scoringrc
85 header "x-mailing" match "toto" score -10
86 subject match "regexp" & to regexp "regexp" score 50
87 subject match "regexp" | to regexpcase "regexp" | age_sup 5 score 30
89 if score is = MIN_SCORE (-999), no more match is done in the list
90 if score is = MAX_SCORE (-999), no more match is done in the list
94 gchar * scoringprop_to_string(ScoringProp * prop)
100 list_str = matcherlist_to_string(prop->matchers);
102 if (list_str == NULL)
105 score_str = itos(prop->score);
106 scoring_str = g_strconcat(list_str, " score ", score_str, NULL);
112 void prefs_scoring_free(GSList * prefs_scoring)
114 while (prefs_scoring != NULL) {
115 ScoringProp * scoring = (ScoringProp *) prefs_scoring->data;
116 scoringprop_free(scoring);
117 prefs_scoring = g_slist_remove(prefs_scoring, scoring);
121 static gboolean prefs_scoring_free_func(GNode *node, gpointer data)
123 FolderItem *item = node->data;
128 prefs_scoring_free(item->prefs->scoring);
129 item->prefs->scoring = NULL;
134 void prefs_scoring_clear()
138 for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
141 folder = (Folder *) cur->data;
142 g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
143 prefs_scoring_free_func, NULL);
146 prefs_scoring_free(global_scoring);
147 global_scoring = NULL;