/**
* imap_general.php
*
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Copyright (c) 1999-2003 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.
$read = '';
$buffer = 4096;
$results = '';
- while (strpos($read, "\n") === false) {
+ $offset = 0;
+ while (strpos($results, "\r\n", $offset) === false) {
if (!($read = fgets($imap_stream, $buffer))) {
break;
}
+ if ( $results != '' ) {
+ $offset = strlen($results) - 1;
+ }
$results .= $read;
}
return $results;
function sqimap_login ($username, $password, $imap_server_address, $imap_port, $hide) {
global $color, $squirrelmail_language, $onetimepad, $use_imap_tls, $imap_auth_mech;
+ if (!isset($onetimepad) || empty($onetimepad)) {
+ sqgetglobalvar('onetimepad' , $onetimepad , SQ_SESSION );
+ }
$imap_server_address = sqimap_get_user_server($imap_server_address, $username);
$host=$imap_server_address;
$password = OneTimePadDecrypt($password, $onetimepad);
if (($imap_auth_mech == 'cram-md5') OR ($imap_auth_mech == 'digest-md5')) {
- // We're using some sort of authentication OTHER than plain
+ // We're using some sort of authentication OTHER than plain or login
$tag=sqimap_session_id(false);
if ($imap_auth_mech == 'digest-md5') {
$query = $tag . " AUTHENTICATE DIGEST-MD5\r\n";
$message='IMAP server does not appear to support the authentication method selected.';
$message .= ' Please contact your system administrator.';
}
- } else {
- // Original PLAIN login code
+ } elseif ($imap_auth_mech == 'login') {
+ // Original IMAP login code
$query = 'LOGIN "' . quoteIMAP($username) . '" "' . quoteIMAP($password) . '"';
$read = sqimap_run_command ($imap_stream, $query, false, $response, $message);
- }
+ } elseif ($imap_auth_mech == 'plain') {
+ /* Replace this with SASL PLAIN if it ever gets implemented */
+ $response="BAD";
+ $message='SquirrelMail does not support SASL PLAIN yet. Rerun conf.pl and use login instead.';
+ } else {
+ $response="BAD";
+ $message="Internal SquirrelMail error - unknown IMAP authentication method chosen. Please contact the developers.";
+ }
/* If the connection was not successful, lets see why */
if ($response != 'OK') {
} else {
$string = sprintf (_("Unknown error: %s") . "<br>\n", $message);
}
- $string .= '<br>' . _("Read data:") . "<br>\n";
- if (is_array($read)) {
+ if (isset($read) && is_array($read)) {
+ $string .= '<br>' . _("Read data:") . "<br>\n";
foreach ($read as $line) {
$string .= htmlspecialchars($line) . "<br>\n";
}