Browse Source

Some user interface changes.
General cleanup of code all over the place.
Addition of a file to hold constants.
Addition of code to do Javascript autodetection, settings, etc.

thomppj 24 năm trước cách đây
mục cha
commit
a634ff1f28
13 tập tin đã thay đổi với 919 bổ sung877 xóa
  1. 7 8
      functions/array.php
  2. 21 0
      functions/constants.php
  3. 226 182
      functions/mailbox_display.php
  4. 4 2
      functions/options.php
  5. 220 168
      functions/strings.php
  6. 22 15
      src/left_main.php
  7. 8 3
      src/load_prefs.php
  8. 138 133
      src/login.php
  9. 17 117
      src/options.php
  10. 11 1
      src/options_display.php
  11. 121 100
      src/redirect.php
  12. 114 100
      src/right_main.php
  13. 10 48
      src/validate.php

+ 7 - 8
functions/array.php

@@ -1,13 +1,12 @@
 <?php
    /**
-    **  array.php
-    **
-    **  This contains functions that work with array manipulation.  They
-    **  will help sort, and do other types of things with arrays
-    **
-    **  $Id$
-    **/
-
+    * array.php
+    *
+    * This contains functions that work with array manipulation.  They
+    * will help sort, and do other types of things with arrays
+    *
+    *  $Id$
+    */
 
    if (defined ('array_php'))
        return; 

+ 21 - 0
functions/constants.php

@@ -0,0 +1,21 @@
+<?php
+    /**
+     * constants.php
+     *
+     * Copyright (c) 1999-2001 The SquirrelMail Development Team
+     * Licensed under the GNU GPL. For full terms see the file COPYING.
+     *
+     * Loads constants used by the rest of the Squirrelmail source.
+     * This file is include by src/login.php, src/redirect.php and
+     * src/load_prefs.php.
+     *
+     * $Id$
+     */
+
+    /* Define constants for javascript settings. */
+    define('SMPREF_JS_ON', 1);
+    define('SMPREF_JS_OFF', 2);
+    define('SMPREF_JS_AUTODETECT', 3);
+
+    do_hook("loading_constants");
+?>

+ 226 - 182
functions/mailbox_display.php

@@ -1,13 +1,15 @@
 <?php
-
    /**
-    **  mailbox_display.php
-    **
-    **  This contains functions that display mailbox information, such as the
-    **  table row that has sender, date, subject, etc...
-    **
-    **  $Id$
-    **/
+    * mailbox_display.php
+    *
+    * Copyright (c) 1999-2001 The Squirrelmail Development Team
+    * Licensed under the GNU GPL. For full terms see the file COPYING.
+    *
+    * This contains functions that display mailbox information, such as the
+    * table row that has sender, date, subject, etc...
+    *
+    * $Id$
+    */
 
    if (defined('mailbox_display_php'))
        return;
@@ -15,7 +17,7 @@
 
    define('PG_SEL_MAX', 10);  /* Default value for page_selector_max. */
 
-   function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
+   function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
       global $checkall;
       global $color, $msgs, $msort;
       global $sent_folder, $draft_folder;
@@ -116,7 +118,7 @@
             case 4: /* subject */
                echo "   <td bgcolor=$hlt_color>$bold";
                    if (! isset($search_stuff)) { $search_stuff = ''; }
-               echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
+               echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
                do_hook("subject_link");
 
                if ($subject != $msg['SUBJECT']) {
@@ -169,7 +171,7 @@
     * and shows them to the user.
     */
    function showMessagesForMailbox
-        ($imapConnection, $mailbox, $numMessages, $startMessage,
+        ($imapConnection, $mailbox, $num_msgs, $start_msg,
          $sort, $color,$show_num, $use_cache) {
       global $msgs, $msort;
       global $sent_folder, $draft_folder;
@@ -185,26 +187,26 @@
       $issent = (($mailbox == $sent_folder) || ($mailbox == $draft_folder));
       if (!$use_cache) {
          /* If it is sorted... */
-         if ($numMessages >= 1) {
+         if ($num_msgs >= 1) {
             if ($sort < 6) {
-               $id = range(1, $numMessages);
+               $id = range(1, $num_msgs);
             } else {
                // if it's not sorted
-               if ($startMessage + ($show_num - 1) < $numMessages) {
-                  $endMessage = $startMessage + ($show_num-1);
+               if ($start_msg + ($show_num - 1) < $num_msgs) {
+                  $end_msg = $start_msg + ($show_num-1);
                } else {
-                  $endMessage = $numMessages;
+                  $end_msg = $num_msgs;
                }
 
-               if ($endMessage < $startMessage) {
-                  $startMessage = $startMessage - $show_num;
-                  if ($startMessage < 1) {
-                      $startMessage = 1;
+               if ($end_msg < $start_msg) {
+                  $start_msg = $start_msg - $show_num;
+                  if ($start_msg < 1) {
+                      $start_msg = 1;
                   }
                }
 
-               $real_startMessage = $numMessages - $startMessage + 1;
-               $real_endMessage = $numMessages - $startMessage - $show_num + 2;
+               $real_startMessage = $num_msgs - $start_msg + 1;
+               $real_endMessage = $num_msgs - $start_msg - $show_num + 2;
                if ($real_endMessage <= 0) {
                    $real_endMessage = 1;
                }
@@ -227,16 +229,16 @@
 
          $j = 0;
          if ($sort == 6) {
-             $end = $startMessage + $show_num - 1;
-             if ($numMessages < $show_num) {
-                 $end_loop = $numMessages;
-             } else if ($end > $numMessages) {
-                 $end_loop = $numMessages - $startMessage + 1;
+             $end = $start_msg + $show_num - 1;
+             if ($num_msgs < $show_num) {
+                 $end_loop = $num_msgs;
+             } else if ($end > $num_msgs) {
+                 $end_loop = $num_msgs - $start_msg + 1;
              } else {
                  $end_loop = $show_num;
              }
          } else {
-            $end = $numMessages;
+            $end = $num_msgs;
             $end_loop = $end;
          }
 
@@ -294,7 +296,7 @@
             $i = 0;
             $j = 0;
 
-            while ($j < $numMessages) {
+            while ($j < $num_msgs) {
                if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
                   $j++;
                   continue;
@@ -304,7 +306,7 @@
                $i++;
                $j++;
             }
-            $numMessages = $i;
+            $num_msgs = $i;
          } else {
              if (!isset($messages)) {
                  $messages = array();
@@ -314,7 +316,7 @@
       }
 
       // There's gotta be messages in the array for it to sort them.
-      if ($numMessages > 0 && ! $use_cache) {
+      if ($num_msgs > 0 && ! $use_cache) {
          /** 0 = Date (up)      4 = Subject (up)
           ** 1 = Date (dn)      5 = Subject (dn)
           ** 2 = Name (up)
@@ -339,14 +341,14 @@
          }
          session_register('msort');
       }
-      displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
+      displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
       session_register('msgs');
    }
 
    /******************************************************************/
    /* Generic function to convert the msgs array into an HTML table. */
    /******************************************************************/
-   function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
+   function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
       global $folder_prefix, $sent_folder;
       global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
       global $index_order, $real_endMessage, $real_startMessage, $checkall;
@@ -355,146 +357,93 @@
       if (!session_is_registered('msgs')) { session_register('msgs'); }
       if (!session_is_registered('msort')) { session_register('msort'); }
 
-      if ($startMessage + ($show_num - 1) < $numMessages) {
-         $endMessage = $startMessage + ($show_num-1);
+      if ($start_msg + ($show_num - 1) < $num_msgs) {
+         $end_msg = $start_msg + ($show_num-1);
       } else {
-         $endMessage = $numMessages;
+         $end_msg = $num_msgs;
       }
 
-      if ($endMessage < $startMessage) {
-         $startMessage = $startMessage - $show_num;
-         if ($startMessage < 1) { $startMessage = 1; }
+      if ($end_msg < $start_msg) {
+         $start_msg = $start_msg - $show_num;
+         if ($start_msg < 1) { $start_msg = 1; }
       }
 
-      $nextGroup = $startMessage + $show_num;
-      $prevGroup = $startMessage - $show_num;
       $urlMailbox = urlencode($mailbox);
 
       do_hook('mailbox_index_before');
 
-      $Message = '';
-      if ($startMessage < $endMessage) {
-         $Message = sprintf( _("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $startMessage, $endMessage, $numMessages );
-      } elseif ($startMessage == $endMessage) {
-         $Message = _("Viewing Message: <b>1</b> (1 total)");
-      } else {
-         $Message = '<br>';
-      }
+      $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
+      $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num);
 
-      if ($sort == 6) {
-         $use = 0;
-      } else {
-         $use = 1;
-      }
-      $lMore = '';
-      $rMore = '';
-      if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
-         $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
-         $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
-      } else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
-         $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
-         $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
-      } else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
-         $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
-         $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
-      }
-      if ($lMore <> '') {
-          $lMore .= ' | ';
-      }
-
-      /* Page selector block. Following code computes page links. */
-      $mMore = '';
-      if (!getPref($data_dir, $username, 'page_selector')
-             && ($numMessages > $show_num)) {
-         $j = intval( $numMessages / $show_num );  // Max pages
-         $k = max( 1, $j / getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX ) );
-         if ($numMessages % $show_num <> 0 ) {
-             $j++;
-         }
-         $startMessage = min( $startMessage, $numMessages );
-         $p = intval( $startMessage / $show_num ) + 1;
-         $i = 1;
-         while( $i < $p ) {
-            $pg = intval( $i );
-            $start = ( ($pg-1) * $show_num ) + 1;
-            $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
-                    "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
-            $i += $k;
-         }
-         $mMore .= "<b>$p</b> ";
-         $i += $k;
-         while( $i <= $j ) {
-            $pg = intval( $i );
-            $start = ( ($pg-1) * $show_num ) + 1;
-            $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
-                    "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
-            $i+=$k;
-         }
-         $mMore .= ' | ';
+      if (! isset($msg)) {
+          $msg = '';
       }
 
-      if (! isset($msg))
-          $msg = '';
-      mail_message_listing_beginning($imapConnection,
-         "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
-          $mailbox, $sort, $Message, $lMore . $mMore . $rMore, $startMessage);
+      mail_message_listing_beginning
+         ($imapConnection,
+         "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
+          $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
 
-      $groupNum = $startMessage % ($show_num - 1);
-      $real_startMessage = $startMessage;
+      $groupNum = $start_msg % ($show_num - 1);
+      $real_startMessage = $start_msg;
       if ($sort == 6) {
-         if ($endMessage - $startMessage < $show_num - 1) {
-            $endMessage = $endMessage - $startMessage + 1;
-            $startMessage = 1;
-         } else if ($startMessage > $show_num) {
-            $endMessage = $show_num;
-            $startMessage = 1;
+         if ($end_msg - $start_msg < $show_num - 1) {
+            $end_msg = $end_msg - $start_msg + 1;
+            $start_msg = 1;
+         } else if ($start_msg > $show_num) {
+            $end_msg = $show_num;
+            $start_msg = 1;
          }
       }
-      $endVar = $endMessage + 1;
+      $endVar = $end_msg + 1;
 
-      // loop through and display the info for each message.
+      /* Loop through and display the info for each message. */
       $t = 0; // $t is used for the checkbox number
-      if ($numMessages == 0) { // if there's no messages in this folder
-         echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
-         echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
-      } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
-         if ($sort != 6)
-            $i = $startMessage;
-         else
-            $i = 1;
-         reset($msort);
-         $k = 0;
-         do {
-            $key = key($msort);
-            next($msort);
-            $k++;
-         } while (isset ($key) && ($k < $i));
-         printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
+      if ($num_msgs == 0) { // if there's no messages in this folder
+          echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n";
+          echo "  <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER>\n";
+          echo "</TD></TR>";
+      } else if ($start_msg == $end_msg) {
+          /* If there's only one message in the box, handle it differently. */
+          if ($sort != 6) {
+              $i = $start_msg;
+          } else {
+              $i = 1;
+          }
+
+          reset($msort);
+          $k = 0;
+          do {
+              $key = key($msort);
+              next($msort);
+              $k++;
+          } while (isset ($key) && ($k < $i));
+          printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
       } else {
-         $i = $startMessage;
-
-         reset($msort);
-         $k = 0;
-         do {
-            $key = key($msort);
-            next($msort);
-            $k++;
-         } while (isset ($key) && ($k < $i));
-
-         do {
-            printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
-            $key = key($msort);
-            $t++;
-            $i++;
-            next($msort);
-         } while ($i && $i < $endVar);
+          $i = $start_msg;
+
+          reset($msort);
+          $k = 0;
+          do {
+              $key = key($msort);
+              next($msort);
+              $k++;
+          } while (isset ($key) && ($k < $i));
+
+          do {
+              printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
+              $key = key($msort);
+              $t++;
+              $i++;
+              next($msort);
+          } while ($i && $i < $endVar);
       }
 
       echo '</table>';
       echo "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" .
               "<tr BGCOLOR=\"$color[4]\">" .
-                 "<table width=100% BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$lMore$mMore$rMore</td>".
-                 "<td align=right>$Message</td></tr></table>".
+                 "<table width=100% BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>".
+                 "<td align=right>$msg_cnt_str</td></tr></table>".
               "</tr>".
            "</table>";
       /** End of message-list table */
@@ -503,8 +452,10 @@
       echo "</TABLE></FORM>\n";
    }
 
-   /* Displays the standard message list header.
-    * To finish the table, you need to do a "</table></table>";
+   /**
+    * Displays the standard message list header. To finish the table,
+    * you need to do a "</table></table>";
+    *
     * $moveURL is the URL to submit the delete/move form to
     * $mailbox is the current mailbox
     * $sort is the current sorting method (-1 for no sorting available [searches])
@@ -513,25 +464,27 @@
     */
    function mail_message_listing_beginning
         ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
-         $Message = '', $More = '', $startMessage = 1) {
+         $msg_cnt_str = '', $paginator = '', $start_msg = 1) {
       global $color, $index_order, $auto_expunge, $move_to_trash;
       global $checkall, $sent_folder, $draft_folder;
       $urlMailbox = urlencode($mailbox);
 
-      /** This is the beginning of the message list table.  It wraps around all messages */
-      echo "<center>$Message</center>" .
-           '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="1" CELLSPACING="0">';
+      /****************************************************
+       * This is the beginning of the message list table. *
+       * It wraps around all messages                     *
+       ****************************************************/
+      echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n";
 
-      echo "<TR BGCOLOR=\"$color[9]\"><TD>";
-
-      echo  "<table bgcolor=\"$color[4]\" cellpadding=2".
-           ' width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>' .
-           "$More</td><td align=right>";
-      ShowSelectAllLink($startMessage, $sort);
-      echo "</td></tr></table>\n</td></tr>";
+      echo "<TR BGCOLOR=\"$color[0]\"><TD>";
+      echo "  <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n";
+      echo "    <TD ALIGN=LEFT>$paginator</TD>\n";
+      echo '    <TD ALIGN=CENTER>' . get_selectall_link($start_msg, $sort) . "</TD>\n";
+      echo "    <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n";
+      echo "  </TR></TABLE>\n";
+      echo "</TD></TR>";
 
       /** The delete and move options */
-      echo "<TD BGCOLOR=\"$color[0]\">";
+      echo "<TR><TD BGCOLOR=\"$color[0]\">";
 
       echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n";
       echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
@@ -645,10 +598,11 @@
            '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
    }
 
-   function ShowSelectAllLink($startMessage, $sort) {
+   function get_selectall_link($start_msg, $sort) {
        global $checkall, $PHP_SELF, $what, $where, $mailbox;
 
-       echo '&nbsp;<script language="JavaScript">' .
+       $result =
+            '&nbsp;<script language="JavaScript">' .
             "\n<!-- \n" .
             "function CheckAll() {\n" .
             "   for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
@@ -661,25 +615,115 @@
             "//-->\n" .
             "</script>\n<noscript>\n";
 
-       echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
-          "&startMessage=$startMessage&sort=$sort&checkall=";
-       if (isset($checkall) && $checkall == '1')
-           echo '0';
-       else
-           echo '1';
-       if (isset($where) && isset($what))
-           echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
-       echo "\">";
-       if (isset($checkall) && $checkall == '1')
-           echo _("Unselect All");
-       else
-           echo _("Select All");
-
-       echo "</A>\n</noscript>\n";
+       $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
+          .  "&startMessage=$start_msg&sort=$sort&checkall=";
+       if (isset($checkall) && $checkall == '1') {
+           $result .= '0';
+       } else {
+           $result .= '1';
+       }
+
+       if (isset($where) && isset($what)) {
+           $result .= '&where=' . urlencode($where) . '&what=' . urlencode($what);
+       }
+
+       $result .= "\">";
+
+       if (isset($checkall) && ($checkall == '1')) {
+           $result .= _("Unselect All");
+       } else {
+           $result .= _("Select All");
+       }
+
+       $result .= "</A>\n</noscript>\n";
+
+       /* Return our final result. */
+       return ($result);
    }
 
-   function processSubject($subject)
-   {
+    /**
+     * This function computes the "Viewing Messages..." string.
+     */
+    function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
+        /* Compute the $msg_cnt_str. */
+        $result = '';
+        if ($start_msg < $end_msg) {
+            $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
+        } else if ($start_msg == $end_msg) {
+            $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
+        } else {
+            $result = '<br>';
+        }
+
+        /* Return our result string. */
+        return ($result);
+    }
+
+    /**
+     * This function computes the paginator string.
+     */
+    function get_paginator_str
+    ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num) {
+        $nextGroup = $start_msg + $show_num;
+        $prevGroup = $start_msg - $show_num;
+
+        if ($sort == 6) {
+            $use = 0;
+        } else {
+            $use = 1;
+        }
+        $lMore = '';
+        $rMore = '';
+        if (($nextGroup <= $num_msgs) && ($prevGroup >= 0)) {
+            $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
+            $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
+        } else if (($nextGroup > $num_msgs) && ($prevGroup >= 0)) {
+            $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
+            $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
+        } else if (($nextGroup <= $num_msgs) && ($prevGroup < 0)) {
+            $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
+            $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
+        }
+        if ($lMore <> '') {
+            $lMore .= ' | ';
+        }
+
+        /* Page selector block. Following code computes page links. */
+        $mMore = '';
+        if (!getPref($data_dir, $username, 'page_selector')
+               && ($num_msgs > $show_num)) {
+            $j = intval( $num_msgs / $show_num );  // Max pages
+            $k = max( 1, $j / getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX ) );
+            if ($num_msgs % $show_num <> 0 ) {
+                $j++;
+            }
+            $start_msgs = min( $start_msgs, $num_msgs );
+            $p = intval( $start_msgs / $show_num ) + 1;
+            $i = 1;
+            while( $i < $p ) {
+                $pg = intval( $i );
+                $start = ( ($pg-1) * $show_num ) + 1;
+                $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
+                          "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
+                $i += $k;
+            }
+            $mMore .= "<b>$p</b> ";
+            $i += $k;
+            while( $i <= $j ) {
+               $pg = intval( $i );
+               $start = ( ($pg-1) * $show_num ) + 1;
+               $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start"
+                       . "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
+               $i+=$k;
+            }
+            $mMore .= ' | ';
+        }
+
+        /* Return the resulting string. */
+        return ($lMore . $mMore . $rMore);
+    }
+
+   function processSubject($subject) {
       // Shouldn't ever happen -- caught too many times in the IMAP functions
       if ($subject == '')
           return _("(no subject)");

+ 4 - 2
functions/options.php

@@ -64,11 +64,13 @@
     }
 
     function OptionText( $title, $name, $value, $size ) {
-
         echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
              "<input name=\"$name\" value=\"$value\" size=\"$size\">" .
              "</td></tr>\n";
+    }
 
+    function OptionHidden( $name, $value ) {
+        echo "<INPUT TYPE=HIDDEN NAME=\"$name\" VALUE=\"$value\">\n";
     }
 
     function OptionCheck( $title, $name, $value, $comment ) {
@@ -94,4 +96,4 @@
 
     }
 
-?>
+?>

+ 220 - 168
functions/strings.php

@@ -1,25 +1,37 @@
 <?php
+   /**
+    * strings.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$
+    */
 
-   /* $Id$ */
-
-   if (defined('strings_php'))
-       return;
-   define('strings_php', true);
+    if (defined('strings_php')) { return; }
+    define('strings_php', true);
 
+   /**
+    * SquirrelMail version number -- DO NOT CHANGE
+    */
+   global $version;
+   $version = '1.2.0 [cvs]';
 
-   //*************************************************************************
-   // Count the number of occurances of $needle are in $haystack.
-   // $needle can be a character or string, and need not occur in $haystack
-   //*************************************************************************
+   /**
+    * Count the number of occurances of $needle are in $haystack.
+    * $needle can be a character or string, and need not occur in $haystack
+    */
    function countCharInString($haystack, $needle) {
       if ($needle == '') return 0;
       return count(explode($needle, $haystack));
    }
 
-   //*************************************************************************
-   // Read from the back of $haystack until $needle is found, or the begining
-   //    of the $haystack is reached.  $needle is a single character
-   //*************************************************************************
+   /**
+    * Read from the back of $haystack until $needle is found, or the begining
+    * of the $haystack is reached. $needle is a single character
+    */
    function readShortMailboxName($haystack, $needle) {
       if ($needle == '') return $haystack;
       $parts = explode($needle, $haystack);
@@ -31,10 +43,10 @@
       return $elem;
    }
 
-   //*************************************************************************
-   // Read from the back of $haystack until $needle is found, or the begining
-   //    of the $haystack is reached.  $needle is a single character
-   //*************************************************************************
+   /**
+    * Read from the back of $haystack until $needle is found, or the begining
+    * of the $haystack is reached. $needle is a single character
+    */
    function readMailboxParent($haystack, $needle) {
       if ($needle == '') return '';
       $parts = explode($needle, $haystack);
@@ -46,7 +58,9 @@
       return join($needle, $parts);
    }
 
-   // Searches for the next position in a string minus white space
+   /**
+    * Searches for the next position in a string minus white space.
+    */
    function next_pos_minus_white ($haystack, $pos) {
       while (substr($haystack, $pos, 1) == ' ' ||
              substr($haystack, $pos, 1) == "\t" ||
@@ -59,11 +73,15 @@
       return $pos;
    }
 
-   // Wraps text at $wrap characters
-   // Has a problem with special HTML characters, so call this before
-   // you do character translation.
-   // Specifically, &#039 comes up as 5 characters instead of 1.
-   // This should not add newlines to the end of lines.
+   /**
+    * Wraps text at $wrap characters
+    *
+    * Has a problem with special HTML characters, so call this before
+    * you do character translation.
+    *
+    * Specifically, &#039 comes up as 5 characters instead of 1.
+    * This should not add newlines to the end of lines.
+    */
    function sqWordWrap(&$line, $wrap) {
       ereg("^([\t >]*)([^\t >].*)?$", $line, $regs);
       $beginning_spaces = $regs[1];
@@ -107,31 +125,28 @@
    }
 
 
-   // Does the opposite of sqWordWrap()
-   function sqUnWordWrap(&$body)
-   {
+   /**
+    * Does the opposite of sqWordWrap()
+    */
+   function sqUnWordWrap(&$body) {
        $lines = explode("\n", $body);
        $body = "";
        $PreviousSpaces = "";
-       for ($i = 0; $i < count($lines); $i ++)
-       {
+       for ($i = 0; $i < count($lines); $i ++) {
            ereg("^([\t >]*)([^\t >].*)?$", $lines[$i], $regs);
            $CurrentSpaces = $regs[1];
-            if (isset($regs[2]))
+           if (isset($regs[2])) {
                $CurrentRest = $regs[2];
-           if ($i == 0)
-           {
+           }
+
+           if ($i == 0) {
                $PreviousSpaces = $CurrentSpaces;
                $body = $lines[$i];
-           }
-           else if ($PreviousSpaces == $CurrentSpaces &&  // Do the beginnings match
-               strlen($lines[$i - 1]) > 65 &&             // Over 65 characters long
-               strlen($CurrentRest))                      // and there's a line to continue with
-           {
+           } else if (($PreviousSpaces == $CurrentSpaces)   // Do the beginnings match
+                        && (strlen($lines[$i - 1]) > 65)    // Over 65 characters long
+                        && strlen($CurrentRest)) {          // and there's a line to continue with
                $body .= ' ' . $CurrentRest;
-           }
-           else
-           {
+           } else {
                $body .= "\n" . $lines[$i];
                $PreviousSpaces = $CurrentSpaces;
            }
@@ -140,8 +155,10 @@
    }
 
 
-   /** Returns an array of email addresses **/
-   /* Be cautious of "user@host.com" */
+   /**
+    * Returns an array of email addresses.
+    * Be cautious of "user@host.com"
+    */
    function parseAddrs($text) {
       if (trim($text) == "")
          return array();
@@ -157,7 +174,9 @@
       return $array;
    }
 
-   /** Returns a line of comma separated email addresses from an array **/
+   /**
+    * Returns a line of comma separated email addresses from an array.
+    */
    function getLineOfAddrs($array) {
       if (is_array($array)) {
         $to_line = implode(', ', $array);
@@ -192,30 +211,26 @@
 
          $Quotes = 0;
          $pos = 0;
-         while (1)
-         {
-             if ($line[$pos] == ' ')
-             {
+         while (1) {
+             if ($line[$pos] == ' ') {
                 $pos ++;
-             }
-             else if (strpos($line, '&gt;', $pos) === $pos)
-             {
+             } else if (strpos($line, '&gt;', $pos) === $pos) {
                 $pos += 4;
                 $Quotes ++;
-             }
-             else
-             {
+             } else {
                  break;
              }
          }
 
          if ($Quotes > 1) {
-	    if (! isset($color[14]))
+	    if (! isset($color[14])) {
 	       $color[14] = '#FF0000';
+            }
             $line = '<FONT COLOR="' . $color[14] . '">' . $line . '</FONT>';
 	 } elseif ($Quotes) {
-	    if (! isset($color[13]))
+	    if (! isset($color[13])) {
 	       $color[13] = '#800000';
+            }
             $line = '<FONT COLOR="' . $color[13] . '">' . $line . '</FONT>';
 	 }
 
@@ -224,11 +239,6 @@
       $body = '<pre>' . implode("\n", $body_ary) . '</pre>';
    }
 
-   /* SquirrelMail version number -- DO NOT CHANGE */
-   global $version;
-   $version = '1.2.0 [cvs]';
-
-
    function find_mailbox_name ($mailbox) {
       if (ereg(" *\"([^\r\n\"]*)\"[ \r\n]*$", $mailbox, $regs))
           return $regs[1];
@@ -237,27 +247,31 @@
 
    }
 
+   /**
+    * This determines the location to forward to relative to your server.
+    * If this doesnt work correctly for you (although it should), you can
+    * remove all this code except the last two lines, and change the header()
+    * function to look something like this, customized to the location of
+    * SquirrelMail on your server:
+    *
+    *   http://www.myhost.com/squirrelmail/src/login.php
+    */
    function get_location () {
-      # This determines the location to forward to relative
-      # to your server.  If this doesnt work correctly for
-      # you (although it should), you can remove all this
-      # code except the last two lines, and change the header()
-      # function to look something like this, customized to
-      # the location of SquirrelMail on your server:
-      #
-      #   http://www.myhost.com/squirrelmail/src/login.php
 
       global $PHP_SELF, $SERVER_NAME, $HTTP_HOST, $SERVER_PORT,
          $HTTP_SERVER_VARS;
 
-      // Get the path
+      /* Get the path. */
       $path = substr($PHP_SELF, 0, strrpos($PHP_SELF, '/'));
 
-      // Check if this is a HTTPS or regular HTTP request
+      /* Check if this is a HTTPS or regular HTTP request. */
       $proto = 'http://';
-      // If you have 'SSLOptions +StdEnvVars' in your apache config
-      // OR if you have HTTPS in your HTTP_SERVER_VARS
-      // OR if you are on port 443
+
+      /*
+       * If you have 'SSLOptions +StdEnvVars' in your apache config
+       *     OR if you have HTTPS in your HTTP_SERVER_VARS
+       *     OR if you are on port 443
+       */
       $getEnvVar = getenv('HTTPS');
       if ((isset($getEnvVar) && !strcasecmp($getEnvVar, 'on')) ||
           (isset($HTTP_SERVER_VARS['HTTPS'])) ||
@@ -268,18 +282,14 @@
 
       // Get the hostname from the Host header or server config.
       $host = '';
-      if (isset($HTTP_HOST) && !empty($HTTP_HOST))
-      {
+      if (isset($HTTP_HOST) && !empty($HTTP_HOST)) {
           $host = $HTTP_HOST;
-      }
-      else if (isset($SERVER_NAME) && !empty($SERVER_NAME))
-      {
+      } else if (isset($SERVER_NAME) && !empty($SERVER_NAME)) {
           $host = $SERVER_NAME;
       }
 
       $port = '';
-      if (! strstr($host, ':'))
-      {
+      if (! strstr($host, ':')) {
           if (isset($SERVER_PORT)) {
               if (($SERVER_PORT != 80 && $proto == 'http://')
                       || ($SERVER_PORT != 443 && $proto == 'https://')) {
@@ -288,25 +298,24 @@
           }
       }
 
-      if ($host)
-          return $proto . $host . $port . $path;
-
-      // Fallback is to omit the server name and use a relative URI,
-      // although this is not RFC 2616 compliant.
-      return $path;
+      /* Fallback is to omit the server name and use a relative */
+      /* URI, although this is not RFC 2616 compliant.          */
+      return ($host ? $proto . $host . $port . $path : $path);
    }
 
 
-   // These functions are used to encrypt the passowrd before it is
-   // stored in a cookie.
+   /**
+    * These functions are used to encrypt the passowrd before it is
+    * stored in a cookie.
+    */
    function OneTimePadEncrypt ($string, $epad) {
-      $pad = base64_decode($epad);
-      $encrypted = '';
-      for ($i = 0; $i < strlen ($string); $i++) {
-          $encrypted .= chr (ord($string[$i]) ^ ord($pad[$i]));
-      }
+       $pad = base64_decode($epad);
+       $encrypted = '';
+       for ($i = 0; $i < strlen ($string); $i++) {
+           $encrypted .= chr (ord($string[$i]) ^ ord($pad[$i]));
+       }
 
-      return base64_encode($encrypted);
+       return base64_encode($encrypted);
    }
 
    function OneTimePadDecrypt ($string, $epad) {
@@ -321,37 +330,29 @@
    }
 
 
-   // Randomize the mt_rand() function.  Toss this in strings or
-   // integers and it will seed the generator appropriately.
-   // With strings, it is better to get them long. Use md5() to
-   // lengthen smaller strings.
-   function sq_mt_seed($Val)
-   {
+   /**
+    * Randomize the mt_rand() function.  Toss this in strings or integers
+    * and it will seed the generator appropriately. With strings, it is
+    * better to get them long. Use md5() to lengthen smaller strings.
+    */
+   function sq_mt_seed($Val) {
        // if mt_getrandmax() does not return a 2^n - 1 number,
        // this might not work well.  This uses $Max as a bitmask.
        $Max = mt_getrandmax();
 
-       if (! is_int($Val))
-       {
-           if (function_exists('crc32'))
-           {
+       if (! is_int($Val)) {
+           if (function_exists('crc32')) {
                $Val = crc32($Val);
-           }
-           else
-           {
+           } else {
                $Str = $Val;
                $Pos = 0;
                $Val = 0;
                $Mask = $Max / 2;
                $HighBit = $Max ^ $Mask;
-               while ($Pos < strlen($Str))
-               {
-                   if ($Val & $HighBit)
-                   {
+               while ($Pos < strlen($Str)) {
+                   if ($Val & $HighBit) {
                        $Val = (($Val & $Mask) << 1) + 1;
-                   }
-                   else
-                   {
+                   } else {
                        $Val = ($Val & $Mask) << 1;
                    }
                    $Val ^= $Str[$Pos];
@@ -360,36 +361,40 @@
            }
        }
 
-       if ($Val < 0)
-         $Val *= -1;
-       if ($Val = 0)
-         return;
+       if ($Val < 0) {
+           $Val *= -1;
+       }
+
+       if ($Val = 0) {
+           return;
+       }
 
        mt_srand(($Val ^ mt_rand(0, $Max)) & $Max);
    }
 
 
-   // This function initializes the random number generator fairly well.
-   // It also only initializes it once, so you don't accidentally get
-   // the same 'random' numbers twice in one session.
-   function sq_mt_randomize()
-   {
+   /**
+    * This function initializes the random number generator fairly well.
+    * It also only initializes it once, so you don't accidentally get
+    * the same 'random' numbers twice in one session.
+    */
+   function sq_mt_randomize() {
       global $REMOTE_PORT, $REMOTE_ADDR, $UNIQUE_ID;
       static $randomized;
 
-      if ($randomized)
-         return;
+      if ($randomized) {
+          return;
+      }
 
-      // Global
+      /* Global. */
       sq_mt_seed((int)((double) microtime() * 1000000));
       sq_mt_seed(md5($REMOTE_PORT . $REMOTE_ADDR . getmypid()));
 
-      // getrusage
+      /* getrusage */
       if (function_exists('getrusage')) {
          // Avoid warnings with Win32
          $dat = @getrusage();
-	 if (isset($dat) && is_array($dat))
-	 {
+	 if (isset($dat) && is_array($dat)) {
             $Str = '';
             foreach ($dat as $k => $v)
             {
@@ -416,75 +421,81 @@
       return base64_encode($pad);
    }
 
-   // Check if we have a required PHP-version. Return TRUE if we do,
-   // or FALSE if we don't.
-   // To check for 4.0.1, use sqCheckPHPVersion(4,0,1)
-   // To check for 4.0b3, use sqCheckPHPVersion(4,0,-3)
-   // Does not handle betas like 4.0.1b1 or development versions
+   /**
+    * Check if we have a required PHP-version. Return TRUE if we do,
+    * or FALSE if we don't.
+    *
+    *     To check for 4.0.1, use sqCheckPHPVersion(4,0,1)
+    *     To check for 4.0b3, use sqCheckPHPVersion(4,0,-3)
+    *
+    * Does not handle betas like 4.0.1b1 or development versions
+    */
    function sqCheckPHPVersion($major, $minor, $release) {
 
       $ver = phpversion();
       eregi('^([0-9]+)\\.([0-9]+)(.*)', $ver, $regs);
 
-      // Parse the version string
+      /* Parse the version string. */
       $vmajor  = strval($regs[1]);
       $vminor  = strval($regs[2]);
       $vrel    = $regs[3];
-      if($vrel[0] == ".")
+      if($vrel[0] == ".") {
           $vrel = strval(substr($vrel, 1));
-      if($vrel[0] == 'b' || $vrel[0] == 'B')
+      }
+      if($vrel[0] == 'b' || $vrel[0] == 'B') {
           $vrel = - strval(substr($vrel, 1));
-      if($vrel[0] == 'r' || $vrel[0] == 'R')
+      }
+      if($vrel[0] == 'r' || $vrel[0] == 'R') {
           $vrel = - strval(substr($vrel, 2))/10;
+      }
 
-      // Compare major version
-      if($vmajor < $major) return false;
-      if($vmajor > $major) return true;
+      /* Compare major version. */
+      if ($vmajor < $major) { return false; }
+      if ($vmajor > $major) { return true; }
 
-      // Major is the same. Compare minor
-      if($vminor < $minor) return false;
-      if($vminor > $minor) return true;
+      /* Major is the same. Compare minor. */
+      if ($vminor < $minor) { return false; }
+      if ($vminor > $minor) { return true; }
 
-      // Major and minor is the same as the required one.
-      // Compare release
-      if($vrel >= 0 && $release >= 0) {       // Neither are beta
+      /* Major and minor is the same as the required one. Compare release */
+      if ($vrel >= 0 && $release >= 0) {       // Neither are beta
           if($vrel < $release) return false;
-      } else if($vrel >= 0 && $release < 0){  // This is not beta, required is beta
+      } else if($vrel >= 0 && $release < 0) {  // This is not beta, required is beta
           return true;
-      } else if($vrel < 0 && $release >= 0){  // This is beta, require not beta
+      } else if($vrel < 0 && $release >= 0){   // This is beta, require not beta
           return false;
-      } else {                                // Both are beta
+      } else {                                 // Both are beta
           if($vrel > $release) return false;
       }
 
       return true;
    }
 
-   /* Returns a string showing the size of the message/attachment */
-   function show_readable_size($bytes)
-   {
+   /**
+    *  Returns a string showing the size of the message/attachment.
+    */
+   function show_readable_size($bytes) {
        $bytes /= 1024;
        $type = 'k';
 
-       if ($bytes / 1024 > 1)
-       {
+       if ($bytes / 1024 > 1) {
            $bytes /= 1024;
            $type = 'm';
        }
 
-       if ($bytes < 10)
-       {
+       if ($bytes < 10) {
            $bytes *= 10;
            settype($bytes, 'integer');
            $bytes /= 10;
-       }
-       else
+       } else {
            settype($bytes, 'integer');
+       }
 
        return $bytes . '<small>&nbsp;' . $type . '</small>';
    }
 
-   /* Generates a random string from the caracter set you pass in
+   /**
+    * Generates a random string from the caracter set you pass in
     *
     * Flags:
     *   1 = add lowercase a-z to $chars
@@ -492,17 +503,20 @@
     *   4 = add numbers 0-9 to $chars
     */
 
-   function GenerateRandomString($size, $chars, $flags = 0)
-   {
-      if ($flags & 0x1)
+   function GenerateRandomString($size, $chars, $flags = 0) {
+      if ($flags & 0x1) {
           $chars .= 'abcdefghijklmnopqrstuvwxyz';
-      if ($flags & 0x2)
+      }
+      if ($flags & 0x2) {
           $chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
-      if ($flags & 0x4)
+      }
+      if ($flags & 0x4) {
           $chars .= '0123456789';
+      }
 
-      if ($size < 1 || strlen($chars) < 1)
+      if (($size < 1) || (strlen($chars) < 1)) {
           return '';
+      }
 
       sq_mt_randomize(); // Initialize the random number generator
 
@@ -514,9 +528,47 @@
       return $String;
    }
 
-   function quoteIMAP($str)
-   {
+   function quoteIMAP($str) {
        return ereg_replace('(["\\])', '\\\\1', $str);
    }
 
-?>
+    /**
+     * Trims every element in the array
+     */
+    function TrimArray(&$array) {
+        foreach ($array as $k => $v) {
+            global $$k;
+            if (is_array($$k)) {
+                foreach ($$k as $k2 => $v2) {
+	           $$k[$k2] = substr($v2, 1);
+                }
+            } else {
+                $$k = substr($v, 1);
+            }
+
+	    /* Re-assign back to array. */
+            $array[$k] = $$k;
+        }
+    }   
+   
+    /**
+     * Removes slashes from every element in the array
+     */
+    function RemoveSlashes(&$array) {
+        foreach ($array as $k => $v) {
+            global $$k;
+            if (is_array($$k)) {
+                foreach ($$k as $k2 => $v2) {
+                    $newArray[stripslashes($k2)] = stripslashes($v2);
+                }
+                $$k = $newArray;
+            } else {
+                $$k = stripslashes($v);
+            }
+
+	    /* Re-assign back to the array. */
+            $array[$k] = $$k;
+        }
+    }
+
+?>

+ 22 - 15
src/left_main.php

@@ -1,14 +1,14 @@
 <?php
    /**
-    **  left_main.php
-    **  Copyright (c) 1999-2000 The SquirrelMail development team
-    **  Licensed under the GNU GPL. For full terms see the file COPYING.
-    **
-    **  This is the code for the left bar.  The left bar shows the folders
-    **  available, and has cookie information.
-    **
-    **  $Id$
-    **/
+    * left_main.php
+    * Copyright (c) 1999-2001 The Squirrelmail Development Team
+    * Licensed under the GNU GPL. For full terms see the file COPYING.
+    *
+    * This is the code for the left bar.  The left bar shows the folders
+    * available, and has cookie information.
+    *
+    * $Id$
+    */
 
     require_once('../src/validate.php');
     require_once('../functions/array.php');
@@ -158,16 +158,19 @@
     echo '<CENTER><FONT SIZE=4><B>';
     echo _("Folders") . "</B><BR></FONT>\n\n";
 
+    /* First, display the clock. */
     if ($hour_format == 1) {
-      if ($date_format == 4)
+      if ($date_format == 4) {
          $hr = "G:i:s";
-      else
+      } else {
          $hr = "G:i";
+      }
     } else {  
-      if ($date_format == 4)
+      if ($date_format == 4) {
          $hr = "g:i:s a";
-      else   
+      } else {
          $hr = "g:i a";
+      }
     }
     
     switch( $date_format ) {
@@ -184,14 +187,18 @@
     default:   
       $clk = date("D, ".$hr, time());
     }
+    $clk = str_replace(' ','&nbsp;',$clk);
+
+    echo '<CENTER><SMALL>' . str_replace(' ','&nbsp;',_("Last Refresh"))
+         .  ": $clk</SMALL></CENTER>";
 
-    echo '<center><small>' . _("Last Refresh") . ":<br>$clk";
-    echo '</small></center>';
+    /* Next, display the refresh button. */
     echo '<SMALL>(<A HREF="../src/left_main.php" TARGET="left">';
     echo _("refresh folder list");
     echo '</A>)</SMALL></CENTER><BR>';
     $delimeter = sqimap_get_delimiter($imapConnection);
 
+    /* Lastly, display the folder list. */
     if (isset($collapse_folders) && $collapse_folders) {
         /* If directed, collapse or uncollapse a folder. */
         if (isset($fold)) {

+ 8 - 3
src/load_prefs.php

@@ -14,7 +14,7 @@
     require_once('../src/validate.php');
 
     /**************************************************************/
-    /* Following code should be removed in the next foo_once step
+    /* Following code should be removed in the next foo_once step */
     if (defined('load_prefs_php')) { return; }
     define('load_prefs_php', true);
     /**************************************************************/
@@ -24,6 +24,7 @@
     if (! isset($color)) { $color = array(); }
     require_once('../functions/prefs.php');
     require_once('../functions/plugin.php');
+    require_once('../functions/constants.php');
       
     if (!isset($username)) { $username = ''; }
     checkForPrefs($data_dir, $username);
@@ -193,11 +194,15 @@
     /* show_html_default is a int value. */
     $show_html_default = intval(getPref($data_dir, $username, 'show_html_default', 1 ) );
 
-    /* SqClock into the core */
+    /* SqClock now in the core */
     global $date_format, $hour_format, $username, $data_dir;
-    
     $date_format = getPref($data_dir, $username, 'date_format', 3);
     $hour_format = getPref($data_dir, $username, 'hour_format', 2);
 
+    /* Load the javascript settings. */
+    global $javascript_setting, $javascript_on;
+    $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
+    $javascript_on = getPref($data_dir, $username, 'javascript_on', true);
+
     do_hook("loading_prefs");
 ?>

+ 138 - 133
src/login.php

@@ -1,149 +1,154 @@
 <?php
-   /**
-    **  login.php -- simple login screen
-    ** 
-    **  Copyright (c) 1999-2000 The SquirrelMail development team
-    **  Licensed under the GNU GPL. For full terms see the file COPYING.
-    **
-    **  This a simple login screen. Some housekeeping is done to clean
-    **  cookies and find language.
-    **
-    **  $Id$
-    **/
+    /**
+     * login.php -- simple login screen
+     * 
+     * Copyright (c) 1999-2001 The Squirrelmail Development Team
+     * Licensed under the GNU GPL. For full terms see the file COPYING.
+     *
+     * This a simple login screen. Some housekeeping is done to clean
+     * cookies and find language.
+     *
+     * $Id$
+     */
 
-   $rcptaddress = '';
-   if (isset($emailaddress)) {
-      if (stristr($emailaddress, 'mailto:'))
-         $rcptaddress = substr($emailaddress, 7);
-      else
-         $rcptaddress = $emailaddress;
+    $rcptaddress = '';
+    if (isset($emailaddress)) {
+        if (stristr($emailaddress, 'mailto:')) {
+            $rcptaddress = substr($emailaddress, 7);
+        } else {
+            $rcptaddress = $emailaddress;
+        }
 	 
-      if (($pos = strpos($rcptaddress, '?')) !== false)
-      {
-         $a = substr($rcptaddress, $pos + 1);
-	 $rcptaddress = substr($rcptaddress, 0, $pos);
-	 $a = explode('=', $a, 2);
-	 if (isset($a[1])) {
-	    $name = urldecode($a[0]);
-	    $val = urldecode($a[1]);
-	    global $$name;
-	    $$name = $val;
-	 }
-      }
+        if (($pos = strpos($rcptaddress, '?')) !== false) {
+            $a = substr($rcptaddress, $pos + 1);
+	    $rcptaddress = substr($rcptaddress, 0, $pos);
+            $a = explode('=', $a, 2);
+            if (isset($a[1])) {
+                $name = urldecode($a[0]);
+                $val = urldecode($a[1]);
+                global $$name;
+                $$naame = $val;
+            }
+        }
       
-      // At this point, we have parsed a lot of the mailto stuff.  Let's
-      // do the rest -- CC, BCC, Subject, Body
-      // Note:  They can all be case insensitive
-      foreach ($GLOBALS as $k => $v)
-      {
-          $key = strtolower($k);
-	  $value = urlencode($v);
-	  if ($key == 'cc')
-	     $rcptaddress .= '&send_to_cc=' . $value;
-	  elseif ($key == 'bcc')
-	     $rcptaddress .= '&send_to_bcc=' . $value;
-	  elseif ($key == 'subject')
-	     $rcptaddress .= '&subject=' . $value;
-	  elseif ($key == 'body')
-	     $rcptaddress .= '&body=' . $value;
-      }
+        /* At this point, we have parsed a lot of the mailto stuff. */
+        /*   Let's do the rest -- CC, BCC, Subject, Body            */
+        /*   Note:  They can all be case insensitive                */
+        foreach ($GLOBALS as $k => $v) {
+            $key = strtolower($k);
+            $value = urlencode($v);
+            if ($key == 'cc') {
+                $rcptaddress .= '&send_to_cc=' . $value;
+            } else if ($key == 'bcc') {
+                $rcptaddress .= '&send_to_bcc=' . $value;
+            } else if ($key == 'subject') {
+                $rcptaddress .= '&subject=' . $value;
+            } else if ($key == 'body') {
+                $rcptaddress .= '&body=' . $value;
+            }
+        }
       
-      // Double-encode in this fashion to get past redirect.php properly
-      $rcptaddress = urlencode($rcptaddress);
-   }
+        /* Double-encode in this fashion to get past redirect.php properly. */
+        $rcptaddress = urlencode($rcptaddress);
+    }
 
-   require_once('../functions/strings.php');
-   require_once('../config/config.php');
-   require_once('../functions/i18n.php');
-   require_once('../functions/plugin.php');
+    require_once('../functions/strings.php');
+    require_once('../config/config.php');
+    require_once('../functions/i18n.php');
+    require_once('../functions/plugin.php');
+    require_once('../functions/constants.php');
 
-   // $squirrelmail_language is set by a cookie when the user selects
-   // language and logs out
-   set_up_language($squirrelmail_language, true);
+    /*
+     * $squirrelmail_language is set by a cookie when the user selects
+     * language and logs out
+     */
+    set_up_language($squirrelmail_language, true);
 
-   // Need the base URI to set the cookies. (Same code as in webmail.php)
-   ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
-   $base_uri = $regs[1];
+    /* Need the base URI to set the cookies. (Same code as in webmail.php). */
+    ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
+    $base_uri = $regs[1];
+    @session_destroy();
 
-   @session_destroy();
-   // In case the last session was not terminated properly, make sure
-   // we get a new one.
-   $cookie_params = session_get_cookie_params(); 
-   setcookie(session_name(),'',0,$cookie_params['path'].$cookie_params['domain']); 
-   setcookie('username', '', 0, $base_uri);
-   setcookie('key', '', 0, $base_uri);
-   header ('Pragma: no-cache');
+    /*
+     * In case the last session was not terminated properly, make sure
+     * we get a new one.
+     */
+    $cookie_params = session_get_cookie_params(); 
+    setcookie(session_name(),'',0,$cookie_params['path'].$cookie_params['domain']); 
+    setcookie('username', '', 0, $base_uri);
+    setcookie('key', '', 0, $base_uri);
+    header ('Pragma: no-cache');
 
-   do_hook('login_cookie');
+    do_hook('login_cookie');
 
-   echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">' .
-        "\n\n" .
-	"<HTML>\n" .
-	"<HEAD>\n";
+    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">' .
+         "\n\n" .
+ 	 "<HTML>\n" .
+	 "<HEAD>\n";
 			   
-   if ($theme_css != "")
-       echo "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"$theme_css\">\n";
+    if ($theme_css != "") {
+        echo "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"$theme_css\">\n";
+    }
 
-   echo '<TITLE>';
-   echo $org_name . ' - ' . _("Login");
-   echo "</TITLE></HEAD>\n";
-   echo "<BODY TEXT=#000000 BGCOLOR=#FFFFFF LINK=#0000CC VLINK=#0000CC ALINK=#0000CC onLoad='document.forms[0].elements[0].focus();'>\n";
-   echo "<FORM ACTION=\"redirect.php\" METHOD=\"POST\" NAME=f>\n";
+    /* Output the javascript onload function. */
+    echo "<SCRIPT LANGUAGE=\"JavaScript\">\n";
+    echo "<!--\n";
+    echo "  function squirrelmail_loginpage_onload() {\n";
+    echo "    document.forms[0].js_autodetect_results.value = '" . SMPREF_JS_ON . "';\n";
+    echo "    document.forms[0].elements[0].focus();\n";
+    echo "  }\n";
+    echo "// -->\n";
+    echo "</script>\n";
+
+    /* Set the title of this page. */
+    echo "<TITLE>$org_name - " . _("Login") . "</TITLE></HEAD>\n";
+    echo "<BODY TEXT=#000000 BGCOLOR=#FFFFFF LINK=#0000CC VLINK=#0000CC ALINK=#0000CC onLoad='squirrelmail_loginpage_onload();'>\n";
+    echo "<FORM ACTION=\"redirect.php\" METHOD=\"POST\" NAME=f>\n";
    
-   $username_form_name = 'login_username';
-   $password_form_name = 'secretkey';
-   do_hook('login_top');
+    $username_form_name = 'login_username';
+    $password_form_name = 'secretkey';
+    do_hook('login_top');
+
+    $loginname_value = (isset($loginname) ? htmlspecialchars($loginname) : '');
    
-   echo "<CENTER><IMG SRC=\"$org_logo\"></CENTER>\n";
-   echo "<CENTER><SMALL>";
-   printf (_("SquirrelMail version %s"), $version);
-   echo "<BR>\n";
-   echo _("By the SquirrelMail Development Team");
-   echo "<BR></SMALL><CENTER>\n";
-   echo "<TABLE COLS=1 WIDTH=350>\n";
-   echo "   <TR>\n";
-   echo "      <TD BGCOLOR=#DCDCDC>\n";
-   echo "         <B><CENTER>";
-   printf (_("%s Login"), $org_name);
-   echo "</CENTER></B>\n";
-   echo "      </TD>\n";
-   echo "   </TR><TR>\n";
-   echo "      <TD BGCOLOR=#FFFFFF>\n";
-   echo "         <TABLE COLS=2 WIDTH=100%>\n";
-   echo "            <TR>\n";
-   echo "               <TD WIDTH=30% ALIGN=right>\n";
-   echo _("Name:");
-   echo "               </TD><TD WIDTH=* ALIGN=left>\n";
-   echo "                  <INPUT TYPE=TEXT NAME=\"$username_form_name\"";
-   if (isset($loginname))
-      echo " value=\"" . htmlspecialchars($loginname) . "\"";
-   echo ">\n";
-   echo "               </TD>\n";
-   echo "            </TR><TR>\n";
-   echo "               <TD WIDTH=30% ALIGN=right>\n";
-   echo _("Password:");
-   echo "               </TD><TD WIDTH=* ALIGN=left>\n";
-   echo "                  <INPUT TYPE=PASSWORD NAME=\"$password_form_name\">\n";
-   echo "               </TD>\n";
-   if ($rcptaddress != '') {
-      echo "               <INPUT TYPE=HIDDEN NAME=\"rcptemail\" VALUE=\"".htmlspecialchars($rcptaddress)."\">\n";
-   }
-   echo "            </TR>\n";
-   echo "         </TABLE>\n";
-   echo "      </TD>\n";
-   echo "   </TR><TR>\n";
-   echo "      <TD>\n";
-   echo '         <CENTER><INPUT TYPE=SUBMIT VALUE="';
-   echo _("Login");
-   echo "\"></CENTER>\n";
-   echo "      </TD>\n";
-   echo "   </TR>\n";
-   echo "</TABLE>\n";
-   echo "<input type=hidden name=just_logged_in value=1>\n";
-   do_hook('login_form');
-   echo "</FORM>\n";
-   do_hook('login_bottom');
-?>
-</BODY>
-</HTML>
+    echo "<CENTER><SMALL>";
+    echo "  <IMG SRC=\"$org_logo\"><BR>\n";
+    echo '  ' . sprintf (_("SquirrelMail version %s"), $version) . "<BR>\n";
+    echo '  ' . _("By the SquirrelMail Development Team") . "<BR>\n";
+    echo "</SMALL><CENTER>\n";
 
+    echo "<TABLE COLS=1 WIDTH=350>\n";
+    echo "   <TR><TD BGCOLOR=#DCDCDC>\n";
+    echo '      <B><CENTER>' . sprintf (_("%s Login"), $org_name) . "</CENTER></B>\n";
+    echo "   </TD></TR>";
+    echo "   <TR><TD BGCOLOR=\"#FFFFFF\"><TABLE COLS=2 WIDTH=\"100%\">\n";
+    echo "      <TR>\n";
+    echo '         <TD WIDTH=30% ALIGN=right>' . _("Name:") . "</TD>\n";
+    echo "         <TD WIDTH=* ALIGN=left>\n";
+    echo "            <INPUT TYPE=TEXT NAME=\"$username_form_name\" VALUE=\"$loginname_value\">\n";
+    echo "         </TD>\n";
+    echo "      </TR>\n";
+    echo "      <TR>\n";
+    echo '         <TD WIDTH="30%" ALIGN=right>' . _("Password:") . "</TD>\n";
+    echo "         <TD WIDTH=* ALIGN=left>\n";
+    echo "            <INPUT TYPE=PASSWORD NAME=\"$password_form_name\">\n";
+    echo "            <INPUT TYPE=HIDDEN NAME=\"js_autodetect_results\" VALUE=\"" . SMPREF_JS_OFF . "\">\n";
+    echo "            <INPUT TYPE=HIDDEN NAME=\"just_logged_in\" value=1>\n";
+    if ($rcptaddress != '') {
+        echo "         <INPUT TYPE=HIDDEN NAME=\"rcptemail\" VALUE=\"".htmlspecialchars($rcptaddress)."\">\n";
+    }
+    echo "         </TD>\n";
+    echo "      </TR>\n";
+    echo "   </TABLE></TD></TR>\n";
+    echo "   <TR><TD>\n";
+    echo '      <CENTER><INPUT TYPE=SUBMIT VALUE="' . _("Login") . "\"></CENTER>\n";
+    echo "   </TD></TR>\n";
+    echo "</TABLE>\n";
+
+    do_hook('login_form');
+    echo "</FORM>\n";
+
+    do_hook('login_bottom');
+    echo "</BODY>\n";
+    echo "</HTML>\n";
+?>

+ 17 - 117
src/options.php

@@ -82,6 +82,7 @@
         setPref($data_dir, $username, 'chosen_theme', $chosentheme);
         setPref($data_dir, $username, 'language', $language);
         setPref($data_dir, $username, 'use_javascript_addr_book', $javascript_abook);
+        setPref($data_dir, $username, 'javascript_setting', $new_javascript_setting);
         setPref($data_dir, $username, 'show_num', $shownum);
         setPref($data_dir, $username, 'wrap_at', $wrapat);
         setPref($data_dir, $username, 'editor_size', $editorsize);
@@ -116,6 +117,17 @@
             setPref($data_dir, $username, 'page_selector', 1);
         }
 
+        $js_autodetect_results = (isset($js_autodetect_results) ? $js_autodetect_results : SMPREF_JS_OFF);
+        if ($new_javascript_setting == SMPREF_JS_AUTODETECT) {
+            if ($js_autodetect_results == SMPREF_JS_ON) {
+                setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
+            } else {
+                setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
+            }
+        } else {
+            setPref($data_dir, $username, 'javascript_on', $new_javascript_setting);
+        }  
+
         do_hook('options_display_save');
 
         echo '<br><b>'._("Successfully saved display preferences!").'</b><br>';
@@ -213,13 +225,13 @@
     /* Let's sort Javascript Option Pages to the bottom. */
     /*****************************************************/
     foreach ($optionpages as $optpage) {
-        if ($optpage['js']) {
+        if (!$optpage['js']) {
+            $reg_optionpages[] = $optpage;
+        } else if ($javascript_on == SMPREF_JS_ON) {
             $js_optionpages[] = $optpage;
-        } else {
-            $nojs_optionpages[] = $optpage;
         }
     }
-    $optionpages = array_merge($nojs_optionpages, $js_optionpages);
+    $optionpages = array_merge($reg_optionpages, $js_optionpages);
 
     /********************************************/
     /* Now, print out each option page section. */
@@ -271,121 +283,9 @@
     /*******************************************************************/
 
     /**
-     * This function prints out an option page row. All it actually
-     * does is call the three functions below.
+     * This function prints out an option page row.
      */
     function print_optionpages_row($leftopt, $rightopt = false) {
-        if ($rightopt == false) {
-            if ($leftopt['js']) {
-                print_optionpages_row_fulljs($leftopt);
-            } else {
-                print_optionpages_row_nojs($leftopt);
-            }
-        } else {
-            if ($leftopt['js']) {
-                if ($rightopt['js']) {
-                    print_optionpages_row_fulljs($leftopt, $rightopt);
-                } else {
-                    print_optionpages_row_partjs($leftopt, $rightopt);
-                }
-            } else {
-                print_optionpages_row_nojs($leftopt, $rightopt);
-            }
-        }
-    }
-
-    /**
-     * This function prints out an option page row: in which the left
-     *   Left:  options for functionality that do not require javascript
-     *   Right: options for functionality that do not require javascript
-     */
-    function print_optionpages_row_nojs($leftopt, $rightopt = false) {
-        global $color;
-?>
-<table bgcolor="<?php echo $color[4] ?>" width="100%" cellpadding="0" cellspacing="5" border="0">
-   <tr><td valign=top>
-      <table width="100%" cellpadding="3" cellspacing="0" border="0">
-         <tr>
-            <td valign="top" bgcolor="<?php echo $color[9] ?>" width="50%">
-               <a href="<?php echo $leftopt['url'] ?>"><?php echo $leftopt['name'] ?></a>
-            </td>
-            <td valign="top" bgcolor="<?php echo $color[4] ?>">&nbsp;</td>
-<?php if ($rightopt != false) { ?>
-            <td valign="top" bgcolor="<?php echo $color[9] ?>" width="50%">
-               <a href="<?php echo $rightopt['url'] ?>"><?php echo $rightopt['name'] ?></a>
-            </td>
-<?php } else { ?>
-            <td valign="top" bgcolor="<?php echo $color[4] ?>" width="50%">&nbsp;</td>
-<?php } ?>
-         </tr>
-         <tr>
-            <td valign="top" bgcolor="<?php echo $color[0] ?>">
-               <?php echo $leftopt['desc'] ?>
-            </td>
-            <td valign="top" bgcolor="<?php echo $color[4] ?>">&nbsp;</td>
-<?php if ($rightopt != false) { ?>
-            <td valign="top" bgcolor="<?php echo $color[0] ?>">
-               <?php echo $rightopt['desc'] ?>
-            </td>
-<?php } else { ?>
-            <td valign="top" bgcolor="<?php echo $color[4] ?>">&nbsp;</td>
-<?php } ?>
-         </tr>
-      </table>
-   </td></tr>
-</table>
-<?php
-    }
-
-    /**
-     * This function prints out an option page row: in which the left
-     *   Left:  options for functionality that does not require javascript
-     *   Right: options for functionality that are javascript only
-     */
-    function print_optionpages_row_partjs($leftopt, $rightopt = false) {
-        global $color;
-?>
-<table bgcolor="<?php echo $color[4] ?>" width="100%" cellpadding="0" cellspacing="5" border="0">
-   <tr><td valign=top>
-      <table width="100%" cellpadding="3" cellspacing="0" border="0">
-         <tr>
-            <td valign="top" bgcolor="<?php echo $color[9] ?>" width="50%">
-               <a href="<?php echo $leftopt['url'] ?>"><?php echo $leftopt['name'] ?></a>
-            </td>
-            <td valign="top" bgcolor="<?php echo $color[4] ?>">&nbsp;</td>
-<?php if ($rightopt != false) { ?>
-            <td valign="top" bgcolor="<?php echo $color[9] ?>" width="50%">
-               <a href="<?php echo $rightopt['url'] ?>"><?php echo $rightopt['name'] ?></a>
-            </td>
-<?php } else { ?>
-            <td valign="top" bgcolor="<?php echo $color[4] ?>" width="50%">&nbsp;</td>
-<?php } ?>
-         </tr>
-         <tr>
-            <td valign="top" bgcolor="<?php echo $color[0] ?>">
-               <?php echo $leftopt['desc'] ?>
-            </td>
-            <td valign="top" bgcolor="<?php echo $color[4] ?>">&nbsp;</td>
-<?php if ($rightopt != false) { ?>
-            <td valign="top" bgcolor="<?php echo $color[0] ?>">
-               <?php echo $rightopt['desc'] ?>
-            </td>
-<?php } else { ?>
-            <td valign="top" bgcolor="<?php echo $color[4] ?>">&nbsp;</td>
-<?php } ?>
-         </tr>
-      </table>
-   </td></tr>
-</table>
-<?php
-    }
-
-    /**
-     * This function prints out an option page row: in which the left
-     *   Left:  options for functionality that are javascript only
-     *   Right: options for functionality that are javascript only
-     */
-    function print_optionpages_row_fulljs($leftopt, $rightopt = false) {
         global $color;
 ?>
 <table bgcolor="<?php echo $color[4] ?>" width="100%" cellpadding="0" cellspacing="5" border="0">

+ 11 - 1
src/options_display.php

@@ -39,6 +39,12 @@
                  array( '1' => _("JavaScript"),
                         '0' => _("HTML") ),
                  $use_javascript_addr_book );
+    OptionSelect( _("Use Javascript"), 'new_javascript_setting',
+                 array(SMPREF_JS_AUTODETECT => _("Autodetect"),
+                       SMPREF_JS_ON         => _("Always"),
+                       SMPREF_JS_OFF        => _("Never") ),
+                 $javascript_setting );
+    OptionHidden('js_autodetect_results', SMPREF_JS_OFF);
     OptionText( _("Number of Messages to Index"), 'shownum', $show_num, 5 );
     OptionText( _("Wrap incoming text at"), 'wrapat', $wrap_at, 5 );
     OptionText( _("Size of editor window"), 'editorsize', $editor_size, 5 );
@@ -105,6 +111,10 @@
     </td></tr>
     </table>
 
+<SCRIPT LANGUAGE="JavaScript"><!--
+  document.forms[0].js_autodetect_results.value = '<?php echo SMPREF_JS_ON; ?>';
+// --></SCRIPT>
+
 </td></tr>
 </table>
-</body></html>
+</body></html>

+ 121 - 100
src/redirect.php

@@ -1,102 +1,123 @@
 <?php
-
-   /**
-    **  redirect.php -- derived from webmail.php by Ralf Kraudelt
-    **                                              kraude@wiwi.uni-rostock.de
-    **
-    **  Copyright (c) 1999-2000 ...
-    **  Licensed under the GNU GPL. For full terms see the file COPYING.
-    **
-    **  prevents users from reposting their form data after a
-    **  successful logout
-    **
-    **  $Id$
-    **/
-
-   require_once('../functions/i18n.php');
-   require_once('../functions/strings.php');
-   require_once('../config/config.php');
-
-   // Before starting the session, the base URI must be known.
-   // Assuming that this file is in the src/ subdirectory (or
-   // something).
-   ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
-   $base_uri = $regs[1];
-
-   header('Pragma: no-cache');
-   $location = get_location();
-
-   session_set_cookie_params (0, $base_uri);
-   session_start();
-
-   session_unregister ('user_is_logged_in');
-   session_register ('base_uri');
-
-   if (! isset($squirrelmail_language))
-      $squirrelmail_language = '';
-   set_up_language($squirrelmail_language, true);
-
-   if(!isset($login_username)) {
-      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\">"._("Go to the login page")."</a>\n";
-      echo "</center>";
-      echo "</body></html>\n";
-      exit;
-   }
-
-   // Refresh the language cookie.
-   if (isset($squirrelmail_language)) {
-      setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,$base_uri);
-   }
-
-
-   require_once('../functions/prefs.php');
-   require_once('../functions/imap.php');
-   require_once('../functions/plugin.php');
-
-   if (!session_is_registered('user_is_logged_in')) {
-      do_hook ('login_before');
-
-      $onetimepad = OneTimePadCreate(strlen($secretkey));
-      $key = OneTimePadEncrypt($secretkey, $onetimepad);
-      session_register('onetimepad');
-      // verify that username and password are correct
-      if ($force_username_lowercase)
-          $login_username = strtolower($login_username);
-
-      $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
-      if (!$imapConnection) {
-         echo "<html><body bgcolor=\"#ffffff\">\n";
-         echo "<br><br>";
-         echo "<center>";
-         echo "<b>"._("There was an error contacting the mail server.")."</b><br>";
-         echo _("Contact your administrator for help.")."\n";
-         echo "</center>";
-         echo "</body></html>\n";
-         exit;
-      } else {
-         $delimiter = sqimap_get_delimiter ($imapConnection);
-      }
-      sqimap_logout($imapConnection);
-
-      $username = $login_username;
-      session_register ('username');
-      setcookie('key', $key, 0, $base_uri);
-      setcookie('delimiter', $delimiter, 0, $base_uri);
-      do_hook ('login_verified');
-   }
-
-   $user_is_logged_in = true;
-   session_register ('user_is_logged_in');
-   $just_logged_in = true;
-   session_register ('just_logged_in');
-
-   if(isset($rcptemail))
-      header("Location: webmail.php?right_frame=compose.php&rcptaddress=" .
-         urlencode($rcptemail));
-   else
-      header("Location: webmail.php");
+    /**
+     * redirect.php
+     * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
+     *
+     * Copyright (c) 1999-2001 The Squirrelmail Development Team
+     * Licensed under the GNU GPL. For full terms see the file COPYING.
+     *
+     * Prevents users from reposting their form data after a successful logout.
+     *
+     * $Id$
+     */
+
+    require_once('../functions/i18n.php');
+    require_once('../functions/strings.php');
+    require_once('../config/config.php');
+
+    /* Before starting the session, the base URI must be known. Assuming */
+    /* that this file is in the src/ subdirectory (or something).        */
+    ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
+    $base_uri = $regs[1];
+
+    header('Pragma: no-cache');
+    $location = get_location();
+
+    session_set_cookie_params (0, $base_uri);
+    session_start();
+
+    session_unregister ('user_is_logged_in');
+    session_register ('base_uri');
+
+    if (! isset($squirrelmail_language)) {
+        $squirrelmail_language = '';
+    }
+    set_up_language($squirrelmail_language, true);
+
+    if (!isset($login_username)) {
+        echo "<HTML><BODY BGCOLOR=\"#ffffff\">\n";
+        echo "<BR><BR>\n";
+        echo "<CENTER>\n";
+        echo '  <B>' . _("You must be logged in to access this page.") . "</B><BR>";
+        echo '  <A HREF="../src/login.php">'  . _("Go to the login page") . "</A>\n";
+        echo "</CENTER>\n";
+        echo "</BODY></HTML>\n";
+        exit;
+    }
+
+    /* Refresh the language cookie. */
+    if (isset($squirrelmail_language)) {
+        setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,$base_uri);
+    }
+
+    require_once('../functions/prefs.php');
+    require_once('../functions/imap.php');
+    require_once('../functions/plugin.php');
+    require_once('../functions/constants.php');
+
+    if (!session_is_registered('user_is_logged_in')) {
+        do_hook ('login_before');
+
+        $onetimepad = OneTimePadCreate(strlen($secretkey));
+        $key = OneTimePadEncrypt($secretkey, $onetimepad);
+        session_register('onetimepad');
+
+        /* Verify that username and password are correct. */
+        if ($force_username_lowercase) {
+            $login_username = strtolower($login_username);
+        }
+
+        $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
+        if (!$imapConnection) {
+            echo "<html><body bgcolor=\"#ffffff\">\n";
+            echo "<br><br>";
+            echo "<center>";
+            echo "<b>"._("There was an error contacting the mail server.")."</b><br>";
+            echo _("Contact your administrator for help.")."\n";
+            echo "</center>";
+            echo "</body></html>\n";
+            exit;
+        } else {
+            $delimiter = sqimap_get_delimiter ($imapConnection);
+        }
+        sqimap_logout($imapConnection);
+
+        $username = $login_username;
+        session_register ('username');
+        setcookie('key', $key, 0, $base_uri);
+        setcookie('delimiter', $delimiter, 0, $base_uri);
+        do_hook ('login_verified');
+    }
+
+    /* Set the login variables. */
+    $user_is_logged_in = true;
+    $just_logged_in = true;
+
+    /* And register with them with the session. */
+    session_register ('user_is_logged_in');
+    session_register ('just_logged_in');
+
+    /* Complete autodetection of Javascript. */
+    $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
+    $js_autodetect_results = (isset($js_autodetect_results) ? $js_autodetect_results : SMPREF_JS_OFF);
+    if ($javascript_setting == SMPREF_JS_AUTODETECT) {
+        if ($js_autodetect_results == SMPREF_JS_ON) {
+            setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
+        } else {
+            setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
+        }
+    } else {
+        setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
+    }
+
+    /* Compute the URL to forward the user to. */
+    if(isset($rcptemail)) {
+        $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
+        $redirect_url .= urlencode($rcptemail);
+    } else {
+        $redirect_url = 'webmail.php';
+    }
+
+    /* Send them off to the appropriate page. */
+    header("Location: $redirect_url");
 ?>

+ 114 - 100
src/right_main.php

@@ -1,115 +1,129 @@
 <?php
-   /**
-    **  right_main.php
-    **
-    **  Copyright (c) 1999-2000 The SquirrelMail development team
-    **  Licensed under the GNU GPL. For full terms see the file COPYING.
-    **
-    **  This is where the mailboxes are listed.  This controls most of what
-    **  goes on in SquirrelMail.
-    **
-    **  $Id$
-    **/
-
-   require_once('../src/validate.php');
-   require_once('../functions/imap.php');
-   require_once('../functions/date.php');
-   require_once('../functions/array.php');
-   require_once('../functions/mime.php');
-   require_once('../functions/mailbox_display.php');
-   require_once('../functions/display_messages.php');
-
-   /////////////////////////////////////////////////////////////////////////////////
-   //
-   // incoming variables from URL:
-   //    $sort             Direction to sort by date
-   //                         values:  0  -  descending order
-   //                         values:  1  -  ascending order
-   //    $startMessage     Message to start at
-   //    $mailbox          Full Mailbox name
-   //
-   // incoming from cookie:
-   //    $username         duh
-   //    $key              pass
-   //
-   /////////////////////////////////////////////////////////////////////////////////
-
-   // open a connection on the imap port (143)
-   $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-
-   if (isset($newsort) && $newsort != $sort) {
-      setPref($data_dir, $username, 'sort', $newsort);
-   }
-
-   // If the page has been loaded without a specific mailbox,
-   //   send them to the inbox
-   if (!isset($mailbox)) {
-      $mailbox = 'INBOX';
-      $startMessage = 1;
-   }
-
-   // compensate for the UW vulnerability
-   if ($imap_server_type == 'uw' && (strstr($mailbox, '../') !== false ||
-                                     substr($mailbox, 0, 1) == '/')) {
-      $mailbox = 'INBOX';
-   }
-
-   sqimap_mailbox_select($imapConnection, $mailbox);
-   displayPageHeader($color, $mailbox);
-
-   do_hook('right_main_after_header');
-
-   if (isset($note))
-      echo "<CENTER><B>$note</B></CENTER><BR>\n";
-
-   if ($just_logged_in == true) {
-      $just_logged_in = false;
-
-      if (strlen(trim($motd)) > 0) {
-         echo "<br><table align=center width=70% cellpadding=0 cellspacing=3 border=0 bgcolor=\"$color[9]\">" .
-              '<tr><td>' .
-              "<table width=100% cellpadding=5 cellspacing=1 border=0 bgcolor=\"$color[4]\">" .
-              "<tr><td align=center>$motd";
-         do_hook('motd');
-         echo '</td></tr>' .
-              '</table>' .
-              '</td></tr></table>';
-      }
-   }
+    /**
+     * right_main.php
+     *
+     * Copyright (c) 1999-2001 The Squirrelmail Development Team
+     * Licensed under the GNU GPL. For full terms see the file COPYING.
+     *
+     * This is where the mailboxes are listed.  This controls most of what
+     * goes on in SquirrelMail.
+     *
+     * $Id$
+     */
+
+    require_once('../src/validate.php');
+    require_once('../functions/imap.php');
+    require_once('../functions/date.php');
+    require_once('../functions/array.php');
+    require_once('../functions/mime.php');
+    require_once('../functions/mailbox_display.php');
+    require_once('../functions/display_messages.php');
+
+    /***********************************************************
+     * incoming variables from URL:                            *
+     *   $sort             Direction to sort by date           *
+     *                        values:  0  -  descending order  *
+     *                        values:  1  -  ascending order   *
+     *   $startMessage     Message to start at                 *
+     *    $mailbox          Full Mailbox name                  *
+     *                                                         *
+     * incoming from cookie:                                   *
+     *    $username         duh                                *
+     *    $key              pass                               *
+     ***********************************************************/
+
+    /* Open a connection on the imap port (143) */
+    $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
+
+    if (isset($newsort) && $newsort != $sort) {
+        setPref($data_dir, $username, 'sort', $newsort);
+    }
+
+    /* If the page has been loaded without a specific mailbox, */
+    /* send them to the inbox                                  */
+    if (!isset($mailbox)) {
+        $mailbox = 'INBOX';
+        $startMessage = 1;
+    }
+
+    /* compensate for the UW vulnerability. */
+    if ($imap_server_type == 'uw' && (strstr($mailbox, '../') !== false ||
+                                      substr($mailbox, 0, 1) == '/')) {
+       $mailbox = 'INBOX';
+    }
+
+    sqimap_mailbox_select($imapConnection, $mailbox);
+    displayPageHeader($color, $mailbox);
+    echo "<br>\n";
+
+    do_hook('right_main_after_header');
+
+    if (isset($note)) {
+        echo "<CENTER><B>$note</B></CENTER><BR>\n";
+    }
+
+    if ($just_logged_in == true) {
+        $just_logged_in = false;
+
+        if (strlen(trim($motd)) > 0) {
+            echo "<br><table align=center width=70% cellpadding=0 cellspacing=3 border=0 bgcolor=\"$color[9]\">" .
+                 '<tr><td>' .
+                 "<table width=100% cellpadding=5 cellspacing=1 border=0 bgcolor=\"$color[4]\">" .
+                 "<tr><td align=center>$motd";
+            do_hook('motd');
+            echo '</td></tr>' .
+                 '</table>' .
+                 '</td></tr></table>';
+        }
+    }
 
     if (isset($newsort)) {
         $sort = $newsort;
         session_register('sort');
     }
 
-   // Check to see if we can use cache or not.  Currently the only time when you wont use it is
-   //    when a link on the left hand frame is used.  Also check to make sure we actually have the
-   //    array in the registered session data.  :)
-   if (! isset($use_mailbox_cache))
-       $use_mailbox_cache = 0;
-   if ($use_mailbox_cache && session_is_registered('msgs')) {
-      showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
-   } else {
-      if (session_is_registered('msgs'))
-         unset($msgs);
-      if (session_is_registered('msort'))
-         unset($msort);
-        if (session_is_registered('numMessages'))
+    /*********************************************************************
+     * Check to see if we can use cache or not. Currently the only time  *
+     * when you will not use it is when a link on the left hand frame is *
+     * used. Also check to make sure we actually have the array in the   *
+     * registered session data.  :)                                      *
+     *********************************************************************/
+    if (! isset($use_mailbox_cache)) {
+        $use_mailbox_cache = 0;
+    }
+
+    if ($use_mailbox_cache && session_is_registered('msgs')) {
+        showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
+    } else {
+        if (session_is_registered('msgs')) {
+            unset($msgs);
+        }
+
+        if (session_is_registered('msort')) {
+            unset($msort);
+        }
+
+        if (session_is_registered('numMessages')) {
             unset($numMessages);
+        }
+
+        $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
 
-    $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
+        showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
 
-      showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
+        if (session_is_registered('msgs') && isset($msgs)) {
+            session_register('msgs');
+        }
 
-      if (session_is_registered('msgs') && isset($msgs))
-         session_register('msgs');
-      if (session_is_registered('msort') && isset($msort))
-         session_register('msort');
-      session_register('numMessages');
-   }
+        if (session_is_registered('msort') && isset($msort)) {
+            session_register('msort');
+        }
+
+        session_register('numMessages');
+    }
 
-   do_hook('right_main_bottom');
-   sqimap_logout ($imapConnection);
+    do_hook('right_main_bottom');
+    sqimap_logout ($imapConnection);
 ?>
 </FONT>
 </BODY>

+ 10 - 48
src/validate.php

@@ -14,6 +14,7 @@
     session_start();
     require_once('../functions/i18n.php');
     require_once('../functions/auth.php');
+    require_once('../functions/strings.php');
 
     is_logged_in();
 
@@ -52,54 +53,15 @@
         }
     }
 
-    /************************************/
-    /* Trims every element in the array */
-    /************************************/
-    function TrimArray(&$array) {
-        foreach ($array as $k => $v) {
-            global $$k;
-            if (is_array($$k)) {
-                foreach ($$k as $k2 => $v2) {
-	           $$k[$k2] = substr($v2, 1);
-                }
-            } else {
-                $$k = substr($v, 1);
-            }
-
-	    /* Re-assign back to array. */
-            $array[$k] = $$k;
-        }
-    }
-   
-   
-    /***************************************************/
-    /* Removes slashes from every element in the array */
-    /***************************************************/
-    function RemoveSlashes(&$array) {
-        foreach ($array as $k => $v) {
-            global $$k;
-            if (is_array($$k)) {
-                foreach ($$k as $k2 => $v2) {
-                    $newArray[stripslashes($k2)] = stripslashes($v2);
-                }
-                $$k = $newArray;
-            } else {
-                $$k = stripslashes($v);
-            }
-
-	    /* Re-assign back to the array. */
-            $array[$k] = $$k;
-        }
-    }
-
-   /**
-    * Everyone needs stuff from config, and config needs stuff from
-    * strings.php, so include them both here.
-    *
-    * Include them down here instead of at the top so that all config
-    * variables overwrite any passed in variables (for security).
-    */
-    require_once('../functions/strings.php');
+    /**
+     * Everyone needs stuff from config, and config needs stuff from
+     * strings.php, so include them both here. Actually, strings is
+     * included at the top now as the string array functions have
+     * been moved into it.
+     *
+     * Include them down here instead of at the top so that all config
+     * variables overwrite any passed in variables (for security).
+     */
     require_once('../config/config.php');
     require_once('../src/load_prefs.php');
     require_once('../functions/page_header.php');