-<?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
+ *
+ * Copyright (c) 1999-2011 CDI (cdi@thewebmasters.net) All Rights Reserved
+ * Modified by Philippe Mingo 2001-2009 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
+ *
+ * @copyright 1999-2011 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @package plugins
+ * @subpackage mail_fetch
+ */
class POP3 {
var $ERROR = ''; // Error string.
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
- function POP3 ( $server = '', $timeout = '' ) {
+ /**
+ * PHP5 constructor.
+ */
+ function __construct ( $server = '', $timeout = '' ) {
settype($this->BUFFER,"integer");
if( !empty($server) ) {
// Do not allow programs to alter MAILSERVER
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;
}
// 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;
}
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;
// 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;
}
}
}
// (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 {
$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;
}
}
}
// 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;
// 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();
}
if(!$this->is_ok($reply))
{
- $this->ERROR = _("POP3 top:") . ' ' . _("Error ") . "[$reply]";
+ $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]";
return false;
}
$MsgArray = array();
$line = fgets($fp,$buffer);
- while ( !ereg("^\.\r\n",$line))
+ while ( !preg_match('/^\.\r\n/',$line))
{
$MsgArray[$count] = $line;
$count++;
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;
}
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";
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();
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)
{
if(!isset($this->FP))
{
- $this->ERROR = _("POP3 get:") . ' ' . _("No connection to server");
+ $this->ERROR = "POP3 get: " . _("No connection to server");
return false;
}
if(!$this->is_ok($reply))
{
- $this->ERROR = _("POP3 get:") . ' ' . _("Error ") . "[$reply]";
+ $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]";
return false;
}
$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);
$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");
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");
if(!$this->is_ok($reply))
{
// The POP3 RSET command -never- gives a -ERR
- // response - if it ever does, something truely
+ // response - if it ever does, something truly
// 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();
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 "";
}
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;
// 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;
}
$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();
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;
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;
if( empty($cmd) )
return false;
else
- return( ereg ("^\+OK", $cmd ) );
+ return( stripos($cmd, '+OK') !== false );
}
function strip_clf ($text = "") {
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;
}
}
$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;
} // End class
-?>
+// For php4 compatibility
+if (!function_exists("stripos")) {
+ function stripos($haystack, $needle){
+ return strpos($haystack, stristr( $haystack, $needle ));
+ }
+}