From 1c72b151600d032fa186f8bbe6190fdcd1710ec6 Mon Sep 17 00:00:00 2001 From: brong Date: Sat, 12 Jan 2002 11:15:12 +0000 Subject: [PATCH] This is a big one - fixes to sqimap_run_command in most uses. Had to add sqimap_run_command_list as well for those list instances. I believe that it's now safe for sqimap_session_id() to return a different ID each time, but haven't yet tested this. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2126 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_general.php | 48 ++++++++++++++++++--------------- functions/imap_mailbox.php | 53 +++++++++++++------------------------ functions/imap_messages.php | 18 +++++-------- functions/imap_search.php | 16 +++++------ functions/mime.php | 12 +++------ 5 files changed, 61 insertions(+), 86 deletions(-) diff --git a/functions/imap_general.php b/functions/imap_general.php index 10d6efe8..ccec8ba1 100755 --- a/functions/imap_general.php +++ b/functions/imap_general.php @@ -38,8 +38,14 @@ function sqimap_session_id() { ** to allow proper session number handling. ******************************************************************************/ +function sqimap_run_command_list ($imap_stream, $query, $handle_errors, &$response, &$message) { + fputs ($imap_stream, sqimap_session_id() . ' ' . $query . "\r\n"); + $read = sqimap_read_data_list ($imap_stream, sqimap_session_id(), $handle_errors, $response, $message); + return $read; +} + function sqimap_run_command ($imap_stream, $query, $handle_errors, &$response, &$message) { - fputs ($imap_stream, sqimap_session_id() . $query . "\r\n"); + fputs ($imap_stream, sqimap_session_id() . ' ' . $query . "\r\n"); $read = sqimap_read_data ($imap_stream, sqimap_session_id(), $handle_errors, $response, $message); return $read; } @@ -180,9 +186,8 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $ exit; } - fputs ($imap_stream, sqimap_session_id() . ' LOGIN "' . quoteIMAP($username) . - '" "' . quoteIMAP($password) . "\"\r\n"); - $read = sqimap_read_data ($imap_stream, sqimap_session_id(), false, $response, $message); + $query = 'LOGIN "' . quoteIMAP($username) . '" "' . quoteIMAP($password) . '"'; + $read = sqimap_run_command ($imap_stream, $query, false, $response, $message); /** If the connection was not successful, lets see why **/ if ($response != 'OK') { @@ -203,14 +208,16 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $ } exit; } else { - // If the user does not log in with the correct - // username and password it is not possible to get the - // correct locale from the user's preferences. - // Therefore, apply the same hack as on the login - // screen. + /* If the user does not log in with the correct + * username and password it is not possible to get the + * correct locale from the user's preferences. + * Therefore, apply the same hack as on the login + * screen. + */ - // $squirrelmail_language is set by a cookie when - // the user selects language and logs out + /* $squirrelmail_language is set by a cookie when + * the user selects language and logs out + */ set_up_language($squirrelmail_language, true); @@ -232,16 +239,16 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $ * Simply logs out the imap session */ function sqimap_logout ($imap_stream) { - fputs ($imap_stream, sqimap_session_id() . " LOGOUT\r\n"); + /* Logout is not valid until the server returns 'BYE' */ + sqimap_run_command($imap_stream, 'LOGOUT', false, $response, $message); } function sqimap_capability($imap_stream, $capability) { global $sqimap_capabilities; if (!is_array($sqimap_capabilities)) { - fputs ($imap_stream, sqimap_session_id() . " CAPABILITY\r\n"); - $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $a, $b); - + $read = sqimap_run_command($imap_stream, 'CAPABILITY', true, $a, $b); + $c = explode(' ', $read[0]); for ($i=2; $i < count($c); $i++) { $cap_list = explode('=', $c[$i]); @@ -280,8 +287,7 @@ function sqimap_get_delimiter ($imap_stream = false) { OS: * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES) OS: We want to lookup all personal NAMESPACES... */ - fputs ($imap_stream, sqimap_session_id() . " NAMESPACE\r\n"); - $read = sqimap_read_data($imap_stream, sqimap_session_id(), true, $a, $b); + $read = sqimap_run_command($imap_stream, 'NAMESPACE', true, $a, $b); if (eregi('\\* NAMESPACE +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL)', $read[0], $data)) { if (eregi('^\\( *\\((.*)\\) *\\)', $data[1], $data2)) { $pn = $data2[1]; @@ -313,8 +319,7 @@ function sqimap_get_delimiter ($imap_stream = false) { */ function sqimap_get_num_messages ($imap_stream, $mailbox) { - fputs ($imap_stream, sqimap_session_id() . " EXAMINE \"$mailbox\"\r\n"); - $read_ary = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $result, $message); + $read_ary = sqimap_run_command ($imap_stream, " EXAMINE \"$mailbox\"", true, $result, $message); for ($i = 0; $i < count($read_ary); $i++) { if (ereg("[^ ]+ +([^ ]+) +EXISTS", $read_ary[$i], $regs)) { return $regs[1]; @@ -382,8 +387,7 @@ function sqimap_find_displayable_name ($string) { */ function sqimap_unseen_messages ($imap_stream, $mailbox) { //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); + $read_ary = sqimap_run_command ($imap_stream, " STATUS \"$mailbox\" (UNSEEN)", true, $result, $message); ereg("UNSEEN ([0-9]+)", $read_ary[0], $regs); return $regs[1]; } @@ -394,7 +398,7 @@ function sqimap_unseen_messages ($imap_stream, $mailbox) { */ function sqimap_append ($imap_stream, $sent_folder, $length) { fputs ($imap_stream, sqimap_session_id() . " APPEND \"$sent_folder\" (\\Seen) \{$length}\r\n"); - $tmp = fgets ($imap_stream, 1024); + $tmp = fgets ($imap_stream, 1024); } function sqimap_append_done ($imap_stream) { diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index 0a5e9b8a..781c7eb0 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -16,9 +16,8 @@ *************************/ function sqimap_mailbox_expunge ($imap_stream, $mailbox,$handle_errors = true) { - fputs ($imap_stream, sqimap_session_id() . " EXPUNGE\r\n"); - $read = sqimap_read_data($imap_stream, sqimap_session_id(), - $handle_errors, $response, $message); + $read = sqimap_run_command($imap_stream, 'EXPUNGE', + $handle_errors, $response, $message); } @@ -30,9 +29,8 @@ function sqimap_mailbox_exists ($imap_stream, $mailbox) if (! isset($mailbox)) { return false; } - fputs ($imap_stream, sqimap_session_id() . " LIST \"\" \"$mailbox\"\r\n"); - $mbx = sqimap_read_data($imap_stream, sqimap_session_id(), - true, $response, $message); + $mbx = sqimap_run_command($imap_stream, "LIST \"\" \"$mailbox\"", + true, $response, $message); return isset($mbx[0]); } @@ -48,9 +46,8 @@ function sqimap_mailbox_select ($imap_stream, $mailbox, return; } - fputs ($imap_stream, sqimap_session_id() . " SELECT \"$mailbox\"\r\n"); - $read = sqimap_read_data($imap_stream, sqimap_session_id(), - true, $response, $message); + $read = sqimap_run_command($imap_stream, "SELECT \"$mailbox\"", + true, $response, $message); if ($recent) { for ($i=0; $iid = $id; diff --git a/functions/imap_search.php b/functions/imap_search.php index 25899ebd..96cb7bb7 100644 --- a/functions/imap_search.php +++ b/functions/imap_search.php @@ -25,24 +25,20 @@ function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$colo $pos = $search_position; $urlMailbox = urlencode($mailbox); - $isid = sqimap_session_id(); /* Construct the Search QuERY */ - $ss = $isid; if (isset($languages[$squirrelmail_language]['CHARSET']) && $languages[$squirrelmail_language]['CHARSET']) { - $ss .= " 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\""; } else { - $ss .= " SEARCH ALL $search_where \"$search_what\"\r\n"; + $ss .= "SEARCH ALL $search_where \"$search_what\""; } - fputs($imapConnection,$ss); /* Read Data Back From IMAP */ - $readin = sqimap_read_data ($imapConnection, $isid, false, $result, $message); + $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message); if (isset($languages[$squirrelmail_language]['CHARSET']) && strtolower($result) == 'no') { - $ss = $isid . " SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\"\r\n"; - fputs ($imapConnection, $ss); - $readin = sqimap_read_data ($imapConnection, $isid, true, $result, $message); + $ss = "SEARCH CHARSET \"US-ASCII\" ALL $search_where \"$search_what\""; + $readin = sqimap_run_command ($imapConnection, $ss, true, $result, $message); } unset($messagelist); $msgs=""; $c = 0; @@ -165,4 +161,4 @@ function sqimap_search($imapConnection,$search_where,$search_what,$mailbox,$colo } } -?> \ No newline at end of file +?> diff --git a/functions/mime.php b/functions/mime.php index 0958e871..b165bd28 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -376,9 +376,7 @@ function mime_fetch_body ($imap_stream, $id, $ent_id ) { // that it is the first one. That is usually the case anyway. if (!$ent_id) $ent_id = 1; - $sid = sqimap_session_id(); - fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id]\r\n"); - $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message); + $data = sqimap_run_command ($imap_stream, " FETCH $id BODY[$ent_id]", true, $response, $message); $topline = array_shift($data); while (! ereg('\\* [0-9]+ FETCH ', $topline) && $data) $topline = array_shift($data); @@ -390,8 +388,7 @@ function mime_fetch_body ($imap_stream, $id, $ent_id ) { in order to parse html messages. Let's get them here. */ if ( $ret{0} == '<' ) { - fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id.MIME]\r\n"); - $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message); + $data = sqimap_run_command ($imap_stream, "FETCH $id BODY[$ent_id.MIME]", true, $response, $message); $base = ''; $k = 10; foreach( $data as $d ) { @@ -436,8 +433,7 @@ function mime_fetch_body ($imap_stream, $id, $ent_id ) { _("Message:") . " $message
" . _("FETCH line:") . " $topline
"; - fputs ($imap_stream, "$sid FETCH $passed_id BODY[]\r\n"); - $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message); + $data = sqimap_run_command ($imap_stream, "FETCH $passed_id BODY[]", true, $response, $message); array_shift($data); $wholemessage = implode('', $data); @@ -1218,4 +1214,4 @@ function find_ent_id( $id, $message ) { return( $ret ); } -?> \ No newline at end of file +?> -- 2.25.1