Example #1
0
 public function getEncoding(string $type = 'input') : string
 {
     if (!in_array($type, $this->inputs)) {
         throw new InvalidArgumentException('Error', 'invalidInput', $type);
     }
     return iconv_get_encoding($type . '_encoding');
 }
Example #2
0
 public function getEncoding($type = 'input')
 {
     if (!is_string($type) || empty($type)) {
         return Error::set(lang('Error', 'stringParameter', '1.(type)'));
     }
     return iconv_get_encoding($type . '_encoding');
 }
 protected function _purifyValue($val)
 {
     if ($val == $this->_example) {
         $val = null;
     } else {
         static $purifier = null;
         if ($this->_prevent_xss) {
             if (!empty($val)) {
                 if ($purifier == null && class_exists('HTMLPurifier')) {
                     if (iconv_get_encoding("internal_encoding") != "UTF-8") {
                         $config = HTMLPurifier_Config::createDefault();
                         $config->set('Core.Encoding', iconv_get_encoding("internal_encoding"));
                         // replace with your encoding
                         $purifier = new HTMLPurifier($config);
                     } else {
                         $purifier = new HTMLPurifier();
                     }
                 }
                 if ($purifier != null) {
                     $val = $purifier->purify($val);
                 }
             }
         }
     }
     return $val;
 }
 /**
  * @return string
  */
 public static function getOutputEncoding()
 {
     if (self::versionGreaterOrEquals56()) {
         return ini_get('output_encoding');
     }
     return iconv_get_encoding('output_encoding');
 }
 /**
  * Gets the current internal encoding.
  *
  * @return string The encoding "name".
  * @throws EncodingDetectionException If the detection fails.
  */
 public static function getInternalEncoding()
 {
     $encoding = iconv_get_encoding(static::ICONV_INTERNAL_ENCODING_FLAG);
     if (false === $encoding) {
         throw EncodingDetectionException::forCurrentSystem();
     }
     return $encoding;
 }
Example #6
0
 function mb_internal_encoding($enc = FALSE)
 {
     if (function_exists('iconv_set_encoding')) {
         if ($enc) {
             iconv_set_encoding('internal_encoding', $enc);
         }
         return iconv_get_encoding('internal_encoding');
     }
     return '';
 }
Example #7
0
 public function setEncoding($encoding = null)
 {
     if ($encoding !== null) {
         $orig = iconv_get_encoding('internal_encoding');
         $result = iconv_set_encoding('internal_encoding', $encoding);
         if (!$result) {
             require_once 'Zend/Validate/Exception.php';
             throw new Zend_Validate_Exception('Given encoding not supported on this OS!');
         }
         iconv_set_encoding('internal_encoding', $orig);
     }
     $this->_encoding = $encoding;
     return $this;
 }
Example #8
0
 /**
  * init iconv
  */
 protected static function initIconv()
 {
     if (extension_loaded('iconv')) {
         if ('UTF-8' !== strtoupper(iconv_get_encoding('input_encoding'))) {
             iconv_set_encoding('input_encoding', 'UTF-8');
         }
         if ('UTF-8' !== strtoupper(iconv_get_encoding('internal_encoding'))) {
             iconv_set_encoding('internal_encoding', 'UTF-8');
         }
         if ('UTF-8' !== strtoupper(iconv_get_encoding('output_encoding'))) {
             iconv_set_encoding('output_encoding', 'UTF-8');
         }
     } elseif (!defined('ICONV_IMPL')) {
         require __DIR__ . '/bootup/iconv.php';
     }
 }
Example #9
0
 public static function initIconv()
 {
     if (extension_loaded('iconv')) {
         if ('UTF-8' !== strtoupper(iconv_get_encoding('input_encoding'))) {
             iconv_set_encoding('input_encoding', 'UTF-8');
         }
         if ('UTF-8' !== strtoupper(iconv_get_encoding('internal_encoding'))) {
             iconv_set_encoding('internal_encoding', 'UTF-8');
         }
         if ('UTF-8' !== strtoupper(iconv_get_encoding('output_encoding'))) {
             iconv_set_encoding('output_encoding', 'UTF-8');
         }
     } elseif (!function_exists('iconv')) {
         require __DIR__ . '/Bootup/iconv.php';
     }
 }
 public function loadResources($language_iso_code, __ActionIdentity $action_identity = null)
 {
     $language_file = $this->getLanguageFile($language_iso_code, $action_identity);
     $return_value = array();
     if (is_file($language_file) && is_readable($language_file)) {
         $resources = parse_ini_file($language_file, false);
         foreach ($resources as $key => $value) {
             if ($this->_encoding != null) {
                 $value = iconv($this->_encoding, iconv_get_encoding("internal_encoding"), $value);
             }
             $resource = $this->_createResource($key, $value);
             $return_value[$key] = $resource;
             unset($resource);
         }
     }
     return $return_value;
 }
Example #11
0
 public function setEncoding($encoding = null)
 {
     if ($encoding !== null) {
         $orig = iconv_get_encoding('internal_encoding');
         if (PHP_VERSION_ID < 50600) {
             $result = iconv_set_encoding('internal_encoding', $encoding);
         } else {
             $result = ini_set('default_charset', $encoding);
         }
         if (!$result) {
             throw new Exception('Given encoding not supported on this OS!');
         }
         if (PHP_VERSION_ID < 50600) {
             iconv_set_encoding('internal_encoding', $orig);
         } else {
             ini_set('default_charset', $orig);
         }
     }
     $this->_encoding = $encoding;
     return $this;
 }
Example #12
0
 static function initIconv()
 {
     if (extension_loaded('iconv')) {
         if ('UTF-8' !== iconv_get_encoding('input_encoding')) {
             iconv_set_encoding('input_encoding', 'UTF-8');
             ini_set('iconv.input_encoding', 'UTF-8');
         }
         if ('UTF-8' !== iconv_get_encoding('internal_encoding')) {
             iconv_set_encoding('internal_encoding', 'UTF-8');
             ini_set('iconv.internal_encoding', 'UTF-8');
         }
         if ('UTF-8' !== iconv_get_encoding('output_encoding')) {
             iconv_set_encoding('output_encoding', 'UTF-8');
             ini_set('iconv.output_encoding', 'UTF-8');
         }
     } else {
         if (!defined('ICONV_IMPL')) {
             require __DIR__ . '/Bootup/iconv.php';
         }
     }
 }
Example #13
0
 /**
  * Sets a new encoding to use
  *
  * @param string $encoding
  * @return \Zend\Validator\StringLength
  */
 public function setEncoding($encoding = null)
 {
     if ($encoding !== null) {
         $orig = iconv_get_encoding('internal_encoding');
         $result = iconv_set_encoding('internal_encoding', $encoding);
         if (!$result) {
             throw new Exception\InvalidArgumentException('Given encoding not supported on this OS!');
         }
         iconv_set_encoding('internal_encoding', $orig);
     }
     $this->_encoding = $encoding;
     return $this;
 }
/**
 * Sets specified internal encoding configuration variables within the PHP iconv extension.
 * @param string $type					The parameter $type could be: 'iconv_internal_encoding', 'iconv_input_encoding', or 'iconv_output_encoding'.
 * @param string $encoding (optional)	The desired encoding to be set.
 * @return bool							Returns TRUE on success, FALSE on error.
 * Note: This function is used in the global initialization script for setting these three internal encodings to the platform's character set.
 * @link http://php.net/manual/en/function.iconv-set-encoding
 */
function _api_iconv_set_encoding($type, $encoding = null)
{
    static $iconv_internal_encoding = null;
    static $iconv_input_encoding = null;
    static $iconv_output_encoding = null;
    if (!ICONV_INSTALLED) {
        return false;
    }
    switch ($type) {
        case 'iconv_internal_encoding':
            if (empty($encoding)) {
                if (is_null($iconv_internal_encoding)) {
                    $iconv_internal_encoding = @iconv_get_encoding($type);
                }
                return $iconv_internal_encoding;
            }
            if (_api_iconv_supports($encoding)) {
                if (@iconv_set_encoding($type, $encoding)) {
                    $iconv_internal_encoding = $encoding;
                    return true;
                }
                return false;
            }
            return false;
        case 'iconv_input_encoding':
            if (empty($encoding)) {
                if (is_null($iconv_input_encoding)) {
                    $iconv_input_encoding = @iconv_get_encoding($type);
                }
                return $iconv_input_encoding;
            }
            if (_api_iconv_supports($encoding)) {
                if (@iconv_set_encoding($type, $encoding)) {
                    $iconv_input_encoding = $encoding;
                    return true;
                }
                return false;
            }
            return false;
        case 'iconv_output_encoding':
            if (empty($encoding)) {
                if (is_null($iconv_output_encoding)) {
                    $iconv_output_encoding = @iconv_get_encoding($type);
                }
                return $iconv_output_encoding;
            }
            if (_api_iconv_supports($encoding)) {
                if (@iconv_set_encoding($type, $encoding)) {
                    $iconv_output_encoding = $encoding;
                    return true;
                }
                return false;
            }
            return false;
    }
    return false;
}
Example #15
0
 public function testDecodeString()
 {
     $is = Mime\Decode::decodeQuotedPrintable('=?UTF-8?Q?"Peter M=C3=BCller"?= <*****@*****.**>');
     $should = iconv('UTF-8', iconv_get_encoding('internal_encoding'), '"Peter Müller" <*****@*****.**>');
     $this->assertEquals($is, $should);
 }
Example #16
0
 /**
  * Sets a new encoding to use
  *
  * @param string $encoding
  * @return Zend_Validate_StringLength
  */
 public function setEncoding($encoding = null)
 {
     if ($encoding !== null) {
         $orig = PHP_VERSION_ID < 50600 ? iconv_get_encoding('internal_encoding') : ini_get('default_charset');
         if (PHP_VERSION_ID < 50600) {
             $result = iconv_set_encoding('internal_encoding', $encoding);
         } else {
             $result = @ini_set('default_charset', $encoding);
         }
         if (!$result) {
             require_once 'Zend/Validate/Exception.php';
             throw new Zend_Validate_Exception('Given encoding not supported on this OS!');
         }
         if (PHP_VERSION_ID < 50600) {
             iconv_set_encoding('internal_encoding', $orig);
         } else {
             @ini_set('default_charset', $orig);
         }
     }
     $this->_encoding = $encoding;
     return $this;
 }
Example #17
0
 /**
  * Internal method to retrieve the current encoding via the ini setting
  * default_charset for PHP >= 5.6 or iconv_get_encoding otherwise.
  *
  * @return string
  */
 protected static function _getEncoding()
 {
     $oenc = PHP_VERSION_ID < 50600 ? iconv_get_encoding('internal_encoding') : ini_get('default_charset');
     return $oenc;
 }
 /**
  * Sets the iconv-internal-encodings, since Zend_Mime does not allow
  * for passing an indivdual charset for decoding.
  * This is a simple helper which allows for either setting the encoding
  * to utf-8 or reset the endoding to the old value.
  *
  * @param string $type
  *
  */
 protected function _setIconvEncoding($type)
 {
     if ($type != self::ICONV_UTF_8) {
         if (!empty($this->_oldEncodings)) {
             iconv_set_encoding('input_encoding', $this->_oldEncodings['input_encoding']);
             iconv_set_encoding('output_encoding', $this->_oldEncodings['output_encoding']);
             iconv_set_encoding('internal_encoding', $this->_oldEncodings['internal_encoding']);
         }
     } else {
         if (empty($this->_oldEncodings)) {
             $this->_oldEncodings = array('input_encoding' => iconv_get_encoding('input_encoding'), 'output_encoding' => iconv_get_encoding('output_encoding'), 'internal_encoding' => iconv_get_encoding('internal_encoding'));
         }
         iconv_set_encoding('input_encoding', 'UTF-8');
         iconv_set_encoding('output_encoding', 'UTF-8');
         iconv_set_encoding('internal_encoding', 'UTF-8');
     }
 }
Example #19
0
 /**
  * Creates a new Zend_Validate_Hostname object for each test method
  *
  * @return void
  */
 public function setUp()
 {
     $this->_origEncoding = iconv_get_encoding('internal_encoding');
     $this->_validator = new Zend_Validate_Hostname();
 }
Example #20
0
 /**
  * Returns a part of a string.
  * Unit-tested by Kasper (single byte charsets only)
  *
  * @param string $charset The character set
  * @param string $string Character string
  * @param int $start Start position (character position)
  * @param int $len Length (in characters)
  * @return string The substring
  * @see substr(), mb_substr()
  */
 public function substr($charset, $string, $start, $len = NULL)
 {
     if ($len === 0 || $string === '') {
         return '';
     }
     if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] === 'mbstring') {
         // Cannot omit $len, when specifying charset
         if ($len === NULL) {
             // Save internal encoding
             $enc = mb_internal_encoding();
             mb_internal_encoding($charset);
             $str = mb_substr($string, $start);
             // Restore internal encoding
             mb_internal_encoding($enc);
             return $str;
         } else {
             return mb_substr($string, $start, $len, $charset);
         }
     } elseif ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] === 'iconv') {
         // Cannot omit $len, when specifying charset
         if ($len === NULL) {
             // Save internal encoding
             $enc = iconv_get_encoding('internal_encoding');
             iconv_set_encoding('internal_encoding', $charset);
             $str = iconv_substr($string, $start);
             // Restore internal encoding
             iconv_set_encoding('internal_encoding', $enc);
             return $str;
         } else {
             return iconv_substr($string, $start, $len, $charset);
         }
     } elseif ($charset === 'utf-8') {
         return $this->utf8_substr($string, $start, $len);
     } elseif ($this->eucBasedSets[$charset]) {
         return $this->euc_substr($string, $start, $charset, $len);
     } elseif ($this->twoByteSets[$charset]) {
         return substr($string, $start * 2, $len * 2);
     } elseif ($this->fourByteSets[$charset]) {
         return substr($string, $start * 4, $len * 4);
     }
     // Treat everything else as single-byte encoding
     return $len === NULL ? substr($string, $start) : substr($string, $start, $len);
 }
Example #21
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if the $value is a valid hostname with respect to the current allow option
  *
  * @param  string $value
  * @throws Zend_Validate_Exception if a fatal error occurs for validation process
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value)) {
         $this->_error(self::INVALID);
         return false;
     }
     $this->_setValue($value);
     // Check input against IP address schema
     if (preg_match('/^[0-9a-f:.]*$/i', $value) && $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) {
         if (!($this->_options['allow'] & self::ALLOW_IP)) {
             $this->_error(self::IP_ADDRESS_NOT_ALLOWED);
             return false;
         } else {
             return true;
         }
     }
     // RFC3986 3.2.2 states:
     //
     //     The rightmost domain label of a fully qualified domain name
     //     in DNS may be followed by a single "." and should be if it is
     //     necessary to distinguish between the complete domain name and
     //     some local domain.
     //
     // (see ZF-6363)
     // Local hostnames are allowed to be partitial (ending '.')
     if ($this->_options['allow'] & self::ALLOW_LOCAL) {
         if (substr($value, -1) === '.') {
             $value = substr($value, 0, -1);
             if (substr($value, -1) === '.') {
                 // Empty hostnames (ending '..') are not allowed
                 $this->_error(self::INVALID_LOCAL_NAME);
                 return false;
             }
         }
     }
     $domainParts = explode('.', $value);
     // Prevent partitial IP V4 adresses (ending '.')
     if (count($domainParts) == 4 && preg_match('/^[0-9.a-e:.]*$/i', $value) && $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) {
         $this->_error(self::INVALID_LOCAL_NAME);
     }
     // Check input against DNS hostname schema
     if (count($domainParts) > 1 && strlen($value) >= 4 && strlen($value) <= 254) {
         $status = false;
         $origenc = iconv_get_encoding('internal_encoding');
         iconv_set_encoding('internal_encoding', 'UTF-8');
         do {
             // First check TLD
             $matches = array();
             if (preg_match('/([^.]{2,10})$/i', end($domainParts), $matches) || end($domainParts) == 'ایران' || end($domainParts) == '中国' || end($domainParts) == '公司' || end($domainParts) == '网络') {
                 reset($domainParts);
                 // Hostname characters are: *(label dot)(label dot label); max 254 chars
                 // label: id-prefix [*ldh{61} id-prefix]; max 63 chars
                 // id-prefix: alpha / digit
                 // ldh: alpha / digit / dash
                 // Match TLD against known list
                 $this->_tld = strtolower($matches[1]);
                 if ($this->_options['tld']) {
                     if (!in_array($this->_tld, $this->_validTlds)) {
                         $this->_error(self::UNKNOWN_TLD);
                         $status = false;
                         break;
                     }
                 }
                 /**
                  * Match against IDN hostnames
                  * Note: Keep label regex short to avoid issues with long patterns when matching IDN hostnames
                  * @see Zend_Validate_Hostname_Interface
                  */
                 $regexChars = array(0 => '/^[a-z0-9\\x2d]{1,63}$/i');
                 if ($this->_options['idn'] && isset($this->_validIdns[strtoupper($this->_tld)])) {
                     if (is_string($this->_validIdns[strtoupper($this->_tld)])) {
                         $regexChars += (include $this->_validIdns[strtoupper($this->_tld)]);
                     } else {
                         $regexChars += $this->_validIdns[strtoupper($this->_tld)];
                     }
                 }
                 // Check each hostname part
                 $check = 0;
                 foreach ($domainParts as $domainPart) {
                     // Decode Punycode domainnames to IDN
                     if (strpos($domainPart, 'xn--') === 0) {
                         $domainPart = $this->decodePunycode(substr($domainPart, 4));
                         if ($domainPart === false) {
                             return false;
                         }
                     }
                     // Check dash (-) does not start, end or appear in 3rd and 4th positions
                     if (strpos($domainPart, '-') === 0 || strlen($domainPart) > 2 && strpos($domainPart, '-', 2) == 2 && strpos($domainPart, '-', 3) == 3 || strpos($domainPart, '-') === strlen($domainPart) - 1) {
                         $this->_error(self::INVALID_DASH);
                         $status = false;
                         break 2;
                     }
                     // Check each domain part
                     $checked = false;
                     foreach ($regexChars as $regexKey => $regexChar) {
                         $status = @preg_match($regexChar, $domainPart);
                         if ($status > 0) {
                             $length = 63;
                             if (array_key_exists(strtoupper($this->_tld), $this->_idnLength) && array_key_exists($regexKey, $this->_idnLength[strtoupper($this->_tld)])) {
                                 $length = $this->_idnLength[strtoupper($this->_tld)];
                             }
                             if (iconv_strlen($domainPart, 'UTF-8') > $length) {
                                 $this->_error(self::INVALID_HOSTNAME);
                             } else {
                                 $checked = true;
                                 break;
                             }
                         }
                     }
                     if ($checked) {
                         ++$check;
                     }
                 }
                 // If one of the labels doesn't match, the hostname is invalid
                 if ($check !== count($domainParts)) {
                     $this->_error(self::INVALID_HOSTNAME_SCHEMA);
                     $status = false;
                 }
             } else {
                 // Hostname not long enough
                 $this->_error(self::UNDECIPHERABLE_TLD);
                 $status = false;
             }
         } while (false);
         iconv_set_encoding('internal_encoding', $origenc);
         // If the input passes as an Internet domain name, and domain names are allowed, then the hostname
         // passes validation
         if ($status && $this->_options['allow'] & self::ALLOW_DNS) {
             return true;
         }
     } else {
         if ($this->_options['allow'] & self::ALLOW_DNS) {
             $this->_error(self::INVALID_HOSTNAME);
         }
     }
     // Check for URI Syntax (RFC3986)
     if ($this->_options['allow'] & self::ALLOW_URI) {
         if (preg_match("/^([a-zA-Z0-9-._~!\$&\\'()*+,;=]|%[[:xdigit:]]{2}){1,254}\$/i", $value)) {
             return true;
         } else {
             $this->_error(self::INVALID_URI);
         }
     }
     // Check input against local network name schema; last chance to pass validation
     $regexLocal = '/^(([a-zA-Z0-9\\x2d]{1,63}\\x2e)*[a-zA-Z0-9\\x2d]{1,63}[\\x2e]{0,1}){1,254}$/';
     $status = @preg_match($regexLocal, $value);
     // If the input passes as a local network name, and local network names are allowed, then the
     // hostname passes validation
     $allowLocal = $this->_options['allow'] & self::ALLOW_LOCAL;
     if ($status && $allowLocal) {
         return true;
     }
     // If the input does not pass as a local network name, add a message
     if (!$status) {
         $this->_error(self::INVALID_LOCAL_NAME);
     }
     // If local network names are not allowed, add a message
     if ($status && !$allowLocal) {
         $this->_error(self::LOCAL_NAME_NOT_ALLOWED);
     }
     return false;
 }
Example #22
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if the $value is a valid hostname with respect to the current allow option
  *
  * @param  string $value
  * @throws Zend_Validate_Exception if a fatal error occurs for validation process
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value)) {
         $this->_error(self::INVALID);
         return false;
     }
     $this->_setValue($value);
     // Check input against IP address schema
     if (preg_match('/^[0-9.a-e:.]*$/i', $value) && $this->_ipValidator->setTranslator($this->getTranslator())->isValid($value)) {
         if (!($this->_allow & self::ALLOW_IP)) {
             $this->_error(self::IP_ADDRESS_NOT_ALLOWED);
             return false;
         } else {
             return true;
         }
     }
     // Check input against DNS hostname schema
     $domainParts = explode('.', $value);
     if (count($domainParts) > 1 && strlen($value) >= 4 && strlen($value) <= 254) {
         $status = false;
         $origenc = iconv_get_encoding('internal_encoding');
         iconv_set_encoding('internal_encoding', 'UTF-8');
         do {
             // First check TLD
             $matches = array();
             if (preg_match('/([^.]{2,10})$/i', end($domainParts), $matches) || end($domainParts) == 'ایران' || end($domainParts) == '中国' || end($domainParts) == '公司' || end($domainParts) == '网络') {
                 reset($domainParts);
                 // Hostname characters are: *(label dot)(label dot label); max 254 chars
                 // label: id-prefix [*ldh{61} id-prefix]; max 63 chars
                 // id-prefix: alpha / digit
                 // ldh: alpha / digit / dash
                 // Match TLD against known list
                 $this->_tld = strtolower($matches[1]);
                 if ($this->_validateTld) {
                     if (!in_array($this->_tld, $this->_validTlds)) {
                         $this->_error(self::UNKNOWN_TLD);
                         $status = false;
                         break;
                     }
                 }
                 /**
                  * Match against IDN hostnames
                  * Note: Keep label regex short to avoid issues with long patterns when matching IDN hostnames
                  * @see Zend_Validate_Hostname_Interface
                  */
                 $regexChars = array(0 => '/^[a-z0-9\\x2d]{1,63}$/i');
                 if ($this->_validateIdn && isset($this->_validIdns[strtoupper($this->_tld)])) {
                     if (is_string($this->_validIdns[strtoupper($this->_tld)])) {
                         $regexChars += (include $this->_validIdns[strtoupper($this->_tld)]);
                     } else {
                         $regexChars += $this->_validIdns[strtoupper($this->_tld)];
                     }
                 }
                 // Check each hostname part
                 $valid = true;
                 foreach ($domainParts as $domainPart) {
                     // Decode Punycode domainnames to IDN
                     if (strpos($domainPart, 'xn--') === 0) {
                         $domainPart = $this->decodePunycode(substr($domainPart, 4));
                         if ($domainPart === false) {
                             return false;
                         }
                     }
                     // Check dash (-) does not start, end or appear in 3rd and 4th positions
                     if (strpos($domainPart, '-') === 0 || strlen($domainPart) > 2 && strpos($domainPart, '-', 2) == 2 && strpos($domainPart, '-', 3) == 3 || strpos($domainPart, '-') === strlen($domainPart) - 1) {
                         $this->_error(self::INVALID_DASH);
                         $status = false;
                         break 2;
                     }
                     // Check each domain part
                     $check = false;
                     foreach ($regexChars as $regexKey => $regexChar) {
                         $status = @preg_match($regexChar, $domainPart);
                         if ($status === false) {
                             iconv_set_encoding('internal_encoding', $origenc);
                             require_once 'Zend/Validate/Exception.php';
                             throw new Zend_Validate_Exception('Internal error: DNS validation failed');
                         } elseif ($status !== 0) {
                             $length = 63;
                             if (array_key_exists(strtoupper($this->_tld), $this->_idnLength) && array_key_exists($regexKey, $this->_idnLength[strtoupper($this->_tld)])) {
                                 $length = $this->_idnLength[strtoupper($this->_tld)];
                             }
                             if (iconv_strlen($domainPart, 'UTF-8') > $length) {
                                 $this->_error(self::INVALID_HOSTNAME);
                             } else {
                                 $check = true;
                                 break 2;
                             }
                         }
                     }
                     if (!$check) {
                         $valid = false;
                     }
                 }
                 // If all labels didn't match, the hostname is invalid
                 if (!$valid) {
                     $this->_error(self::INVALID_HOSTNAME_SCHEMA);
                     $status = false;
                 }
             } else {
                 // Hostname not long enough
                 $this->_error(self::UNDECIPHERABLE_TLD);
                 $status = false;
             }
         } while (false);
         iconv_set_encoding('internal_encoding', $origenc);
         // If the input passes as an Internet domain name, and domain names are allowed, then the hostname
         // passes validation
         if ($status && $this->_allow & self::ALLOW_DNS) {
             return true;
         }
     } else {
         $this->_error(self::INVALID_HOSTNAME);
     }
     // Check input against local network name schema; last chance to pass validation
     $regexLocal = '/^(([a-zA-Z0-9\\x2d]{1,63}\\x2e)*[a-zA-Z0-9\\x2d]{1,63}){1,254}$/';
     $status = @preg_match($regexLocal, $value);
     if (false === $status) {
         /**
          * Regex error
          * @see Zend_Validate_Exception
          */
         require_once 'Zend/Validate/Exception.php';
         throw new Zend_Validate_Exception('Internal error: local network name validation failed');
     }
     // If the input passes as a local network name, and local network names are allowed, then the
     // hostname passes validation
     $allowLocal = $this->_allow & self::ALLOW_LOCAL;
     if ($status && $allowLocal) {
         return true;
     }
     // If the input does not pass as a local network name, add a message
     if (!$status) {
         $this->_error(self::INVALID_LOCAL_NAME);
     }
     // If local network names are not allowed, add a message
     if ($status && !$allowLocal) {
         $this->_error(self::LOCAL_NAME_NOT_ALLOWED);
     }
     return false;
 }
 /**
  * Creates a new Zend_Validate_Hostname object for each test method
  *
  * @return void
  */
 public function setUp()
 {
     $this->_origEncoding = PHP_VERSION_ID < 50600 ? iconv_get_encoding('internal_encoding') : ini_get('default_charset');
     $this->_validator = new Zend_Validate_Hostname();
 }
Example #24
0
function buildUtf8LangFile($langFile)
{
    $content = '';
    if ($hdl = fopen($langFile, 'r')) {
        $content = fread($hdl, filesize($langFile));
        fclose($hdl);
        // Charset auf UTF-8 ändern
        $content = preg_replace('/^htmlcharset = (.*)$/m', 'htmlcharset = utf-8', $content);
    }
    $utf8File = str_replace('.lang', '_utf8.lang', $langFile);
    if ($hdl = fopen($utf8File, 'w+')) {
        fwrite($hdl, iconv(iconv_get_encoding($content), 'UTF-8', $content));
        fclose($hdl);
    }
}
Example #25
0
 static function convert_encoding($a, $to, $from = NULL)
 {
     static $meth = NULL;
     isset($meth) or $meth = function_exists('mb_convert_encoding');
     isset($from) or $from = $meth ? mb_internal_encoding() : iconv_get_encoding('internal_encoding');
     if (is_array($a)) {
         $ret = array();
         foreach ($a as $n => $v) {
             $ret[is_string($n) ? self::convert_encoding($n, $to, $from) : $n] = is_string($v) || is_array($v) || $v instanceof stdClass ? self::convert_encoding($v, $to, $from) : $v;
         }
         return $ret;
     } elseif ($a instanceof stdClass) {
         $ret = (object) array();
         foreach ($a as $n => $v) {
             $ret->{is_string($n) ? self::convert_encoding($n, $to, $from) : $n} = is_string($v) || is_array($v) || $v instanceof stdClass ? self::convert_encoding($v, $to, $from) : $v;
         }
         return $ret;
     }
     return is_string($a) ? $meth ? mb_convert_encoding($a, $to, $from) : iconv($from, $to, $a) : $a;
 }
                    <div id="wrapper-search">
                        <div id="share">

                            <?php 
if (isset($zonal_actual_label)) {
    ?>
                                <div id="zonal-actual"><p><?php 
    echo $zonal_actual_label;
    ?>
</p></div>
                            <?php 
}
?>

                            <?php 
$arr_codificacion = iconv_get_encoding();
$codificacion = $arr_codificacion['internal_encoding'];
?>
                            <p>
                                <?php 
echo utf8_encode(ucfirst(strftime("%A %d.%m.%Y")));
?>
<br /><span id="hora"></span></p>
                            <!--
                                                  <p style="text-transform:uppercase;">
                                                          <strong>Compartinos:</strong> 
                                                          <a href="http://www.facebook.com/pages/Zonales/139612986080624">
                                                                  <img src="<?php 
echo $this->baseurl;
?>
/images/social/facebook_16x16.png" alt="Zonales en Facebook" />
Example #27
0
 public function testGetDecodedHeader()
 {
     $message = new Zend_Mail_Message(array('file' => $this->_file));
     $this->assertEquals($message->from, iconv('UTF-8', iconv_get_encoding('internal_encoding'), '"Peter Müller" <*****@*****.**>'));
 }
Example #28
0
 public function testGetDecodedHeader()
 {
     $message = new Zend_Mail_Message(array('file' => $this->_file));
     $enc = PHP_VERSION_ID < 50600 ? iconv_get_encoding('internal_encoding') : ini_get('default_charset');
     $this->assertEquals($message->from, iconv('UTF-8', $enc, '"Peter Müller" <*****@*****.**>'));
 }
 /**
  * Parse date and split in named array fields
  *
  * @param   string  $date     Date string to parse
  * @param   array   $options  Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details.
  * @return  array             Possible array members: day, month, year, hour, minute, second, fixed, format
  */
 private static function _parseDate($date, $options)
 {
     if (!self::_getUniCodeSupport()) {
         trigger_error("Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE);
     }
     $options = self::_checkOptions($options) + self::$_options;
     $test = array('h', 'H', 'm', 's', 'y', 'Y', 'M', 'd', 'D', 'E', 'S', 'l', 'B', 'I', 'X', 'r', 'U', 'G', 'w', 'e', 'a', 'A', 'Z', 'z', 'v');
     $format = $options['date_format'];
     $number = $date;
     // working copy
     $result['date_format'] = $format;
     // save the format used to normalize $number (convenience)
     $result['locale'] = $options['locale'];
     // save the locale used to normalize $number (convenience)
     $oenc = iconv_get_encoding('internal_encoding');
     iconv_set_encoding('internal_encoding', 'UTF-8');
     $day = iconv_strpos($format, 'd');
     $month = iconv_strpos($format, 'M');
     $year = iconv_strpos($format, 'y');
     $hour = iconv_strpos($format, 'H');
     $min = iconv_strpos($format, 'm');
     $sec = iconv_strpos($format, 's');
     $am = null;
     if ($hour === false) {
         $hour = iconv_strpos($format, 'h');
     }
     if ($year === false) {
         $year = iconv_strpos($format, 'Y');
     }
     if ($day === false) {
         $day = iconv_strpos($format, 'E');
         if ($day === false) {
             $day = iconv_strpos($format, 'D');
         }
     }
     if ($day !== false) {
         $parse[$day] = 'd';
         if (!empty($options['locale']) && $options['locale'] !== 'root' && (!is_object($options['locale']) || (string) $options['locale'] !== 'root')) {
             // erase day string
             $daylist = Zend_Locale_Data::getList($options['locale'], 'day');
             foreach ($daylist as $key => $name) {
                 if (iconv_strpos($number, $name) !== false) {
                     $number = str_replace($name, "EEEE", $number);
                     break;
                 }
             }
         }
     }
     $position = false;
     if ($month !== false) {
         $parse[$month] = 'M';
         if (!empty($options['locale']) && $options['locale'] !== 'root' && (!is_object($options['locale']) || (string) $options['locale'] !== 'root')) {
             // prepare to convert month name to their numeric equivalents, if requested,
             // and we have a $options['locale']
             $position = self::_replaceMonth($number, Zend_Locale_Data::getList($options['locale'], 'month'));
             if ($position === false) {
                 $position = self::_replaceMonth($number, Zend_Locale_Data::getList($options['locale'], 'month', array('gregorian', 'format', 'abbreviated')));
             }
         }
     }
     if ($year !== false) {
         $parse[$year] = 'y';
     }
     if ($hour !== false) {
         $parse[$hour] = 'H';
     }
     if ($min !== false) {
         $parse[$min] = 'm';
     }
     if ($sec !== false) {
         $parse[$sec] = 's';
     }
     if (empty($parse)) {
         iconv_set_encoding('internal_encoding', $oenc);
         // require_once 'Zend/Locale/Exception.php';
         throw new Zend_Locale_Exception("Unknown date format, neither date nor time in '" . $format . "' found");
     }
     ksort($parse);
     // get daytime
     if (iconv_strpos($format, 'a') !== false) {
         if (iconv_strpos(strtoupper($number), strtoupper(Zend_Locale_Data::getContent($options['locale'], 'am'))) !== false) {
             $am = true;
         } else {
             if (iconv_strpos(strtoupper($number), strtoupper(Zend_Locale_Data::getContent($options['locale'], 'pm'))) !== false) {
                 $am = false;
             }
         }
     }
     // split number parts
     $split = false;
     preg_match_all('/\\d+/u', $number, $splitted);
     if (count($splitted[0]) == 0) {
         iconv_set_encoding('internal_encoding', $oenc);
         // require_once 'Zend/Locale/Exception.php';
         throw new Zend_Locale_Exception("No date part in '{$date}' found.");
     }
     if (count($splitted[0]) == 1) {
         $split = 0;
     }
     $cnt = 0;
     foreach ($parse as $key => $value) {
         switch ($value) {
             case 'd':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['day'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['day'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 'M':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['month'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['month'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 'y':
                 $length = 2;
                 if (iconv_substr($format, $year, 4) == 'yyyy' || iconv_substr($format, $year, 4) == 'YYYY') {
                     $length = 4;
                 }
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['year'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['year'] = iconv_substr($splitted[0][0], $split, $length);
                     $split += $length;
                 }
                 ++$cnt;
                 break;
             case 'H':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['hour'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['hour'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 'm':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['minute'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['minute'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 's':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['second'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['second'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
         }
     }
     // AM/PM correction
     if ($hour !== false) {
         if ($am === true and $result['hour'] == 12) {
             $result['hour'] = 0;
         } else {
             if ($am === false and $result['hour'] != 12) {
                 $result['hour'] += 12;
             }
         }
     }
     if ($options['fix_date'] === true) {
         $result['fixed'] = 0;
         // nothing has been "fixed" by swapping date parts around (yet)
     }
     if ($day !== false) {
         // fix false month
         if (isset($result['day']) and isset($result['month'])) {
             if ($position !== false and (iconv_strpos($date, $result['day']) === false or isset($result['year']) and iconv_strpos($date, $result['year']) === false)) {
                 if ($options['fix_date'] !== true) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     // require_once 'Zend/Locale/Exception.php';
                     throw new Zend_Locale_Exception("Unable to parse date '{$date}' using '" . $format . "' (false month, {$position}, {$month})");
                 }
                 $temp = $result['day'];
                 $result['day'] = $result['month'];
                 $result['month'] = $temp;
                 $result['fixed'] = 1;
             }
         }
         // fix switched values d <> y
         if (isset($result['day']) and isset($result['year'])) {
             if ($result['day'] > 31) {
                 if ($options['fix_date'] !== true) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     // require_once 'Zend/Locale/Exception.php';
                     throw new Zend_Locale_Exception("Unable to parse date '{$date}' using '" . $format . "' (d <> y)");
                 }
                 $temp = $result['year'];
                 $result['year'] = $result['day'];
                 $result['day'] = $temp;
                 $result['fixed'] = 2;
             }
         }
         // fix switched values M <> y
         if (isset($result['month']) and isset($result['year'])) {
             if ($result['month'] > 31) {
                 if ($options['fix_date'] !== true) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     // require_once 'Zend/Locale/Exception.php';
                     throw new Zend_Locale_Exception("Unable to parse date '{$date}' using '" . $format . "' (M <> y)");
                 }
                 $temp = $result['year'];
                 $result['year'] = $result['month'];
                 $result['month'] = $temp;
                 $result['fixed'] = 3;
             }
         }
         // fix switched values M <> d
         if (isset($result['month']) and isset($result['day'])) {
             if ($result['month'] > 12) {
                 if ($options['fix_date'] !== true || $result['month'] > 31) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     // require_once 'Zend/Locale/Exception.php';
                     throw new Zend_Locale_Exception("Unable to parse date '{$date}' using '" . $format . "' (M <> d)");
                 }
                 $temp = $result['day'];
                 $result['day'] = $result['month'];
                 $result['month'] = $temp;
                 $result['fixed'] = 4;
             }
         }
     }
     if (isset($result['year'])) {
         if (iconv_strlen($result['year']) == 2 && $result['year'] < 10 || (iconv_strpos($format, 'yy') !== false && iconv_strpos($format, 'yyyy') === false || iconv_strpos($format, 'YY') !== false && iconv_strpos($format, 'YYYY') === false)) {
             if ($result['year'] >= 0 && $result['year'] < 100) {
                 if ($result['year'] < 70) {
                     $result['year'] = (int) $result['year'] + 100;
                 }
                 $result['year'] = (int) $result['year'] + 1900;
             }
         }
     }
     iconv_set_encoding('internal_encoding', $oenc);
     return $result;
 }
 /**
  * 	Check Pop3 Moblog
  *
  * 	
  */
 function check_pop_moblog()
 {
     /** ------------------------------
     		/**  Email Login Check
     		/** ------------------------------*/
     $port = 110;
     $ssl = substr($this->moblog_array['moblog_email_server'], 0, 6) == 'ssl://';
     if ($ssl or stripos($this->moblog_array['moblog_email_server'], 'gmail') !== FALSE) {
         if (!$ssl) {
             $this->moblog_array['moblog_email_server'] = 'ssl://' . $this->moblog_array['moblog_email_server'];
         }
         $port = 995;
     }
     if (!($this->fp = @fsockopen($this->moblog_array['moblog_email_server'], $port, $errno, $errstr, 20))) {
         $this->message_array[] = 'no_server_connection';
         return FALSE;
     }
     if (strncasecmp(fgets($this->fp, 1024), '+OK', 3) != 0) {
         $this->message_array[] = 'invalid_server_response';
         @fclose($this->fp);
         return FALSE;
     }
     if (strncasecmp($this->pop_command("USER " . base64_decode($this->moblog_array['moblog_email_login'])), '+OK', 3) != 0) {
         // Windows servers something require a different line break.
         // So, we change the line break and try again.
         $this->pop_newline = "\r\n";
         if (strncasecmp($this->pop_command("USER " . base64_decode($this->moblog_array['moblog_email_login'])), '+OK', 3) != 0) {
             $this->message_array[] = 'invalid_username';
             $line = $this->pop_command("QUIT");
             @fclose($this->fp);
             return FALSE;
         }
     }
     if (strncasecmp($this->pop_command("PASS " . base64_decode($this->moblog_array['moblog_email_password'])), '+OK', 3) != 0) {
         $this->message_array[] = 'invalid_password';
         $line = $this->pop_command("QUIT");
         @fclose($this->fp);
         return FALSE;
     }
     /** ------------------------------
     		/**  Got Mail?
     		/** ------------------------------*/
     if (!($line = $this->pop_command("STAT"))) {
         $this->message_array[] = 'unable_to_retrieve_emails';
         $line = $this->pop_command("QUIT");
         @fclose($this->fp);
         return FALSE;
     }
     $stats = explode(" ", $line);
     $total = !isset($stats['1']) ? 0 : $stats['1'];
     $this->total_size = !isset($stats['2']) ? 0 : $stats['2'];
     if ($total == 0) {
         $this->message_array[] = 'no_valid_emails';
         $line = $this->pop_command("QUIT");
         @fclose($this->fp);
         return;
     }
     /** ------------------------------
     		/**  Determine Sizes of Emails
     		/** ------------------------------*/
     if ($this->total_size > $this->max_size) {
         if (!($line = $this->pop_command("LIST"))) {
             $this->message_array[] = 'unable_to_retrieve_emails';
             $line = $this->pop_command("QUIT");
             @fclose($this->fp);
             return FALSE;
         }
         do {
             $data = fgets($this->fp, 1024);
             $data = $this->iso_clean($data);
             if (empty($data) or trim($data) == '.') {
                 break;
             }
             $x = explode(' ', $data);
             if (count($x) == 1) {
                 break;
             }
             $this->email_sizes[$x['0']] = $x['1'];
         } while (strncmp($data, ".\r\n", 3) != 0);
     }
     /** ------------------------------
     		/**  Find Valid Emails
     		/** ------------------------------*/
     $valid_emails = array();
     $valid_froms = explode("|", $this->moblog_array['moblog_valid_from']);
     for ($i = 1; $i <= $total; $i++) {
         if (strncasecmp($this->pop_command("TOP {$i} 0"), '+OK', 3) != 0) {
             $line = $this->pop_command("QUIT");
             @fclose($this->fp);
             return FALSE;
         }
         $valid_subject = 'n';
         $valid_from = $this->moblog_array['moblog_valid_from'] != '' ? 'n' : 'y';
         $str = fgets($this->fp, 1024);
         while (strncmp($str, ".\r\n", 3) != 0) {
             $str = fgets($this->fp, 1024);
             $str = $this->iso_clean($str);
             if (empty($str)) {
                 break;
             }
             // ------------------------
             // Does email contain correct prefix? (if prefix is set)
             // Liberal interpretation of prefix location
             // ------------------------
             if ($this->moblog_array['moblog_subject_prefix'] == '') {
                 $valid_subject = 'y';
             } elseif (preg_match("/Subject:(.*)/", $str, $subject)) {
                 if (strpos(trim($subject['1']), $this->moblog_array['moblog_subject_prefix']) !== FALSE) {
                     $valid_subject = 'y';
                 }
             }
             if ($this->moblog_array['moblog_valid_from'] != '') {
                 if (preg_match("/From:\\s*(.*)\\s*\\<(.*)\\>/", $str, $from) or preg_match("/From:\\s*(.*)\\s*/", $str, $from)) {
                     $address = !isset($from['2']) ? $from['1'] : $from['2'];
                     if (in_array(trim($address), $valid_froms)) {
                         $valid_from = 'y';
                     }
                 }
             }
         }
         if ($valid_subject == 'y' && $valid_from == 'y') {
             $valid_emails[] = $i;
         }
     }
     unset($subject);
     unset($str);
     if (count($valid_emails) == 0) {
         $this->message_array[] = 'no_valid_emails';
         $line = $this->pop_command("QUIT");
         @fclose($this->fp);
         return;
     }
     /** ------------------------------
     		/**  Process Valid Emails
     		/** ------------------------------*/
     foreach ($valid_emails as $email_id) {
         // Reset Variables
         $this->post_data = array();
         $this->email_files = array();
         $this->body = '';
         $this->sender_email = '';
         $this->entry_data = array();
         $email_data = '';
         $this->attach_as_txt = FALSE;
         /** ------------------------------------------
         			/**  Do Not Exceed Max Size During a Moblog Check
         			/** ------------------------------------------*/
         if ($this->total_size > $this->max_size && isset($this->email_sizes[$email_id])) {
             if ($this->checked_size + $this->email_sizes[$email_id] > $this->max_size) {
                 continue;
             }
             $this->checked_size += $this->email_sizes[$email_id];
         }
         /** ---------------------------------------
         			/**  Failure does happen at times
         			/** ---------------------------------------*/
         if (strncasecmp($this->pop_command("RETR {$email_id}"), '+OK', 3) != 0) {
             continue;
         }
         // Under redundant, see redundant
         $this->post_data['subject'] = 'Moblog Entry';
         $this->post_data['ip'] = '127.0.0.1';
         $format_flow = 'n';
         /** ------------------------------
         			/**  Retrieve Email data
         			/** ------------------------------*/
         do {
             $data = fgets($this->fp, 1024);
             $data = $this->iso_clean($data);
             if (empty($data)) {
                 break;
             }
             if ($format_flow == 'n' && stristr($data, 'format=flowed')) {
                 $format_flow = 'y';
             }
             $email_data .= $data;
         } while (strncmp($data, ".\r\n", 3) != 0);
         //echo $email_data."<br /><br />\n\n";
         if (preg_match("/charset=(.*?)(\\s|" . $this->newline . ")/is", $email_data, $match)) {
             $this->charset = trim(str_replace(array("'", '"', ';'), '', $match['1']));
         }
         /** --------------------------
         			/**  Set Subject, Remove Moblog Prefix
         			/** --------------------------*/
         if (preg_match("/Subject:(.*)/", trim($email_data), $subject)) {
             if ($this->moblog_array['moblog_subject_prefix'] == '') {
                 $this->post_data['subject'] = trim($subject['1']) != '' ? trim($subject['1']) : 'Moblog Entry';
             } elseif (strpos(trim($subject['1']), $this->moblog_array['moblog_subject_prefix']) !== FALSE) {
                 $str_subject = str_replace($this->moblog_array['moblog_subject_prefix'], '', $subject['1']);
                 $this->post_data['subject'] = trim($str_subject) != '' ? trim($str_subject) : 'Moblog Entry';
             }
             // If the subject header was read with imap_utf8() in the iso_clean() method, then
             // we don't need to do anything further
             if (!function_exists('imap_utf8')) {
                 // If subject header was processed with MB or Iconv functions, then the internal encoding
                 // must be used to decode the subject, not the charset used by the email
                 if (function_exists('mb_convert_encoding')) {
                     $this->post_data['subject'] = mb_convert_encoding($this->post_data['subject'], strtoupper($this->EE->config->item('charset')), mb_internal_encoding());
                 } elseif (function_exists('iconv')) {
                     $this->post_data['subject'] = iconv(iconv_get_encoding('internal_encoding'), strtoupper($this->EE->config->item('charset')), $this->post_data['subject']);
                 } elseif (strtolower($this->EE->config->item('charset')) == 'utf-8' && strtolower($this->charset) == 'iso-8859-1') {
                     $this->post_data['subject'] = utf8_encode($this->post_data['subject']);
                 } elseif (strtolower($this->EE->config->item('charset')) == 'iso-8859-1' && strtolower($this->charset) == 'utf-8') {
                     $this->post_data['subject'] = utf8_decode($this->post_data['subject']);
                 }
             }
         }
         /** --------------------------
         			/**  IP Address of Sender
         			/** --------------------------*/
         if (preg_match("/Received:\\s*from\\s*(.*)\\[+(.*)\\]+/", $email_data, $subject)) {
             if (isset($subject['2']) && $this->EE->input->valid_ip(trim($subject['2']))) {
                 $this->post_data['ip'] = trim($subject['2']);
             }
         }
         /** --------------------------
         			/**  Check if AT&T email
         			/** --------------------------*/
         if (preg_match("/From:\\s*(.*)\\s*\\<(.*)\\>/", $email_data, $from) or preg_match("/From:\\s*(.*)\\s*/", $email_data, $from)) {
             $this->sender_email = !isset($from['2']) ? $from['1'] : $from['2'];
             if (strpos(trim($this->sender_email), 'mobile.att.net') !== FALSE) {
                 $this->attach_as_txt = TRUE;
             }
         }
         /** -------------------------------------
         			/**  Eliminate new line confusion
         			/** -------------------------------------*/
         $email_data = $this->remove_newlines($email_data, $this->newline);
         /** -------------------------------------
         			/**  Determine Boundary
         			/** -------------------------------------*/
         if (!$this->find_boundary($email_data)) {
             /** -------------------------
             				/**  No files, just text
             				/** -------------------------*/
             $duo = $this->newline . $this->newline;
             $this->body = $this->find_data($email_data, $duo, $duo . '.' . $this->newline);
             if ($this->body == '') {
                 $this->body = $this->find_data($email_data, $duo, $this->newline . '.' . $this->newline);
             }
             // Check for Quoted-Printable and Base64 encoding
             if (stristr($email_data, 'Content-Transfer-Encoding')) {
                 $encoding = $this->find_data($email_data, "Content-Transfer-Encoding: ", $this->newline);
                 if (!stristr(trim($encoding), "quoted-printable") and !stristr(trim($encoding), "base64")) {
                     // try it without the space after the colon...
                     $encoding = $this->find_data($email_data, "Content-Transfer-Encoding:", $this->newline);
                 }
                 if (stristr(trim($encoding), "quoted-printable")) {
                     $this->body = str_replace($this->newline, "\n", $this->body);
                     $this->body = quoted_printable_decode($this->body);
                     $this->body = substr($this->body, 0, 1) != '=' ? $this->body : substr($this->body, 1);
                     $this->body = substr($this->body, -1) != '=' ? $this->body : substr($this->body, 0, -1);
                     $this->body = $this->remove_newlines($this->body, $this->newline);
                 } elseif (stristr(trim($encoding), "base64")) {
                     $this->body = str_replace($this->newline, "\n", $this->body);
                     $this->body = base64_decode(trim($this->body));
                     $this->body = $this->remove_newlines($this->body, $this->newline);
                 }
             }
             if ($this->charset != $this->EE->config->item('charset')) {
                 if (function_exists('mb_convert_encoding')) {
                     $this->body = mb_convert_encoding($this->body, strtoupper($this->EE->config->item('charset')), strtoupper($this->charset));
                 } elseif (function_exists('iconv') and ($iconvstr = @iconv(strtoupper($this->charset), strtoupper($this->EE->config->item('charset')), $this->body)) !== FALSE) {
                     $this->body = $iconvstr;
                 } elseif (strtolower($this->EE->config->item('charset')) == 'utf-8' && strtolower($this->charset) == 'iso-8859-1') {
                     $this->body = utf8_encode($this->body);
                 } elseif (strtolower($this->EE->config->item('charset')) == 'iso-8859-1' && strtolower($this->charset) == 'utf-8') {
                     $this->body = utf8_decode($this->body);
                 }
             }
         } else {
             if (!$this->parse_email($email_data)) {
                 $this->message_array[] = 'unable_to_parse';
                 return FALSE;
             }
             // Email message as .txt file?
             // Make the email body the attachment's contents
             // Unset attachment from files array.
             if ($this->attach_as_txt === TRUE && trim($this->body) == '' && $this->attach_text != '') {
                 $this->body = $this->attach_text;
                 $this->attach_text = '';
                 foreach ($this->post_data['files'] as $key => $value) {
                     if ($value == $this->attach_name) {
                         unset($this->post_data['files'][$key]);
                     }
                 }
             }
         }
         /** ---------------------------
         			/**  Authorization Check
         			/** ---------------------------*/
         if (!$this->check_login()) {
             if ($this->moblog_array['moblog_auth_required'] == 'y') {
                 /** -----------------------------
                 				/**  Delete email?
                 				/** -----------------------------*/
                 if ($this->moblog_array['moblog_auth_delete'] == 'y' && strncasecmp($this->pop_command("DELE {$email_id}"), '+OK', 3) != 0) {
                     $this->message_array[] = 'undeletable_email';
                     //.$email_id;
                     return FALSE;
                 }
                 /** -----------------------------
                 				/**  Delete any uploaded images
                 				/** -----------------------------*/
                 if (count($this->email_files) > 0) {
                     foreach ($this->email_files as $axe) {
                         @unlink($this->upload_path . $axe);
                     }
                 }
                 // Error...
                 $this->message_array[] = 'authorization_failed';
                 $this->message_array[] = $this->post_data['subject'];
                 continue;
             }
         }
         /** -----------------------------
         			/**  Format Flow Fix - Oh Joy!
         			/** -----------------------------*/
         if ($format_flow == 'y') {
             $x = explode($this->newline, $this->body);
             $wrap_point = 10;
             if (count($x) > 1) {
                 $this->body = '';
                 // First, find wrap point
                 for ($p = 0; $p < count($x); $p++) {
                     $wrap_point = strlen($x[$p]) > $wrap_point ? strlen($x[$p]) : $wrap_point;
                 }
                 // Unwrap the Content
                 for ($p = 0; $p < count($x); $p++) {
                     $next = isset($x[$p + 1]) && count($y = explode(' ', $x[$p + 1])) ? $y['0'] : '';
                     $this->body .= strlen($x[$p]) < $wrap_point && strlen($x[$p] . $next) <= $wrap_point ? $x[$p] . $this->newline : $x[$p];
                 }
             }
         }
         $allow_overrides = !isset($this->moblog_array['moblog_allow_overrides']) ? 'y' : $this->moblog_array['moblog_allow_overrides'];
         /** -----------------------------
         			/**  Image Archive set in email?
         			/** -----------------------------*/
         if ($allow_overrides == 'y' && (preg_match("/\\{file_archive\\}(.*)\\{\\/file_archive\\}/s", $this->body, $matches) or preg_match("/\\<file_archive\\>(.*)\\<\\/file_archive\\>/s", $this->body, $matches))) {
             $matches['1'] = trim($matches['1']);
             if ($matches['1'] == 'y' or $matches['1'] == 'true' or $matches['1'] == '1') {
                 $this->moblog_array['moblog_file_archive'] = 'y';
             } else {
                 $this->moblog_array['moblog_file_archive'] = 'n';
             }
             $this->body = str_replace($matches['0'], '', $this->body);
         }
         /** -----------------------------
         			/**  Categories set in email?
         			/** -----------------------------*/
         if ($allow_overrides == 'n' or !preg_match("/\\{category\\}(.*)\\{\\/category\\}/s", $this->body, $cats) && !preg_match("/\\<category\\>(.*)\\<\\/category\\>/s", $this->body, $cats)) {
             $this->post_data['categories'] = trim($this->moblog_array['moblog_categories']);
         } else {
             $cats['1'] = str_replace(':', '|', $cats['1']);
             $cats['1'] = str_replace(',', '|', $cats['1']);
             $this->post_data['categories'] = trim($cats['1']);
             $this->body = str_replace($cats['0'], '', $this->body);
         }
         /** -----------------------------
         			/**  Status set in email
         			/** -----------------------------*/
         if ($allow_overrides == 'n' or !preg_match("/\\{status\\}(.*)\\{\\/status\\}/s", $this->body, $cats) && !preg_match("/\\<status\\>(.*)\\<\\/status\\>/s", $this->body, $cats)) {
             $this->post_data['status'] = trim($this->moblog_array['moblog_status']);
         } else {
             $this->post_data['status'] = trim($cats['1']);
             $this->body = str_replace($cats['0'], '', $this->body);
         }
         /** -----------------------------
         			/**  Sticky Set in Email
         			/** -----------------------------*/
         if ($allow_overrides == 'n' or !preg_match("/\\{sticky\\}(.*)\\{\\/sticky\\}/s", $this->body, $mayo) && !preg_match("/\\<sticky\\>(.*)\\<\\/sticky\\>/s", $this->body, $mayo)) {
             $this->post_data['sticky'] = !isset($this->moblog_array['moblog_sticky_entry']) ? $this->sticky : $this->moblog_array['moblog_sticky_entry'];
         } else {
             $this->post_data['sticky'] = (trim($mayo['1']) == 'yes' or trim($mayo['1']) == 'y') ? 'y' : 'n';
             $this->body = str_replace($mayo['0'], '', $this->body);
         }
         /** -----------------------------
         			/**  Default Field set in email?
         			/** -----------------------------*/
         if ($allow_overrides == 'y' && (preg_match("/\\{field\\}(.*)\\{\\/field\\}/s", $this->body, $matches) or preg_match("/\\<field\\>(.*)\\<\\/field\\>/s", $this->body, $matches))) {
             $matches[1] = trim($matches[1]);
             $this->EE->db->select('field_id');
             $this->EE->db->from('channel_fields, channels');
             $this->EE->db->where('channels.field_group', 'channel_fields.group_id');
             $this->EE->db->where('channels.channel_id', $this->moblog_array['moblog_channel_id']);
             $this->EE->db->where('channel_fields.group_id', $query->row('field_group'));
             $this->EE->db->where('(channel_fields.field_name = "' . $matches[1] . '" OR ' . $this->EE->db->dbprefix('channel_fields') . '.field_label = "' . $matches[1] . '")', NULL, FALSE);
             /* -------------------------------------
             			/*  Hidden Configuration Variable
             			/*  - moblog_allow_nontextareas => Removes the textarea only restriction
             			/*	for custom fields in the moblog module (y/n)
             			/* -------------------------------------*/
             if ($this->EE->config->item('moblog_allow_nontextareas') != 'y') {
                 $this->EE->db->where('channel_fields.field_type', 'textarea');
             }
             $results = $this->EE->db->get();
             if ($results->num_rows() > 0) {
                 $this->moblog_array['moblog_field_id'] = trim($results->row('field_id'));
             }
             $this->body = str_replace($matches['0'], '', $this->body);
         }
         /** -----------------------------
         			/**  Set Entry Title in Email
         			/** -----------------------------*/
         if (preg_match("/\\{entry_title\\}(.*)\\{\\/entry_title\\}/", $this->body, $matches) or preg_match("/\\<entry_title\\>(.*)\\<\\/entry_title\\>/", $this->body, $matches)) {
             if (strlen($matches['1']) > 1) {
                 $this->post_data['subject'] = trim(str_replace($this->newline, "\n", $matches['1']));
             }
             $this->body = str_replace($matches['0'], '', $this->body);
         }
         /** ----------------------------
         			/**  Post Entry
         			/** ----------------------------*/
         if ($this->moblog_array['moblog_channel_id'] != '0' && $this->moblog_array['moblog_file_archive'] == 'n') {
             $this->template = $this->moblog_array['moblog_template'];
             $tag = 'field';
             if ($this->moblog_array['moblog_field_id'] != 'none' or preg_match("/" . LD . 'field:' . "(.*?)" . RD . "(.*?)" . LD . '\\/' . 'field:' . "(.*?)" . RD . "/s", $this->template, $matches) or preg_match("/[\\<\\{]field\\:(.*?)[\\}\\>](.*?)[\\<\\{]\\/field\\:(.*?)[\\}\\>]/", $this->body, $matches)) {
                 $this->post_entry();
             } else {
                 $this->emails_done++;
                 continue;
             }
         }
         /** -------------------------
         			/**  Delete Email
         			/** -------------------------*/
         if (strncasecmp($this->pop_command("DELE {$email_id}"), '+OK', 3) != 0) {
             $this->message_array[] = 'undeletable_email';
             //.$email_id;
             return FALSE;
         }
         $this->emails_done++;
     }
     /** -----------------------------
     		/**  Close Email Connection
     		/** -----------------------------*/
     $line = $this->pop_command("QUIT");
     @fclose($this->fp);
     /** ---------------------------------
     		/**  Clear caches if needed
     		/** ---------------------------------*/
     if ($this->emails_done > 0) {
         if ($this->EE->config->item('new_posts_clear_caches') == 'y') {
             $this->EE->functions->clear_caching('all');
         } else {
             $this->EE->functions->clear_caching('sql_cache');
         }
     }
     return TRUE;
 }