function protectEmails(&$str, $area = '')
 {
     if (!is_string($str) || $str == '') {
         return;
     }
     // No action needed if no @ is found
     if (strpos($str, '@') === false) {
         return;
     }
     if ($this->params->protect_in_js && strpos($str, '</script>') !== false) {
         if (preg_match_all($this->params->regex_js, $str, $matches, PREG_SET_ORDER) > 0) {
             foreach ($matches as $match) {
                 $script = $match[0];
                 while (preg_match($this->params->regex_injs, $script, $regs, PREG_OFFSET_CAPTURE)) {
                     $protected = str_replace(array('.', '@'), array($regs[1][0] . ' + ' . 'String.fromCharCode(46)' . ' + ' . $regs[1][0], $regs[1][0] . ' + ' . 'String.fromCharCode(64)' . ' + ' . $regs[1][0]), $regs[0][0]);
                     $script = substr_replace($script, $protected, $regs[0][1], strlen($regs[0][0]));
                 }
                 $str = str_replace($match[0], $script, $str);
             }
         }
     }
     $this->protect($str);
     // Do not protect if {emailprotector=off} is found in text
     if (strpos($str, '{emailprotector=off}') !== false || strpos($str, '<!-- EPOFF -->') !== false) {
         $str = str_replace(array('<p>{emailprotector=off}</p>', '{emailprotector=off}'), '<!-- EPOFF -->', $str);
         NNProtect::unprotect($str);
         return;
     }
     // Fix derivatives of link code <a href="http://mce_host/ourdirectory/email@domain.com">email@domain.com</a>
     // This happens when inserting an email in TinyMCE, cancelling its suggestion to add the mailto: prefix...
     if (strpos($str, 'mce_host') !== false) {
         $str = preg_replace('#"http://mce_host([\\x20-\\x7f][^<>]+/)#i', '"mailto:', $str);
     }
     // Search for derivatives of link code <a href="mailto:email@domain.com">anytext</a>
     while (preg_match($this->params->regex_link, $str, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = str_replace('&amp;', '&', $regs[2][0]);
         $protected = $this->protectEmail($mail, $regs[5][0], $regs[1][0], $regs[4][0]);
         $str = substr_replace($str, $protected, $regs[0][1], strlen($regs[0][0]));
     }
     NNProtect::protectHtmlTags($str);
     $pre = '';
     $post = '';
     $len = strlen($str);
     // Split the string for very long strings
     if ($len > 2000) {
         $first = strpos($str, '@');
         if ($first === false) {
             NNProtect::unprotect($str);
             return;
         }
         $last = strrpos($str, '@');
         $first = max($first - 100, 0);
         $last = min($last + 100, $len);
         $pre = substr($str, 0, $first);
         $post = substr($str, $last);
         $str = substr($str, $first, $last - $first);
     }
     // Search for plain text email@domain.com
     while (preg_match($this->params->regex, $str, $regs, PREG_OFFSET_CAPTURE)) {
         $protected = $this->protectEmail('', $regs[1][0]);
         $str = substr_replace($str, $protected, $regs[1][1], strlen($regs[1][0]));
     }
     $str = $pre . $str . $post;
     NNProtect::unprotect($str);
 }