Rollback LTR changes. it will be resubmitted after stable release.
[squirrelmail.git] / functions / imap_general.php
index bcf9b9f828b9109489ca82925cf2ade910ff37eb..4ff96041570d4a2ef5cc928134ec6dc8b146317b 100755 (executable)
@@ -80,10 +80,14 @@ function sqimap_fgets($imap_stream) {
     $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;
@@ -209,6 +213,9 @@ function sqimap_read_data ($imap_stream, $pre, $handle_errors, &$response, &$mes
 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;
        
@@ -279,8 +286,13 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
          // Original IMAP login code
       $query = 'LOGIN "' . quoteIMAP($username) .  '" "' . quoteIMAP($password) . '"';
       $read = sqimap_run_command ($imap_stream, $query, false, $response, $message);
-    } else {
-         // Insert SASL PLAIN code here, if it ever gets implemented
+    } 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 */
@@ -296,8 +308,8 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
                 } 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";
                     }