X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/ff81ee6e8304a1982a3ec4f5b134764a29d502cf..4feeb71a9d812a9ae371c28a3d8b442a4394ded7:/wp-includes/class-pop3.php diff --git a/wp-includes/class-pop3.php b/wp-includes/class-pop3.php index 468ca8bd..ffbc377d 100644 --- a/wp-includes/class-pop3.php +++ b/wp-includes/class-pop3.php @@ -1,20 +1,20 @@ -BUFFER,"integer"); if( !empty($server) ) { // Do not allow programs to alter MAILSERVER @@ -59,13 +59,22 @@ 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; } + /** + * PHP4 constructor. + */ + public function POP3( $server = '', $timeout = '' ) { + self::__construct( $server, $timeout ); + } + function update_timer () { - set_time_limit($this->TIMEOUT); + if (!ini_get('safe_mode')) + set_time_limit($this->TIMEOUT); return true; } @@ -73,21 +82,22 @@ class POP3 { // Opens a socket to the specified server. Unless overridden, // port defaults to 110. Returns true on success, false on fail - // If MAILSERVER is set, override $server with it's value + // If MAILSERVER is set, override $server with its 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 +109,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 +142,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 +169,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 +193,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 +212,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 +237,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 +253,7 @@ class POP3 { } if(!$this->is_ok($reply)) { - $this->ERROR = _("POP3 top:") . ' ' . _("Error ") . "[$reply]"; + $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]"; return false; } @@ -281,7 +261,7 @@ class POP3 { $MsgArray = array(); $line = fgets($fp,$buffer); - while ( !ereg("^\.\r\n",$line)) + while ( !preg_match('/^\.\r\n/',$line)) { $MsgArray[$count] = $line; $count++; @@ -299,7 +279,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 +307,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 +318,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(); @@ -348,12 +328,12 @@ class POP3 { if($msgC > $Total) { break; } $line = fgets($fp,$this->BUFFER); $line = $this->strip_clf($line); - if(ereg("^\.",$line)) + if(strpos($line, '.') === 0) { - $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 +353,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 +366,7 @@ class POP3 { if(!$this->is_ok($reply)) { - $this->ERROR = _("POP3 get:") . ' ' . _("Error ") . "[$reply]"; + $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]"; return false; } @@ -394,8 +374,9 @@ class POP3 { $MsgArray = array(); $line = fgets($fp,$buffer); - while ( !ereg("^\.\r\n",$line)) + while ( !preg_match('/^\.\r\n/',$line)) { + if ( $line{0} == '.' ) { $line = substr($line,1); } $MsgArray[$count] = $line; $count++; $line = fgets($fp,$buffer); @@ -412,18 +393,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 +423,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 +433,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 +457,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 +483,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 +520,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 +532,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,18 +555,15 @@ 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; } $line = ""; $count = 1; $line = fgets($fp,$buffer); - while ( !ereg("^\.\r\n",$line)) { - if(ereg("^\.\r\n",$line)) { - break; - } - list ($msg,$msgUidl) = explode(" ",$line); + while ( !preg_match('/^\.\r\n/',$line)) { + list ($msg,$msgUidl) = preg_split('/\s+/',$line); $msgUidl = $this->strip_clf($msgUidl); if($count == $msg) { $UIDLArray[$msg] = $msgUidl; @@ -607,18 +585,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; @@ -634,7 +612,7 @@ class POP3 { if( empty($cmd) ) return false; else - return( ereg ("^\+OK", $cmd ) ); + return( stripos($cmd, '+OK') !== false ); } function strip_clf ($text = "") { @@ -643,8 +621,7 @@ class POP3 { if(empty($text)) return $text; else { - $stripped = str_replace("\r",'',$text); - $stripped = str_replace("\n",'',$stripped); + $stripped = str_replace(array("\r","\n"),'',$text); return $stripped; } } @@ -655,8 +632,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; @@ -677,4 +654,9 @@ class POP3 { } // End class -?> +// For php4 compatibility +if (!function_exists("stripos")) { + function stripos($haystack, $needle){ + return strpos($haystack, stristr( $haystack, $needle )); + } +}