Home  >  Article  >  Backend Development  >  POP3 class written using PHP Socket (1)_PHP tutorial

POP3 class written using PHP Socket (1)_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:05:34928browse

When I looked at the POP3/SMTP protocol, I wanted to try writing an operation class myself. The core is nothing, just use fsockopen, and then write/receive data. Only the core functions are implemented. It is regarded as learning Socket operation. Practice. It refers to RFC 2449 and part of the code of Uebimiau, a simple foreign web mail system, but it is definitely not copied from him. HOHO, it is absolutely original. If you like it, please collect it and modify it as you like, um, but remember not to delete the comments in the category. After all, I have worked hard to write it for several days.
In addition, you are welcome to play freely, improve or modify this class, I hope it can be of use to you. The code has not been debugged carefully. If you find bugs, please correct them yourself, HOHO!

/**
* Class name: SocketPOPClient
* Function: Basic operation class of POP3 protocol client
* Author: heiyeluren
* Time: 2006- 7-3
* Reference: RFC 2449, Uebimiau
* License: BSD License
*/

class SocketPOPClient
{
var $strMessage = '';
var $intErrorNum = 0;
var $bolDebug = false;

var $strEmail = '';
var $strPasswd = '';
var $strHost = '';
var $intPort = 110;
var $intConnSecond = 30;
var $intBuffSize = 8192;

var $resHandler = NULL;
var $bolIsLogin = false;
var $strRequest = ' ';
var $strResponse = '';
var $arrRequest = array();
var $arrResponse = array();


//----- ----------
//Basic operations
//---------------

//Constructor
function SocketPOP3Client($strLoginEmail, $strLoginPasswd, $strPopHost='', $intPort='')
{
$this->strEmail = trim(strtolower($strLoginEmail));
$this- >strPasswd = trim($strLoginPasswd);
$this->strHost = trim(strtolower($strPopHost));

if ($this->strEmail=='' || $ this->strPasswd=='')
{
$this->setMessage('Email address or Passwd is empty', 1001);
return false;
}
if (!preg_match("/^[w-] (.[w-] )*@[w-] (.[w-] ) $/i", $this->strEmail))
{
$this->setMessage('Email address invalid', 1002);
return false;
}
if ($this->strHost=='')
{
$this->strHost = substr(strrchr($this->strEmail, "@"), 1);
}
if ($intPort!='')
{
$ this->intPort = $intPort;
}
$this->connectHost();
}

//Connect to the server
function connectHost()
{
if ($this->bolDebug)
{
echo "Connection ".$this->strHost." ...rn";
}
if (!$this ->getIsConnect())


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445119.htmlTechArticleWhen looking at the POP3/SMTP protocol, I wanted to try to write an operation class myself. The core is nothing, just use fsockopen. Then writing/receiving data only implements some of the core functions...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn