* src/actions.[ch]
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 14 Sep 2003 10:28:01 +0000 (10:28 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 14 Sep 2003 10:28:01 +0000 (10:28 +0000)
* src/filtering.[ch]
* src/prefs_actions.c
allow `filtering actions` in actions; only for advanced users
right now: try for example, "%as{mark color 2}"

ChangeLog.claws
configure.ac
src/action.c
src/action.h
src/filtering.c
src/filtering.h
src/prefs_actions.c

index 010403f..55e7664 100644 (file)
@@ -1,3 +1,11 @@
+2003-09-14 [alfons]    0.9.5claws10
+       
+       * src/actions.[ch]
+       * src/filtering.[ch]
+       * src/prefs_actions.c
+               allow `filtering actions` in actions; only for advanced users
+               right now: try for example, "%as{mark color 2}" 
+       
 2003-09-13 [paul]      0.9.5claws9
        
        * po/pl.po
index 294c0a2..0932559 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=9
+EXTRA_VERSION=10
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
index fc5bc80..a6171c9 100644 (file)
@@ -49,6 +49,8 @@
 #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;
@@ -112,6 +114,9 @@ static void message_actions_execute (MessageView    *msgview,
                                         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,
@@ -191,8 +196,18 @@ ActionType action_get_type(const gchar *action_str)
                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;
@@ -471,7 +486,7 @@ static void compose_actions_execute_cb(Compose *compose, guint action_nb,
        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;
        }
 
@@ -534,7 +549,39 @@ static void message_actions_execute(MessageView *msgview, guint action_nb,
        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,
index a7abadb..9f4179f 100644 (file)
@@ -41,6 +41,7 @@ typedef enum
        ACTION_USER_STR         = 1 << 9,
        ACTION_USER_HIDDEN_STR  = 1 << 10,
        ACTION_SELECTION_STR    = 1 << 11,
+       ACTION_FILTERING_ACTION = 1 << 12,
        ACTION_ERROR            = 1 << 30
 } ActionType;
 
index 2bba091..9dbe9b7 100644 (file)
@@ -339,6 +339,23 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info)
        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);
index bda6ca5..2f3ffc8 100644 (file)
@@ -50,6 +50,7 @@ FilteringAction * filteringaction_new(int type, int account_id,
                                      gint labelcolor);
 void filteringaction_free(FilteringAction *action);
 FilteringAction * filteringaction_parse(gchar **str);
+gboolean filteringaction_apply_action_list (GSList *action_list, MsgInfo *info);
 
 FilteringProp * filteringprop_new(MatcherList *matchers,
                                  GSList *action_list);
index e976814..5068a7b 100644 (file)
@@ -654,6 +654,7 @@ static gchar *actions_desc_strings[] = {
        "     %u",  N_("for a user provided argument"),
        "     %h",  N_("for a user provided hidden argument (e.g. password)"),
        "     %s",  N_("for the text selection"),
+       "  %as{}",  N_("apply filtering actions between {} to selected messages"),
        NULL
 };