2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2002-2012 by the Claws Mail Team and Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "claws-features.h"
26 #include <glib/gi18n.h>
38 #include "procheader.h"
40 #include "matcher_parser.h"
41 #include "prefs_gtk.h"
42 #include "addr_compl.h"
44 #include "quoted-printable.h"
47 #include "prefs_common.h"
50 #include "folder_item_prefs.h"
54 *\brief Keyword lookup element
57 gint id; /*!< keyword id */
58 gchar *str; /*!< keyword */
60 typedef struct _MatchParser MatchParser;
63 *\brief Table with strings and ids used by the lexer and
64 * the parser. New keywords can be added here.
66 static const MatchParser matchparser_tab[] = {
68 {MATCHCRITERIA_ALL, "all"},
69 {MATCHCRITERIA_UNREAD, "unread"},
70 {MATCHCRITERIA_NOT_UNREAD, "~unread"},
71 {MATCHCRITERIA_NEW, "new"},
72 {MATCHCRITERIA_NOT_NEW, "~new"},
73 {MATCHCRITERIA_MARKED, "marked"},
74 {MATCHCRITERIA_NOT_MARKED, "~marked"},
75 {MATCHCRITERIA_DELETED, "deleted"},
76 {MATCHCRITERIA_NOT_DELETED, "~deleted"},
77 {MATCHCRITERIA_REPLIED, "replied"},
78 {MATCHCRITERIA_NOT_REPLIED, "~replied"},
79 {MATCHCRITERIA_FORWARDED, "forwarded"},
80 {MATCHCRITERIA_NOT_FORWARDED, "~forwarded"},
81 {MATCHCRITERIA_LOCKED, "locked"},
82 {MATCHCRITERIA_NOT_LOCKED, "~locked"},
83 {MATCHCRITERIA_COLORLABEL, "colorlabel"},
84 {MATCHCRITERIA_NOT_COLORLABEL, "~colorlabel"},
85 {MATCHCRITERIA_IGNORE_THREAD, "ignore_thread"},
86 {MATCHCRITERIA_NOT_IGNORE_THREAD, "~ignore_thread"},
87 {MATCHCRITERIA_WATCH_THREAD, "watch_thread"},
88 {MATCHCRITERIA_NOT_WATCH_THREAD, "~watch_thread"},
89 {MATCHCRITERIA_SPAM, "spam"},
90 {MATCHCRITERIA_NOT_SPAM, "~spam"},
91 {MATCHCRITERIA_HAS_ATTACHMENT, "has_attachment"},
92 {MATCHCRITERIA_HAS_NO_ATTACHMENT, "~has_attachment"},
93 {MATCHCRITERIA_SIGNED, "signed"},
94 {MATCHCRITERIA_NOT_SIGNED, "~signed"},
97 {MATCHCRITERIA_SUBJECT, "subject"},
98 {MATCHCRITERIA_NOT_SUBJECT, "~subject"},
99 {MATCHCRITERIA_FROM, "from"},
100 {MATCHCRITERIA_NOT_FROM, "~from"},
101 {MATCHCRITERIA_TO, "to"},
102 {MATCHCRITERIA_NOT_TO, "~to"},
103 {MATCHCRITERIA_CC, "cc"},
104 {MATCHCRITERIA_NOT_CC, "~cc"},
105 {MATCHCRITERIA_TO_OR_CC, "to_or_cc"},
106 {MATCHCRITERIA_NOT_TO_AND_NOT_CC, "~to_or_cc"},
107 {MATCHCRITERIA_TAG, "tag"},
108 {MATCHCRITERIA_NOT_TAG, "~tag"},
109 {MATCHCRITERIA_TAGGED, "tagged"},
110 {MATCHCRITERIA_NOT_TAGGED, "~tagged"},
111 {MATCHCRITERIA_AGE_GREATER, "age_greater"},
112 {MATCHCRITERIA_AGE_LOWER, "age_lower"},
113 {MATCHCRITERIA_AGE_GREATER_HOURS, "age_greater_hours"},
114 {MATCHCRITERIA_AGE_LOWER_HOURS, "age_lower_hours"},
115 {MATCHCRITERIA_NEWSGROUPS, "newsgroups"},
116 {MATCHCRITERIA_NOT_NEWSGROUPS, "~newsgroups"},
117 {MATCHCRITERIA_INREPLYTO, "inreplyto"},
118 {MATCHCRITERIA_NOT_INREPLYTO, "~inreplyto"},
119 {MATCHCRITERIA_REFERENCES, "references"},
120 {MATCHCRITERIA_NOT_REFERENCES, "~references"},
121 {MATCHCRITERIA_SCORE_GREATER, "score_greater"},
122 {MATCHCRITERIA_SCORE_LOWER, "score_lower"},
123 {MATCHCRITERIA_SCORE_EQUAL, "score_equal"},
124 {MATCHCRITERIA_PARTIAL, "partial"},
125 {MATCHCRITERIA_NOT_PARTIAL, "~partial"},
126 {MATCHCRITERIA_FOUND_IN_ADDRESSBOOK, "found_in_addressbook"},
127 {MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK, "~found_in_addressbook"},
129 {MATCHCRITERIA_SIZE_GREATER, "size_greater"},
130 {MATCHCRITERIA_SIZE_SMALLER, "size_smaller"},
131 {MATCHCRITERIA_SIZE_EQUAL, "size_equal"},
133 /* content have to be read */
134 {MATCHCRITERIA_HEADER, "header"},
135 {MATCHCRITERIA_NOT_HEADER, "~header"},
136 {MATCHCRITERIA_HEADERS_PART, "headers_part"},
137 {MATCHCRITERIA_NOT_HEADERS_PART, "~headers_part"},
138 {MATCHCRITERIA_MESSAGE, "message"},
139 {MATCHCRITERIA_NOT_MESSAGE, "~message"},
140 {MATCHCRITERIA_BODY_PART, "body_part"},
141 {MATCHCRITERIA_NOT_BODY_PART, "~body_part"},
142 {MATCHCRITERIA_TEST, "test"},
143 {MATCHCRITERIA_NOT_TEST, "~test"},
146 {MATCHTYPE_MATCHCASE, "matchcase"},
147 {MATCHTYPE_MATCH, "match"},
148 {MATCHTYPE_REGEXPCASE, "regexpcase"},
149 {MATCHTYPE_REGEXP, "regexp"},
152 {MATCHACTION_SCORE, "score"}, /* for backward compatibility */
153 {MATCHACTION_MOVE, "move"},
154 {MATCHACTION_COPY, "copy"},
155 {MATCHACTION_DELETE, "delete"},
156 {MATCHACTION_MARK, "mark"},
157 {MATCHACTION_UNMARK, "unmark"},
158 {MATCHACTION_LOCK, "lock"},
159 {MATCHACTION_UNLOCK, "unlock"},
160 {MATCHACTION_MARK_AS_READ, "mark_as_read"},
161 {MATCHACTION_MARK_AS_UNREAD, "mark_as_unread"},
162 {MATCHACTION_MARK_AS_SPAM, "mark_as_spam"},
163 {MATCHACTION_MARK_AS_HAM, "mark_as_ham"},
164 {MATCHACTION_FORWARD, "forward"},
165 {MATCHACTION_FORWARD_AS_ATTACHMENT, "forward_as_attachment"},
166 {MATCHACTION_EXECUTE, "execute"},
167 {MATCHACTION_COLOR, "color"},
168 {MATCHACTION_REDIRECT, "redirect"},
169 {MATCHACTION_CHANGE_SCORE, "change_score"},
170 {MATCHACTION_SET_SCORE, "set_score"},
171 {MATCHACTION_STOP, "stop"},
172 {MATCHACTION_HIDE, "hide"},
173 {MATCHACTION_IGNORE, "ignore"},
174 {MATCHACTION_WATCH, "watch"},
175 {MATCHACTION_ADD_TO_ADDRESSBOOK, "add_to_addressbook"},
176 {MATCHACTION_SET_TAG, "set_tag"},
177 {MATCHACTION_UNSET_TAG, "unset_tag"},
178 {MATCHACTION_CLEAR_TAGS, "clear_tags"},
202 static gchar *context_str[N_CONTEXT_STRS];
204 void matcher_init(void)
206 if (context_str[CONTEXT_SUBJECT] != NULL)
209 context_str[CONTEXT_SUBJECT] = g_strdup_printf(_("%s header"), prefs_common_translated_header_name("Subject:"));
210 context_str[CONTEXT_FROM] = g_strdup_printf(_("%s header"), prefs_common_translated_header_name("From:"));
211 context_str[CONTEXT_TO] = g_strdup_printf(_("%s header"), prefs_common_translated_header_name("To:"));
212 context_str[CONTEXT_CC] = g_strdup_printf(_("%s header"), prefs_common_translated_header_name("Cc:"));
213 context_str[CONTEXT_NEWSGROUPS] = g_strdup_printf(_("%s header"), prefs_common_translated_header_name("Newsgroups:"));
214 context_str[CONTEXT_IN_REPLY_TO] = g_strdup_printf(_("%s header"), prefs_common_translated_header_name("In-Reply-To:"));
215 context_str[CONTEXT_REFERENCES] = g_strdup_printf(_("%s header"), prefs_common_translated_header_name("References:"));
216 context_str[CONTEXT_HEADER] = g_strdup(_("header"));
217 context_str[CONTEXT_HEADER_LINE] = g_strdup(_("header line"));
218 context_str[CONTEXT_BODY_LINE] = g_strdup(_("body line"));
219 context_str[CONTEXT_TAG] = g_strdup(_("tag"));
222 void matcher_done(void)
225 for (i = 0; i < N_CONTEXT_STRS; i++) {
226 g_free(context_str[i]);
227 context_str[i] = NULL;
231 extern gboolean debug_filtering_session;
234 *\brief Look up table with keywords defined in \sa matchparser_tab
236 static GHashTable *matchparser_hashtab;
239 *\brief Translate keyword id to keyword string
241 *\param id Id of keyword
243 *\return const gchar * Keyword
245 const gchar *get_matchparser_tab_str(gint id)
249 for (i = 0; i < sizeof matchparser_tab / sizeof matchparser_tab[0]; i++) {
250 if (matchparser_tab[i].id == id)
251 return matchparser_tab[i].str;
257 *\brief Create keyword lookup table
259 static void create_matchparser_hashtab(void)
263 if (matchparser_hashtab) return;
264 matchparser_hashtab = g_hash_table_new(g_str_hash, g_str_equal);
265 for (i = 0; i < sizeof matchparser_tab / sizeof matchparser_tab[0]; i++)
266 g_hash_table_insert(matchparser_hashtab,
267 matchparser_tab[i].str,
268 (gpointer) &matchparser_tab[i]);
272 *\brief Return a keyword id from a keyword string
274 *\param str Keyword string
276 *\return gint Keyword id
278 gint get_matchparser_tab_id(const gchar *str)
282 if (NULL != (res = g_hash_table_lookup(matchparser_hashtab, str))) {
288 /* **************** data structure allocation **************** */
291 *\brief Allocate a structure for a filtering / scoring
292 * "condition" (a matcher structure)
294 *\param criteria Criteria ID (MATCHCRITERIA_XXXX)
295 *\param header Header string (if criteria is MATCHCRITERIA_HEADER
296 or MATCHCRITERIA_FOUND_IN_ADDRESSBOOK)
297 *\param matchtype Type of action (MATCHTYPE_XXX)
298 *\param expr String value or expression to check
299 *\param value Integer value to check
301 *\return MatcherProp * Pointer to newly allocated structure
303 MatcherProp *matcherprop_new(gint criteria, const gchar *header,
304 gint matchtype, const gchar *expr,
309 prop = g_new0(MatcherProp, 1);
310 prop->criteria = criteria;
311 prop->header = header != NULL ? g_strdup(header) : NULL;
313 prop->expr = expr != NULL ? g_strdup(expr) : NULL;
315 prop->matchtype = matchtype;
324 *\brief Free a matcher structure
326 *\param prop Pointer to matcher structure allocated with
329 void matcherprop_free(MatcherProp *prop)
332 g_free(prop->header);
333 if (prop->preg != NULL) {
341 *\brief Copy a matcher structure
343 *\param src Matcher structure to copy
345 *\return MatcherProp * Pointer to newly allocated matcher structure
347 MatcherProp *matcherprop_copy(const MatcherProp *src)
349 MatcherProp *prop = g_new0(MatcherProp, 1);
351 prop->criteria = src->criteria;
352 prop->header = src->header ? g_strdup(src->header) : NULL;
353 prop->expr = src->expr ? g_strdup(src->expr) : NULL;
354 prop->matchtype = src->matchtype;
356 prop->preg = NULL; /* will be re-evaluated */
357 prop->value = src->value;
358 prop->error = src->error;
362 /* ************** match ******************************/
364 static gboolean match_with_addresses_in_addressbook
365 (MatcherProp *prop, GSList *address_list, gint type,
366 gchar* folderpath, gint match)
369 gboolean found = FALSE;
372 cm_return_val_if_fail(address_list != NULL, FALSE);
374 debug_print("match_with_addresses_in_addressbook(%d, %s)\n",
375 g_slist_length(address_list), folderpath?folderpath:"(null)");
377 if (folderpath == NULL ||
378 strcasecmp(folderpath, "Any") == 0 ||
384 start_address_completion(path);
386 for (walk = address_list; walk != NULL; walk = walk->next) {
387 /* exact matching of email address */
388 guint num_addr = complete_address(walk->data);
391 /* skip first item (this is the search string itself) */
393 for (; i < num_addr && !found; i++) {
394 gchar *addr = get_complete_address(i);
395 extract_address(addr);
396 if (strcasecmp(addr, walk->data) == 0) {
400 if (debug_filtering_session
401 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
402 log_print(LOG_DEBUG_FILTERING,
403 "address [ %s ] matches\n",
404 (gchar *)walk->data);
411 if (debug_filtering_session
412 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH
414 log_print(LOG_DEBUG_FILTERING,
415 "address [ %s ] does NOT match\n",
416 (gchar *)walk->data);
420 if (match == MATCH_ALL) {
421 /* if matching all addresses, stop if one doesn't match */
424 if (debug_filtering_session
425 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
426 log_print(LOG_DEBUG_FILTERING,
427 "not all address match (matching all)\n");
431 } else if (match == MATCH_ANY) {
432 /* if matching any address, stop if one does match */
435 if (debug_filtering_session
436 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
437 log_print(LOG_DEBUG_FILTERING,
438 "at least one address matches (matching any)\n");
443 /* MATCH_ONE: there should be only one loop iteration */
446 end_address_completion();
452 *\brief Find out if a string matches a condition
454 *\param prop Matcher structure
455 *\param str String to check
457 *\return gboolean TRUE if str matches the condition in the
460 static gboolean matcherprop_string_match(MatcherProp *prop, const gchar *str,
461 const gchar *debug_context)
465 gboolean ret = FALSE;
466 gboolean should_free = FALSE;
470 if (prop->matchtype == MATCHTYPE_REGEXPCASE ||
471 prop->matchtype == MATCHTYPE_MATCHCASE) {
472 str1 = g_utf8_casefold(str, -1);
473 down_expr = g_utf8_casefold(prop->expr, -1);
477 down_expr = (gchar *)prop->expr;
481 switch (prop->matchtype) {
482 case MATCHTYPE_REGEXPCASE:
483 case MATCHTYPE_REGEXP:
485 if (!prop->preg && (prop->error == 0)) {
486 prop->preg = g_new0(regex_t, 1);
487 /* if regexp then don't use the escaped string */
488 if (regcomp(prop->preg, down_expr,
489 REG_NOSUB | REG_EXTENDED
490 | ((prop->matchtype == MATCHTYPE_REGEXPCASE)
491 ? REG_ICASE : 0)) != 0) {
497 if (prop->preg == NULL) {
502 if (regexec(prop->preg, str1, 0, NULL, 0) == 0)
508 if (debug_filtering_session
509 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
510 gchar *stripped = g_strdup(str);
512 strretchomp(stripped);
514 log_print(LOG_DEBUG_FILTERING,
515 "%s value [ %s ] matches regular expression [ %s ] (%s)\n",
516 debug_context, stripped, prop->expr,
517 prop->matchtype == MATCHTYPE_REGEXP ? _("Case sensitive"):_("Case insensitive"));
519 log_print(LOG_DEBUG_FILTERING,
520 "%s value [ %s ] does NOT match regular expression [ %s ] (%s)\n",
521 debug_context, stripped, prop->expr,
522 prop->matchtype == MATCHTYPE_REGEXP ? _("Case sensitive"):_("Case insensitive"));
528 case MATCHTYPE_MATCHCASE:
529 case MATCHTYPE_MATCH:
530 ret = (strstr(str1, down_expr) != NULL);
533 if (debug_filtering_session
534 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
535 gchar *stripped = g_strdup(str);
537 strretchomp(stripped);
539 log_print(LOG_DEBUG_FILTERING,
540 "%s value [ %s ] contains [ %s ] (%s)\n",
541 debug_context, stripped, prop->expr,
542 prop->matchtype == MATCHTYPE_MATCH ? _("Case sensitive"):_("Case insensitive"));
544 log_print(LOG_DEBUG_FILTERING,
545 "%s value [ %s ] does NOT contain [ %s ] (%s)\n",
546 debug_context, stripped, prop->expr,
547 prop->matchtype == MATCHTYPE_MATCH ? _("Case sensitive"):_("Case insensitive"));
566 *\brief Find out if a tag matches a condition
568 *\param prop Matcher structure
569 *\param msginfo message to check
571 *\return gboolean TRUE if msginfo matches the condition in the
574 static gboolean matcherprop_tag_match(MatcherProp *prop, MsgInfo *msginfo,
575 const gchar *debug_context)
577 gboolean ret = FALSE;
580 if (msginfo == NULL || msginfo->tags == NULL)
583 for (cur = msginfo->tags; cur; cur = cur->next) {
584 const gchar *str = tags_get_tag(GPOINTER_TO_INT(cur->data));
587 if (matcherprop_string_match(prop, str, debug_context)) {
596 *\brief Find out if the string-ed list matches a condition
598 *\param prop Matcher structure
599 *\param list GSList of strings to check
601 *\return gboolean TRUE if str matches the condition in the
604 static gboolean matcherprop_list_match(MatcherProp *prop, const GSList *list,
605 const gchar *debug_context)
609 for(cur = list; cur != NULL; cur = cur->next) {
610 if (matcherprop_string_match(prop, (gchar *)cur->data, debug_context))
616 static gboolean matcherprop_header_line_match(MatcherProp *prop, const gchar *hdr,
617 const gchar *str, const gchar *debug_context)
620 gboolean res = FALSE;
622 if (hdr == NULL || str == NULL)
625 line = g_strdup_printf("%s %s", hdr, str);
626 res = matcherprop_string_match(prop, line, debug_context);
633 typedef struct _thread_data {
640 static void *matcher_test_thread(void *data)
642 thread_data *td = (thread_data *)data;
645 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
646 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
648 result = system(td->cmd);
649 td->done = TRUE; /* let the caller thread join() */
650 return GINT_TO_POINTER(result);
655 *\brief Execute a command defined in the matcher structure
657 *\param prop Pointer to matcher structure
658 *\param info Pointer to message info structure
660 *\return gboolean TRUE if command was executed succesfully
662 static gboolean matcherprop_match_test(const MatcherProp *prop,
671 thread_data *td = g_new0(thread_data, 1);
673 time_t start_time = time(NULL);
676 file = procmsg_get_message_file(info);
685 cmd = matching_build_command(prop->expr, info);
695 if (debug_filtering_session
696 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
697 log_print(LOG_DEBUG_FILTERING,
698 "starting threaded command [ %s ]\n",
704 if (pthread_attr_init(&pta) != 0 ||
705 pthread_attr_setdetachstate(&pta, PTHREAD_CREATE_JOINABLE) != 0 ||
706 pthread_create(&pt, &pta, matcher_test_thread, td) != 0)
707 retval = system(cmd);
709 debug_print("waiting for test thread\n");
711 /* don't let the interface freeze while waiting */
713 if (time(NULL) - start_time > 30) {
719 pthread_join(pt, &res);
720 retval = GPOINTER_TO_INT(res);
721 debug_print(" test thread returned %d\n", retval);
726 if (debug_filtering_session
727 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
728 log_print(LOG_DEBUG_FILTERING,
729 "starting synchronous command [ %s ]\n",
733 retval = system(cmd);
735 debug_print("Command exit code: %d\n", retval);
738 if (debug_filtering_session
739 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
740 log_print(LOG_DEBUG_FILTERING,
741 "command returned [ %d ]\n",
746 return (retval == 0);
750 *\brief Check if a message matches the condition in a matcher
753 *\param prop Pointer to matcher structure
754 *\param info Pointer to message info
756 *\return gboolean TRUE if a match
758 static gboolean matcherprop_match(MatcherProp *prop,
762 gint age_mult_hours = 1;
764 switch(prop->criteria) {
765 case MATCHCRITERIA_ALL:
767 case MATCHCRITERIA_UNREAD:
768 return MSG_IS_UNREAD(info->flags);
769 case MATCHCRITERIA_NOT_UNREAD:
770 return !MSG_IS_UNREAD(info->flags);
771 case MATCHCRITERIA_NEW:
772 return MSG_IS_NEW(info->flags);
773 case MATCHCRITERIA_NOT_NEW:
774 return !MSG_IS_NEW(info->flags);
775 case MATCHCRITERIA_MARKED:
776 return MSG_IS_MARKED(info->flags);
777 case MATCHCRITERIA_NOT_MARKED:
778 return !MSG_IS_MARKED(info->flags);
779 case MATCHCRITERIA_DELETED:
780 return MSG_IS_DELETED(info->flags);
781 case MATCHCRITERIA_NOT_DELETED:
782 return !MSG_IS_DELETED(info->flags);
783 case MATCHCRITERIA_REPLIED:
784 return MSG_IS_REPLIED(info->flags);
785 case MATCHCRITERIA_NOT_REPLIED:
786 return !MSG_IS_REPLIED(info->flags);
787 case MATCHCRITERIA_FORWARDED:
788 return MSG_IS_FORWARDED(info->flags);
789 case MATCHCRITERIA_NOT_FORWARDED:
790 return !MSG_IS_FORWARDED(info->flags);
791 case MATCHCRITERIA_LOCKED:
792 return MSG_IS_LOCKED(info->flags);
793 case MATCHCRITERIA_NOT_LOCKED:
794 return !MSG_IS_LOCKED(info->flags);
795 case MATCHCRITERIA_SPAM:
796 return MSG_IS_SPAM(info->flags);
797 case MATCHCRITERIA_NOT_SPAM:
798 return !MSG_IS_SPAM(info->flags);
799 case MATCHCRITERIA_HAS_ATTACHMENT:
800 return MSG_IS_WITH_ATTACHMENT(info->flags);
801 case MATCHCRITERIA_HAS_NO_ATTACHMENT:
802 return !MSG_IS_WITH_ATTACHMENT(info->flags);
803 case MATCHCRITERIA_SIGNED:
804 return MSG_IS_SIGNED(info->flags);
805 case MATCHCRITERIA_NOT_SIGNED:
806 return !MSG_IS_SIGNED(info->flags);
807 case MATCHCRITERIA_COLORLABEL:
809 gint color = MSG_GET_COLORLABEL_VALUE(info->flags);
810 gboolean ret = (color == prop->value);
813 if (debug_filtering_session
814 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
816 log_print(LOG_DEBUG_FILTERING,
817 "message color value [ %d ] matches color value [ %d ]\n",
820 log_print(LOG_DEBUG_FILTERING,
821 "message color value [ %d ] does NOT match color value [ %d ]\n",
827 case MATCHCRITERIA_NOT_COLORLABEL:
829 gint color = MSG_GET_COLORLABEL_VALUE(info->flags);
830 gboolean ret = (color != prop->value);
833 if (debug_filtering_session
834 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
836 log_print(LOG_DEBUG_FILTERING,
837 "message color value [ %d ] matches color value [ %d ]\n",
840 log_print(LOG_DEBUG_FILTERING,
841 "message color value [ %d ] does NOT match color value [ %d ]\n",
847 case MATCHCRITERIA_IGNORE_THREAD:
848 return MSG_IS_IGNORE_THREAD(info->flags);
849 case MATCHCRITERIA_NOT_IGNORE_THREAD:
850 return !MSG_IS_IGNORE_THREAD(info->flags);
851 case MATCHCRITERIA_WATCH_THREAD:
852 return MSG_IS_WATCH_THREAD(info->flags);
853 case MATCHCRITERIA_NOT_WATCH_THREAD:
854 return !MSG_IS_WATCH_THREAD(info->flags);
855 case MATCHCRITERIA_SUBJECT:
856 return matcherprop_string_match(prop, info->subject, context_str[CONTEXT_SUBJECT]);
857 case MATCHCRITERIA_NOT_SUBJECT:
858 return !matcherprop_string_match(prop, info->subject, context_str[CONTEXT_SUBJECT]);
859 case MATCHCRITERIA_FROM:
860 return matcherprop_string_match(prop, info->from, context_str[CONTEXT_FROM]);
861 case MATCHCRITERIA_NOT_FROM:
862 return !matcherprop_string_match(prop, info->from, context_str[CONTEXT_FROM]);
863 case MATCHCRITERIA_TO:
864 return matcherprop_string_match(prop, info->to, context_str[CONTEXT_TO]);
865 case MATCHCRITERIA_NOT_TO:
866 return !matcherprop_string_match(prop, info->to, context_str[CONTEXT_TO]);
867 case MATCHCRITERIA_CC:
868 return matcherprop_string_match(prop, info->cc, context_str[CONTEXT_CC]);
869 case MATCHCRITERIA_NOT_CC:
870 return !matcherprop_string_match(prop, info->cc, context_str[CONTEXT_CC]);
871 case MATCHCRITERIA_TO_OR_CC:
872 return matcherprop_string_match(prop, info->to, context_str[CONTEXT_TO])
873 || matcherprop_string_match(prop, info->cc, context_str[CONTEXT_CC]);
874 case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
875 return !matcherprop_string_match(prop, info->to, context_str[CONTEXT_TO])
876 && !matcherprop_string_match(prop, info->cc, context_str[CONTEXT_CC]);
877 case MATCHCRITERIA_TAG:
878 return matcherprop_tag_match(prop, info, context_str[CONTEXT_TAG]);
879 case MATCHCRITERIA_NOT_TAG:
880 return !matcherprop_tag_match(prop, info, context_str[CONTEXT_TAG]);
881 case MATCHCRITERIA_TAGGED:
882 return info->tags != NULL;
883 case MATCHCRITERIA_NOT_TAGGED:
884 return info->tags == NULL;
885 case MATCHCRITERIA_AGE_GREATER:
887 /* Fallthrough intended */
888 case MATCHCRITERIA_AGE_GREATER_HOURS:
894 age = ((t - info->date_t) / (60 * 60 * age_mult_hours));
895 ret = (age >= prop->value);
898 if (debug_filtering_session
899 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
901 log_print(LOG_DEBUG_FILTERING,
902 "message age [ %d ] is greater than [ %d ]\n",
905 log_print(LOG_DEBUG_FILTERING,
906 "message age [ %d ] is not greater than [ %d ]\n",
912 case MATCHCRITERIA_AGE_LOWER:
914 /* Fallthrough intended */
915 case MATCHCRITERIA_AGE_LOWER_HOURS:
921 age = ((t - info->date_t) / (60 * 60 * age_mult_hours));
922 ret = (age < prop->value);
925 if (debug_filtering_session
926 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
928 log_print(LOG_DEBUG_FILTERING,
929 "message age [ %d ] is lower than [ %d ]\n",
932 log_print(LOG_DEBUG_FILTERING,
933 "message age [ %d ] is not lower than [ %d ]\n",
939 case MATCHCRITERIA_SCORE_GREATER:
941 gboolean ret = (info->score > prop->value);
944 if (debug_filtering_session
945 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
947 log_print(LOG_DEBUG_FILTERING,
948 "message score [ %d ] is greater than [ %d ]\n",
949 info->score, prop->value);
951 log_print(LOG_DEBUG_FILTERING,
952 "message score [ %d ] is not greater than [ %d ]\n",
953 info->score, prop->value);
958 case MATCHCRITERIA_SCORE_LOWER:
960 gboolean ret = (info->score < prop->value);
963 if (debug_filtering_session
964 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
966 log_print(LOG_DEBUG_FILTERING,
967 "message score [ %d ] is lower than [ %d ]\n",
968 info->score, prop->value);
970 log_print(LOG_DEBUG_FILTERING,
971 "message score [ %d ] is not lower than [ %d ]\n",
972 info->score, prop->value);
977 case MATCHCRITERIA_SCORE_EQUAL:
979 gboolean ret = (info->score == prop->value);
982 if (debug_filtering_session
983 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
985 log_print(LOG_DEBUG_FILTERING,
986 "message score [ %d ] is equal to [ %d ]\n",
987 info->score, prop->value);
989 log_print(LOG_DEBUG_FILTERING,
990 "message score [ %d ] is not equal to [ %d ]\n",
991 info->score, prop->value);
996 case MATCHCRITERIA_SIZE_GREATER:
998 /* FIXME: info->size is a goffset */
999 gboolean ret = (info->size > (goffset) prop->value);
1002 if (debug_filtering_session
1003 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
1005 log_print(LOG_DEBUG_FILTERING,
1006 "message size is greater than [ %d ]\n",
1009 log_print(LOG_DEBUG_FILTERING,
1010 "message size is not greater than [ %d ]\n",
1016 case MATCHCRITERIA_SIZE_SMALLER:
1018 /* FIXME: info->size is a goffset */
1019 gboolean ret = (info->size < (goffset) prop->value);
1022 if (debug_filtering_session
1023 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
1025 log_print(LOG_DEBUG_FILTERING,
1026 "message size is smaller than [ %d ]\n",
1029 log_print(LOG_DEBUG_FILTERING,
1030 "message size is not smaller than [ %d ]\n",
1036 case MATCHCRITERIA_SIZE_EQUAL:
1038 /* FIXME: info->size is a goffset */
1039 gboolean ret = (info->size == (goffset) prop->value);
1042 if (debug_filtering_session
1043 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
1045 log_print(LOG_DEBUG_FILTERING,
1046 "message size is equal to [ %d ]\n",
1049 log_print(LOG_DEBUG_FILTERING,
1050 "message size is not equal to [ %d ]\n",
1056 case MATCHCRITERIA_PARTIAL:
1058 /* FIXME: info->size is a goffset */
1059 gboolean ret = (info->total_size != 0 && info->size != (goffset)info->total_size);
1062 if (debug_filtering_session
1063 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
1065 log_print(LOG_DEBUG_FILTERING,
1066 "message is partially downloaded, size is less than total size [ %d ])\n",
1069 log_print(LOG_DEBUG_FILTERING,
1070 "message is not partially downloaded\n");
1075 case MATCHCRITERIA_NOT_PARTIAL:
1077 /* FIXME: info->size is a goffset */
1078 gboolean ret = (info->total_size == 0 || info->size == (goffset)info->total_size);
1081 if (debug_filtering_session
1082 && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
1084 log_print(LOG_DEBUG_FILTERING,
1085 "message is not partially downloaded\n");
1087 log_print(LOG_DEBUG_FILTERING,
1088 "message is partially downloaded, size is less than total size [ %d ])\n",
1094 case MATCHCRITERIA_NEWSGROUPS:
1095 return matcherprop_string_match(prop, info->newsgroups, context_str[CONTEXT_NEWSGROUPS]);
1096 case MATCHCRITERIA_NOT_NEWSGROUPS:
1097 return !matcherprop_string_match(prop, info->newsgroups, context_str[CONTEXT_NEWSGROUPS]);
1098 case MATCHCRITERIA_INREPLYTO:
1099 return matcherprop_string_match(prop, info->inreplyto, context_str[CONTEXT_IN_REPLY_TO]);
1100 case MATCHCRITERIA_NOT_INREPLYTO:
1101 return !matcherprop_string_match(prop, info->inreplyto, context_str[CONTEXT_IN_REPLY_TO]);
1102 case MATCHCRITERIA_REFERENCES:
1103 return matcherprop_list_match(prop, info->references, context_str[CONTEXT_REFERENCES]);
1104 case MATCHCRITERIA_NOT_REFERENCES:
1105 return !matcherprop_list_match(prop, info->references, context_str[CONTEXT_REFERENCES]);
1106 case MATCHCRITERIA_TEST:
1107 return matcherprop_match_test(prop, info);
1108 case MATCHCRITERIA_NOT_TEST:
1109 return !matcherprop_match_test(prop, info);
1115 /* ********************* MatcherList *************************** */
1118 *\brief Create a new list of matchers
1120 *\param matchers List of matcher structures
1121 *\param bool_and Operator
1123 *\return MatcherList * New list
1125 MatcherList *matcherlist_new(GSList *matchers, gboolean bool_and)
1129 cond = g_new0(MatcherList, 1);
1131 cond->matchers = matchers;
1132 cond->bool_and = bool_and;
1139 *\brief Builds a single regular expresion from an array of srings.
1141 *\param strings The lines containing the different sub-regexp.
1143 *\return The newly allocated regexp string.
1145 static gchar *build_complete_regexp(gchar **strings)
1149 while (strings && strings[i] && *strings[i]) {
1150 int old_len = expr ? strlen(expr):0;
1152 gchar *tmpstr = NULL;
1154 if (g_utf8_validate(strings[i], -1, NULL))
1155 tmpstr = g_strdup(strings[i]);
1157 tmpstr = conv_codeset_strdup(strings[i],
1158 conv_get_locale_charset_str_no_utf8(),
1161 if (strstr(tmpstr, "\n"))
1162 *(strstr(tmpstr, "\n")) = '\0';
1164 new_len = strlen(tmpstr);
1166 expr = g_realloc(expr,
1167 expr ? (old_len + strlen("|()") + new_len + 1)
1168 : (strlen("()") + new_len + 1));
1171 strcpy(expr + old_len, "|(");
1172 strcpy(expr + old_len + 2, tmpstr);
1173 strcpy(expr + old_len + 2 + new_len, ")");
1175 strcpy(expr+old_len, "(");
1176 strcpy(expr+old_len + 1, tmpstr);
1177 strcpy(expr+old_len + 1 + new_len, ")");
1187 *\brief Create a new list of matchers from a multi-line string
1189 *\param lines String with "\n"-separated expressions
1190 *\param bool_and Operator
1192 *\return MatcherList * New matcher list
1194 MatcherList *matcherlist_new_from_lines(gchar *lines, gboolean bool_and)
1196 MatcherProp *m = NULL;
1197 GSList *matchers = NULL;
1198 gchar **strings = g_strsplit(lines, "\n", -1);
1202 expr = build_complete_regexp(strings);
1203 debug_print("building matcherprop for expr '%s'\n", expr?expr:"NULL");
1205 m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, MATCHTYPE_REGEXP,
1208 /* print error message */
1209 debug_print("failed to allocate memory for matcherprop\n");
1211 matchers = g_slist_append(matchers, m);
1217 while (strings && strings[i] && *strings[i]) {
1218 m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, MATCHTYPE_MATCHCASE,
1221 /* print error message */
1222 debug_print("failed to allocate memory for matcherprop\n");
1224 matchers = g_slist_append(matchers, m);
1229 g_strfreev(strings);
1231 return matcherlist_new(matchers, bool_and);
1235 *\brief Frees a list of matchers
1237 *\param cond List of matchers
1239 void matcherlist_free(MatcherList *cond)
1243 cm_return_if_fail(cond);
1244 for (l = cond->matchers ; l != NULL ; l = g_slist_next(l)) {
1245 matcherprop_free((MatcherProp *) l->data);
1247 g_slist_free(cond->matchers);
1252 *\brief Skip all headers in a message file
1254 *\param fp Message file
1256 static void matcherlist_skip_headers(FILE *fp)
1258 gchar buf[BUFFSIZE];
1260 while (procheader_get_one_field(buf, sizeof(buf), fp, NULL) != -1)
1265 *\brief Check if a header matches a matcher condition
1267 *\param matcher Matcher structure to check header for
1268 *\param buf Header name
1270 *\return boolean TRUE if matching header
1272 static gboolean matcherprop_match_one_header(MatcherProp *matcher,
1275 gboolean result = FALSE;
1276 Header *header = NULL;
1278 switch (matcher->criteria) {
1279 case MATCHCRITERIA_HEADER:
1280 case MATCHCRITERIA_NOT_HEADER:
1281 header = procheader_parse_header(buf);
1284 if (procheader_headername_equal(header->name,
1286 if (matcher->criteria == MATCHCRITERIA_HEADER)
1287 result = matcherprop_string_match(matcher, header->body, context_str[CONTEXT_HEADER]);
1289 result = !matcherprop_string_match(matcher, header->body, context_str[CONTEXT_HEADER]);
1290 procheader_header_free(header);
1294 procheader_header_free(header);
1297 case MATCHCRITERIA_HEADERS_PART:
1298 case MATCHCRITERIA_MESSAGE:
1299 header = procheader_parse_header(buf);
1302 result = matcherprop_header_line_match(matcher,
1303 header->name, header->body, context_str[CONTEXT_HEADER_LINE]);
1304 procheader_header_free(header);
1306 case MATCHCRITERIA_NOT_HEADERS_PART:
1307 case MATCHCRITERIA_NOT_MESSAGE:
1308 header = procheader_parse_header(buf);
1311 result = !matcherprop_header_line_match(matcher,
1312 header->name, header->body, context_str[CONTEXT_HEADER_LINE]);
1313 procheader_header_free(header);
1315 case MATCHCRITERIA_FOUND_IN_ADDRESSBOOK:
1316 case MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK:
1318 GSList *address_list = NULL;
1319 gint match = MATCH_ONE;
1320 gboolean found = FALSE;
1322 /* how many address headers are me trying to mach? */
1323 if (strcasecmp(matcher->header, "Any") == 0)
1325 else if (strcasecmp(matcher->header, "All") == 0)
1328 if (match == MATCH_ONE) {
1329 /* matching one address header exactly, is that the right one? */
1330 header = procheader_parse_header(buf);
1332 !procheader_headername_equal(header->name, matcher->header))
1334 address_list = address_list_append(address_list, header->body);
1335 if (address_list == NULL)
1339 header = procheader_parse_header(buf);
1342 /* address header is one of the headers we have to match when checking
1343 for any address header or all address headers? */
1344 if (procheader_headername_equal(header->name, "From") ||
1345 procheader_headername_equal(header->name, "To") ||
1346 procheader_headername_equal(header->name, "Cc") ||
1347 procheader_headername_equal(header->name, "Reply-To") ||
1348 procheader_headername_equal(header->name, "Sender"))
1349 address_list = address_list_append(address_list, header->body);
1350 if (address_list == NULL)
1354 found = match_with_addresses_in_addressbook
1355 (matcher, address_list, matcher->criteria,
1356 matcher->expr, match);
1357 g_slist_free(address_list);
1359 if (matcher->criteria == MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK)
1370 *\brief Check if the matcher structure wants headers to
1373 *\param matcher Matcher structure
1375 *\return gboolean TRUE if the matcher structure describes
1376 * a header match condition
1378 static gboolean matcherprop_criteria_headers(const MatcherProp *matcher)
1380 switch (matcher->criteria) {
1381 case MATCHCRITERIA_HEADER:
1382 case MATCHCRITERIA_NOT_HEADER:
1383 case MATCHCRITERIA_HEADERS_PART:
1384 case MATCHCRITERIA_NOT_HEADERS_PART:
1385 case MATCHCRITERIA_FOUND_IN_ADDRESSBOOK:
1386 case MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK:
1394 *\brief Check if the matcher structure wants the message
1395 * to be matched (just perform an action on any
1398 *\param matcher Matcher structure
1400 *\return gboolean TRUE if matcher condition should match
1403 static gboolean matcherprop_criteria_message(MatcherProp *matcher)
1405 switch (matcher->criteria) {
1406 case MATCHCRITERIA_MESSAGE:
1407 case MATCHCRITERIA_NOT_MESSAGE:
1415 *\brief Check if a list of conditions matches one header in
1418 *\param matchers List of conditions
1419 *\param fp Message file
1421 *\return gboolean TRUE if one of the headers is matched by
1422 * the list of conditions.
1424 static gboolean matcherlist_match_headers(MatcherList *matchers, FILE *fp)
1427 gchar buf[BUFFSIZE];
1429 while (procheader_get_one_field(buf, sizeof(buf), fp, NULL) != -1) {
1430 for (l = matchers->matchers ; l != NULL ; l = g_slist_next(l)) {
1431 MatcherProp *matcher = (MatcherProp *) l->data;
1432 gint match = MATCH_ANY;
1437 /* determine the match range (all, any are our concern here) */
1438 if (matcher->criteria == MATCHCRITERIA_NOT_HEADERS_PART ||
1439 matcher->criteria == MATCHCRITERIA_NOT_MESSAGE) {
1442 } else if (matcher->criteria == MATCHCRITERIA_FOUND_IN_ADDRESSBOOK ||
1443 matcher->criteria == MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK) {
1444 Header *header = NULL;
1446 /* address header is one of the headers we have to match when checking
1447 for any address header or all address headers? */
1448 header = procheader_parse_header(buf);
1450 (procheader_headername_equal(header->name, "From") ||
1451 procheader_headername_equal(header->name, "To") ||
1452 procheader_headername_equal(header->name, "Cc") ||
1453 procheader_headername_equal(header->name, "Reply-To") ||
1454 procheader_headername_equal(header->name, "Sender"))) {
1456 if (strcasecmp(matcher->header, "Any") == 0)
1458 else if (strcasecmp(matcher->header, "All") == 0)
1463 /* further call to matcherprop_match_one_header() can't match
1464 and it irrelevant, so: don't alter the match result */
1469 /* ZERO line must NOT match for the rule to match.
1471 if (match == MATCH_ALL) {
1472 if (matcherprop_match_one_header(matcher, buf)) {
1473 matcher->result = TRUE;
1475 matcher->result = FALSE;
1476 matcher->done = TRUE;
1478 /* else, just one line matching is enough for the rule to match
1480 } else if (matcherprop_criteria_headers(matcher) ||
1481 matcherprop_criteria_message(matcher)) {
1482 if (matcherprop_match_one_header(matcher, buf)) {
1483 matcher->result = TRUE;
1484 matcher->done = TRUE;
1488 /* if the rule matched and the matchers are OR, no need to
1489 * check the others */
1490 if (matcher->result && matcher->done) {
1491 if (!matchers->bool_and)
1501 *\brief Check if a matcher wants to check the message body
1503 *\param matcher Matcher structure
1505 *\return gboolean TRUE if body must be matched.
1507 static gboolean matcherprop_criteria_body(const MatcherProp *matcher)
1509 switch (matcher->criteria) {
1510 case MATCHCRITERIA_BODY_PART:
1511 case MATCHCRITERIA_NOT_BODY_PART:
1518 static gboolean matcherlist_match_binary_content(MatcherList *matchers, MimeInfo *partinfo)
1521 gchar buf[BUFFSIZE];
1524 if (partinfo->type == MIMETYPE_TEXT)
1527 outfp = procmime_get_binary_content(partinfo);
1532 while (fgets(buf, sizeof(buf), outfp) != NULL) {
1535 for (l = matchers->matchers ; l != NULL ; l = g_slist_next(l)) {
1536 MatcherProp *matcher = (MatcherProp *) l->data;
1541 /* Don't scan non-text parts when looking in body, only
1542 * when looking in whole message
1544 if (partinfo && partinfo->type != MIMETYPE_TEXT &&
1545 (matcher->criteria == MATCHCRITERIA_NOT_BODY_PART ||
1546 matcher->criteria == MATCHCRITERIA_BODY_PART))
1549 /* if the criteria is ~body_part or ~message, ZERO lines
1550 * must match for the rule to match.
1552 if (matcher->criteria == MATCHCRITERIA_NOT_BODY_PART ||
1553 matcher->criteria == MATCHCRITERIA_NOT_MESSAGE) {
1554 if (matcherprop_string_match(matcher, buf,
1555 context_str[CONTEXT_BODY_LINE])) {
1556 matcher->result = FALSE;
1557 matcher->done = TRUE;
1559 matcher->result = TRUE;
1560 /* else, just one line has to match */
1561 } else if (matcherprop_criteria_body(matcher) ||
1562 matcherprop_criteria_message(matcher)) {
1563 if (matcherprop_string_match(matcher, buf,
1564 context_str[CONTEXT_BODY_LINE])) {
1565 matcher->result = TRUE;
1566 matcher->done = TRUE;
1570 /* if the matchers are OR'ed and the rule matched,
1571 * no need to check the others. */
1572 if (matcher->result && matcher->done) {
1573 if (!matchers->bool_and) {
1585 static gboolean match_content_cb(const gchar *buf, gpointer data)
1587 MatcherList *matchers = (MatcherList *)data;
1588 gboolean all_done = TRUE;
1591 for (l = matchers->matchers ; l != NULL ; l = g_slist_next(l)) {
1592 MatcherProp *matcher = (MatcherProp *) l->data;
1597 /* if the criteria is ~body_part or ~message, ZERO lines
1598 * must match for the rule to match.
1600 if (matcher->criteria == MATCHCRITERIA_NOT_BODY_PART ||
1601 matcher->criteria == MATCHCRITERIA_NOT_MESSAGE) {
1602 if (matcherprop_string_match(matcher, buf,
1603 context_str[CONTEXT_BODY_LINE])) {
1604 matcher->result = FALSE;
1605 matcher->done = TRUE;
1607 matcher->result = TRUE;
1608 /* else, just one line has to match */
1609 } else if (matcherprop_criteria_body(matcher) ||
1610 matcherprop_criteria_message(matcher)) {
1611 if (matcherprop_string_match(matcher, buf,
1612 context_str[CONTEXT_BODY_LINE])) {
1613 matcher->result = TRUE;
1614 matcher->done = TRUE;
1618 /* if the matchers are OR'ed and the rule matched,
1619 * no need to check the others. */
1620 if (matcher->result && matcher->done) {
1621 if (!matchers->bool_and) {
1632 static gboolean matcherlist_match_text_content(MatcherList *matchers, MimeInfo *partinfo)
1634 if (partinfo->type != MIMETYPE_TEXT)
1637 return procmime_scan_text_content(partinfo, match_content_cb, matchers);
1641 *\brief Check if a line in a message file's body matches
1644 *\param matchers List of conditions
1645 *\param fp Message file
1647 *\return gboolean TRUE if succesful match
1649 static gboolean matcherlist_match_body(MatcherList *matchers, gboolean body_only, MsgInfo *info)
1651 MimeInfo *mimeinfo = NULL;
1652 MimeInfo *partinfo = NULL;
1653 gboolean first_text_found = FALSE;
1655 cm_return_val_if_fail(info != NULL, FALSE);
1657 mimeinfo = procmime_scan_message(info);
1660 partinfo = procmime_mimeinfo_next(mimeinfo);
1662 for (; partinfo != NULL; partinfo = procmime_mimeinfo_next(partinfo)) {
1664 if (partinfo->type != MIMETYPE_TEXT && body_only)
1667 if (partinfo->type == MIMETYPE_TEXT) {
1668 first_text_found = TRUE;
1669 if (matcherlist_match_text_content(matchers, partinfo)) {
1670 procmime_mimeinfo_free_all(mimeinfo);
1673 } else if (matcherlist_match_binary_content(matchers, partinfo)) {
1674 procmime_mimeinfo_free_all(mimeinfo);
1678 if (body_only && first_text_found)
1681 procmime_mimeinfo_free_all(mimeinfo);
1687 *\brief Check if a message file matches criteria
1689 *\param matchers Criteria
1690 *\param info Message info
1691 *\param result Default result
1693 *\return gboolean TRUE if matched
1695 static gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
1698 gboolean read_headers;
1705 /* file need to be read ? */
1707 read_headers = FALSE;
1710 for (l = matchers->matchers ; l != NULL ; l = g_slist_next(l)) {
1711 MatcherProp *matcher = (MatcherProp *) l->data;
1713 if (matcherprop_criteria_headers(matcher))
1714 read_headers = TRUE;
1715 if (matcherprop_criteria_body(matcher))
1717 if (matcherprop_criteria_message(matcher)) {
1718 read_headers = TRUE;
1722 matcher->result = FALSE;
1723 matcher->done = FALSE;
1726 if (!read_headers && !read_body)
1729 file = procmsg_get_message_file_full(info, read_headers, read_body);
1733 if ((fp = g_fopen(file, "rb")) == NULL) {
1734 FILE_OP_ERROR(file, "fopen");
1739 /* read the headers */
1742 if (matcherlist_match_headers(matchers, fp))
1745 matcherlist_skip_headers(fp);
1750 matcherlist_match_body(matchers, body_only, info);
1753 for (l = matchers->matchers; l != NULL; l = g_slist_next(l)) {
1754 MatcherProp *matcher = (MatcherProp *) l->data;
1756 if (matcherprop_criteria_headers(matcher) ||
1757 matcherprop_criteria_body(matcher) ||
1758 matcherprop_criteria_message(matcher)) {
1759 if (matcher->result) {
1760 if (!matchers->bool_and) {
1766 if (matchers->bool_and) {
1782 *\brief Test list of conditions on a message.
1784 *\param matchers List of conditions
1785 *\param info Message info
1787 *\return gboolean TRUE if matched
1789 gboolean matcherlist_match(MatcherList *matchers, MsgInfo *info)
1797 if (matchers->bool_and)
1802 /* test the cached elements */
1804 for (l = matchers->matchers; l != NULL ;l = g_slist_next(l)) {
1805 MatcherProp *matcher = (MatcherProp *) l->data;
1807 if (debug_filtering_session) {
1808 gchar *buf = matcherprop_to_string(matcher);
1809 log_print(LOG_DEBUG_FILTERING, _("checking if message matches [ %s ]\n"), buf);
1813 switch(matcher->criteria) {
1814 case MATCHCRITERIA_ALL:
1815 case MATCHCRITERIA_UNREAD:
1816 case MATCHCRITERIA_NOT_UNREAD:
1817 case MATCHCRITERIA_NEW:
1818 case MATCHCRITERIA_NOT_NEW:
1819 case MATCHCRITERIA_MARKED:
1820 case MATCHCRITERIA_NOT_MARKED:
1821 case MATCHCRITERIA_DELETED:
1822 case MATCHCRITERIA_NOT_DELETED:
1823 case MATCHCRITERIA_REPLIED:
1824 case MATCHCRITERIA_NOT_REPLIED:
1825 case MATCHCRITERIA_FORWARDED:
1826 case MATCHCRITERIA_NOT_FORWARDED:
1827 case MATCHCRITERIA_LOCKED:
1828 case MATCHCRITERIA_NOT_LOCKED:
1829 case MATCHCRITERIA_SPAM:
1830 case MATCHCRITERIA_NOT_SPAM:
1831 case MATCHCRITERIA_HAS_ATTACHMENT:
1832 case MATCHCRITERIA_HAS_NO_ATTACHMENT:
1833 case MATCHCRITERIA_SIGNED:
1834 case MATCHCRITERIA_NOT_SIGNED:
1835 case MATCHCRITERIA_COLORLABEL:
1836 case MATCHCRITERIA_NOT_COLORLABEL:
1837 case MATCHCRITERIA_IGNORE_THREAD:
1838 case MATCHCRITERIA_NOT_IGNORE_THREAD:
1839 case MATCHCRITERIA_WATCH_THREAD:
1840 case MATCHCRITERIA_NOT_WATCH_THREAD:
1841 case MATCHCRITERIA_SUBJECT:
1842 case MATCHCRITERIA_NOT_SUBJECT:
1843 case MATCHCRITERIA_FROM:
1844 case MATCHCRITERIA_NOT_FROM:
1845 case MATCHCRITERIA_TO:
1846 case MATCHCRITERIA_NOT_TO:
1847 case MATCHCRITERIA_CC:
1848 case MATCHCRITERIA_NOT_CC:
1849 case MATCHCRITERIA_TO_OR_CC:
1850 case MATCHCRITERIA_NOT_TO_AND_NOT_CC:
1851 case MATCHCRITERIA_TAG:
1852 case MATCHCRITERIA_NOT_TAG:
1853 case MATCHCRITERIA_TAGGED:
1854 case MATCHCRITERIA_NOT_TAGGED:
1855 case MATCHCRITERIA_AGE_GREATER:
1856 case MATCHCRITERIA_AGE_LOWER:
1857 case MATCHCRITERIA_AGE_GREATER_HOURS:
1858 case MATCHCRITERIA_AGE_LOWER_HOURS:
1859 case MATCHCRITERIA_NEWSGROUPS:
1860 case MATCHCRITERIA_NOT_NEWSGROUPS:
1861 case MATCHCRITERIA_INREPLYTO:
1862 case MATCHCRITERIA_NOT_INREPLYTO:
1863 case MATCHCRITERIA_REFERENCES:
1864 case MATCHCRITERIA_NOT_REFERENCES:
1865 case MATCHCRITERIA_SCORE_GREATER:
1866 case MATCHCRITERIA_SCORE_LOWER:
1867 case MATCHCRITERIA_SCORE_EQUAL:
1868 case MATCHCRITERIA_SIZE_GREATER:
1869 case MATCHCRITERIA_SIZE_SMALLER:
1870 case MATCHCRITERIA_SIZE_EQUAL:
1871 case MATCHCRITERIA_TEST:
1872 case MATCHCRITERIA_NOT_TEST:
1873 case MATCHCRITERIA_PARTIAL:
1874 case MATCHCRITERIA_NOT_PARTIAL:
1875 if (matcherprop_match(matcher, info)) {
1876 if (!matchers->bool_and) {
1877 if (debug_filtering_session)
1878 log_status_ok(LOG_DEBUG_FILTERING, _("message matches\n"));
1883 if (matchers->bool_and) {
1884 if (debug_filtering_session)
1885 log_status_nok(LOG_DEBUG_FILTERING, _("message does not match\n"));
1892 /* test the condition on the file */
1894 if (matcherlist_match_file(matchers, info, result)) {
1895 if (!matchers->bool_and) {
1896 if (debug_filtering_session)
1897 log_status_ok(LOG_DEBUG_FILTERING, _("message matches\n"));
1901 if (matchers->bool_and) {
1902 if (debug_filtering_session)
1903 log_status_nok(LOG_DEBUG_FILTERING, _("message does not match\n"));
1908 if (debug_filtering_session) {
1910 log_status_ok(LOG_DEBUG_FILTERING, _("message matches\n"));
1912 log_status_nok(LOG_DEBUG_FILTERING, _("message does not match\n"));
1918 static gint quote_filter_str(gchar * result, guint size,
1928 for(p = path ; * p != '\0' ; p ++) {
1930 if ((* p != '\"') && (* p != '\\')) {
1931 if (remaining > 0) {
1937 result[size - 1] = '\0';
1942 if (remaining >= 2) {
1950 result[size - 1] = '\0';
1955 if (remaining > 0) {
1959 result[size - 1] = '\0';
1967 gchar * matcher_quote_str(const gchar * src)
1972 len = strlen(src) * 2 + 1;
1973 res = g_malloc(len);
1974 quote_filter_str(res, len, src);
1980 *\brief Convert a matcher structure to a string
1982 *\param matcher Matcher structure
1984 *\return gchar * Newly allocated string
1986 gchar *matcherprop_to_string(MatcherProp *matcher)
1988 gchar *matcher_str = NULL;
1989 const gchar *criteria_str;
1990 const gchar *matchtype_str;
1992 gchar * quoted_expr;
1993 gchar * quoted_header;
1995 criteria_str = NULL;
1996 for (i = 0; i < (int) (sizeof(matchparser_tab) / sizeof(MatchParser)); i++) {
1997 if (matchparser_tab[i].id == matcher->criteria)
1998 criteria_str = matchparser_tab[i].str;
2000 if (criteria_str == NULL)
2003 switch (matcher->criteria) {
2004 case MATCHCRITERIA_AGE_GREATER:
2005 case MATCHCRITERIA_AGE_LOWER:
2006 case MATCHCRITERIA_AGE_GREATER_HOURS:
2007 case MATCHCRITERIA_AGE_LOWER_HOURS:
2008 case MATCHCRITERIA_SCORE_GREATER:
2009 case MATCHCRITERIA_SCORE_LOWER:
2010 case MATCHCRITERIA_SCORE_EQUAL:
2011 case MATCHCRITERIA_SIZE_GREATER:
2012 case MATCHCRITERIA_SIZE_SMALLER:
2013 case MATCHCRITERIA_SIZE_EQUAL:
2014 case MATCHCRITERIA_COLORLABEL:
2015 case MATCHCRITERIA_NOT_COLORLABEL:
2016 return g_strdup_printf("%s %i", criteria_str, matcher->value);
2017 case MATCHCRITERIA_ALL:
2018 case MATCHCRITERIA_UNREAD:
2019 case MATCHCRITERIA_NOT_UNREAD:
2020 case MATCHCRITERIA_NEW:
2021 case MATCHCRITERIA_NOT_NEW:
2022 case MATCHCRITERIA_MARKED:
2023 case MATCHCRITERIA_NOT_MARKED:
2024 case MATCHCRITERIA_DELETED:
2025 case MATCHCRITERIA_NOT_DELETED:
2026 case MATCHCRITERIA_REPLIED:
2027 case MATCHCRITERIA_NOT_REPLIED:
2028 case MATCHCRITERIA_FORWARDED:
2029 case MATCHCRITERIA_NOT_FORWARDED:
2030 case MATCHCRITERIA_LOCKED:
2031 case MATCHCRITERIA_NOT_LOCKED:
2032 case MATCHCRITERIA_SPAM:
2033 case MATCHCRITERIA_NOT_SPAM:
2034 case MATCHCRITERIA_HAS_ATTACHMENT:
2035 case MATCHCRITERIA_HAS_NO_ATTACHMENT:
2036 case MATCHCRITERIA_SIGNED:
2037 case MATCHCRITERIA_NOT_SIGNED:
2038 case MATCHCRITERIA_PARTIAL:
2039 case MATCHCRITERIA_NOT_PARTIAL:
2040 case MATCHCRITERIA_IGNORE_THREAD:
2041 case MATCHCRITERIA_NOT_IGNORE_THREAD:
2042 case MATCHCRITERIA_WATCH_THREAD:
2043 case MATCHCRITERIA_NOT_WATCH_THREAD:
2044 case MATCHCRITERIA_TAGGED:
2045 case MATCHCRITERIA_NOT_TAGGED:
2046 return g_strdup(criteria_str);
2047 case MATCHCRITERIA_TEST:
2048 case MATCHCRITERIA_NOT_TEST:
2049 quoted_expr = matcher_quote_str(matcher->expr);
2050 matcher_str = g_strdup_printf("%s \"%s\"",
2051 criteria_str, quoted_expr);
2052 g_free(quoted_expr);
2054 case MATCHCRITERIA_FOUND_IN_ADDRESSBOOK:
2055 case MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK:
2056 quoted_header = matcher_quote_str(matcher->header);
2057 quoted_expr = matcher_quote_str(matcher->expr);
2058 matcher_str = g_strdup_printf("%s \"%s\" in \"%s\"",
2059 criteria_str, quoted_header, quoted_expr);
2060 g_free(quoted_header);
2061 g_free(quoted_expr);
2065 matchtype_str = NULL;
2066 for (i = 0; i < sizeof matchparser_tab / sizeof matchparser_tab[0]; i++) {
2067 if (matchparser_tab[i].id == matcher->matchtype)
2068 matchtype_str = matchparser_tab[i].str;
2071 if (matchtype_str == NULL)
2074 switch (matcher->matchtype) {
2075 case MATCHTYPE_MATCH:
2076 case MATCHTYPE_MATCHCASE:
2077 case MATCHTYPE_REGEXP:
2078 case MATCHTYPE_REGEXPCASE:
2079 quoted_expr = matcher_quote_str(matcher->expr);
2080 if (matcher->header) {
2081 quoted_header = matcher_quote_str(matcher->header);
2082 matcher_str = g_strdup_printf
2083 ("%s \"%s\" %s \"%s\"",
2084 criteria_str, quoted_header,
2085 matchtype_str, quoted_expr);
2086 g_free(quoted_header);
2089 matcher_str = g_strdup_printf
2090 ("%s %s \"%s\"", criteria_str,
2091 matchtype_str, quoted_expr);
2092 g_free(quoted_expr);
2100 *\brief Convert a list of conditions to a string
2102 *\param matchers List of conditions
2104 *\return gchar * Newly allocated string
2106 gchar *matcherlist_to_string(const MatcherList *matchers)
2112 gchar *result = NULL;
2114 count = g_slist_length(matchers->matchers);
2115 vstr = g_new(gchar *, count + 1);
2117 for (l = matchers->matchers, cur_str = vstr; l != NULL;
2118 l = g_slist_next(l), cur_str ++) {
2119 *cur_str = matcherprop_to_string((MatcherProp *) l->data);
2120 if (*cur_str == NULL)
2125 if (matchers->bool_and)
2126 result = g_strjoinv(" & ", vstr);
2128 result = g_strjoinv(" | ", vstr);
2130 for (cur_str = vstr ; *cur_str != NULL ; cur_str ++)
2138 #define STRLEN_ZERO(s) ((s) ? strlen(s) : 0)
2139 #define STRLEN_DEFAULT(s,d) ((s) ? strlen(s) : STRLEN_ZERO(d))
2141 static void add_str_default(gchar ** dest,
2142 const gchar * s, const gchar * d)
2144 gchar quoted_str[4096];
2152 quote_cmd_argument(quoted_str, sizeof(quoted_str), str);
2153 strcpy(* dest, quoted_str);
2155 (* dest) += strlen(* dest);
2158 /* matching_build_command() - preferably cmd should be unescaped */
2160 *\brief Build the command-line to execute
2162 *\param cmd String with command-line specifiers
2163 *\param info Message info to use for command
2165 *\return gchar * Newly allocated string
2167 gchar *matching_build_command(const gchar *cmd, MsgInfo *info)
2169 const gchar *s = cmd;
2170 gchar *filename = NULL;
2171 gchar *processed_cmd;
2175 const gchar *const no_subject = _("(none)") ;
2176 const gchar *const no_from = _("(none)") ;
2177 const gchar *const no_to = _("(none)") ;
2178 const gchar *const no_cc = _("(none)") ;
2179 const gchar *const no_date = _("(none)") ;
2180 const gchar *const no_msgid = _("(none)") ;
2181 const gchar *const no_newsgroups = _("(none)") ;
2182 const gchar *const no_references = _("(none)") ;
2184 size = STRLEN_ZERO(cmd) + 1;
2185 while (*s != '\0') {
2192 case 's': /* subject */
2193 size += STRLEN_DEFAULT(info->subject, no_subject) - 2;
2195 case 'f': /* from */
2196 size += STRLEN_DEFAULT(info->from, no_from) - 2;
2199 size += STRLEN_DEFAULT(info->to, no_to) - 2;
2202 size += STRLEN_DEFAULT(info->cc, no_cc) - 2;
2204 case 'd': /* date */
2205 size += STRLEN_DEFAULT(info->date, no_date) - 2;
2207 case 'i': /* message-id */
2208 size += STRLEN_DEFAULT(info->msgid, no_msgid) - 2;
2210 case 'n': /* newsgroups */
2211 size += STRLEN_DEFAULT(info->newsgroups, no_newsgroups) - 2;
2213 case 'r': /* references */
2214 /* FIXME: using the inreplyto header for reference */
2215 size += STRLEN_DEFAULT(info->inreplyto, no_references) - 2;
2217 case 'F': /* file */
2218 if (filename == NULL)
2219 filename = folder_item_fetch_msg(info->folder, info->msgnum);
2221 if (filename == NULL) {
2222 g_warning("filename is not set");
2226 size += strlen(filename) - 2;
2235 /* as the string can be quoted, we double the result */
2238 processed_cmd = g_new0(gchar, size);
2242 while (*s != '\0') {
2250 case 's': /* subject */
2251 add_str_default(&p, info->subject,
2254 case 'f': /* from */
2255 add_str_default(&p, info->from,
2259 add_str_default(&p, info->to,
2263 add_str_default(&p, info->cc,
2266 case 'd': /* date */
2267 add_str_default(&p, info->date,
2270 case 'i': /* message-id */
2271 add_str_default(&p, info->msgid,
2274 case 'n': /* newsgroups */
2275 add_str_default(&p, info->newsgroups,
2278 case 'r': /* references */
2279 /* FIXME: using the inreplyto header for references */
2280 add_str_default(&p, info->inreplyto, no_references);
2282 case 'F': /* file */
2283 if (filename != NULL)
2284 add_str_default(&p, filename, NULL);
2303 return processed_cmd;
2305 #undef STRLEN_DEFAULT
2308 /* ************************************************************ */
2312 *\brief Write filtering list to file
2315 *\param prefs_filtering List of filtering conditions
2317 static int prefs_filtering_write(FILE *fp, GSList *prefs_filtering)
2321 for (cur = prefs_filtering; cur != NULL; cur = cur->next) {
2322 gchar *filtering_str = NULL;
2323 gchar *tmp_name = NULL;
2324 FilteringProp *prop = NULL;
2326 if (NULL == (prop = (FilteringProp *) cur->data))
2329 if (NULL == (filtering_str = filteringprop_to_string(prop)))
2332 if (prop->enabled) {
2333 if (fputs("enabled ", fp) == EOF) {
2334 FILE_OP_ERROR("filtering config", "fputs");
2338 if (fputs("disabled ", fp) == EOF) {
2339 FILE_OP_ERROR("filtering config", "fputs");
2344 if (fputs("rulename \"", fp) == EOF) {
2345 FILE_OP_ERROR("filtering config", "fputs");
2346 g_free(filtering_str);
2349 tmp_name = prop->name;
2350 while (tmp_name && *tmp_name != '\0') {
2351 if (*tmp_name != '"') {
2352 if (fputc(*tmp_name, fp) == EOF) {
2353 FILE_OP_ERROR("filtering config", "fputs || fputc");
2354 g_free(filtering_str);
2357 } else if (*tmp_name == '"') {
2358 if (fputc('\\', fp) == EOF ||
2359 fputc('"', fp) == EOF) {
2360 FILE_OP_ERROR("filtering config", "fputs || fputc");
2361 g_free(filtering_str);
2367 if (fputs("\" ", fp) == EOF) {
2368 FILE_OP_ERROR("filtering config", "fputs");
2369 g_free(filtering_str);
2373 if (prop->account_id != 0) {
2376 tmp = g_strdup_printf("account %d ", prop->account_id);
2377 if (fputs(tmp, fp) == EOF) {
2378 FILE_OP_ERROR("filtering config", "fputs");
2385 if(fputs(filtering_str, fp) == EOF ||
2386 fputc('\n', fp) == EOF) {
2387 FILE_OP_ERROR("filtering config", "fputs || fputc");
2388 g_free(filtering_str);
2391 g_free(filtering_str);
2397 typedef struct _NodeLoopData {
2403 *\brief Write matchers from a folder item
2405 *\param node Node with folder info
2406 *\param data File pointer
2408 *\return gboolean FALSE
2410 static gboolean prefs_matcher_write_func(GNode *node, gpointer d)
2413 NodeLoopData *data = (NodeLoopData *)d;
2415 GSList *prefs_filtering;
2418 /* prevent warning */
2419 if (item->path == NULL)
2421 id = folder_item_get_identifier(item);
2424 prefs_filtering = item->prefs->processing;
2426 if (prefs_filtering != NULL) {
2427 if (fprintf(data->fp, "[%s]\n", id) < 0) {
2431 if (prefs_filtering_write(data->fp, prefs_filtering) < 0) {
2435 if (fputc('\n', data->fp) == EOF) {
2447 *\brief Save matchers from folder items
2451 static int prefs_matcher_save(FILE *fp)
2459 for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
2462 folder = (Folder *) cur->data;
2463 g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
2464 prefs_matcher_write_func, &data);
2467 if (data.error == TRUE)
2470 /* pre global rules */
2471 if (fprintf(fp, "[preglobal]\n") < 0 ||
2472 prefs_filtering_write(fp, pre_global_processing) < 0 ||
2473 fputc('\n', fp) == EOF)
2476 /* post global rules */
2477 if (fprintf(fp, "[postglobal]\n") < 0 ||
2478 prefs_filtering_write(fp, post_global_processing) < 0 ||
2479 fputc('\n', fp) == EOF)
2482 /* filtering rules */
2483 if (fprintf(fp, "[filtering]\n") < 0 ||
2484 prefs_filtering_write(fp, filtering_rules) < 0 ||
2485 fputc('\n', fp) == EOF)
2492 *\brief Write filtering / matcher configuration file
2494 void prefs_matcher_write_config(void)
2499 debug_print("Writing matcher configuration...\n");
2501 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
2504 if ((pfile = prefs_write_open(rcpath)) == NULL) {
2505 g_warning("failed to write configuration to file\n");
2512 if (prefs_matcher_save(pfile->fp) < 0) {
2513 g_warning("failed to write configuration to file\n");
2514 prefs_file_close_revert(pfile);
2515 } else if (prefs_file_close(pfile) < 0) {
2516 g_warning("failed to save configuration to file\n");
2520 /* ******************************************************************* */
2522 static void matcher_add_rulenames(const gchar *rcpath)
2524 gchar *newpath = g_strconcat(rcpath, ".new", NULL);
2525 FILE *src = g_fopen(rcpath, "rb");
2526 FILE *dst = g_fopen(newpath, "wb");
2527 gchar buf[BUFFSIZE];
2545 while (fgets (buf, sizeof(buf), src) != NULL) {
2546 if (strlen(buf) > 2 && buf[0] != '['
2547 && strncmp(buf, "rulename \"", 10)
2548 && strncmp(buf, "enabled rulename \"", 18)
2549 && strncmp(buf, "disabled rulename \"", 18)) {
2550 r = fwrite("enabled rulename \"\" ",
2551 strlen("enabled rulename \"\" "), 1, dst);
2553 g_message("cannot fwrite rulename\n");
2556 r = fwrite(buf, strlen(buf), 1, dst);
2558 g_message("cannot fwrite rule\n");
2563 move_file(newpath, rcpath, TRUE);
2568 *\brief Read matcher configuration
2570 void prefs_matcher_read_config(void)
2573 gchar *rc_old_format;
2576 create_matchparser_hashtab();
2577 prefs_filtering_clear();
2579 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MATCHER_RC, NULL);
2580 rc_old_format = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MATCHER_RC,
2581 ".pre_names", NULL);
2583 if (!is_file_exist(rc_old_format) && is_file_exist(rcpath)) {
2584 /* backup file with no rules names, in case
2585 * anything goes wrong */
2586 copy_file(rcpath, rc_old_format, FALSE);
2587 /* now hack the file in order to have it to the new format */
2588 matcher_add_rulenames(rcpath);
2591 g_free(rc_old_format);
2593 f = g_fopen(rcpath, "rb");
2597 matcher_parser_start_parsing(f);
2598 fclose(matcher_parserin);
2601 /* previous version compatibility */
2603 /* g_print("reading filtering\n"); */
2604 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
2605 FILTERING_RC, NULL);
2606 f = g_fopen(rcpath, "rb");
2610 matcher_parser_start_parsing(f);
2611 fclose(matcher_parserin);
2614 /* g_print("reading scoring\n"); */
2615 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
2617 f = g_fopen(rcpath, "rb");
2621 matcher_parser_start_parsing(f);
2622 fclose(matcher_parserin);