POP3 class written using PHP Socket (1)

Source: Internet
Author: User

When viewing POP3/SMTP protocols, I want to write an operation class by myself. The core is to use fsockopen and then write/receive data, which only implements the core functions, as a trainer who learns Socket operations. Refer to RFC 2449 and some code of Uebimiau, a simple Web mail system in foreign countries, but they are not copied, HOHO, and they are absolutely original. If you like it, please add it to your favorites and modify it as you like. Well, remember not to delete the reputation in the even class. It's just a couple of days of hard work.
In addition, you are welcome to give full play to it, improve or correct this class, and hope it can be used for you. The Code was not carefully debugged. Please correct the bug yourself, HOHO!

<? Php
/**
* Class Name: SocketPOPClient
* Function: basic operations of POP3 client
* Author: heiyeluren * Time: 2006-7-3
* Reference: RFC 2449, Uebimiau
* Authorization: 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 ())


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.