mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 11:27:24 +08:00
remove vue admin + include/smtp+browser
This commit is contained in:
@@ -1,270 +0,0 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
|
||||
Browser Emulating file functions v2.0
|
||||
(c) Kai Blankenhorn
|
||||
www.bitfolge.de/en
|
||||
kaib@bitfolge.de
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
****************************************************************************
|
||||
|
||||
|
||||
Changelog:
|
||||
|
||||
v2.0 03-09-03
|
||||
added a wrapper class; this has the advantage that you no longer need
|
||||
to specify a lot of parameters, just call the methods to set
|
||||
each option
|
||||
added option to use a special port number, may be given by setPort or
|
||||
as part of the URL (e.g. server.com:80)
|
||||
added getLastResponseHeaders()
|
||||
|
||||
v1.5
|
||||
added Basic HTTP user authorization
|
||||
minor optimizations
|
||||
|
||||
v1.0
|
||||
initial release
|
||||
|
||||
|
||||
|
||||
***************************************************************************/
|
||||
/**
|
||||
* BrowserEmulator class. Provides methods for opening urls and emulating
|
||||
* a web browser request.
|
||||
**/
|
||||
class BrowserEmulator {
|
||||
|
||||
var $headerLines = Array ();
|
||||
var $postData = Array ();
|
||||
var $authUser = "";
|
||||
var $authPass = "";
|
||||
var $port;
|
||||
var $lastResponse = Array ();
|
||||
|
||||
function __construct () {
|
||||
$this->resetHeaderLines ();
|
||||
$this->resetPort ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a single header field to the HTTP request header. The resulting header
|
||||
* line will have the format
|
||||
* $name: $value\n
|
||||
**/
|
||||
function addHeaderLine ($name, $value) {
|
||||
$this->headerLines[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all custom header lines. This will not remove the User-Agent header field,
|
||||
* which is necessary for correct operation.
|
||||
**/
|
||||
function resetHeaderLines () {
|
||||
$this->headerLines = Array ();
|
||||
|
||||
/*******************************************************************************/
|
||||
/************** YOU MAX SET THE USER AGENT STRING HERE *******************/
|
||||
/* */
|
||||
/* default is "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", */
|
||||
/* which means Internet Explorer 6.0 on WinXP */
|
||||
|
||||
$this->headerLines["User-Agent"] =
|
||||
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a post parameter. Post parameters are sent in the body of an HTTP POST request.
|
||||
**/
|
||||
function addPostData ($name, $value) {
|
||||
$this->postData[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all custom post parameters.
|
||||
**/
|
||||
function resetPostData () {
|
||||
$this->postData = Array ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an auth user and password to use for the request.
|
||||
* Set both as empty strings to disable authentication.
|
||||
**/
|
||||
function setAuth ($user, $pass) {
|
||||
$this->authUser = $user;
|
||||
$this->authPass = $pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects a custom port to use for the request.
|
||||
**/
|
||||
function setPort ($portNumber) {
|
||||
$this->port = $portNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the port used for request to the HTTP default (80).
|
||||
**/
|
||||
function resetPort () {
|
||||
$this->port = 80;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an fopen call to $url with the parameters set by previous member
|
||||
* method calls. Send all set headers, post data and user authentication data.
|
||||
* Returns a file handle on success, or false on failure.
|
||||
**/
|
||||
function fopen ($url) {
|
||||
$debug = false;
|
||||
|
||||
$this->lastResponse = Array ();
|
||||
|
||||
preg_match ("~([a-z]*://)?([^:^/]*)(:([0-9]{1,5}))?(/.*)?~i", $url,
|
||||
$matches);
|
||||
if ($debug)
|
||||
var_dump ($matches);
|
||||
$protocol = $matches[1];
|
||||
$server = $matches[2];
|
||||
$port = $matches[4];
|
||||
$path = $matches[5];
|
||||
if ($port != "") {
|
||||
$this->setPort ($port);
|
||||
}
|
||||
if ($path == "")
|
||||
$path = "/";
|
||||
$socket = false;
|
||||
$socket = fsockopen ($server, $this->port);
|
||||
if ($socket) {
|
||||
$this->headerLines["Host"] = $server;
|
||||
|
||||
if ($this->authUser != "" AND $this->authPass != "") {
|
||||
$headers["Authorization"] =
|
||||
"Basic ".base64_encode ($this->authUser.":".$this->
|
||||
authPass);
|
||||
}
|
||||
|
||||
if (count ($this->postData) == 0) {
|
||||
$request = "GET $path HTTP/1.0\r\n";
|
||||
}
|
||||
else {
|
||||
$request = "POST $path HTTP/1.0\r\n";
|
||||
}
|
||||
|
||||
if ($debug)
|
||||
echo $request;
|
||||
fputs ($socket, $request);
|
||||
|
||||
if (count ($this->postData) > 0) {
|
||||
$PostStringArray = Array ();
|
||||
foreach ($this->postData AS $key => $value) {
|
||||
$PostStringArray[] = "$key=$value";
|
||||
}
|
||||
$PostString = join ("&", $PostStringArray);
|
||||
$this->headerLines["Content-Length"] =
|
||||
strlen ($PostString);
|
||||
}
|
||||
|
||||
foreach ($this->headerLines AS $key => $value) {
|
||||
if ($debug)
|
||||
echo "$key: $value\n";
|
||||
fputs ($socket, "$key: $value\r\n");
|
||||
}
|
||||
if ($debug)
|
||||
echo "\n";
|
||||
fputs ($socket, "\r\n");
|
||||
if (count ($this->postData) > 0) {
|
||||
if ($debug)
|
||||
echo "$PostString";
|
||||
fputs ($socket, $PostString."\r\n");
|
||||
}
|
||||
}
|
||||
if ($debug)
|
||||
echo "\n";
|
||||
if ($socket) {
|
||||
$line = fgets ($socket, 1000);
|
||||
if ($debug)
|
||||
echo $line;
|
||||
$this->lastResponse[] = $line;
|
||||
$status = substr ($line, 9, 3);
|
||||
while (trim ($line = fgets ($socket, 1000)) != "") {
|
||||
if ($debug)
|
||||
echo "$line";
|
||||
$this->lastResponse[] = $line;
|
||||
if ($status == "401" AND strpos ($line, "WWW-Authenticate: Basic realm=\"") === 0) {
|
||||
fclose ($socket);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an file call to $url with the parameters set by previous member
|
||||
* method calls. Send all set headers, post data and user authentication data.
|
||||
* Returns the requested file as an array on success, or false on failure.
|
||||
**/
|
||||
function file ($url) {
|
||||
$file = Array ();
|
||||
$socket = $this->fopen ($url);
|
||||
if ($socket) {
|
||||
$file = Array ();
|
||||
while (!feof ($socket)) {
|
||||
$file[] = fgets ($socket, 10000);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
|
||||
function getLastResponseHeaders () {
|
||||
return $this->lastResponse;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// example code
|
||||
/*
|
||||
$be = new BrowserEmulator();
|
||||
//$be->addHeaderLine("Referer", "http://previous.server.com/");
|
||||
//$be->addHeaderLine("Accept-Encoding", "x-compress; x-zip");
|
||||
//$be->addPostData("Submit", "OK");
|
||||
//$be->addPostData("item", "42");
|
||||
//$be->setAuth("admin", "secretpass");
|
||||
// also possible:
|
||||
// $be->setPort(10080);
|
||||
|
||||
$file = $be->fopen("http://us.imdb.com/Title?0209144");
|
||||
$response = $be->getLastResponseHeaders();
|
||||
|
||||
while ($line = fgets($file, 1024)) {
|
||||
// do something with the file
|
||||
echo $line;
|
||||
}
|
||||
fclose($file);
|
||||
|
||||
*/
|
||||
|
||||
?>
|
||||
@@ -1,114 +0,0 @@
|
||||
<?php
|
||||
|
||||
class info_extractor{
|
||||
function __construct(){}
|
||||
|
||||
/** truncate a given string
|
||||
* @method truncate
|
||||
* @param string src(source string), string s_str(starting needle), string e_str(ending needle, "" for open end), integer e_offset(optional where to start finding the $e_str)
|
||||
* @return string trucated string
|
||||
*/
|
||||
function truncate($src, $s_str, $e_str = "", $e_offset = 0)
|
||||
{
|
||||
$ret = "";
|
||||
$e_offset = strlen($s_str);
|
||||
|
||||
$ret = strstr($src, $s_str);
|
||||
if($ret == false)
|
||||
return "";
|
||||
|
||||
if($e_str != "")
|
||||
{
|
||||
$endpos = strpos ($ret , $e_str, $e_offset);
|
||||
if($endpos == false)
|
||||
return "";
|
||||
}
|
||||
|
||||
return substr($ret, strlen($s_str), $endpos - strlen($s_str));
|
||||
}
|
||||
|
||||
/** find a certain pattern in a given string
|
||||
* @method find_pattern
|
||||
* @param string src(source string), string regex(regular expression), boolean multiple(if pattern has multiple occurance), array string res_where_array(where the res should be in regex, order of res_where_array and res_array should be the same, for example: res_array could be "array(array('Name' => '', 'Cloudsize' => '', 'Link' => ''))", then the first element in res_where_array could be, say, "3", which corrsponds to 'Name'), array string res_array(one or multi-dimensional array for the extraced info)
|
||||
* @return boolean found_pattern
|
||||
*/
|
||||
function find_pattern($src, $regex, $multiple, $res_where_array)
|
||||
{
|
||||
$res_array = array();
|
||||
if($multiple == true)
|
||||
{
|
||||
if(!preg_match_all($regex,$src,$info_block,PREG_SET_ORDER))
|
||||
return false;
|
||||
else
|
||||
{
|
||||
$counter_infoblock = 0;
|
||||
foreach($info_block as $info)
|
||||
{
|
||||
$counter_reswhere = 0;
|
||||
foreach ($res_where_array as $res_where_array_each)
|
||||
{
|
||||
$res_array[$counter_infoblock][$counter_reswhere] = $info[$res_where_array_each];
|
||||
$counter_reswhere++;
|
||||
}
|
||||
$counter_infoblock++;
|
||||
}
|
||||
return $res_array;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!preg_match($regex,$src,$info))
|
||||
return false;
|
||||
else
|
||||
{
|
||||
$counter = 0;
|
||||
foreach ($res_where_array as $res_where_array_each)
|
||||
{
|
||||
$res_array[$counter] = $info[$res_where_array_each];
|
||||
$counter++;
|
||||
}
|
||||
return $res_array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** remove a given pattern from a given string
|
||||
* @method truncate
|
||||
* @param string src(source string), string $regex_s(starting needle), string $regex_e(ending needle), integer max(set it to 1 if you are sure the pattern only occurs once, otherwise, it indicates the maximum possible occurance in case of dead loop), boolean all(if remove all or just the pattern)
|
||||
* @return string processed string
|
||||
*/
|
||||
function remove($src, $regex_s, $regex_e, $max = 100, $all = false)
|
||||
{
|
||||
$ret = "";
|
||||
$ret = preg_replace("/" . $regex_s . "((\s|.)+?)" . $regex_e . "/i", ($all == false ? "\\1" : ""), $src, $max);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/** trim a given array of strings types from a given string
|
||||
* @method trim_str
|
||||
* @param string src(source string), string array regex_trim_array(specifies strings to be trimmed), integersafe_counter(maximum possible occurance of string to be trimmed)
|
||||
* @return string processed string
|
||||
*/
|
||||
function trim_str($src, $regex_trim_array, $safe_counter =10)
|
||||
{
|
||||
$ret = "";
|
||||
|
||||
while($safe_counter>0)
|
||||
{
|
||||
$safe_counter--;
|
||||
$break_flag = true;
|
||||
foreach($regex_trim_array as $regex_trim_array_each)
|
||||
{
|
||||
$ret = preg_replace("/^((" . $regex_trim_array_each . ")*)((\s|.)+?)((" . $regex_trim_array_each . ")*)$/i","\\3", trim($src), 1);
|
||||
if($ret != $src)
|
||||
$break_flag = false;
|
||||
$src = $ret;
|
||||
}
|
||||
if($break_flag)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
$mechs = array('LOGIN', 'PLAIN', 'CRAM_MD5');
|
||||
|
||||
foreach ($mechs as $mech) {
|
||||
if (!defined($mech)) {
|
||||
define($mech, $mech);
|
||||
} elseif (constant($mech) != $mech) {
|
||||
trigger_error(sprintf("Constant %s already defined, can't proceed", $mech), E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SASL Mechanisms
|
||||
* @package SASL
|
||||
* @author Fredrik Haugbergsmyr <smtp.lib@lagnut.net>
|
||||
*/
|
||||
$rootpath = './';
|
||||
require_once ($rootpath . 'include/smtp/net.const.php');
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @access public
|
||||
* @todo phpdoc
|
||||
*/
|
||||
class sasl
|
||||
{
|
||||
|
||||
|
||||
function _hmac_md5($key, $data)
|
||||
{
|
||||
if (strlen($key) > 64) {
|
||||
$key = pack('H32', md5($key));
|
||||
}
|
||||
|
||||
if (strlen($key) < 64) {
|
||||
$key = str_pad($key, 64, chr(0));
|
||||
}
|
||||
|
||||
$k_ipad = substr($key, 0, 64) ^ str_repeat(chr(0x36), 64);
|
||||
$k_opad = substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64);
|
||||
|
||||
$inner = pack('H32', md5($k_ipad . $data));
|
||||
$digest = md5($k_opad . $inner);
|
||||
|
||||
return $digest;
|
||||
}
|
||||
|
||||
function cram_md5($user, $pass, $challenge)
|
||||
{
|
||||
var_dump($challenge);
|
||||
$chall = base64_decode($challenge);
|
||||
var_dump($chall);
|
||||
return base64_encode(sprintf('%s %s', $user, $this->_hmac_md5($pass, $chall)));
|
||||
}
|
||||
|
||||
function plain($username, $password)
|
||||
{
|
||||
return base64_encode(sprintf('%c%s%c%s', 0, $username, 0, $password));
|
||||
}
|
||||
|
||||
function login($input)
|
||||
{
|
||||
return base64_encode(sprintf('%s', $input));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,531 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Allows users to send email without e-mailserver on the localmachine
|
||||
* @package SMTP
|
||||
* @author Fredrik Haugbergsmyr <smtp.lib@lagnut.net>
|
||||
*/
|
||||
|
||||
require_once ('net.const.php');
|
||||
|
||||
/**
|
||||
* @version 0.0.2.2
|
||||
* @access public
|
||||
* @todo split messages, attachments
|
||||
*/
|
||||
class smtp
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* lagnut-smtp version, send in the headers
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_version = '0.0.2.2';
|
||||
|
||||
|
||||
/**
|
||||
* Turn debugon / off
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $_debug = false;
|
||||
|
||||
|
||||
/**
|
||||
* Serverconnection resource
|
||||
*
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $_connection = null;
|
||||
|
||||
|
||||
/**
|
||||
* E-mailheaders
|
||||
*
|
||||
* @var array headers
|
||||
* @access private
|
||||
*/
|
||||
var $_hdrs = array();
|
||||
|
||||
|
||||
/**
|
||||
* E-mailbody
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_body = '';
|
||||
|
||||
|
||||
/**
|
||||
* Default Content type
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_mime = 'text/html';
|
||||
|
||||
|
||||
/**
|
||||
* Default Charset
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_charset = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Default Transfer-Content-Encoding
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_CTEncoding = 'base64';
|
||||
|
||||
// These are actually not necessary, but for the shitty eYou email system
|
||||
/**
|
||||
* Charset for Special Case
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_charset_eYou = 'GBK';
|
||||
|
||||
/**
|
||||
* Charset for Special Case
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_specialcase = 'eYou';
|
||||
|
||||
/**
|
||||
* Class contruction, sets client headers
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function smtp($charset = 'UTF-8', $specialcase = "")
|
||||
{
|
||||
$this->_specialcase = $specialcase;
|
||||
$this->_charset = $charset;
|
||||
$this->_add_hdr('X-Mailer', sprintf('LAGNUT-SMTP/%s', $this->_version));
|
||||
$this->_add_hdr('User-Agent', sprintf('LAGNUT-SMTP/%s', $this->_version));
|
||||
$this->_add_hdr('MIME-Version', '1.0');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Turn debugging on/off
|
||||
*
|
||||
* @access public
|
||||
* @param bool $debug command
|
||||
*/
|
||||
function debug($debug)
|
||||
{
|
||||
$this->_debug = (bool)$debug;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean input to prevent injection
|
||||
*
|
||||
* @param string $input User data
|
||||
*/
|
||||
function _clean(&$input)
|
||||
{
|
||||
if (!is_string($input)) {
|
||||
return false;
|
||||
}
|
||||
$input = urldecode($input);
|
||||
$input = str_replace("\n", '', str_replace("\r", '', $input));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send command to server
|
||||
*
|
||||
* @access private
|
||||
* @param string $cmdcommand
|
||||
* @param optional $data data
|
||||
*/
|
||||
function _cmd($cmd, $data = false)
|
||||
{
|
||||
$this->_clean($cmd);
|
||||
$this->_clean($data);
|
||||
|
||||
if ($this->_is_closed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
$command = sprintf("%s\r\n", $cmd);
|
||||
}else {
|
||||
$command = sprintf("%s: %s\r\n", $cmd,$data);
|
||||
}
|
||||
|
||||
fwrite($this->_connection, $command);
|
||||
$resp = $this->_read();
|
||||
if ($this->_debug){
|
||||
printf($command);
|
||||
printf($resp);
|
||||
}
|
||||
if ($this->_is_closed($resp)) {
|
||||
return false;
|
||||
}
|
||||
return $resp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Collects header
|
||||
*
|
||||
* @access private
|
||||
* @param string$key
|
||||
* @param string $data
|
||||
*/
|
||||
function _add_hdr($key, $data)
|
||||
{
|
||||
$this->_clean($key);
|
||||
$this->_clean($data);
|
||||
$this->_hdrs[$key] = sprintf("%s: %s\r\n", $key, $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read server output
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _read()
|
||||
{
|
||||
if ($this->_is_closed()) {
|
||||
return false;
|
||||
}
|
||||
$o = '';
|
||||
do {
|
||||
$str = @fgets($this->_connection, 515);
|
||||
if (!$str) {
|
||||
break;
|
||||
}
|
||||
$o .= $str;
|
||||
if (substr($str, 3, 1) == ' ') {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if server denies more commands
|
||||
*
|
||||
* @access private
|
||||
* @param $int
|
||||
* @return bool true if connection is closed
|
||||
*/
|
||||
function _is_closed($response = false)
|
||||
{
|
||||
if (!$this->_connection) {
|
||||
return true;
|
||||
}
|
||||
if (isset($response{0}) && ($response{0} == 4|| $response{0}== 5)) {
|
||||
$this->close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open connection to server
|
||||
*
|
||||
* @access public
|
||||
* @param string $server SMTP server
|
||||
* @param int $port Server port
|
||||
*/
|
||||
function open($server, $port = 25)
|
||||
{
|
||||
$this->_connection = fsockopen($server, $port, $e, $er, 8);
|
||||
|
||||
if ($this->_is_closed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$init= $this->_read();
|
||||
if ($this->_debug){
|
||||
printf($init);
|
||||
}
|
||||
|
||||
if ($this->_is_closed($init)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lhost = (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1');
|
||||
|
||||
if (strpos($init,'ESMTP') === false){
|
||||
$this->_cmd('HELO '. gethostbyaddr($lhost));
|
||||
} else {
|
||||
$this->_cmd('EHLO '. gethostbyaddr($lhost));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start TLS communication
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function start_tls()
|
||||
{
|
||||
if (!function_exists('stream_socket_enable_crypto')) {
|
||||
trigger_error('TLS is not supported', E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$this->_cmd('STARTTLS');
|
||||
stream_socket_enable_crypto($this->_connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs SMTP authentication
|
||||
*
|
||||
* @access public
|
||||
* @param string $username username
|
||||
* @param string $password password
|
||||
* @param int authentication mecanism
|
||||
*/
|
||||
function auth($username, $password, $type = LOGIN)
|
||||
{
|
||||
|
||||
include_once ('sasl.lib.php');
|
||||
$sasl =& new sasl($sasl, $username, $password);
|
||||
switch ($type) {
|
||||
case PLAIN:
|
||||
$this->_cmd('AUTH PLAIN');
|
||||
$this->_cmd($sasl->plain($username, $password));
|
||||
break;
|
||||
case LOGIN:
|
||||
$this->_cmd('AUTH LOGIN');
|
||||
$this->_cmd($sasl->login($username));
|
||||
$this->_cmd($sasl->login($password));
|
||||
break;
|
||||
case CRAM_MD5:
|
||||
$resp = explode(' ', $this->_cmd('AUTH CRAM-MD5'));
|
||||
$this->_cmd($sasl->cram_md5($username, $password, trim($resp[1])));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes connection to the server
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
if ($this->_is_closed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_cmd('RSET');
|
||||
$this->_cmd('QUIT');
|
||||
fclose($this->_connection);
|
||||
$this->_connection = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* E-mail sender
|
||||
*
|
||||
* @access public
|
||||
* @param string $from Sender
|
||||
*/
|
||||
function from($email, $name = '')
|
||||
{
|
||||
$from = !empty($name) ? sprintf('%s <%s>', $name, $email) : $email;
|
||||
$this->_cmd('MAIL FROM', sprintf('<%s>', $email));
|
||||
$this->_add_hdr('FROM', $from);
|
||||
$this->_add_hdr('Return-path', $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set BCC header
|
||||
*
|
||||
* @access public
|
||||
* @param string $tolist recipients whose email address should be concealed
|
||||
*/
|
||||
function bcc($tolist)
|
||||
{
|
||||
$this->_add_hdr('Bcc', $tolist);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send reply-to header
|
||||
*
|
||||
* @param string $to
|
||||
*/
|
||||
function reply_to($email, $name = '')
|
||||
{
|
||||
$to = !empty($name) ? sprintf('%s <%s>', $name, $email) : $email;
|
||||
$this->_add_hdr('REPLY-TO', $to);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* E-mail reciever
|
||||
*
|
||||
* @access public
|
||||
* @param string $to Reciever
|
||||
*/
|
||||
function to($email, $name = '')
|
||||
{
|
||||
$to = !empty($name) ? sprintf('%s <%s>', $name, $email) : $email;
|
||||
$this->_cmd('RCPT TO', sprintf('<%s>', $email));
|
||||
$this->_add_hdr('TO', $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple E-mail reciever
|
||||
*
|
||||
* @access public
|
||||
* @param string $email Reciever, with out other recepients info disclosed
|
||||
*/
|
||||
function multi_to($email)
|
||||
{
|
||||
$this->_cmd('RCPT TO', sprintf('<%s>', $email));
|
||||
}
|
||||
|
||||
/**
|
||||
* E-mail reciever
|
||||
*
|
||||
* @access public
|
||||
* @param string $email TO head on mass mailing
|
||||
*/
|
||||
function multi_to_head($to)
|
||||
{
|
||||
$this->_add_hdr('TO', $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* MIME type
|
||||
*
|
||||
* @access public
|
||||
* @param string $mime MIME type
|
||||
*/
|
||||
function mime_charset($mime = 'text/html',$charset = 'UTF-8')
|
||||
{
|
||||
$this->_charset = $charset;
|
||||
$this->_mime = $mime;
|
||||
$this->_add_hdr('Content-type', sprintf('%s; charset=%s', $this->_mime, $this->_charset));
|
||||
}
|
||||
|
||||
/**
|
||||
* MIME Content-Transfer-Encoding
|
||||
*
|
||||
* @access public
|
||||
* @param string $mime MIME type
|
||||
*/
|
||||
function mime_content_transfer_encoding($CTEncoding = 'base64')
|
||||
{
|
||||
$this->_CTEncoding = $CTEncoding;
|
||||
$this->_add_hdr('Content-Transfer-Encoding', sprintf('%s', $this->_CTEncoding));
|
||||
}
|
||||
|
||||
/**
|
||||
* E-mail subject
|
||||
*
|
||||
* @access public
|
||||
* @param string $subject subject
|
||||
*/
|
||||
function subject($subject)
|
||||
{
|
||||
$this->_clean($subject);
|
||||
|
||||
if($this->_specialcase = "")
|
||||
$this->_add_hdr('SUBJECT', $this->encode_hdrs($subject));
|
||||
elseif($this->_specialcase = "eYou")
|
||||
{
|
||||
$temp = $this->_charset;
|
||||
$this->_charset = $this->_charset_eYou;
|
||||
$this->_add_hdr('SUBJECT', $this->encode_hdrs($subject));
|
||||
$this->_charset = $temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* E-mail body
|
||||
*
|
||||
* @access public
|
||||
* @param string $body body
|
||||
*/
|
||||
function body($body)
|
||||
{
|
||||
$body = preg_replace("/([\n|\r])\.([\n|\r])/", "$1..$2", $body);
|
||||
|
||||
if($this->_CTEncoding == 'base64')
|
||||
$this->_body = sprintf("\r\n%s", base64_encode($body));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send the mail
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function send()
|
||||
{
|
||||
$resp = $this->_cmd('DATA');
|
||||
if ($this->_is_closed($resp)) {
|
||||
$this->close();
|
||||
return false;
|
||||
}
|
||||
foreach ($this->_hdrs as $header) {
|
||||
fwrite($this->_connection, $header);
|
||||
if ($this->_debug) {
|
||||
printf($header);
|
||||
}
|
||||
}
|
||||
fwrite($this->_connection,$this->_body);
|
||||
fwrite($this->_connection, "\r\n.\r\n");
|
||||
$resp = trim($this->_read());
|
||||
if ($this->_debug){
|
||||
printf("%s\r\n", $this->_body);
|
||||
printf("\r\n.\r\n");
|
||||
printf('%s', $resp);
|
||||
}
|
||||
if ((int)$resp{0} != 2) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* encode headers
|
||||
*
|
||||
* @access private
|
||||
* @param string $input
|
||||
* @return string
|
||||
*/
|
||||
function encode_hdrs($input)
|
||||
{
|
||||
$replacement = preg_replace('/([\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $input);
|
||||
|
||||
$input = str_replace($input, sprintf('=?%s?Q?%s?=', $this->_charset, $replacement), $input);
|
||||
return $input;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user