/**
* imap_general.php
*
- * Copyright (c) 1999-2003 The SquirrelMail Project Team
+ * 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.
*
- * $Id$
+ * @version $Id$
* @package squirrelmail
+ * @subpackage imap
*/
/** Includes.. */
require_once(SM_PATH . 'functions/auth.php');
-global $sqimap_session_id;
-$sqimap_session_id = 1;
-
/**
* Generates a new session ID by incrementing the last one used;
* this ensures that each command has a unique ID.
* @param bool unique_id
* @return string IMAP session id of the form 'A000'.
*/
-function sqimap_session_id($unique_id = false) {
- global $data_dir, $username, $sqimap_session_id;
+function sqimap_session_id($unique_id = FALSE) {
+ static $sqimap_session_id = 1;
+
if (!$unique_id) {
return( sprintf("A%03d", $sqimap_session_id++) );
} else {
$read = sqimap_read_data ($imap_stream, $tag, $handle_errors, $response,
$message, $query,$filter,$outputstream,$no_return);
+ if (empty($read)) { //Imap server dropped its connection
+ $response = '';
+ $message = '';
+ return false;
+ }
/* retrieve the response and the message */
$response = $response[$tag];
$message = $message[$tag];
-
+
if (!empty($read[$tag])) {
return $read[$tag][0];
} else {
* 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
- * @param string message the error message
+ * @param string message_title optional message title
+ * @param string message optional error message
+ * @param string $link an optional link to try again
* @return void
*/
-function sqimap_error_box($title, $query = '', $message_title = '', $message = '')
+function sqimap_error_box($title, $query = '', $message_title = '', $message = '', $link = '')
{
global $color, $squirrelmail_language;
if ($message != '')
$string .= htmlspecialchars($message);
$string .= "</font><br>\n";
+ if ($link != '')
+ $string .= $link;
error_box($string,$color);
}
$read = '';
if (!is_array($message)) $message = array();
if (!is_array($response)) $response = array();
+ $aResponse = '';
$resultlist = array();
$data = array();
$read = sqimap_fgets($imap_stream);
/* error processing in case $read is false */
if ($read === false) {
unset($data);
- sqimap_error_box(_("ERROR : Connection dropped by imap-server."), $query);
- exit;
+ if ($handle_errors) {
+ sqimap_error_box(_("ERROR : Connection dropped by imap-server."), $query);
+ exit;
+ }
}
/* Set $resultlist array */
/* Return result or handle errors */
if ($handle_errors == false) {
return $aResponse;
- return( $resultlist ); //?? Why this?
}
switch ($response[$tag]) {
case 'OK':
function sqimap_create_stream($server,$port,$tls=false) {
global $username, $use_imap_tls;
- if ($use_imap_tls == true) {
+ if ($tls == true) {
if ((check_php_version(4,3)) and (extension_loaded('openssl'))) {
/* Use TLS by prefixing "tls://" to the hostname */
- $server = 'tls://' . $imap_server_address;
+ $server = 'tls://' . $server;
} else {
require_once(SM_PATH . 'functions/display_messages.php');
$string = "Unable to connect to IMAP server!<br>TLS is enabled, but this " .
for ($i=2; $i < count($c); $i++) {
$cap_list = explode('=', $c[$i]);
if (isset($cap_list[1])) {
+ // FIX ME. capabilities can occure multiple times.
+ // THREAD=REFERENCES THREAD=ORDEREDSUBJECT
$sqimap_capabilities[$cap_list[0]] = $cap_list[1];
} else {
$sqimap_capabilities[$cap_list[0]] = TRUE;