X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fimap_general.php;h=1373a20e3d7cd2756bee325e89425d833f748ce2;hp=511161bf46572ea0d467551a414b9332447b7e6d;hb=b2e8c7a0f6ef359d6fbd7fc597fb0f728d06a752;hpb=d5c472f16d5aa03b3f69dc1e985299cd53c2fb77
diff --git a/functions/imap_general.php b/functions/imap_general.php
index 511161bf..1373a20e 100755
--- a/functions/imap_general.php
+++ b/functions/imap_general.php
@@ -3,11 +3,10 @@
/**
* imap_general.php
*
- * Copyright (c) 1999-2004 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
- * This implements all functions that do general imap functions.
+ * This implements all functions that do general IMAP functions.
*
+ * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
* @package squirrelmail
* @subpackage imap
@@ -16,13 +15,17 @@
/** Includes.. */
require_once(SM_PATH . 'functions/page_header.php');
require_once(SM_PATH . 'functions/auth.php');
+include_once(SM_PATH . 'functions/rfc822address.php');
/**
* Generates a new session ID by incrementing the last one used;
* this ensures that each command has a unique ID.
- * @param bool unique_id
+ * @param bool $unique_id (since 1.3.0) controls use of unique
+ * identifiers/message sequence numbers in IMAP commands. See IMAP
+ * rfc 'UID command' chapter.
* @return string IMAP session id of the form 'A000'.
+ * @since 1.2.0
*/
function sqimap_session_id($unique_id = FALSE) {
static $sqimap_session_id = 1;
@@ -37,6 +40,15 @@ function sqimap_session_id($unique_id = FALSE) {
/**
* Both send a command and accept the result from the command.
* This is to allow proper session number handling.
+ * @param stream $imap_stream imap connection resource
+ * @param string $query imap command
+ * @param boolean $handle_errors see sqimap_retrieve_imap_response()
+ * @param array $response
+ * @param array $message
+ * @param boolean $unique_id (since 1.3.0) see sqimap_session_id().
+ * @return mixed returns false on imap error. displays error message
+ * if imap stream is not available.
+ * @since 1.2.3
*/
function sqimap_run_command_list ($imap_stream, $query, $handle_errors, &$response, &$message, $unique_id = false) {
if ($imap_stream) {
@@ -54,13 +66,27 @@ function sqimap_run_command_list ($imap_stream, $query, $handle_errors, &$respon
set_up_language($squirrelmail_language);
require_once(SM_PATH . 'functions/display_messages.php');
$string = "\n" .
- _("ERROR : No available imapstream.") .
+ _("ERROR: No available IMAP stream.") .
"\n";
error_box($string,$color);
return false;
}
}
+/**
+ * @param stream $imap_stream imap connection resource
+ * @param string $query imap command
+ * @param boolean $handle_errors see sqimap_retrieve_imap_response()
+ * @param array $response empty string, if return = false
+ * @param array $message empty string, if return = false
+ * @param boolean $unique_id (since 1.3.0) see sqimap_session_id()
+ * @param boolean $filter (since 1.4.1 and 1.5.0) see sqimap_fread()
+ * @param mixed $outputstream (since 1.4.1 and 1.5.0) see sqimap_fread()
+ * @param boolean $no_return (since 1.4.1 and 1.5.0) see sqimap_fread()
+ * @return mixed returns false on imap error. displays error message
+ * if imap stream is not available.
+ * @since 1.2.3
+ */
function sqimap_run_command ($imap_stream, $query, $handle_errors, &$response,
&$message, $unique_id = false,$filter=false,
$outputstream=false,$no_return=false) {
@@ -72,7 +98,7 @@ function sqimap_run_command ($imap_stream, $query, $handle_errors, &$response,
$read = sqimap_read_data ($imap_stream, $tag, $handle_errors, $response,
$message, $query,$filter,$outputstream,$no_return);
- if (empty($read)) { //Imap server dropped its connection
+ if (empty($read)) { //IMAP server dropped its connection
$response = '';
$message = '';
return false;
@@ -91,13 +117,20 @@ function sqimap_run_command ($imap_stream, $query, $handle_errors, &$response,
set_up_language($squirrelmail_language);
require_once(SM_PATH . 'functions/display_messages.php');
$string = "\n" .
- _("ERROR : No available imapstream.") .
+ _("ERROR: No available IMAP stream.") .
"\n";
error_box($string,$color);
return false;
}
}
+/**
+ * @param mixed $new_query
+ * @param string $tag
+ * @param array $aQuery
+ * @param boolean $unique_id see sqimap_session_id()
+ * @since 1.5.0
+ */
function sqimap_prepare_pipelined_query($new_query,&$tag,&$aQuery,$unique_id) {
$sid = sqimap_session_id($unique_id);
$tag_uid_a = explode(' ',trim($sid));
@@ -106,15 +139,27 @@ function sqimap_prepare_pipelined_query($new_query,&$tag,&$aQuery,$unique_id) {
$aQuery[$tag] = $query;
}
+/**
+ * @param stream $imap_stream imap stream
+ * @param array $aQueryList
+ * @param boolean $handle_errors
+ * @param array $aServerResponse
+ * @param array $aServerMessage
+ * @param boolean $unique_id see sqimap_session_id()
+ * @param boolean $filter see sqimap_fread()
+ * @param mixed $outputstream see sqimap_fread()
+ * @param boolean $no_return see sqimap_fread()
+ * @since 1.5.0
+ */
function sqimap_run_pipelined_command ($imap_stream, $aQueryList, $handle_errors,
&$aServerResponse, &$aServerMessage, $unique_id = false,
$filter=false,$outputstream=false,$no_return=false) {
$aResponse = false;
/*
- Do not fire all calls at once to the imap-server but split the calls up
+ Do not fire all calls at once to the IMAP server but split the calls up
in portions of $iChunkSize. If we do not do that I think we misbehave as
- IMAP client or should handle BYE calls if the IMAP-server drops the
+ IMAP client or should handle BYE calls if the IMAP server drops the
connection because the number of queries is to large. This isn't tested
but a wild guess how it could work in the field.
@@ -170,10 +215,11 @@ function sqimap_run_pipelined_command ($imap_stream, $aQueryList, $handle_errors
}
/**
- * Custom fgets function: gets a line from the IMAP-server,
+ * Custom fgets function: gets a line from the IMAP server,
* no matter how big it may be.
- * @param stream imap_stream the stream to read from
+ * @param stream $imap_stream the stream to read from
* @return string a line
+ * @since 1.2.8
*/
function sqimap_fgets($imap_stream) {
$read = '';
@@ -195,6 +241,15 @@ function sqimap_fgets($imap_stream) {
return $results;
}
+/**
+ * @param stream $imap_stream
+ * @param integer $iSize
+ * @param boolean $filter
+ * @param mixed $outputstream stream or 'php://stdout' string
+ * @param boolean $no_return controls data returned by function
+ * @return string
+ * @since 1.4.1
+ */
function sqimap_fread($imap_stream,$iSize,$filter=false,
$outputstream=false, $no_return=false) {
if (!$filter || !$outputstream) {
@@ -219,20 +274,20 @@ function sqimap_fread($imap_stream,$iSize,$filter=false,
if ($iRemaining < $iBufferSize) {
$iBufferSize = $iRemaining;
}
- if (!$sRead) {
+ if ($sRead == '') {
$results = false;
break;
}
- if ($sReadRem) {
+ if ($sReadRem != '') {
$sRead = $sReadRem . $sRead;
$sReadRem = '';
}
- if ($filter && $sRead) {
+ if ($filter && $sRead != '') {
// in case the filter is base64 decoding we return a remainder
$sReadRem = $filter($sRead);
}
- if ($outputstream && $sRead) {
+ if ($outputstream && $sRead != '') {
if (is_resource($outputstream)) {
fwrite($outputstream,$sRead);
} else if ($outputstream == 'php://stdout') {
@@ -251,7 +306,14 @@ function sqimap_fread($imap_stream,$iSize,$filter=false,
/**
* Obsolete function, inform plugins that use it
- * @deprecated use sqimap_run_command or sqimap_run_command_list instead
+ * @param stream $imap_stream
+ * @param string $tag
+ * @param boolean $handle_errors
+ * @param array $response
+ * @param array $message
+ * @param string $query
+ * @since 1.1.3
+ * @deprecated (since 1.5.0) use sqimap_run_command or sqimap_run_command_list instead
*/
function sqimap_read_data_list($imap_stream, $tag, $handle_errors,
&$response, &$message, $query = '') {
@@ -259,7 +321,7 @@ function sqimap_read_data_list($imap_stream, $tag, $handle_errors,
set_up_language($squirrelmail_language);
require_once(SM_PATH . 'functions/display_messages.php');
$string = "\n" .
- _("ERROR : Bad function call.") .
+ _("ERROR: Bad function call.") .
"
\n" .
_("Reason:") . ' '.
'There is a plugin installed which make use of the
' .
@@ -274,13 +336,14 @@ function sqimap_read_data_list($imap_stream, $tag, $handle_errors,
}
/**
- * Function to display an error related to an IMAP-query.
+ * Function to display an error related to an IMAP query.
* @param string title the caption of the error box
* @param string query the query that went wrong
* @param string message_title optional message title
* @param string message optional error message
* @param string $link an optional link to try again
* @return void
+ * @since 1.5.0
*/
function sqimap_error_box($title, $query = '', $message_title = '', $message = '', $link = '')
{
@@ -308,6 +371,16 @@ function sqimap_error_box($title, $query = '', $message_title = '', $message = '
* 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,
* the errors will be sent back through $response and $message.
+ * @param stream $imap_stream imap stream
+ * @param string $tag
+ * @param boolean $handle_errors handle errors internally or send them in $response and $message.
+ * @param array $response
+ * @param array $message
+ * @param string $query command that can be printed if something fails
+ * @param boolean $filter see sqimap_fread()
+ * @param mixed $outputstream see sqimap_fread()
+ * @param boolean $no_return see sqimap_fread()
+ * @since 1.5.0
*/
function sqimap_retrieve_imap_response($imap_stream, $tag, $handle_errors,
&$response, &$message, $query = '',
@@ -319,8 +392,14 @@ function sqimap_retrieve_imap_response($imap_stream, $tag, $handle_errors,
$aResponse = '';
$resultlist = array();
$data = array();
+ $sCommand = '';
+ if (preg_match("/^(\w+)\s*/",$query,$aMatch)) {
+ $sCommand = strtoupper($aMatch[1]);
+ } else {
+ // error reporting (shouldn't happen)
+ }
$read = sqimap_fgets($imap_stream);
- $i = $k = 0;
+ $i = 0;
while ($read) {
$char = $read{0};
switch ($char)
@@ -375,14 +454,14 @@ function sqimap_retrieve_imap_response($imap_stream, $tag, $handle_errors,
}
$read = sqimap_fgets($imap_stream);
if ($read === false) { /* error */
- break 3; /* switch switch while */
+ break 2; /* switch while */
}
break;
} // end case $tag{0}
case '*':
{
- if (preg_match('/^\*\s\d+\sFETCH/',$read)) {
+ if (($sCommand == "FETCH" || $sCommand == "STORE") && preg_match('/^\*\s\d+\sFETCH/',$read)) {
/* check for literal */
$s = substr($read,-3);
$fetch_data = array();
@@ -476,12 +555,12 @@ function sqimap_retrieve_imap_response($imap_stream, $tag, $handle_errors,
if (!$handle_errors) {
$query = '';
}
- sqimap_error_box(_("ERROR : Imap server closed the connection."), $query, _("Server responded:"),$sResponse);
+ sqimap_error_box(_("ERROR: IMAP server closed the connection."), $query, _("Server responded:"),$sResponse);
echo '