/**
** imap.php
**
** This implements all functions that do general imap functions.
**/
/******************************************************************************
** 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
******************************************************************************/
function sqimap_read_data ($imap_stream, $pre, $handle_errors, $response, $message) {
global $color;
$read = fgets ($imap_stream, 1024);
$counter = 0;
while ((substr($read, 0, strlen("$pre OK")) != "$pre OK") &&
(substr($read, 0, strlen("$pre BAD")) != "$pre BAD") &&
(substr($read, 0, strlen("$pre NO")) != "$pre NO")) {
$data[$counter] = $read;
$read = fgets ($imap_stream, 1024);
$counter++;
}
if (substr($read, 0, strlen("$pre OK")) == "$pre OK") {
$response = "OK";
$message = trim(substr($read, strlen("$pre OK"), strlen($read)));
}
else if (substr($read, 0, strlen("$pre BAD")) == "$pre BAD") {
$response = "BAD";
$message = trim(substr($read, strlen("$pre BAD"), strlen($read)));
}
else {
$response = "NO";
$message = trim(substr($read, strlen("$pre NO"), strlen($read)));
}
if ($handle_errors == true) {
if ($response == "NO") {
echo "
";
echo _("ERROR : Could not complete request.");
echo "
";
echo _("Reason Given: ");
echo "$message
";
exit;
} else if ($response == "BAD") {
echo "
";
echo _("ERROR : Bad or malformed request.");
echo "
";
echo _("Server responded: ");
echo "$message
";
exit;
}
}
return $data;
}
/******************************************************************************
** Logs the user into the imap server. If $hide is set, no error messages
** will be displayed. This function returns the imap connection handle.
******************************************************************************/
function sqimap_login ($username, $password, $imap_server_address, $imap_port, $hide) {
global $color;
$imap_stream = fsockopen ($imap_server_address, $imap_port, &$error_number, &$error_string);
$server_info = fgets ($imap_stream, 1024);
/** Do some error correction **/
if (!$imap_stream) {
if (!$hide) {
echo "Error connecting to IMAP server: $imap_server_address.
\r\n";
echo "$error_number : $error_string
\r\n";
}
exit;
}
fputs ($imap_stream, "a001 LOGIN \"$username\" \"$password\"\r\n");
$read = fgets ($imap_stream, 1024);
/** If the connection was not successful, lets see why **/
if (substr($read, 0, 7) != "a001 OK") {
if (!$hide) {
if (substr($read, 0, 8) == "a001 BAD") {
echo "Bad request: $read
\r\n";
exit;
} else if (substr($read, 0, 7) == "a001 NO") {
?>
|
echo _("Click here to try again") ?> |