fix for unsafe images links. Somehow the wrong were in de view unsafe images
[squirrelmail.git] / functions / imap_general.php
index ba53e1b933b65ff0e1a735dd236c47b7b1a3a311..4ff96041570d4a2ef5cc928134ec6dc8b146317b 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * 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.
@@ -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;
        
@@ -238,7 +245,7 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
     $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";
@@ -275,11 +282,18 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
                $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') {
@@ -294,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";
                     }