2011-11-24 [pawel] 3.7.10cvs102
authorPaweł Pękala <c0rn@gazeta.pl>
Thu, 24 Nov 2011 16:50:13 +0000 (16:50 +0000)
committerPaweł Pękala <c0rn@gazeta.pl>
Thu, 24 Nov 2011 16:50:13 +0000 (16:50 +0000)
* src/account.c
* src/filtering.c
* src/filtering.h
* src/imap_gtk.c
* src/mh_gtk.c
* src/prefs_actions.c
* src/prefs_actions.h
Implement actions updating on folder/account rename
This fixes bug #2543 'filter actions in actionsrc not
updated upon account renaming'

ChangeLog
PATCHSETS
configure.ac
src/account.c
src/filtering.c
src/filtering.h
src/imap_gtk.c
src/mh_gtk.c
src/prefs_actions.c
src/prefs_actions.h

index 7bc1fae..3259133 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-11-24 [pawel]     3.7.10cvs102
+
+       * src/account.c
+       * src/filtering.c
+       * src/filtering.h
+       * src/imap_gtk.c
+       * src/mh_gtk.c
+       * src/prefs_actions.c
+       * src/prefs_actions.h
+               Implement actions updating on folder/account rename
+               This fixes bug #2543 'filter actions in actionsrc not
+               updated upon account renaming'
+
 2011-11-24 [wwp]       3.7.10cvs101
 
        * src/gtk/gtkcmctree.c
index 3aef97a..d56a356 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.61.2.102 -r 1.61.2.103 src/account.c;  cvs diff -u -r 1.59.2.86 -r 1.59.2.87 src/prefs_filtering.c;  cvs diff -u -r 1.6.2.11 -r 1.6.2.12 src/prefs_filtering.h;  ) > 3.7.10cvs99.patchset
 ( cvs diff -u -r 1.1.2.24 -r 1.1.2.25 src/gtk/gtkcmctree.c;  ) > 3.7.10cvs100.patchset
 ( cvs diff -u -r 1.1.2.25 -r 1.1.2.26 src/gtk/gtkcmctree.c;  ) > 3.7.10cvs101.patchset
+( cvs diff -u -r 1.61.2.103 -r 1.61.2.104 src/account.c;  cvs diff -u -r 1.60.2.59 -r 1.60.2.60 src/filtering.c;  cvs diff -u -r 1.21.2.20 -r 1.21.2.21 src/filtering.h;  cvs diff -u -r 1.1.2.67 -r 1.1.2.68 src/imap_gtk.c;  cvs diff -u -r 1.2.2.39 -r 1.2.2.40 src/mh_gtk.c;  cvs diff -u -r 1.60.2.77 -r 1.60.2.78 src/prefs_actions.c;  cvs diff -u -r 1.5.2.7 -r 1.5.2.8 src/prefs_actions.h;  ) > 3.7.10cvs102.patchset
index e6291c9..d3d1841 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=7
 MICRO_VERSION=10
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=101
+EXTRA_VERSION=102
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index c00d910..9b72365 100644 (file)
@@ -51,6 +51,7 @@
 #include "remotefolder.h"
 #include "manual.h"
 #include "filtering.h"
+#include "prefs_actions.h"
 
 enum {
        ACCOUNT_IS_DEFAULT,
@@ -467,6 +468,7 @@ void account_open(PrefsAccount *ac_prefs)
 
                        account_rename_path(old_prefix, new_prefix);
                        prefs_filtering_rename_path(old_prefix, new_prefix);
+                       prefs_actions_rename_path(old_prefix, new_prefix);
                        
                        g_free(old_prefix);
                        g_free(new_prefix);
index 8e6f66a..3cdf6f7 100644 (file)
@@ -1126,3 +1126,94 @@ gboolean filtering_peek_per_account_rules(GSList *filtering_list)
 
        return FALSE;
 }
+
+gboolean filtering_action_list_rename_path(GSList *action_list, const gchar *old_path,
+                                          const gchar *new_path)
+{
+       gchar *base;
+       gchar *prefix;
+       gchar *suffix;
+       gchar *dest_path;
+       gchar *old_path_with_sep;
+       gint destlen;
+       gint prefixlen;
+       gint oldpathlen;
+        GSList * action_cur;
+       const gchar *separator=G_DIR_SEPARATOR_S;
+       gboolean matched = FALSE;
+#ifdef G_OS_WIN32
+again:
+#endif
+       oldpathlen = strlen(old_path);
+       old_path_with_sep = g_strconcat(old_path,separator,NULL);
+
+       for(action_cur = action_list ; action_cur != NULL ;
+               action_cur = action_cur->next) {
+
+               FilteringAction *action = action_cur->data;
+                        
+               if (action->type == MATCHACTION_SET_TAG ||
+                   action->type == MATCHACTION_UNSET_TAG)
+                       continue;
+               if (!action->destination) 
+                       continue;
+               
+               destlen = strlen(action->destination);
+                        
+               if (destlen > oldpathlen) {
+                       prefixlen = destlen - oldpathlen;
+                       suffix = action->destination + prefixlen;
+                                
+                       if (!strncmp(old_path, suffix, oldpathlen)) {
+                               prefix = g_malloc0(prefixlen + 1);
+                               strncpy2(prefix, action->destination, prefixlen);
+                                        
+                               base = suffix + oldpathlen;
+                               while (*base == G_DIR_SEPARATOR) base++;
+                                if (*base == '\0')
+                                       dest_path = g_strconcat(prefix, separator,
+                                                               new_path, NULL);
+                               else
+                                       dest_path = g_strconcat(prefix,
+                                                               separator,
+                                                               new_path,
+                                                               separator,
+                                                               base, NULL);
+                                        
+                                       g_free(prefix);
+                                       g_free(action->destination);
+                                       action->destination = dest_path;
+                                       matched = TRUE;
+                       } else { /* for non-leaf folders */
+                               /* compare with trailing slash */
+                               if (!strncmp(old_path_with_sep, action->destination, oldpathlen+1)) {
+                                                
+                                       suffix = action->destination + oldpathlen + 1;
+                                       dest_path = g_strconcat(new_path, separator,
+                                                               suffix, NULL);
+                                       g_free(action->destination);
+                                       action->destination = dest_path;
+                                       matched = TRUE;
+                               }
+                       }
+               } else {
+                       /* folder-moving a leaf */
+                       if (!strcmp(old_path, action->destination)) {
+                               dest_path = g_strdup(new_path);
+                               g_free(action->destination);
+                               action->destination = dest_path;
+                               matched = TRUE;
+                       }
+               }
+       }
+       
+       g_free(old_path_with_sep);
+#ifdef G_OS_WIN32
+       if (!strcmp(separator, G_DIR_SEPARATOR_S) && !matched) {
+               separator = "/";
+               goto again;
+       }
+#endif
+
+       return matched;
+}
index 31ba325..43efc6a 100644 (file)
@@ -107,5 +107,7 @@ extern GSList * post_global_processing;
 gboolean filtering_peek_per_account_rules(GSList *filtering_list);
 
 GSList *filtering_action_list_sort(GSList *action_list);
+gboolean filtering_action_list_rename_path(GSList *action_list, const gchar *old_path,
+                                       const gchar *new_path);
 
 #endif
index 72b5ef3..1939e47 100644 (file)
@@ -298,7 +298,7 @@ static void rename_folder_cb(GtkAction *action, gpointer data)
        new_id = folder_item_get_identifier(item);
        prefs_filtering_rename_path(old_id, new_id);
        account_rename_path(old_id, new_id);
-
+       prefs_actions_rename_path(old_id, new_id);
        g_free(old_id);
        g_free(new_id);
 
index cef0ed1..ad6edeb 100644 (file)
@@ -282,6 +282,7 @@ static void rename_folder_cb(GtkAction *action, gpointer data)
        new_id = folder_item_get_identifier(item);
        prefs_filtering_rename_path(old_id, new_id);
        account_rename_path(old_id, new_id);
+       prefs_actions_rename_path(old_id, new_id);
        g_free(old_id);
        g_free(new_id);
 
index c1b90b2..6bcfc1f 100644 (file)
@@ -1336,3 +1336,31 @@ static void prefs_action_define_filter_done(GSList * action_list)
                modified = TRUE;
        }
 }
+
+void prefs_actions_rename_path(const gchar *old_path, const gchar *new_path)
+{
+       gchar **tokens, *action_str;
+       GSList *action, *action_list;
+       
+       for (action = prefs_common.actions_list; action != NULL;
+                       action = action->next) {
+               action_str = (gchar *)action->data;
+               tokens = g_strsplit_set(action_str, "{}", 5);
+               
+               if (tokens[0] && tokens[1] && *tokens[1] != '\0')
+                       action_list = matcher_parser_get_action_list(tokens[1]);
+               else
+                       action_list = NULL;
+
+               if (action_list &&
+                   filtering_action_list_rename_path(action_list,
+                                               old_path, new_path)) {
+                       g_free(action->data);
+                       action->data = g_strconcat(tokens[0], "{",
+                               filteringaction_list_to_string(action_list),
+                               "}", NULL);
+               }
+
+               g_strfreev(tokens);
+       }
+}
index 437dd54..6bedfcb 100644 (file)
@@ -25,5 +25,7 @@
 void prefs_actions_read_config         (void);
 void prefs_actions_write_config                (void);
 void prefs_actions_open                        (MainWindow     *mainwin);
+void prefs_actions_rename_path         (const gchar *old_path,
+                                        const gchar *new_path);
 
 #endif /* __PREFS_ACTIONS_H__ */