Use sqimap_session_id instead of axxxx for imap connections.
authorphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 4 Oct 2001 14:31:57 +0000 (14:31 +0000)
committerphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 4 Oct 2001 14:31:57 +0000 (14:31 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1543 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/imap_general.php
functions/imap_mailbox.php
functions/imap_messages.php
functions/imap_search.php
functions/mime.php

index 8a7319148ebeeb2614b0c4bb2f96ea5aa0437e25..f4acc08c642574d3d080d5462df50262224a10d8 100755 (executable)
    global $imap_general_debug;
    $imap_general_debug = false;
 
    global $imap_general_debug;
    $imap_general_debug = false;
 
+   /******************************************************************************
+    **  Sets an unique session id in order to avoid simultanous sessions crash.
+    ******************************************************************************/
+
+   function sqimap_session_id() {
+      return( substr( session_id(), -4 ) );
+   }
+
+
    /******************************************************************************
     **  Reads the output from the IMAP stream.  If handle_errors is set to true,
     **  this will also handle all errors that are received.  If it is not set,
    /******************************************************************************
     **  Reads the output from the IMAP stream.  If handle_errors is set to true,
     **  this will also handle all errors that are received.  If it is not set,
          exit;
       }
 
          exit;
       }
 
-      fputs ($imap_stream, "a001 LOGIN \"" . quoteIMAP($username) . 
+      fputs ($imap_stream, sqimap_session_id() . ' LOGIN "' . quoteIMAP($username) . 
          '" "' . quoteIMAP($password) . "\"\r\n");
          '" "' . quoteIMAP($password) . "\"\r\n");
-      $read = sqimap_read_data ($imap_stream, 'a001', false, $response, $message);
+      $read = sqimap_read_data ($imap_stream, sqimap_session_id(), false, $response, $message);
 
       /** If the connection was not successful, lets see why **/
       if ($response != "OK") {
 
       /** If the connection was not successful, lets see why **/
       if ($response != "OK") {
     **  Simply logs out the imap session
     ******************************************************************************/
    function sqimap_logout ($imap_stream) {
     **  Simply logs out the imap session
     ******************************************************************************/
    function sqimap_logout ($imap_stream) {
-      fputs ($imap_stream, "a001 LOGOUT\r\n");
+      fputs ($imap_stream, sqimap_session_id() . " LOGOUT\r\n");
    }
 
    function sqimap_capability($imap_stream, $capability) {
    }
 
    function sqimap_capability($imap_stream, $capability) {
        global $imap_general_debug;
 
        if (!is_array($sqimap_capabilities)) {
        global $imap_general_debug;
 
        if (!is_array($sqimap_capabilities)) {
-               fputs ($imap_stream, "a001 CAPABILITY\r\n");
-               $read = sqimap_read_data($imap_stream, 'a001', true, $a, $b);
+               fputs ($imap_stream, sqimap_session_id() . " CAPABILITY\r\n");
+               $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $a, $b);
 
                $c = explode(' ', $read[0]);
                for ($i=2; $i < count($c); $i++) {
 
                $c = explode(' ', $read[0]);
                for ($i=2; $i < count($c); $i++) {
                           OS:  * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES)
                           OS:  We want to lookup all personal NAMESPACES...
                        */
                           OS:  * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES)
                           OS:  We want to lookup all personal NAMESPACES...
                        */
-                       fputs ($imap_stream, "a001 NAMESPACE\r\n");
-                       $read = sqimap_read_data($imap_stream, 'a001', true, $a, $b);
+                       fputs ($imap_stream, sqimap_session_id() . " NAMESPACE\r\n");
+                       $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $a, $b);
                        if (eregi('\\* NAMESPACE +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL)', $read[0], $data)) {
                                if (eregi('^\\( *\\((.*)\\) *\\)', $data[1], $data2))
                                        $pn = $data2[1];
                        if (eregi('\\* NAMESPACE +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL)', $read[0], $data)) {
                                if (eregi('^\\( *\\((.*)\\) *\\)', $data[1], $data2))
                                        $pn = $data2[1];
     **  Gets the number of messages in the current mailbox. 
     ******************************************************************************/
    function sqimap_get_num_messages ($imap_stream, $mailbox) {
     **  Gets the number of messages in the current mailbox. 
     ******************************************************************************/
    function sqimap_get_num_messages ($imap_stream, $mailbox) {
-      fputs ($imap_stream, "a001 EXAMINE \"$mailbox\"\r\n");
-      $read_ary = sqimap_read_data ($imap_stream, 'a001', true, $result, $message);
+      fputs ($imap_stream, sqimap_session_id() . " EXAMINE \"$mailbox\"\r\n");
+      $read_ary = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $result, $message);
       for ($i = 0; $i < count($read_ary); $i++) {
          if (ereg("[^ ]+ +([^ ]+) +EXISTS", $read_ary[$i], $regs)) {
            return $regs[1];
       for ($i = 0; $i < count($read_ary); $i++) {
          if (ereg("[^ ]+ +([^ ]+) +EXISTS", $read_ary[$i], $regs)) {
            return $regs[1];
     **  Returns the number of unseen messages in this folder 
     ******************************************************************************/
    function sqimap_unseen_messages ($imap_stream, $mailbox) {
     **  Returns the number of unseen messages in this folder 
     ******************************************************************************/
    function sqimap_unseen_messages ($imap_stream, $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);
+      //fputs ($imap_stream, sqimap_session_id() . " SEARCH UNSEEN NOT DELETED\r\n");
+      fputs ($imap_stream, sqimap_session_id() . " STATUS \"$mailbox\" (UNSEEN)\r\n");
+      $read_ary = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $result, $message);
       ereg("UNSEEN ([0-9]+)", $read_ary[0], $regs);
       return $regs[1];
    }
       ereg("UNSEEN ([0-9]+)", $read_ary[0], $regs);
       return $regs[1];
    }
     **  Saves a message to a given folder -- used for saving sent messages
     ******************************************************************************/
    function sqimap_append ($imap_stream, $sent_folder, $length) {
     **  Saves a message to a given folder -- used for saving sent messages
     ******************************************************************************/
    function sqimap_append ($imap_stream, $sent_folder, $length) {
-      fputs ($imap_stream, "a001 APPEND \"$sent_folder\" (\\Seen) \{$length}\r\n");
+      fputs ($imap_stream, sqimap_session_id() . " APPEND \"$sent_folder\" (\\Seen) \{$length}\r\n");
       $tmp = fgets ($imap_stream, 1024);
    } 
 
       $tmp = fgets ($imap_stream, 1024);
    } 
 
index 0bdc55660ac7b4274bdce3f0dc5ca4de051a633d..9aa7825680b062360144007a08be56124c438fda 100755 (executable)
@@ -15,8 +15,8 @@
     **  Expunges a mailbox 
     ******************************************************************************/
    function sqimap_mailbox_expunge ($imap_stream, $mailbox,$handle_errors = true) {
     **  Expunges a mailbox 
     ******************************************************************************/
    function sqimap_mailbox_expunge ($imap_stream, $mailbox,$handle_errors = true) {
-      fputs ($imap_stream, "a001 EXPUNGE\r\n");
-      $read = sqimap_read_data($imap_stream, "a001", $handle_errors, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " EXPUNGE\r\n");
+      $read = sqimap_read_data($imap_stream, sqimap_session_id(), $handle_errors, $response, $message);
    }
 
 
    }
 
 
@@ -26,8 +26,8 @@
    function sqimap_mailbox_exists ($imap_stream, $mailbox) {
       if (! isset($mailbox))
           return false;
    function sqimap_mailbox_exists ($imap_stream, $mailbox) {
       if (! isset($mailbox))
           return false;
-      fputs ($imap_stream, "a001 LIST \"\" \"$mailbox\"\r\n");
-      $mbx = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " LIST \"\" \"$mailbox\"\r\n");
+      $mbx = sqimap_read_data($imap_stream, sqimap_session_id(), true, $response, $message);
       return isset($mbx[0]);
    }
 
       return isset($mbx[0]);
    }
 
@@ -40,8 +40,8 @@
       if( $mailbox == _("None") )
           return;
       
       if( $mailbox == _("None") )
           return;
       
-      fputs ($imap_stream, "a001 SELECT \"$mailbox\"\r\n");
-             $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " SELECT \"$mailbox\"\r\n");
+             $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $response, $message);
       if ($recent) {
          for ($i=0; $i<count($read); $i++) {
             if (strpos(strtolower($read[$i]), "recent")) {
       if ($recent) {
          for ($i=0; $i<count($read); $i++) {
             if (strpos(strtolower($read[$i]), "recent")) {
@@ -51,8 +51,8 @@
          return $r[1];
       }
       if ($auto_expunge) {
          return $r[1];
       }
       if ($auto_expunge) {
-         fputs ($imap_stream, "a001 EXPUNGE\r\n");
-         $tmp = sqimap_read_data($imap_stream, "a001", false, $a, $b);
+         fputs ($imap_stream, sqimap_session_id() . " EXPUNGE\r\n");
+         $tmp = sqimap_read_data($imap_stream, sqimap_session_id(), false, $a, $b);
       }   
    }
 
       }   
    }
 
@@ -66,8 +66,8 @@
          $dm = sqimap_get_delimiter($imap_stream);
          $mailbox = $mailbox.$dm;
       }
          $dm = sqimap_get_delimiter($imap_stream);
          $mailbox = $mailbox.$dm;
       }
-      fputs ($imap_stream, "a001 CREATE \"$mailbox\"\r\n");
-      $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " CREATE \"$mailbox\"\r\n");
+      $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(), true, $response, $message);
 
       sqimap_subscribe ($imap_stream, $mailbox);
    }
 
       sqimap_subscribe ($imap_stream, $mailbox);
    }
@@ -78,8 +78,8 @@
     **  Subscribes to an existing folder 
     ******************************************************************************/
    function sqimap_subscribe ($imap_stream, $mailbox) {
     **  Subscribes to an existing folder 
     ******************************************************************************/
    function sqimap_subscribe ($imap_stream, $mailbox) {
-      fputs ($imap_stream, "a001 SUBSCRIBE \"$mailbox\"\r\n");
-      $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " SUBSCRIBE \"$mailbox\"\r\n");
+      $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(), true, $response, $message);
    }
 
 
    }
 
 
@@ -91,8 +91,8 @@
    function sqimap_unsubscribe ($imap_stream, $mailbox) {
                 global $imap_server_type;
 
    function sqimap_unsubscribe ($imap_stream, $mailbox) {
                 global $imap_server_type;
 
-      fputs ($imap_stream, "a001 UNSUBSCRIBE \"$mailbox\"\r\n");
-      $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " UNSUBSCRIBE \"$mailbox\"\r\n");
+      $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(), true, $response, $message);
    }
 
 
    }
 
 
     **  This function simply deletes the given folder
     ******************************************************************************/
    function sqimap_mailbox_delete ($imap_stream, $mailbox) {
     **  This function simply deletes the given folder
     ******************************************************************************/
    function sqimap_mailbox_delete ($imap_stream, $mailbox) {
-      fputs ($imap_stream, "a001 DELETE \"$mailbox\"\r\n");
-      $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " DELETE \"$mailbox\"\r\n");
+      $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(), true, $response, $message);
       sqimap_unsubscribe ($imap_stream, $mailbox);
    }
    
       sqimap_unsubscribe ($imap_stream, $mailbox);
    }
    
       $dm = sqimap_get_delimiter ($imap_stream);
 
       /** LSUB array **/
       $dm = sqimap_get_delimiter ($imap_stream);
 
       /** LSUB array **/
-      fputs ($imap_stream, "a001 LSUB \"$folder_prefix\" \"*\"\r\n");
-      $lsub_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " LSUB \"$folder_prefix\" \"*\"\r\n");
+      $lsub_ary = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
       
       // Section about removing the last element was removed
       // We don't return "* OK" anymore from sqimap_read_data
       
       // Section about removing the last element was removed
       // We don't return "* OK" anymore from sqimap_read_data
          else
             $mbx = $sorted_lsub_ary[$i];
 
          else
             $mbx = $sorted_lsub_ary[$i];
 
-         fputs ($imap_stream, "a001 LIST \"\" \"$mbx\"\r\n");
-         $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+         fputs ($imap_stream, sqimap_session_id() . " LIST \"\" \"$mbx\"\r\n");
+         $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
         // Another workaround for EIMS
          if (isset($read[1]) && 
             ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", 
         // Another workaround for EIMS
          if (isset($read[1]) && 
             ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", 
       /** Just in case they're not subscribed to their inbox, we'll get it 
           for them anyway **/
       if ($inbox_subscribed == false || $inbox_in_list == false) {
       /** Just in case they're not subscribed to their inbox, we'll get it 
           for them anyway **/
       if ($inbox_subscribed == false || $inbox_in_list == false) {
-         fputs ($imap_stream, "a001 LIST \"\" \"INBOX\"\r\n");
-         $inbox_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+         fputs ($imap_stream, sqimap_session_id() . " LIST \"\" \"INBOX\"\r\n");
+         $inbox_ary = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
         // Another workaround for EIMS
          if (isset($inbox_ary[1]) &&
             ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", 
         // Another workaround for EIMS
          if (isset($inbox_ary[1]) &&
             ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", 
       
       $dm = sqimap_get_delimiter ($imap_stream);
 
       
       $dm = sqimap_get_delimiter ($imap_stream);
 
-      fputs ($imap_stream, "a001 LIST \"$folder_prefix\" *\r\n");
-      $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+      $ssid = sqimap_session_id();
+      $lsid = strlen( $ssid ); 
+      fputs ($imap_stream, $ssid . " LIST \"$folder_prefix\" *\r\n");
+      $read_ary = sqimap_read_data ($imap_stream, $ssid, true, $response, $message);
       $g = 0;
       $g = 0;
-      $phase = "inbox"; 
+      $phase = "inbox";
 
       for ($i = 0; $i < count($read_ary); $i++) {
          // Another workaround for EIMS
 
       for ($i = 0; $i < count($read_ary); $i++) {
          // Another workaround for EIMS
-        if (isset($read_ary[$i + 1]) &&
-            ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", 
-            $read_ary[$i], $regs)) {
-           $i ++;
-           $read_ary[$i] = $regs[1] . '"' . 
-              addslashes(trim($read_ary[$i])) .
-              '"' . $regs[2];
-        }
-         if (substr ($read_ary[$i], 0, 4) != "a001") {
+                       if (isset($read_ary[$i + 1]) &&
+                         ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", 
+                         $read_ary[$i], $regs)) {
+                        $i ++;
+                        $read_ary[$i] = $regs[1] . '"' . 
+                           addslashes(trim($read_ary[$i])) .
+                           '"' . $regs[2];
+                       }
+         if (substr ($read_ary[$i], 0, $lsid) != $ssid ) {
 
             // Store the raw IMAP reply
             $boxes[$g]["raw"] = $read_ary[$i];
 
             // Store the raw IMAP reply
             $boxes[$g]["raw"] = $read_ary[$i];
             $boxes[$g]["id"] = $g;
 
             /** Now lets get the flags for this mailbox **/
             $boxes[$g]["id"] = $g;
 
             /** Now lets get the flags for this mailbox **/
-            fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\r\n"); 
-            $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
-           // Another workaround for EIMS
-           if (isset($read_mlbx[1]) &&
-               ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", 
-               $read_mlbx[0], $regs)) {
-              $read_mlbx[0] = $regs[1] . '"' . 
-                 addslashes(trim($read_mlbx[1])) .
-                 '"' . $regs[2];
-           }
+            fputs ($imap_stream, sqimap_session_id() . " LIST \"\" \"$mailbox\"\r\n"); 
+            $read_mlbx = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
+            
+                               // Another workaround for EIMS
+                               if (isset($read_mlbx[1]) &&
+                                 ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", 
+                                 $read_mlbx[0], $regs)) {
+                                $read_mlbx[0] = $regs[1] . '"' . 
+                                   addslashes(trim($read_mlbx[1])) .
+                                   '"' . $regs[2];
+                               }
 
             $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+1);
             $flags = substr($flags, 0, strpos($flags, ")"));
 
             $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+1);
             $flags = substr($flags, 0, strpos($flags, ")"));
index 00ca7ef83582f04704bf87e34ea0394fce9b5578..38dd15e4ae9014ad08fa17ad9af7f8e4ccf5dc87 100755 (executable)
@@ -15,8 +15,8 @@
     **  Copies specified messages to specified folder
     ******************************************************************************/
    function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
     **  Copies specified messages to specified folder
     ******************************************************************************/
    function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
-      fputs ($imap_stream, "a001 COPY $start:$end \"$mailbox\"\r\n");
-      $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " COPY $start:$end \"$mailbox\"\r\n");
+      $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
    }
 
    /******************************************************************************
    }
 
    /******************************************************************************
@@ -37,8 +37,8 @@
     **  Sets the specified messages with specified flag
     ******************************************************************************/
    function sqimap_messages_flag ($imap_stream, $start, $end, $flag) {
     **  Sets the specified messages with specified flag
     ******************************************************************************/
    function sqimap_messages_flag ($imap_stream, $start, $end, $flag) {
-      fputs ($imap_stream, "a001 STORE $start:$end +FLAGS (\\$flag)\r\n");
-      $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " STORE $start:$end +FLAGS (\\$flag)\r\n");
+      $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
    }
 
 
    }
 
 
@@ -46,8 +46,8 @@
     **  Remove specified flag from specified messages
     ******************************************************************************/
    function sqimap_messages_remove_flag ($imap_stream, $start, $end, $flag) {
     **  Remove specified flag from specified messages
     ******************************************************************************/
    function sqimap_messages_remove_flag ($imap_stream, $start, $end, $flag) {
-      fputs ($imap_stream, "a001 STORE $start:$end -FLAGS (\\$flag)\r\n");
-      $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " STORE $start:$end -FLAGS (\\$flag)\r\n");
+      $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
    }
 
 
    }
 
 
       }
 
 
       }
 
 
-      $query = "a001 FETCH $msgs_str BODY.PEEK[HEADER.FIELDS (Date To From Cc Subject Message-Id X-Priority Content-Type)]\r\n";
+      $query = sqimap_session_id() . " FETCH $msgs_str BODY.PEEK[HEADER.FIELDS (Date To From Cc Subject Message-Id X-Priority Content-Type)]\r\n";
       fputs ($imap_stream, $query);
       fputs ($imap_stream, $query);
-      $readin_list = sqimap_read_data_list($imap_stream, "a001", true, $response, $message);
+      $readin_list = sqimap_read_data_list($imap_stream, sqimap_session_id(), true, $response, $message);
 
 
       foreach ($readin_list as $r) {
 
 
       foreach ($readin_list as $r) {
       }
       arsort($read_list);
       
       }
       arsort($read_list);
       
-      $query = "a002 FETCH $msgs_str RFC822.SIZE\r\n";
+      $query = sqimap_session_id() . " FETCH $msgs_str RFC822.SIZE\r\n";
       fputs ($imap_stream, $query);
       fputs ($imap_stream, $query);
-      $sizesin_list = sqimap_read_data_list($imap_stream, "a002", true, $response, $message);
+      $sizesin_list = sqimap_read_data_list($imap_stream, sqimap_session_id(), true, $response, $message);
       
       foreach ($sizesin_list as $r) {
          if (!eregi("^\\* ([0-9]+) FETCH", $r[0], $regs)) {
       
       foreach ($sizesin_list as $r) {
          if (!eregi("^\\* ([0-9]+) FETCH", $r[0], $regs)) {
             
          }
          if (trim($date) == "") {
             
          }
          if (trim($date) == "") {
-            fputs($imap_stream, "a002 FETCH $msg_list[$msgi] INTERNALDATE\r\n");
-            $readdate = sqimap_read_data($imap_stream, "a002", true, $response, $message);
+            fputs($imap_stream, sqimap_session_id() . " FETCH $msg_list[$msgi] INTERNALDATE\r\n");
+            $readdate = sqimap_read_data($imap_stream, sqimap_session_id(), true, $response, $message);
             if (eregi(".*INTERNALDATE \"(.*)\".*", $readdate[0], $regs)) {
                $date_list = explode(" ", trim($regs[1]));
                $date_list[0] = str_replace("-", " ", $date_list[0]);
             if (eregi(".*INTERNALDATE \"(.*)\".*", $readdate[0], $regs)) {
                $date_list = explode(" ", trim($regs[1]));
                $date_list[0] = str_replace("-", " ", $date_list[0]);
     **  Returns the flags for the specified messages 
     ******************************************************************************/
    function sqimap_get_flags ($imap_stream, $i) {
     **  Returns the flags for the specified messages 
     ******************************************************************************/
    function sqimap_get_flags ($imap_stream, $i) {
-      fputs ($imap_stream, "a001 FETCH $i:$i FLAGS\r\n");
-      $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " FETCH $i:$i FLAGS\r\n");
+      $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
       if (ereg("FLAGS(.*)", $read[0], $regs))
           return explode(" ", trim(ereg_replace('[\\(\\)\\\\]', '', $regs[1])));
       return Array('None');
       if (ereg("FLAGS(.*)", $read[0], $regs))
           return explode(" ", trim(ereg_replace('[\\(\\)\\\\]', '', $regs[1])));
       return Array('None');
       for ($i = 0; $i < sizeof($msg_list); $i++) {
          $id2index[$msg_list[$i]] = $i;
       }
       for ($i = 0; $i < sizeof($msg_list); $i++) {
          $id2index[$msg_list[$i]] = $i;
       }
-      fputs ($imap_stream, "a001 FETCH $msgs_str FLAGS\r\n");
-      $result_list = sqimap_read_data_list ($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " FETCH $msgs_str FLAGS\r\n");
+      $result_list = sqimap_read_data_list ($imap_stream, sqimap_session_id(), true, $response, $message);
       $result_flags = array();
 
       for ($i = 0; $i < sizeof($result_list); $i++) {
       $result_flags = array();
 
       for ($i = 0; $i < sizeof($result_list); $i++) {
     **  Wrapper function that reformats the header information.
     ******************************************************************************/
    function sqimap_get_message_header ($imap_stream, $id, $mailbox) {
     **  Wrapper function that reformats the header information.
     ******************************************************************************/
    function sqimap_get_message_header ($imap_stream, $id, $mailbox) {
-      fputs ($imap_stream, "a001 FETCH $id:$id BODY[HEADER]\r\n");
-      $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " FETCH $id:$id BODY[HEADER]\r\n");
+      $read = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
      
       $header = sqimap_get_header($imap_stream, $read); 
       $header->id = $id;
      
       $header = sqimap_get_header($imap_stream, $read); 
       $header->id = $id;
index 7efff2d8c2ed56622f16a1b0a97cfaf2aba44755..6180c46732e0988c09246638d85115cb3757af6c 100644 (file)
@@ -20,20 +20,20 @@ function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$colo
    $urlMailbox = urlencode($mailbox);
    
    # Construct the Search QuERY
    $urlMailbox = urlencode($mailbox);
    
    # Construct the Search QuERY
-   
+   $ss = sqimap_session_id();
    if (isset($languages[$squirrelmail_language]["CHARSET"]) && $languages[$squirrelmail_language]["CHARSET"]) {
    if (isset($languages[$squirrelmail_language]["CHARSET"]) && $languages[$squirrelmail_language]["CHARSET"]) {
-      $ss = "a001 SEARCH CHARSET ".$languages[$squirrelmail_language]["CHARSET"]." ALL $search_where \"$search_what\"\r\n";
+      $ss = " SEARCH CHARSET ".$languages[$squirrelmail_language]["CHARSET"]." ALL $search_where \"$search_what\"\r\n";
    } else {
    } else {
-      $ss = "a001 SEARCH ALL $search_where \"$search_what\"\r\n";
+      $ss = " SEARCH ALL $search_where \"$search_what\"\r\n";
    }
    fputs($imapConnection,$ss);
 
    # Read Data Back From IMAP
    }
    fputs($imapConnection,$ss);
 
    # Read Data Back From IMAP
-   $readin = sqimap_read_data ($imapConnection, "a001", false, $result, $message);
+   $readin = sqimap_read_data ($imapConnection, sqimap_session_id(), false, $result, $message);
    if (isset($languages[$squirrelmail_language]["CHARSET"]) && strtolower($result) == "no") { 
    if (isset($languages[$squirrelmail_language]["CHARSET"]) && strtolower($result) == "no") { 
-      $ss = "a001 SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"\r\n";
+      $ss = sqimap_session_id() . " SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"\r\n";
       fputs ($imapConnection, $ss);
       fputs ($imapConnection, $ss);
-      $readin = sqimap_read_data ($imapConnection, "a001", true, $result, $message);
+      $readin = sqimap_read_data ($imapConnection, sqimap_session_id(), true, $result, $message);
    }
    unset($messagelist); $msgs=""; $c = 0;
 
    }
    unset($messagelist); $msgs=""; $c = 0;
 
index 52a452ea6cd11ba6c8381a3971db604f0ba5d849..73360d7f508dd21731f6d2496424be17ce5edabf 100644 (file)
       sqimap_messages_flag ($imap_stream, $header->id, $header->id, "Seen");
       
       $id = $header->id;
       sqimap_messages_flag ($imap_stream, $header->id, $header->id, "Seen");
       
       $id = $header->id;
-      fputs ($imap_stream, "a001 FETCH $id BODYSTRUCTURE\r\n");
+      fputs ($imap_stream, sqimap_session_id() . " FETCH $id BODYSTRUCTURE\r\n");
       //
       // This should use sqimap_read_data instead of reading it itself
       //
       //
       // This should use sqimap_read_data instead of reading it itself
       //
+      $sid = sqimap_session_id();
+      $lsid = strlen( $sid );
       $read = fgets ($imap_stream, 10000);
       $read = fgets ($imap_stream, 10000);
-      $response = substr($read, 0, 4);
       $bodystructure = "";
       $bodystructure = "";
-      while ($response != 'a001' ) && !feof( $imap_stream ) {
+      while( substr($read, 0, $lsid) <> $sid && !feof( $imap_stream ) ) {
          $bodystructure .= $read;
          $read = fgets ($imap_stream, 10000);
          $bodystructure .= $read;
          $read = fgets ($imap_stream, 10000);
-         $response = substr($read, 0, 4);
       }
       $read = $bodystructure;
 
       }
       $read = $bodystructure;
 
       // that it is the first one.  That is usually the case anyway.
       if (!$ent_id) $ent_id = 1;
 
       // that it is the first one.  That is usually the case anyway.
       if (!$ent_id) $ent_id = 1;
 
-      fputs ($imap_stream, "a010 FETCH $id BODY[$ent_id]\r\n");
-      $data = sqimap_read_data ($imap_stream, 'a010', true, $response, $message);
+      fputs ($imap_stream, sqimap_session_id() . " FETCH $id BODY[$ent_id]\r\n");
+      $data = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
       $topline = array_shift($data);
       while (! ereg('\\* [0-9]+ FETCH ', $topline) && $data)
           $topline = array_shift($data);
       $topline = array_shift($data);
       while (! ereg('\\* [0-9]+ FETCH ', $topline) && $data)
           $topline = array_shift($data);
          return $regs[1];
       }
       
          return $regs[1];
       }
       
-      $str = "Body retrieval error.  Please report this bug!\n";
-      $str .= "Response:  $response\n";
-      $str .= "Message:  $message\n";
-      $str .= "FETCH line:  $topline";
-      $str .= "---------------\n$wholemessage";
-      foreach ($data as $d)
-      {
+      $str = "Body retrieval error.  Please report this bug!\n" .
+             "Response:  $response\n" .
+             "Message:  $message\n" .
+             "FETCH line:  $topline" .
+             "---------------\n$wholemessage";
+      foreach ($data as $d) {
           $str .= htmlspecialchars($d) . "\n";
       }
       return $str;
           $str .= htmlspecialchars($d) . "\n";
       }
       return $str;
       // and it would take over 30 seconds to download it.
       set_time_limit(0);
       
       // and it would take over 30 seconds to download it.
       set_time_limit(0);
       
-      fputs ($imap_stream, "a001 FETCH $id BODY[$ent_id]\r\n");
+      fputs ($imap_stream, sqimap_session_id() . " FETCH $id BODY[$ent_id]\r\n");
          $cnt = 0;
          $continue = true;
                $read = fgets ($imap_stream,4096);
          $cnt = 0;
          $continue = true;
                $read = fgets ($imap_stream,4096);
-               // This could be bad -- if the section has 'a001 OK'
+               // This could be bad -- if the section has sqimap_session_id() . ' OK'
                // or similar, it will kill the download.
                // or similar, it will kill the download.
-               while (!ereg("^a001 (OK|BAD|NO)(.*)$", $read, $regs)) {
+               while (!ereg("^" . sqimap_session_id() . " (OK|BAD|NO)(.*)$", $read, $regs)) {
                        if (trim($read) == ")==") {
                                $read1 = $read;
                                $read = fgets ($imap_stream,4096);
                        if (trim($read) == ")==") {
                                $read1 = $read;
                                $read = fgets ($imap_stream,4096);
-                               if (ereg("^a001 (OK|BAD|NO)(.*)$", $read, $regs)) {
+                               if (ereg("^" . sqimap_session_id() . " (OK|BAD|NO)(.*)$", $read, $regs)) {
                                        return;
                                } else {
                                        return;
                                } else {
-                                       echo decodeBody($read1, $encoding);
-                                       echo decodeBody($read, $encoding);
+                                       echo decodeBody($read1, $encoding) . 
+                                            decodeBody($read, $encoding);
                                }
                        } else if ($cnt) {
                                echo decodeBody($read, $encoding);
                                }
                        } else if ($cnt) {
                                echo decodeBody($read, $encoding);