Happy New Year
[squirrelmail.git] / src / left_main.php
index 194eb5b5a3806a44b5cb7915574a1be4cab287aa..0519381f35eb4ebd6d8ae0d689eef620db32ab94 100644 (file)
@@ -6,12 +6,15 @@
  * This is the code for the left bar. The left bar shows the folders
  * available, and has cookie information.
  *
- * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @copyright 1999-2020 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  */
 
+/** This is the left_main page */
+define('PAGE_NAME', 'left_main');
+
 /**
  * Include the SquirrelMail initialization file.
  */
@@ -20,18 +23,14 @@ require('../include/init.php');
 /* SquirrelMail required files. */
 require_once(SM_PATH . 'functions/imap_general.php');
 require_once(SM_PATH . 'functions/date.php');
-require_once(SM_PATH . 'templates/util_global.php');
-require_once(SM_PATH . 'templates/util_left_main.php');
+require_once(SM_PATH . 'functions/template/folder_list_util.php');
 
 /* These constants are used for folder stuff. */
 define('SM_BOX_UNCOLLAPSED', 0);
 define('SM_BOX_COLLAPSED',   1);
 
 /* get globals */
-sqgetGlobalVar('username', $username, SQ_SESSION);
-sqgetGlobalVar('key', $key, SQ_COOKIE);
 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
-sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
 
 sqgetGlobalVar('fold', $fold, SQ_GET);
 sqgetGlobalVar('unfold', $unfold, SQ_GET);
@@ -39,16 +38,15 @@ sqgetGlobalVar('unfold', $unfold, SQ_GET);
 
 // open a connection on the imap port (143)
 // why hide the output?
-$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, true);
+global $imap_stream_options; // in case not defined in config
+$imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, true, $imap_stream_options);
 
 /**
  * Using stristr since very old preferences may contain "None" and "none".
  */
 if (!empty($left_refresh) &&
     !stristr($left_refresh, 'none')){
-    $xtra =  "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\" />\n" .
-             "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n".
-             "<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
+    $xtra =  "\n<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
 } else {
     $xtra = '';
 }
@@ -56,7 +54,7 @@ if (!empty($left_refresh) &&
 /**
  * Include extra javascript files needed by template
  */
-$js_includes = $oTemplate->getJavascriptIncludes();
+$js_includes = $oTemplate->get_javascript_includes(TRUE);
 foreach ($js_includes as $js_file) {
     $xtra .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
 }
@@ -64,7 +62,8 @@ foreach ($js_includes as $js_file) {
 // get mailbox list and cache it
 $mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders);
 
-displayHtmlHeader( 'SquirrelMail', $xtra );
+displayHtmlHeader( $org_title, $xtra );
+$oErrorHandler->setDelayedErrors(true);
 
 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION);
 /* If requested and not yet complete, attempt to autocreate folders. */
@@ -72,9 +71,19 @@ if ($auto_create_special && !isset($auto_create_done)) {
     $autocreate = array($sent_folder, $trash_folder, $draft_folder);
     $folders_created = false;
     foreach( $autocreate as $folder ) {
-        if (($folder != '') && ($folder != 'none')) {
-            // use $mailboxes array for checking if mailbox exists
-            if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailboxes)) {
+        if ($folder != '' && $folder != SMPREF_NONE) {
+            /**
+             * If $show_only_subscribed_folders is true, don't use 
+             * $mailboxes array for checking if mailbox exists.
+             * Mailbox list contains only subscribed folders. 
+             * sqimap_mailbox_create() will fail, if folder exists.
+             */
+            if ($show_only_subscribed_folders) {
+                $mailbox_cache = false;
+            } else {
+                $mailbox_cache = $mailboxes;
+            }
+            if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailbox_cache)) {
                 sqimap_mailbox_create($imapConnection, $folder, '');
                 $folders_created = true;
             } else {
@@ -134,6 +143,7 @@ if ($date_format != 6) {
     }
     $clk = str_replace(' ','&nbsp;',$clk);
 
+//FIXME don't build HTML here - do it in template
     $clock = '<small><span style="white-space: nowrap;">'
        . str_replace(' ', '&nbsp;', _("Last Refresh"))
        . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
@@ -183,9 +193,8 @@ $oTemplate->assign('mailboxes', $mailbox_structure);
  * globals, which are dirty, filthy things in templates. :)
  */
 $settings = array();
-$settings['imapConnection'] = $imapConnection;
-$settings['iconThemePath'] = $icon_theme_path;
-$settings['templateDirectory'] = $sTplDir;
+#$settings['imapConnection'] = $imapConnection;
+$settings['templateID'] = $sTemplateID;
 $settings['unreadNotificationEnabled'] = $unseen_notify!=1;
 $settings['unreadNotificationAllFolders'] = $unseen_notify == 3;
 $settings['unreadNotificationDisplayTotal'] = $unseen_type == 2;
@@ -195,8 +204,13 @@ $settings['messageRecyclingEnabled'] = $move_to_trash;
 $settings['collapsableFoldersEnabled'] = $collapse_folders==1;
 $oTemplate->assign('settings', $settings);
 
+//access keys
+//
+$oTemplate->assign('accesskey_folders_refresh', $accesskey_folders_refresh);
+$oTemplate->assign('accesskey_folders_purge_trash', $accesskey_folders_purge_trash);
+$oTemplate->assign('accesskey_folders_inbox', $accesskey_folders_inbox);
+
 $oTemplate->display('left_main.tpl');
 
 sqimap_logout($imapConnection);
 $oTemplate->display('footer.tpl');
-?>
\ No newline at end of file