Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php class SMTP { const VERSION = "\x35\56\x32\56\x31\64"; const CRLF = "\xd\xa"; const ..

Decoded Output download

<?php
 class SMTP { const VERSION = "5.2.14"; const CRLF = "\xd\xa"; const DEFAULT_SMTP_PORT = 25; const MAX_LINE_LENGTH = 998; const DEBUG_OFF = 0; const DEBUG_CLIENT = 1; const DEBUG_SERVER = 2; const DEBUG_CONNECTION = 3; const DEBUG_LOWLEVEL = 4; public $Version = "5.2.14"; public $SMTP_PORT = 25; public $CRLF = "
\xa"; public $do_debug = self::DEBUG_OFF; public $Debugoutput = "echo"; public $do_verp = false; public $Timeout = 300; public $Timelimit = 300; protected $smtp_conn; protected $error = array("error" => '', "detail" => '', "smtp_code" => '', "smtp_code_ex" => ''); protected $helo_rply = null; protected $server_caps = null; protected $last_reply = ''; protected function edebug($str, $level = 0) { if ($level > $this->do_debug) { return; } if (!in_array($this->Debugoutput, array("error_log", "html", "echo")) and is_callable($this->Debugoutput)) { call_user_func($this->Debugoutput, $str, $this->do_debug); return; } switch ($this->Debugoutput) { case "error_log": error_log($str); break; case "html": echo htmlentities(preg_replace("/[\r\n]+/", '', $str), ENT_QUOTES, "UTF-8") . "<br>\xa"; break; case "echo": default: $str = preg_replace("/(\r\n|\r|\n)/ms", "\xa", $str); echo gmdate("Y-m-d H:i:s") . "	" . str_replace("\xa", "\xa                   	                  ", trim($str)) . "\xa"; } } public function connect($host, $port = null, $timeout = 30, $options = array()) { static $streamok; if (is_null($streamok)) { $streamok = function_exists("stream_socket_client"); } $this->setError(''); if ($this->connected()) { $this->setError("Already connected to a server"); return false; } if (empty($port)) { $port = self::DEFAULT_SMTP_PORT; } $this->edebug("Connection: opening to {$host}:{$port}, timeout={$timeout}, options=" . var_export($options, true), self::DEBUG_CONNECTION); $errno = 0; $errstr = ''; if ($streamok) { $socket_context = stream_context_create($options); $this->smtp_conn = @stream_socket_client($host . ":" . $port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $socket_context); } else { $this->edebug("Connection: stream_socket_client not available, falling back to fsockopen", self::DEBUG_CONNECTION); $this->smtp_conn = fsockopen($host, $port, $errno, $errstr, $timeout); } if (!is_resource($this->smtp_conn)) { $this->setError("Failed to connect to server", $errno, $errstr); $this->edebug("SMTP ERROR: " . $this->error["error"] . ": {$errstr} ({$errno})", self::DEBUG_CLIENT); return false; } $this->edebug("Connection: opened", self::DEBUG_CONNECTION); if (substr(PHP_OS, 0, 3) != "WIN") { $max = ini_get("max_execution_time"); if ($max != 0 && $timeout > $max) { @set_time_limit($timeout); } stream_set_timeout($this->smtp_conn, $timeout, 0); } $announce = $this->get_lines(); $this->edebug("SERVER -> CLIENT: " . $announce, self::DEBUG_SERVER); return true; } public function startTLS() { if (!$this->sendCommand("STARTTLS", "STARTTLS", 220)) { return false; } if (!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { return false; } return true; } public function authenticate($username, $password, $authtype = null, $realm = '', $workstation = '', $OAuth = null) { if (!$this->server_caps) { $this->setError("Authentication is not allowed before HELO/EHLO"); return false; } if (array_key_exists("EHLO", $this->server_caps)) { if (!array_key_exists("AUTH", $this->server_caps)) { $this->setError("Authentication is not allowed at this stage"); return false; } self::edebug("Auth method requested: " . ($authtype ? $authtype : "UNKNOWN"), self::DEBUG_LOWLEVEL); self::edebug("Auth methods available on the server: " . implode(",", $this->server_caps["AUTH"]), self::DEBUG_LOWLEVEL); if (empty($authtype)) { foreach (array("LOGIN", "CRAM-MD5", "PLAIN") as $method) { if (in_array($method, $this->server_caps["AUTH"])) { $authtype = $method; break; } } if (empty($authtype)) { $this->setError("No supported authentication methods found"); return false; } self::edebug("Auth method selected: " . $authtype, self::DEBUG_LOWLEVEL); } if (!in_array($authtype, $this->server_caps["AUTH"])) { $this->setError("The requested authentication method "{$authtype}" is not supported by the server"); return false; } } elseif (empty($authtype)) { $authtype = "LOGIN"; } switch ($authtype) { case "PLAIN": if (!$this->sendCommand("AUTH", "AUTH PLAIN", 334)) { return false; } if (!$this->sendCommand("User & Password", base64_encode("\x0" . $username . "\0" . $password), 235)) { return false; } break; case "LOGIN": if (!$this->sendCommand("AUTH", "AUTH LOGIN", 334)) { return false; } if (!$this->sendCommand("Username", base64_encode($username), 334)) { return false; } if (!$this->sendCommand("Password", base64_encode($password), 235)) { return false; } break; case "CRAM-MD5": if (!$this->sendCommand("AUTH CRAM-MD5", "AUTH CRAM-MD5", 334)) { return false; } $challenge = base64_decode(substr($this->last_reply, 4)); $response = $username . " " . $this->hmac($challenge, $password); return $this->sendCommand("Username", base64_encode($response), 235); default: $this->setError("Authentication method "{$authtype}" is not supported"); return false; } return true; } protected function hmac($data, $key) { if (function_exists("hash_hmac")) { return hash_hmac("md5", $data, $key); } $bytelen = 64; if (strlen($key) > $bytelen) { $key = pack("H*", md5($key)); } $key = str_pad($key, $bytelen, chr(0)); $ipad = str_pad('', $bytelen, chr(54)); $opad = str_pad('', $bytelen, chr(92)); $k_ipad = $key ^ $ipad; $k_opad = $key ^ $opad; return md5($k_opad . pack("H*", md5($k_ipad . $data))); } public function connected() { if (is_resource($this->smtp_conn)) { $sock_status = stream_get_meta_data($this->smtp_conn); if ($sock_status["eof"]) { $this->edebug("SMTP NOTICE: EOF caught while checking if connected", self::DEBUG_CLIENT); $this->close(); return false; } return true; } return false; } public function close() { $this->setError(''); $this->server_caps = null; $this->helo_rply = null; if (is_resource($this->smtp_conn)) { fclose($this->smtp_conn); $this->smtp_conn = null; $this->edebug("Connection: closed", self::DEBUG_CONNECTION); } } public function data($msg_data) { if (!$this->sendCommand("DATA", "DATA", 354)) { return false; } $lines = explode("
", str_replace(array("\xd
", "\xd"), "
", $msg_data)); $field = substr($lines[0], 0, strpos($lines[0], ":")); $in_headers = false; if (!empty($field) && strpos($field, " ") === false) { $in_headers = true; } foreach ($lines as $line) { $lines_out = array(); if ($in_headers and $line == '') { $in_headers = false; } while (isset($line[self::MAX_LINE_LENGTH])) { $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), " "); if (!$pos) { $pos = self::MAX_LINE_LENGTH - 1; $lines_out[] = substr($line, 0, $pos); $line = substr($line, $pos); } else { $lines_out[] = substr($line, 0, $pos); $line = substr($line, $pos + 1); } if ($in_headers) { $line = "\x9" . $line; } } $lines_out[] = $line; foreach ($lines_out as $line_out) { if (!empty($line_out) and $line_out[0] == ".") { $line_out = "." . $line_out; } $this->client_send($line_out . self::CRLF); } } $savetimelimit = $this->Timelimit; $this->Timelimit = $this->Timelimit * 2; $result = $this->sendCommand("DATA END", ".", 250); $this->Timelimit = $savetimelimit; return $result; } public function hello($host = '') { return (bool) ($this->sendHello("EHLO", $host) or $this->sendHello("HELO", $host)); } protected function sendHello($hello, $host) { $noerror = $this->sendCommand($hello, $hello . " " . $host, 250); $this->helo_rply = $this->last_reply; if ($noerror) { $this->parseHelloFields($hello); } else { $this->server_caps = null; } return $noerror; } protected function parseHelloFields($type) { $this->server_caps = array(); $lines = explode("\xa", $this->last_reply); foreach ($lines as $n => $s) { $s = trim(substr($s, 4)); if (empty($s)) { continue; } $fields = explode(" ", $s); if (!empty($fields)) { if (!$n) { $name = $type; $fields = $fields[0]; } else { $name = array_shift($fields); switch ($name) { case "SIZE": $fields = $fields ? $fields[0] : 0; break; case "AUTH": if (!is_array($fields)) { $fields = array(); } break; default: $fields = true; } } $this->server_caps[$name] = $fields; } } } public function mail($from) { $useVerp = $this->do_verp ? " XVERP" : ''; return $this->sendCommand("MAIL FROM", "MAIL FROM:<" . $from . ">" . $useVerp, 250); } public function quit($close_on_error = true) { $noerror = $this->sendCommand("QUIT", "QUIT", 221); $err = $this->error; if ($noerror or $close_on_error) { $this->close(); $this->error = $err; } return $noerror; } public function recipient($address) { return $this->sendCommand("RCPT TO", "RCPT TO:<" . $address . ">", array(250, 251)); } public function reset() { return $this->sendCommand("RSET", "RSET", 250); } protected function sendCommand($command, $commandstring, $expect) { if (!$this->connected()) { $this->setError("Called {$command} without being connected"); return false; } if (strpos($commandstring, "\xa") !== false or strpos($commandstring, "
") !== false) { $this->setError("Command '{$command}' contained line breaks"); return false; } $this->client_send($commandstring . self::CRLF); $this->last_reply = $this->get_lines(); $matches = array(); if (preg_match("/^([0-9]{3})[ -](?:([0-9]\.[0-9]\.[0-9]) )?/", $this->last_reply, $matches)) { $code = $matches[1]; $code_ex = count($matches) > 2 ? $matches[2] : null; $detail = preg_replace("/{$code}[ -]" . ($code_ex ? str_replace(".", "\.", $code_ex) . " " : '') . "/m", '', $this->last_reply); } else { $code = substr($this->last_reply, 0, 3); $code_ex = null; $detail = substr($this->last_reply, 4); } $this->edebug("SERVER -> CLIENT: " . $this->last_reply, self::DEBUG_SERVER); if (!in_array($code, (array) $expect)) { $this->setError("{$command} command failed", $detail, $code, $code_ex); $this->edebug("SMTP ERROR: " . $this->error["error"] . ": " . $this->last_reply, self::DEBUG_CLIENT); return false; } $this->setError(''); return true; } public function sendAndMail($from) { return $this->sendCommand("SAML", "SAML FROM:{$from}", 250); } public function verify($name) { return $this->sendCommand("VRFY", "VRFY {$name}", array(250, 251)); } public function noop() { return $this->sendCommand("NOOP", "NOOP", 250); } public function turn() { $this->setError("The SMTP TURN command is not implemented"); $this->edebug("SMTP NOTICE: " . $this->error["error"], self::DEBUG_CLIENT); return false; } public function client_send($data) { $this->edebug("CLIENT -> SERVER: {$data}", self::DEBUG_CLIENT); return fwrite($this->smtp_conn, $data); } public function getError() { return $this->error; } public function getServerExtList() { return $this->server_caps; } public function getServerExt($name) { if (!$this->server_caps) { $this->setError("No HELO/EHLO was sent"); return null; } if (!array_key_exists($name, $this->server_caps)) { if ($name == "HELO") { return $this->server_caps["EHLO"]; } if ($name == "EHLO" || array_key_exists("EHLO", $this->server_caps)) { return false; } $this->setError("HELO handshake was used. Client knows nothing about server extensions"); return null; } return $this->server_caps[$name]; } public function getLastReply() { return $this->last_reply; } protected function get_lines() { if (!is_resource($this->smtp_conn)) { return ''; } $data = ''; $endtime = 0; stream_set_timeout($this->smtp_conn, $this->Timeout); if ($this->Timelimit > 0) { $endtime = time() + $this->Timelimit; } while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { $str = @fgets($this->smtp_conn, 515); $this->edebug("SMTP -> get_lines(): $data is "{$data}"", self::DEBUG_LOWLEVEL); $this->edebug("SMTP -> get_lines(): $str is  "{$str}"", self::DEBUG_LOWLEVEL); $data .= $str; if (isset($str[3]) and $str[3] == " ") { break; } $info = stream_get_meta_data($this->smtp_conn); if ($info["timed_out"]) { $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " sec)", self::DEBUG_LOWLEVEL); break; } if ($endtime and time() > $endtime) { $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " sec)", self::DEBUG_LOWLEVEL); break; } } return $data; } public function setVerp($enabled = false) { $this->do_verp = $enabled; } public function getVerp() { return $this->do_verp; } protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '') { $this->error = array("error" => $message, "detail" => $detail, "smtp_code" => $smtp_code, "smtp_code_ex" => $smtp_code_ex); } public function setDebugOutput($method = "echo") { $this->Debugoutput = $method; } public function getDebugOutput() { return $this->Debugoutput; } public function setDebugLevel($level = 0) { $this->do_debug = $level; } public function getDebugLevel() { return $this->do_debug; } public function setTimeout($timeout = 0) { $this->Timeout = $timeout; } public function getTimeout() { return $this->Timeout; } } ?>

Did this file decode correctly?

Original Code

<?php
 class SMTP { const VERSION = "\x35\56\x32\56\x31\64"; const CRLF = "\xd\xa"; const DEFAULT_SMTP_PORT = 25; const MAX_LINE_LENGTH = 998; const DEBUG_OFF = 0; const DEBUG_CLIENT = 1; const DEBUG_SERVER = 2; const DEBUG_CONNECTION = 3; const DEBUG_LOWLEVEL = 4; public $Version = "\65\56\x32\x2e\61\x34"; public $SMTP_PORT = 25; public $CRLF = "\15\xa"; public $do_debug = self::DEBUG_OFF; public $Debugoutput = "\145\143\150\157"; public $do_verp = false; public $Timeout = 300; public $Timelimit = 300; protected $smtp_conn; protected $error = array("\145\162\x72\157\x72" => '', "\x64\x65\x74\x61\151\x6c" => '', "\163\x6d\x74\160\x5f\x63\157\x64\x65" => '', "\163\155\164\160\137\x63\x6f\144\x65\x5f\145\170" => ''); protected $helo_rply = null; protected $server_caps = null; protected $last_reply = ''; protected function edebug($str, $level = 0) { if ($level > $this->do_debug) { return; } if (!in_array($this->Debugoutput, array("\145\x72\162\x6f\x72\x5f\x6c\157\147", "\150\164\155\x6c", "\145\x63\x68\x6f")) and is_callable($this->Debugoutput)) { call_user_func($this->Debugoutput, $str, $this->do_debug); return; } switch ($this->Debugoutput) { case "\145\162\162\157\162\137\154\x6f\147": error_log($str); break; case "\150\164\155\154": echo htmlentities(preg_replace("\57\133\x5c\x72\134\156\135\x2b\57", '', $str), ENT_QUOTES, "\x55\x54\x46\x2d\70") . "\x3c\x62\162\x3e\xa"; break; case "\x65\x63\150\x6f": default: $str = preg_replace("\x2f\x28\x5c\x72\x5c\x6e\x7c\134\x72\174\134\x6e\x29\x2f\x6d\163", "\xa", $str); echo gmdate("\131\x2d\x6d\x2d\x64\40\x48\72\151\x3a\163") . "\11" . str_replace("\xa", "\xa\x20\40\40\40\40\x20\40\x20\x20\x20\x20\40\x20\x20\40\40\x20\40\x20\11\x20\x20\x20\x20\x20\x20\40\40\40\40\40\x20\x20\40\40\40\x20\x20", trim($str)) . "\xa"; } } public function connect($host, $port = null, $timeout = 30, $options = array()) { static $streamok; if (is_null($streamok)) { $streamok = function_exists("\x73\x74\x72\x65\x61\x6d\x5f\x73\157\x63\x6b\145\x74\137\143\x6c\x69\145\x6e\x74"); } $this->setError(''); if ($this->connected()) { $this->setError("\x41\x6c\162\x65\141\x64\171\x20\143\x6f\x6e\x6e\x65\x63\x74\x65\x64\x20\x74\x6f\x20\x61\40\x73\x65\x72\166\x65\x72"); return false; } if (empty($port)) { $port = self::DEFAULT_SMTP_PORT; } $this->edebug("\103\x6f\x6e\156\145\143\x74\151\x6f\156\x3a\40\157\160\145\156\151\156\x67\x20\164\157\x20{$host}\72{$port}\x2c\40\164\151\x6d\145\x6f\165\164\x3d{$timeout}\x2c\40\x6f\x70\164\151\157\156\163\x3d" . var_export($options, true), self::DEBUG_CONNECTION); $errno = 0; $errstr = ''; if ($streamok) { $socket_context = stream_context_create($options); $this->smtp_conn = @stream_socket_client($host . "\72" . $port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $socket_context); } else { $this->edebug("\103\157\x6e\156\x65\143\164\151\157\x6e\72\40\163\x74\162\x65\x61\x6d\x5f\163\x6f\143\153\145\x74\x5f\x63\154\x69\145\x6e\164\40\156\157\164\x20\141\166\x61\151\x6c\141\x62\x6c\145\54\x20\x66\x61\x6c\x6c\151\156\147\40\142\x61\143\x6b\40\x74\x6f\40\x66\x73\157\x63\153\x6f\160\x65\156", self::DEBUG_CONNECTION); $this->smtp_conn = fsockopen($host, $port, $errno, $errstr, $timeout); } if (!is_resource($this->smtp_conn)) { $this->setError("\x46\141\x69\x6c\x65\144\40\x74\157\x20\x63\x6f\156\x6e\145\143\x74\40\164\157\40\163\145\x72\166\x65\x72", $errno, $errstr); $this->edebug("\x53\115\124\x50\x20\x45\x52\x52\x4f\x52\72\x20" . $this->error["\x65\x72\x72\157\162"] . "\72\x20{$errstr}\40\50{$errno}\51", self::DEBUG_CLIENT); return false; } $this->edebug("\x43\x6f\156\x6e\145\x63\164\151\157\x6e\72\40\x6f\160\x65\156\x65\144", self::DEBUG_CONNECTION); if (substr(PHP_OS, 0, 3) != "\127\x49\x4e") { $max = ini_get("\x6d\141\170\x5f\x65\170\145\143\x75\164\x69\157\x6e\137\x74\151\155\x65"); if ($max != 0 && $timeout > $max) { @set_time_limit($timeout); } stream_set_timeout($this->smtp_conn, $timeout, 0); } $announce = $this->get_lines(); $this->edebug("\123\x45\x52\x56\x45\x52\x20\55\76\40\x43\x4c\111\x45\x4e\x54\x3a\40" . $announce, self::DEBUG_SERVER); return true; } public function startTLS() { if (!$this->sendCommand("\x53\x54\101\x52\x54\124\x4c\123", "\123\124\x41\122\x54\x54\x4c\123", 220)) { return false; } if (!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { return false; } return true; } public function authenticate($username, $password, $authtype = null, $realm = '', $workstation = '', $OAuth = null) { if (!$this->server_caps) { $this->setError("\101\x75\164\150\x65\x6e\x74\151\143\141\x74\151\x6f\x6e\40\x69\163\40\156\x6f\x74\40\141\x6c\154\157\x77\145\144\x20\142\x65\146\x6f\x72\145\x20\110\x45\114\x4f\57\105\x48\x4c\x4f"); return false; } if (array_key_exists("\x45\110\114\x4f", $this->server_caps)) { if (!array_key_exists("\x41\125\x54\x48", $this->server_caps)) { $this->setError("\x41\165\164\150\x65\x6e\164\x69\x63\141\x74\151\157\156\x20\x69\x73\40\x6e\x6f\164\40\141\x6c\154\x6f\x77\145\144\x20\x61\x74\x20\164\x68\151\163\40\163\x74\x61\x67\145"); return false; } self::edebug("\101\165\164\x68\40\x6d\x65\x74\150\x6f\144\x20\162\145\161\x75\145\163\x74\x65\144\72\x20" . ($authtype ? $authtype : "\125\116\113\116\117\127\116"), self::DEBUG_LOWLEVEL); self::edebug("\x41\x75\164\150\x20\x6d\145\164\150\x6f\x64\x73\40\141\x76\x61\x69\154\141\142\x6c\x65\40\157\x6e\40\164\x68\145\40\163\x65\x72\166\145\x72\72\40" . implode("\54", $this->server_caps["\x41\125\124\110"]), self::DEBUG_LOWLEVEL); if (empty($authtype)) { foreach (array("\x4c\117\x47\x49\x4e", "\103\x52\101\x4d\x2d\115\x44\x35", "\x50\114\x41\x49\116") as $method) { if (in_array($method, $this->server_caps["\101\x55\124\x48"])) { $authtype = $method; break; } } if (empty($authtype)) { $this->setError("\x4e\157\40\163\x75\x70\x70\157\x72\164\145\x64\40\x61\165\164\150\x65\x6e\164\151\x63\141\x74\x69\x6f\156\40\x6d\x65\x74\x68\157\x64\163\40\146\157\165\x6e\x64"); return false; } self::edebug("\x41\165\x74\x68\40\x6d\145\x74\x68\157\x64\40\163\145\154\145\x63\164\145\x64\x3a\x20" . $authtype, self::DEBUG_LOWLEVEL); } if (!in_array($authtype, $this->server_caps["\x41\125\x54\x48"])) { $this->setError("\x54\150\x65\40\162\x65\161\165\145\163\164\x65\x64\x20\x61\x75\x74\150\145\x6e\164\151\143\141\164\151\x6f\x6e\x20\155\x65\164\150\157\144\x20\x22{$authtype}\x22\x20\x69\163\40\x6e\x6f\164\40\163\165\160\160\157\162\164\x65\x64\x20\x62\x79\40\x74\150\x65\40\163\145\x72\x76\145\162"); return false; } } elseif (empty($authtype)) { $authtype = "\114\117\x47\111\116"; } switch ($authtype) { case "\x50\x4c\x41\111\x4e": if (!$this->sendCommand("\x41\125\124\110", "\x41\125\x54\x48\x20\120\x4c\101\x49\x4e", 334)) { return false; } if (!$this->sendCommand("\x55\x73\145\x72\40\46\40\120\141\163\x73\x77\157\162\x64", base64_encode("\x0" . $username . "\0" . $password), 235)) { return false; } break; case "\114\x4f\x47\x49\116": if (!$this->sendCommand("\101\125\x54\110", "\x41\x55\124\110\x20\114\x4f\x47\x49\116", 334)) { return false; } if (!$this->sendCommand("\125\163\145\162\156\x61\155\145", base64_encode($username), 334)) { return false; } if (!$this->sendCommand("\120\x61\163\x73\x77\x6f\162\x64", base64_encode($password), 235)) { return false; } break; case "\x43\122\x41\115\x2d\115\x44\x35": if (!$this->sendCommand("\x41\125\124\110\x20\x43\x52\x41\x4d\x2d\x4d\104\x35", "\x41\125\x54\x48\x20\103\x52\101\115\x2d\x4d\104\65", 334)) { return false; } $challenge = base64_decode(substr($this->last_reply, 4)); $response = $username . "\x20" . $this->hmac($challenge, $password); return $this->sendCommand("\125\163\x65\x72\x6e\x61\155\x65", base64_encode($response), 235); default: $this->setError("\x41\165\164\150\x65\156\164\151\143\x61\164\x69\x6f\x6e\40\x6d\145\x74\150\x6f\x64\40\42{$authtype}\42\40\151\163\40\x6e\x6f\164\x20\x73\x75\x70\160\157\162\x74\x65\144"); return false; } return true; } protected function hmac($data, $key) { if (function_exists("\x68\x61\x73\x68\137\x68\x6d\141\143")) { return hash_hmac("\155\x64\65", $data, $key); } $bytelen = 64; if (strlen($key) > $bytelen) { $key = pack("\x48\x2a", md5($key)); } $key = str_pad($key, $bytelen, chr(0)); $ipad = str_pad('', $bytelen, chr(54)); $opad = str_pad('', $bytelen, chr(92)); $k_ipad = $key ^ $ipad; $k_opad = $key ^ $opad; return md5($k_opad . pack("\x48\x2a", md5($k_ipad . $data))); } public function connected() { if (is_resource($this->smtp_conn)) { $sock_status = stream_get_meta_data($this->smtp_conn); if ($sock_status["\x65\x6f\146"]) { $this->edebug("\x53\115\x54\120\x20\116\117\x54\111\103\105\72\40\x45\117\x46\x20\143\x61\165\147\150\164\x20\x77\x68\151\154\x65\x20\143\150\145\143\x6b\x69\156\147\x20\x69\x66\40\x63\x6f\x6e\156\145\143\x74\145\144", self::DEBUG_CLIENT); $this->close(); return false; } return true; } return false; } public function close() { $this->setError(''); $this->server_caps = null; $this->helo_rply = null; if (is_resource($this->smtp_conn)) { fclose($this->smtp_conn); $this->smtp_conn = null; $this->edebug("\x43\157\156\x6e\x65\x63\x74\x69\157\156\72\x20\x63\154\157\x73\145\144", self::DEBUG_CONNECTION); } } public function data($msg_data) { if (!$this->sendCommand("\104\101\x54\x41", "\x44\101\124\x41", 354)) { return false; } $lines = explode("\12", str_replace(array("\xd\12", "\xd"), "\12", $msg_data)); $field = substr($lines[0], 0, strpos($lines[0], "\72")); $in_headers = false; if (!empty($field) && strpos($field, "\x20") === false) { $in_headers = true; } foreach ($lines as $line) { $lines_out = array(); if ($in_headers and $line == '') { $in_headers = false; } while (isset($line[self::MAX_LINE_LENGTH])) { $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), "\40"); if (!$pos) { $pos = self::MAX_LINE_LENGTH - 1; $lines_out[] = substr($line, 0, $pos); $line = substr($line, $pos); } else { $lines_out[] = substr($line, 0, $pos); $line = substr($line, $pos + 1); } if ($in_headers) { $line = "\x9" . $line; } } $lines_out[] = $line; foreach ($lines_out as $line_out) { if (!empty($line_out) and $line_out[0] == "\x2e") { $line_out = "\x2e" . $line_out; } $this->client_send($line_out . self::CRLF); } } $savetimelimit = $this->Timelimit; $this->Timelimit = $this->Timelimit * 2; $result = $this->sendCommand("\104\x41\x54\101\40\x45\x4e\x44", "\56", 250); $this->Timelimit = $savetimelimit; return $result; } public function hello($host = '') { return (bool) ($this->sendHello("\x45\x48\114\x4f", $host) or $this->sendHello("\x48\105\x4c\x4f", $host)); } protected function sendHello($hello, $host) { $noerror = $this->sendCommand($hello, $hello . "\40" . $host, 250); $this->helo_rply = $this->last_reply; if ($noerror) { $this->parseHelloFields($hello); } else { $this->server_caps = null; } return $noerror; } protected function parseHelloFields($type) { $this->server_caps = array(); $lines = explode("\xa", $this->last_reply); foreach ($lines as $n => $s) { $s = trim(substr($s, 4)); if (empty($s)) { continue; } $fields = explode("\40", $s); if (!empty($fields)) { if (!$n) { $name = $type; $fields = $fields[0]; } else { $name = array_shift($fields); switch ($name) { case "\123\x49\132\x45": $fields = $fields ? $fields[0] : 0; break; case "\x41\125\x54\110": if (!is_array($fields)) { $fields = array(); } break; default: $fields = true; } } $this->server_caps[$name] = $fields; } } } public function mail($from) { $useVerp = $this->do_verp ? "\40\130\126\105\x52\120" : ''; return $this->sendCommand("\x4d\101\111\114\x20\x46\x52\x4f\x4d", "\115\101\x49\114\x20\106\122\117\x4d\x3a\x3c" . $from . "\x3e" . $useVerp, 250); } public function quit($close_on_error = true) { $noerror = $this->sendCommand("\121\x55\111\124", "\121\125\x49\x54", 221); $err = $this->error; if ($noerror or $close_on_error) { $this->close(); $this->error = $err; } return $noerror; } public function recipient($address) { return $this->sendCommand("\122\x43\120\124\x20\x54\x4f", "\x52\x43\120\124\40\124\x4f\x3a\74" . $address . "\x3e", array(250, 251)); } public function reset() { return $this->sendCommand("\x52\123\105\124", "\x52\x53\x45\124", 250); } protected function sendCommand($command, $commandstring, $expect) { if (!$this->connected()) { $this->setError("\103\141\x6c\154\145\144\40{$command}\40\167\151\x74\x68\x6f\165\164\x20\142\145\151\156\147\x20\x63\157\x6e\x6e\x65\143\164\145\144"); return false; } if (strpos($commandstring, "\xa") !== false or strpos($commandstring, "\15") !== false) { $this->setError("\x43\x6f\155\x6d\x61\x6e\x64\40\x27{$command}\47\x20\143\x6f\x6e\x74\x61\x69\156\145\144\x20\x6c\x69\156\145\40\x62\162\x65\141\x6b\x73"); return false; } $this->client_send($commandstring . self::CRLF); $this->last_reply = $this->get_lines(); $matches = array(); if (preg_match("\57\136\50\133\x30\x2d\71\x5d\x7b\x33\x7d\51\133\40\55\135\x28\x3f\72\50\x5b\x30\55\x39\x5d\134\x2e\133\x30\x2d\71\x5d\x5c\56\x5b\x30\55\71\135\x29\x20\51\77\57", $this->last_reply, $matches)) { $code = $matches[1]; $code_ex = count($matches) > 2 ? $matches[2] : null; $detail = preg_replace("\57{$code}\133\x20\55\135" . ($code_ex ? str_replace("\56", "\x5c\x2e", $code_ex) . "\x20" : '') . "\x2f\x6d", '', $this->last_reply); } else { $code = substr($this->last_reply, 0, 3); $code_ex = null; $detail = substr($this->last_reply, 4); } $this->edebug("\x53\105\122\x56\105\122\x20\x2d\x3e\40\x43\x4c\x49\x45\116\124\x3a\40" . $this->last_reply, self::DEBUG_SERVER); if (!in_array($code, (array) $expect)) { $this->setError("{$command}\40\143\157\x6d\x6d\x61\156\144\x20\x66\141\151\154\145\x64", $detail, $code, $code_ex); $this->edebug("\x53\115\x54\x50\40\105\x52\x52\x4f\122\72\40" . $this->error["\x65\162\x72\x6f\162"] . "\x3a\40" . $this->last_reply, self::DEBUG_CLIENT); return false; } $this->setError(''); return true; } public function sendAndMail($from) { return $this->sendCommand("\123\101\x4d\114", "\x53\101\x4d\x4c\x20\x46\122\117\115\x3a{$from}", 250); } public function verify($name) { return $this->sendCommand("\126\122\x46\131", "\126\122\x46\x59\40{$name}", array(250, 251)); } public function noop() { return $this->sendCommand("\116\117\117\x50", "\116\117\x4f\x50", 250); } public function turn() { $this->setError("\x54\150\145\x20\x53\115\124\120\x20\x54\x55\122\x4e\x20\x63\157\x6d\155\141\x6e\144\40\x69\x73\x20\x6e\157\x74\x20\151\x6d\160\x6c\145\x6d\145\156\x74\145\x64"); $this->edebug("\123\x4d\124\120\x20\116\117\124\111\x43\105\x3a\x20" . $this->error["\x65\162\x72\157\x72"], self::DEBUG_CLIENT); return false; } public function client_send($data) { $this->edebug("\103\x4c\111\105\116\x54\x20\55\x3e\40\x53\x45\x52\x56\105\x52\x3a\x20{$data}", self::DEBUG_CLIENT); return fwrite($this->smtp_conn, $data); } public function getError() { return $this->error; } public function getServerExtList() { return $this->server_caps; } public function getServerExt($name) { if (!$this->server_caps) { $this->setError("\x4e\x6f\x20\110\x45\114\x4f\x2f\105\110\114\x4f\x20\x77\x61\x73\40\163\x65\x6e\164"); return null; } if (!array_key_exists($name, $this->server_caps)) { if ($name == "\110\x45\114\117") { return $this->server_caps["\x45\x48\x4c\117"]; } if ($name == "\x45\110\x4c\117" || array_key_exists("\105\110\x4c\117", $this->server_caps)) { return false; } $this->setError("\x48\x45\x4c\117\x20\150\x61\x6e\x64\x73\150\x61\x6b\145\40\167\141\163\40\x75\163\x65\144\x2e\40\103\154\151\145\156\164\x20\x6b\156\x6f\167\163\40\x6e\x6f\164\x68\x69\156\147\40\x61\142\157\165\x74\40\163\145\x72\x76\145\x72\x20\145\x78\x74\x65\156\163\x69\157\156\163"); return null; } return $this->server_caps[$name]; } public function getLastReply() { return $this->last_reply; } protected function get_lines() { if (!is_resource($this->smtp_conn)) { return ''; } $data = ''; $endtime = 0; stream_set_timeout($this->smtp_conn, $this->Timeout); if ($this->Timelimit > 0) { $endtime = time() + $this->Timelimit; } while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { $str = @fgets($this->smtp_conn, 515); $this->edebug("\123\x4d\124\x50\x20\x2d\76\40\x67\145\164\x5f\154\x69\x6e\145\x73\50\x29\x3a\x20\x24\144\141\164\141\x20\x69\163\40\42{$data}\42", self::DEBUG_LOWLEVEL); $this->edebug("\x53\x4d\124\x50\40\x2d\x3e\40\x67\x65\x74\137\154\151\156\145\163\x28\x29\72\x20\44\x73\164\162\x20\151\x73\40\40\x22{$str}\x22", self::DEBUG_LOWLEVEL); $data .= $str; if (isset($str[3]) and $str[3] == "\40") { break; } $info = stream_get_meta_data($this->smtp_conn); if ($info["\164\151\x6d\145\144\137\157\165\x74"]) { $this->edebug("\x53\115\124\120\x20\x2d\x3e\40\147\145\164\137\x6c\151\x6e\145\x73\x28\x29\x3a\40\164\x69\155\x65\144\x2d\x6f\x75\164\x20\x28" . $this->Timeout . "\x20\x73\145\x63\51", self::DEBUG_LOWLEVEL); break; } if ($endtime and time() > $endtime) { $this->edebug("\x53\x4d\124\x50\x20\x2d\x3e\40\x67\x65\164\137\154\151\156\x65\163\x28\x29\x3a\40\x74\x69\155\145\x6c\x69\x6d\x69\x74\40\162\x65\x61\x63\150\145\x64\x20\x28" . $this->Timelimit . "\x20\163\145\143\x29", self::DEBUG_LOWLEVEL); break; } } return $data; } public function setVerp($enabled = false) { $this->do_verp = $enabled; } public function getVerp() { return $this->do_verp; } protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '') { $this->error = array("\145\162\x72\157\162" => $message, "\144\145\164\x61\151\x6c" => $detail, "\x73\x6d\x74\160\x5f\143\157\144\145" => $smtp_code, "\x73\x6d\x74\160\x5f\x63\x6f\x64\145\137\x65\x78" => $smtp_code_ex); } public function setDebugOutput($method = "\145\143\x68\x6f") { $this->Debugoutput = $method; } public function getDebugOutput() { return $this->Debugoutput; } public function setDebugLevel($level = 0) { $this->do_debug = $level; } public function getDebugLevel() { return $this->do_debug; } public function setTimeout($timeout = 0) { $this->Timeout = $timeout; } public function getTimeout() { return $this->Timeout; } }

Function Calls

None

Variables

None

Stats

MD5 9048da0e38b0de295d6076a0420effac
Eval Count 0
Decode Time 92 ms