]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-pop3.php
Wordpress 2.8.4-scripts
[autoinstalls/wordpress.git] / wp-includes / class-pop3.php
index 468ca8bdfd1f58e00536a8aff04ae794f0f1ae3b..c11676c4944895f7cd2efde77cf687dc6e3fb158 100644 (file)
@@ -1,20 +1,21 @@
-<?php 
-
-   /**
-    * mail_fetch/setup.php
-    *
-    * Copyright (c) 1999-2002 The SquirrelMail Project Team
-    *
-    * 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.
-    *
-    * Licensed under the GNU GPL. For full terms see the file COPYING.
-    *
-    * pop3 class
-    *
-    * $Id: class-pop3.php 2066 2005-01-07 01:29:49Z saxmatt $
-    */
+<?php
+/**
+ * mail_fetch/setup.php
+ *
+ * @package SquirrelMail
+ *
+ * @copyright (c) 1999-2006 The SquirrelMail Project Team
+ *
+ * @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.
+ *
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * pop3 class
+ *
+ * $Id: class-pop3.php 9503 2008-11-03 23:25:11Z ryan $
+ */
 
 class POP3 {
     var $ERROR      = '';       //  Error string.
@@ -40,9 +41,6 @@ class POP3 {
     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()
                                 //  This must be set to true
                                 //  manually
@@ -59,13 +57,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;
     }
 
@@ -75,19 +75,20 @@ 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;
 
         if(empty($server)){
-            $this->ERROR = _("POP3 connect:") . ' ' . _("No server specified");
+            $this->ERROR = "POP3 connect: " . _("No server specified");
             unset($this->FP);
             return false;
         }
 
-        $fp = fsockopen("$server", $port, $errno, $errstr);
+        $fp = @fsockopen("$server", $port, $errno, $errstr);
 
         if(!$fp) {
-            $this->ERROR = _("POP3 connect:") . ' ' . _("Error ") . "[$errno] [$errstr]";
+            $this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]";
             unset($this->FP);
             return false;
         }
@@ -99,46 +100,28 @@ class POP3 {
         if($this->DEBUG)
             error_log("POP3 SEND [connect: $server] GOT [$reply]",0);
         if(!$this->is_ok($reply)) {
-            $this->ERROR = _("POP3 connect:") . ' ' . _("Error ") . "[$reply]";
+            $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]";
             unset($this->FP);
             return false;
         }
         $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 = "") {
         // Sends the USER command, returns true or false
 
         if( empty($user) ) {
-            $this->ERROR = _("POP3 user:") . ' ' . _("no login ID submitted");
+            $this->ERROR = "POP3 user: " . _("no login ID submitted");
             return false;
         } elseif(!isset($this->FP)) {
-            $this->ERROR = _("POP3 user:") . ' ' . _("connection not established");
+            $this->ERROR = "POP3 user: " . _("connection not established");
             return false;
         } else {
             $reply = $this->send_cmd("USER $user");
             if(!$this->is_ok($reply)) {
-                $this->ERROR = _("POP3 user:") . ' ' . _("Error ") . "[$reply]";
+                $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]";
                 return false;
             } else
                 return true;
@@ -150,28 +133,22 @@ class POP3 {
         // returns false (undef) on Auth failure
 
         if(empty($pass)) {
-            $this->ERROR = _("POP3 pass:") . ' ' . _("No password submitted");
+            $this->ERROR = "POP3 pass: " . _("No password submitted");
             return false;
         } elseif(!isset($this->FP)) {
-            $this->ERROR = _("POP3 pass:") . ' ' . _("connection not established");
+            $this->ERROR = "POP3 pass: " . _("connection not established");
             return false;
         } 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;
             }
         }
     }
@@ -183,21 +160,21 @@ class POP3 {
         //  (apop is optional per rfc1939)
 
         if(!isset($this->FP)) {
-            $this->ERROR = _("POP3 apop:") . ' ' . _("No connection to server");
+            $this->ERROR = "POP3 apop: " . _("No connection to server");
             return false;
         } elseif(!$this->ALLOWAPOP) {
             $retVal = $this->login($login,$pass);
             return $retVal;
         } elseif(empty($login)) {
-            $this->ERROR = _("POP3 apop:") . ' ' . _("No login ID submitted");
+            $this->ERROR = "POP3 apop: " . _("No login ID submitted");
             return false;
         } elseif(empty($pass)) {
-            $this->ERROR = _("POP3 apop:") . ' ' . _("No password submitted");
+            $this->ERROR = "POP3 apop: " . _("No password submitted");
             return false;
         } else {
             $banner = $this->BANNER;
             if( (!$banner) or (empty($banner)) ) {
-                $this->ERROR = _("POP3 apop:") . ' ' . _("No server banner") . ' - ' . _("abort");
+                $this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort");
                 $retVal = $this->login($login,$pass);
                 return $retVal;
             } else {
@@ -207,20 +184,14 @@ class POP3 {
                 $cmd = "APOP $login $APOPString";
                 $reply = $this->send_cmd($cmd);
                 if(!$this->is_ok($reply)) {
-                    $this->ERROR = _("POP3 apop:") . ' ' . _("apop authentication failed") . ' - ' . _("abort");
+                    $this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort");
                     $retVal = $this->login($login,$pass);
                     return $retVal;
                 } else {
                     //  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;
                 }
             }
         }
@@ -232,7 +203,7 @@ class POP3 {
         // the number of messages.)
 
         if( !isset($this->FP) ) {
-            $this->ERROR = _("POP3 login:") . ' ' . _("No connection to server");
+            $this->ERROR = "POP3 login: " . _("No connection to server");
             return false;
         } else {
             $fp = $this->FP;
@@ -257,7 +228,7 @@ class POP3 {
         //  only the header information, and none of the body.
 
         if(!isset($this->FP)) {
-            $this->ERROR = _("POP3 top:") . ' ' . _("No connection to server");
+            $this->ERROR = "POP3 top: " . _("No connection to server");
             return false;
         }
         $this->update_timer();
@@ -273,7 +244,7 @@ class POP3 {
         }
         if(!$this->is_ok($reply))
         {
-            $this->ERROR = _("POP3 top:") . ' ' . _("Error ") . "[$reply]";
+            $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]";
             return false;
         }
 
@@ -299,7 +270,7 @@ class POP3 {
 
         if(!isset($this->FP))
         {
-            $this->ERROR = _("POP3 pop_list:") . ' ' . _("No connection to server");
+            $this->ERROR = "POP3 pop_list: " . _("No connection to server");
             return false;
         }
         $fp = $this->FP;
@@ -327,10 +298,10 @@ class POP3 {
             }
             if(!$this->is_ok($reply))
             {
-                $this->ERROR = _("POP3 pop_list:") . ' ' . _("Error ") . "[$reply]";
+                $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";
@@ -338,7 +309,7 @@ class POP3 {
         if(!$this->is_ok($reply))
         {
             $reply = $this->strip_clf($reply);
-            $this->ERROR = _("POP3 pop_list:") . ' ' . _("Error ") .  "[$reply]";
+            $this->ERROR = "POP3 pop_list: " . _("Error ") .  "[$reply]";
             return false;
         }
         $MsgArray = array();
@@ -350,10 +321,10 @@ class POP3 {
             $line = $this->strip_clf($line);
             if(ereg("^\.",$line))
             {
-                $this->ERROR = _("POP3 pop_list:") . ' ' . _("Premature end of list");
+                $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)
             {
@@ -373,7 +344,7 @@ class POP3 {
 
         if(!isset($this->FP))
         {
-            $this->ERROR = _("POP3 get:") . ' ' . _("No connection to server");
+            $this->ERROR = "POP3 get: " . _("No connection to server");
             return false;
         }
 
@@ -386,7 +357,7 @@ class POP3 {
 
         if(!$this->is_ok($reply))
         {
-            $this->ERROR = _("POP3 get:") . ' ' . _("Error ") . "[$reply]";
+            $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]";
             return false;
         }
 
@@ -396,6 +367,7 @@ class POP3 {
         $line = fgets($fp,$buffer);
         while ( !ereg("^\.\r\n",$line))
         {
+            if ( $line{0} == '.' ) { $line = substr($line,1); }
             $MsgArray[$count] = $line;
             $count++;
             $line = fgets($fp,$buffer);
@@ -412,18 +384,18 @@ class POP3 {
         $last = -1;
         if(!isset($this->FP))
         {
-            $this->ERROR = _("POP3 last:") . ' ' . _("No connection to server");
+            $this->ERROR = "POP3 last: " . _("No connection to server");
             return $last;
         }
 
         $reply = $this->send_cmd("STAT");
         if(!$this->is_ok($reply))
         {
-            $this->ERROR = _("POP3 last:") . ' ' . _("Error ") . "[$reply]";
+            $this->ERROR = "POP3 last: " . _("Error ") . "[$reply]";
             return $last;
         }
 
-        $Vars = explode(" ",$reply);
+        $Vars = preg_split('/\s+/',$reply);
         $count = $Vars[1];
         $size = $Vars[2];
         settype($count,"integer");
@@ -442,7 +414,7 @@ class POP3 {
 
         if(!isset($this->FP))
         {
-            $this->ERROR = _("POP3 reset:") . ' ' . _("No connection to server");
+            $this->ERROR = "POP3 reset: " . _("No connection to server");
             return false;
         }
         $reply = $this->send_cmd("RSET");
@@ -452,7 +424,7 @@ class POP3 {
             //  response - if it ever does, something truely
             //  wild is going on.
 
-            $this->ERROR = _("POP3 reset:") . ' ' . _("Error ") . "[$reply]";
+            $this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]";
             @error_log("POP3 reset: ERROR [$reply]",0);
         }
         $this->quit();
@@ -476,13 +448,13 @@ class POP3 {
 
         if(!isset($this->FP))
         {
-            $this->ERROR = _("POP3 send_cmd:") . ' ' . _("No connection to server");
+            $this->ERROR = "POP3 send_cmd: " . _("No connection to server");
             return false;
         }
 
         if(empty($cmd))
         {
-            $this->ERROR = _("POP3 send_cmd:") . ' ' . _("Empty command string");
+            $this->ERROR = "POP3 send_cmd: " . _("Empty command string");
             return "";
         }
 
@@ -502,7 +474,7 @@ class POP3 {
 
         if(!isset($this->FP))
         {
-            $this->ERROR = _("POP3 quit:") . ' ' . _("connection does not exist");
+            $this->ERROR = "POP3 quit: " . _("connection does not exist");
             return false;
         }
         $fp = $this->FP;
@@ -539,7 +511,7 @@ class POP3 {
         //  Array element 0 will contain the total number of msgs
 
         if(!isset($this->FP)) {
-            $this->ERROR = _("POP3 uidl:") . ' ' . _("No connection to server");
+            $this->ERROR = "POP3 uidl: " . _("No connection to server");
             return false;
         }
 
@@ -551,10 +523,10 @@ class POP3 {
             $reply = $this->send_cmd($cmd);
             if(!$this->is_ok($reply))
             {
-                $this->ERROR = _("POP3 uidl:") . ' ' . _("Error ") . "[$reply]";
+                $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();
@@ -574,7 +546,7 @@ class POP3 {
             if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); }
             if(!$this->is_ok($reply))
             {
-                $this->ERROR = _("POP3 uidl:") . ' ' . _("Error ") . "[$reply]";
+                $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]";
                 return false;
             }
 
@@ -585,7 +557,7 @@ 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;
@@ -607,18 +579,18 @@ class POP3 {
 
         if(!isset($this->FP))
         {
-            $this->ERROR = _("POP3 delete:") . ' ' . _("No connection to server");
+            $this->ERROR = "POP3 delete: " . _("No connection to server");
             return false;
         }
         if(empty($msgNum))
         {
-            $this->ERROR = _("POP3 delete:") . ' ' . _("No msg number submitted");
+            $this->ERROR = "POP3 delete: " . _("No msg number submitted");
             return false;
         }
         $reply = $this->send_cmd("DELE $msgNum");
         if(!$this->is_ok($reply))
         {
-            $this->ERROR = _("POP3 delete:") . ' ' . _("Command failed ") . "[$reply]";
+            $this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]";
             return false;
         }
         return true;
@@ -655,8 +627,8 @@ class POP3 {
         $length = strlen($server_text);
         for($count =0; $count < $length; $count++)
         {
-            $digit = substr($server_text, $count, 1);
-            if ( false !== $digit ) {
+            $digit = substr($server_text,$count,1);
+            if(!empty($digit))             {
                 if( (!$outside) && ($digit != '<') && ($digit != '>') )
                 {
                     $banner .= $digit;
@@ -676,5 +648,4 @@ class POP3 {
     }
 
 }   // End class
-
 ?>