diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index b17e93e..c14e191 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -119,6 +119,13 @@ class rcube_imap
     $ICL_PORT = $port;
     $IMAP_USE_INTERNAL_DATE = false;
 
+    // Setting rootdir before iil_Connect can save time detecting the namespace
+    if ($imap_root = rcmail::get_instance()->config->get('imap_root')) {
+        // Iloha looks for a global variable $my_prefs
+        global $my_prefs;
+        $my_prefs["rootdir"] = $imap_root; 
+    }
+
     $this->conn = iil_Connect($host, $user, $pass, array('imap' => $auth_type ? $auth_type : 'check'));
     $this->host = $host;
     $this->user = $user;
