- $this->ERROR = _("POP3 pass:") . ' ' . _("Authentication failed...
[squirrelmail.git] / plugins / mail_fetch / class.POP3.php
index ba8cd77b613e74e19409c6ec417f2422601c5ae3..28daed7c090574dd98ef07a9d34734ae96cc58da 100644 (file)
@@ -1,14 +1,28 @@
-<?
-
-/*
-    class.POP3.php3 v1.0    99/03/24 CDI cdi@thewebmasters.net
-    Copyright (c) 1999 - CDI (cdi@thewebmasters.net) All Rights Reserved
-    Modified by Philippe Mingo 2001 mingo@rotedic.com
-    An RFC 1939 compliant wrapper class for the POP3 protocol.
-*/
-
+<?php
+
+/**
+ * mail_fetch/class.POP3.php
+ *
+ * Copyright (c) 1999 CDI (cdi@thewebmasters.net) All Rights Reserved
+ * Modified by Philippe Mingo 2001 mingo@rotedic.com
+ * An RFC 1939 compliant wrapper class for the POP3 protocol.
+ *
+ * POP3 class
+ *
+ * @copyright &copy; 1999-2005 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @version $Id$
+ * @package plugins
+ * @subpackage mail_fetch
+ */
+
+/**
+ * This is the POP3 class - DOCUMENT ME
+ * @package plugins
+ * @subpackage mail_fetch
+ */
 class POP3 {
-    var $ERROR      = "";       //  Error string.
+    var $ERROR      = '';       //  Error string.
 
     var $TIMEOUT    = 60;       //  Default timeout before giving up on a
                                 //  network operation.
@@ -19,26 +33,23 @@ class POP3 {
                                 //  Per RFC 1939 the returned line a POP3
                                 //  server can send is 512 bytes.
 
-    var $FP         = "";       //  The connection to the server's
+    var $FP         = '';       //  The connection to the server's
                                 //  file descriptor
 
-    var $MAILSERVER = "";       // Set this to hard code the server name
+    var $MAILSERVER = '';       // Set this to hard code the server name
 
-    var $DEBUG      = false;    // set to true to echo pop3
+    var $DEBUG      = FALSE;    // set to true to echo pop3
                                 // commands and responses to error_log
                                 // this WILL log passwords!
 
-    var $BANNER     = "";       //  Holds the banner returned by the
+    var $BANNER     = '';       //  Holds the banner returned by the
                                 //  pop server - used for apop()
 
-    var $RFC1939    = true;     //  Set by noop(). See rfc1939.txt
-                                //
-
-    var $ALLOWAPOP  = false;    //  Allow or disallow apop()
+    var $ALLOWAPOP  = FALSE;    //  Allow or disallow apop()
                                 //  This must be set to true
                                 //  manually
 
-    function POP3 ( $server = "", $timeout = "" ) {
+    function POP3 ( $server = '', $timeout = '' ) {
         settype($this->BUFFER,"integer");
         if( !empty($server) ) {
             // Do not allow programs to alter MAILSERVER
@@ -50,13 +61,15 @@ class POP3 {
         if(!empty($timeout)) {
             settype($timeout,"integer");
             $this->TIMEOUT = $timeout;
-            set_time_limit($timeout);
+            if (!ini_get('safe_mode'))
+                set_time_limit($timeout);
         }
         return true;
     }
 
     function update_timer () {
-        set_time_limit($this->TIMEOUT);
+        if (!ini_get('safe_mode'))
+            set_time_limit($this->TIMEOUT);
         return true;
     }
 
@@ -66,6 +79,7 @@ class POP3 {
 
         // If MAILSERVER is set, override $server with it's value
 
+        if (!isset($port) || !$port) {$port = 110;}
         if(!empty($this->MAILSERVER))
             $server = $this->MAILSERVER;
 
@@ -75,7 +89,7 @@ class POP3 {
             return false;
         }
 
-        $fp = fsockopen("$server", $port, $errno, $errstr);
+        $fp = @fsockopen("$server", $port, $errno, $errstr);
 
         if(!$fp) {
             $this->ERROR = _("POP3 connect:") . ' ' . _("Error ") . "[$errno] [$errstr]";
@@ -96,25 +110,7 @@ class POP3 {
         }
         $this->FP = $fp;
         $this->BANNER = $this->parse_banner($reply);
-        $this->RFC1939 = $this->noop();
-        if($this->RFC1939) {
-            $this->ERROR = _("POP3: premature NOOP OK, NOT an RFC 1939 Compliant server");
-            $this->quit();
-            return false;
-        } else
-            return true;
-    }
-
-    function noop () {
-    
-        if(!isset($this->FP)) {
-            $this->ERROR = _("POP3 noop:") . ' ' . _("No connection to server");
-            return false;
-        } else {
-            $cmd = "NOOP";
-            $reply = $this->send_cmd( $cmd );
-            return( $this->is_ok( $reply ) );
-        }
+        return true;
     }
 
     function user ($user = "") {
@@ -149,20 +145,14 @@ class POP3 {
         } else {
             $reply = $this->send_cmd("PASS $pass");
             if(!$this->is_ok($reply)) {
-                $this->ERROR = _("POP3 pass:") . ' ' . _("authentication failed ") . "[$reply]";
+                $this->ERROR = _("POP3 pass:") . ' ' . _("Authentication failed") . " [$reply]";
                 $this->quit();
                 return false;
             } else {
                 //  Auth successful.
                 $count = $this->last("count");
                 $this->COUNT = $count;
-                $this->RFC1939 = $this->noop();
-                if(!$this->RFC1939) {
-                    $this->ERROR = _("POP3 pass:") . ' ' . _("NOOP failed. Server not RFC 1939 compliant");
-                    $this->quit();
-                    return false;
-                } else
-                    return $count;
+                return $count;
             }
         }
     }
@@ -205,13 +195,7 @@ class POP3 {
                     //  Auth successful.
                     $count = $this->last("count");
                     $this->COUNT = $count;
-                    $this->RFC1939 = $this->noop();
-                    if(!$this->RFC1939) {
-                        $this->ERROR = _("POP3 apop:") . ' ' . _("NOOP failed. Server not RFC 1939 compliant");
-                        $this->quit();
-                        return false;
-                    } else
-                        return $count;
+                    return $count;
                 }
             }
         }
@@ -321,7 +305,7 @@ class POP3 {
                 $this->ERROR = _("POP3 pop_list:") . ' ' . _("Error ") . "[$reply]";
                 return false;
             }
-            list($junk,$num,$size) = explode(" ",$reply);
+            list($junk,$num,$size) = preg_split('/\s+/',$reply);
             return $size;
         }
         $cmd = "LIST";
@@ -344,7 +328,7 @@ class POP3 {
                 $this->ERROR = _("POP3 pop_list:") . ' ' . _("Premature end of list");
                 return false;
             }
-            list($thisMsg,$msgSize) = explode(" ",$line);
+            list($thisMsg,$msgSize) = preg_split('/\s+/',$line);
             settype($thisMsg,"integer");
             if($thisMsg != $msgC)
             {
@@ -414,7 +398,7 @@ class POP3 {
             return $last;
         }
 
-        $Vars = explode(" ",$reply);
+        $Vars = preg_split('/\s+/',$reply);
         $count = $Vars[1];
         $size = $Vars[2];
         settype($count,"integer");
@@ -545,7 +529,7 @@ class POP3 {
                 $this->ERROR = _("POP3 uidl:") . ' ' . _("Error ") . "[$reply]";
                 return false;
             }
-            list ($ok,$num,$myUidl) = explode(" ",$reply);
+            list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply);
             return $myUidl;
         } else {
             $this->update_timer();
@@ -576,14 +560,14 @@ class POP3 {
                 if(ereg("^\.\r\n",$line)) {
                     break;
                 }
-                list ($msg,$msgUidl) = explode(" ",$line);
+                list ($msg,$msgUidl) = preg_split('/\s+/',$line);
                 $msgUidl = $this->strip_clf($msgUidl);
                 if($count == $msg) {
                     $UIDLArray[$msg] = $msgUidl;
                 }
                 else
                 {
-                    $UIDLArray[$count] = "deleted";
+                    $UIDLArray[$count] = 'deleted';
                 }
                 $count++;
                 $line = fgets($fp,$buffer);
@@ -668,4 +652,4 @@ class POP3 {
 
 }   // End class
 
-?>
+?>
\ No newline at end of file