Просмотр исходного кода

Some fixup:

- Operation foo_once step 2 (and final)
- Create folders bugfix
- None folder bugfix
- Fixed some tabs, structs etc.
- Added some (c) stuff
- Removed some debug stuff

This changes should result in a faster SM.
philippe_mingo 23 лет назад
Родитель
Сommit
c3aed0d769

+ 1 - 4
functions/addressbook.php

@@ -7,10 +7,7 @@
    **
    **  $Id$
    **/
-    
-   if (defined ('addressbook_php'))
-      return; 
-   define ('addressbook_php', true); 
+
 
    // This is the path to the global site-wide addressbook.
    // It looks and feels just like a user's .abook file

+ 0 - 3
functions/array.php

@@ -8,9 +8,6 @@
     *  $Id$
     */
 
-   if (defined ('array_php'))
-       return; 
-   define ('array_php', true); 
 
    function ary_sort($ary,$col, $dir = 1){
       // The globals are used because USORT determines what is passed to comp2

+ 22 - 27
functions/auth.php

@@ -1,33 +1,28 @@
 <?php
 
-/**
- ** auth.php
- **
- ** Contains functions used to do authentication.
- **
- ** $Id$
- **/
+    /**
+    ** auth.php
+    **
+    ** Contains functions used to do authentication.
+    **
+    ** $Id$
+    **/
 
-   if (defined ('auth_php'))
-      return; 
-   define ('auth_php', true);
-   
-   function is_logged_in () {
-      global $squirrelmail_language;
-      
-      if (session_is_registered('user_is_logged_in'))
-         return;
 
-      set_up_language($squirrelmail_language, true);
-      
-      echo "<html><body bgcolor=\"ffffff\">\n";
-      echo "<br><br>";
-      echo "<center>";
-      echo "<b>"._("You must be logged in to access this page.")."</b><br>";
-      echo "<a href=\"../src/login.php\" target=\"_top\">"._("Go to the login page")."</a>\n";
-      echo "</center>";
-      echo "</body></html>\n";
-      exit;
-   }
+    function is_logged_in () {
+        global $squirrelmail_language;
+
+        if ( session_is_registered('user_is_logged_in') )
+            return;
+
+        set_up_language($squirrelmail_language, true);
+
+        echo "<html><body bgcolor=\"ffffff\">\n" .
+            '<br><br>echo "<center><b>'.
+            _("You must be logged in to access this page.").'</b><br>'.
+            "<a href=\"../src/login.php\" target=\"_top\">"._("Go to the login page")."</a>\n".
+            "</center></body></html>\n";
+        exit;
+    }
 
 ?>

+ 0 - 4
functions/date.php

@@ -10,10 +10,6 @@
     **  $Id$
     **/
 
-   if (defined ('date_php'))
-      return; 
-   define ('date_php', true);
-   
    // corrects a time stamp to be the local time
    function getGMTSeconds($stamp, $gmt) {
       global $invert_time;

+ 119 - 123
functions/db_prefs.php

@@ -28,155 +28,151 @@
     **  $Id$
     **/
 
-   if (defined('prefs_php'))
-       return;
-   define('prefs_php', true);
-
    require_once('DB.php');
 
    class dbPrefs {
       var $DSN   = 'mysql://user@host/database';
       var $table = 'userprefs';
-      
+
       var $dbh   = NULL;
       var $error = NULL;
 
       var $default = Array('chosen_theme'      => '../themes/default_theme.php',
-			   'show_html_default' => '0');
-      
+                           'show_html_default' => '0');
+
       function dbPrefs() {
-	 $this->open();
+         $this->open();
       }
-      
+
       function open() {
-	 if(isset($this->dbh)) return true;
-	 $dbh = DB::connect($this->DSN, true);
-	 
-	 if(DB::isError($dbh) || DB::isWarning($dbh)) {
-	    $this->error = DB::errorMessage($dbh);
-	    return false;
-	 }
-	 
-	 $this->dbh = $dbh;
-	 return true;
+        if(isset($this->dbh)) return true;
+        $dbh = DB::connect($this->DSN, true);
+
+        if(DB::isError($dbh) || DB::isWarning($dbh)) {
+            $this->error = DB::errorMessage($dbh);
+            return false;
+        }
+
+        $this->dbh = $dbh;
+        return true;
       }
-      
+
 
       function failQuery($res = NULL) {
-	 if($res == NULL) {
-	    printf(_("Preference database error (%s). Exiting abnormally"),
-		   $this->error);
-	 } else {
-	    printf(_("Preference database error (%s). Exiting abnormally"),
-		   DB::errorMessage($res));
-	 }
-	 exit;
+        if($res == NULL) {
+            printf(_("Preference database error (%s). Exiting abnormally"),
+            $this->error);
+        } else {
+            printf(_("Preference database error (%s). Exiting abnormally"),
+            DB::errorMessage($res));
+        }
+        exit;
       }
 
 
       function getKey($user, $key) {
-	 $this->open();
-	 $query = sprintf("SELECT prefval FROM %s ".
-			  "WHERE user='%s' AND prefkey='%s'",
-			  $this->table, 
-			  $this->dbh->quoteString($user),
-			  $this->dbh->quoteString($key));
-
-	 $res = $this->dbh->query($query);
-	 if(DB::isError($res))
-	    $this->failQuery($res);
-
-	 if($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
-	    return $row['prefval'];
-	 } else {
-	    if(isset($this->default[$key])) {
-	       return $this->default[$key];
-	    } else {
-	       return '';
-	    }
-	 }
-
-	 return '';
+        $this->open();
+        $query = sprintf("SELECT prefval FROM %s ".
+                "WHERE user='%s' AND prefkey='%s'",
+                $this->table,
+                $this->dbh->quoteString($user),
+                $this->dbh->quoteString($key));
+
+        $res = $this->dbh->query($query);
+        if(DB::isError($res))
+            $this->failQuery($res);
+
+        if($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
+            return $row['prefval'];
+        } else {
+            if(isset($this->default[$key])) {
+            return $this->default[$key];
+            } else {
+            return '';
+            }
+        }
+
+        return '';
       }
 
       function deleteKey($user, $key) {
-	 $this->open();
-	 $query = sprintf("DELETE FROM %s WHERE user='%s' AND prefkey='%s'",
-			  $this->table, 
-			  $this->dbh->quoteString($user),
-			  $this->dbh->quoteString($key));
+        $this->open();
+        $query = sprintf("DELETE FROM %s WHERE user='%s' AND prefkey='%s'",
+                $this->table,
+                $this->dbh->quoteString($user),
+                $this->dbh->quoteString($key));
 
-	 $res = $this->dbh->simpleQuery($query);
-         if(DB::isError($res))
-	    $this->failQuery($res);
+        $res = $this->dbh->simpleQuery($query);
+            if(DB::isError($res))
+            $this->failQuery($res);
 
-	 if(substr($key, 0, 9) == 'highlight') {
-	    $this->renumberHighlightList($user);
-	 }
+        if(substr($key, 0, 9) == 'highlight') {
+            $this->renumberHighlightList($user);
+        }
 
-	 return true;
+        return true;
       }
 
       function setKey($user, $key, $value) {
-	 $this->open();
-	 $query = sprintf("REPLACE INTO %s (user,prefkey,prefval) ".
-			  "VALUES('%s','%s','%s')",
-			  $this->table, 
-			  $this->dbh->quoteString($user),
-			  $this->dbh->quoteString($key),
-			  $this->dbh->quoteString($value));
-
-         $res = $this->dbh->simpleQuery($query);
-         if(DB::isError($res)) 
-	    $this->failQuery($res);
-
-	 return true;
+        $this->open();
+        $query = sprintf("REPLACE INTO %s (user,prefkey,prefval) ".
+                "VALUES('%s','%s','%s')",
+                $this->table,
+                $this->dbh->quoteString($user),
+                $this->dbh->quoteString($key),
+                $this->dbh->quoteString($value));
+
+            $res = $this->dbh->simpleQuery($query);
+            if(DB::isError($res))
+            $this->failQuery($res);
+
+        return true;
       }
 
-      
+
       /**
        ** When a highlight option is deleted the preferences module
        ** must renumber the list.  This should be done somewhere else,
-       ** but it is not, so....  
+       ** but it is not, so....
        **/
       function renumberHighlightList($user) {
-	 $this->open();
-	 $query = sprintf("SELECT * FROM %s WHERE user='%s' ".
-			  "AND prefkey LIKE 'highlight%%' ORDER BY prefkey",
-			  $this->table, 
-			  $this->dbh->quoteString($user));
-
-	 $res = $this->dbh->query($query);
-         if(DB::isError($res))
-	    $this->failQuery($res);
-
-	 // Store old data in array
-	 $rows = Array();
-	 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) 
-	    $rows[] = $row;
-
-	 // Renumber keys of old data
-	 $hilinum = 0;
-	 for($i = 0; $i < count($rows) ; $i++) {
-	    $oldkey = $rows[$i]['prefkey'];
-	    $newkey = substr($oldkey, 0, 9) . $hilinum;
-	    $hilinum++;
-
-	    if($oldkey != $newkey) {
-	       $query = sprintf("UPDATE %s SET prefkey='%s' WHERE user='%s' ".
-				"AND prefkey='%s'", 
-				$this->table,
-				$this->dbh->quoteString($newkey),
-				$this->dbh->quoteString($user),
-				$this->dbh->quoteString($oldkey));
-	       
-	       $res = $this->dbh->simpleQuery($query);
-	       if(DB::isError($res))
-		  $this->failQuery($res);
-	    }
-	 }
-
-	 return;
+        $this->open();
+        $query = sprintf("SELECT * FROM %s WHERE user='%s' ".
+                "AND prefkey LIKE 'highlight%%' ORDER BY prefkey",
+                $this->table,
+                $this->dbh->quoteString($user));
+
+        $res = $this->dbh->query($query);
+            if(DB::isError($res))
+            $this->failQuery($res);
+
+        // Store old data in array
+        $rows = Array();
+        while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
+            $rows[] = $row;
+
+        // Renumber keys of old data
+        $hilinum = 0;
+        for($i = 0; $i < count($rows) ; $i++) {
+            $oldkey = $rows[$i]['prefkey'];
+            $newkey = substr($oldkey, 0, 9) . $hilinum;
+            $hilinum++;
+
+            if($oldkey != $newkey) {
+            $query = sprintf("UPDATE %s SET prefkey='%s' WHERE user='%s' ".
+                    "AND prefkey='%s'",
+                    $this->table,
+                    $this->dbh->quoteString($newkey),
+                    $this->dbh->quoteString($user),
+                    $this->dbh->quoteString($oldkey));
+
+            $res = $this->dbh->simpleQuery($query);
+            if(DB::isError($res))
+            $this->failQuery($res);
+            }
+        }
+
+        return;
       }
 
    } // end class dbPrefs
@@ -186,9 +182,9 @@
    function getPref($data_dir, $username, $string, $default ) {
       $db = new dbPrefs;
       if(isset($db->error)) {
-	 printf(_("Preference database error (%s). Exiting abnormally"),
-		$db->error);
-	 exit;
+        printf( _("Preference database error (%s). Exiting abnormally"),
+                $db->error);
+        exit;
       }
 
       return $db->getKey($username, $string);
@@ -202,12 +198,12 @@
       $db->deleteKey($username, $string);
       return;
    }
-   
+
    /** sets the pref, $string, to $set_to **/
    function setPref($data_dir, $username, $string, $set_to) {
       $db = new dbPrefs;
       if(isset($db->error))
-	 $db->failQuery();
+         $db->failQuery();
 
       $db->setKey($username, $string, $set_to);
       return;
@@ -217,14 +213,14 @@
    function checkForPrefs($data_dir, $username) {
       $db = new dbPrefs;
       if(isset($db->error))
-	 $db->failQuery();
+         $db->failQuery();
    }
 
    /** Writes the Signature **/
    function setSig($data_dir, $username, $string) {
       $db = new dbPrefs;
-      if(isset($db->error)) 
-	 $db->failQuery();
+      if(isset($db->error))
+         $db->failQuery();
 
       $db->setKey($username, "___signature___", $string);
       return;
@@ -234,7 +230,7 @@
    function getSig($data_dir, $username) {
       $db = new dbPrefs;
       if(isset($db->error))
-	 $db->failQuery();
+         $db->failQuery();
 
       return $db->getKey($username, "___signature___");
    }

+ 0 - 4
functions/display_messages.php

@@ -8,10 +8,6 @@
     ** $Id$
     **/
 
-    if (defined ('display_messages_php'))
-       return; 
-    define ('display_messages_php', true); 
-
     function error_username_password_incorrect($color) {
       echo '<BR>';
       echo " <TABLE COLS=1 WIDTH=75% NOBORDER BGCOLOR=\"$color[4]\" ALIGN=CENTER>";

+ 0 - 4
functions/gettext.php

@@ -9,10 +9,6 @@
     * Very special thanks to Konstantin Riabitsev for letting me use a
     * server that didn't already have gettext on it!
     */
-     
-   if (defined('gettext_php'))
-      return;
-   define('gettext_php', true);
    
    global $gettext_php_domain, $gettext_php_dir, $gettext_php_loaded,
       $gettext_php_translateStrings, $gettext_php_loaded_language,

+ 4 - 8
functions/i18n.php

@@ -12,10 +12,6 @@
  ** $Id$
  **/
 
-   if (defined ('i18n_php'))
-      return; 
-   define ('i18n_php', true);
-
    global $squirrelmail_language, $languages;
    if (! isset($squirrelmail_language)) { $squirrelmail_language = ''; }
 
@@ -26,9 +22,9 @@
 
    /* PLEASE DON'T TOUCH!!!
     * Correct locale name, which should be set by setlocale and/or putenv('LC_ALL='...)
-	* is 'cs_CZ' and NOT 'cs', this applies to all locale names, look into docs, if you
-	* don't believe me.  Ondrej Sury, czech and slovak translator.
-	*/
+    * is 'cs_CZ' and NOT 'cs', this applies to all locale names, look into docs, if you
+    * don't believe me.  Ondrej Sury, czech and slovak translator.
+    */
    $languages['cs_CZ']['NAME']    = 'Czech';
    $languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
    $languages['cs']['ALIAS']      = 'cs_CZ';
@@ -882,4 +878,4 @@
      if ($my_charset) $default_charset=$my_charset;
    }
 
-?>
+?>

+ 3 - 5
functions/imap.php

@@ -1,18 +1,16 @@
 <?php
+
    /**  This just includes the different sections of the imap functions.
     **  They have been organized into these sections for simplicity sake.
     **
     **  $Id$
     **/
 
-   if (defined ('imap_php'))
-      return; 
-   define ('imap_php', true); 
-
    $imap_backend = 'imap';
-   
+
    require_once('../functions/' . $imap_backend . '_mailbox.php');
    require_once('../functions/' . $imap_backend . '_messages.php');
    require_once('../functions/' . $imap_backend . '_general.php');
    require_once('../functions/' . $imap_backend . '_search.php');
+
 ?>

+ 0 - 4
functions/imap_general.php

@@ -10,10 +10,6 @@
     **  $Id$
     **/
 
-   if (defined ('imap_general_php'))
-      return;
-   define ('imap_general_php', true);
-
 global $imap_general_debug;
 $imap_general_debug = false;
 

+ 3 - 3
functions/imap_mailbox.php

@@ -40,9 +40,9 @@
    function sqimap_mailbox_select ($imap_stream, $mailbox, $hide=true, $recent=false) {
       global $auto_expunge;
 
-      if( $mailbox == _("None") )
+      if( $mailbox == 'None' )
           return;
-      
+
       fputs ($imap_stream, sqimap_session_id() . " SELECT \"$mailbox\"\r\n");
              $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $response, $message);
       if ($recent) {
@@ -66,7 +66,7 @@
     ******************************************************************************/
    function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
       global $delimiter;
-      if (strtolower($type) == "noselect") {
+      if (strtolower($type) == 'noselect') {
          $mailbox = $mailbox.$delimiter;
       }
       fputs ($imap_stream, sqimap_session_id() . " CREATE \"$mailbox\"\r\n");

+ 0 - 4
functions/imap_messages.php

@@ -7,10 +7,6 @@
     **  $Id$
     **/
 
-   if (defined ('imap_messages_php'))
-       return;
-   define ('imap_messages_php', true);
-
    /******************************************************************************
     **  Copies specified messages to specified folder
     ******************************************************************************/

+ 0 - 4
functions/imap_search.php

@@ -3,10 +3,6 @@
     ** IMAP SEARCH ROUTIES
     ** $Id$
     *****************************************************************/
-    
-   if (defined ('imap_search_php'))
-      return;
-   define ('imap_search_php', true);
    
    require_once('../functions/imap.php');
    require_once('../functions/date.php');

+ 10 - 10
functions/index.php

@@ -1,14 +1,14 @@
 <?php
-/**
- ** index.php
- **
- ** This file simply takes any attempt to view source files
- ** and sends those people to the login screen. At this
- ** point no attempt is made to see if the person is logged
- ** or not.
- **/
+    /**
+    ** index.php
+    **
+    ** This file simply takes any attempt to view source files
+    ** and sends those people to the login screen. At this
+    ** point no attempt is made to see if the person is logged
+    ** or not.
+    **/
 
-header("Location:../index.php");
+    header("Location:../index.php");
 
-/** pretty impressive huh? **/
+    /** pretty impressive huh? **/
 ?>

+ 1 - 5
functions/mailbox_display.php

@@ -11,10 +11,6 @@
     * $Id$
     */
 
-   if (defined('mailbox_display_php'))
-       return;
-   define('mailbox_display_php', true);
-
    define('PG_SEL_MAX', 10);  /* Default value for page_selector_max. */
 
    function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
@@ -39,7 +35,7 @@
       $msg = $msgs[$key];
 
       $senderName = htmlspecialchars(sqimap_find_displayable_name($msg['FROM']));
-      if( $mailbox == _("None") ) {
+      if( $mailbox == 'None' ) {
          // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
          $boxes = sqimap_mailbox_list($imapConnection);
          // sqimap_logout($imapConnection);

+ 0 - 4
functions/mime.php

@@ -7,10 +7,6 @@
     ** $Id$
     **/
 
-   if (defined('mime_php'))
-      return;
-   define('mime_php', true);
-
    require_once('../functions/imap.php');
    require_once('../functions/attachment_common.php');
 

+ 0 - 4
functions/page_header.php

@@ -7,10 +7,6 @@
     **  $Id$
     **/
 
-   if (defined('page_header_php'))
-       return;
-   define('page_header_php', true);
-
    // Always set up the language before calling these functions
 
    function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE ) {

+ 55 - 82
functions/plugin.php

@@ -1,90 +1,63 @@
 <?php
 
-/**
- ** plugin.php
- **
- ** This file provides the framework for a plugin architecture.
- **
- ** Plugins will eventually be a way to provide added functionality
- ** without having to patch the SquirrelMail source code. Have some
- ** patience, though, as the these funtions might change in the near
- ** future.
- **
- ** Documentation on how to write plugins might show up some time.
- **
- ** $Id$
- **/
-
-
-   if (defined('plugin_php'))
-      return;
-   define('plugin_php', true);
-
-   global $plugin_general_debug, $squirrelmail_plugin_hooks;
-   $plugin_general_debug = false;
-   
-   $squirrelmail_plugin_hooks = array();
-
-   // This function adds a plugin
-   function use_plugin ($name) {
-      global $plugin_general_debug;
-      
-      if (file_exists('../plugins/'.$name.'/setup.php')) {
-         if ($plugin_general_debug)
-	    echo "plugin:  --  Loading $name/setup.php<br>\n";
-         include_once('../plugins/'.$name.'/setup.php');
-         $function = 'squirrelmail_plugin_init_'.$name;
-         if (function_exists($function))
-	 {
-	    if ($plugin_general_debug)
-	       echo "plugin:  ---- Executing $function to init plugin<br>\n";
-            $function($plugin_general_debug);
-	 }
-	 elseif ($plugin_general_debug)
-	    echo "plugin:  -- Init function $function doesn't exist.<br>\n";
-      }
-      elseif ($plugin_general_debug)
-         echo "plugin:  Couldn't find $name/setup.php<br>\n";
-   }
-
-   // This function executes a hook
-   function do_hook ($name) {
-      global $squirrelmail_plugin_hooks;
-      $Data = func_get_args();
-      if (isset($squirrelmail_plugin_hooks[$name]) && 
-          is_array($squirrelmail_plugin_hooks[$name])) {
-         foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
-            // Add something to set correct gettext domain for plugin
+    /**
+    ** plugin.php
+    **
+    ** This file provides the framework for a plugin architecture.
+    **
+    ** Plugins will eventually be a way to provide added functionality
+    ** without having to patch the SquirrelMail source code. Have some
+    ** patience, though, as the these funtions might change in the near
+    ** future.
+    **
+    ** Documentation on how to write plugins might show up some time.
+    **
+    ** $Id$
+    **/
+
+    global $squirrelmail_plugin_hooks;
+
+    $squirrelmail_plugin_hooks = array();
+
+    // This function adds a plugin
+    function use_plugin ($name) {
+
+        if (file_exists('../plugins/'.$name.'/setup.php')) {
+            include_once('../plugins/'.$name.'/setup.php');
+            $function = 'squirrelmail_plugin_init_'.$name;
             if (function_exists($function)) {
-                $function($Data);
+                $function();
+            }
+        }
+
+    }
+
+    // This function executes a hook
+    function do_hook ($name) {
+        global $squirrelmail_plugin_hooks;
+        $Data = func_get_args();
+        if (isset($squirrelmail_plugin_hooks[$name]) &&
+            is_array($squirrelmail_plugin_hooks[$name])) {
+            foreach ($squirrelmail_plugin_hooks[$name] as $function) {
+                // Add something to set correct gettext domain for plugin
+                if (function_exists($function)) {
+                    $function($Data);
+                }
             }
-         }
-      }
-      
-      // Variable-length argument lists have a slight problem when
-      // passing values by reference.  Pity.  This is a workaround.
-      return $Data;
-  }
+        }
+
+        // Variable-length argument lists have a slight problem when
+        // passing values by reference.  Pity.  This is a workaround.
+        return $Data;
+    }
 
-   // On startup, register all plugins configured for use
-   if (isset($plugins) && is_array($plugins))
-      foreach ($plugins as $id => $name)
-      {
-         if ($plugin_general_debug)
-	    echo "plugin:  Attempting load of plugin $name<br>\n";
-         use_plugin($name);
-      }
+    /* -------------------- MAIN --------------------- */
 
-   if ($plugin_general_debug)
-   {
-      echo "plugin:  Hook list<br>\n";
-      foreach ($squirrelmail_plugin_hooks as $Hook => $Plugins)
-      {
-          foreach ($Plugins as $Name => $Func)
-	  {
-	      echo "[$Hook][$Name] = $Func<br>\n";
-	  }
-      }
-   }
+    // On startup, register all plugins configured for use
+    if (isset($plugins) && is_array($plugins)) {
+        foreach ($plugins as $name) {
+            use_plugin($name);
+        }
+    }
 
 ?>

+ 0 - 4
functions/prefs.php

@@ -7,10 +7,6 @@
     **  $Id$
     **/
 
-   if (defined('prefs_php'))
-      return;
-   define('prefs_php', true);
-
    global $prefs_are_cached, $prefs_cache;
    if (!session_is_registered('prefs_are_cached')) {
       $prefs_are_cached = false;

+ 0 - 4
functions/smtp.php

@@ -7,10 +7,6 @@
     ** $Id$
     **/
 
-   if (defined('smtp_php'))
-      return;
-   define('smtp_php', true);
-
    require_once('../functions/addressbook.php');
    require_once('../functions/plugin.php');
 

+ 0 - 3
functions/strings.php

@@ -10,9 +10,6 @@
     * $Id$
     */
 
-    if (defined('strings_php')) { return; }
-    define('strings_php', true);
-
    /**
     * SquirrelMail version number -- DO NOT CHANGE
     */

+ 10 - 5
functions/tree.php

@@ -1,10 +1,15 @@
 <?php
 
-   /* $Id$ */
-
-   if (defined('tree_php'))
-       return;
-   define('tree_php', true);
+   /**
+    * tree.php
+    * Copyright (c) 1999-2001 The Squirrelmail Development Team
+    * Licensed under the GNU GPL. For full terms see the file COPYING.
+    *
+    * This code provides various string manipulation functions that are
+    * used by the rest of the Squirrelmail code.
+    *
+    * $Id$
+    */
 
    require_once('../functions/imap.php');
 

+ 10 - 5
functions/url_parser.php

@@ -1,10 +1,15 @@
 <?php
-   /* URL Passing code to allow links from with in emails */
-   /* $Id$ */
 
-   if (defined('url_parser_php'))
-      return;
-   define('url_parser_php', true);
+   /**
+    * url_parser.php
+    * Copyright (c) 1999-2001 The Squirrelmail Development Team
+    * Licensed under the GNU GPL. For full terms see the file COPYING.
+    *
+    * This code provides various string manipulation functions that are
+    * used by the rest of the Squirrelmail code.
+    *
+    * $Id$
+    */
 
    function replaceBlock (&$in, $replace, $start, $end) {
       $begin = substr($in,0,$start);

+ 3 - 3
src/addressbook.php

@@ -18,9 +18,9 @@
    // Sort array by the key "name"
    function alistcmp($a,$b) {   
       if($a['backend'] > $b['backend']) 
-	 return 1;
-      else if($a['backend'] < $b['backend']) 
-	 return -1;
+         return 1;
+      else if($a['backend'] < $b['backend'])
+         return -1;
       
       return (strtolower($a['name']) > strtolower($b['name'])) ? 1 : -1;
    }

+ 1 - 1
src/compose.php

@@ -453,7 +453,7 @@
       $attachments[] = $newAttachment;
     }
 
-   if (!isset($mailbox) || $mailbox == "" || ($mailbox == "None"))
+   if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None'))
       $mailbox = "INBOX";
 
    if (isset($draft)) {

+ 1 - 1
src/download.php

@@ -25,7 +25,7 @@
       global $where, $what, $charset;
       global $startMessage;
       
-      displayPageHeader($color, "None");
+      displayPageHeader($color, 'None');
 
       echo "<BR><TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\">";
       echo "<B><CENTER>";

+ 12 - 1
src/draft_actions.php

@@ -1,5 +1,16 @@
 <?php
-require_once ('../src/validate.php');
+
+   /**
+    **  draft_actions.php
+    **
+    **  Copyright (c) 1999-2000 The SquirrelMail development team
+    **  Licensed under the GNU GPL. For full terms see the file COPYING.
+    **
+    **
+    **  $Id$
+    **/
+
+    require_once ('../src/validate.php');
 
    /* Print all the needed RFC822 headers */
    function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers) {

+ 1 - 1
src/folders.php

@@ -17,7 +17,7 @@
    require_once('../functions/array.php');
    require_once('../functions/plugin.php');
 
-   displayPageHeader($color, _("None"));
+   displayPageHeader($color, 'None');
 
 ?>
 

+ 1 - 1
src/folders_rename_getname.php

@@ -30,7 +30,7 @@
       $old_parent = "";
    }
 
-   displayPageHeader($color, "None");
+   displayPageHeader($color, 'None');
    echo "<br><TABLE align=center border=0 WIDTH=95% COLS=1>";
    echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
    echo _("Rename a folder");

+ 1 - 1
src/folders_subscribe.php

@@ -37,7 +37,7 @@
    sqimap_logout($imapConnection);
 
    /*
-   displayPageHeader($color, "None");
+   displayPageHeader($color, 'None');
    echo "<BR><BR><BR><CENTER><B>";
    if ($method == "sub") {
       echo _("Subscribed Successfully!");

+ 28 - 28
src/help.php

@@ -16,20 +16,20 @@
    require_once('../functions/array.php');
 
 
-   displayPageHeader($color, "None");
-
-	$helpdir[0] = "basic.hlp";
-	$helpdir[1] = "main_folder.hlp";
-	$helpdir[2] = "read_mail.hlp";
-	$helpdir[3] = "compose.hlp";
-	$helpdir[4] = "addresses.hlp";
-	$helpdir[5] = "folders.hlp";
-	$helpdir[6] = "options.hlp";
-	$helpdir[7] = "search.hlp";
-	$helpdir[8] = "FAQ.hlp";
+   displayPageHeader($color, 'None' );
+
+   $helpdir[0] = 'basic.hlp';
+   $helpdir[1] = 'main_folder.hlp';
+   $helpdir[2] = 'read_mail.hlp';
+   $helpdir[3] = 'compose.hlp';
+   $helpdir[4] = 'addresses.hlp';
+   $helpdir[5] = 'folders.hlp';
+   $helpdir[6] = 'options.hlp';
+   $helpdir[7] = 'search.hlp';
+   $helpdir[8] = 'FAQ.hlp';
 
    /****************[ HELP FUNCTIONS ]********************/
-   // parses through and gets the information from the different documents.  
+   // parses through and gets the information from the different documents.
    // this returns one section at a time.  You must keep track of the position
    // so that it knows where to start to look for the next section.
 
@@ -42,18 +42,18 @@
                   $ary[0] = trim($doc[$n]);
                }
                if (trim(strtolower($doc[$n])) == "<description>") {
-	          $ary[1] = "";
+                  $ary[1] = "";
                   for ($n++;$n < count($doc) && (trim(strtolower($doc[$n])) != "</description>"); $n++) {
                      $ary[1] .= $doc[$n];
                   }
                }
                if (trim(strtolower($doc[$n])) == "<summary>") {
-	          $ary[2] = "";
+                  $ary[2] = "";
                   for ($n++;$n < count($doc) && (trim(strtolower($doc[$n])) != "</summary>"); $n++) {
                      $ary[2] .= $doc[$n];
                   }
                }
-            }   
+            }
             if (isset($ary)) {
                $ary[3] = $n;
                return $ary;
@@ -62,14 +62,14 @@
                $ary[1] = "ERROR: Help files are not in the right format!";
                $ary[2] = "ERROR: Help files are not in the right format!";
                return $ary;
-            }   
+            }
          }
       }
       $ary[0] = "ERROR: Help files are not in the right format!";
       $ary[1] = "ERROR: Help files are not in the right format!";
       return $ary;
    }
-   
+
    /**************[ END HELP FUNCTIONS ]******************/
 
 ?>
@@ -87,21 +87,21 @@
    if ($HTTP_REFERER) {
       $ref = strtolower($HTTP_REFERER);
       if (strpos($ref, "src/compose"))
-         $context = "compose"; 
+         $context = "compose";
       else if (strpos($ref, "src/addr"))
-         $context = "address"; 
+         $context = "address";
       else if (strpos($ref, "src/folders"))
-         $context = "folders"; 
+         $context = "folders";
       else if (strpos($ref, "src/options"))
-         $context = "options"; 
+         $context = "options";
       else if (strpos($ref, "src/right_main"))
-         $context = "index"; 
+         $context = "index";
       else if (strpos($ref, "src/read_body"))
-         $context = "read"; 
+         $context = "read";
       else if (strpos($ref, "src/search"))
-         $context = "search"; 
+         $context = "search";
    }
-   
+
    if (!$squirrelmail_language)
       $squirrelmail_language = "en";
 
@@ -122,7 +122,7 @@
       echo "</td></tr></table>";
       exit;
    }
-   
+
    if ($help_exists) {
       if (! isset($context))
           $context = '';
@@ -170,7 +170,7 @@
          echo "<font size=5><b>$chapter - $help_info[0]</b></font><br><br>\n";
          if (isset($help_info[1]))
             echo "$help_info[1]\n";
-         else   
+         else
             echo "<p>$help_info[2]</p>\n";
 
          $section = 0;
@@ -187,7 +187,7 @@
          echo "<br><center><a href=\"#pagetop\">" . _("Top") . "</a></center>\n";
       }
    }
-   do_hook("help_bottom"); 
+   do_hook("help_bottom");
 ?>
 <tr><td bgcolor="<?php echo $color[0] ?>">&nbsp;</td></tr></table>
 <td></tr></table>

+ 10 - 7
src/image.php

@@ -1,11 +1,14 @@
 <?php
-/**
- ** image.php
- **
- ** This file shows an attached image
- **
- ** $Id$
- **/
+    /**
+    ** image.php
+    **
+    **  Copyright (c) 1999-2000 The SquirrelMail development team
+    **  Licensed under the GNU GPL. For full terms see the file COPYING.
+    **
+    ** This file shows an attached image
+    **
+    ** $Id$
+    **/
 
    require_once('../src/validate.php');
    require_once('../functions/date.php');

+ 10 - 10
src/index.php

@@ -1,14 +1,14 @@
 <?php
-/**
- ** index.php
- **
- ** This file simply takes any attempt to view index of files
- ** and sends those people to the login screen. At this
- ** point no attempt is made to see if the person is logged
- ** or not.
- **/
+    /**
+    ** index.php
+    **
+    ** This file simply takes any attempt to view index of files
+    ** and sends those people to the login screen. At this
+    ** point no attempt is made to see if the person is logged
+    ** or not.
+    **/
 
-header("Location:../index.php");
+    header("Location:../index.php");
 
-/** pretty impressive huh? **/
+    /** pretty impressive huh? **/
 ?>

+ 239 - 247
src/left_main.php

@@ -1,6 +1,7 @@
 <?php
    /**
     * left_main.php
+    *
     * Copyright (c) 1999-2001 The Squirrelmail Development Team
     * Licensed under the GNU GPL. For full terms see the file COPYING.
     *
@@ -14,249 +15,147 @@
     require_once('../functions/array.php');
     require_once('../functions/imap.php');
     require_once('../functions/plugin.php');
+    require_once('../functions/page_header.php');
 
     /* These constants are used for folder stuff. */
     define('SM_BOX_UNCOLLAPSED', 0);
     define('SM_BOX_COLLAPSED',   1);
 
-    global $delimiter;
+/* --------------------- FUNCTIONS ------------------------- */
 
-    // open a connection on the imap port (143)
-    $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
+    function formatMailboxName($imapConnection, $box_array) {
+        global $folder_prefix, $trash_folder, $sent_folder;
+        global $color, $move_to_sent, $move_to_trash;
+        global $unseen_notify, $unseen_type, $collapse_folders;
+        global $draft_folder, $save_as_draft;
+        global $use_special_folder_color;
 
-    displayHtmlHeader();
+        $real_box = $box_array['unformatted'];
+        $mailbox = str_replace('&nbsp;','',$box_array['formatted']);
+        $mailboxURL = urlencode($real_box);
 
-    /* If requested and not yet complete, attempt to autocreate folders. */
-    if ($auto_create_special && ! isset($auto_create_done)) {
-        /* Autocreate the sent folder, if needed. */
-        if (isset ($sent_folder) && $sent_folder != 'none') {
-            if (!sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
-                sqimap_mailbox_create ($imapConnection, $sent_folder, '');
-            } else if (! sqimap_mailbox_is_subscribed($imapConnection, $sent_folder)) {
-                sqimap_subscribe($imapConnection, $sent_folder);
-            }
+        /* Strip down the mailbox name. */
+        if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
+            $mailbox = $regs[2];
         }
 
-            /* Autocreate the trash folder, if needed. */
-        if (isset ($trash_folder) && $trash_folder != 'none') {
-            if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)) {
-                sqimap_mailbox_create ($imapConnection, $trash_folder, '');
-            } else if (! sqimap_mailbox_is_subscribed($imapConnection, $trash_folder)) {
-                sqimap_subscribe($imapConnection, $trash_folder);
+        $unseen = 0;
+
+        if (($unseen_notify == 2 && $real_box == 'INBOX') ||
+            $unseen_notify == 3) {
+            $unseen = sqimap_unseen_messages($imapConnection, $real_box);
+            if ($unseen_type == 1 && $unseen > 0) {
+                $unseen_string = "($unseen)";
+                $unseen_found = true;
+            } else if ($unseen_type == 2) {
+                $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
+                $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
+                $unseen_found = true;
             }
         }
 
-        /* Autocreate the drafts folder, if needed. */
-        if (isset ($draft_folder) && $draft_folder != 'none') {
-            if (!sqimap_mailbox_exists ($imapConnection, $draft_folder)) {
-                sqimap_mailbox_create ($imapConnection, $draft_folder, '');
-            } else if (! sqimap_mailbox_is_subscribed($imapConnection, $draft_folder)) {
-                sqimap_subscribe($imapConnection, $draft_folder);
+        $special_color = false;
+        if ($use_special_folder_color) {
+            if ((strtolower($real_box) == 'inbox')
+                    || (($real_box == $trash_folder) && ($move_to_trash))
+                    || (($real_box == $sent_folder) && ($move_to_sent))
+                    || (($real_box == $draft_folder) && ($save_as_draft))) {
+                $special_color = true;
             }
         }
 
-          /* Let the world know that autocreation is complete! Hurrah! */
-        $auto_create_done = true;
-        session_register('auto_create_done');
-    }
+        /* Start off with a blank line. */
+        $line = '';
 
-   function formatMailboxName($imapConnection, $box_array) {
-      global $folder_prefix, $trash_folder, $sent_folder;
-      global $color, $move_to_sent, $move_to_trash;
-      global $unseen_notify, $unseen_type, $collapse_folders;
-      global $draft_folder, $save_as_draft;
-      global $use_special_folder_color;
-
-      $real_box = $box_array['unformatted'];
-      $mailbox = str_replace('&nbsp;','',$box_array['formatted']);
-      $mailboxURL = urlencode($real_box);
-
-      /* Strip down the mailbox name. */
-      if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
-          $mailbox = $regs[2];
-      }
-
-      $unseen = 0;
-
-      if (($unseen_notify == 2 && $real_box == 'INBOX') ||
-          $unseen_notify == 3) {
-         $unseen = sqimap_unseen_messages($imapConnection, $real_box);
-         if ($unseen_type == 1 && $unseen > 0) {
-            $unseen_string = "($unseen)";
-            $unseen_found = true;
-         } else if ($unseen_type == 2) {
-            $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
-            $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
-            $unseen_found = true;
-         }
-      }
-      
-      $special_color = false;
-      if ($use_special_folder_color) {
-          if ((strtolower($real_box) == 'inbox')
-                || (($real_box == $trash_folder) && ($move_to_trash))
-                || (($real_box == $sent_folder) && ($move_to_sent))
-                || (($real_box == $draft_folder) && ($save_as_draft))) {
-              $special_color = true;
-          }
-      }
-         
-      /* Start off with a blank line. */
-      $line = '';
-
-      /* If there are unseen message, bold the line. */      
-      if ($unseen > 0) { $line .= '<B>'; }
-
-      /* Crate the link for this folder. */
-      $line .= "<A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" TARGET=\"right\" STYLE=\"text-decoration:none\">";
-      if ($special_color == true)
-         $line .= "<FONT COLOR=\"$color[11]\">";
-      $line .= str_replace(' ','&nbsp;',$mailbox);
-      if ($special_color == true)
-         $line .= "</FONT>";
-      $line .= '</A>';
-
-      /* If there are unseen message, close bolding. */
-      if ($unseen > 0) { $line .= "</B>"; }
-
-      /* Print unseen information. */
-      if (isset($unseen_found) && $unseen_found) {
-         $line .= "&nbsp;<SMALL>$unseen_string</SMALL>";
-      }
-
-      if (($move_to_trash == true) && ($real_box == $trash_folder)) {
-         if (! isset($numMessages)) {
-            $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
-         }
-
-         if ($numMessages > 0) {
-            $urlMailbox = urlencode($real_box);
-            $line .= "\n<small>\n";
-            $line .= "&nbsp;&nbsp;(<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("empty")."</A>)";
-            $line .= "\n</small>\n";
-         }
-      }
-
-      /* Return the final product. */
-      return ($line);
-   }
-
-   /**********************************/
-   /* END OF FUNCTION - BACK TO MAIN */
-   /**********************************/
+        /* If there are unseen message, bold the line. */
+        if ($unseen > 0) { $line .= '<B>'; }
 
-    if (isset($left_refresh) && ($left_refresh != 'none') && ($left_refresh != '')) {
-        echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
-        echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"; 
-        echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
-    }
-   
-    echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
+        /* Crate the link for this folder. */
+        $line .= "<A HREF=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" TARGET=\"right\" STYLE=\"text-decoration:none\">";
+        if ($special_color == true)
+            $line .= "<FONT COLOR=\"$color[11]\">";
+        $line .= str_replace(' ','&nbsp;',$mailbox);
+        if ($special_color == true)
+            $line .= "</FONT>";
+        $line .= '</A>';
 
-    do_hook("left_main_before");
+        /* If there are unseen message, close bolding. */
+        if ($unseen > 0) { $line .= "</B>"; }
 
-    $boxes = sqimap_mailbox_list($imapConnection);
+        /* Print unseen information. */
+        if (isset($unseen_found) && $unseen_found) {
+            $line .= "&nbsp;<SMALL>$unseen_string</SMALL>";
+        }
 
-    echo '<CENTER><FONT SIZE=4><B>';
-    echo _("Folders") . "</B><BR></FONT>\n\n";
+        if (($move_to_trash == true) && ($real_box == $trash_folder)) {
+            if (! isset($numMessages)) {
+                $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
+            }
 
-    if ($date_format != 6) { 
-        /* First, display the clock. */
-        if ($hour_format == 1) {
-          if ($date_format == 4) {
-             $hr = "G:i:s";
-          } else {
-             $hr = "G:i";
-          }
-        } else {  
-          if ($date_format == 4) {
-             $hr = "g:i:s a";
-          } else {
-             $hr = "g:i a";
-          }
+            if ($numMessages > 0) {
+                $urlMailbox = urlencode($real_box);
+                $line .= "\n<small>\n" .
+                        "&nbsp;&nbsp;(<A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("empty")."</A>)" .
+                        "\n</small>\n";
+            }
         }
-    
-	switch( $date_format ) {
-	case 1:
-	  $clk = date("m/d/y ".$hr, time()); 
-	  break;
-	case 2:
-	  $clk = date("d/m/y ".$hr, time()); 
-	  break;
-	case 4:
-	case 5:
-	  $clk = date($hr, time()); 
-	  break;
-	default:   
-	  $clk = date("D, ".$hr, time());
-	}
-	$clk = str_replace(' ','&nbsp;',$clk);
-
-	echo '<CENTER><SMALL>' . str_replace(' ','&nbsp;',_("Last Refresh"))
-	  .  ": $clk</SMALL></CENTER>";
+
+        /* Return the final product. */
+        return ($line);
     }
 
-    /* Next, display the refresh button. */
-    echo '<SMALL>(<A HREF="../src/left_main.php" TARGET="left">';
-    echo _("refresh folder list");
-    echo '</A>)</SMALL></CENTER><BR>';
+    /**
+     * Recursive function that computes the collapsed status and parent
+     * (or not parent) status of this box, and the visiblity and collapsed
+     * status and parent (or not parent) status for all children boxes.
+     */
+    function compute_folder_children(&$parbox, $boxcount) {
+        global $boxes, $data_dir, $username, $collapse_folders;
+        $nextbox = $parbox + 1;
 
-    /* Lastly, display the folder list. */
-    if (isset($collapse_folders) && $collapse_folders ) {
-        /* If directed, collapse or uncollapse a folder. */
-        if (isset($fold)) {
-            setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
-        } else if (isset($unfold)) {
-            setPref($data_dir, $username, 'collapse_folder_' . $unfold, $SM_BOX_UNCOLLAPSED);
+        /* Retreive the name for the parent box. */
+        $parbox_name = $boxes[$parbox]['unformatted'];
+
+        /* 'Initialize' this parent box to childless. */
+        $boxes[$parbox]['parent'] = false;
+
+        /* Compute the collapse status for this box. */
+        if( isset($collapse_folders) && $collapse_folders ) {
+            $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name);
+            $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
+        } else {
+            $collapse = SM_BOX_UNCOLLAPSED;
         }
-    }
+        $boxes[$parbox]['collapse'] = $collapse;
 
-    /* Prepare do do out collapsedness and visibility computation. */
-    $curbox = 0;
-    $boxcount = count($boxes);
+        /* Otherwise, get the name of the next box. */
+        if (isset($boxes[$nextbox]['unformatted']))
+            $nextbox_name = $boxes[$nextbox]['unformatted'];
+        else
+            $nextbox_name = '';
 
-    /* Compute the collapsedness and visibility of each box. */
-    while ($curbox < $boxcount) {
-        $boxes[$curbox]['visible'] = true;
-        compute_folder_children($curbox, $boxcount);
-    }
-  
-    for ($i = 0;$i < count($boxes); $i++) {
-        if ($boxes[$i]['visible'] == true) {
-            $mailbox = $boxes[$i]['formatted'];
-            $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
+        /* Compute any children boxes for this box. */
+        while (($nextbox < $boxcount) &&
+               (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) {
 
-            /* Create the prefix for the folder name and link. */
-            $prefix = str_repeat('  ',$mblevel);
-            if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
-                $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2));
-                $prefix .= create_collapse_link($i) . '&nbsp;';
-            } else {
-                $prefix = str_replace(' ','&nbsp;',$prefix);
-            }
-            $line = "<NOBR><TT>$prefix</TT>";
+            /* Note that this 'parent' box has at least one child. */
+            $boxes[$parbox]['parent'] = true;
 
-            /* Add the folder name and link. */
-            if (in_array('noselect', $boxes[$i]['flags'])) {
-                $line .= "<FONT COLOR=\"$color[10]\">";
-                if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
-                    $mailbox = str_replace('&nbsp;','',$mailbox);
-                    $line .= str_replace(' ', '&nbsp;', $mailbox);
-                }
-                $line .= '</FONT>';
+            /* Compute the visiblity of this box. */
+            if ($boxes[$parbox]['visible'] &&
+                ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED)) {
+                $boxes[$nextbox]['visible'] = true;
             } else {
-                $line .= formatMailboxName($imapConnection, $boxes[$i]);
+                $boxes[$nextbox]['visible'] = false;
             }
 
-            /* Put the final touches on our folder line. */
-            $line .= "</NOBR><BR>\n";
-
-            /* Output the line for this folder. */
-            echo $line;
+            /* Compute the visibility of any child boxes. */
+            compute_folder_children($nextbox, $boxcount);
         }
+
+        /* Set the parent box to the current next box. */
+        $parbox = $nextbox;
     }
-    sqimap_logout($imapConnection);
-    do_hook("left_main_after");
 
     /**
      * Create the link for a parent folder that will allow that
@@ -280,7 +179,7 @@
         /* Return the finished product. */
         return ($link);
     }
-   
+
     /**
      * This simple function checks if a box is another box's parent.
      */
@@ -297,57 +196,150 @@
         return ($parbox_name == $actual_parname);
     }
 
-    /**
-     * Recursive function that computes the collapsed status and parent
-     * (or not parent) status of this box, and the visiblity and collapsed
-     * status and parent (or not parent) status for all children boxes.
-     */
-    function compute_folder_children(&$parbox, $boxcount) {
-        global $boxes, $data_dir, $username, $collapse_folders;
-        $nextbox = $parbox + 1;
 
-        /* Retreive the name for the parent box. */
-        $parbox_name = $boxes[$parbox]['unformatted'];
+    /* -------------------- MAIN ------------------------ */
 
-        /* 'Initialize' this parent box to childless. */
-        $boxes[$parbox]['parent'] = false;
+    global $delimiter, $default_folder_prefix;
 
-        /* Compute the collapse status for this box. */
-        if( isset($collapse_folders) && $collapse_folders ) {
-            $collapse = getPref($data_dir, $username, 'collapse_folder_' . $parbox_name);
-            $collapse = ($collapse == '' ? SM_BOX_UNCOLLAPSED : $collapse);
-        } else {
-            $collapse = SM_BOX_UNCOLLAPSED;
+    // open a connection on the imap port (143)
+    $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
+
+
+    if (isset($left_refresh) && ($left_refresh != 'none') && ($left_refresh != '')) {
+        $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";
+    } else {
+        $xtra = '';
+    }
+
+    displayHtmlHeader( 'SquirrelMail', $xtra );
+
+    /* If requested and not yet complete, attempt to autocreate folders. */
+    if ($auto_create_special && !isset($auto_create_done)) {
+        $autocreate = array( $sent_folder,
+                             $trash_folder,
+                             $draft_folder );
+        foreach( $autocreate as $folder ) {
+            if ($folder != '' && $folder != 'none') {
+                if ( !sqimap_mailbox_exists($imapConnection, $folder)) {
+                    sqimap_mailbox_create($imapConnection, $default_folder_prefix.$folder, '');
+                } elseif ( !sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
+                    sqimap_subscribe($imapConnection, $folder);
+                }
+            }
         }
-        $boxes[$parbox]['collapse'] = $collapse;
 
-        /* Otherwise, get the name of the next box. */
-    	if (isset($boxes[$nextbox]['unformatted']))
-               $nextbox_name = $boxes[$nextbox]['unformatted'];
-    	else
-    	   $nextbox_name = '';
+        /* Let the world know that autocreation is complete! Hurrah! */
+        $auto_create_done = true;
+        session_register('auto_create_done');
+    }
 
-        /* Compute any children boxes for this box. */
-        while (($nextbox < $boxcount) &&
-               (is_parent_box($boxes[$nextbox]['unformatted'], $parbox_name))) {
+    echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
 
-            /* Note that this 'parent' box has at least one child. */
-            $boxes[$parbox]['parent'] = true;
+    do_hook('left_main_before');
 
-            /* Compute the visiblity of this box. */
-            if ($boxes[$parbox]['visible'] &&
-                ($boxes[$parbox]['collapse'] != SM_BOX_COLLAPSED)) {
-                $boxes[$nextbox]['visible'] = true;
+    $boxes = sqimap_mailbox_list($imapConnection);
+
+    echo '<CENTER><FONT SIZE=4><B>'. _("Folders") . "</B><BR></FONT>\n\n";
+
+    if ($date_format != 6) {
+        /* First, display the clock. */
+        if ($hour_format == 1) {
+            $hr = 'G:i';
+            if ($date_format == 4) {
+                $hr .= ':s';
+            }
+        } else {
+            if ($date_format == 4) {
+                $hr = 'g:i:s a';
             } else {
-                $boxes[$nextbox]['visible'] = false;
+                $hr = 'g:i a';
             }
+        }
 
-            /* Compute the visibility of any child boxes. */
-            compute_folder_children($nextbox, $boxcount);
+        switch( $date_format ) {
+        case 1:
+            $clk = date('m/d/y '.$hr, time());
+            break;
+        case 2:
+            $clk = date('d/m/y '.$hr, time());
+            break;
+        case 4:
+        case 5:
+            $clk = date($hr, time());
+            break;
+        default:
+            $clk = date('D, '.$hr, time());
         }
+        $clk = str_replace(' ','&nbsp;',$clk);
 
-        /* Set the parent box to the current next box. */
-        $parbox = $nextbox;
+        echo '<CENTER><SMALL>' . str_replace(' ','&nbsp;',_("Last Refresh")) .
+             ": $clk</SMALL></CENTER>";
     }
+
+    /* Next, display the refresh button. */
+    echo '<SMALL>(<A HREF="../src/left_main.php" TARGET="left">'.
+         _("refresh folder list") . '</A>)</SMALL></CENTER><BR>';
+
+    /* Lastly, display the folder list. */
+    if ( $collapse_folders ) {
+        /* If directed, collapse or uncollapse a folder. */
+        if (isset($fold)) {
+            setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED);
+        } else if (isset($unfold)) {
+            setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED);
+        }
+    }
+
+    /* Prepare do do out collapsedness and visibility computation. */
+    $curbox = 0;
+    $boxcount = count($boxes);
+
+    /* Compute the collapsedness and visibility of each box. */
+    while ($curbox < $boxcount) {
+        $boxes[$curbox]['visible'] = TRUE;
+        compute_folder_children($curbox, $boxcount);
+    }
+
+    for ($i = 0;$i < count($boxes); $i++) {
+        if ( $boxes[$i]['visible'] ) {
+            $mailbox = $boxes[$i]['formatted'];
+            $mblevel = substr_count($boxes[$i]['unformatted'], $delimiter) + 1;
+
+            /* Create the prefix for the folder name and link. */
+            $prefix = str_repeat('  ',$mblevel);
+            if (isset($collapse_folders) && $collapse_folders && $boxes[$i]['parent']) {
+                $prefix = str_replace(' ','&nbsp;',substr($prefix,0,strlen($prefix)-2)).
+                          create_collapse_link($i) . '&nbsp;';
+            } else {
+                $prefix = str_replace(' ','&nbsp;',$prefix);
+            }
+            $line = "<NOBR><TT>$prefix</TT>";
+
+            /* Add the folder name and link. */
+            if (in_array('noselect', $boxes[$i]['flags'])) {
+                $line .= "<FONT COLOR=\"$color[10]\">";
+                if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
+                    $mailbox = str_replace('&nbsp;','',$mailbox);
+                    $line .= str_replace(' ', '&nbsp;', $mailbox);
+                }
+                $line .= '</FONT>';
+            } else {
+                $line .= formatMailboxName($imapConnection, $boxes[$i]);
+            }
+
+            /* Put the final touches on our folder line. */
+            $line .= "</NOBR><BR>\n";
+
+            /* Output the line for this folder. */
+            echo $line;
+        }
+    }
+
+    sqimap_logout($imapConnection);
+    do_hook('left_main_after');
+
     echo "</BODY></HTML>\n";
-?>
+
+?>

+ 1 - 1
src/options.php

@@ -34,7 +34,7 @@ if (isset($language)) {
 /*** Build the resultant page. ***/
 /*********************************/
 
-displayPageHeader($color, _("None"));
+displayPageHeader($color, 'None');
 
 define('SMOPT_MODE_DISPLAY', 'display');
 define('SMOPT_MODE_SUBMIT', 'submit');

+ 10 - 1
src/search.php

@@ -1,6 +1,15 @@
 <?php
 
-   /* $Id$ */
+
+    /**
+     * right_main.php
+     *
+     * Copyright (c) 1999-2001 The Squirrelmail Development Team
+     * Licensed under the GNU GPL. For full terms see the file COPYING.
+     *
+     * $Id$
+     */
+
 
    require_once('../src/validate.php');
    require_once('../functions/imap.php');

+ 7 - 7
src/validate.php

@@ -1,12 +1,12 @@
 <?php
     /**
-     * validate.php
-     *
-     * Copyright (c) 1999-2000 The SquirrelMail Development Team
-     * Licensed under the GNU GPL. For full terms see the file COPYING.
-     *
-     * $Id$
-     */
+     ** validate.php
+     **
+     ** Copyright (c) 1999-2001 The SquirrelMail Development Team
+     ** Licensed under the GNU GPL. For full terms see the file COPYING.
+     **
+     ** $Id$
+     **/
 
     if (defined ('validate_php')) { return; }
     define ('validate_php', true);

+ 3 - 0
src/vcard.php

@@ -2,6 +2,9 @@
 /**
  ** vcard.php
  **
+ ** Copyright (c) 1999-2001 The SquirrelMail Development Team
+ ** Licensed under the GNU GPL. For full terms see the file COPYING.
+ **
  ** This file shows an attched vcard
  **
  ** $Id$