#include "procmsg.h"
#include "gtkstext.h"
#include "textview.h"
+#include "matcher_parser.h" /* CLAWS */
+#include "filtering.h"
typedef struct _Children Children;
typedef struct _ChildInfo ChildInfo;
guint action_nb,
GSList *msg_list);
+static gboolean execute_filtering_actions(gchar *action,
+ GSList *msglist);
+
static gboolean execute_actions (gchar *action,
GSList *msg_list,
GtkWidget *text,
return ACTION_ERROR;
while (*p && action_type != ACTION_ERROR) {
- if (p[0] == '%') {
+ if (p[0] == '%' && p[1]) {
switch (p[1]) {
+ case 'a':
+ /* CLAWS: filtering action is a mutually exclusive
+ * action. we can enable others if needed later. we
+ * add ACTION_SINGLE | ACTION_MULTIPLE so it will
+ * only be executed from the main window toolbar */
+ if (p[2] == 's') /* source messages */
+ action_type = ACTION_FILTERING_ACTION
+ | ACTION_SINGLE
+ | ACTION_MULTIPLE;
+ break;
case 'f':
action_type |= ACTION_SINGLE;
break;
if (action_type & (ACTION_SINGLE | ACTION_MULTIPLE)) {
alertpanel_warning
(_("The selected action cannot be used in the compose window\n"
- "because it contains %%f, %%F or %%p."));
+ "because it contains %%f, %%F, %%as or %%p."));
return;
}
if (action_type & (ACTION_PIPE_OUT | ACTION_INSERT))
msgview->filtered = TRUE;
- execute_actions(action, msg_list, text, msgfont, body_pos, partinfo);
+ if (action_type & ACTION_FILTERING_ACTION)
+ /* CLAWS: most of the above code is not necessary for applying
+ * filtering */
+ execute_filtering_actions(action, msg_list);
+ else
+ execute_actions(action, msg_list, text, msgfont, body_pos, partinfo);
+}
+
+static gboolean execute_filtering_actions(gchar *action, GSList *msglist)
+{
+ GSList *action_list, *p;
+ const gchar *sbegin, *send;
+ gchar *action_string;
+
+ if (NULL == (sbegin = strstr2(action, "%as{")))
+ return FALSE;
+ sbegin += sizeof "%as{" - 1;
+ if (NULL == (send = strrchr(sbegin, '}')))
+ return FALSE;
+ action_string = g_strndup(sbegin, send - sbegin);
+
+ action_list = matcher_parser_get_action_list(action_string);
+ g_free(action_string);
+ if (action_list == NULL) return FALSE;
+
+ /* apply actions on each message info */
+ for (p = msglist; p && p->data; p = g_slist_next(p))
+ filteringaction_apply_action_list(action_list, (MsgInfo *) p->data);
+
+ for (p = action_list; p; p = g_slist_next(p))
+ if (p->data) filteringaction_free(p->data);
+ g_slist_free(action_list);
+ return TRUE;
}
static gboolean execute_actions(gchar *action, GSList *msg_list,
return FALSE;
}
+gboolean filteringaction_apply_action_list(GSList *action_list, MsgInfo *info)
+{
+ GSList *p;
+ g_return_val_if_fail(action_list, FALSE);
+ g_return_val_if_fail(info, FALSE);
+ for (p = action_list; p && p->data; p = g_slist_next(p)) {
+ FilteringAction *a = (FilteringAction *) p->data;
+ if (filteringaction_apply(a, info)) {
+ if (filtering_is_final_action(a))
+ break;
+ } else
+ return FALSE;
+
+ }
+ return TRUE;
+}
+
static gboolean filtering_match_condition(FilteringProp *filtering, MsgInfo *info)
{
return matcherlist_match(filtering->matchers, info);