⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pop3.php

📁 jsp程序开发系统
💻 PHP
字号:
<?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']."\r\n");
		$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'])."\r\n");
		} else {
			fputs($this->fp, 'PASS '.$this->serverinfo['password']."\r\n");
		}
		$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, "LIST\r\n");
		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 != ".\r\n") {
			$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 $msgnum\r\n", $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 $lines\r\n", $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 != ".\r\n") {
			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 $msgnum\r\n");
		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, "QUIT\r\n");
			fclose($this->fp);
		}
	}

	function error($error) {
		$this->errorval = $error;
	}

	function error_num() {
		return $this->errorval;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -