pop3.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:5k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: pop3.php,v $
- // | $Date: 2004/02/10 01:34:25 $
- // | $Revision: 1.5 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - POP3 mail fetching module
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE);
- class POP_Socket {
- var $fp = null;
- var $connected = false;
- var $serverinfo = array();
- var $encrypted = false;
- var $msgNums = array();
- var $msgIDs = array();
- // Sets up the server information array
- function POP_Socket($info, $enc = false) {
- $this->serverinfo = $info;
- $this->encrypted = $enc;
- }
- // Connect to the server
- function connect() {
- $this->fp = fsockopen($this->serverinfo['server'], $this->serverinfo['port'], $error_no, $error_str);
- if (!is_resource($this->fp)) {
- $this->error(101);
- return false;
- }
- $this->connected = true;
- $buffer = fgets($this->fp, 4096);
- if (substr($buffer, 0, 3) != '+OK') {
- $this->error(101);
- $this->close();
- return false;
- } else {
- return true;
- }
- }
- // Login to the server
- function auth() {
- if (!is_resource($this->fp) and $this->connect() === false) {
- return false;
- }
- fputs($this->fp, 'USER '.$this->serverinfo['username']."rn");
- $buffer = fgets($this->fp, 4096);
- if (substr($buffer, 0, 3) != '+OK') {
- $this->close();
- return false;
- }
- if ($this->encrypted) {
- fputs($this->fp, 'PASS '.pop_decrypt($this->serverinfo['password'])."rn");
- } else {
- fputs($this->fp, 'PASS '.$this->serverinfo['password']."rn");
- }
- $buffer = fgets($this->fp, 4096);
- if (substr($buffer, 0, 3) != '+OK') {
- $this->error(102);
- $this->close();
- return false;
- } else {
- return true;
- }
- }
- // Get the list of messages and their ID's
- function get_list() {
- fputs($this->fp, "LISTrn");
- if (substr(fgets($this->fp, 4096), 0, 3) != '+OK') {
- $this->close();
- return false;
- }
- // Store the message numbers and sizes
- $buffer = fgets($this->fp, 4096);
- while ($buffer != ".rn") {
- $msginfo = explode(' ', $buffer);
- $this->msgNums[(trim($msginfo[0]))] = trim($msginfo[1]);
- $buffer = fgets($this->fp, 4096);
- }
- return true;
- }
- // Gets email number $msgnum from the server
- function get_email($msgnum, &$source, $stopat = '', $onelineonly = false) {
- $this->get_data("RETR $msgnumrn", $source, $stopat, $onelineonly);
- }
- // Gets the top $lines from the message
- function get_top($msgnum, &$source, $lines = 0, $stopat = '', $onelineonly = false) {
- $this->get_data("TOP $msgnum $linesrn", $source, $stopat, $onelineonly);
- }
- // Issues $command and returns the output
- function get_data($command, &$source, $stopat = '', $onelineonly = false) {
- fputs($this->fp, $command);
- if (substr(fgets($this->fp, 4096), 0, 3) != '+OK') {
- return false;
- }
- $source = '';
- $buffer = fgets($this->fp, 4096);
- while ($buffer != ".rn") {
- if (!$onelineonly) {
- $source .= $buffer;
- }
- if (!empty($stopat) and strtolower(substr($buffer, 0, strlen($stopat))) == strtolower($stopat)) {
- // We're doing this "weirdly" because we still have to fgets() the rest of the buffer
- if ($onelineonly) {
- $source = $buffer;
- $stopat = '';
- } else {
- $onelineonly = true;
- $stopat = '';
- }
- }
- $buffer = fgets($this->fp, 4096);
- }
- return true;
- }
- // Delete message number $msgnum from the server
- function delete_email($msgnum) {
- fputs($this->fp, "DELE $msgnumrn");
- if (substr(fgets($this->fp, 4096), 0, 3) != '+OK') {
- return false;
- } else {
- return true;
- }
- }
- // Close connection to the server
- function close() {
- if ($this->connected == true and is_resource($this->fp)) {
- $this->connected = false;
- fputs($this->fp, "QUITrn");
- fclose($this->fp);
- }
- }
- function error($error) {
- $this->errorval = $error;
- }
- function error_num() {
- return $this->errorval;
- }
- }