diff -b -dNru --exclude-from=excl balsa-cvs/help/C/balsa.sgml balsa-defer-imap/help/C/balsa.sgml
--- balsa-cvs/help/C/balsa.sgml	Tue Dec  4 13:48:43 2001
+++ balsa-defer-imap/help/C/balsa.sgml	Wed Dec  5 13:59:04 2001
@@ -2392,10 +2392,18 @@
 
 <variablelist>
 <varlistentry>
+  <term><guilabel>Open Inbox upon Startup</guilabel></term>
+  <listitem>
+    <para>If set, &Balsa; will open your system inbox upon startup.</para>
+  </listitem>
+</varlistentry>
+
+<varlistentry>
   <term><guilabel>Check Mail at Startup</guilabel></term>
   <listitem>
     <para>If set, &Balsa; will automatically attempt to download mail
-      from the &POP3; mail server upon startup.</para>
+      from the &POP3; mail server upon startup, and will check for new
+      mail on an &IMAP; server.</para>
   </listitem>
 </varlistentry>
 
@@ -2407,6 +2415,22 @@
       were open when &Balsa; was last quit.</para>
   </listitem>
 </varlistentry>
+
+<varlistentry>
+  <term><guilabel>IMAP Folder Scan Depth</guilabel></term>
+  <listitem>
+    <para>Opening an &IMAP; folder can be time-consuming, because of the
+    need to explore an entire tree of subfolders. You can defer scanning
+    the tree by setting the scan depth to 1. &Balsa; will then descend
+    into the tree only far enough to discover whether any folders that
+    you can see have subfolders. The first time you expand any subtree,
+    &Balsa; will explore more of the tree.</para> <para>If you prefer
+    to have the whole tree available from startup, choose a depth as
+    great as that of your folder tree. Intermediate settings may also
+    be used.</para>
+  </listitem>
+</varlistentry>
+
 </variablelist>
 </sect1>
 
@@ -2467,25 +2491,36 @@
 
 <itemizedlist mark="bullet">
 
-  <listitem><para>&quot;Folder name&quot; is how the folder is shown
+  <listitem><para><quote>Folder name</quote> is how the folder is shown
   in the mailbox tree on the left side.</para></listitem>
 
-  <listitem><para>``Subfolder of'' indicates the immediate parent of
+  <listitem><para><quote>Subfolder of</quote> indicates the immediate parent of
   the folder.</para></listitem>
 </itemizedlist>
 
 <para>
-  When the dialog is opened from the ``File->New->Remote IMAP
-  subfolder'' menu item, you can enter the folder name and browse IMAP
+  When the dialog is opened from
+  <menuchoice>
+  <guimenu>File</guimenu>
+  <guisubmenu>New</guisubmenu>
+  <guimenuitem>Remote IMAP subfolder</guimenuitem>
+  </menuchoice>,
+  you can enter the folder name and browse IMAP
   trees to find the parent folder. If you had already selected a
   mailbox in an IMAP tree, only that tree is shown for browsing;
   otherwise, all IMAP trees will be shown.
 </para>
 
 <para>
-  When the dialog is opened from the ``Mailbox->Edit'' menu item
+  When the dialog is opened from
+  <menuchoice>
+  <guimenu>Mailbox</guimenu>
+  <guimenuitem>Edit</guimenuitem>
+  </menuchoice>
   with an IMAP folder selected, or by right-clicking on an IMAP
-  mailbox and selecting ``Properties...'', the mailbox may be:
+  mailbox and selecting
+  <guimenuitem>Properties...</guimenuitem>,
+  the mailbox may be:
 
   <itemizedlist mark="bullet">
     <listitem><para>Renamed, by editing the folder name;</para></listitem>
diff -b -dNru --exclude-from=excl balsa-cvs/libbalsa/folder-scanners.c balsa-defer-imap/libbalsa/folder-scanners.c
--- balsa-cvs/libbalsa/folder-scanners.c	Wed Oct 24 17:31:04 2001
+++ balsa-defer-imap/libbalsa/folder-scanners.c	Mon Dec  3 11:25:56 2001
@@ -179,13 +179,16 @@
 
     if (list_inbox)
         /* force INBOX into the mailbox list
-         * delim doesn't matter, so we'll give it '/' */
-        mailbox_handler(rnode, "INBOX", '/');
+         * delim doesn't matter, so we'll give it '/'
+         * and we'll mark it as not scanned, in case it
+         * has any subfolders */
+        mailbox_handler(rnode, "INBOX", '/', FALSE);
 
     state.subfolders = g_list_append(NULL, g_strdup(path));
     state.folder = NULL;
 
     for(i=0; state.subfolders && i<depth; i++) {
+	state.scanned = (i < depth - 1);
 	list = state.subfolders;
 	state.subfolders = NULL;
 	printf("Deph: %i -------------------------------------------\n", i);
@@ -248,7 +251,7 @@
 	++isFolder;
     }
     if (isMailbox)
-	state->mailbox_handler(state->rnode, folder, delim);
+	state->mailbox_handler(state->rnode, folder, delim, state->scanned);
     else if (isFolder)
-	state->folder_handler(state->rnode, folder, delim);
+	state->folder_handler(state->rnode, folder, delim, state->scanned);
 }
diff -b -dNru --exclude-from=excl balsa-cvs/libbalsa/folder-scanners.h balsa-defer-imap/libbalsa/folder-scanners.h
--- balsa-cvs/libbalsa/folder-scanners.h	Wed Oct 24 17:31:04 2001
+++ balsa-defer-imap/libbalsa/folder-scanners.h	Mon Dec  3 10:42:58 2001
@@ -23,7 +23,8 @@
 #define __FOLDER_SCANNERS_H__
 
 typedef GNode* (LocalHandler)(GNode*root, const char*d_name, const char* fn);
-typedef GNode* (ImapHandler)(GNode*root, const char* fn, char delim);
+typedef GNode *(ImapHandler) (GNode *root, const char *fn, char delim,
+			      gboolean scanned);
 
 /* read_dir used by mailbox-node append-subtree callback */
 void libbalsa_scanner_local_dir(GNode *rnode, const gchar * prefix, 
diff -b -dNru --exclude-from=excl balsa-cvs/libmutt/browser.h balsa-defer-imap/libmutt/browser.h
--- balsa-cvs/libmutt/browser.h	Mon Aug 20 10:07:21 2001
+++ balsa-defer-imap/libmutt/browser.h	Mon Dec  3 10:43:51 2001
@@ -52,6 +52,7 @@
   int marked : 1;
   int unmarked : 1;
   /*BALSA data begin */
+  int scanned : 1;
   void * rnode;        /* points to a GNode */
   void * server;       /* points to a LibBalsaServer */
   void (*mailbox_handler)();
diff -b -dNru --exclude-from=excl balsa-cvs/src/balsa-app.c balsa-defer-imap/src/balsa-app.c
--- balsa-cvs/src/balsa-app.c	Mon Nov 26 07:54:28 2001
+++ balsa-defer-imap/src/balsa-app.c	Thu Nov 29 07:54:48 2001
@@ -354,6 +354,7 @@
     /* IMAP */
     balsa_app.check_imap = 1;
     balsa_app.check_imap_inbox = 0;
+    balsa_app.imap_scan_depth = 1;
 
     /* RFC2646 format=flowed */
     balsa_app.recognize_rfc2646_format_flowed = TRUE;
diff -b -dNru --exclude-from=excl balsa-cvs/src/balsa-app.h balsa-defer-imap/src/balsa-app.h
--- balsa-cvs/src/balsa-app.h	Mon Nov 26 07:54:28 2001
+++ balsa-defer-imap/src/balsa-app.h	Thu Nov 29 07:51:51 2001
@@ -166,6 +166,9 @@
     gchar *smtp_certificate_passphrase;
 #endif
 
+    /* IMAP folder scanning */
+    guint imap_scan_depth;
+
     BalsaWindow *main_window;
     BalsaMBList *mblist;
 
diff -b -dNru --exclude-from=excl balsa-cvs/src/balsa-mblist.c balsa-defer-imap/src/balsa-mblist.c
--- balsa-cvs/src/balsa-mblist.c	Sun Nov  4 08:15:38 2001
+++ balsa-defer-imap/src/balsa-mblist.c	Wed Dec  5 13:35:49 2001
@@ -69,6 +69,8 @@
 static void balsa_mblist_disconnect_mailbox_signals(GtkCTree * tree,
 						    GtkCTreeNode * node,
 						    gpointer data);
+static void balsa_mblist_scan_children(GtkCTree * tree,
+                                           GtkCTreeNode * node);
 
 /* callbacks */
 static gboolean mailbox_nodes_to_ctree(GtkCTree *, guint, GNode *,
@@ -477,7 +479,7 @@
 
     gtk_ctree_construct(GTK_CTREE(tree), 3, 0, titles);
 
-    gtk_signal_connect(GTK_OBJECT(tree), "tree_expand",
+    gtk_signal_connect_after(GTK_OBJECT(tree), "tree_expand",
 		       GTK_SIGNAL_FUNC(mailbox_tree_expand), NULL);
     gtk_signal_connect(GTK_OBJECT(tree), "tree_collapse",
 		       GTK_SIGNAL_FUNC(mailbox_tree_collapse), NULL);
@@ -645,26 +648,22 @@
 void
 balsa_mblist_repopulate(BalsaMBList * bmbl)
 {
-    GtkCTree *ctree;
-
     g_return_if_fail(BALSA_IS_MBLIST(bmbl));
 
-    ctree = GTK_CTREE(bmbl);
-
     gtk_ctree_post_recursive(GTK_CTREE(bmbl), NULL,
 			     balsa_mblist_disconnect_mailbox_signals,
 			     NULL); 
 
-    gtk_clist_freeze(GTK_CLIST(ctree));
-    gtk_clist_clear(GTK_CLIST(ctree));
+    gtk_clist_freeze(GTK_CLIST(bmbl));
+    gtk_clist_clear(GTK_CLIST(bmbl));
 
     if (bmbl->display_info)
-	gtk_clist_column_titles_show(GTK_CLIST(ctree));
+	gtk_clist_column_titles_show(GTK_CLIST(bmbl));
     else 
-	gtk_clist_column_titles_hide(GTK_CLIST(ctree));
+	gtk_clist_column_titles_hide(GTK_CLIST(bmbl));
 
-    gtk_clist_set_column_visibility(GTK_CLIST(ctree), 1, bmbl->display_info);
-    gtk_clist_set_column_visibility(GTK_CLIST(ctree), 2, bmbl->display_info);
+    gtk_clist_set_column_visibility(GTK_CLIST(bmbl), 1, bmbl->display_info);
+    gtk_clist_set_column_visibility(GTK_CLIST(bmbl), 2, bmbl->display_info);
 
     if (balsa_app.mailbox_nodes) {
 	GNode *walk;
@@ -673,14 +672,14 @@
 	for(walk = g_node_last_child(balsa_app.mailbox_nodes);
 	    walk; walk = walk->prev) {
 	    node =
-		gtk_ctree_insert_gnode(ctree, NULL, NULL, walk,
+		gtk_ctree_insert_gnode(GTK_CTREE(bmbl), NULL, NULL, walk,
 				       mailbox_nodes_to_ctree, NULL);
 
 	}
     }
-    gtk_ctree_sort_recursive(ctree, NULL);
+    gtk_ctree_sort_recursive(GTK_CTREE(bmbl), NULL);
     balsa_mblist_have_new(bmbl);
-    gtk_clist_thaw(GTK_CLIST(ctree));
+    gtk_clist_thaw(GTK_CLIST(bmbl));
 }
 
 /* mailbox_nodes_to_ctree
@@ -762,6 +761,7 @@
 
     mbnode = gtk_ctree_node_get_row_data(ctree, GTK_CTREE_NODE(node));
     mbnode->expanded = TRUE;
+    balsa_mblist_scan_children(ctree, GTK_CTREE_NODE(node));
 }
 
 static void
@@ -1596,3 +1596,57 @@
                         GDK_ACTION_MOVE, time);
     return FALSE;
 }
+
+/* mblist_scan_mailbox_node:
+ * public interface for checking whether a mailbox node's children need
+ * scanning.
+ */
+
+void
+mblist_scan_mailbox_node(BalsaMBList * mblist, BalsaMailboxNode * mbnode)
+{
+    GtkCTreeNode *node =
+        gtk_ctree_find_by_row_data(GTK_CTREE(mblist), NULL, mbnode);
+    balsa_mblist_scan_children(GTK_CTREE(mblist), node);
+}
+
+/* balsa_mblist_scan_children:
+ * called by mailbox_tree_expand, after the tree has been expanded, and
+ * by mblist_scan_mailbox_node, the public interface.
+ */
+
+static void
+balsa_mblist_scan_children(GtkCTree * ctree, GtkCTreeNode * node)
+{
+    GList *list = NULL;
+
+    for (node = GTK_CTREE_ROW(node)->children; node;
+         node = GTK_CTREE_ROW(node)->sibling) {
+        BalsaMailboxNode *mbnode =
+            BALSA_MAILBOX_NODE(gtk_ctree_node_get_row_data(ctree, node));
+        if (mbnode && (LIBBALSA_IS_MAILBOX_IMAP(mbnode->mailbox)
+                       || (!mbnode->mailbox && mbnode->server
+                           && mbnode->server->type ==
+                           LIBBALSA_SERVER_IMAP))
+            && !mbnode->scanned) {
+            list = g_list_append(list, mbnode);
+        }
+    }
+
+    if (list) {
+        GList *l = list;
+
+        gtk_clist_freeze(GTK_CLIST(ctree));
+        while (list) {
+            BalsaMailboxNode *mbnode = list->data;
+            balsa_mailbox_node_rescan(mbnode);
+            mbnode->scanned = TRUE;
+            list = g_list_next(list);
+        }
+        gtk_clist_thaw(GTK_CLIST(ctree));
+
+        g_list_free(l);
+        if (BALSA_MBLIST(ctree) != balsa_app.mblist)
+            balsa_mblist_repopulate(BALSA_MBLIST(ctree));
+    }
+}
diff -b -dNru --exclude-from=excl balsa-cvs/src/balsa-mblist.h balsa-defer-imap/src/balsa-mblist.h
--- balsa-cvs/src/balsa-mblist.h	Fri Oct  5 18:06:42 2001
+++ balsa-defer-imap/src/balsa-mblist.h	Wed Dec  5 10:36:43 2001
@@ -75,4 +75,6 @@
 			       GtkCTreeNode * cnode);
 gboolean mblist_remove_mailbox_node(BalsaMBList *mblist,
 				    BalsaMailboxNode* mbnode);
+void mblist_scan_mailbox_node(BalsaMBList *mblist,
+                                  BalsaMailboxNode* mbnode);
 #endif
diff -b -dNru --exclude-from=excl balsa-cvs/src/mailbox-node.c balsa-defer-imap/src/mailbox-node.c
--- balsa-cvs/src/mailbox-node.c	Mon Nov 26 07:54:29 2001
+++ balsa-defer-imap/src/mailbox-node.c	Wed Dec  5 11:52:13 2001
@@ -54,8 +54,10 @@
 static GNode* add_local_mailbox(GNode*root, const char*d_name, const char* fn);
 static GNode* add_local_folder(GNode*root, const char*d_name, const char* fn);
 
-static GNode* add_imap_mailbox(GNode*root, const char* fn, char delim);
-static GNode* add_imap_folder(GNode*root, const char* fn, char delim);
+static GNode *add_imap_mailbox(GNode * root, const char *fn, char delim,
+			       gboolean scanned);
+static GNode *add_imap_folder(GNode * root, const char *fn, char delim,
+			      gboolean scanned);
 
 enum {
     SAVE_CONFIG,
@@ -145,6 +147,7 @@
     mn->sort_type = GTK_SORT_DESCENDING;
     mn->sort_field = BALSA_SORT_NO;
     mn->subscribed = FALSE;
+    mn->scanned = FALSE;
 }
 
 static void
@@ -233,7 +236,8 @@
 {
     g_return_if_fail(mb->server);
     libbalsa_scanner_imap_dir(r, mb->server, mb->dir, mb->subscribed,
-                              mb->list_inbox, 7,
+                              mb->list_inbox, 
+                              balsa_app.imap_scan_depth,
 			      add_imap_folder, add_imap_mailbox);
     /* register whole tree */
     printf("imap_dir_cb:  main mailbox node %s mailbox is %p\n", 
@@ -418,7 +422,7 @@
 {
     GNode *gnode;
 
-    g_return_if_fail(mn->mailbox == NULL);
+    /* Why: g_return_if_fail(mn->mailbox == NULL); ? */
 
     gnode = balsa_find_mbnode(balsa_app.mailbox_nodes, mn);
 
@@ -430,6 +434,9 @@
 	balsa_mailbox_node_append_subtree(mn, gnode);
 	mn->expanded = expanded;
 	balsa_mblist_repopulate(balsa_app.mblist);
+        if (expanded)
+            /* if this is an IMAP node, we must scan the children */
+	    mblist_scan_mailbox_node(balsa_app.mblist, mn);
     } else g_warning("folder node %s (%p) not found in hierarchy.\n",
 		     mn->name, mn);
 }
@@ -826,7 +833,7 @@
  * Finds the node if it exists, and creates one if it doesn't.
  */
 static GNode* 
-add_imap_entry(GNode*root, const char* fn, char delim)
+add_imap_entry(GNode*root, const char* fn, char delim, gboolean scanned)
 { 
     GNode* node;
     gchar * parent_name;
@@ -870,6 +877,7 @@
 	mbnode->name = g_strdup(basename);
 	mbnode->parent = BALSA_MAILBOX_NODE(parent->data);
 	mbnode->subscribed = mbnode->parent->subscribed;
+	mbnode->scanned = scanned;
 	node = g_node_new(mbnode);
     }
 
@@ -890,7 +898,7 @@
    
 */
 static GNode*
-add_imap_mailbox(GNode*root, const char* fn, char delim)
+add_imap_mailbox(GNode*root, const char* fn, char delim, gboolean scanned)
 { 
     LibBalsaMailboxImap* m;
     const gchar *basename;
@@ -905,7 +913,7 @@
 	    return NULL; 
     }
 
-    node = add_imap_entry(root, fn, delim);
+    node = add_imap_entry(root, fn, delim, scanned);
     mbnode = BALSA_MAILBOX_NODE(node->data);
     if (LIBBALSA_IS_MAILBOX_IMAP(mbnode->mailbox))
 	/* it already has a mailbox */
@@ -932,10 +940,10 @@
 }
 
 static GNode*
-add_imap_folder(GNode*root, const char* fn, char delim)
+add_imap_folder(GNode*root, const char* fn, char delim, gboolean scanned)
 { 
     if(balsa_app.debug) 
 	printf("add_imap_folder: Adding folder of path %s\n", fn);
-    return add_imap_entry(root, fn, delim);
+    return add_imap_entry(root, fn, delim, scanned);
 }
 
diff -b -dNru --exclude-from=excl balsa-cvs/src/mailbox-node.h balsa-defer-imap/src/mailbox-node.h
--- balsa-cvs/src/mailbox-node.h	Wed Oct 24 17:31:04 2001
+++ balsa-defer-imap/src/mailbox-node.h	Thu Nov 29 07:56:05 2001
@@ -73,6 +73,7 @@
     LibBalsaServer * server; /* Used only by remote; is referenced */
     gboolean subscribed;     /* Used only by remote */
     gboolean list_inbox;     /* Used only by remote */
+    gboolean scanned;        /* IMAP flag */
 };
 
 struct _BalsaMailboxNodeClass {
diff -b -dNru --exclude-from=excl balsa-cvs/src/pref-manager.c balsa-defer-imap/src/pref-manager.c
--- balsa-cvs/src/pref-manager.c	Sun Nov 11 17:00:17 2001
+++ balsa-defer-imap/src/pref-manager.c	Sat Dec  1 08:00:46 2001
@@ -138,6 +138,9 @@
     GtkWidget *spell_check_sig;
     GtkWidget *spell_check_quoted;
 
+    /* IMAP folder scanning */
+    GtkWidget *imap_scan_depth;
+
 } PropertyUI;
 
 
@@ -439,6 +442,10 @@
 		       GTK_SIGNAL_FUNC(properties_modified_cb),
 		       property_box);
 
+    gtk_signal_connect(GTK_OBJECT(pui->imap_scan_depth), "changed",
+		       GTK_SIGNAL_FUNC(properties_modified_cb),
+		       property_box);
+
     gtk_signal_connect(GTK_OBJECT(pui->empty_trash), "toggled",
 		       GTK_SIGNAL_FUNC(properties_modified_cb),
 		       property_box);
@@ -674,6 +681,9 @@
 	GTK_TOGGLE_BUTTON(pui->check_mail_upon_startup)->active;
     balsa_app.remember_open_mboxes =
 	GTK_TOGGLE_BUTTON(pui->remember_open_mboxes)->active;
+    balsa_app.imap_scan_depth =
+	gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON
+					 (pui->imap_scan_depth));
     balsa_app.empty_trash_on_exit =
 	GTK_TOGGLE_BUTTON(pui->empty_trash)->active;
 
@@ -929,6 +939,8 @@
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
 				 (pui->remember_open_mboxes),
 				 balsa_app.remember_open_mboxes);
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(pui->imap_scan_depth),
+			      balsa_app.imap_scan_depth);
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pui->empty_trash),
 				 balsa_app.empty_trash_on_exit);
 
@@ -2105,7 +2117,6 @@
     GtkWidget *frame;
     GtkWidget *vb1;
     GtkObject *scan_adj;
-    GtkWidget *scan_spin;
     GtkWidget *hbox;
     const guint padding = 5;
 
@@ -2131,6 +2142,37 @@
     gtk_box_pack_start(GTK_BOX(vb1), pui->remember_open_mboxes,
 		       FALSE, FALSE, 0);
 
+    /* do the IMAP scan depth */
+    frame = gtk_frame_new(_("IMAP Folder Scanning"));
+    gtk_container_set_border_width(GTK_CONTAINER(frame), padding);
+    gtk_box_pack_start(GTK_BOX(vbox1), frame, FALSE, FALSE, 0);
+    vb1 = vbox_in_container(frame);
+
+    hbox = gtk_hbox_new(FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(vb1), hbox, FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(hbox),
+                       gtk_label_new(_("Choose depth 1 for fast startup; "
+                                       "this defers scanning some folders.")),
+                       FALSE, FALSE, 0);
+    hbox = gtk_hbox_new(FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(vb1), hbox, FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(hbox),
+                       gtk_label_new(_("To see more of the tree at startup, "
+                                       "choose a greater depth.")),
+                       FALSE, FALSE, 0);
+
+    hbox = gtk_hbox_new(FALSE, padding);
+    gtk_box_pack_start(GTK_BOX(vb1), hbox, FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(hbox),
+                       gtk_label_new(_("Scan tree to depth")),
+                       FALSE, FALSE, 0);
+    scan_adj = gtk_adjustment_new(1.0, 1.0, 99.0, 1.0, 5.0, 0.0);
+    pui->imap_scan_depth =
+        gtk_spin_button_new(GTK_ADJUSTMENT(scan_adj), 1, 0);
+    gtk_box_pack_start(GTK_BOX(hbox), pui->imap_scan_depth,
+                       FALSE, FALSE, 0);
+
+
     return vbox1;
 
 }
diff -b -dNru --exclude-from=excl balsa-cvs/src/save-restore.c balsa-defer-imap/src/save-restore.c
--- balsa-cvs/src/save-restore.c	Wed Nov 28 05:43:09 2001
+++ balsa-defer-imap/src/save-restore.c	Thu Nov 29 08:04:00 2001
@@ -668,6 +668,11 @@
     balsa_app.quiet_background_check=d_get_gint("QuietBackgroundCheck", 0);
     gnome_config_pop_prefix();
 
+    /* IMAP folder scanning */
+    gnome_config_push_prefix(BALSA_CONFIG_PREFIX "IMAPFolderScanning/");
+    balsa_app.imap_scan_depth = d_get_gint("ScanDepth", 1);
+    gnome_config_pop_prefix();
+
     /* how to react if a message with MDN request is displayed */
     gnome_config_push_prefix(BALSA_CONFIG_PREFIX "MDNReply/");
     balsa_app.mdn_reply_clean = gnome_config_get_int("Clean=1");
@@ -929,6 +934,11 @@
 
     gnome_config_pop_prefix();
 
+    /* IMAP folder scanning */
+    gnome_config_push_prefix(BALSA_CONFIG_PREFIX "IMAPFolderScanning/");
+    gnome_config_set_int("ScanDepth", balsa_app.imap_scan_depth);
+    gnome_config_pop_prefix();
+
     /* how to react if a message with MDN request is displayed */
     gnome_config_push_prefix(BALSA_CONFIG_PREFIX "MDNReply/");
     gnome_config_set_int("Clean", balsa_app.mdn_reply_clean);
