Major update -- Added mail reading, and many many many bug fixes
authorlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 2 Dec 1999 22:51:58 +0000 (22:51 +0000)
committerlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 2 Dec 1999 22:51:58 +0000 (22:51 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@48 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/mailbox.php
functions/mailbox_display.php
images/sort_none.gif [new file with mode: 0644]
src/move_messages.php

index 45dbbb7..d4159f5 100644 (file)
@@ -35,6 +35,9 @@
          exit;
       }
 
+      $from_pos = 0;
+      $date_pos = 0;
+      $subj_pos = 0;
       while ($rel_start <= $end) {
          if ($end - $rel_start > 50) {
             $rel_end = $rel_start + 50;
          fputs($imapConnection, "messageFetch FETCH $rel_start:$rel_end RFC822.HEADER.LINES (From Subject Date)\n");
          $read = fgets($imapConnection, 1024);
 
-         $from_num = $rel_start - 1;
-         $date_num = $rel_start - 1;
-         $subj_num = $rel_start - 1;
          while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
             if (substr($read, 0, 5) == "From:") {
                $read = ereg_replace("<", "EMAILSTART--", $read);
                $read = ereg_replace(">", "--EMAILEND", $read);
-               $from[$from_num] = substr($read, 5, strlen($read) - 6);
-               $from_num++;
+               $from[$from_pos] = substr($read, 5, strlen($read) - 6);
+               $from_pos++;
             }
             else if (substr($read, 0, 5) == "Date:") {
                $read = ereg_replace("<", "&lt;", $read);
                $read = ereg_replace(">", "&gt;", $read);
-               $date[$date_num] = substr($read, 5, strlen($read) - 6);
-               $date_num++;
+               $date[$date_pos] = substr($read, 5, strlen($read) - 6);
+               $date_pos++;
             }
             else if (substr($read, 0, 8) == "Subject:") {
                $read = ereg_replace("<", "&lt;", $read);
                $read = ereg_replace(">", "&gt;", $read);
-               $subject[$subj_num] = substr($read, 8, strlen($read) - 9);
-               $subj_num++;
+               $subject[$subj_pos] = substr($read, 8, strlen($read) - 9);
+               if (strlen(Chop($subject[$subj_pos])) == 0)
+                  $subject[$subj_pos] = "(no subject)";
+               $subj_pos++;
             }
             $read = fgets($imapConnection, 1024);
          }
 
       return $box;
    }
+
+   function fetchBody($imapConnection, $id) {
+      fputs($imapConnection, "messageFetch FETCH $id:$id BODY[TEXT]\n");
+      $count = 0;
+      $read[$count] = fgets($imapConnection, 1024);
+      while ((substr($read[$count], 0, 15) != "messageFetch OK") && (substr($read[$count], 0, 16) != "messageFetch BAD")) {
+         $count++;
+         $read[$count] = fgets($imapConnection, 1024);
+      }
+
+      $count = 0;
+      $useHTML= false;
+      while ($count < count($read)) {
+         $read[$count] = "^^$read[$count]";
+         if (strpos($read[$count], "<html>") == true) {
+            $useHTML = true;
+         } else if (strpos(strtolower($read[$count]), "</html") == true) {
+            $useHTML= false;
+         }
+         $read[$count] = substr($read[$count], 2, strlen($read[$count]));
+
+         if ($useHTML == false) {
+            $read[$count] = str_replace(" ", "&nbsp;", $read[$count]);
+            $read[$count] = str_replace("\n", "", $read[$count]);
+            $read[$count] = str_replace("\r", "", $read[$count]);
+            $read[$count] = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", $read[$count]);
+
+            $read[$count] = "^^$read[$count]";
+            if (strpos(trim(str_replace("&nbsp;", "", $read[$count])), ">>") == 2) {
+               $read[$count] = substr($read[$count], 2, strlen($read[$count]));
+               $read[$count] = "<FONT FACE=\"Fixed\" COLOR=FF0000>$read[$count]</FONT>\n";
+            } else if (strpos(trim(str_replace("&nbsp;", "", $read[$count])), ">") == 2) {
+               $read[$count] = substr($read[$count], 2, strlen($read[$count]));
+               $read[$count] = "<FONT FACE=\"Fixed\" COLOR=800000>$read[$count]</FONT>\n";
+            } else {
+               $read[$count] = substr($read[$count], 2, strlen($read[$count]));
+               $read[$count] = "<FONT FACE=\"Fixed\" COLOR=000000>$read[$count]</FONT>\n";
+            }
+
+            if (strpos(strtolower($read[$count]), "http://") != false) {
+               $start = strpos(strtolower($read[$count]), "http://");
+               $link = substr($read[$count], $start, strlen($read[$count]));
+
+               if (strpos($link, "&nbsp;"))
+                  $end = strpos($link, "&nbsp;");
+               else if (strpos($link, "<"))
+                  $end = strpos($link, "<");
+               else
+                  $end = strlen($link);
+
+               $link = substr($link, 0, $end);
+
+               $read[$count] = str_replace($link, "<A HREF=\"$link\" TARGET=_top>$link</A>", $read[$count]);
+            }
+         }
+         $count++;
+      }
+
+      return $read;
+   }
 ?>
index 4621169..645ec00 100644 (file)
@@ -8,22 +8,20 @@
     **
     **/
 
-   function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen) {
+   function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox) {
       $senderName = getSenderName($from);
-      if (strlen(Chop($subject)) == 0)
-         $subject = "(no subject)";
-
+      $urlMailbox = urlencode($mailbox);
       echo "<TR>\n";
       if ($seen == false) {
          echo "   <TD><FONT FACE=\"Arial,Helvetica\"><nobr><B><input type=checkbox name=\"msg[$t]\" value=$i></B></nobr></FONT></TD>\n";
          echo "   <TD><FONT FACE=\"Arial,Helvetica\"><B>$senderName</B></FONT></TD>\n";
          echo "   <TD><CENTER><B><FONT FACE=\"Arial,Helvetica\">$dateString</FONT></B></CENTER></TD>\n";
-         echo "   <TD><FONT FACE=\"Arial,Helvetica\"><B>$subject</B></FONT></TD>\n";
+         echo "   <TD><FONT FACE=\"Arial,Helvetica\"><B><A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$i\">$subject</A></B></FONT></TD>\n";
       } else {
          echo "   <TD><FONT FACE=\"Arial,Helvetica\"><nobr><input type=checkbox name=\"msg[$t]\" value=$i></nobr></FONT></TD>\n";
          echo "   <TD><FONT FACE=\"Arial,Helvetica\">$senderName</FONT></TD>\n";
          echo "   <TD><FONT FACE=\"Arial,Helvetica\"><CENTER>$dateString</CENTER></FONT></TD>\n";
-         echo "   <TD><FONT FACE=\"Arial,Helvetica\">$subject</FONT></TD>\n";
+         echo "   <TD><FONT FACE=\"Arial,Helvetica\"><A HREF=\"read_body.php?mailbox=$urlMailbox&passed_id=$i\">$subject</A></FONT></TD>\n";
       }
       echo "</TR>\n";
    }
 
       /** The delete and move options */
       echo "<TR><TD BGCOLOR=DCDCDC>";
-      echo "<FORM name=messageList method=post action=\"move_messages.php?mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage\">";
+      echo "<FORM name=messageList method=post action=\"move_messages.php?msg=$msg&mailbox=$urlMailbox&sort=$sort&startMessage=$startMessage\">";
       echo "<SELECT NAME=move_or_delete><OPTION>Delete selected messages<OPTION>Move selected messages</SELECT>";
       echo "<NOBR><INPUT TYPE=SUBMIT VALUE=\"Go\">";
       if (($move_to_trash == true) && ($mailbox == $trash_folder))
          echo "<TR><TD BGCOLOR=FFFFFF COLSPAN=4><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.
          $i = $startMessage - 1;
-         printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"]);
+         printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox);
       } else {
          for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
-            printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"]);
+            printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"], $mailbox);
             $t++;
          }
       }
diff --git a/images/sort_none.gif b/images/sort_none.gif
new file mode 100644 (file)
index 0000000..0cef65c
Binary files /dev/null and b/images/sort_none.gif differ
index 0dc83b9..8fcc2e5 100644 (file)
@@ -4,39 +4,41 @@
    include("../functions/strings.php");
    include("../functions/page_header.php");
    include("../functions/display_messages.php");
+   include("../functions/imap.php");
 
-   $imapConnection = loginToImapServer($username, $key);
+   echo "<HTML><BODY TEXT=\"#000000\" BGCOLOR=\"#FFFFFF\" LINK=\"#0000EE\" VLINK=\"#0000EE\" ALINK=\"#0000EE\">";
+   $imapConnection = loginToImapServer($username, $key, $imapServerAddress);
 
    // switch to the mailbox, and get the number of messages in it.
    selectMailbox($imapConnection, $mailbox, $numMessages, $imapServerAddress);
 
-   // Marks the selected messages ad 'Deleted'
-   $j = 0;
-   $i = 0;
-
-   while ($j < count($msg)) {
-      if ($msg[$i]) {
-         /** check if they would like to move it to the trash folder or not */
-         if ($move_to_trash == true) {
-            $success = copyMessages($imapConnection, $msg[$i], $msg[$i], $trash_folder);
-            if ($success == true)
-               setMessageFlag($imapConnection, $msg[$i], $msg[$i], "Deleted");
-         } else {
-            setMessageFlag($imapConnection, $msg[$i], "Deleted");
+   if (strtolower($move_or_delete) == "delete selected messages") {
+      // Marks the selected messages ad 'Deleted'
+      $j = 0;
+      $i = 0;
+      while ($j < count($msg)) {
+         if ($msg[$i]) {
+            /** check if they would like to move it to the trash folder or not */
+            if ($move_to_trash == true) {
+               $success = copyMessages($imapConnection, $msg[$i], $msg[$i], $trash_folder);
+               if ($success == true)
+                  setMessageFlag($imapConnection, $msg[$i], $msg[$i], "Deleted");
+            } else {
+               setMessageFlag($imapConnection, $msg[$i], "Deleted");
+            }
+            $j++;
          }
-         $j++;
+         $i++;
       }
-      $i++;
+      if ($auto_expunge == true)
+         expungeBox($imapConnection, $mailbox, $numMessages);
+      displayPageHeader($mailbox);
+      messages_deleted_message($mailbox, $sort, $startMessage);
+   } else {
+      echo "Move";
    }
 
-   if ($auto_expunge == true)
-      expungeBox($imapConnection, $mailbox, $numMessages);
-
    // Log out this session
    fputs($imapConnection, "1 logout");
 
-   echo "<HTML><BODY TEXT=\"#000000\" BGCOLOR=\"#FFFFFF\" LINK=\"#0000EE\" VLINK=\"#0000EE\" ALINK=\"#0000EE\">";
-   displayPageHeader($mailbox);
-
-   messages_deleted_message($mailbox, $sort, $startMessage);
 ?>