Home > php教程 > php手册 > body text

使用PHP的Socket写的POP3类(一)

WBOY
Release: 2016-06-13 11:21:34
Original
1051 people have browsed it

查看 POP3/SMTP 协议的时候想尝试一下自己写一个操作类,核心没啥,就是使用 fsockopen ,然后写入/接收数据,只实现了最核心的部分功能,当作是学习 Socket 操作的练手。其中参考了 RFC 2449和一个国外的简单Web邮件系统 Uebimiau 的部分代码,不过绝对没有抄他滴,HOHO,绝对原创。假如你喜欢,请收藏,随便修改,嗯,但是记得不要删除偶类里的声名,究竟偶也是辛辛劳苦写了好几天呐。
另外,欢迎自由发挥,改善或者修正这个类,希望能够为你所用。代码没有认真仔细的调试,发现bug请自己修正,HOHO!

/**
* 类名:SocketPOPClient
* 功能:POP3 协议客户端的基本操作类
* 作者:heiyeluren
* 时间:2006-7-3
* 参考:RFC 2449, Uebimiau
* 授权: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();


//---------------
// 基础操作
//---------------

//构造函数
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();
}

//连接服务器
function connectHost()
{
if ($this->bolDebug)
{
echo "Connection ".$this->strHost." ...rn";
}
if (!$this->getIsConnect())


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template