-<?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.
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
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;
}
// 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;
}
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;
}
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();
$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)
{
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;
}
$line = fgets($fp,$buffer);
while ( !ereg("^\.\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");
// 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();
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;
}
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;
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;
$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
-
?>