浏览代码

speed optomizations and less imap commands

Luke Ehresman 25 年之前
父节点
当前提交
1b94a32042
共有 3 个文件被更改,包括 29 次插入21 次删除
  1. 5 12
      functions/imap_general.php
  2. 10 4
      functions/imap_mailbox.php
  3. 14 5
      functions/imap_messages.php

+ 5 - 12
functions/imap_general.php

@@ -217,21 +217,14 @@
    /******************************************************************************
     **  Returns the number of unseen messages in this folder 
     ******************************************************************************/
-   function sqimap_unseen_messages ($imap_stream, &$num_unseen) {
-      fputs ($imap_stream, "a001 SEARCH UNSEEN NOT DELETED\r\n");
+   function sqimap_unseen_messages ($imap_stream, &$num_unseen, $mailbox) {
+      //fputs ($imap_stream, "a001 SEARCH UNSEEN NOT DELETED\r\n");
+      fputs ($imap_stream, "a001 STATUS \"$mailbox\" (UNSEEN)\r\n");
       $read_ary = sqimap_read_data ($imap_stream, "a001", true, $result, $message);
       $unseen = false;
       
-      if (strlen($read_ary[0]) > 10) {
-         $unseen = true;
-         $ary = explode (" ", $read_ary[0]);
-         $num_unseen = count($ary) - 2;
-      } else {
-         $unseen = false;
-         $num_unseen = 0;
-      }
-
-      return $unseen;
+		$read_ary[0] = trim($read_ary[0]);
+		return substr($read_ary[0], strrpos($read_ary[0], " ")+1, (strlen($read_ary[0]) - strrpos($read_ary[0], " ") - 2)); 
    }
  
   

+ 10 - 4
functions/imap_mailbox.php

@@ -33,9 +33,9 @@
    /******************************************************************************
     **  Selects a mailbox
     ******************************************************************************/
-   function sqimap_mailbox_select ($imap_stream, $mailbox) {
+   function sqimap_mailbox_select ($imap_stream, $mailbox, $hide) {
       fputs ($imap_stream, "a001 SELECT \"$mailbox\"\r\n");
-      $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+     	$read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
    }
 
    
@@ -229,24 +229,30 @@
          if (strtolower($boxes[$i]["unformatted"]) == "inbox") {
             $boxesnew[0] = $boxes[$i];
             $boxes[$i]["used"] = true;
+				$i = count($boxes);
          }
       }
 
       if ($list_special_folders_first == true) {
-         for ($i = 0; $i < count($boxes); $i++) {
+         for ($i = count($boxes)-1; $i >= 0 ; $i--) {
 				if (($boxes[$i]["unformatted"] == $trash_folder) && ($move_to_trash)) {	
                $pos = count($boxesnew);
                $boxesnew[$pos] = $boxes[$i];
                $boxes[$i]["used"] = true;
+					$trash_found = true;
             }
 				else if (($boxes[$i]["unformatted"] == $sent_folder) && ($move_to_sent)) {	
                $pos = count($boxesnew);
                $boxesnew[$pos] = $boxes[$i];
                $boxes[$i]["used"] = true;
+					$sent_found = true;
             }
+
+				if (($sent_found && $trash_found) || ($sent_found && !$move_to_trash) || ($trash_found && !$move_to_sent) || (!$move_to_sent && !$move_to_trash))
+					$i = -1;
          }
       }
-		
+
       for ($i = 0; $i < count($boxes); $i++) {
          if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
              ($boxes[$i]["used"] == false))  {

+ 14 - 5
functions/imap_messages.php

@@ -38,18 +38,27 @@
    /******************************************************************************
     **  Returns some general header information -- FROM, DATE, and SUBJECT
     ******************************************************************************/
-   function sqimap_get_small_header ($imap_stream, $id, &$from, &$subject, &$date) {
+   function sqimap_get_small_header ($imap_stream, $id, &$from, &$subject, &$date, $sent) {
       //fputs ($imap_stream, "a001 FETCH $id BODY[HEADER.FIELDS (DATE FROM SUBJECT)]\r\n");
       //fputs ($imap_stream, "a001 FETCH $id RFC822.HEADER\r\n");
-      fputs ($imap_stream, "a001 FETCH $id BODY.PEEK[HEADER.FIELDS (Date From Subject)]\r\n");
+      fputs ($imap_stream, "a001 FETCH $id BODY.PEEK[HEADER.FIELDS (Date To From Subject)]\r\n");
       $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
 
       $subject = _("(no subject)");
       $from = _("Unknown Sender");
       for ($i = 0; $i < count($read); $i++) {
-         if (eregi ("^from:", $read[$i])) {
-            $from = sqimap_find_displayable_name(substr($read[$i], 5));
-         } else if (eregi ("^date:", $read[$i])) {
+
+			if ($sent == true) {
+         	if (eregi ("^to:", $read[$i])) {
+            	$from = sqimap_find_displayable_name(substr($read[$i], 3));
+				}	
+			} else { 
+         	if (eregi ("^from:", $read[$i])) {
+            	$from = sqimap_find_displayable_name(substr($read[$i], 5));
+				}	
+			}
+
+         if (eregi ("^date:", $read[$i])) {
             $date = substr($read[$i], 5);
          } else if (eregi ("^subject:", $read[$i])) {
             $subject = htmlspecialchars(eregi_replace ("^subject: ", "", $read[$i]));