function fetch_imap_folders()
 {
     $server = array_var($_GET, 'server');
     $ssl = array_var($_GET, 'ssl') == "checked";
     $port = array_var($_GET, 'port');
     $email = array_var($_GET, 'email');
     $pass = array_var($_GET, 'pass');
     $genid = array_var($_GET, 'genid');
     tpl_assign('genid', $genid);
     $account = new MailAccount();
     $account->setIncomingSsl($ssl);
     $account->setIncomingSslPort($port);
     $account->setEmail($email);
     $account->setPassword(MailUtilities::ENCRYPT_DECRYPT($pass));
     $account->setServer($server);
     try {
         $real_folders = MailUtilities::getImapFolders($account);
         $imap_folders = array();
         foreach ($real_folders as $folder_name) {
             $acc_folder = new MailAccountImapFolder();
             $acc_folder->setAccountId(0);
             $acc_folder->setFolderName($folder_name);
             $acc_folder->setCheckFolder($folder_name == 'INBOX');
             // By default only INBOX is checked
             $imap_folders[] = $acc_folder;
         }
         tpl_assign('imap_folders', $imap_folders);
     } catch (Exception $e) {
         //Logger::log($e->getTraceAsString());
     }
 }