[balsa/wip/gtk4: 332/351] mailbox-node: Make it private



commit 69fe6e93c8cc371d3d863fecb1fafd4b04b4a5a7
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri May 4 20:57:33 2018 -0400

    mailbox-node: Make it private
    
    …and provide a full set of setters and getters.
    And clean up some related code.

 libinit_balsa/assistant_page_user.c |    4 +-
 src/balsa-app.c                     |   76 +++++++-----
 src/balsa-index.c                   |  237 ++++++++++++++++++++++-------------
 src/balsa-index.h                   |    5 +
 src/balsa-mblist.c                  |  131 ++++++++++---------
 src/filter-edit-callbacks.c         |    2 +-
 src/folder-conf.c                   |  100 ++++++++--------
 src/mailbox-conf.c                  |   27 ++--
 src/mailbox-node.c                  |  170 ++++++++++++++++++++++---
 src/mailbox-node.h                  |   48 ++++---
 src/main-window.c                   |  175 +++++++++++++++-----------
 src/main.c                          |   15 ++-
 src/message-window.c                |    9 +-
 src/pref-manager.c                  |   18 ++--
 src/save-restore.c                  |   19 ++-
 src/sendmsg-window.c                |    4 +-
 16 files changed, 661 insertions(+), 379 deletions(-)
---
diff --git a/libinit_balsa/assistant_page_user.c b/libinit_balsa/assistant_page_user.c
index 1c99ef4..40358c2 100644
--- a/libinit_balsa/assistant_page_user.c
+++ b/libinit_balsa/assistant_page_user.c
@@ -239,8 +239,10 @@ create_imap_mbx(const gchar *name, const gchar* host, gint security,
      libbalsa_server_set_tls_mode(server, LIBBALSA_TLS_DISABLED);
     }
     libbalsa_server_set_remember_passwd(server, remember);
+
     mbnode = balsa_mailbox_node_new_imap_folder(server, NULL);
-    mbnode->name = g_strdup(name && *name ? name : host);
+    balsa_mailbox_node_set_name(mbnode,
+                                name != NULL && name[0] != '\0' ? name : host);
 
     config_folder_add(mbnode, NULL);
     /* memory leak? */
diff --git a/src/balsa-app.c b/src/balsa-app.c
index a253cc7..9b117d2 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -174,25 +174,31 @@ set_passwd_from_matching_server(GtkTreeModel *model,
 {
     LibBalsaServer *server;
     LibBalsaServer *master;
-    LibBalsaMailbox *mbox;
-    BalsaMailboxNode *node;
-
-    gtk_tree_model_get(model, iter, 0, &node, -1);
-    g_return_val_if_fail(node != NULL, FALSE);
-    if(node->server) {
-        server = node->server;
-       g_object_unref(node);
-    } else {
-        mbox = node->mailbox;
-       g_object_unref(node);
-        if(!mbox) /* eg. a collection of mboxes */
+    BalsaMailboxNode *mbnode;
+
+    gtk_tree_model_get(model, iter, 0, &mbnode, -1);
+    g_return_val_if_fail(mbnode != NULL, FALSE);
+
+    server = balsa_mailbox_node_get_server(mbnode);
+    if (server == NULL) {
+        LibBalsaMailbox *mailbox;
+
+        mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+        if(mailbox == NULL) { /* eg. a collection of mailboxes */
+            g_object_unref(mbnode);
             return FALSE;
-        g_return_val_if_fail(LIBBALSA_IS_MAILBOX(mbox), FALSE);
+        }
+        g_return_val_if_fail(LIBBALSA_IS_MAILBOX(mailbox), FALSE);
 
-        if (!LIBBALSA_IS_MAILBOX_REMOTE(mbox)) return FALSE;
-        server = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mbox);
+        if (!LIBBALSA_IS_MAILBOX_REMOTE(mailbox)) {
+            g_object_unref(mbnode);
+            return FALSE;
+        }
+        server = LIBBALSA_MAILBOX_REMOTE_GET_SERVER(mailbox);
         g_return_val_if_fail(server != NULL, FALSE);
     }
+    g_object_unref(mbnode);
+
     g_return_val_if_fail(libbalsa_server_get_host(server) != NULL, FALSE);
     g_return_val_if_fail(libbalsa_server_get_username(server) != NULL, FALSE);
     if (libbalsa_server_get_password(server) == NULL) return FALSE;
@@ -547,8 +553,8 @@ balsa_find_mailbox_by_url(const gchar * url)
     BalsaMailboxNode *mbnode;
     LibBalsaMailbox *mailbox = NULL;
 
-    if ((mbnode = balsa_mailbox_node_find_from_url(url))) {
-       mailbox = mbnode->mailbox;
+    if ((mbnode = balsa_mailbox_node_find_from_url(url)) != NULL) {
+       mailbox = balsa_mailbox_node_get_mailbox(mbnode);
        g_object_unref(mbnode);
     }
     return mailbox;
@@ -561,20 +567,32 @@ balsa_find_sentbox_by_url(const gchar *url)
     return res ? res : balsa_app.sentbox;
 }
 
-gchar*
-balsa_get_short_mailbox_name(const gchar *url)
+gchar *
+balsa_get_short_mailbox_name(const gchar * url)
 {
+    gchar *retval = NULL;
     BalsaMailboxNode *mbnode;
 
-    if ((mbnode = balsa_mailbox_node_find_from_url(url)) && mbnode->mailbox) {
-        if (mbnode->server) {
-            return g_strconcat(libbalsa_server_get_host(mbnode->server), ":",
-                               libbalsa_mailbox_get_name(mbnode->mailbox), NULL);
-        } else {
-            return g_strdup(libbalsa_mailbox_get_name(mbnode->mailbox));
+    if ((mbnode = balsa_mailbox_node_find_from_url(url)) != NULL) {
+        LibBalsaMailbox *mailbox;
+
+        mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+        if (mailbox != NULL) {
+            LibBalsaServer *server;
+
+            server = balsa_mailbox_node_get_server(mbnode);
+            if (server != NULL) {
+                retval =
+                    g_strconcat(libbalsa_server_get_host(server),
+                                ":",
+                                libbalsa_mailbox_get_name(mailbox), NULL);
+            } else {
+                retval = g_strdup(libbalsa_mailbox_get_name(mailbox));
+            }
         }
     }
-    return g_strdup(url);
+
+    return retval != NULL ? retval : g_strdup(url);
 }
 
 struct balsa_find_iter_by_data_info {
@@ -593,7 +611,7 @@ balsa_find_iter_by_data_func(GtkTreeModel * model, GtkTreePath * path,
     gtk_tree_model_get(model, iter, 0, &mbnode, -1);
     if(!mbnode)
         return FALSE;
-    if (mbnode == bf->data || mbnode->mailbox == bf->data) {
+    if (mbnode == bf->data || balsa_mailbox_node_get_mailbox(mbnode) == bf->data) {
        *bf->iter = *iter;
        bf->found = TRUE;
     }
@@ -642,8 +660,8 @@ balsa_find_index_by_mailbox(LibBalsaMailbox * mailbox)
          gtk_notebook_get_nth_page(GTK_NOTEBOOK(balsa_app.notebook), i));
         i++) {
         index = gtk_bin_get_child(GTK_BIN(page));
-       if (index && BALSA_INDEX(index)->mailbox_node
-            && BALSA_INDEX(index)->mailbox_node->mailbox == mailbox)
+       if (index  != NULL &&
+            balsa_index_get_mailbox(BALSA_INDEX(index)) == mailbox)
            return BALSA_INDEX(index);
     }
 
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 4d848af..d648d1d 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -190,7 +190,8 @@ bndx_destroy(GObject * obj)
     if (index->mailbox_node) {
        LibBalsaMailbox* mailbox;
 
-       if ((mailbox = index->mailbox_node->mailbox)) {
+       mailbox = balsa_index_get_mailbox(index);
+       if (mailbox != NULL) {
            g_signal_handlers_disconnect_matched(mailbox,
                                                 G_SIGNAL_MATCH_DATA,
                                                 0, 0, NULL, NULL, index);
@@ -481,7 +482,7 @@ bndx_selection_changed_idle(BalsaIndex * index)
 
     if (!index->mailbox_node)
         return FALSE;
-    mailbox = index->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox(index);
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(index));
 
     /* Save next_msgno, because changing flags may zero it. */
@@ -543,10 +544,11 @@ bndx_selection_changed(GtkTreeSelection * selection, BalsaIndex * index)
                                         &index->next_msgno);
 
     if (index->current_msgno) {
+        LibBalsaMailbox *mailbox;
         GtkTreePath *path;
 
-        if (libbalsa_mailbox_msgno_find(index->mailbox_node->mailbox,
-                                        index->current_msgno,
+        mailbox = balsa_index_get_mailbox(index);
+        if (libbalsa_mailbox_msgno_find(mailbox, index->current_msgno,
                                         &path, NULL)) {
             gboolean update_preview = TRUE;
 
@@ -661,11 +663,21 @@ bndx_row_activated(GtkTreeView * tree_view, GtkTreePath * path,
 
 static gboolean
 bndx_find_current_msgno(BalsaIndex * bindex,
-                        GtkTreePath ** path , GtkTreeIter * iter)
+                        GtkTreePath ** path, GtkTreeIter * iter)
 {
-    return bindex->current_msgno > 0
-        && libbalsa_mailbox_msgno_find(bindex->mailbox_node->mailbox,
-                                       bindex->current_msgno, path, iter);
+    gboolean retval = FALSE;
+
+    if (bindex->current_msgno > 0) {
+        LibBalsaMailbox *mailbox;
+
+        mailbox = balsa_index_get_mailbox(bindex);
+
+        retval =
+            libbalsa_mailbox_msgno_find(mailbox, bindex->current_msgno,
+                                        path, iter);
+    }
+
+    return retval;
 }
 
 /* bndx_tree_expand_cb:
@@ -806,7 +818,7 @@ bndx_scroll_on_open_idle(BalsaIndex *index)
         return FALSE;
 
     balsa_index_update_tree(index, balsa_app.expand_tree);
-    mailbox = index->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox(index);
     if ((msgno = libbalsa_mailbox_get_first_unread(mailbox))) {
        libbalsa_mailbox_set_first_unread(mailbox, 0);
         if(!libbalsa_mailbox_msgno_find(mailbox, msgno, &path, NULL))
@@ -948,9 +960,8 @@ balsa_index_load_mailbox_node(BalsaIndex * index,
     g_return_val_if_fail(BALSA_IS_INDEX(index), TRUE);
     g_return_val_if_fail(index->mailbox_node == NULL, TRUE);
     g_return_val_if_fail(BALSA_IS_MAILBOX_NODE(mbnode), TRUE);
-    g_return_val_if_fail(LIBBALSA_IS_MAILBOX(mbnode->mailbox), TRUE);
-
-    mailbox = mbnode->mailbox;
+    mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+    g_return_val_if_fail(LIBBALSA_IS_MAILBOX(mailbox), TRUE);
 
     /*
      * set the new mailbox
@@ -989,7 +1000,7 @@ balsa_index_load_mailbox_node(BalsaIndex * index,
                                              LIBBALSA_MESSAGE_FLAG_DELETED);
     index->search_iter = libbalsa_mailbox_search_iter_new(cond_undeleted);
     /* Note when this mailbox was opened, for use in auto-closing. */
-    time(&index->mailbox_node->last_use);
+    balsa_mailbox_node_set_last_use(index->mailbox_node);
 
     return FALSE;
 }
@@ -1092,33 +1103,32 @@ bndx_find_root(BalsaIndex * index, GtkTreeIter * iter)
 
 static gboolean
 bndx_search_iter(BalsaIndex * index,
-                LibBalsaMailboxSearchIter * search_iter,
-                GtkTreeIter * iter,
-                BndxSearchDirection direction,
-                BndxSearchViewable viewable,
-                guint stop_msgno)
+                 LibBalsaMailboxSearchIter * search_iter,
+                 GtkTreeIter * iter,
+                 BndxSearchDirection direction,
+                 BndxSearchViewable viewable, guint stop_msgno)
 {
+    LibBalsaMailbox *mailbox;
     gboolean found;
 
+    mailbox = balsa_index_get_mailbox(index);
+
     do {
-       GtkTreePath *path;
-
-       found =
-           libbalsa_mailbox_search_iter_step(index->mailbox_node->mailbox,
-                                             search_iter, iter,
-                                             direction ==
-                                             BNDX_SEARCH_DIRECTION_NEXT,
-                                             stop_msgno);
-       if (!found)
-           break;
-       if (viewable == BNDX_SEARCH_VIEWABLE_ANY)
-           break;
+        GtkTreePath *path;
 
-       path = gtk_tree_model_get_path(GTK_TREE_MODEL
-                                      (index->mailbox_node->mailbox),
-                                      iter);
-       found = bndx_row_is_viewable(index, path);
-       gtk_tree_path_free(path);
+        found =
+            libbalsa_mailbox_search_iter_step(mailbox, search_iter, iter,
+                                              direction ==
+                                              BNDX_SEARCH_DIRECTION_NEXT,
+                                              stop_msgno);
+        if (!found)
+            break;
+        if (viewable == BNDX_SEARCH_VIEWABLE_ANY)
+            break;
+
+        path = gtk_tree_model_get_path(GTK_TREE_MODEL(mailbox), iter);
+        found = bndx_row_is_viewable(index, path);
+        gtk_tree_path_free(path);
     } while (!found);
 
     return found;
@@ -1132,12 +1142,15 @@ bndx_search_iter_and_select(BalsaIndex * index,
                             BndxSearchStart start,
                             BndxSearchWrap wrap)
 {
+    LibBalsaMailbox *mailbox;
     GtkTreeIter iter;
     guint stop_msgno;
 
+    mailbox = balsa_index_get_mailbox(index);
+
     if (!((index->next_msgno > 0
-           && libbalsa_mailbox_msgno_find(index->mailbox_node->mailbox,
-                                          index->next_msgno, NULL, &iter))
+           && libbalsa_mailbox_msgno_find(mailbox, index->next_msgno,
+                                          NULL, &iter))
           || (start == BNDX_SEARCH_START_ANY
               && bndx_find_root(index, &iter))))
         return FALSE;
@@ -1357,7 +1370,7 @@ bndx_mailbox_changed_idle(BalsaIndex * bindex)
 
     bindex->has_mailbox_changed_idle = FALSE;
 
-    mailbox = bindex->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox(bindex);
     if ((msgno = libbalsa_mailbox_get_first_unread(mailbox)) > 0
         && libbalsa_mailbox_msgno_find(mailbox, msgno, &path, NULL)) {
         bndx_expand_to_row(bindex, path);
@@ -1421,19 +1434,25 @@ balsa_index_selected_msgnos_new(BalsaIndex * index)
     GArray *msgnos = g_array_new(FALSE, FALSE, sizeof(guint));
     GtkTreeView *tree_view = GTK_TREE_VIEW(index);
     GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
+    LibBalsaMailbox *mailbox;
 
     gtk_tree_selection_selected_foreach(selection,
                                         (GtkTreeSelectionForeachFunc)
                                         bndx_selected_msgnos_func, msgnos);
-    libbalsa_mailbox_register_msgnos(index->mailbox_node->mailbox, msgnos);
+
+    mailbox = balsa_index_get_mailbox(index);
+    libbalsa_mailbox_register_msgnos(mailbox, msgnos);
+
     return msgnos;
 }
 
 void
 balsa_index_selected_msgnos_free(BalsaIndex * index, GArray * msgnos)
 {
-    libbalsa_mailbox_unregister_msgnos(index->mailbox_node->mailbox,
-                                       msgnos);
+    LibBalsaMailbox *mailbox;
+
+    mailbox = balsa_index_get_mailbox(index);
+    libbalsa_mailbox_unregister_msgnos(mailbox, msgnos);
     g_array_free(msgnos, TRUE);
 }
 
@@ -1441,9 +1460,12 @@ static void
 bndx_view_source(gpointer data)
 {
     BalsaIndex *index = BALSA_INDEX(data);
-    LibBalsaMailbox *mailbox = index->mailbox_node->mailbox;
+    LibBalsaMailbox *mailbox;
     guint i;
-    GArray *selected = balsa_index_selected_msgnos_new(index);
+    GArray *selected;
+
+    selected = balsa_index_selected_msgnos_new(index);
+    mailbox = balsa_index_get_mailbox(index);
 
     for (i = 0; i < selected->len; i++) {
         guint msgno = g_array_index(selected, guint, i);
@@ -1512,10 +1534,13 @@ balsa_index_selected_list(BalsaIndex * index)
 static void
 bndx_compose_foreach(BalsaIndex * index, SendType send_type)
 {
-    LibBalsaMailbox *mailbox = index->mailbox_node->mailbox;
-    GArray *selected = balsa_index_selected_msgnos_new(index);
+    GArray *selected;
+    LibBalsaMailbox *mailbox;
     guint i;
 
+    selected = balsa_index_selected_msgnos_new(index);
+    mailbox = balsa_index_get_mailbox(index);
+
     for (i = 0; i < selected->len; i++) {
         guint msgno = g_array_index(selected, guint, i);
         BalsaSendmsg *sm;
@@ -1573,10 +1598,14 @@ balsa_message_continue(gpointer user_data)
 static void
 bndx_compose_from_list(BalsaIndex * index, SendType send_type)
 {
-    GArray *selected = balsa_index_selected_msgnos_new(index);
-    BalsaSendmsg *sm =
-        sendmsg_window_new_from_list(index->mailbox_node->mailbox,
-                                     selected, send_type);
+    GArray *selected;
+    LibBalsaMailbox *mailbox;
+    BalsaSendmsg *sm;
+
+    selected = balsa_index_selected_msgnos_new(index);
+    mailbox = balsa_index_get_mailbox(index);
+
+    sm = sendmsg_window_new_from_list(mailbox, selected, send_type);
 
     balsa_index_selected_msgnos_free(index, selected);
     g_signal_connect(sendmsg_window_get_window(sm), "destroy",
@@ -1612,12 +1641,16 @@ balsa_message_forward_default(gpointer user_data)
 static void
 bndx_do_delete(BalsaIndex* index, gboolean move_to_trash)
 {
-    BalsaIndex *trash = balsa_find_index_by_mailbox(balsa_app.trash);
-    GArray *selected = balsa_index_selected_msgnos_new(index);
+    BalsaIndex *trash;
+    GArray *selected;
     GArray *messages;
-    LibBalsaMailbox *mailbox = index->mailbox_node->mailbox;
+    LibBalsaMailbox *mailbox;
     guint i;
 
+    trash = balsa_find_index_by_mailbox(balsa_app.trash);
+    selected = balsa_index_selected_msgnos_new(index);
+    mailbox = balsa_index_get_mailbox(index);
+
     messages = g_array_new(FALSE, FALSE, sizeof(guint));
     for (i = 0; i < selected->len; i++) {
         guint msgno = g_array_index(selected, guint, i);
@@ -1663,7 +1696,7 @@ balsa_message_move_to_trash(gpointer user_data)
     bndx_do_delete(index, TRUE);
     /* Note when message was flagged as deleted, for use in
      * auto-expunge. */
-    time(&index->mailbox_node->last_use);
+    balsa_mailbox_node_set_last_use(index->mailbox_node);
 }
 
 gint
@@ -1681,8 +1714,8 @@ balsa_find_notebook_page_num(LibBalsaMailbox * mailbox)
          i++) {
         GtkWidget *index = gtk_bin_get_child(GTK_BIN(page));
 
-        if (index && BALSA_INDEX(index)->mailbox_node
-            && BALSA_INDEX(index)->mailbox_node->mailbox == mailbox)
+        if (index != NULL &&
+            balsa_index_get_mailbox(BALSA_INDEX(index)) == mailbox)
             return i;
     }
 
@@ -1696,11 +1729,14 @@ balsa_find_notebook_page_num(LibBalsaMailbox * mailbox)
 void
 balsa_index_toggle_flag(BalsaIndex* index, LibBalsaMessageFlag flag)
 {
-    LibBalsaMailbox *mailbox = index->mailbox_node->mailbox;
+    LibBalsaMailbox *mailbox;
     int is_all_flagged = TRUE;
-    GArray *selected = balsa_index_selected_msgnos_new(index);
+    GArray *selected;
     guint i;
 
+    selected = balsa_index_selected_msgnos_new(index);
+    mailbox = balsa_index_get_mailbox(index);
+
     /* First see if we should set given flag or unset */
     for (i = 0; i < selected->len; i++) {
         guint msgno = g_array_index(selected, guint, i);
@@ -1718,7 +1754,7 @@ balsa_index_toggle_flag(BalsaIndex* index, LibBalsaMessageFlag flag)
     if (flag == LIBBALSA_MESSAGE_FLAG_DELETED)
        /* Note when deleted flag was changed, for use in
         * auto-expunge. */
-       time(&index->mailbox_node->last_use);
+       balsa_mailbox_node_set_last_use(index->mailbox_node);
 }
 
 static void
@@ -1734,8 +1770,10 @@ bi_toggle_deleted_cb(gpointer user_data, GtkWidget * widget)
 
     selected = balsa_index_selected_msgnos_new(index);
     if (widget == index->undelete_item && selected->len > 0) {
-       LibBalsaMailbox *mailbox = index->mailbox_node->mailbox;
+       LibBalsaMailbox *mailbox;
         guint msgno = g_array_index(selected, guint, 0);
+
+       mailbox = balsa_index_get_mailbox(index);
         if (libbalsa_mailbox_msgno_has_flags(mailbox, msgno,
                                              LIBBALSA_MESSAGE_FLAG_DELETED,
                                             0))
@@ -1773,7 +1811,7 @@ mru_menu_cb(const gchar * url, BalsaIndex * index)
 
     g_return_if_fail(mailbox != NULL);
 
-    if (index->mailbox_node->mailbox != mailbox) {
+    if (balsa_index_get_mailbox(index) != mailbox) {
         GArray *selected = balsa_index_selected_msgnos_new(index);
         balsa_index_transfer(index, selected, mailbox, FALSE);
         balsa_index_selected_msgnos_free(index, selected);
@@ -1877,17 +1915,19 @@ bndx_do_popup(BalsaIndex * index, const GdkEvent * event)
 {
     GtkWidget *menu = index->popup_menu;
     GtkWidget *submenu;
+    GArray *selected;
     LibBalsaMailbox* mailbox;
     gboolean any;
     gboolean readonly;
     gboolean any_deleted = FALSE;
     gboolean any_not_deleted = FALSE;
-    GArray *selected = balsa_index_selected_msgnos_new(index);
     guint i;
 
     BALSA_DEBUG();
 
-    mailbox = index->mailbox_node->mailbox;
+    selected = balsa_index_selected_msgnos_new(index);
+    mailbox = balsa_index_get_mailbox(index);
+
     for (i = 0; i < selected->len; i++) {
         guint msgno = g_array_index(selected, guint, i);
         if (libbalsa_mailbox_msgno_has_flags(mailbox, msgno,
@@ -1903,7 +1943,6 @@ bndx_do_popup(BalsaIndex * index, const GdkEvent * event)
     gtk_container_foreach(GTK_CONTAINER(menu), bndx_set_sensitive_func,
                           GINT_TO_POINTER(any));
 
-    mailbox = index->mailbox_node->mailbox;
     readonly = libbalsa_mailbox_get_readonly(mailbox);
     gtk_widget_set_sensitive(index->delete_item,
                              any_not_deleted && !readonly);
@@ -1993,8 +2032,7 @@ balsa_index_set_threading_type(BalsaIndex * index, int thtype)
     LibBalsaMailbox *mailbox;
 
     g_return_if_fail(index != NULL);
-    g_return_if_fail(index->mailbox_node != NULL);
-    mailbox = index->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox(index);
     g_return_if_fail(mailbox != NULL);
 
     if (thtype != LB_MAILBOX_THREADING_FLAT
@@ -2014,7 +2052,7 @@ balsa_index_set_view_filter(BalsaIndex * bindex, int filter_no,
     LibBalsaMailbox *mailbox;
 
     g_return_if_fail(BALSA_IS_INDEX(bindex));
-    mailbox = bindex->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox(bindex);
 
     g_free(bindex->filter_string);
     bindex->filter_no = filter_no;
@@ -2049,7 +2087,7 @@ balsa_index_transfer(BalsaIndex *index, GArray * msgnos,
     if (msgnos->len == 0)
         return;
 
-    from_mailbox = index->mailbox_node->mailbox;
+    from_mailbox = balsa_index_get_mailbox(index);
     success = copy ?
         libbalsa_mailbox_messages_copy(from_mailbox, msgnos, to_mailbox, &e) :
         libbalsa_mailbox_messages_move(from_mailbox, msgnos, to_mailbox, &e);
@@ -2075,7 +2113,7 @@ balsa_index_transfer(BalsaIndex *index, GArray * msgnos,
     if (!copy)
        /* Note when message was flagged as deleted, for use in
         * auto-expunge. */
-       time(&index->mailbox_node->last_use);
+       balsa_mailbox_node_set_last_use(index->mailbox_node);
 }
 
 /* General helpers. */
@@ -2166,7 +2204,7 @@ balsa_index_expunge(BalsaIndex * index)
 
     g_return_if_fail(index != NULL);
 
-    mailbox = index->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox(index);
     if (libbalsa_mailbox_get_readonly(mailbox))
        return;
 
@@ -2183,19 +2221,24 @@ bndx_next_msgno(BalsaIndex * index, guint current_msgno,
                 LibBalsaMailboxSearchIter * search_iter,
                 BndxSearchDirection direction)
 {
-    LibBalsaMailbox *mailbox = index->mailbox_node->mailbox;
-    GtkTreeModel *model = GTK_TREE_MODEL(mailbox);
+    LibBalsaMailbox *mailbox;
     GtkTreeIter iter;
     guint msgno = 0;
 
-    if (!(current_msgno > 0
-          && libbalsa_mailbox_msgno_find(mailbox, current_msgno, NULL,
-                                         &iter)))
+    if (current_msgno == 0)
+        return 0;
+
+    mailbox = balsa_index_get_mailbox(index);
+    if (!libbalsa_mailbox_msgno_find(mailbox, current_msgno, NULL, &iter))
         return 0;
 
     if (bndx_search_iter(index, search_iter, &iter, direction,
-                         BNDX_SEARCH_VIEWABLE_ONLY, 0))
+                         BNDX_SEARCH_VIEWABLE_ONLY, 0)) {
+        GtkTreeModel *model;
+
+        model = GTK_TREE_MODEL(mailbox);
         gtk_tree_model_get(model, &iter, LB_MBOX_MSGNO_COL, &msgno, -1);
+    }
 
     return msgno;
 }
@@ -2564,6 +2607,7 @@ bndx_pipe_response(GtkWidget * dialog, gint response,
 void
 balsa_index_pipe(BalsaIndex * index)
 {
+    LibBalsaMailbox *mailbox;
     struct bndx_mailbox_info *info;
     GtkWidget *label, *entry;
     GtkWidget *dialog;
@@ -2571,22 +2615,20 @@ balsa_index_pipe(BalsaIndex * index)
     GList *list;
 
     g_return_if_fail(BALSA_IS_INDEX(index));
-    g_return_if_fail(BALSA_IS_MAILBOX_NODE(index->mailbox_node));
-    g_return_if_fail(LIBBALSA_IS_MAILBOX(index->mailbox_node->mailbox));
+    mailbox = balsa_index_get_mailbox(index);
+    g_return_if_fail(LIBBALSA_IS_MAILBOX(mailbox));
 
-    info =
-        g_object_get_data(G_OBJECT(index->mailbox_node->mailbox),
-                          BALSA_INDEX_PIPE_INFO);
+    info = g_object_get_data(G_OBJECT(mailbox), BALSA_INDEX_PIPE_INFO);
     if (info) {
         gtk_window_present(GTK_WINDOW(info->dialog));
         return;
     }
 
-    if(!libbalsa_mailbox_open(index->mailbox_node->mailbox, NULL))
+    if(!libbalsa_mailbox_open(mailbox, NULL))
        return;
     info = g_new(struct bndx_mailbox_info, 1);
     info->bindex = index;
-    info->mailbox = index->mailbox_node->mailbox;
+    info->mailbox = mailbox;
     g_object_set_data_full(G_OBJECT(info->mailbox), BALSA_INDEX_PIPE_INFO,
                            info, bndx_mailbox_notify);
 
@@ -2704,20 +2746,24 @@ balsa_index_count_selected_messages(BalsaIndex * bindex)
 void
 balsa_index_select_thread(BalsaIndex * bindex)
 {
+    LibBalsaMailbox *mailbox;
+    GtkTreeModel *model;
     GtkTreeIter iter;
-    GtkTreeModel *model = GTK_TREE_MODEL(bindex->mailbox_node->mailbox);
     GtkTreeIter next_iter;
     GtkTreePath *path;
     GtkTreeSelection *selection =
         gtk_tree_view_get_selection(GTK_TREE_VIEW(bindex));
     gboolean valid;
 
-    if (!bindex->current_msgno
-        || !libbalsa_mailbox_msgno_find(bindex->mailbox_node->mailbox,
-                                        bindex->current_msgno, NULL,
-                                        &iter))
+    if (bindex->current_msgno == 0)
+        return;
+
+    mailbox = balsa_index_get_mailbox(bindex);
+    if (!libbalsa_mailbox_msgno_find(mailbox, bindex->current_msgno,
+                                        NULL, &iter))
         return;
 
+    model = GTK_TREE_MODEL(mailbox);
     while (gtk_tree_model_iter_parent(model, &next_iter, &iter))
         iter = next_iter;
 
@@ -2745,3 +2791,20 @@ balsa_index_select_thread(BalsaIndex * bindex)
     } while (valid
              && gtk_tree_model_iter_parent(model, &next_iter, &iter));
 }
+
+/*
+ * Helper
+ */
+
+LibBalsaMailbox *
+balsa_index_get_mailbox(BalsaIndex * bindex)
+{
+    BalsaMailboxNode *mailbox_node;
+
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), NULL);
+
+    mailbox_node = bindex->mailbox_node;
+
+    return mailbox_node != NULL ?
+        balsa_mailbox_node_get_mailbox(mailbox_node) : NULL;
+}
diff --git a/src/balsa-index.h b/src/balsa-index.h
index 20fc53b..a59139c 100644
--- a/src/balsa-index.h
+++ b/src/balsa-index.h
@@ -183,6 +183,11 @@ void balsa_index_select_thread(BalsaIndex *bindex);
 /* Count of selected messages. */
 gint balsa_index_count_selected_messages(BalsaIndex *bindex);
 
+/*
+ * Helper
+ */
+LibBalsaMailbox * balsa_index_get_mailbox(BalsaIndex * bindex);
+
 #define BALSA_INDEX_VIEW_ON_OPEN "balsa-index-view-on-open"
 
 G_END_DECLS
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index cac9ebe..ea2bc6b 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -122,8 +122,7 @@ static gboolean bmbl_find_all_unread_mboxes_func(GtkTreeModel * model,
                                                  GtkTreePath * path,
                                                  GtkTreeIter * iter,
                                                  gpointer data);
-static void bmbl_real_disconnect_mbnode_signals(BalsaMailboxNode * mbnode,
-                                             GtkTreeModel * model);
+static void bmbl_real_disconnect_mbnode_signals(BalsaMailboxNode * mbnode);
 static gboolean bmbl_store_redraw_mbnode(GtkTreeIter * iter,
                                         BalsaMailboxNode * mbnode);
 static void bmbl_node_style(GtkTreeModel * model, GtkTreeIter * iter);
@@ -467,14 +466,17 @@ bmbl_selection_func(GtkTreeSelection * selection, GtkTreeModel * model,
     BalsaMailboxNode *mbnode;
     gboolean retval;
 
-    gtk_tree_model_get_iter(model, &iter, path);
-    gtk_tree_model_get(model, &iter, MBNODE_COLUMN, &mbnode, -1);
-
     /* If the node is selected, allow it to be deselected, whether or
      * not it has a mailbox (if it doesn't, it shouldn't have been
      * selected in the first place, but you never know...). */
-    retval = (path_currently_selected || (mbnode && mbnode->mailbox));
+    if (path_currently_selected)
+        return TRUE;
+
+    gtk_tree_model_get_iter(model, &iter, path);
+    gtk_tree_model_get(model, &iter, MBNODE_COLUMN, &mbnode, -1);
+    retval = balsa_mailbox_node_get_mailbox(mbnode) != NULL;
     g_object_unref(mbnode);
+
     return retval;
 }
 
@@ -503,7 +505,7 @@ bmbl_tree_expand(GtkTreeView * tree_view, GtkTreeIter * iter,
     gtk_tree_model_get(model, iter, MBNODE_COLUMN, &mbnode, -1);
     balsa_mailbox_node_scan_children(mbnode);
 
-    if (!mbnode->mailbox)
+    if (balsa_mailbox_node_get_mailbox(mbnode) == NULL)
         gtk_tree_store_set(GTK_TREE_STORE(model), iter,
                            ICON_COLUMN,
                            balsa_icon_id(BALSA_PIXMAP_MBOX_DIR_OPEN),
@@ -514,22 +516,25 @@ bmbl_tree_expand(GtkTreeView * tree_view, GtkTreeIter * iter,
        GtkWidget *current_index =
            balsa_window_find_current_index(balsa_app.main_window);
        LibBalsaMailbox *current_mailbox =
-           current_index ?
-           BALSA_INDEX(current_index)->mailbox_node->mailbox :
+           current_index != NULL ?
+           balsa_index_get_mailbox(BALSA_INDEX(current_index)) :
            NULL;
        gboolean first_mailbox = TRUE;
 
         do {
+            LibBalsaMailbox *mailbox;
+
             gtk_tree_model_get(model, &child_iter,
                                MBNODE_COLUMN, &mbnode, -1);
-            if (mbnode && mbnode->mailbox) {
+            if (mbnode != NULL &&
+                (mailbox = balsa_mailbox_node_get_mailbox(mbnode)) != NULL) {
                /* Mark only one mailbox as exposed. */
                if (first_mailbox) {
-                   libbalsa_mailbox_set_exposed(mbnode->mailbox, TRUE);
+                   libbalsa_mailbox_set_exposed(mailbox, TRUE);
                    first_mailbox = FALSE;
                } else
-                   libbalsa_mailbox_set_exposed(mbnode->mailbox, FALSE);
-               if (mbnode->mailbox == current_mailbox) {
+                   libbalsa_mailbox_set_exposed(mailbox, FALSE);
+               if (mailbox == current_mailbox) {
                    GtkTreeSelection *selection =
                        gtk_tree_view_get_selection(tree_view);
                    gtk_tree_selection_select_iter(selection, &child_iter);
@@ -552,8 +557,8 @@ bmbl_tree_collapse_helper(GtkTreeModel * model, GtkTreeIter * iter)
 
             gtk_tree_model_get(model, &child_iter,
                                MBNODE_COLUMN, &mbnode, -1);
-            if (mbnode->mailbox)
-               libbalsa_mailbox_set_exposed(mbnode->mailbox, FALSE);
+            if (balsa_mailbox_node_get_mailbox(mbnode))
+               libbalsa_mailbox_set_exposed(balsa_mailbox_node_get_mailbox(mbnode), FALSE);
            g_object_unref(mbnode);
             bmbl_tree_collapse_helper(model, &child_iter);
         } while (gtk_tree_model_iter_next(model, &child_iter));
@@ -569,7 +574,7 @@ bmbl_tree_collapse(GtkTreeView * tree_view, GtkTreeIter * iter,
 
     gtk_tree_model_get(model, iter, MBNODE_COLUMN, &mbnode, -1);
 
-    if (!mbnode->mailbox)
+    if (!balsa_mailbox_node_get_mailbox(mbnode))
         gtk_tree_store_set(GTK_TREE_STORE(model), iter,
                            ICON_COLUMN,
                            balsa_icon_id(BALSA_PIXMAP_MBOX_DIR_CLOSED),
@@ -602,12 +607,12 @@ bmbl_row_compare(GtkTreeModel * model, GtkTreeIter * iter1,
 
     gtk_tree_model_get(model, iter1,
                        MBNODE_COLUMN, &mbnode, NAME_COLUMN, &name1, -1);
-    m1 = mbnode->mailbox;
+    m1 = balsa_mailbox_node_get_mailbox(mbnode);
     g_object_unref(mbnode);
 
     gtk_tree_model_get(model, iter2,
                        MBNODE_COLUMN, &mbnode, NAME_COLUMN, &name2, -1);
-    m2 = mbnode->mailbox;
+    m2 = balsa_mailbox_node_get_mailbox(mbnode);
     g_object_unref(mbnode);
 
     switch (sort_column) {
@@ -793,7 +798,7 @@ bmbl_drag_cb(GtkWidget        * widget,
         return;
     }
 
-    orig_mailbox = orig_index->mailbox_node->mailbox;
+    orig_mailbox = balsa_index_get_mailbox(orig_index);
 
     /* find the node and mailbox */
 
@@ -807,7 +812,7 @@ bmbl_drag_cb(GtkWidget        * widget,
 
         gtk_tree_model_get_iter(model, &iter, path);
         gtk_tree_model_get(model, &iter, MBNODE_COLUMN, &mbnode, -1);
-        mailbox = mbnode->mailbox;
+        mailbox = balsa_mailbox_node_get_mailbox(mbnode);
        g_object_unref(mbnode);
 
         /* cannot transfer to the originating mailbox */
@@ -843,8 +848,8 @@ bmbl_row_activated_cb(GtkTreeView * tree_view, GtkTreePath * path,
     gtk_tree_model_get(model, &iter, MBNODE_COLUMN, &mbnode, -1);
     g_return_if_fail(mbnode != NULL);
 
-    if (mbnode->mailbox)
-        balsa_mblist_open_mailbox(mbnode->mailbox);
+    if (balsa_mailbox_node_get_mailbox(mbnode))
+        balsa_mblist_open_mailbox(balsa_mailbox_node_get_mailbox(mbnode));
     g_object_unref(mbnode);
 }
 
@@ -969,7 +974,7 @@ bmbl_find_all_unread_mboxes_func(GtkTreeModel * model, GtkTreePath * path,
     gtk_tree_model_get(model, iter, MBNODE_COLUMN, &mbnode, -1);
     if(!mbnode) /* this node has no MBNODE associated at this time */
         return FALSE;
-    mailbox = mbnode->mailbox;
+    mailbox = balsa_mailbox_node_get_mailbox(mbnode);
     g_object_unref(mbnode);
 
     if (mailbox
@@ -1024,9 +1029,8 @@ bmbl_open_mailbox(LibBalsaMailbox * mailbox, gboolean set_current)
     index = balsa_window_find_current_index(balsa_app.main_window);
 
     /* If we currently have a page open, update the time last visited */
-    if (index) {
-       time(&BALSA_INDEX(index)->mailbox_node->last_use);
-    }
+    if (index != NULL)
+        balsa_mailbox_node_set_last_use(BALSA_INDEX(index)->mailbox_node);
 
     i = balsa_find_notebook_page_num(mailbox);
     if (i != -1) {
@@ -1034,7 +1038,7 @@ bmbl_open_mailbox(LibBalsaMailbox * mailbox, gboolean set_current)
             gtk_notebook_set_current_page(GTK_NOTEBOOK(balsa_app.notebook),
                                           i);
             index = balsa_window_find_current_index(balsa_app.main_window);
-            time(&BALSA_INDEX(index)->mailbox_node->last_use);
+            balsa_mailbox_node_set_last_use(BALSA_INDEX(index)->mailbox_node);
             balsa_index_set_column_widths(BALSA_INDEX(index));
         }
     } else { /* page with mailbox not found, open it */
@@ -1093,15 +1097,18 @@ get_lru_descendant(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
     if(!gtk_tree_path_is_descendant(path, dt->ancestor_path))
         return FALSE;
     gtk_tree_model_get(model, iter, MBNODE_COLUMN, &mbnode, -1);
-    if(mbnode->mailbox && libbalsa_mailbox_is_open(mbnode->mailbox) &&
-       (!dt->mbnode || (mbnode->last_use < dt->mbnode->last_use)) )
+
+    if (balsa_mailbox_node_get_mailbox(mbnode) != NULL &&
+        libbalsa_mailbox_is_open(balsa_mailbox_node_get_mailbox(mbnode)) &&
+        (dt->mbnode == NULL ||
+         (balsa_mailbox_node_get_last_use(mbnode)
+          < balsa_mailbox_node_get_last_use(dt->mbnode))))
     {
-        if (dt->mbnode)
-            g_object_unref(dt->mbnode);
-        dt->mbnode = mbnode;
+        g_set_object(&dt->mbnode, mbnode);
     }
 
-    else g_object_unref(mbnode);
+    g_object_unref(mbnode);
+
     return FALSE;
 }
 
@@ -1170,14 +1177,17 @@ balsa_mblist_default_signal_bindings(BalsaMBList * mblist)
  * Remove the signals we attached to the mailboxes.
  */
 static void
-bmbl_real_disconnect_mbnode_signals(BalsaMailboxNode * mbnode,
-                                   GtkTreeModel * model)
+bmbl_real_disconnect_mbnode_signals(BalsaMailboxNode * mbnode)
 {
-    if (mbnode->mailbox)
-        g_signal_handlers_disconnect_by_func(mbnode->mailbox,
+    LibBalsaMailbox *mailbox;
+
+    mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+    if (mailbox != NULL) {
+        g_signal_handlers_disconnect_by_func(mailbox,
                                              G_CALLBACK
                                              (bmbl_mailbox_changed_cb),
                                              NULL);
+    }
 }
 
 /* bmbl_store_redraw_mbnode
@@ -1195,8 +1205,8 @@ bmbl_store_redraw_mbnode(GtkTreeIter * iter, BalsaMailboxNode * mbnode)
 
     g_return_val_if_fail(mbnode, FALSE);
 
-    if (mbnode->mailbox) {
-        LibBalsaMailbox *mailbox = mbnode->mailbox;
+    if (balsa_mailbox_node_get_mailbox(mbnode)) {
+        LibBalsaMailbox *mailbox = balsa_mailbox_node_get_mailbox(mbnode);
        static guint mailbox_changed_signal = 0;
 
        if (LIBBALSA_IS_MAILBOX_POP3(mailbox)) {
@@ -1243,10 +1253,10 @@ bmbl_store_redraw_mbnode(GtkTreeIter * iter, BalsaMailboxNode * mbnode)
        if (!mailbox_changed_signal)
            mailbox_changed_signal =
                g_signal_lookup("changed", LIBBALSA_TYPE_MAILBOX);
-       if (!g_signal_has_handler_pending(G_OBJECT(mbnode->mailbox),
+       if (!g_signal_has_handler_pending(G_OBJECT(balsa_mailbox_node_get_mailbox(mbnode)),
                                           mailbox_changed_signal, 0, TRUE)) {
            /* Now we have a mailbox: */
-           g_signal_connect(mbnode->mailbox, "changed",
+           g_signal_connect(balsa_mailbox_node_get_mailbox(mbnode), "changed",
                             G_CALLBACK(bmbl_mailbox_changed_cb),
                             NULL);
             if (libbalsa_mailbox_get_unread(mailbox) > 0
@@ -1257,12 +1267,12 @@ bmbl_store_redraw_mbnode(GtkTreeIter * iter, BalsaMailboxNode * mbnode)
                               0, TRUE);
            /* If necessary, expand rows to expose this mailbox after
             * setting its mbnode in the tree-store. */
-           expose = libbalsa_mailbox_get_exposed(mbnode->mailbox);
+           expose = libbalsa_mailbox_get_exposed(balsa_mailbox_node_get_mailbox(mbnode));
        }
     } else {
        /* new directory, but not a mailbox */
        icon = BALSA_PIXMAP_MBOX_DIR_CLOSED;
-        name = tmp = g_path_get_basename(mbnode->name);
+        name = tmp = g_path_get_basename(balsa_mailbox_node_get_name(mbnode));
     }
 
     gtk_tree_store_set(balsa_app.mblist_tree_store, iter,
@@ -1276,7 +1286,7 @@ bmbl_store_redraw_mbnode(GtkTreeIter * iter, BalsaMailboxNode * mbnode)
                        -1);
     g_free(tmp);
 
-    if (mbnode->mailbox) {
+    if (balsa_mailbox_node_get_mailbox(mbnode) != NULL) {
        GtkTreeModel *model = GTK_TREE_MODEL(balsa_app.mblist_tree_store);
        if (expose) {
            GtkTreePath *path = gtk_tree_model_get_path(model, iter);
@@ -1314,7 +1324,8 @@ bmbl_update_mailbox(GtkTreeStore * store, LibBalsaMailbox * mailbox)
     bmbl_node_style(model, &iter);
 
     bindex = balsa_window_find_current_index(balsa_app.main_window);
-    if (!bindex || mailbox != BALSA_INDEX(bindex)->mailbox_node->mailbox)
+    if (bindex == NULL ||
+        mailbox != balsa_index_get_mailbox(BALSA_INDEX(bindex)))
         return;
 
     balsa_window_set_statusbar(balsa_app.main_window, mailbox);
@@ -1350,10 +1361,10 @@ bmbl_node_style(GtkTreeModel * model, GtkTreeIter * iter)
     gchar *text_total = NULL;
 
     gtk_tree_model_get(model, iter, MBNODE_COLUMN, &mbnode, -1);
-    if (!mbnode || !mbnode->mailbox)
+    if (!mbnode || !balsa_mailbox_node_get_mailbox(mbnode))
         return;
 
-    mailbox = mbnode->mailbox;
+    mailbox = balsa_mailbox_node_get_mailbox(mbnode);
     unread_messages = libbalsa_mailbox_get_unread(mailbox);
     total_messages = libbalsa_mailbox_get_total(mailbox);
 
@@ -1381,12 +1392,12 @@ bmbl_node_style(GtkTreeModel * model, GtkTreeIter * iter)
                 name = tmp = g_strdup_printf("%s (%d)", name, unread_messages);
 
             weight = PANGO_WEIGHT_BOLD;
-            mbnode->style |= MBNODE_STYLE_NEW_MAIL;
+            balsa_mailbox_node_change_style(mbnode, MBNODE_STYLE_NEW_MAIL, 0);
         } else {
             icon = (mailbox == balsa_app.inbox) ?
                 BALSA_PIXMAP_MBOX_IN : BALSA_PIXMAP_MBOX_TRAY_EMPTY;
             weight = PANGO_WEIGHT_NORMAL;
-            mbnode->style &= ~MBNODE_STYLE_NEW_MAIL;
+            balsa_mailbox_node_change_style(mbnode, 0, MBNODE_STYLE_NEW_MAIL);
         }
 
         gtk_tree_store_set(GTK_TREE_STORE(model), iter,
@@ -1426,18 +1437,18 @@ bmbl_node_style(GtkTreeModel * model, GtkTreeIter * iter)
            do {
                BalsaMailboxNode *mn;
                gtk_tree_model_get(model, &child, MBNODE_COLUMN, &mn, -1);
-               if (mn->style & (MBNODE_STYLE_NEW_MAIL |
-                                MBNODE_STYLE_UNREAD_CHILD))
+               if (balsa_mailbox_node_get_style(mn) &
+                        (MBNODE_STYLE_NEW_MAIL | MBNODE_STYLE_UNREAD_CHILD))
                    has_unread_child = TRUE;
                g_object_unref(mn);
            } while (!has_unread_child && gtk_tree_model_iter_next(model, &child));
        }
        if (has_unread_child) {
-           mbnode->style |= MBNODE_STYLE_UNREAD_CHILD;
+            balsa_mailbox_node_change_style(mbnode, MBNODE_STYLE_UNREAD_CHILD, 0);
            gtk_tree_store_set(GTK_TREE_STORE(model), &parent,
                               STYLE_COLUMN, PANGO_STYLE_OBLIQUE, -1);
        } else {
-           mbnode->style &= ~MBNODE_STYLE_UNREAD_CHILD;
+            balsa_mailbox_node_change_style(mbnode, 0, MBNODE_STYLE_UNREAD_CHILD);
            gtk_tree_store_set(GTK_TREE_STORE(model), &parent,
                               STYLE_COLUMN, PANGO_STYLE_NORMAL, -1);
        }
@@ -1521,12 +1532,10 @@ balsa_mblist_mailbox_node_remove(BalsaMailboxNode* mbnode)
 {
     GtkTreeIter iter;
 
-    g_return_val_if_fail(mbnode, FALSE);
+    g_return_val_if_fail(mbnode != NULL, FALSE);
 
     if (balsa_find_iter_by_data(&iter, mbnode)) {
-       bmbl_real_disconnect_mbnode_signals(mbnode,
-                                           GTK_TREE_MODEL
-                                           (balsa_app.mblist_tree_store));
+       bmbl_real_disconnect_mbnode_signals(mbnode);
         gtk_tree_store_remove(balsa_app.mblist_tree_store, &iter);
 
         return TRUE;
@@ -1796,9 +1805,9 @@ bmbl_mru_activated_cb(GtkTreeView * tree_view, GtkTreePath * path,
     gtk_tree_model_get(model, &iter, MBNODE_COLUMN, &mbnode, -1);
     g_return_if_fail(mbnode != NULL);
 
-    if (mbnode->mailbox) {
+    if (balsa_mailbox_node_get_mailbox(mbnode)) {
         ((BalsaMBListMRUEntry *) data)->url =
-            g_strdup(libbalsa_mailbox_get_url(mbnode->mailbox));
+            g_strdup(libbalsa_mailbox_get_url(balsa_mailbox_node_get_mailbox(mbnode)));
         bmbl_mru_activate_cb(NULL, data);
 
         gtk_dialog_response(GTK_DIALOG
@@ -2095,11 +2104,9 @@ balsa_mblist_mailbox_node_append(BalsaMailboxNode * root,
         GtkTreePath *parent_path =
             gtk_tree_model_get_path(model, parent_iter);
         if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(balsa_app.mblist),
-                                       parent_path)
-            && !mbnode->scanned) {
+                                       parent_path)) {
             /* Check this node for children. */
             balsa_mailbox_node_append_subtree(mbnode);
-            mbnode->scanned = TRUE;
         }
         gtk_tree_path_free(parent_path);
     }
diff --git a/src/filter-edit-callbacks.c b/src/filter-edit-callbacks.c
index ddc4a93..804a8a3 100644
--- a/src/filter-edit-callbacks.c
+++ b/src/filter-edit-callbacks.c
@@ -1330,7 +1330,7 @@ update_filters_mailbox(GtkTreeModel * model, GtkTreePath * path,
     const gchar *url;
 
     gtk_tree_model_get(model, iter, 0, &mbnode, -1);
-    mailbox = mbnode->mailbox;
+    mailbox = balsa_mailbox_node_get_mailbox(mbnode);
     g_object_unref(mbnode);
     if (!mailbox)
        return FALSE;
diff --git a/src/folder-conf.c b/src/folder-conf.c
index a113edb..6588409 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -180,7 +180,7 @@ folder_conf_clicked_ok(FolderDialogData * fcw)
 
     if (fcw->mbnode) {
         insert = FALSE;
-        s = fcw->mbnode->server;
+        s = balsa_mailbox_node_get_server(fcw->mbnode);
     } else {
         insert = TRUE;
        s = LIBBALSA_SERVER(libbalsa_imap_server_new(username, host));
@@ -223,15 +223,14 @@ folder_conf_clicked_ok(FolderDialogData * fcw)
                                (GDestroyNotify) folder_conf_destroy_cdd);
     }
 
-    g_free(fcw->mbnode->dir);
-    fcw->mbnode->dir = gtk_editable_get_chars(GTK_EDITABLE(fcw->prefix), 0, -1);
-    g_free(fcw->mbnode->name);
-    fcw->mbnode->name =
-        gtk_editable_get_chars(GTK_EDITABLE(fcw->folder_name), 0, -1);
-    fcw->mbnode->subscribed =
-        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fcw->subscribed));
-    fcw->mbnode->list_inbox =
-        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fcw->list_inbox));
+    balsa_mailbox_node_set_dir(fcw->mbnode,
+            gtk_entry_get_text(GTK_ENTRY(fcw->prefix)));
+    balsa_mailbox_node_set_name(fcw->mbnode,
+            gtk_entry_get_text(GTK_ENTRY(fcw->folder_name)));
+    balsa_mailbox_node_set_subscribed(fcw->mbnode,
+            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fcw->subscribed)));
+    balsa_mailbox_node_set_list_inbox(fcw->mbnode,
+            gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fcw->list_inbox)));
 
     libbalsa_server_set_host(s, host, 
                              balsa_server_conf_get_use_ssl(&fcw->bsc));
@@ -283,7 +282,7 @@ folder_conf_imap_node(BalsaMailboxNode *mn)
         return;
     }
 
-    s = mn ? mn->server : NULL;
+    s = mn ? balsa_mailbox_node_get_server(mn) : NULL;
 
     fcw = g_new(FolderDialogData, 1);
     fcw->ok = (CommonDialogFunc) folder_conf_clicked_ok;
@@ -364,7 +363,7 @@ folder_conf_imap_node(BalsaMailboxNode *mn)
     label = libbalsa_create_grid_label(_("Descriptive _name:"), grid, 0);
     fcw->folder_name =
         libbalsa_create_grid_entry(grid, G_CALLBACK(validate_folder),
-                                   fcw, r++, mn ? mn->name : NULL,
+                                   fcw, r++, mn ? balsa_mailbox_node_get_name(mn) : NULL,
                                   label);
 
     default_server = libbalsa_guess_imap_server();
@@ -401,15 +400,15 @@ folder_conf_imap_node(BalsaMailboxNode *mn)
 
     fcw->subscribed =
         libbalsa_create_grid_check(_("Subscribed _folders only"), grid, r++,
-                                   mn ? mn->subscribed : FALSE);
+                                   mn ? balsa_mailbox_node_get_subscribed(mn) : FALSE);
     fcw->list_inbox =
         libbalsa_create_grid_check(_("Always show _Inbox"), grid, r++,
-                                   mn ? mn->list_inbox : TRUE);
+                                   mn ? balsa_mailbox_node_get_list_inbox(mn) : TRUE);
 
     label = libbalsa_create_grid_label(_("Pr_efix:"), grid, r);
     fcw->prefix =
         libbalsa_create_grid_entry(grid, NULL, NULL, r++,
-                                   mn ? mn->dir : NULL, label);
+                                   mn ? balsa_mailbox_node_get_dir(mn) : NULL, label);
 
     gtk_widget_show(GTK_WIDGET(fcw->dialog));
 
@@ -439,7 +438,7 @@ validate_sub_folder(GtkWidget * w, SubfolderDialogData * sdd)
      * Allow typing in the parent_folder entry box only if we already
      * have the server information in mn:
      */
-    gboolean have_server = (mn && LIBBALSA_IS_IMAP_SERVER(mn->server));
+    gboolean have_server = (mn && LIBBALSA_IS_IMAP_SERVER(balsa_mailbox_node_get_server(mn)));
     gtk_editable_set_editable(GTK_EDITABLE(sdd->parent_folder),
                              have_server);
     /*
@@ -496,12 +495,12 @@ browse_button_response(GtkDialog * dialog, gint response,
             return;
 
         bbd->sdd->parent = mbnode;
-        if (mbnode->dir)
+        if (balsa_mailbox_node_get_dir(mbnode))
             gtk_entry_set_text(GTK_ENTRY(bbd->sdd->parent_folder),
-                               mbnode->dir);
-        if(mbnode->server)
+                               balsa_mailbox_node_get_dir(mbnode));
+        if(balsa_mailbox_node_get_server(mbnode))
             gtk_label_set_label(GTK_LABEL(bbd->sdd->host_label),
-                                libbalsa_server_get_host(mbnode->server));
+                                libbalsa_server_get_host(balsa_mailbox_node_get_server(mbnode)));
     }
     validate_sub_folder(NULL, bbd->sdd);
     gtk_widget_set_sensitive(bbd->button, TRUE);
@@ -519,9 +518,10 @@ folder_selection_func(GtkTreeSelection * selection, GtkTreeModel * model,
 
     gtk_tree_model_get_iter(model, &iter, path);
     gtk_tree_model_get(model, &iter, 0, &mbnode, -1);
-    retval = (LIBBALSA_IS_IMAP_SERVER(mbnode->server)
+    retval = (LIBBALSA_IS_IMAP_SERVER(balsa_mailbox_node_get_server(mbnode))
              && (sdd->mbnode == NULL
-                 || sdd->mbnode->server == mbnode->server));
+                 || balsa_mailbox_node_get_server(sdd->mbnode) ==
+                     balsa_mailbox_node_get_server(mbnode)));
     g_object_unref(mbnode);
 
     return retval;
@@ -620,8 +620,8 @@ subfolder_conf_clicked_ok(SubfolderDialogData * sdd)
 
     if (sdd->mbnode) {
         /* Views stuff. */
-        if (sdd->mbnode->mailbox)
-            mailbox_conf_view_check(sdd->mcv, sdd->mbnode->mailbox);
+        if (balsa_mailbox_node_get_mailbox(sdd->mbnode))
+            mailbox_conf_view_check(sdd->mcv, balsa_mailbox_node_get_mailbox(sdd->mbnode));
         
         /* rename */
         if ((g_strcmp0(parent, sdd->old_parent) != 0) ||
@@ -666,8 +666,8 @@ folder, parent);
                 balsa_window_close_mbnode(balsa_app.main_window,
                                           sdd->mbnode);
                 if(!libbalsa_imap_rename_subfolder
-                   (LIBBALSA_MAILBOX_IMAP(sdd->mbnode->mailbox),
-                    parent, folder, sdd->mbnode->subscribed, &err)) {
+                   (LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(sdd->mbnode)),
+                    parent, folder, balsa_mailbox_node_get_subscribed(sdd->mbnode), &err)) {
                     balsa_information(LIBBALSA_INFORMATION_ERROR,
                                       _("Folder rename failed. Reason: %s"),
                                       err ? err->message : "unknown");
@@ -675,15 +675,14 @@ folder, parent);
                     ret = FALSE;
                     goto error;
                 }
-                g_free(sdd->mbnode->dir);
-                sdd->mbnode->dir = g_strdup(parent);
+                balsa_mailbox_node_set_dir(sdd->mbnode, parent);
 
                 /*  Rescan as little of the tree as possible. */
                 if (sdd->old_parent
                     && !strncmp(parent, sdd->old_parent, strlen(parent))) {
                     /* moved it up the tree */
                    BalsaMailboxNode *mbnode =
-                        balsa_mailbox_node_find_from_dir(sdd->parent->server, parent);
+                        balsa_mailbox_node_find_from_dir(balsa_mailbox_node_get_server(sdd->parent), parent);
                     if (mbnode) {
                         balsa_mailbox_node_rescan(mbnode);
                        g_object_unref(mbnode);
@@ -694,7 +693,7 @@ folder, parent);
                                        strlen(sdd->old_parent))) {
                     /* moved it down the tree */
                    BalsaMailboxNode *mbnode =
-                       balsa_mailbox_node_find_from_dir(sdd->parent->server, sdd->old_parent);
+                       balsa_mailbox_node_find_from_dir(balsa_mailbox_node_get_server(sdd->parent), 
sdd->old_parent);
                     if (mbnode) {
                         balsa_mailbox_node_rescan(mbnode);
                        g_object_unref(mbnode);
@@ -703,9 +702,9 @@ folder, parent);
                     /* moved it sideways: a chain of folders might
                      * go away, so we'd better rescan from higher up
                      */
-                    BalsaMailboxNode *mb = sdd->mbnode->parent;
-                    while (!mb->mailbox && mb->parent)
-                        mb = mb->parent;
+                    BalsaMailboxNode *mb = balsa_mailbox_node_get_parent(sdd->mbnode);
+                    while (!balsa_mailbox_node_get_mailbox(mb) && balsa_mailbox_node_get_parent(mb))
+                        mb = balsa_mailbox_node_get_parent(mb);
                     balsa_mailbox_node_rescan(mb);
                     balsa_mailbox_node_rescan(sdd->mbnode);
                 }
@@ -715,8 +714,9 @@ folder, parent);
         GError *err = NULL;
         /* create and subscribe, if parent was. */
         if(libbalsa_imap_new_subfolder(parent, folder,
-                                       sdd->parent->subscribed,
-                                       sdd->parent->server, &err)) {
+                                       balsa_mailbox_node_get_subscribed(sdd->parent),
+                                       balsa_mailbox_node_get_server(sdd->parent),
+                                       &err)) {
             /* see it as server sees it: */
             balsa_mailbox_node_rescan(sdd->parent);
         } else {
@@ -766,21 +766,21 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
 
     if ((sdd->mbnode = mn)) {
        /* update */
-       if (!mn->mailbox) {
+       if (!balsa_mailbox_node_get_mailbox(mn)) {
             balsa_information(LIBBALSA_INFORMATION_ERROR,
                               _("An IMAP folder that is not a mailbox\n"
                                 "has no properties that can be changed."));
             g_free(sdd);
            return;
        }
-       sdd->parent = mn->parent;
-       sdd->old_folder = libbalsa_mailbox_get_name(mn->mailbox);
+       sdd->parent = balsa_mailbox_node_get_parent(mn);
+       sdd->old_folder = libbalsa_mailbox_get_name(balsa_mailbox_node_get_mailbox(mn));
     } else {
        /* create */
         sdd->old_folder = NULL;
         sdd->parent = NULL;
     }
-    sdd->old_parent = sdd->mbnode ? sdd->mbnode->parent->dir : NULL;
+    sdd->old_parent = sdd->mbnode ? balsa_mailbox_node_get_dir(balsa_mailbox_node_get_parent(sdd->mbnode)) : 
NULL;
 
     sdd->dialog = 
         GTK_DIALOG(gtk_dialog_new_with_buttons
@@ -834,8 +834,8 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
     ++row;
     (void) libbalsa_create_grid_label(_("Host:"), grid, row);
     sdd->host_label =
-        gtk_label_new(sdd->mbnode && sdd->mbnode->server
-                      ? libbalsa_server_get_host(sdd->mbnode->server) : "");
+        gtk_label_new(sdd->mbnode && balsa_mailbox_node_get_server(sdd->mbnode)
+                      ? libbalsa_server_get_host(balsa_mailbox_node_get_server(sdd->mbnode)) : "");
     gtk_widget_set_halign(sdd->host_label, GTK_ALIGN_START);
     gtk_widget_set_hexpand(sdd->host_label, TRUE);
     gtk_grid_attach(GTK_GRID(grid), sdd->host_label, 1, row, 1, 1);
@@ -877,14 +877,14 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
         (void) libbalsa_create_grid_label(_("Permissions:"), grid, row);
 
         /* mailbox closed: no detailed permissions available */
-        readonly = libbalsa_mailbox_get_readonly(mn->mailbox);
-        if (!libbalsa_mailbox_imap_is_connected(LIBBALSA_MAILBOX_IMAP(mn->mailbox))) {
+        readonly = libbalsa_mailbox_get_readonly(balsa_mailbox_node_get_mailbox(mn));
+        if (!libbalsa_mailbox_imap_is_connected(LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(mn)))) {
             rights_str = g_string_new(std_acls[readonly ? 1 : 3]);
             rights_str =
                 g_string_append(rights_str,
                                 _("\ndetailed permissions are available only for open folders"));
         } else {
-            rights = libbalsa_imap_get_rights(LIBBALSA_MAILBOX_IMAP(mn->mailbox));
+            rights = libbalsa_imap_get_rights(LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(mn)));
             if (!rights) {
                 rights_str = g_string_new(std_acls[readonly ? 1 : 3]);
                 rights_str =
@@ -907,7 +907,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
 
                 /* acl's - only available if I have admin privileges */
                 if ((acls =
-                     libbalsa_imap_get_acls(LIBBALSA_MAILBOX_IMAP(mn->mailbox)))) {
+                     libbalsa_imap_get_acls(LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(mn))))) {
                     int uid;
 
                     for (uid = 0; acls[uid]; uid += 2) {
@@ -939,12 +939,12 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
         (void) libbalsa_create_grid_label(_("Quota:"), grid, row);
 
         /* mailbox closed: no quota available */
-        if (!libbalsa_mailbox_imap_is_connected(LIBBALSA_MAILBOX_IMAP(mn->mailbox)))
+        if (!libbalsa_mailbox_imap_is_connected(LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(mn))))
             quotas = g_strdup(_("quota information available only for open folders"));
         else {
             gulong max, used;
 
-            if (!libbalsa_imap_get_quota(LIBBALSA_MAILBOX_IMAP(mn->mailbox), &max, &used))
+            if (!libbalsa_imap_get_quota(LIBBALSA_MAILBOX_IMAP(balsa_mailbox_node_get_mailbox(mn)), &max, 
&used))
                 quotas = g_strdup(_("the server does not support quotas"));
             else if (max == 0 && used == 0)
                 quotas = g_strdup(_("no limits"));
@@ -964,7 +964,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
         gtk_grid_attach(GTK_GRID(grid), label, 1, row, 1, 1);
         g_free(quotas);
 
-        sdd->mcv = mailbox_conf_view_new(mn->mailbox,
+        sdd->mcv = mailbox_conf_view_new(balsa_mailbox_node_get_mailbox(mn),
                                          GTK_WINDOW(sdd->dialog),
                                          grid, 5,
                                          G_CALLBACK(set_ok_sensitive));
@@ -987,7 +987,7 @@ folder_conf_delete(BalsaMailboxNode* mbnode)
     GtkWidget* ask;
     gint response;
 
-    if(!mbnode->config_prefix) {
+    if(!balsa_mailbox_node_get_config_prefix(mbnode)) {
         balsa_information(LIBBALSA_INFORMATION_ERROR,
                          _("This folder is not stored in configuration. "
                            "I do not yet know how to remove it "
@@ -1002,7 +1002,7 @@ folder_conf_delete(BalsaMailboxNode* mbnode)
                                    "“%s” from the list.\n"
                                    "You may use “New IMAP Folder” "
                                    "later to add this folder again.\n"),
-                                 mbnode->name);
+                                 balsa_mailbox_node_get_name(mbnode));
 #if HAVE_MACOSX_DESKTOP
     libbalsa_macosx_menu_for_parent(ask, GTK_WINDOW(balsa_app.main_window));
 #endif
diff --git a/src/mailbox-conf.c b/src/mailbox-conf.c
index 5be65fb..4502399 100644
--- a/src/mailbox-conf.c
+++ b/src/mailbox-conf.c
@@ -402,7 +402,7 @@ mailbox_conf_delete_cb(GtkWidget * widget, gpointer data)
     BalsaMailboxNode *mbnode =
         balsa_mblist_get_selected_node(balsa_app.mblist);
 
-    if (mbnode->mailbox == NULL)
+    if (balsa_mailbox_node_get_mailbox(mbnode) == NULL)
         balsa_information(LIBBALSA_INFORMATION_ERROR,
                            _("No mailbox selected."));
     else
@@ -428,7 +428,7 @@ mailbox_conf_delete(BalsaMailboxNode * mbnode)
 {
     gint button;
     GtkWidget *ask;
-    LibBalsaMailbox* mailbox = mbnode->mailbox;
+    LibBalsaMailbox* mailbox = balsa_mailbox_node_get_mailbox(mbnode);
     gchar *url, *group;
 
     if(BALSA_IS_MAILBOX_SPECIAL(mailbox)) {
@@ -526,15 +526,16 @@ mailbox_conf_delete(BalsaMailboxNode * mbnode)
     if (LIBBALSA_IS_MAILBOX_IMAP(mailbox) &&
         libbalsa_mailbox_get_config_prefix(mailbox) == NULL) {
         GError *err = NULL;
-       BalsaMailboxNode *parent = mbnode->parent;
+       BalsaMailboxNode *parent = balsa_mailbox_node_get_parent(mbnode);
         if(libbalsa_imap_delete_folder(LIBBALSA_MAILBOX_IMAP(mailbox),
                                        &err)) {
             /* a chain of folders might go away, so we'd better rescan from
              * higher up
              */
-            while (!parent->mailbox && parent->parent) {
+            while (!balsa_mailbox_node_get_mailbox(parent) &&
+                    balsa_mailbox_node_get_parent(parent)) {
                 mbnode = parent;
-                parent = parent->parent;
+                parent = balsa_mailbox_node_get_parent(parent);
             }
             balsa_mblist_mailbox_node_remove(mbnode);
             balsa_mailbox_node_rescan(parent); /* see it as server sees it */
@@ -607,7 +608,7 @@ run_mailbox_conf(BalsaMailboxNode* mbnode, GType mailbox_type,
     if (update) {
         mcw->ok_handler = mailbox_conf_update;
         mcw->ok_button_name = _("_Update");
-        mcw->mailbox = mbnode->mailbox;
+        mcw->mailbox = balsa_mailbox_node_get_mailbox(mbnode);
     } else {
         mcw->ok_handler = mailbox_conf_add;
         mcw->ok_button_name = _("_Add");
@@ -656,22 +657,20 @@ mailbox_conf_new(GType mailbox_type)
 void
 mailbox_conf_edit(BalsaMailboxNode * mbnode)
 {
+    LibBalsaMailbox *mailbox;
     GtkWidget *dialog;
 
-    g_return_if_fail(LIBBALSA_IS_MAILBOX(mbnode->mailbox));
+    mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+    g_return_if_fail(LIBBALSA_IS_MAILBOX(mailbox));
 
-    dialog = g_object_get_data(G_OBJECT(mbnode->mailbox),
-                               BALSA_MAILBOX_CONF_DIALOG);
+    dialog = g_object_get_data(G_OBJECT(mailbox), BALSA_MAILBOX_CONF_DIALOG);
     if (dialog) {
         gtk_window_present(GTK_WINDOW(dialog));
         return;
     }
 
-    dialog =
-        run_mailbox_conf(mbnode, G_OBJECT_TYPE(G_OBJECT(mbnode->mailbox)),
-                         TRUE);
-    g_object_set_data(G_OBJECT(mbnode->mailbox), BALSA_MAILBOX_CONF_DIALOG,
-                      dialog);
+    dialog = run_mailbox_conf(mbnode, G_OBJECT_TYPE(G_OBJECT(mailbox)), TRUE);
+    g_object_set_data(G_OBJECT(mailbox), BALSA_MAILBOX_CONF_DIALOG, dialog);
 }
 
 static void
diff --git a/src/mailbox-node.c b/src/mailbox-node.c
index f6e4082..0037a27 100644
--- a/src/mailbox-node.c
+++ b/src/mailbox-node.c
@@ -85,6 +85,26 @@ static gint check_imap_path(const char     *fn,
 static void mark_imap_path(const gchar *fn,
                            gpointer     data);
 
+struct _BalsaMailboxNode {
+    GObject object;
+
+    BalsaMailboxNode *parent; /* NULL for root-level folders & mailboxes */
+    LibBalsaMailbox *mailbox; /* != NULL for leaves only */
+    gchar *name;       /* used for folders, i.e. when mailbox == NULL */
+    time_t last_use;   /* for closing least recently used mailboxes */
+    BalsaMailboxNodeStyle style;
+    /* folder data */
+    gchar *config_prefix;
+    gchar *dir;
+    LibBalsaServer *server;  /* Used only by remote; is referenced */
+    char delim; /* IMAP delimiter so that we do not need to check it
+                 * too often. */
+
+    unsigned subscribed : 1;     /* Used only by remote */
+    unsigned list_inbox : 1;     /* Used only by remote */
+    unsigned scanned : 1;        /* IMAP flag */
+};
+
 G_DEFINE_TYPE(BalsaMailboxNode, balsa_mailbox_node, G_TYPE_OBJECT)
 
 enum {
@@ -153,8 +173,9 @@ balsa_mailbox_node_init(BalsaMailboxNode *mn)
     mn->name          = NULL;
     mn->dir           = NULL;
     mn->config_prefix = NULL;
-    mn->subscribed    = FALSE;
-    mn->scanned       = FALSE;
+    mn->subscribed    = 0;
+    mn->scanned       = 0;
+    mn->list_inbox    = 0;
 
     g_signal_connect(mn, "save-config",
                      G_CALLBACK(balsa_mailbox_node_real_save_config), NULL);
@@ -186,20 +207,20 @@ balsa_mailbox_node_dispose(GObject *object)
 static void
 balsa_mailbox_node_finalize(GObject *object)
 {
-    BalsaMailboxNode *mn;
+    BalsaMailboxNode *mbnode;
 
-    mn = BALSA_MAILBOX_NODE(object);
+    mbnode = BALSA_MAILBOX_NODE(object);
 
-    balsa_mailbox_node_clear_children_cache(mn);
-    mn->parent = NULL;
-    g_free(mn->name);
-    g_free(mn->dir);
-    g_free(mn->config_prefix);
+    balsa_mailbox_node_clear_children_cache(mbnode);
+    mbnode->parent = NULL;
+    g_free(mbnode->name);
+    g_free(mbnode->dir);
+    g_free(mbnode->config_prefix);
 
-    if (mn->server != NULL) {
-        g_signal_handlers_disconnect_matched(mn->server,
+    if (mbnode->server != NULL) {
+        g_signal_handlers_disconnect_matched(mbnode->server,
                                              G_SIGNAL_MATCH_DATA, 0,
-                                             (GQuark) 0, NULL, NULL, mn);
+                                             (GQuark) 0, NULL, NULL, mbnode);
     }
 
     G_OBJECT_CLASS(balsa_mailbox_node_parent_class)->finalize(object);
@@ -368,10 +389,11 @@ check_local_path(const gchar *path,
 static gboolean
 mark_local_path(BalsaMailboxNode *mbnode)
 {
-    if (mbnode->scanned)
+    if (mbnode->scanned != 0)
         return FALSE;
 
-    mbnode->scanned = TRUE;
+    mbnode->scanned = 1;
+
     return TRUE;
 }
 
@@ -703,8 +725,11 @@ balsa_mailbox_node_show_prop_dialog(BalsaMailboxNode *mn)
 void
 balsa_mailbox_node_append_subtree(BalsaMailboxNode *mn)
 {
-    g_signal_emit(G_OBJECT(mn),
-                  balsa_mailbox_node_signals[APPEND_SUBTREE], 0);
+    if (mn->scanned == 0) {
+        g_signal_emit(G_OBJECT(mn),
+                balsa_mailbox_node_signals[APPEND_SUBTREE], 0);
+        mn->scanned = 1;
+    }
 }
 
 
@@ -861,7 +886,7 @@ balsa_mailbox_node_rescan(BalsaMailboxNode *mn)
         balsa_mailbox_node_remove_children(mn);
         mn = balsa_app.root_node;
     }
-    mn->scanned = FALSE;
+    mn->scanned = 0;
     balsa_mailbox_node_append_subtree(mn);
 }
 
@@ -983,7 +1008,7 @@ bmbn_scan_children_idle(BalsaMailboxNode **mbnode)
             if (mn->mailbox)
                 libbalsa_mailbox_set_has_unread_messages
                     (mn->mailbox, has_unread_messages);
-            mn->scanned = TRUE;
+            mn->scanned = 1;
         } else if (balsa_app.debug) {
             g_print("%s: %s “%s” was already scanned\n", __func__,
                     mn->mailbox ? "mailbox" : "folder",
@@ -1755,3 +1780,112 @@ balsa_mailbox_node_find_from_url(const gchar * url)
 
     return bf.mbnode;
 }
+
+/*
+ * Setters
+ */
+
+void
+balsa_mailbox_node_set_dir(BalsaMailboxNode * mbnode, const gchar * dir)
+{
+    g_free(mbnode->dir);
+    mbnode->dir = g_strdup(dir);
+}
+
+void
+balsa_mailbox_node_set_name(BalsaMailboxNode * mbnode, const gchar * name)
+{
+    g_free(mbnode->name);
+    mbnode->name = g_strdup(name);
+}
+
+void
+balsa_mailbox_node_set_last_use(BalsaMailboxNode * mbnode)
+{
+    time(&mbnode->last_use);
+}
+
+void
+balsa_mailbox_node_change_style(BalsaMailboxNode * mbnode,
+                                BalsaMailboxNodeStyle set,
+                                BalsaMailboxNodeStyle clear)
+{
+    mbnode->style |= set;
+    mbnode->style &= ~clear;
+}
+
+void
+balsa_mailbox_node_set_list_inbox(BalsaMailboxNode * mbnode, guint list_inbox)
+{
+    mbnode->list_inbox = !!list_inbox;
+}
+
+void
+balsa_mailbox_node_set_subscribed(BalsaMailboxNode * mbnode, guint subscribed)
+{
+    mbnode->subscribed = !!subscribed;
+}
+
+/*
+ * Getters
+ */
+
+LibBalsaMailbox *
+balsa_mailbox_node_get_mailbox(BalsaMailboxNode * mbnode)
+{
+    return mbnode->mailbox;
+}
+
+const gchar *
+balsa_mailbox_node_get_name(BalsaMailboxNode * mbnode)
+{
+    return mbnode->name;
+}
+
+const gchar *
+balsa_mailbox_node_get_config_prefix(BalsaMailboxNode * mbnode)
+{
+    return mbnode->config_prefix;
+}
+
+time_t
+balsa_mailbox_node_get_last_use(BalsaMailboxNode * mbnode)
+{
+    return mbnode->last_use;
+}
+
+LibBalsaServer *
+balsa_mailbox_node_get_server(BalsaMailboxNode * mbnode)
+{
+    return mbnode->server;
+}
+
+BalsaMailboxNodeStyle
+balsa_mailbox_node_get_style(BalsaMailboxNode * mbnode)
+{
+    return mbnode->style;
+}
+
+guint
+balsa_mailbox_node_get_subscribed(BalsaMailboxNode * mbnode)
+{
+    return mbnode->subscribed;
+}
+
+guint
+balsa_mailbox_node_get_list_inbox(BalsaMailboxNode * mbnode)
+{
+    return mbnode->list_inbox;
+}
+
+const gchar *
+balsa_mailbox_node_get_dir(BalsaMailboxNode * mbnode)
+{
+    return mbnode->dir;
+}
+
+BalsaMailboxNode *
+balsa_mailbox_node_get_parent(BalsaMailboxNode * mbnode)
+{
+    return mbnode->parent;
+}
diff --git a/src/mailbox-node.h b/src/mailbox-node.h
index e97afea..ba7e021 100644
--- a/src/mailbox-node.h
+++ b/src/mailbox-node.h
@@ -44,7 +44,9 @@ G_DECLARE_FINAL_TYPE(BalsaMailboxNode,
  *      is being displayed in the mailbox list
  *
  * */
+
 typedef enum _BalsaMailboxNodeStyle BalsaMailboxNodeStyle;
+
 enum _BalsaMailboxNodeStyle {
     MBNODE_STYLE_NEW_MAIL        = 1 << 1,
     MBNODE_STYLE_UNREAD_MESSAGES = 1 << 2,
@@ -52,26 +54,6 @@ enum _BalsaMailboxNodeStyle {
     MBNODE_STYLE_UNREAD_CHILD    = 1 << 4
 };
 
-struct _BalsaMailboxNode {
-    GObject object;
-
-    BalsaMailboxNode *parent; /* NULL for root-level folders & mailboxes */
-    LibBalsaMailbox *mailbox; /* != NULL for leaves only */
-    gchar *name;       /* used for folders, i.e. when mailbox == NULL */
-    time_t last_use;   /* for closing least recently used mailboxes */
-    BalsaMailboxNodeStyle style;
-    /* folder data */
-    gchar *config_prefix;
-    gchar *dir;
-    LibBalsaServer *server;  /* Used only by remote; is referenced */
-    char delim; /* IMAP delimiter so that we do not need to check it
-                 * too often. */
-
-    unsigned subscribed : 1;     /* Used only by remote */
-    unsigned list_inbox : 1;     /* Used only by remote */
-    unsigned scanned : 1;        /* IMAP flag */
-};
-
 BalsaMailboxNode *balsa_mailbox_node_new(void);
 BalsaMailboxNode *balsa_mailbox_node_new_from_mailbox(LibBalsaMailbox *m);
 BalsaMailboxNode *balsa_mailbox_node_new_from_dir(const gchar *dir);
@@ -105,4 +87,30 @@ BalsaMailboxNode *balsa_mailbox_node_find_from_mailbox(LibBalsaMailbox * mailbox
 BalsaMailboxNode *balsa_mailbox_node_find_from_dir(LibBalsaServer *server, const gchar * path);
 BalsaMailboxNode *balsa_mailbox_node_find_from_url(const gchar * url);
 
+/*
+ * Setters
+ */
+void balsa_mailbox_node_set_dir(BalsaMailboxNode * mbnode, const gchar * dir);
+void balsa_mailbox_node_set_name(BalsaMailboxNode * mbnode, const gchar * name);
+void balsa_mailbox_node_set_last_use(BalsaMailboxNode * mbnode);
+void balsa_mailbox_node_change_style(BalsaMailboxNode * mbnode,
+                                     BalsaMailboxNodeStyle set,
+                                     BalsaMailboxNodeStyle clear);
+void balsa_mailbox_node_set_subscribed(BalsaMailboxNode * mbnode, guint subscribed);
+void balsa_mailbox_node_set_list_inbox(BalsaMailboxNode * mbnode, guint list_inbox);
+
+/*
+ * Getters
+ */
+LibBalsaMailbox * balsa_mailbox_node_get_mailbox(BalsaMailboxNode * mbnode);
+const gchar * balsa_mailbox_node_get_dir(BalsaMailboxNode * mbnode);
+const gchar * balsa_mailbox_node_get_name(BalsaMailboxNode * mbnode);
+const gchar * balsa_mailbox_node_get_config_prefix(BalsaMailboxNode * mbnode);
+time_t balsa_mailbox_node_get_last_use(BalsaMailboxNode * mbnode);
+LibBalsaServer * balsa_mailbox_node_get_server(BalsaMailboxNode * mbnode);
+BalsaMailboxNodeStyle balsa_mailbox_node_get_style(BalsaMailboxNode * mbnode);
+guint balsa_mailbox_node_get_subscribed(BalsaMailboxNode * mbnode);
+guint balsa_mailbox_node_get_list_inbox(BalsaMailboxNode * mbnode);
+BalsaMailboxNode * balsa_mailbox_node_get_parent(BalsaMailboxNode * mbnode);
+
 #endif
diff --git a/src/main-window.c b/src/main-window.c
index cf82241..b5b55b7 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -1054,8 +1054,8 @@ continue_activated(GSimpleAction * action,
 
     index = balsa_window_find_current_index(window);
 
-    if (index
-        && BALSA_INDEX(index)->mailbox_node->mailbox == balsa_app.draftbox)
+    if (index != NULL
+        && balsa_index_get_mailbox(BALSA_INDEX(index)) == balsa_app.draftbox)
         balsa_message_continue(BALSA_INDEX(index));
     else
         balsa_mblist_open_mailbox(balsa_app.draftbox);
@@ -1120,14 +1120,17 @@ print_activated(GSimpleAction * action,
         return;
 
     bindex = BALSA_INDEX(index);
-    if (bindex->current_msgno) {
-        LibBalsaMessage *message =
-            libbalsa_mailbox_get_message(bindex->mailbox_node->mailbox,
-                                         bindex->current_msgno);
-        if (!message)
-            return;
-        message_print(message, GTK_WINDOW(window));
-        g_object_unref(message);
+    if (bindex->current_msgno != 0) {
+        LibBalsaMailbox *mailbox;
+        LibBalsaMessage *message;
+
+        mailbox = balsa_index_get_mailbox(bindex);
+        message = libbalsa_mailbox_get_message(mailbox, bindex->current_msgno);
+
+        if (message != NULL) {
+            message_print(message, GTK_WINDOW(window));
+            g_object_unref(message);
+        }
     }
 }
 
@@ -1401,9 +1404,14 @@ mailbox_close_activated(GSimpleAction * action,
     GtkWidget *index;
 
     index = balsa_window_find_current_index(window);
-    if (index)
-        balsa_mblist_close_mailbox(BALSA_INDEX(index)->mailbox_node->
-                                   mailbox);
+    if (index != NULL) {
+        BalsaMailboxNode *mbnode;
+        LibBalsaMailbox *mailbox;
+
+        mbnode = BALSA_INDEX(index)->mailbox_node;
+        mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+        balsa_mblist_close_mailbox(mailbox);
+    }
 }
 
 static void
@@ -1425,15 +1433,20 @@ select_filters_activated(GSimpleAction * action,
     GtkWidget *index;
 
     index = balsa_window_find_current_index(window);
-    if (index)
-        filters_run_dialog(BALSA_INDEX(index)->mailbox_node->mailbox,
-                           GTK_WINDOW(balsa_app.main_window));
-    else
+    if (index != NULL) {
+        BalsaMailboxNode *mbnode;
+        LibBalsaMailbox *mailbox;
+
+        mbnode = BALSA_INDEX(index)->mailbox_node;
+        mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+        filters_run_dialog(mailbox, GTK_WINDOW(balsa_app.main_window));
+    } else {
        /* FIXME : Perhaps should we be able to apply filters on folders (ie recurse on all mailboxes in it),
           but there are problems of infinite recursion (when one mailbox being filtered is also the 
destination
           of the filter action (eg a copy)). So let's see that later :) */
        balsa_information(LIBBALSA_INFORMATION_WARNING,
                           _("You can apply filters only on mailbox\n"));
+    }
 }
 
 static void
@@ -1445,19 +1458,22 @@ remove_duplicates_activated(GSimpleAction * action,
     GtkWidget *index;
 
     index = balsa_window_find_current_index(window);
-    if (index) {
-        LibBalsaMailbox *mailbox =
-            BALSA_INDEX(index)->mailbox_node->mailbox;
+    if (index != NULL) {
+        BalsaMailboxNode *mbnode;
+        LibBalsaMailbox *mailbox;
+        gint dup_count;
         GError *err = NULL;
-        gint dup_count =
-            libbalsa_mailbox_move_duplicates(mailbox, NULL, &err);
-        if (err) {
+
+        mbnode = BALSA_INDEX(index)->mailbox_node;
+        mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+        dup_count = libbalsa_mailbox_move_duplicates(mailbox, NULL, &err);
+        if (err != NULL) {
             balsa_information(LIBBALSA_INFORMATION_WARNING,
                               _("Removing duplicates failed: %s"),
                               err->message);
             g_error_free(err);
         } else {
-           if(dup_count)
+           if (dup_count != 0)
                 balsa_information(LIBBALSA_INFORMATION_MESSAGE,
                                   ngettext("Removed %d duplicate",
                                            "Removed %d duplicates",
@@ -1944,8 +1960,9 @@ threading_change_state(GSimpleAction * action,
     /* bw->current_index may have been destroyed and cleared during
      * set-threading: */
     index = balsa_window_find_current_index(window);
-    if (index && (mbnode = BALSA_INDEX(index)->mailbox_node)
-        && (mailbox = mbnode->mailbox))
+    if (index != NULL &&
+        (mbnode = BALSA_INDEX(index)->mailbox_node) != NULL &&
+        (mailbox = balsa_mailbox_node_get_mailbox(mbnode)))
         bw_enable_expand_collapse(window, mailbox);
 
     g_simple_action_set_state(action, state);
@@ -2505,7 +2522,7 @@ bw_enable_mailbox_menus(BalsaWindow * window, BalsaIndex * index)
     enable = (index != NULL);
     if (enable) {
         mbnode = index->mailbox_node;
-        mailbox = mbnode->mailbox;
+        mailbox = balsa_mailbox_node_get_mailbox(mbnode);
     }
     bw_action_set_enabled(window, "mailbox-expunge",
     /* cppcheck-suppress nullPointer */
@@ -2555,25 +2572,34 @@ static void
 bw_enable_message_menus(BalsaWindow * window, guint msgno)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    gboolean enable, enable_mod, enable_store;
     BalsaIndex *bindex = BALSA_INDEX(priv->current_index);
+    gboolean enable_current_message_actions = FALSE;
+    gboolean enable_message_actions = FALSE;
+    gboolean enable_modify_message_actions = FALSE;
+    gboolean enable_store = FALSE;
 
-    enable = (msgno != 0 && bindex != NULL);
-    bw_actions_set_enabled(window, current_message_actions,
-                           G_N_ELEMENTS(current_message_actions), enable);
+    if (bindex != NULL) {
+        LibBalsaMailbox *mailbox;
 
-    enable = (bindex != NULL
-              && balsa_index_count_selected_messages(bindex) > 0);
-    bw_actions_set_enabled(window, message_actions,
-                           G_N_ELEMENTS(message_actions), enable);
+        enable_current_message_actions = (msgno != 0);
+        enable_message_actions = (balsa_index_count_selected_messages(bindex) > 0);
+
+        mailbox = balsa_index_get_mailbox(bindex);
+        enable_modify_message_actions =
+            (mailbox != NULL && !libbalsa_mailbox_get_readonly(mailbox));
 
-    enable_mod =
-        (enable && !libbalsa_mailbox_get_readonly(bindex->mailbox_node->mailbox));
+        enable_store = (balsa_app.address_book_list != NULL);
+    }
+
+    bw_actions_set_enabled(window, current_message_actions,
+                           G_N_ELEMENTS(current_message_actions),
+                           enable_current_message_actions);
+    bw_actions_set_enabled(window, message_actions,
+                           G_N_ELEMENTS(message_actions),
+                           enable_message_actions);
     bw_actions_set_enabled(window, modify_message_actions,
                            G_N_ELEMENTS(modify_message_actions),
-                           enable_mod);
-
-    enable_store = (enable && balsa_app.address_book_list != NULL);
+                           enable_modify_message_actions);
     bw_action_set_enabled(window, "store-address", enable_store);
 
     balsa_window_enable_continue(window);
@@ -2708,7 +2734,7 @@ bw_set_threading_menu(BalsaWindow * window, int option)
 
     if ((index = balsa_window_find_current_index(window))
        && (mbnode = BALSA_INDEX(index)->mailbox_node)
-       && (mailbox = mbnode->mailbox))
+       && (mailbox = balsa_mailbox_node_get_mailbox(mbnode)))
        bw_enable_expand_collapse(window, mailbox);
 }
 
@@ -2821,7 +2847,7 @@ bw_notebook_label_new(BalsaMailboxNode * mbnode)
 
     box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
 
-    lab = gtk_label_new(libbalsa_mailbox_get_name(mbnode->mailbox));
+    lab = gtk_label_new(libbalsa_mailbox_get_name(balsa_mailbox_node_get_mailbox(mbnode)));
     gtk_widget_set_name(lab, "balsa-notebook-tab-label");
 
     /* Try to make text not bold: */
@@ -2839,8 +2865,8 @@ bw_notebook_label_new(BalsaMailboxNode * mbnode)
     g_object_unref(css_provider);
 
     bw_notebook_label_style(GTK_LABEL(lab),
-                            libbalsa_mailbox_get_unread(mbnode->mailbox) > 0);
-    g_signal_connect_object(mbnode->mailbox, "changed",
+                            libbalsa_mailbox_get_unread(balsa_mailbox_node_get_mailbox(mbnode)) > 0);
+    g_signal_connect_object(balsa_mailbox_node_get_mailbox(mbnode), "changed",
                             G_CALLBACK(bw_mailbox_changed), lab, 0);
     gtk_widget_set_hexpand(lab, TRUE);
     gtk_box_pack_start(GTK_BOX(box), lab);
@@ -2852,7 +2878,7 @@ bw_notebook_label_new(BalsaMailboxNode * mbnode)
                      G_CALLBACK(bw_mailbox_tab_close_cb), mbnode);
     gtk_box_pack_start(GTK_BOX(box), but);
 
-    gtk_widget_set_tooltip_text(box, libbalsa_mailbox_get_url(mbnode->mailbox));
+    gtk_widget_set_tooltip_text(box, libbalsa_mailbox_get_url(balsa_mailbox_node_get_mailbox(mbnode)));
     return box;
 }
 
@@ -2875,7 +2901,7 @@ bw_real_open_mbnode_idle_cb(BalsaWindowRealOpenMbnodeInfo * info)
     BalsaMailboxNode *mbnode  = info->mbnode;
     BalsaWindow      *window  = info->window;
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    LibBalsaMailbox  *mailbox = mbnode->mailbox;
+    LibBalsaMailbox  *mailbox = balsa_mailbox_node_get_mailbox(mbnode);
     GtkWidget        *label;
     GtkWidget        *scroll;
     gint              page_num;
@@ -2949,7 +2975,7 @@ bw_real_open_mbnode_thread(BalsaWindowRealOpenMbnodeInfo * info)
 {
     static GMutex open_lock;
     gint try_cnt;
-    LibBalsaMailbox *mailbox = info->mbnode->mailbox;
+    LibBalsaMailbox *mailbox = balsa_mailbox_node_get_mailbox(info->mbnode);
     GError *err = NULL;
     gboolean successp;
 
@@ -3000,7 +3026,7 @@ balsa_window_real_open_mbnode(BalsaWindow * window,
     GThread *open_thread;
     BalsaWindowRealOpenMbnodeInfo *info;
 
-    if (bw_is_open_mailbox(mailbox = mbnode->mailbox))
+    if (bw_is_open_mailbox(mailbox = balsa_mailbox_node_get_mailbox(mbnode)))
         return;
 
     index = BALSA_INDEX(balsa_index_new());
@@ -3051,13 +3077,13 @@ balsa_window_real_close_mbnode(BalsaWindow * window,
     gint i;
     LibBalsaMailbox **mailbox;
 
-    g_return_if_fail(mbnode->mailbox);
+    g_return_if_fail(balsa_mailbox_node_get_mailbox(mbnode));
 
-    i = balsa_find_notebook_page_num(mbnode->mailbox);
+    i = balsa_find_notebook_page_num(balsa_mailbox_node_get_mailbox(mbnode));
 
     if (i != -1) {
         gtk_notebook_remove_page(GTK_NOTEBOOK(priv->notebook), i);
-        bw_unregister_open_mailbox(mbnode->mailbox);
+        bw_unregister_open_mailbox(balsa_mailbox_node_get_mailbox(mbnode));
 
         /* If this is the last notebook page clear the message preview
            and the status bar */
@@ -3092,7 +3118,7 @@ balsa_window_real_close_mbnode(BalsaWindow * window,
     index = balsa_window_find_current_index(window);
     mailbox = g_new(LibBalsaMailbox *, 1);
     if (index) {
-       *mailbox = BALSA_INDEX(index)->mailbox_node-> mailbox;
+       *mailbox = balsa_index_get_mailbox(BALSA_INDEX(index));
        g_object_add_weak_pointer(G_OBJECT(*mailbox), (gpointer) mailbox);
     } else
        *mailbox = NULL;
@@ -3135,7 +3161,8 @@ bw_close_mailbox_on_timer(BalsaWindow * window)
             continue;
 
         if (balsa_app.close_mailbox_auto &&
-            (delta_time = current_time - index->mailbox_node->last_use) >
+            (delta_time = current_time -
+             balsa_mailbox_node_get_last_use(index->mailbox_node)) >
             balsa_app.close_mailbox_timeout) {
             if (balsa_app.debug)
                 fprintf(stderr, "Closing Page %d unused for %d s\n",
@@ -3288,10 +3315,15 @@ bw_check_mailbox_list(struct check_messages_thread_info *info, GList *mailbox_li
     }
 
     for ( ; mailbox_list; mailbox_list = mailbox_list->next) {
-        LibBalsaMailbox *mailbox = BALSA_MAILBOX_NODE(mailbox_list->data)->mailbox;
-        LibBalsaMailboxPop3 *pop3 = LIBBALSA_MAILBOX_POP3(mailbox);
+        BalsaMailboxNode *mbnode;
+        LibBalsaMailbox *mailbox;
+        LibBalsaMailboxPop3 *pop3;
         bw_pop_mbox_t *bw_pop_mbox;
 
+        mbnode = BALSA_MAILBOX_NODE(mailbox_list->data);
+        mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+        pop3 = LIBBALSA_MAILBOX_POP3(mailbox);
+
         bw_pop_mbox = g_malloc0(sizeof(bw_pop_mbox_t));
         bw_pop_mbox->mailbox = g_object_ref(mailbox);
         libbalsa_mailbox_pop3_set_inbox(mailbox, balsa_app.inbox);
@@ -3322,9 +3354,9 @@ bw_add_mbox_to_checklist(GtkTreeModel * model, GtkTreePath * path,
     gtk_tree_model_get(model, iter, 0, &mbnode, -1);
     g_return_val_if_fail(mbnode, FALSE);
 
-    if ((mailbox = mbnode->mailbox)) { /* mailbox, not a folder */
+    if ((mailbox = balsa_mailbox_node_get_mailbox(mbnode))) {  /* mailbox, not a folder */
        if (!LIBBALSA_IS_MAILBOX_IMAP(mailbox) ||
-           bw_imap_check_test(mbnode->dir ? mbnode->dir :
+           bw_imap_check_test(balsa_mailbox_node_get_dir(mbnode) ? balsa_mailbox_node_get_dir(mbnode) :
                            libbalsa_mailbox_imap_get_path
                            (LIBBALSA_MAILBOX_IMAP(mailbox))))
            *list = g_slist_prepend(*list, g_object_ref(mailbox));
@@ -3698,10 +3730,11 @@ mw_mbox_change_connection_status(GtkTreeModel * model, GtkTreePath * path,
     gtk_tree_model_get(model, iter, 0, &mbnode, -1);
     g_return_val_if_fail(mbnode, FALSE);
 
-    if ((mailbox = mbnode->mailbox)) {  /* mailbox, not a folder */
+    if ((mailbox = balsa_mailbox_node_get_mailbox(mbnode))) {  /* mailbox, not a folder */
         if (LIBBALSA_IS_MAILBOX_IMAP(mailbox) &&
-            bw_imap_check_test(mbnode->dir ? mbnode->dir :
-                               libbalsa_mailbox_imap_get_path(LIBBALSA_MAILBOX_IMAP(mailbox)))) {
+            bw_imap_check_test(balsa_mailbox_node_get_dir(mbnode) ?
+                balsa_mailbox_node_get_dir(mbnode) :
+                libbalsa_mailbox_imap_get_path(LIBBALSA_MAILBOX_IMAP(mailbox)))) {
             libbalsa_mailbox_test_can_reach(g_object_ref(mailbox),
                                             mw_mbox_can_reach_cb, NULL);
         }
@@ -3756,7 +3789,7 @@ bw_change_connection_status_idle(gpointer user_data)
         return FALSE;
     if ((mbnode = balsa_app.inbox_input->data) == NULL)
         return FALSE;
-    if ((mailbox = mbnode->mailbox) == NULL)
+    if ((mailbox = balsa_mailbox_node_get_mailbox(mbnode)) == NULL)
         return FALSE;
 
     libbalsa_mailbox_test_can_reach(mailbox, bw_change_connection_status_can_reach_cb,
@@ -4018,7 +4051,7 @@ bw_find_real(BalsaWindow * window, BalsaIndex * bindex, gboolean again)
 
         if(ok == FIND_RESPONSE_FILTER) {
             LibBalsaMailbox *mailbox =
-                BALSA_INDEX(bindex)->mailbox_node->mailbox;
+                balsa_index_get_mailbox(BALSA_INDEX(bindex));
             LibBalsaCondition *filter, *res;
             filter = bw_get_view_filter(window);
             res = libbalsa_condition_new_bool_ptr(FALSE, CONDITION_AND,
@@ -4089,7 +4122,7 @@ bw_hide_changed_set_view_filter(BalsaWindow * window)
     if(!index)
         return;
 
-    mailbox = BALSA_INDEX(index)->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox(BALSA_INDEX(index));
     /* Store the new filter mask in the mailbox view before we set the
      * view filter; rethreading triggers bw_set_filter_menu,
      * which retrieves the mask from the mailbox view, and we want it to
@@ -4252,7 +4285,7 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
        g_object_remove_weak_pointer(G_OBJECT(priv->current_index),
                                     (gpointer) &priv->current_index);
        /* Note when this mailbox was hidden, for use in auto-closing. */
-       time(&BALSA_INDEX(priv->current_index)->mailbox_node->last_use);
+        balsa_mailbox_node_set_last_use(BALSA_INDEX(priv->current_index)->mailbox_node);
         priv->current_index = NULL;
     }
 
@@ -4267,9 +4300,9 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
     g_object_add_weak_pointer(G_OBJECT(index),
                              (gpointer) &priv->current_index);
     /* Note when this mailbox was exposed, for use in auto-expunge. */
-    time(&index->mailbox_node->last_use);
+    balsa_mailbox_node_set_last_use(index->mailbox_node);
 
-    mailbox = index->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox(index);
     if (libbalsa_mailbox_get_name(mailbox)) {
         if (libbalsa_mailbox_get_readonly(mailbox)) {
             title =
@@ -4372,7 +4405,7 @@ bw_idle_cb(BalsaWindow * window)
     index = (BalsaIndex *) priv->current_index;
     if (index)
         balsa_message_set(BALSA_MESSAGE(priv->preview),
-                          index->mailbox_node->mailbox,
+                          balsa_index_get_mailbox(index),
                           index->current_msgno);
     else
         balsa_message_set(BALSA_MESSAGE(priv->preview), NULL, 0);
@@ -4483,14 +4516,14 @@ bw_notebook_drag_received_cb(GtkWidget        * widget,
         return;
     }
 
-    orig_mailbox = orig_index->mailbox_node->mailbox;
+    orig_mailbox = balsa_index_get_mailbox(orig_index);
 
     index = bw_notebook_find_page (GTK_NOTEBOOK(widget), x, y);
 
     if (index == NULL)
         return;
 
-    mailbox = index->mailbox_node->mailbox;
+    mailbox = balsa_index_get_mailbox(index);
 
     if (mailbox != NULL && mailbox != orig_mailbox)
         balsa_index_transfer(orig_index, selected, mailbox,
@@ -4711,7 +4744,7 @@ update_view_menu(BalsaWindow * window)
 void
 balsa_window_update_tab(BalsaMailboxNode * mbnode)
 {
-    gint i = balsa_find_notebook_page_num(mbnode->mailbox);
+    gint i = balsa_find_notebook_page_num(balsa_mailbox_node_get_mailbox(mbnode));
     if (i != -1) {
        GtkWidget *page =
            gtk_notebook_get_nth_page(GTK_NOTEBOOK(balsa_app.notebook), i);
@@ -4822,7 +4855,7 @@ balsa_window_next_unread(BalsaWindow * window)
 {
     BalsaIndex *index =
         BALSA_INDEX(balsa_window_find_current_index(window));
-    LibBalsaMailbox *mailbox = index ? index->mailbox_node->mailbox : NULL;
+    LibBalsaMailbox *mailbox = index ? balsa_index_get_mailbox(index) : NULL;
 
     if (libbalsa_mailbox_get_unread(mailbox) > 0) {
         if (!balsa_index_select_next_unread(index)) {
diff --git a/src/main.c b/src/main.c
index db8240e..c7eb3e9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -348,13 +348,18 @@ periodic_expunge_cb(void)
                           (GtkTreeModelForeachFunc)mbnode_expunge_func,
                           &list);
 
-    for (l = list; l; l = l->next) {
+    for (l = list; l != NULL; l = l->next) {
         BalsaMailboxNode *mbnode = l->data;
-        if (mbnode->mailbox && libbalsa_mailbox_is_open(mbnode->mailbox)
-            && !libbalsa_mailbox_get_readonly(mbnode->mailbox)) {
+        LibBalsaMailbox *mailbox;
+
+        mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+        if (mailbox != NULL && libbalsa_mailbox_is_open(mailbox)
+            && !libbalsa_mailbox_get_readonly(mailbox)) {
             time_t tm = time(NULL);
-            if (tm-mbnode->last_use > balsa_app.expunge_timeout)
-                libbalsa_mailbox_sync_storage(mbnode->mailbox, TRUE);
+            if (tm - balsa_mailbox_node_get_last_use(mbnode)
+                    > balsa_app.expunge_timeout) {
+                libbalsa_mailbox_sync_storage(mailbox, TRUE);
+            }
         }
         g_object_unref(mbnode);
     }
diff --git a/src/message-window.c b/src/message-window.c
index 097891b..0d71325 100644
--- a/src/message-window.c
+++ b/src/message-window.c
@@ -319,13 +319,12 @@ mw_set_buttons_sensitive(MessageWindow * mw)
     enable = index && balsa_index_previous_msgno(index, current_msgno) > 0;
     mw_set_enabled(mw, "previous-message", enable);
 
-    enable = index != NULL &&
-        libbalsa_mailbox_get_unread_messages(index->mailbox_node->mailbox) > 0;
+    if (index != NULL)
+        mailbox = balsa_index_get_mailbox(index);
+    enable = index != NULL && libbalsa_mailbox_get_unread_messages(mailbox) > 0;
     mw_set_enabled(mw, "next-unread", enable);
 
-    enable = index
-        && libbalsa_mailbox_total_messages(index->mailbox_node->mailbox) >
-        0;
+    enable = index != NULL && libbalsa_mailbox_total_messages(mailbox) > 0;
     mw_set_enabled(mw, "next-flagged", enable);
 }
 
diff --git a/src/pref-manager.c b/src/pref-manager.c
index ca9a29f..b3d6e77 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -968,17 +968,16 @@ add_other_server(BalsaMailboxNode * mbnode, GtkTreeModel * model)
     gboolean append = FALSE;
 
     if (mbnode) {
-        LibBalsaMailbox *mailbox = mbnode->mailbox;
+        LibBalsaMailbox *mailbox = balsa_mailbox_node_get_mailbox(mbnode);
         if (mailbox) {
             if (LIBBALSA_IS_MAILBOX_IMAP(mailbox)) {
                 protocol = "IMAP";
                 name = libbalsa_mailbox_get_name(mailbox);
                 append = TRUE;
             }
-        } else
-            if (LIBBALSA_IS_IMAP_SERVER(mbnode->server)) {
+        } else if (LIBBALSA_IS_IMAP_SERVER(balsa_mailbox_node_get_server(mbnode))) {
             protocol = "IMAP";
-            name = mbnode->name;
+            name = balsa_mailbox_node_get_name(mbnode);
             append = TRUE;
         }
         if (append) {
@@ -1719,7 +1718,7 @@ server_del_cb(GtkTreeView * tree_view)
     gtk_tree_model_get(model, &iter, MS_DATA_COLUMN, &mbnode, -1);
     g_return_if_fail(mbnode);
 
-    if (mbnode->mailbox)
+    if (balsa_mailbox_node_get_mailbox(mbnode))
        mailbox_conf_delete(mbnode);
     else
        folder_conf_delete(mbnode);
@@ -3548,11 +3547,14 @@ update_mail_servers(void)
 
     gtk_list_store_clear(GTK_LIST_STORE(model));
     for (list = balsa_app.inbox_input; list; list = list->next) {
+        LibBalsaMailbox *mailbox;
+
         if (!(mbnode = list->data))
             continue;
-        if (LIBBALSA_IS_MAILBOX_POP3(mbnode->mailbox))
+        mailbox = balsa_mailbox_node_get_mailbox(mbnode);
+        if (LIBBALSA_IS_MAILBOX_POP3(mailbox))
             protocol = "POP3";
-        else if (LIBBALSA_IS_MAILBOX_IMAP(mbnode->mailbox))
+        else if (LIBBALSA_IS_MAILBOX_IMAP(mailbox))
             protocol = "IMAP";
         else
             protocol = _("Unknown");
@@ -3560,7 +3562,7 @@ update_mail_servers(void)
         gtk_list_store_append(GTK_LIST_STORE(model), &iter);
         gtk_list_store_set(GTK_LIST_STORE(model), &iter,
                            MS_PROT_COLUMN, protocol,
-                           MS_NAME_COLUMN, libbalsa_mailbox_get_name(mbnode->mailbox),
+                           MS_NAME_COLUMN, libbalsa_mailbox_get_name(mailbox),
                            MS_DATA_COLUMN, mbnode, -1);
     }
     /*
diff --git a/src/save-restore.c b/src/save-restore.c
index f1a9d0a..3535459 100644
--- a/src/save-restore.c
+++ b/src/save-restore.c
@@ -65,17 +65,23 @@ static void config_identities_load(void);
 
 static void config_filters_load(void);
 
-#define folder_section_path(mn) \
-    BALSA_MAILBOX_NODE(mn)->config_prefix ? \
-    g_strdup(BALSA_MAILBOX_NODE(mn)->config_prefix) : \
-    config_get_unused_group(FOLDER_SECTION_PREFIX)
+static gchar *
+folder_section_path(BalsaMailboxNode * mbnode)
+{
+    const gchar *config_prefix;
+
+    config_prefix = balsa_mailbox_node_get_config_prefix(mbnode);
+
+    return config_prefix != NULL ? g_strdup(config_prefix) :
+        config_get_unused_group(FOLDER_SECTION_PREFIX);
+}
 
 static gchar *
 mailbox_section_path(LibBalsaMailbox * mailbox)
 {
     const gchar *config_prefix;
 
-    config_prefix = libbalsa_mailbox_get_config_prefix(LIBBALSA_MAILBOX(mailbox));
+    config_prefix = libbalsa_mailbox_get_config_prefix(mailbox);
 
     return config_prefix != NULL ? g_strdup(config_prefix) :
         config_get_unused_group(MAILBOX_SECTION_PREFIX);
@@ -452,7 +458,8 @@ config_folder_init(const gchar * prefix)
     g_return_val_if_fail(prefix != NULL, FALSE);
 
     if( (folder = balsa_mailbox_node_new_from_config(prefix)) ) {
-       g_signal_connect_swapped(folder->server, "config-changed",
+       g_signal_connect_swapped(balsa_mailbox_node_get_server(folder),
+                                 "config-changed",
                                  G_CALLBACK(config_folder_update),
                                 folder);
        balsa_mblist_mailbox_node_append(NULL, folder);
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 8924782..b5883b7 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -2352,7 +2352,7 @@ attachments_add(GtkWidget        *widget,
     if (target == g_intern_static_string("x-application/x-message-list")) {
         BalsaIndex *index =
             *(BalsaIndex **) gtk_selection_data_get_data(selection_data);
-        LibBalsaMailbox *mailbox = index->mailbox_node->mailbox;
+        LibBalsaMailbox *mailbox = balsa_index_get_mailbox(index);
         GArray *selected         = balsa_index_selected_msgnos_new(index);
         guint i;
 
@@ -2958,7 +2958,7 @@ drag_data_quote(GtkWidget        *widget,
     if (target == g_intern_static_string(drop_types[TARGET_MESSAGES])) {
         index =
             *(BalsaIndex **) gtk_selection_data_get_data(selection_data);
-        mailbox  = index->mailbox_node->mailbox;
+        mailbox  = balsa_index_get_mailbox(index);
         selected = balsa_index_selected_msgnos_new(index);
         buffer   = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]