fix actions: escaping, forwarding, execute
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Thu, 19 Jul 2001 21:18:57 +0000 (21:18 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Thu, 19 Jul 2001 21:18:57 +0000 (21:18 +0000)
ChangeLog.claws
src/filtering.c
src/matcher.c
src/matcher.h
src/prefs_filtering.c

index c0fe76bafaa396250498d9337258f7317a4fd8b7..bd20342503bbaf49ca08628c66845552dddb46f4 100644 (file)
@@ -1,3 +1,15 @@
+2001-07-19 [alfons]
+
+       * src/matcher.[ch], src/filtering.c, src/prefs_filtering.c
+               fix messy handling of escaping... now at least the
+               execute command is useful. escape char is '\', we
+               accept \n and \r too. 
+
+               Real life example:
+               
+               subject match "GIMME YOUR FILTERS" execute "mail -s \"%f don\'t hurt me, please!\" %f < ~/.sylpheed/filteringrc
+               subject match "GIMME YOUR FILTERS" execute "mail -s \"mommy, mommy, %f is being mean!\" admin < %F
+
 2001-07-18 [alfons]
 
        0.5.0claws6
index e1806bf66a6915e10511d91c7fd405f5d7464dcb..edf0d08e2659a589c4db12ed96f6b3f693cba5eb 100644 (file)
@@ -127,6 +127,7 @@ FilteringAction * filteringaction_parse(gchar ** str)
        }
 
        * str = tmp;
+
        action = filteringaction_new(key, account_id, destination);
 
        return action;
@@ -240,6 +241,8 @@ static gchar * filteringaction_execute_command(gchar * cmd, MsgInfo * info)
        gchar * p;
        gint size;
 
+       matcher_unescape_str(cmd);
+
        size = strlen(cmd) + 1;
        while (*s != '\0') {
                if (*s == '%') {
@@ -947,6 +950,7 @@ static gboolean filter_incoming_perform_actions(FolderItem *default_folder,
                        }
                                
                        flags = msginfo->flags.perm_flags | markflags.perm_flags;
+                       flags |= MSG_FORWARDED;
                        add_mark(default_folder, msgnum, flags);
 
                        /* grab the dropped message */
@@ -955,9 +959,12 @@ static gboolean filter_incoming_perform_actions(FolderItem *default_folder,
                        tmp.perm_flags = tmp.tmp_flags = 0;
                        fwd_msg = procheader_parse(fwd_msg_name, tmp, TRUE);
 
+                       fwd_msg->folder = default_folder;
+                       fwd_msg->msgnum = msgnum;
+
                        /* do the compose_XXX stuff */
                        account = account_find_from_id(ma_tail->action->account_id);
-                       compose = compose_forward(account, fwd_msg, ma_tail->action->type == ACTION ? FALSE : TRUE);
+                       compose = compose_forward(account, fwd_msg, ACTION == MATCHING_ACTION_FORWARD ? FALSE : TRUE);
                        if (compose->account->protocol == A_NNTP)
                                compose_entry_append(compose, ma_tail->action->destination,
                                                     COMPOSE_NEWSGROUPS);
index ccd394da63edc4a0d90e170b0cee8e932065dcde..06b5f1244fa153d6b94a9acdadb058712e4dfdfc 100644 (file)
@@ -407,6 +407,10 @@ gchar * matcher_parse_regexp(gchar ** str)
        return g_strdup(start);
 }
 
+/* matcher_parse_str() - parses a string until it hits a 
+ * terminating \". to unescape characters use \. The string
+ * should not be used directly: matcher_unescape_str() 
+ * returns a string that can be used directly. */
 gchar * matcher_parse_str(gchar ** str)
 {
        gchar * p;
@@ -429,22 +433,52 @@ gchar * matcher_parse_str(gchar ** str)
        p ++;
        start = p;
        dest = p;
-       while (*p != '"') {
+
+       for ( ; *p && *p != '\"'; p++, dest++) {
                if (*p == '\\') {
-                       p++;
+                       *dest++ = *p++;
                        *dest = *p;
                }
-               else
+               else 
                        *dest = *p;
-               dest++;
-               p++;
        }
        *dest = '\0';
-
+       
        *str += dest - dup + 2;
        return g_strdup(start);
 }
 
+gchar *matcher_unescape_str(gchar *str)
+{
+       gchar *tmp = alloca(strlen(str) + 1);
+       register gchar *src = tmp;
+       register gchar *dst = str;
+       
+       strcpy(tmp, str);
+
+       for ( ; *src; src++) {
+               if (*src != '\\') 
+                       *dst++ = *src;
+               else {
+                       src++;
+                       if (*src == '\\')
+                               *dst++ = '\\';
+                       else if (*src == 'n')
+                               *dst++ = '\n';
+                       else if (*src == 'r') 
+                               *dst++ = '\r';
+                       else if (*src == '\'' || *src == '\"')
+                               *dst++ = *src;
+                       else {
+                               src--;
+                               *dst++ = *src;
+                       }                               
+               }
+       }
+       *dst = 0;
+       return str;
+}
+
 /* **************** data structure allocation **************** */
 
 
@@ -1280,6 +1314,8 @@ gchar * matching_build_command(gchar * cmd, MsgInfo * info)
        gchar * p;
        gint size;
 
+       matcher_unescape_str(cmd);
+
        size = strlen(cmd) + 1;
        while (*s != '\0') {
                if (*s == '%') {
@@ -1419,6 +1455,8 @@ gchar * matching_build_command(gchar * cmd, MsgInfo * info)
                }
        }
 
+       debug_print("*** exec string \"%s\"\n", processed_cmd);
+
        g_free(filename);
        return processed_cmd;
 }
index 6afad950bb59b44369bc9f508a80739f2e3d61c1..29a3ca9e5888bb91af5edfaa47d1eca25884ed4a 100644 (file)
@@ -118,6 +118,7 @@ gint matcher_parse_number(gchar ** str);
 gboolean matcher_parse_boolean_op(gchar ** str);
 gchar * matcher_parse_regexp(gchar ** str);
 gchar * matcher_parse_str(gchar ** str);
+gchar * matcher_unescape_str(gchar *str);
 gchar * matcherprop_to_string(MatcherProp * matcher);
 gchar * matcherlist_to_string(MatcherList * matchers);
 gchar * matching_build_command(gchar * cmd, MsgInfo * info);
index b13eeeba709909976773244333ca402afe1aa7d3..aa3c7da5b7d53399bd31c2a1d7e39cb54b1617e0 100644 (file)
@@ -837,10 +837,9 @@ static void prefs_filtering_select_set(FilteringProp * prop)
        }
 
        gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), matcher_str);
-
+       
        if (action->destination)
-               gtk_entry_set_text(GTK_ENTRY(filtering.dest_entry),
-                                  action->destination);
+               gtk_entry_set_text(GTK_ENTRY(filtering.dest_entry), action->destination);
        else
                gtk_entry_set_text(GTK_ENTRY(filtering.dest_entry), "");