Bläddra i källkod

added caching of messages in mailbox, as well as next and previous message
while reading a message.

nehresma 25 år sedan
förälder
incheckning
4e5055bdbf
3 ändrade filer med 67 tillägg och 20 borttagningar
  1. 4 6
      functions/mailbox_display.php
  2. 50 3
      src/read_body.php
  3. 13 11
      src/right_main.php

+ 4 - 6
functions/mailbox_display.php

@@ -34,7 +34,7 @@
    /**
    /**
     ** This function loops through a group of messages in the mailbox and shows them
     ** This function loops through a group of messages in the mailbox and shows them
     **/
     **/
-   function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num) {
+   function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, &$msgs) {
       include ("../config/config.php");
       include ("../config/config.php");
 
 
       if ($numMessages >= 1) {
       if ($numMessages >= 1) {
@@ -145,9 +145,6 @@
          }
          }
       }
       }
 
 
-//      session_register("messages");
-//      $messages = serialize($msgs);
-
       displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $mailbox, $sort, $color,$show_num);
       displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $mailbox, $sort, $color,$show_num);
    }
    }
 
 
@@ -158,8 +155,9 @@
          include("../config/config.php");
          include("../config/config.php");
 
 
       // if cache isn't already set, do it now
       // if cache isn't already set, do it now
-//      if (!session_is_registered("messages"))
-//         session_register("messages");
+      if (!session_is_registered("msgs"))
+         session_register("msgs");
+
       if ($startMessage + ($show_num - 1) < $numMessages) {
       if ($startMessage + ($show_num - 1) < $numMessages) {
          $endMessage = $startMessage + ($show_num-1);
          $endMessage = $startMessage + ($show_num-1);
       } else {
       } else {

+ 50 - 3
src/read_body.php

@@ -14,6 +14,36 @@
    if (!isset($date_php))
    if (!isset($date_php))
       include("../functions/date.php");
       include("../functions/date.php");
 
 
+   // given an IMAP message id number, this will look it up in the cached and sorted msgs array and
+   //    return the index.  used for finding the next and previous messages
+
+   // returns the index of the next valid message from the array
+   function findNextMessage() {
+      global $currentArrayIndex, $msgs;
+      if ($currentArrayIndex < (count($msgs)-1))
+         return $msgs[$currentArrayIndex+1]["ID"];
+      return -1;
+   }
+
+   // returns the index of the previous message from the array
+   function findPreviousMessage() {
+      global $currentArrayIndex, $msgs;
+      if ($currentArrayIndex > 0)
+         return $msgs[$currentArrayIndex-1]["ID"];
+      return -1;
+   }
+
+   if (isset($msgs)) {
+      for ($i=0; $i < count($msgs); $i++) {
+         if ($msgs[$i]["ID"] == $passed_id) {
+            $currentArrayIndex = $i;
+            break;
+         }
+      }
+   } else {
+      $currentArrayIndex = -1;
+   }
+
    include("../src/load_prefs.php");
    include("../src/load_prefs.php");
    $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
    $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
    sqimap_mailbox_select($imapConnection, $mailbox);
    sqimap_mailbox_select($imapConnection, $mailbox);
@@ -97,16 +127,33 @@
    echo "   <TR><TD BGCOLOR=\"$color[0]\" WIDTH=100%>";
    echo "   <TR><TD BGCOLOR=\"$color[0]\" WIDTH=100%>";
    echo "      <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
    echo "      <TABLE WIDTH=100% CELLSPACING=0 BORDER=0 COLS=2 CELLPADDING=3>";
    echo "         <TR>";
    echo "         <TR>";
-   echo "            <TD ALIGN=LEFT WIDTH=50%>";
+   echo "            <TD ALIGN=LEFT WIDTH=33%>";
    echo "               <SMALL>";
    echo "               <SMALL>";
-   echo "               <A HREF=\"right_main.php?sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
+   echo "               <A HREF=\"right_main.php?use_mailbox_cache=1&sort=$sort&startMessage=$startMessage&mailbox=$urlMailbox\">";
    echo _("Message List");
    echo _("Message List");
    echo "</A>&nbsp;|&nbsp;";
    echo "</A>&nbsp;|&nbsp;";
    echo "               <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">";
    echo "               <A HREF=\"delete_message.php?mailbox=$urlMailbox&message=$passed_id&sort=$sort&startMessage=1\">";
    echo _("Delete");
    echo _("Delete");
    echo "</A>&nbsp;&nbsp;";
    echo "</A>&nbsp;&nbsp;";
    echo "               </SMALL>";
    echo "               </SMALL>";
-   echo "            </TD><TD WIDTH=50% ALIGN=RIGHT>";
+   echo "            </TD><TD WIDTH=33% ALIGN=CENTER>";
+   echo "               <SMALL>\n";
+   if ($currentArrayIndex == -1) {
+      echo "Previous&nbsp;|&nbspNext";
+   } else {
+      $prev = findPreviousMessage();
+      $next = findNextMessage();
+      if ($prev != -1)
+         echo "<a href=\"read_body.php?passed_id=$prev&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;";
+      else
+         echo _("Previous") . "&nbsp;|&nbsp;";
+      if ($next != -1)
+         echo "<a href=\"read_body.php?passed_id=$next&mailbox=$mailbox&sort=$sort&startMessage=$startMessage&show_more=0\">" . _("Next") . "</A>";
+      else
+         echo _("Next");
+   }
+   echo "               </SMALL>\n";
+   echo "            </TD><TD WIDTH=33% ALIGN=RIGHT>";
    echo "               <SMALL>";
    echo "               <SMALL>";
    echo "               <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox\">";
    echo "               <A HREF=\"compose.php?forward_id=$passed_id&forward_subj=$url_subj&mailbox=$urlMailbox\">";
    echo _("Forward");
    echo _("Forward");

+ 13 - 11
src/right_main.php

@@ -78,18 +78,20 @@
    // Check to see if we can use cache or not.  Currently the only time when you wont use it is
    // 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
    //    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.  :)
    //    array in the registered session data.  :)
-//   if (!$use_mailbox_cache || !session_is_registered("msgs")) {
-//      echo "<br>not using cache<br>\n";
-//      if (session_is_registered("messages"))
-//         session_unregister("messages");
+   if ($use_mailbox_cache && session_is_registered("msgs")) {
+      displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $mailbox, $sort, $color,$show_num);
+   } else {
+      if (session_is_registered("msgs"))
+         unset($msgs);
 
 
-      showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num);
-//   } else {
-//      echo "<br>using cache<br>\n";
-//      $msgs = unserialize($messages);
-
-//      displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $mailbox, $sort, $color,$show_num);
-//   }
+      // i have found that only global variables can be registered successfully with a session.  therefore
+      //    i am passing in a simple empty variable (msgs) which will be returned with an array and can be
+      //    then registered here as a global variable.  whew.
+      showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $msgs);
+      
+      if (session_is_registered("msgs") && isset($msgs))
+         session_register("msgs");
+   }
 
 
    // close the connection
    // close the connection
    sqimap_logout ($imapConnection);
    sqimap_logout ($imapConnection);