From 180aa6d7967f215ec4f3ba2e4658d02c08a5f53c Mon Sep 17 00:00:00 2001 From: philippe_mingo Date: Thu, 4 Oct 2001 14:31:57 +0000 Subject: [PATCH] Use sqimap_session_id instead of axxxx for imap connections. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1543 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_general.php | 35 ++++++++------ functions/imap_mailbox.php | 91 +++++++++++++++++++------------------ functions/imap_messages.php | 36 +++++++-------- functions/imap_search.php | 12 ++--- functions/mime.php | 37 ++++++++------- 5 files changed, 111 insertions(+), 100 deletions(-) diff --git a/functions/imap_general.php b/functions/imap_general.php index 8a731914..f4acc08c 100755 --- a/functions/imap_general.php +++ b/functions/imap_general.php @@ -14,6 +14,15 @@ 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, @@ -156,9 +165,9 @@ exit; } - fputs ($imap_stream, "a001 LOGIN \"" . quoteIMAP($username) . + fputs ($imap_stream, sqimap_session_id() . ' LOGIN "' . quoteIMAP($username) . '" "' . 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") { @@ -238,7 +247,7 @@ ** 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) { @@ -246,8 +255,8 @@ 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++) { @@ -284,8 +293,8 @@ 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]; @@ -316,8 +325,8 @@ ** 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]; @@ -377,9 +386,9 @@ ** 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]; } @@ -389,7 +398,7 @@ ** 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); } diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index 0bdc5566..9aa78256 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -15,8 +15,8 @@ ** 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; - 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]); } @@ -40,8 +40,8 @@ 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; $iid = $id; diff --git a/functions/imap_search.php b/functions/imap_search.php index 7efff2d8..6180c467 100644 --- a/functions/imap_search.php +++ b/functions/imap_search.php @@ -20,20 +20,20 @@ function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$colo $urlMailbox = urlencode($mailbox); # Construct the Search QuERY - + $ss = sqimap_session_id(); 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 { - $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 - $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") { - $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); - $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; diff --git a/functions/mime.php b/functions/mime.php index 52a452ea..73360d7f 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -57,17 +57,17 @@ 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 // + $sid = sqimap_session_id(); + $lsid = strlen( $sid ); $read = fgets ($imap_stream, 10000); - $response = substr($read, 0, 4); $bodystructure = ""; - while ($response != 'a001' ) && !feof( $imap_stream ) { + while( substr($read, 0, $lsid) <> $sid && !feof( $imap_stream ) ) { $bodystructure .= $read; $read = fgets ($imap_stream, 10000); - $response = substr($read, 0, 4); } $read = $bodystructure; @@ -379,8 +379,8 @@ // 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); @@ -393,13 +393,12 @@ 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; @@ -414,21 +413,21 @@ // 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); - // 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. - 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 (ereg("^a001 (OK|BAD|NO)(.*)$", $read, $regs)) { + if (ereg("^" . sqimap_session_id() . " (OK|BAD|NO)(.*)$", $read, $regs)) { return; } else { - echo decodeBody($read1, $encoding); - echo decodeBody($read, $encoding); + echo decodeBody($read1, $encoding) . + decodeBody($read, $encoding); } } else if ($cnt) { echo decodeBody($read, $encoding); -- 2.25.1