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 7bc1fae3488478d5ca89a041a86941268609e7e7..325913343b686e34a464988b6f9c904dcb0fbf53 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
 2011-11-24 [wwp]       3.7.10cvs101
 
        * src/gtk/gtkcmctree.c
index 3aef97a652e75d5bccb2ccf22e25053f25632121..d56a35646b42fdcf17f1f511af092be45fca28da 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.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 e6291c948d167e838f6e2ca46da29efecf6381f0..d3d1841bd9dc6d0e167237eb3b7f00636004ced0 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=7
 MICRO_VERSION=10
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=10
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=101
+EXTRA_VERSION=102
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index c00d910cc106d54d4b41014007b9ed591ca1de4f..9b723651afb889dea9557d646a11e9f99cd91f43 100644 (file)
@@ -51,6 +51,7 @@
 #include "remotefolder.h"
 #include "manual.h"
 #include "filtering.h"
 #include "remotefolder.h"
 #include "manual.h"
 #include "filtering.h"
+#include "prefs_actions.h"
 
 enum {
        ACCOUNT_IS_DEFAULT,
 
 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);
 
                        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);
                        
                        g_free(old_prefix);
                        g_free(new_prefix);
index 8e6f66a9c367d1eb852ef593eb6c60b15723943e..3cdf6f73cfb4fa8a24517eb6d99939c21cc25127 100644 (file)
@@ -1126,3 +1126,94 @@ gboolean filtering_peek_per_account_rules(GSList *filtering_list)
 
        return FALSE;
 }
 
        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 31ba325e90add0ecd2e701d90b3dbe9788aca250..43efc6aa314108fd011f1a601ebb54ac90ddc56a 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_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
 
 #endif
index 72b5ef3700a9a5f632bd26c4a79f631c0cf1096d..1939e47eff7eb06964b9ff9023289e18b0a40a5a 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);
        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);
 
        g_free(old_id);
        g_free(new_id);
 
index cef0ed1e909218cbafde5cd1bdbee54dc73dbf90..ad6edebaad1ac9b55c45fabe84713dbb4248858e 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);
        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);
 
        g_free(old_id);
        g_free(new_id);
 
index c1b90b2a8aa99538e81b6ee0064d4f7bfd40ffe1..6bcfc1ffed0e8edc39235adcfaef97fb94a1af8c 100644 (file)
@@ -1336,3 +1336,31 @@ static void prefs_action_define_filter_done(GSList * action_list)
                modified = TRUE;
        }
 }
                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 437dd54bebc7b683e8a8d6fb269bab2de96a717c..6bedfcb9944f88a03db4109d15800f8c3708d6a2 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_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__ */
 
 #endif /* __PREFS_ACTIONS_H__ */