2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto & The Sylpheed Claws Team
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 2 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * initital Hoa initial
22 * 07/16/01 Alfons fix bugs
23 * 07/18/01 Alfons rewrite things
28 * filter_message() is no longer the entry point for filtering. it's
29 * replaced with filter_incoming_message() which does not trust
30 * on MsgInfo's from a folder. instead it directly works with
32 * updating the mark file is a lot easier now, because we can do that
33 * right after a call to folder_item_add_msg().
45 #include "procheader.h"
47 #include "filtering.h"
51 #define PREFSBUFSIZE 1024
53 GSList * global_processing = NULL;
55 FilteringAction * filteringaction_new(int type, int account_id,
59 FilteringAction * action;
61 action = g_new0(FilteringAction, 1);
64 action->account_id = account_id;
66 action->destination = g_strdup(destination);
67 action->labelcolor = labelcolor;
71 void filteringaction_free(FilteringAction * action)
73 if (action->destination)
74 g_free(action->destination);
78 FilteringProp * filteringprop_new(MatcherList * matchers,
79 FilteringAction * action)
81 FilteringProp * filtering;
83 filtering = g_new0(FilteringProp, 1);
84 filtering->matchers = matchers;
85 filtering->action = action;
90 void filteringprop_free(FilteringProp * prop)
92 matcherlist_free(prop->matchers);
93 filteringaction_free(prop->action);
97 /* filteringaction_update_mark() - updates a mark for a message. note that
98 * the message should not have been moved or copied. remember that the
99 * procmsg_open_mark_file(PATH, TRUE) actually _appends_ a new record.
101 static gboolean filteringaction_update_mark(MsgInfo * info)
106 if (info->folder->folder->type == F_MH) {
107 dest_path = folder_item_get_path(info->folder);
108 if (!is_dir_exist(dest_path))
109 make_dir_hier(dest_path);
111 if (dest_path == NULL) {
112 g_warning(_("Can't open mark file.\n"));
116 if ((fp = procmsg_open_mark_file(dest_path, TRUE))
118 g_warning(_("Can't open mark file.\n"));
122 procmsg_write_flags(info, fp);
129 static inline gint strlen_with_check(const gchar *expr, gint fline, const gchar *str)
134 debug_print("%s(%d) - invalid string %s\n", __FILE__, fline, expr);
139 #define STRLEN_WITH_CHECK(expr) \
140 strlen_with_check(#expr, __LINE__, expr)
142 static gchar * filteringaction_execute_command(gchar * cmd, MsgInfo * info)
145 gchar * filename = NULL;
146 gchar * processed_cmd;
150 matcher_unescape_str(cmd);
152 size = strlen(cmd) + 1;
160 case 's': /* subject */
161 size += STRLEN_WITH_CHECK(info->subject) - 2;
164 size += STRLEN_WITH_CHECK(info->from) - 2;
167 size += STRLEN_WITH_CHECK(info->to) - 2;
170 size += STRLEN_WITH_CHECK(info->cc) - 2;
173 size += STRLEN_WITH_CHECK(info->date) - 2;
175 case 'i': /* message-id */
176 size += STRLEN_WITH_CHECK(info->msgid) - 2;
178 case 'n': /* newsgroups */
179 size += STRLEN_WITH_CHECK(info->newsgroups) - 2;
181 case 'r': /* references */
182 size += STRLEN_WITH_CHECK(info->references) - 2;
185 if (MSG_IS_FILTERING(info->flags))
186 filename = g_strdup((gchar *)info->folder);
188 filename = folder_item_fetch_msg(info->folder, info->msgnum);
190 if (filename == NULL) {
191 g_warning(_("filename is not set"));
195 size += strlen(filename) - 2;
204 processed_cmd = g_new0(gchar, size);
216 case 's': /* subject */
217 if (info->subject != NULL)
218 strcpy(p, info->subject);
224 if (info->from != NULL)
225 strcpy(p, info->from);
231 if (info->to != NULL)
238 if (info->cc != NULL)
245 if (info->date != NULL)
246 strcpy(p, info->date);
251 case 'i': /* message-id */
252 if (info->msgid != NULL)
253 strcpy(p, info->msgid);
258 case 'n': /* newsgroups */
259 if (info->newsgroups != NULL)
260 strcpy(p, info->newsgroups);
265 case 'r': /* references */
266 if (info->references != NULL)
267 strcpy(p, info->references);
293 return processed_cmd;
297 fitleringaction_apply
298 runs the action on one MsgInfo
299 return value : return TRUE if the action could be applied
302 #define CHANGE_FLAGS(msginfo) \
304 if (msginfo->folder->folder->change_flags != NULL) \
305 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
310 static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
311 GHashTable *folder_table)
313 FolderItem * dest_folder;
316 PrefsAccount * account;
319 switch(action->type) {
320 case MATCHACTION_MOVE:
322 folder_find_item_from_identifier(action->destination);
326 if (folder_item_move_msg(dest_folder, info) == -1) {
330 /* WRONG: can not update the mark, because the message has
331 * been moved. info pertains to original location.
332 * folder_item_move_msg() already updated the mark for the
333 * destination folder.
335 filteringaction_update_mark(info);
338 val = GPOINTER_TO_INT(g_hash_table_lookup
339 (folder_table, dest_folder));
341 folder_item_scan(dest_folder);
342 g_hash_table_insert(folder_table, dest_folder,
345 val = GPOINTER_TO_INT(g_hash_table_lookup
346 (folder_table, info->folder));
348 folder_item_scan(info->folder);
349 g_hash_table_insert(folder_table, info->folder,
355 case MATCHACTION_COPY:
357 folder_find_item_from_identifier(action->destination);
362 /* NOTE: the following call *will* update the mark file for
363 * the destination folder. but the original message will
364 * still be there in the inbox. */
366 if (folder_item_copy_msg(dest_folder, info) == -1)
370 val = GPOINTER_TO_INT(g_hash_table_lookup
371 (folder_table, dest_folder));
373 folder_item_scan(dest_folder);
374 g_hash_table_insert(folder_table, dest_folder,
380 case MATCHACTION_DELETE:
381 if (folder_item_remove_msg(info->folder, info->msgnum) == -1)
384 /* WRONG: can not update the mark. this would actually add
385 * a bogus record to the mark file for the message's original
388 filteringaction_update_mark(info);
393 case MATCHACTION_MARK:
394 MSG_SET_PERM_FLAGS(info->flags, MSG_MARKED);
395 debug_print("*** MARKING message %d, in folder %s, \"%s\"\n",
396 info->msgnum, info->folder->name,
397 info->subject ? info->subject : "<none>");
398 filteringaction_update_mark(info);
404 case MATCHACTION_UNMARK:
405 MSG_UNSET_PERM_FLAGS(info->flags, MSG_MARKED);
406 filteringaction_update_mark(info);
412 case MATCHACTION_MARK_AS_READ:
413 MSG_UNSET_PERM_FLAGS(info->flags, MSG_UNREAD | MSG_NEW);
414 filteringaction_update_mark(info);
420 case MATCHACTION_MARK_AS_UNREAD:
421 MSG_SET_PERM_FLAGS(info->flags, MSG_UNREAD | MSG_NEW);
422 filteringaction_update_mark(info);
428 case MATCHACTION_FORWARD:
430 account = account_find_from_id(action->account_id);
431 compose = compose_forward(account, info, FALSE);
432 if (compose->account->protocol == A_NNTP)
433 compose_entry_append(compose, action->destination,
436 compose_entry_append(compose, action->destination,
439 val = compose_send(compose);
441 gtk_widget_destroy(compose->window);
445 gtk_widget_destroy(compose->window);
448 case MATCHACTION_FORWARD_AS_ATTACHMENT:
450 account = account_find_from_id(action->account_id);
451 compose = compose_forward(account, info, TRUE);
452 if (compose->account->protocol == A_NNTP)
453 compose_entry_append(compose, action->destination,
456 compose_entry_append(compose, action->destination,
459 val = compose_send(compose);
461 gtk_widget_destroy(compose->window);
465 gtk_widget_destroy(compose->window);
468 case MATCHACTION_BOUNCE:
470 account = account_find_from_id(action->account_id);
471 compose = compose_bounce(account, info);
472 if (compose->account->protocol == A_NNTP)
475 compose_entry_append(compose, action->destination,
478 val = compose_send(compose);
480 gtk_widget_destroy(compose->window);
484 gtk_widget_destroy(compose->window);
487 case MATCHACTION_EXECUTE:
489 cmd = matching_build_command(action->destination, info);
504 /* filteringprop_apply() - runs the action on one MsgInfo if it matches the
505 * criterium. certain actions can be followed by other actions. in this
506 * case the function returns FALSE. if an action can not be followed
507 * by others, the function returns TRUE.
509 * remember that this is because of the fact that msg flags are always
510 * _appended_ to mark files. currently sylpheed does not insert messages
511 * at a certain index.
512 * now, after having performed a certain action, the MsgInfo is still
513 * valid for the message. in *this* case the function returns FALSE.
515 static gboolean filteringprop_apply(FilteringProp * filtering, MsgInfo * info,
516 GHashTable *folder_table)
518 if (matcherlist_match(filtering->matchers, info)) {
523 if (FALSE == (result = filteringaction_apply(filtering->action, info,
525 action_str = filteringaction_to_string(buf, sizeof buf, filtering->action);
526 g_warning(_("action %s could not be applied"), action_str);
530 switch(filtering->action->type) {
531 case MATCHACTION_MOVE:
532 case MATCHACTION_DELETE:
533 return TRUE; /* MsgInfo invalid for message */
534 case MATCHACTION_EXECUTE:
535 case MATCHACTION_COPY:
536 case MATCHACTION_MARK:
537 case MATCHACTION_MARK_AS_READ:
538 case MATCHACTION_UNMARK:
539 case MATCHACTION_MARK_AS_UNREAD:
540 case MATCHACTION_FORWARD:
541 case MATCHACTION_FORWARD_AS_ATTACHMENT:
542 case MATCHACTION_BOUNCE:
543 return FALSE; /* MsgInfo still valid for message */
552 void filter_msginfo(GSList * filtering_list, MsgInfo * info,
553 GHashTable *folder_table)
558 g_warning(_("msginfo is not set"));
562 for(l = filtering_list ; l != NULL ; l = g_slist_next(l)) {
563 FilteringProp * filtering = (FilteringProp *) l->data;
565 if (filteringprop_apply(filtering, info, folder_table))
570 void filter_msginfo_move_or_delete(GSList * filtering_list, MsgInfo * info,
571 GHashTable *folder_table)
576 g_warning(_("msginfo is not set"));
580 for(l = filtering_list ; l != NULL ; l = g_slist_next(l)) {
581 FilteringProp * filtering = (FilteringProp *) l->data;
583 switch (filtering->action->type) {
584 case MATCHACTION_MOVE:
585 case MATCHACTION_DELETE:
586 if (filteringprop_apply(filtering, info, folder_table))
592 void filter_message(GSList * filtering_list, FolderItem * item,
593 gint msgnum, GHashTable *folder_table)
597 MsgFlags msgflags = { 0, 0 };
600 g_warning(_("folderitem not set"));
604 filename = folder_item_fetch_msg(item, msgnum);
606 if (filename == NULL) {
607 g_warning(_("filename is not set"));
611 msginfo = procheader_parse(filename, msgflags, TRUE);
615 if (msginfo == NULL) {
616 g_warning(_("could not get info for %s"), filename);
620 msginfo->folder = item;
621 msginfo->msgnum = msgnum;
623 filter_msginfo(filtering_list, msginfo, folder_table);
627 /******************************************************************************/
629 /* revised filtering system.
631 * 07/18/01 alfons initial revisement
636 * the revised filtering system does not rely on a message being "registered"
637 * in one of sylpheed's folders. it now uses the file sylpheed created on
638 * incorporation of mail.
639 * i do use MsgInfo data; that's needed by the matcher, but for the rest
640 * the MsgInfo is not really used. */
643 /* add_mark() - adds a mark for a file */
644 static void add_mark(FolderItem *folder, gint msgnum, MsgPermFlags flags)
649 if (folder->folder->type == F_MH) {
650 dest_path = folder_item_get_path(folder);
651 if (!is_dir_exist(dest_path))
652 make_dir_hier(dest_path);
654 if (dest_path == NULL) {
655 g_warning(_("Can't open mark file.\n"));
659 if ((fp = procmsg_open_mark_file(dest_path, TRUE))
661 g_warning(_("Can't open mark file.\n"));
665 /* TODO: straight from procmsg.c:procmsg_write_flags()
666 * should update this when mark file version changes */
667 #if MARK_VERSION == 2
668 WRITE_CACHE_DATA_INT(msgnum, fp);
669 WRITE_CACHE_DATA_INT(flags, fp);
671 #error should rewrite the above for new mark version
672 /* paste the source code of procmsg.c:procmsg_write_flags() */
680 /* prepare_destination() - prepares destination folder by registering it
681 * in the global folder table (if not already there). it returns TRUE if
682 * successful. it also returns the FolderItem for the destination */
683 static gboolean prepare_destination(const gchar *destination, FolderItem **item,
684 GHashTable *folder_table)
689 result = folder_find_item_from_identifier(destination);
694 val = GPOINTER_TO_INT(g_hash_table_lookup(folder_table, *item));
696 folder_item_scan(*item);
697 g_hash_table_insert(folder_table, *item, GINT_TO_POINTER(1));
703 /* filter_incoming_perform_actions() - performs actions on incoming
704 * message. this function handles updating marks a little bit smarter;
705 * remember that marks can only be appended. */
706 static gboolean filter_incoming_perform_actions(FolderItem *default_folder,
708 GHashTable *folder_table)
710 /* matching actions for msginfo */
711 struct matching_action {
712 FilteringAction *action;
713 struct matching_action *next;
716 struct matching_action ma_head = { NULL, NULL };
717 struct matching_action *ma_tail = &ma_head;
719 /* need this for the forwarding stuff */
720 PrefsAccount *account;
727 MsgFlags markflags = { 0, 0 };
729 /* use the global prefs_filtering list */
730 GSList * list = global_processing;
732 /* things we get after having added a message to a folder */
733 FolderItem *dest_folder;
736 /* after performing certain action, we may have to copy
737 * the message to inbox too */
738 gboolean copy_to_inbox_too = TRUE;
740 /* filename is only put in msginfo->folder if MSG_FILTERING is set. */
741 const gchar *filename = (gchar *) msginfo->folder;
747 /* build list of matching actions */
748 for (; list != NULL; list = g_slist_next(list)) {
749 FilteringProp *prop = (FilteringProp *) list->data;
751 if (!matcherlist_match(prop->matchers, msginfo))
754 if (NULL == (ma_tail->next = alloca(sizeof(struct matching_action)))) {
755 debug_print(_("action allocation error\n"));
759 debug_print("*** action %d\n", prop->action->type);
761 ma_tail->action = prop->action;
762 ma_tail->next->action = NULL;
763 ma_tail->next->next = NULL;
764 ma_tail = ma_tail->next;
767 debug_print("*** collecting marks\n");
769 /* collect all marks */
770 for (ma_tail = &ma_head, stop = FALSE; ma_tail->action && !stop; ma_tail = ma_tail->next) {
771 switch (ma_tail->action->type) {
773 case MATCHACTION_MARK:
774 MSG_SET_PERM_FLAGS(markflags, MSG_MARKED);
777 case MATCHACTION_UNMARK:
778 MSG_UNSET_PERM_FLAGS(markflags, MSG_MARKED);
781 case MATCHACTION_MARK_AS_READ:
782 MSG_UNSET_PERM_FLAGS(markflags, MSG_UNREAD);
785 case MATCHACTION_MARK_AS_UNREAD:
786 MSG_SET_PERM_FLAGS(markflags, MSG_UNREAD);
789 case MATCHACTION_COLOR:
790 MSG_SET_COLORLABEL_VALUE(markflags, ma_tail->action->labelcolor);
794 case MATCHACTION_FORWARD:
795 case MATCHACTION_FORWARD_AS_ATTACHMENT:
796 case MATCHACTION_BOUNCE:
797 case MATCHACTION_MOVE:
798 case MATCHACTION_DELETE:
808 /* msgnum & dest_folder should have valid values after a succesful
809 * drop; in this case there is a MsgInfo available */
813 debug_print("*** performing actions\n");
815 for (ma_tail = &ma_head ; ma_tail->action; ma_tail = ma_tail->next) {
817 /* there are variables you have to use when defining new actions:
819 * copy_to_inbox_too - if the original message should be copied to the inbox
820 * (default_folder) too.
822 * also note that after dropping it to a folder (folder_item_add_msg()) you have
823 * to mark the message, just to make sure any defined mark actions are applied. */
825 #define ACTION (ma_tail->action->type)
827 /* C O N T I N U A B L E */
829 if (MATCHACTION_COPY == ACTION) {
830 debug_print("*** performing copy\n");
831 copy_to_inbox_too = TRUE;
832 if (!prepare_destination(ma_tail->action->destination, &dest_folder, folder_table)) {
833 debug_print("Rule failed: unknown destination %s\n", ma_tail->action->destination);
834 continue; /* try next action */
836 if (0 > (msgnum = folder_item_add_msg(dest_folder, filename, FALSE))) {
837 debug_print(_("Rule failed: could not copy to folder %s\n"),
838 ma_tail->action->destination);
839 continue; /* try next action */
841 flags = msginfo->flags.perm_flags | markflags.perm_flags;
842 add_mark(dest_folder, msgnum, flags);
844 else if (MATCHACTION_EXECUTE == ACTION) {
845 debug_print("*** performing exec\n");
846 copy_to_inbox_too = TRUE;
848 /* matching_build_command() knows about filtering */
849 cmd = matching_build_command(ma_tail->action->destination, msginfo);
855 debug_print(_("Rule failed: no command line\n"));
858 /* U N C O N T I N U A B L E */
860 else if (MATCHACTION_FORWARD == ACTION
861 || MATCHACTION_FORWARD_AS_ATTACHMENT == ACTION) {
862 debug_print("*** performing forward\n");
864 /* forwarding messages is complicated because there's currently no
865 * way to forward a message using "filenames"; you can only forward
866 * a message if you have its MsgInfo. this means we have to drop
867 * the message first */
868 if (0 > (msgnum = folder_item_add_msg(default_folder, filename, FALSE))) {
869 debug_print(_("Rule failed: could not forward\n"));
870 copy_to_inbox_too = TRUE;
874 flags = msginfo->flags.perm_flags | markflags.perm_flags;
875 flags |= MSG_FORWARDED;
876 add_mark(default_folder, msgnum, flags);
878 /* grab the dropped message */
879 fwd_msg_name = folder_item_fetch_msg(default_folder, msgnum);
881 tmp.perm_flags = tmp.tmp_flags = 0;
882 fwd_msg = procheader_parse(fwd_msg_name, tmp, TRUE);
884 fwd_msg->folder = default_folder;
885 fwd_msg->msgnum = msgnum;
887 /* do the compose_XXX stuff */
888 account = account_find_from_id(ma_tail->action->account_id);
889 compose = compose_forward(account, fwd_msg, ACTION == MATCHACTION_FORWARD ? FALSE : TRUE);
890 if (compose->account->protocol == A_NNTP)
891 compose_entry_append(compose, ma_tail->action->destination,
894 compose_entry_append(compose, ma_tail->action->destination,
897 compose_send(compose);
899 procmsg_msginfo_free(fwd_msg);
901 gtk_widget_destroy(compose->window);
904 else if (MATCHACTION_BOUNCE == ACTION) {
905 if (0 > (msgnum = folder_item_add_msg(default_folder, filename, FALSE))) {
906 debug_print(_("Rule failed: could not forward\n"));
907 copy_to_inbox_too = TRUE;
911 /* grab the dropped message */
912 fwd_msg_name = folder_item_fetch_msg(default_folder, msgnum);
914 fwd_msg = procheader_parse(fwd_msg_name, tmp, TRUE);
916 fwd_msg->folder = default_folder;
917 fwd_msg->msgnum = msgnum;
919 /* do the compose_XXX stuff */
920 account = account_find_from_id(ma_tail->action->account_id);
921 compose = compose_bounce(account, fwd_msg);
922 if (compose->account->protocol == A_NNTP)
925 compose_entry_append(compose, ma_tail->action->destination,
928 compose_send(compose);
930 procmsg_msginfo_free(fwd_msg);
932 gtk_widget_destroy(compose->window);
935 else if (MATCHACTION_DELETE == ACTION) {
936 debug_print("*** performing delete\n");
937 copy_to_inbox_too = FALSE;
940 dest_folder = folder_get_default_trash();
941 msgnum = folder_item_add_msg(dest_folder, filename, FALSE);
943 debug_print(_("Rule failed: could not move to trash"));
944 copy_to_inbox_too = TRUE;
947 flags = msginfo->flags.perm_flags | markflags.perm_flags;
948 add_mark(dest_folder, msgnum, flags);
952 else if (MATCHACTION_MOVE == ACTION) {
953 debug_print("*** performing move\n");
954 copy_to_inbox_too = FALSE;
956 if (!prepare_destination(ma_tail->action->destination, &dest_folder, folder_table)) {
957 copy_to_inbox_too = TRUE;
961 msgnum = folder_item_add_msg(dest_folder, filename, FALSE);
963 debug_print(_("Rule failed: could not move to folder %s\n"),
964 ma_tail->action->destination);
965 copy_to_inbox_too = TRUE;
969 flags = msginfo->flags.perm_flags | markflags.perm_flags;
970 add_mark(dest_folder, msgnum, flags);
975 /* may need to copy it to inbox too */
976 if (copy_to_inbox_too) {
977 debug_print("*** performing inbox copy\n");
978 msgnum = folder_item_add_msg(default_folder, filename, TRUE);
980 debug_print(_("error copying incoming file %s to inbox\n"),
984 flags = msginfo->flags.perm_flags | markflags.perm_flags;
985 add_mark(default_folder, msgnum, flags);
988 debug_print("*** unlinking\n");
989 if (unlink(filename) < 0)
990 debug_print(_("error deleting incoming message file\n"));
998 static void filter_incoming_msginfo(FolderItem *default_folder, MsgInfo *msginfo,
999 GHashTable *folder_table)
1001 filter_incoming_perform_actions(default_folder, msginfo, folder_table);
1004 /* filter_incoming_message() - tries to apply a filter on one incoming message.
1005 * it also handles the case when there's no filter match */
1006 void filter_incoming_message(FolderItem *default_folder, const gchar *file_name,
1007 GHashTable *folder_table)
1010 MsgFlags msgflags = { 0, 0 };
1012 /* make an "uncomplete" msginfo. it's incomplete because it doesn't
1013 * have a message number / folder yet. */
1014 if (NULL == (msginfo = procheader_parse(file_name, msgflags, TRUE))) {
1015 g_warning(_("error filtering incoming message %s\n"),
1020 /* let matcher know that this is a message that has no
1021 * valid body data yet. */
1022 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_FILTERING);
1023 msginfo->folder = (FolderItem *) g_strdup(file_name); /* actually storing a pointer to a string */
1024 msginfo->msgnum = 0;
1026 filter_incoming_msginfo(default_folder, msginfo, folder_table);
1028 g_free(msginfo->folder);
1029 procmsg_msginfo_free(msginfo);
1032 /****************************************************************************/
1036 gchar *filteringaction_to_string(gchar *dest, gint destlen, FilteringAction *action)
1040 command_str = get_matchparser_tab_str(action->type);
1042 if (command_str == NULL)
1045 switch(action->type) {
1046 case MATCHACTION_MOVE:
1047 case MATCHACTION_COPY:
1048 case MATCHACTION_EXECUTE:
1049 g_snprintf(dest, destlen, "%s \"%s\"", command_str, action->destination);
1052 case MATCHACTION_DELETE:
1053 case MATCHACTION_MARK:
1054 case MATCHACTION_UNMARK:
1055 case MATCHACTION_MARK_AS_READ:
1056 case MATCHACTION_MARK_AS_UNREAD:
1057 g_snprintf(dest, destlen, "%s", command_str);
1060 case MATCHACTION_BOUNCE:
1061 case MATCHACTION_FORWARD:
1062 case MATCHACTION_FORWARD_AS_ATTACHMENT:
1063 g_snprintf(dest, destlen, "%s %d \"%s\"", command_str, action->account_id, action->destination);
1066 case MATCHACTION_COLOR:
1067 g_snprintf(dest, destlen, "%s %d", command_str, action->labelcolor);
1070 g_snprintf(dest, destlen, "%s %d \"%s\"", command_str,
1071 action->account_id, action->destination);
1079 gchar * filteringprop_to_string(FilteringProp * prop)
1083 gchar *filtering_str;
1086 action_str = filteringaction_to_string(buf, sizeof buf, prop->action);
1088 if (action_str == NULL)
1091 list_str = matcherlist_to_string(prop->matchers);
1093 if (list_str == NULL)
1096 filtering_str = g_strconcat(list_str, " ", action_str, NULL);
1099 return filtering_str;
1102 void prefs_filtering_free(GSList * prefs_filtering)
1104 while (prefs_filtering != NULL) {
1105 FilteringProp * filtering = (FilteringProp *)
1106 prefs_filtering->data;
1107 filteringprop_free(filtering);
1108 prefs_filtering = g_slist_remove(prefs_filtering, filtering);
1112 static gboolean prefs_filtering_free_func(GNode *node, gpointer data)
1114 FolderItem *item = node->data;
1119 prefs_filtering_free(item->prefs->processing);
1120 item->prefs->processing = NULL;
1125 void prefs_filtering_clear()
1129 for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
1132 folder = (Folder *) cur->data;
1133 g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
1134 prefs_filtering_free_func, NULL);
1137 prefs_filtering_free(global_processing);
1138 global_processing = NULL;