Fix bug #2447, "Compose window crashes if moving a folder that is being replied to...
authorColin Leroy <colin@colino.net>
Thu, 22 May 2014 20:11:07 +0000 (22:11 +0200)
committerColin Leroy <colin@colino.net>
Thu, 22 May 2014 20:11:07 +0000 (22:11 +0200)
src/compose.c
src/compose.h
src/folder.c
src/main.c
src/prefs_actions.c
src/toolbar.c

index 5da0cc0..d0123db 100644 (file)
@@ -763,8 +763,8 @@ static GtkTargetEntry compose_mime_types[] =
 
 static gboolean compose_put_existing_to_front(MsgInfo *info)
 {
-       GList *compose_list = compose_get_compose_list();
-       GList *elem = NULL;
+       const GList *compose_list = compose_get_compose_list();
+       const GList *elem = NULL;
        
        if (compose_list) {
                for (elem = compose_list; elem != NULL && elem->data != NULL; 
@@ -2535,7 +2535,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
        return compose;
 }
 
-GList *compose_get_compose_list(void)
+const GList *compose_get_compose_list(void)
 {
        return compose_list;
 }
@@ -11803,6 +11803,33 @@ static void compose_subject_entry_activated(GtkWidget *widget, gpointer data)
        gtk_widget_grab_focus(compose->text);
 }
 
+void compose_list_update_folders(FolderItem *old_item, FolderItem *new_item)
+{
+       const GList *compose_list = compose_get_compose_list();
+       const GList *elem = NULL;
+       
+       if (compose_list) {
+               for (elem = compose_list; elem != NULL && elem->data != NULL; 
+                    elem = elem->next) {
+                       Compose *c = (Compose*)elem->data;
+
+                       if (c->targetinfo && c->targetinfo->folder == old_item)
+                               c->targetinfo->folder = new_item;
+
+                       if (c->replyinfo && c->replyinfo->folder == old_item)
+                               c->replyinfo->folder = new_item;
+
+                       if (c->fwdinfo && c->fwdinfo->folder == old_item)
+                               c->fwdinfo->folder = new_item;
+
+                       if (c->autosaved_draft && c->autosaved_draft->folder == old_item)
+                               c->autosaved_draft->folder = new_item;
+
+               }
+       }
+}
+
+
 /*
  * End of Source.
  */
index a475110..b7eb416 100644 (file)
@@ -297,7 +297,7 @@ Compose *compose_redirect           (PrefsAccount   *account,
 Compose *compose_reedit                        (MsgInfo        *msginfo,
                                         gboolean        batch);
 
-GList *compose_get_compose_list                (void);
+const GList *compose_get_compose_list  (void);
 
 void compose_entry_append              (Compose          *compose,
                                         const gchar      *address,
@@ -342,4 +342,6 @@ void compose_clear_exit_drafts              (void);
 void compose_reopen_exit_drafts                (void);
 void compose_attach_from_list (Compose *compose, GList *file_list, gboolean free_data);
 void compose_check_for_email_account(Compose *compose);
+void compose_list_update_folders(FolderItem *old_item, FolderItem *new_item);
+
 #endif /* __COMPOSE_H__ */
index 1bd7d98..52fc192 100644 (file)
@@ -431,7 +431,8 @@ void folder_item_remove(FolderItem *item)
                        folder_item_remove(sub_item);
                }
        }
-       
+
+       compose_list_update_folders(item, NULL);
        /* remove myself */
        if (item->cache != NULL) {
                msgcache_destroy(item->cache);
@@ -3292,6 +3293,8 @@ static FolderItem *folder_item_move_recursive(FolderItem *src, FolderItem *dest,
        old_id = folder_item_get_identifier(src);
        new_id = folder_item_get_identifier(new_item);
 
+       compose_list_update_folders(src, new_item);
+
        /* if src supports removing, otherwise only copy folder */
        if (src->folder->klass->remove_folder != NULL && !copy) 
                src->folder->klass->remove_folder(src->folder, src);
index 26c7e18..41d49cf 100644 (file)
@@ -2026,7 +2026,7 @@ static void initial_processing(FolderItem *item, gpointer data)
 
 static gboolean draft_all_messages(void)
 {
-       GList *compose_list = NULL;
+       const GList *compose_list = NULL;
        
        compose_clear_exit_drafts();
        compose_list = compose_get_compose_list();
index 673d9b5..030a66d 100644 (file)
@@ -920,8 +920,8 @@ static void prefs_actions_cancel(GtkWidget *w, gpointer data)
 static void prefs_actions_ok(GtkWidget *widget, gpointer data)
 {
        MainWindow *mainwin = (MainWindow *) data;
-       GList *list;
-       GList *iter;
+       const GList *list;
+       const GList *iter;
        MessageView *msgview;
        Compose *compose;
        GtkListStore *store;
index 8588d51..0f79780 100644 (file)
@@ -983,8 +983,8 @@ void toolbar_set_learn_button(Toolbar            *toolbar,
 void toolbar_toggle(guint action, gpointer data)
 {
        MainWindow *mainwin = (MainWindow*)data;
-       GList *list;
-       GList *cur;
+       const GList *list;
+       const GList *cur;
 
        cm_return_if_fail(mainwin != NULL);