/**
  * Provides a fixed length string text ; if longer than allowed length will add trailing dots (...)
  *
  * @param 	STRING 	$ystr 				:: The text string to be processed
  * @param 	STRING 	$ylen 				:: The fixed length of the string
  * @param 	BOOLEAN	$y_cut_words		:: if TRUE, will CUT last word to provide a fixed length ; if FALSE will eliminate unterminate last word ; default is TRUE
  *
  * @return 	STRING						:: The processed string (text)
  */
 public static function text_endpoints($ystr, $ylen, $y_cut_words = true, $y_dots = '...')
 {
     //--
     $ystr = (string) trim((string) $ystr);
     $ylen = Smart::format_number_int($ylen, '+');
     //--
     if ($ylen > 0 and SmartUnicode::str_len($ystr) > $ylen) {
         $ystr = (string) SmartUnicode::sub_str($ystr, 0, $ylen - 3);
         if (!$y_cut_words) {
             $ystr = (string) preg_replace('/\\s+?(\\S+)?$/', '', (string) $ystr);
         }
         //end if
         $ystr .= (string) $y_dots;
     }
     //end if
     //--
     return (string) $ystr;
     //--
 }
 private function blockTableContinue($Line, array $Block)
 {
     //--
     if (isset($Block['interrupted'])) {
         return;
     }
     //end if
     //--
     if ($Line['text'][0] === '|' or strpos($Line['text'], '|')) {
         // here strpos must not check with true/false, because the first character is already checked and must not be checked again
         //--
         $Elements = array();
         //--
         $row = $Line['text'];
         $row = trim($row);
         $row = trim($row, '|');
         //--
         preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches);
         //--
         foreach ($matches[0] as $index => $cell) {
             //--
             $cell = trim($cell);
             //--
             $Element = array('name' => 'td', 'handler' => 'line');
             //-- unixman
             $matches = array();
             if (preg_match('/' . $this->regexAttribute . '/', $cell, $matches)) {
                 if (!is_array($Element['attributes'])) {
                     $Element['attributes'] = array();
                 }
                 //end if
                 $Element['attributes'] += $this->parseAttributeData($matches[1]);
                 $cell = trim(SmartUnicode::sub_str($cell, 0, SmartUnicode::str_len($cell) - SmartUnicode::str_len($matches[1]) - 2));
             }
             //end if
             //-- # end unixman
             $Element['text'] = $cell;
             //--
             if (isset($Block['alignments'][$index])) {
                 if (!is_array($Element['attributes'])) {
                     $Element['attributes'] = array();
                 }
                 //end if
                 //$Element['attributes']['style'] = 'text-align: '.$Block['alignments'][$index].';';
                 $Element['attributes']['style'] = 'text-align: ' . $Block['alignments'][$index] . '; ' . $Element['attributes']['style'];
                 // fix by unixman
             }
             //end if
             //--
             $Elements[] = $Element;
             //--
         }
         //end foreach
         //--
         $Element = array('name' => 'tr', 'handler' => 'elements', 'text' => $Elements);
         //--
         $Block['element']['text'][1]['text'][] = $Element;
         //--
         return $Block;
         //--
     }
     //end if
     //--
 }
 /**
  * Decompress a Base64 + LZS compressed string
  *
  * @param		STRING		$input		The Base64 LZS Compressed String
  * @return		STRING		The uncompressed string
  *
  */
 public static function decompressFromBase64($input)
 {
     //--
     $input = (string) $input;
     //--
     $output = '';
     //--
     $ol = 0;
     $output_ = NULL;
     $chr1 = NULL;
     $chr2 = NULL;
     $chr3 = NULL;
     $enc1 = NULL;
     $enc2 = NULL;
     $enc3 = NULL;
     $enc4 = NULL;
     //--
     $input = preg_replace('/[^A-Za-z0-9\\+\\/\\=]/', '', (string) $input);
     //--
     $i = 0;
     //--
     while ($i < SmartUnicode::str_len($input)) {
         //--
         $enc1 = strpos(self::$keyStr, (string) $input[$i++]);
         $enc2 = strpos(self::$keyStr, (string) $input[$i++]);
         $enc3 = strpos(self::$keyStr, (string) $input[$i++]);
         $enc4 = strpos(self::$keyStr, (string) $input[$i++]);
         //--
         $chr1 = $enc1 << 2 | $enc2 >> 4;
         $chr2 = ($enc2 & 15) << 4 | $enc3 >> 2;
         $chr3 = ($enc3 & 3) << 6 | $enc4;
         //--
         if ($ol % 2 == 0) {
             //--
             $output_ = $chr1 << 8;
             //--
             if ($enc3 != 64) {
                 //--
                 $output .= self::fromCharCode($output_ | $chr2);
                 //--
             }
             //end if
             //--
             if ($enc4 != 64) {
                 //--
                 $output_ = $chr3 << 8;
                 //--
             }
             //end if
             //--
         } else {
             //--
             $output = $output . self::fromCharCode($output_ | $chr1);
             //--
             if ($enc3 != 64) {
                 $output_ = $chr2 << 8;
             }
             //end if
             //--
             if ($enc4 != 64) {
                 //--
                 $output .= self::fromCharCode($output_ | $chr3);
                 //--
             }
             //end if
             //--
         }
         //end if else
         //--
         $ol += 3;
         //--
     }
     //end while
     //--
     return self::decompressRawLZS($output);
     //--
 }
 /**
  * List code points for a given input
  *
  * @param string $input
  * @return array Multi-dimension array with basic, non-basic and aggregated code points
  */
 private function listCodePoints($input)
 {
     $codePoints = array('all' => array(), 'basic' => array(), 'nonBasic' => array());
     $length = (int) SmartUnicode::str_len((string) $input);
     for ($i = 0; $i < $length; $i++) {
         $char = (string) SmartUnicode::sub_str((string) $input, $i, 1);
         $code = $this->charToCodePoint($char);
         if ($code < 128) {
             $codePoints['all'][] = $codePoints['basic'][] = $code;
         } else {
             $codePoints['all'][] = $codePoints['nonBasic'][] = $code;
         }
     }
     //end for
     return $codePoints;
 }
    public static function test_strings()
    {
        //--
        $unicode_text = '"Unicode78źź:ăĂîÎâÂșȘțȚşŞţŢグッド';
        //--
        $idn_domain_unicode = 'jösefsson.tßst123.org';
        $idn_domain_iso = 'xn--jsefsson-n4a.xn--tst123-bta.org';
        $idn_email_unicode = 'räksmörgås@jösefsson.tßst123.org';
        $idn_email_iso = '*****@*****.**';
        //--
        //--
        $err = '';
        //--
        //--
        $tests[] = '##### Unicode STRING / TESTS: #####';
        //--
        //--
        $regex_positive = '/^[\\w"\\:\\?]+$/';
        $regex_negative = '/[^\\w"\\:\\?]/';
        //--
        //--
        if (defined('SMART_FRAMEWORK_SECURITY_FILTER_INPUT')) {
            if ((string) SMART_FRAMEWORK_SECURITY_FILTER_INPUT != '') {
                if ((string) $err == '') {
                    $the_test = 'Smart.Framework Security Input Filter Regex - test over a full Unicode String';
                    $tests[] = $the_test;
                    if (preg_match((string) SMART_FRAMEWORK_SECURITY_FILTER_INPUT, 'Platform クラウドアプリケーションプラットフォーム \'áâãäåāăąÁÂÃÄÅĀĂĄćĉčçĆĈČÇďĎèéêëēĕėěęÈÉÊËĒĔĖĚĘĝģĜĢĥħĤĦìíîïĩīĭȉȋįÌÍÎÏĨĪĬȈȊĮijĵIJĴķĶĺļľłĹĻĽŁñńņňÑŃŅŇòóôõöōŏőøœÒÓÔÕÖŌŎŐØŒŕŗřŔŖŘșşšśŝßȘŞŠŚŜțţťȚŢŤùúûüũūŭůűųÙÚÛÜŨŪŬŮŰŲŵŴẏỳŷÿýẎỲŶŸÝźżžŹŻŽ " <p></p> ? & * ^ $ @ ! ` ~ % () [] {} | \\ / + - _ : ; , . #\'0.51085600 1454529112#' . "\r\n\t" . '`~@#$%^&*()-_=+[{]}|;:"<>,.?/\\')) {
                        $err = 'ERROR: ' . $the_test . ' FAILED ...';
                    }
                    //end if
                }
                //end if
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode Regex Test Positive';
            $tests[] = $the_test;
            if (!preg_match((string) $regex_positive . 'u', (string) $unicode_text)) {
                $err = 'ERROR: ' . $the_test . ' FAILED (1) ...';
            } elseif (preg_match((string) $regex_positive, (string) $unicode_text)) {
                $err = 'ERROR: ' . $the_test . ' FAILED (2) ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode Regex Test Negative';
            $tests[] = $the_test;
            if (preg_match((string) $regex_negative . 'u', (string) $unicode_text)) {
                $err = 'ERROR: ' . $the_test . ' FAILED (1) ...';
            } elseif (!preg_match((string) $regex_negative, (string) $unicode_text)) {
                $err = 'ERROR: ' . $the_test . ' FAILED (2) ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Deaccented ISO Regex Test Positive';
            $tests[] = $the_test;
            if (!preg_match((string) $regex_positive, (string) SmartUnicode::deaccent_str($unicode_text))) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Deaccented ISO Regex Test Negative';
            $tests[] = $the_test;
            if (preg_match((string) $regex_negative, (string) SmartUnicode::deaccent_str($unicode_text))) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode Strlen Test';
            $tests[] = $the_test;
            if (SmartUnicode::str_len($unicode_text) !== 30) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            // this tests also SmartUnicode::str_ipos
            $the_test = 'Unicode Find Substring (Case Insensitive), Positive';
            $tests[] = $the_test;
            if (SmartUnicode::str_icontains($unicode_text, 'șș') !== true) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            // this tests also SmartUnicode::str_ipos
            $the_test = 'Unicode Find Substring (Case Insensitive), Negative';
            $tests[] = $the_test;
            if (SmartUnicode::str_icontains($unicode_text, 'șş') !== false) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            // this tests also SmartUnicode::str_pos
            $the_test = 'Unicode Find Substring (Case Sensitive), Positive';
            $tests[] = $the_test;
            if (SmartUnicode::str_contains($unicode_text, 'țȚ') !== true) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            // this tests also SmartUnicode::str_pos
            $the_test = 'Unicode Find Substring (Case Sensitive), Negative';
            $tests[] = $the_test;
            if (SmartUnicode::str_contains($unicode_text, 'țŢ') !== false) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode Find Substring (Case Insensitive), Reverse';
            $tests[] = $the_test;
            if (SmartUnicode::str_ripos($unicode_text, 'ţţグ') === false) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode Find Substring (Case Sensitive), Reverse';
            $tests[] = $the_test;
            if (SmartUnicode::str_rpos($unicode_text, 'ţŢグ') === false) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode Return Substring (Case Insensitive)';
            $tests[] = $the_test;
            if (SmartUnicode::stri_str($unicode_text, 'âȘșȚ') !== 'ÂșȘțȚşŞţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode Return Substring (Case Sensitive)';
            $tests[] = $the_test;
            if (SmartUnicode::str_str($unicode_text, 'ÂșȘț') !== 'ÂșȘțȚşŞţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode String to LowerCase';
            $tests[] = $the_test;
            if (SmartUnicode::str_tolower($unicode_text) !== '"unicode78źź:ăăîîââșșțțşşţţグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode String to UpperCase';
            $tests[] = $the_test;
            if (SmartUnicode::str_toupper($unicode_text) !== '"UNICODE78ŹŹ:ĂĂÎÎÂÂȘȘȚȚŞŞŢŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode SubString function (without last param)';
            $tests[] = $the_test;
            if (SmartUnicode::sub_str($unicode_text, 25) !== 'ţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode SubString function (with last param)';
            $tests[] = $the_test;
            if (SmartUnicode::sub_str($unicode_text, 25, 3) !== 'ţŢグ') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode SubString Count function';
            $tests[] = $the_test;
            if (SmartUnicode::substr_count($unicode_text, 'ţ') !== 1) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode String Replace with Limit (Case Sensitive)';
            $tests[] = $the_test;
            if (SmartUnicode::str_limit_replace('ź', '@', $unicode_text, 1) !== '"Unicode78@ź:ăĂîÎâÂșȘțȚşŞţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'String Replace without Limit (Case Sensitive)';
            $tests[] = $the_test;
            if (str_replace('ź', '@', $unicode_text) !== '"Unicode78@@:ăĂîÎâÂșȘțȚşŞţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            /* This test fails if the replacements accented characters are different case than one find in string (upper/lower) ... */
            $the_test = 'String Replace without Limit (Case Insensitive) *** Only with unaccented replacements !!';
            $tests[] = $the_test;
            if (str_ireplace('E7', '@', $unicode_text) !== '"Unicod@8źź:ăĂîÎâÂșȘțȚşŞţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Deaccent String';
            $tests[] = $the_test;
            if (SmartUnicode::deaccent_str($unicode_text) !== '"Unicode78zz:aAiIaAsStTsStT???') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'YAML Unicode Test: Compose from Array / Parse from YAML';
            $tests[] = $the_test;
            $test_arr = array('@test' => 'Testing weird key characters', 'line1' => 'Some ISO-8859-1 String: @ # $ % ^ & * (\') _ - + = { [ ] } ; < ,. > / ? \\ |', 'line2' => 'Unicode (long) String: ' . $unicode_text . ' ' . SmartUnicode::str_toupper($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::str_tolower($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::deaccent_str($unicode_text) . ' ' . $unicode_text, $unicode_text => 'Unicode as Key', 'line3' => ['A' => 'b', 100, 'Thousand'], 'line4' => [1, 0.2, 3.0001], 'line5' => date('Y-m-d H:i:s'));
            $test_yaml = (string) '# start YAML (to test also comments)' . "\n" . (new SmartYamlConverter())->compose($test_arr) . "\n" . '# end YAML';
            $test_parr = (new SmartYamlConverter())->parse($test_yaml);
            if ($test_arr !== $test_parr) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' #ORIGINAL Array [' . print_r($test_arr, 1) . ']' . "\n\n" . '#YAML Array (from YAML String): ' . print_r($test_parr, 1) . "\n\n" . '#YAML String (from ORIGINAL Array): ' . "\n" . $test_yaml;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'XML Unicode Test: Compose from Array / Parse from XML';
            $tests[] = $the_test;
            $test_arr = array('TEST' => 'Testing weird key characters', 'line1' => 'Some ISO-8859-1 String: @ # $ % ^ & * (\') _ - + = { [ ] } ; < ,. > / ? \\ |', 'line2' => 'Unicode (long) String: ' . $unicode_text . ' ' . SmartUnicode::str_toupper($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::str_tolower($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::deaccent_str($unicode_text) . ' ' . $unicode_text, 'line3' => ['A' => 'b', 'c' => 'D'], 'line4' => '', 'line5' => date('Y-m-d H:i:s'));
            $test_xml = (string) (new SmartXmlComposer())->transform($test_arr);
            $test_parr = (new SmartXmlParser())->transform($test_xml);
            if ($test_arr !== $test_parr) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' #ORIGINAL Array [' . print_r($test_arr, 1) . ']' . "\n\n" . '#XML Array (from XML String): ' . print_r($test_parr, 1) . "\n\n" . '#XML String (from ORIGINAL Array): ' . "\n" . $test_xml;
            }
            //end if
        }
        //end if
        //--
        $the_random_unicode_text = sha1($unicode_text . Smart::random_number(1000, 9999)) . '-' . $unicode_text . " \r\n\t" . '-' . Smart::uuid_10_num() . '-' . Smart::uuid_10_str() . '-' . Smart::uuid_10_seq();
        //--
        if ((string) $err == '') {
            $the_test = 'Data: Archive / Unarchive';
            $tests[] = $the_test;
            if (SmartUtils::data_unarchive(SmartUtils::data_archive($the_random_unicode_text)) !== (string) $the_random_unicode_text) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $the_random_unicode_text . ']';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Cache: Archive / Unarchive';
            $tests[] = $the_test;
            if (SmartUtils::cache_variable_unarchive(SmartUtils::cache_variable_archive($the_random_unicode_text)) !== (string) $the_random_unicode_text) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $the_random_unicode_text . ']';
            }
            //end if
        }
        //end if
        //--
        //--
        if ((string) $err == '') {
            $the_test = 'IDN: Domain Punycode Encode UTF-8 to ISO';
            $tests[] = $the_test;
            if ((string) (new SmartPunycode())->encode($idn_domain_unicode) != (string) $idn_domain_iso) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_domain_unicode . ' -> ' . $idn_domain_iso . ']';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'IDN: Domain Punycode Decode ISO to UTF-8';
            $tests[] = $the_test;
            if ((string) (new SmartPunycode())->decode($idn_domain_iso) != (string) $idn_domain_unicode) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_domain_iso . ' -> ' . $idn_domain_unicode . ']';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'IDN: Email Punycode Encode UTF-8 to ISO';
            $tests[] = $the_test;
            if ((string) (new SmartPunycode())->encode($idn_email_unicode) != (string) $idn_email_iso) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_email_unicode . ' -> ' . $idn_email_iso . ']';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'IDN: Email Punycode Decode ISO to UTF-8';
            $tests[] = $the_test;
            if ((string) (new SmartPunycode())->decode($idn_email_iso) != (string) $idn_email_unicode) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_email_iso . ' -> ' . $idn_email_unicode . ']';
            }
            //end if
        }
        //end if
        //--
        //-- regex positive tests
        $arr_regex = ['number-integer' => [0, '75', '-101'], 'number-decimal' => [0, '0.0', '0.1', '75', '75.0', '75.1', '-555', '-555.0', '-555.1'], 'number-list-integer' => '1;2;30', 'number-list-decimal' => '1.0;2;30.44', 'url' => ['https://192.168.1.0', 'http://localhost', 'https://www.dom.ext', 'http://dom.ext/path?a=b&c=d%20#s'], 'domain' => ['domain.com', 'sdom.domain.org'], 'email' => ['root@localhost', '*****@*****.**', '*****@*****.**'], 'fax' => ['~+99-(0)999-123.456.78~'], 'macaddr' => ['00:0A:95:9d:68:16', '00-0a-95-9D-68-16'], 'ipv4' => ['192.168.0.1', '169.254.1.0', '1.0.0.1'], 'ipv6' => ['::1', '0000:0000:0000:0000:0000:0000:0000:0001', '2001:0db8:0000:0000:0000:ff00:0042:8329', '2001:dB8::2:1', '2001:db8::1', '3731:54:65fe:2::a7']];
        //--
        foreach ((array) $arr_regex as $key => $val) {
            //--
            if (is_array($val)) {
                for ($i = 0; $i < Smart::array_size($val); $i++) {
                    $the_test = 'Regex Validate Positive (#' . $i . '): ' . $key . ' [' . $val[$i] . ']';
                    $tests[] = $the_test;
                    if (SmartValidator::validate_string($val[$i], $key) !== true) {
                        $err = 'ERROR: ' . $the_test . ' FAILED ...';
                        break;
                    }
                    //end if
                    if (stripos((string) $key, 'number-') === 0 and stripos((string) $key, 'number-list-') === false) {
                        $the_test = 'Regex Validate Numeric Positive (#' . $i . '): ' . $key . ' [' . $val[$i] . ']';
                        $tests[] = $the_test;
                        if (SmartValidator::validate_numeric_integer_or_decimal_values($val[$i], $key) !== true) {
                            $err = 'ERROR: ' . $the_test . ' FAILED ...';
                            break;
                        }
                        //end if
                    }
                    //end if
                }
                //end for
            } else {
                $the_test = 'Regex Validate Positive: ' . $key . ' [' . $val . ']';
                $tests[] = $the_test;
                if (SmartValidator::validate_string($val, $key) !== true) {
                    $err = 'ERROR: ' . $the_test . ' FAILED ...';
                }
                //end if
                if (stripos((string) $key, 'number-') === 0 and stripos((string) $key, 'number-list-') === false) {
                    $the_test = 'Regex Validate Numeric Positive: ' . $key . ' [' . $val . ']';
                    $tests[] = $the_test;
                    if (SmartValidator::validate_numeric_integer_or_decimal_values($val, $key) !== true) {
                        $err = 'ERROR: ' . $the_test . ' FAILED ...';
                    }
                    //end if
                }
                //end if
            }
            //end if else
            //--
            if ((string) $err != '') {
                break;
            }
            //end if
            //--
        }
        //end foreach
        //--
        //-- regex negative tests
        $arr_regex = ['number-integer' => ['', '.', 'a9', '7B', '-9 ', ' -7'], 'number-decimal' => ['', '.0', '.1', '-.10', ' -7', '-9.0 '], 'number-list-integer' => '1;2.3;30', 'number-list-decimal' => '1.0;2;30.44a', 'url' => ['http:://192.168.1.0', 'https://local host', 'http:/www.dom.ext', 'https:dom.ext/path?a=b&c=d%20#s'], 'domain' => ['doMain.com', 's dom.domain.org', '.dom.ext', 'dom..ext', 'localhost', 'loc', 'dom.ext.'], 'email' => ['rooT@localhost', 'root@local host.loc', 'sometest-name.extra@do_m.ext'], 'fax' => ['~ +99-(0)999-123.456.78 ~'], 'macaddr' => ['00:0A:95:9z:68:16', '00-0Z-95-9D-68-16'], 'ipv4' => ['192.168.0.', '169..1.0', '1.0.1'], 'ipv6' => ['::x', '00z0:0000:0000:0000:0000:0000:0000:0001', '2001:0dx8:0000:0000:0000:ff00:0042:8329', '2001:WB8::2:1', '2001:@db8::1', '3731:54:65Qe:2::a7']];
        //--
        foreach ((array) $arr_regex as $key => $val) {
            //--
            if (is_array($val)) {
                for ($i = 0; $i < Smart::array_size($val); $i++) {
                    $the_test = 'Regex Validate Negative (#' . $i . '): ' . $key . ' [' . $val[$i] . ']';
                    $tests[] = $the_test;
                    if (SmartValidator::validate_string($val[$i], $key) === true) {
                        $err = 'ERROR: ' . $the_test . ' FAILED ...';
                        break;
                    }
                    //end if
                }
                //end for
            } else {
                $the_test = 'Regex Validate Negative: ' . $key . ' [' . $val . ']';
                $tests[] = $the_test;
                if (SmartValidator::validate_string($val, $key) === true) {
                    $err = 'ERROR: ' . $the_test . ' FAILED ...';
                }
                //end if
            }
            //end if else
            //--
            if ((string) $err != '') {
                break;
            }
            //end if
            //--
        }
        //end foreach
        //--
        //--
        $endtest = '##### END TESTS ... #####';
        //--
        //--
        if ((string) $err == '') {
            $img_sign = 'lib/core/img/sign_info.png';
            $img_check = 'lib/core/img/q_completed.png';
            $text_main = Smart::escape_js('<span style="color:#83B953;">Good ... Perfect &nbsp;&nbsp;&nbsp; :: &nbsp;&nbsp;&nbsp; グッド ... パーフェクト</span>');
            $text_info = Smart::escape_js('<h2><span style="color:#83B953;">All</span> the SmartFramework Unicode String <span style="color:#83B953;">Tests PASSED on PHP</span><hr></h2><span style="font-size:14px;">' . Smart::nl_2_br(Smart::escape_html(implode("\n" . '* ', $tests) . "\n" . $endtest)) . '</span>');
        } else {
            $img_sign = 'lib/core/img/sign_error.png';
            $img_check = 'lib/core/img/q_warning.png';
            $text_main = Smart::escape_js('<span style="color:#FF5500;">An ERROR occured ... &nbsp;&nbsp;&nbsp; :: &nbsp;&nbsp;&nbsp; エラーが発生しました ...</span>');
            $text_info = Smart::escape_js('<h2><span style="color:#FF5500;">A test FAILED</span> when testing Unicode String Tests.<span style="color:#FF5500;"><hr>FAILED Test Details</span>:</h2><br><h3>' . Smart::escape_html($tests[Smart::array_size($tests) - 1]) . '</h3><br><span style="font-size:14px;"><pre>' . Smart::escape_html($err) . '</pre></span>');
        }
        //end if else
        //--
        //--
        $html = <<<HTML
<h1>SmartFramework Unicode Strings Tests: DONE ...</h1>
<script type="text/javascript">
\tSmartJS_BrowserUtils.alert_Dialog(
\t\t'<img src="{$img_sign}" align="right"><h1>{$text_main}</h1><hr><span style="color:#333333;"><img src="{$img_check}" align="right">{$text_info}<br>',
\t\t'',
\t\t'Unicode String Test Suite for SmartFramework: PHP',
\t\t'725',
\t\t'425'
\t);
</script>
HTML;
        //--
        //--
        return $html;
        //--
    }
 private function parse_banner($reply)
 {
     //--
     $outside = true;
     $banner = '';
     //--
     $reply = trim($reply);
     //--
     for ($i = 0; $i < SmartUnicode::str_len($reply); $i++) {
         //--
         $digit = SmartUnicode::sub_str($reply, $i, 1);
         //--
         if (strlen($digit) > 0) {
             //--
             if (!$outside and (string) $digit != '<' and (string) $digit != '>') {
                 $banner .= $digit;
             }
             //end if
             //--
             if ((string) $digit == '<') {
                 $outside = false;
             }
             //end if
             //--
             if ((string) $digit == '>') {
                 $outside = true;
             }
             //end if
             //--
         }
         //end if
         //--
     }
     //end for
     //--
     $banner = trim($this->strip_clf($banner));
     // just in case
     if (strlen($banner) > 0) {
         $banner = '<' . $banner . '>';
     }
     //end if
     //--
     return $banner;
     //--
 }
 public static function extract_description($ytxt, $y_limit = 155)
 {
     //--
     $ytxt = (string) $ytxt;
     if ((string) $ytxt == '') {
         return '';
     }
     //end if
     //--
     $y_limit = Smart::format_number_int($y_limit, '+');
     if ($y_limit < 1) {
         $y_limit = 1;
     }
     //end if
     if ($y_limit > 256) {
         $y_limit = 256;
     }
     //end if
     //--
     $arr = self::extract_words_from_text_html($ytxt);
     //--
     $out = '';
     for ($i = 0; $i < Smart::array_size($arr); $i++) {
         $tmp_word = trim($arr[$i]);
         if ((string) $tmp_word != '') {
             if ((string) $out == '') {
                 $out .= $tmp_word . ' ';
             } else {
                 $out .= SmartUnicode::str_tolower($tmp_word) . ' ';
             }
             //end if else
         }
         //end if
         if (SmartUnicode::str_len($out) >= $y_limit) {
             break;
         }
         //end if
     }
     //end for
     //--
     return trim($out);
     //--
 }
 public function data_send($msg_data)
 {
     //--
     if ($this->debug) {
         $this->log .= '[INF] Data-Send command is sent on Mail Server' . "\n";
     }
     //end if
     //--
     if (strlen($this->error) > 0) {
         return 0;
     }
     //end if
     //--
     $reply = $this->send_cmd('DATA');
     if (strlen($this->error) > 0) {
         return 0;
     }
     //end if
     //--
     $test = $this->answer_code($reply);
     if ((string) $test != '354') {
         $this->error = '[ERR] Data-Send command Failed on Server :: ' . $test . ' // ' . $reply;
         return 0;
     }
     //end if
     //--
     // The server is ready to accept data. According to rfc 821 we should not send more than 1000 characters including the CRLF on a single line
     // so we will break the data up into lines by \r and/or \n then if needed we will break each of those into smaller lines to fit within the limit.
     // In addition we will be looking for lines that start with a period '.' and append and additional period '.' to that line.
     // NOTE: this does not count towards are limit.
     //-- normalize the line breaks so we know the explode works
     $msg_data = str_replace(array("\r\n", "\r"), array("\n", "\n"), $msg_data);
     // replacing the CRLF to LF
     $lines = (array) explode("\n", (string) $msg_data);
     $msg_data = '';
     // cleanup
     //--
     // We need to find a good way to determine if headers are in the msg_data or if it is a straight msg body.
     // Currently assuming rfc 822 definitions of msg headers and if the first field of the first line (':' sperated) does not contain a space
     // then it _should_ be a header and we can process all lines before a blank "" line as headers.
     //--
     $field = SmartUnicode::sub_str($lines[0], 0, SmartUnicode::str_pos($lines[0], ':'));
     $in_headers = false;
     //--
     if (strlen($field) > 0 and !SmartUnicode::str_contains($field, ' ')) {
         $in_headers = true;
     }
     //end if
     //--
     $max_line_length = 800;
     // used below ; set here for ease in change (we use a lower value than 1000 as we use UTF-8 text)
     //--
     //while(list(,$line) = @each($lines)) {
     while (list($key, $line) = @each($lines)) {
         // FIX to be compatible with the upcoming PHP 7
         //--
         $lines_out = null;
         //--
         if ((string) $line == '' and $in_headers) {
             $in_headers = false;
         }
         //end if
         //-- ok we need to break this line up into several smaller lines
         while (SmartUnicode::str_len($line) > $max_line_length) {
             //--
             $pos = SmartUnicode::str_rpos(SmartUnicode::sub_str($line, 0, $max_line_length), ' ');
             // here we need reverse strpos
             $lines_out[] = SmartUnicode::sub_str($line, 0, $pos);
             $line = SmartUnicode::sub_str($line, $pos + 1);
             //-- if we are processing headers we need to add a LWSP-char to the front of the new line rfc 822 on long msg headers
             if ($in_headers) {
                 $line = "\t" . $line;
             }
             //end if
             //--
         }
         //end while
         //--
         $lines_out[] = $line;
         //-- now send the lines to the server
         //while(list(,$line_out) = @each($lines_out)) {
         while (list($key, $line_out) = @each($lines_out)) {
             // FIX to be compatible with the upcoming PHP 7
             //--
             if (strlen($line_out) > 0) {
                 if (SmartUnicode::sub_str($line_out, 0, 1) == '.') {
                     $line_out = '.' . $line_out;
                 }
                 //end if
             }
             //end if
             //--
             @fputs($this->socket, $line_out . "\r\n");
             //--
         }
         //end while
         //--
     }
     //end while
     //-- ok all the message data has been sent so lets get this over with aleady
     @fputs($this->socket, "\r\n" . '.' . "\r\n");
     //--
     $reply = $this->retry_data();
     $test = $this->answer_code($reply);
     //--
     if ($this->debug) {
         $this->log .= '[INF] Data-Send Mail Server Reply is :: ' . $test . ' // ' . $reply . "\n";
     }
     //end if
     //--
     if (strlen($this->error) > 0) {
         return 0;
     }
     //end if
     //--
     if ((string) $test != '250') {
         $this->error = '[ERR] Data-Send Finalize Failed on Server :: ' . $test . ' // ' . $reply;
         return 0;
     }
     //end if
     //--
     return 1;
     //--
 }
 /**
  * Send Email Mime Message from custom MailBox to a destination
  *
  * @param ARRAY			$y_server_settings	arr = [ server_name, server_port, server_sslmode, server_auth_user, server_auth_pass, send_from_addr, send_from_name, smtp_mxdomain ]
  * @param ENUM			$y_mode				'send' = do send | 'send-return' = do send + return | 'return' = return mime formated mail
  * @param STRING 		$to					To:
  * @param STRING 		$cc					Cc: | empty
  * @param STRING 		$subj				Subject:
  * @param STRING 		$message			Body/Message:
  * @param TRUE/FALSE 	$is_html			* Format: Html or Text/Plain
  * @param ARRAY 		$attachments		* $attachments = array('file1.txt'=>'This is the file 1 content', ...);
  * @param ENUM			$charset			* charset
  * @param ENUM			$priority			* 1=High ; 3=Normal ; 5=Low
  * @param STRING 		$inreplyto			'' | the ID of message that is replying to
  * @return ARRAY							OPERATION RESULT, ERROR, MIME MESSAGE
  */
 public static function send_extended_email($y_server_settings, $y_mode, $to, $cc, $subj, $message, $is_html, $attachments, $charset, $priority, $inreplyto, $bcc = '', $replytoaddr = '')
 {
     //-- SMTP Hello
     $server_helo = trim($y_server_settings['smtp_mxdomain']);
     //-- SMTP connection vars
     $server_name = trim($y_server_settings['server_name']);
     $server_port = trim($y_server_settings['server_port']);
     $server_sslmode = trim($y_server_settings['server_sslmode']);
     $server_user = trim($y_server_settings['server_auth_user']);
     $server_pass = trim($y_server_settings['server_auth_pass']);
     //-- SEND FROM
     $send_from_addr = trim($y_server_settings['send_from_addr']);
     $send_from_name = trim($y_server_settings['send_from_name']);
     //--
     //-- mail send class init
     $mail = new SmartMailerSend();
     $mail->usealways_b64 = true;
     //--
     if ((string) $server_name == '@mail') {
         //--
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             SmartFrameworkRegistry::setDebugMsg('mail', 'SEND', 'Send eMail Method Selected: [MAIL]');
         }
         //end if
         //-- mail method
         $mail->method = 'mail';
         //--
     } elseif (strlen($server_name) > 0) {
         //--
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             SmartFrameworkRegistry::setDebugMsg('mail', 'SEND', 'Send eMail Method Selected: [SMTP]');
         }
         //end if
         //-- smtp server method
         $mail->method = 'smtp';
         $mail->smtp_timeout = '30';
         //--
         $mail->smtp_helo = $server_helo;
         $mail->smtp_server = $server_name;
         $mail->smtp_port = $server_port;
         $mail->smtp_ssl = $server_sslmode;
         //--
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             $mail->debuglevel = 1;
             // default is 1
         } else {
             $mail->debuglevel = 0;
             // no debug
         }
         //end if else
         //--
         if ((string) $server_user == '' or (string) $server_pass == '') {
             $mail->smtp_login = false;
         } else {
             $mail->smtp_login = true;
             $mail->smtp_user = $server_user;
             $mail->smtp_password = $server_pass;
         }
         //end if
         //--
     } else {
         //--
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             SmartFrameworkRegistry::setDebugMsg('mail', 'SEND', 'Send eMail Method Selected: [NONE] !!!');
         }
         //end if
         //--
         $mail->method = 'skip';
         //--
     }
     //end if else
     //--
     //-- charset
     if ((string) $charset == '') {
         $charset = 'UTF-8';
         // default
     }
     //end if
     //--
     $mail->charset = (string) $charset;
     //--
     //--
     if ((string) $mail->charset != 'UTF-8') {
         // in this case (ISO-88591 / ISO-8859-2) we deaccent the things for maximum compatibility
         $send_from_name = SmartUnicode::deaccent_str($send_from_name);
         $subj = SmartUnicode::deaccent_str($subj);
         $message = SmartUnicode::deaccent_str($message);
     }
     //end if
     //--
     //--
     $tmp_explode_arr = (array) explode('@', (string) $send_from_addr);
     $tmp_name = trim($tmp_explode_arr[0]);
     // not used
     $tmp_domain = trim($tmp_explode_arr[1]);
     // used for message ID
     //--
     $tmp_my_uid = getmyuid();
     $tmp_my_gid = getmygid();
     //--
     //-- Extra Mail Headers
     $mail->headers = '';
     //-- Errors Reporting Header
     $mail->headers .= 'Errors-To: ' . $send_from_addr . "\r\n";
     //-- In-Reply-To Header
     if ((string) $inreplyto != '') {
         $mail->headers .= 'In-Reply-To: ' . $inreplyto . "\r\n";
     }
     //end if else
     //-- Reply-To Header
     if ((string) $replytoaddr != '') {
         $mail->headers .= 'Reply-To: ' . $replytoaddr . "\r\n";
     }
     //end if
     //-- antiSPAM Header
     $mail->headers .= 'X-AntiAbuse: This header was added to track abuse, please include it with any abuse report' . "\r\n";
     $mail->headers .= 'X-AntiAbuse: Primary Hostname - ' . $server_helo . "\r\n";
     $mail->headers .= 'X-AntiAbuse: Original Domain - ' . $server_helo . "\r\n";
     $mail->headers .= 'X-AntiAbuse: Originator/Caller UID/GID - [48880 48885] / [' . $tmp_my_uid . ' ' . $tmp_my_gid . ']' . "\r\n";
     $mail->headers .= 'X-AntiAbuse: Sender Address Domain - ' . $tmp_domain . "\r\n";
     //--
     //--
     $mail->priority = $priority;
     // high=1 | low=5 | normal=3
     //--
     //-- from
     $mail->from_return = $send_from_addr;
     $mail->from = $send_from_addr;
     $mail->namefrom = $send_from_name;
     //--
     //-- subject
     $mail->subject = $subj;
     //--
     //-- if message is html, include CID imgs as attachments
     if ((string) $y_mode != 'return' and $is_html) {
         //-- init
         $arr_links = array();
         //-- embedd all images
         $htmlparser = new SmartHtmlParser($message);
         $htmlparser->get_clean_html();
         // to be tested ...
         $arr_links = $htmlparser->get_tags('img');
         $htmlparser = '';
         unset($htmlparser);
         //--
         $chk_duplicates_arr = array();
         $uniq_id = 0;
         //--
         for ($i = 0; $i < Smart::array_size($arr_links); $i++) {
             //--
             $tmp_original_img_link = trim($arr_links[$i][src]);
             // trim any possible spaces
             //-- reverse the &amp; back to & (generated from JavaScript) ...
             $tmp_imglink = str_replace('&amp;', '&', (string) $tmp_original_img_link);
             //--
             $tmp_cid = 'img_' . sha1('SmartFramework eMail-Utils // CID Embedd // ' . '@' . $tmp_imglink . '#');
             // this should not vary by $i or others because if duplicate images are detected only the first is attached
             //--
             if (strlen($chk_duplicates_arr[$tmp_cid]) <= 0) {
                 // avoid browse twice the same image
                 //--
                 $tmp_original_lnk = (string) $tmp_imglink;
                 $tmp_eval_link = (string) $tmp_imglink;
                 $tmp_allow_credentials = 'no';
                 if (substr($tmp_original_lnk, 0, 10) == 'admin.php?') {
                     $tmp_original_lnk = (string) SmartUtils::get_server_current_url() . $tmp_imglink;
                     $tmp_allow_credentials = 'yes';
                     // in the case we have embedded pictures generated by admin.php who always need authentication to work, we have to send credentials too
                     $tmp_eval_link = '';
                     // we clear to re-eval
                 } elseif (SmartUnicode::sub_str($tmp_original_lnk, 0, SmartUnicode::str_len(SmartUtils::get_server_current_url() . 'admin.php?')) == SmartUtils::get_server_current_url() . 'admin.php?' and (substr($tmp_original_lnk, 0, 7) == 'http://' or substr($tmp_original_lnk, 0, 8) == 'https://')) {
                     $tmp_allow_credentials = 'yes';
                     // in the case we have embedded pictures generated by admin.php who always need authentication to work, we have to send credentials too
                     $tmp_eval_link = '';
                     // we clear to re-eval
                 } elseif (substr($tmp_original_lnk, 0, 10) == 'index.php?' or substr($tmp_original_lnk, 0, 1) == '?') {
                     $tmp_original_lnk = (string) SmartUtils::get_server_current_url() . $tmp_imglink;
                     $tmp_eval_link = '';
                     // we clear to re-eval
                 } elseif (SmartUnicode::sub_str($tmp_original_lnk, 0, SmartUnicode::str_len(SmartUtils::get_server_current_url() . 'index.php?')) == SmartUtils::get_server_current_url() . 'index.php?' and (substr($tmp_original_lnk, 0, 7) == 'http://' or substr($tmp_original_lnk, 0, 8) == 'https://')) {
                     $tmp_eval_link = '';
                     // we clear to re-eval
                 } elseif (SmartUnicode::sub_str($tmp_original_lnk, 0, SmartUnicode::str_len(SmartUtils::get_server_current_url() . '?')) == SmartUtils::get_server_current_url() . '?' and (substr($tmp_original_lnk, 0, 7) == 'http://' or substr($tmp_original_lnk, 0, 8) == 'https://')) {
                     $tmp_eval_link = '';
                     // we clear to re-eval
                 }
                 //end if
                 //--
                 $tmp_browse_arr = array();
                 $tmp_browse_arr = SmartUtils::load_url_or_file($tmp_original_lnk, SMART_FRAMEWORK_NETSOCKET_TIMEOUT, 'GET', '', '', '', $tmp_allow_credentials);
                 // [OK]
                 //Smart::log_notice(print_r($tmp_browse_arr,1));
                 //--
                 $guess_arr = array();
                 $guess_arr = SmartUtils::guess_image_extension_by_url_head($tmp_browse_arr['headers']);
                 $tmp_img_ext = (string) $guess_arr['extension'];
                 $tmp_where_we_guess = (string) $guess_arr['where-was-detected'];
                 //Smart::log_notice('Guess Ext by URL Head: '.$tmp_browse_arr['headers']."\n".'### '.print_r($guess_arr,1)."\n".'#');
                 if ((string) $tmp_img_ext == '') {
                     $tmp_img_ext = SmartUtils::guess_image_extension_by_first_bytes(substr($tmp_browse_arr['content'], 0, 256));
                     if ((string) $tmp_img_ext != '') {
                         $tmp_where_we_guess = ' First Bytes ...';
                     }
                     //end if
                 }
                 //end if
                 //Smart::log_notice('Guess Ext by First Bytes: '.$tmp_img_ext."\n".'#');
                 if ((string) $tmp_eval_link == '') {
                     $tmp_eval_link = 'file' . $tmp_img_ext;
                 }
                 //end if
                 //--
                 $tmp_fcontent = '';
                 if ((string) $tmp_browse_arr['result'] == '1' and (string) $tmp_browse_arr['code'] == '200') {
                     if ((string) $tmp_img_ext == '' or (string) $tmp_img_ext == '.png' or (string) $tmp_img_ext == '.gif' or (string) $tmp_img_ext == '.jpg') {
                         $tmp_fcontent = (string) $tmp_browse_arr['content'];
                     }
                     //end if
                 }
                 //end if else
                 //--
                 if (strlen($tmp_fcontent) > 0) {
                     //--
                     $tmp_arr_fmime = array();
                     $tmp_arr_fmime = SmartFileSysUtils::mime_eval($tmp_eval_link);
                     //--
                     $tmp_fmime = (string) $tmp_arr_fmime[0];
                     if ((string) $tmp_fmime == '' or (string) $tmp_fmime == 'application/octet-stream') {
                         $tmp_fmime = 'image';
                         // in the case of CIDS we already pre-validated the images
                     }
                     //end if
                     $tmp_fname = 'cid_' . $uniq_id . '__' . $tmp_cid . $tmp_img_ext;
                     //--
                     $mail->add_attachment($tmp_fcontent, $tmp_fname, $tmp_fmime, 'inline', $tmp_cid . $tmp_img_ext);
                     // attachment
                     $message = str_replace('src="' . $tmp_original_img_link . '"', 'src="cid:' . $tmp_cid . $tmp_img_ext . '"', $message);
                     //--
                     $uniq_id += 1;
                     //--
                 }
                 //end if
                 //--
                 $chk_duplicates_arr[$tmp_cid] = 'embedd';
                 //--
             }
             //end if
             //--
         }
         //end for
         //-- clean
         $chk_duplicates_arr = array();
         $uniq_id = 0;
         $tmp_original_img_link = '';
         $tmp_imglink = '';
         $tmp_cid = '';
         $tmp_browse_arr = array();
         $tmp_fcontent = '';
         $tmp_arr_fmime = array();
         $tmp_fmime = '';
         $tmp_fname = '';
         //--
     }
     //end if
     //--
     //-- message body
     $mail->is_html = $is_html;
     // false | true
     $mail->body = $message;
     //--
     $message = '';
     unset($message);
     //--
     //-- attachments
     if (is_array($attachments)) {
         if (Smart::array_size($attachments) > 0) {
             while (list($key, $val) = each($attachments)) {
                 //--
                 $tmp_arr_fmime = array();
                 $tmp_arr_fmime = SmartFileSysUtils::mime_eval($key);
                 //--
                 $mail->add_attachment($val, $key, (string) $tmp_arr_fmime[0], 'attachment', '', 'yes');
                 // force as real attachments
                 //--
             }
             //end while
         }
         //end if
     }
     //end if
     //--
     //--
     switch ((string) $y_mode) {
         case 'return':
             //--
             $mail->to = '[::!::]';
             $mail->cc = '';
             //-- only return mime formated message
             $mail->send('no');
             return array('result' => 1, 'error' => '', 'message' => $mail->mime_message);
             //--
             break;
         case 'send-return':
         case 'send':
         default:
             //--
             $out = 0;
             //--
             $arr_to = array();
             if (!is_array($to)) {
                 $arr_to[] = (string) $to;
                 $tmp_send_to = (string) $to;
             } else {
                 $arr_to = (array) $to;
                 if (Smart::array_size($arr_to) > 1) {
                     $tmp_send_to = '[::@::]';
                     // multi message
                 } else {
                     $tmp_send_to = (string) $arr_to[0];
                 }
                 //end if else
             }
             //end if else
             //--
             $tmp_send_log = '';
             $tmp_send_log .= '-----------------------------------------------------------------------' . "\n";
             $tmp_send_log .= 'Smart / eMail Send Log :: ' . $send_from_addr . ' [' . $send_from_name . ']' . "\n";
             $tmp_send_log .= $server_sslmode . '://' . $server_name . ':' . $server_port . ' # ' . $server_user . ' :: ' . $server_helo . "\n";
             $tmp_send_log .= '-----------------------------------------------------------------------' . "\n";
             //--
             $counter_sent = 0;
             for ($i = 0; $i < Smart::array_size($arr_to); $i++) {
                 //--
                 $arr_to[$i] = trim($arr_to[$i]);
                 //--
                 if (strlen($arr_to[$i]) > 0) {
                     //--
                     $mail->to = (string) $arr_to[$i];
                     //--
                     $mail->cc = $cc;
                     // can be string or array
                     //--
                     $mail->bcc = (string) $bcc;
                     //--
                     $tmp_send_log .= '#' . ($i + 1) . '. To: \'' . $arr_to[$i] . '\' :: ' . date('Y-m-d H:i:s O');
                     //-- real send
                     if ((string) $mail->method == 'mail' or (string) $mail->method == 'smtp') {
                         $err = $mail->send('yes');
                         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                             SmartFrameworkRegistry::setDebugMsg('mail', 'SEND', 'Send eMail Log #' . ($i + 1) . ': ' . $mail->log);
                         }
                         //end if
                     } else {
                         $err = 'WARNING: SMTP Server or Mail Method IS NOT SET in CONFIG. Send eMail - Operation ABORTED !';
                     }
                     //end if else
                     //--
                     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                         SmartFrameworkRegistry::setDebugMsg('mail', 'SEND', '========== SEND TO: ' . $arr_to[$i] . ' ==========' . "\n" . 'ERRORS: ' . $err . "\n" . '==========' . "\n" . $mail->log . "\n" . '========== # ==========');
                     }
                     //end if
                     //--
                     if (strlen($err) > 0) {
                         $tmp_send_log .= ' :: ERROR:' . "\n" . $arr_to[$i] . "\n" . $err . "\n";
                     } else {
                         $counter_sent += 1;
                         $tmp_send_log .= ' :: OK' . "\n";
                     }
                     //end if else
                     //--
                     if ($i > 10000) {
                         break;
                         // hard limit
                     }
                     //end if
                     //--
                 }
                 //end if
                 //--
             }
             //end for
             //--
             if ($counter_sent > 0) {
                 $out = 1;
             }
             //end if
             //--
             $tmp_send_log .= '-----------------------------------------------------------------------' . "\n\n";
             if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                 SmartFrameworkRegistry::setDebugMsg('mail', 'SEND', 'Send eMail Operations Log: ' . $tmp_send_log);
             }
             //end if
             //--
             if ((string) $y_mode == 'send-return') {
                 $mail->to = $tmp_send_to;
                 if (is_array($cc)) {
                     $mail->cc = (string) implode(', ', $cc);
                 } elseif ((string) $cc != '') {
                     $mail->cc = (string) $cc;
                 }
                 //end if else
                 $mail->add_attachment($tmp_send_log, 'smart-email-send.log', 'text/plain', 'inline');
                 $mail->send('no');
                 return array('result' => $out, 'error' => $err, 'log' => $tmp_send_log, 'message' => $mail->mime_message);
             } else {
                 return array('result' => $out, 'error' => $err, 'log' => $tmp_send_log, 'message' => '');
                 // skip returning the message
             }
             //end if else
             //--
     }
     //end switch
     //--
 }