/*
Public: Get replies with validated email addresses

Returns array
173918
public function getValidatedReplies()
    {
        $comments = $this->getValidatedReplyManager();

        $comments = $comments->values();

        $comments = is_null($comments) ? array() : $comments;

        return $comments;
    }
361029
private function getAddressFields($_params = array())
    {
        $params = array_merge(
            array(
                'includeHeader' => true,
            ),
            (array) $_params
        );

        $fields = array(
            TextField::create('Address', _t('Addressable.ADDRESS', 'Address')),
            TextField::create('Suburb', _t('Addressable.SUBURB', 'Suburb'))
        );

        if ($params['includeHeader']) {
            array_unshift(
                $fields,
                HeaderField::create('AddressHeader', _t('Addressable.ADDRESSHEADER', 'Address'))
            );
        }


        // Get state field
        $label = _t('Addressable.STATE', 'State');
        $allowedStates = $this->owner->getAllowedStates();
        if (count($allowedStates) >= 1) {
            // If allowed states are restricted, only allow those
            $fields[] = DropdownField::create('State', $label, $allowedStates);
        } elseif (!$allowedStates) {
            // If no allowed states defined, allow the user to type anything
            $fields[] = TextField::create('State', $label);
        }

        // Get postcode field
        $postcode = RegexTextField::create('Postcode', _t('Addressable.POSTCODE', 'Postcode'));
        $postcode->setRegex($this->getPostcodeRegex());
        $fields[] = $postcode;

        // Get country field
        $fields[] = DropdownField::create(
            'Country',
            _t('Addressable.COUNTRY', 'Country'),
            $this->owner->getAllowedCountries()
        );

        $this->owner->extend("updateAddressFields", $fields);

        return $fields;
    }
799643
function validateEMailHTTPInput( $email, $contentObjectAttribute )
    {
        if ( !eZMail::validate( $email ) )
        {
            $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
                                                                 'The email address is not valid.' ) );
            return eZInputValidator::STATE_INVALID;
        }
        return eZInputValidator::STATE_ACCEPTED;
    }
629225
protected function validateUserEmailInstall()
    {
        if ($this->isExcluded('user.email')) {
            return null;
        }

        $options = $this->options;
        $this->options['parents'] = 'user';
        $result = $this->validateEmail();
        $this->options = $options; // Restore original

        return $result;
    }
777213
static function fetchByEmail( $email, $sorts = null, $offset = null, $length = null, $status = false )
    {
        $cond = array();
        $cond['email'] = $email;
        if ( $status !== false )
        {
            $cond['status'] = $status;
        }
        $limit = null;
        if ( !is_null( $offset ) )
        {
           $limit = array();
           $limit = array( 'offset' => $offset, 'length' => $length );
        }
        $return = eZPersistentObject::fetchObjectList( self::definition(), null, $cond, $sorts, $limit );
        return $return;
    }
406159
private function parse_headers($headers)
    {
        $result = array();

        if ($headers->subject)
            $result[] = array('Subject', rcube_mime::decode_header($headers->subject));

        // @TODO: List-Id, others?
        foreach (array('From', 'To') as $h) {
            $hl = strtolower($h);
            if ($headers->$hl) {
                $list = rcube_mime::decode_address_list($headers->$hl);
                foreach ($list as $item) {
                    if ($item['mailto']) {
                        $result[] = array($h, $item['mailto']);
                    }
                }
            }
        }

        return $result;
    }
255556
private Map<String, String> getEmails(Map<String, String> emails) {

		if (emails == null || emails.size() == 0) {
			return null;
		}

		Map<String, String> out = new HashMap<>();

		for (String email : emails.keySet()) {
			if (excluded(email)) {
				continue;
			}

			out.put(email, emails.get(email));
		}

		return out;
	}
155268
public function getEmails($start = 0, $range = 10)
    {
        Argument::i()
            ->test(1, 'int')
            ->test(2, 'int');

        $total = $this->getEmailTotal();

        if ($total == 0) {
            return array();
        }

        if (!is_array($start)) {
            $range = $range > 0 ? $range : 1;
            $start = $start >= 0 ? $start : 0;
            $max = $total - $start;

            if ($max < 1) {
                $max = $total;
            }

            $min = $max - $range + 1;

            if ($min < 1) {
                $min = 1;
            }

            $set = $min . ':' . $max;

            if ($min == $max) {
                $set = $min;
            }
        }

        $emails = array();
        for ($i = $min; $i <= $max; $i++) {
            $emails[] = $this->getEmailFormat($this->call('RETR '.$i, true));
        }

        return $emails;
    }
295655
public function parse()
    {
        $parts  = explode('@', $this->getEmail());
        $domain = array_pop($parts);
        $user   = implode('@', $parts);

        return array($user, $domain);
    }
678650
public static function check_email($email, $dns_check=true)
    {
        // Check for invalid characters
        if (preg_match('/[\x00-\x1F\x7F-\xFF]/', $email)) {
            return false;
        }

        // Check for length limit specified by RFC 5321 (#1486453)
        if (strlen($email) > 254) {
            return false;
        }

        $email_array = explode('@', $email);

        // Check that there's one @ symbol
        if (count($email_array) < 2) {
            return false;
        }

        $domain_part = array_pop($email_array);
        $local_part  = implode('@', $email_array);

        // from PEAR::Validate
        $regexp = '&^(?:
            ("\s*(?:[^"\f\n\r\t\v\b\s]+\s*)+")|                             #1 quoted name
            ([-\w!\#\$%\&\'*+~/^`|{}=]+(?:\.[-\w!\#\$%\&\'*+~/^`|{}=]+)*))  #2 OR dot-atom (RFC5322)
            $&xi';

        if (!preg_match($regexp, $local_part)) {
            return false;
        }

        // Validate domain part
        if (preg_match('/^\[((IPv6:[0-9a-f:.]+)|([0-9.]+))\]$/i', $domain_part, $matches)) {
            return self::check_ip(preg_replace('/^IPv6:/i', '', $matches[1])); // valid IPv4 or IPv6 address
        }
        else {
            // If not an IP address
            $domain_array = explode('.', $domain_part);
            // Not enough parts to be a valid domain
            if (count($domain_array) < 2) {
                return false;
            }

            foreach ($domain_array as $part) {
                if (!preg_match('/^((xn--)?([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]))$/', $part)) {
                    return false;
                }
            }

            // last domain part
            $last_part = array_pop($domain_array);
            if (strpos($last_part, 'xn--') !== 0 && preg_match('/[^a-zA-Z]/', $last_part)) {
                return false;
            }

            $rcube = rcube::get_instance();

            if (!$dns_check || !function_exists('checkdnsrr') || !$rcube->config->get('email_dns_check')) {
                return true;
            }

            // Check DNS record(s)
            // Note: We can't use ANY (#6581)
            foreach (array('A', 'MX', 'CNAME', 'AAAA') as $type) {
                if (checkdnsrr($domain_part, $type)) {
                    return true;
                }
            }
        }

        return false;
    }
596399
protected function _parseMailbox()
    {
        $this->_comments = array();
        $start = $this->_ptr;

        if (!($ob = $this->_parseNameAddr())) {
            $this->_comments = array();
            $this->_ptr = $start;
            $ob = $this->_parseAddrSpec();
        }

        if ($ob) {
            $ob->comment = $this->_comments;
        }

        return $ob;
    }
483222
def validate(address, mailbox_verification = false)
      params = {:address => address}
      params[:mailbox_verification] = true if mailbox_verification

      res = @client.get "address/validate", params
      return res.to_h!
    end
698339
public function getMailboxes()
    {
        if (!$this->socket) {
            $this->connect();
        }

        $response = $this->call('LIST', $this->escape('', '*'));

        $mailboxes = array();
        foreach ($response as $line) {
            if (strpos($line, 'Noselect') !== false || strpos($line, 'LIST') == false) {
                continue;
            }

            $line = explode('"', $line);

            if (strpos(trim($line[0]), '*') !== 0) {
                continue;
            }

            $mailboxes[] = $line[count($line)-2];
        }

        return $mailboxes;
    }
1176276
public static function addressesGet($addresses)
    {
        // $this->debug->groupCollapsed(__CLASS__.'->'.__FUNCTION__);
        $return = array();
        if (!is_array($addresses)) {
            $addresses = self::addressParse($addresses);
        }
        foreach ($addresses as $k => $v) {
            if (is_array($v)) {
                // parsed address
                if (!empty($v['name'])) {
                    $return[ $v['email'] ] = $v['name'];
                } else {
                    $return[] = $v['email'];
                }
            } elseif (is_int($k)) {
                $v = self::addressParse($v);
                $v = array_shift($v);
                // $this->debug->log($k, $v);
                if (!empty($v['name'])) {
                    $return[ $v['email'] ] = $v['name'];
                } else {
                    $return[] = $v['email'];
                }
            } else {
                // email => name
                $return[$k] = $v;
            }
        }
        // $this->debug->groupEnd();
        return $return;
    }
848089
public function getValidatedComments()
    {
        $app = App::getInstance();

        $comments = (new CommentManager())
            ->filter("article = %i", array($this->getId()))
            ->filter("active = 1")
            ->filter("spam = 0 ");

        $validation = BaseManager::build('FelixOnline\Core\EmailValidation', 'email_validation')
            ->filter("confirmed = 1");

        $comments->join($validation, null, 'email', 'email');

        $comments = $comments->values();

        $comments = is_null($comments) ? array() : $comments;

        return $comments;
    }
762094
public function get_errors_array($convert_to_string = false) {
        if (empty($this->errors)) {
            return ($convert_to_string) ? null : array();
        }

        $resp = array();

        foreach ($this->errors as $e) {
            $field = ucwords(str_replace(array('_', '-'), chr(32), $e['field']));
            $param = $e['param'];

            // Let's fetch explicit field names if they exist
            if (array_key_exists($e['field'], self::$fields)) {
                $field = self::$fields[$e['field']];
            }

            switch ($e['rule']) {
                case 'mismatch' :
                    $resp[$field] = "There is no validation rule for $field";
                    break;
                case 'validate_required':
                    $resp[$field] = "The $field field is required";
                    break;
                case 'validate_valid_email':
                    $resp[$field] = "The $field field is required to be a valid email address";
                    break;
                case 'validate_max_len':
                    $resp[$field] = "The $field field needs to be $param or shorter in length";
                    break;
                case 'validate_min_len':
                    $resp[$field] = "The $field field needs to be $param or longer in length";
                    break;
                case 'validate_exact_len':
                    $resp[$field] = "The $field field needs to be exactly $param characters in length";
                    break;
                case 'validate_alpha':
                    $resp[$field] = "The $field field may only contain alpha characters(a-z)";
                    break;
                case 'validate_alpha_numeric':
                    $resp[$field] = "The $field field may only contain alpha-numeric characters";
                    break;
                case 'validate_alpha_dash':
                    $resp[$field] = "The $field field may only contain alpha characters &amp; dashes";
                    break;
                case 'validate_numeric':
                    $resp[$field] = "The $field field may only contain numeric characters";
                    break;
                case 'validate_integer':
                    $resp[$field] = "The $field field may only contain a numeric value";
                    break;
                case 'validate_boolean':
                    $resp[$field] = "The $field field may only contain a true or false value";
                    break;
                case 'validate_float':
                    $resp[$field] = "The $field field may only contain a float value";
                    break;
                case 'validate_valid_url':
                    $resp[$field] = "The $field field is required to be a valid URL";
                    break;
                case 'validate_url_exists':
                    $resp[$field] = "The $field URL does not exist";
                    break;
                case 'validate_valid_ip':
                    $resp[$field] = "The $field field needs to contain a valid IP address";
                    break;
                case 'validate_valid_cc':
                    $resp[$field] = "The $field field needs to contain a valid credit card number";
                    break;
                case 'validate_valid_name':
                    $resp[$field] = "The $field field needs to contain a valid human name";
                    break;
                case 'validate_contains':
                    $resp[$field] = "The $field field needs to contain one of these values: " . implode(', ', $param);
                    break;
                case 'validate_contains_list':
                    $resp[$field] = "The $field field needs to contain a value from its drop down list";
                    break;
                case 'validate_doesnt_contain_list':
                    $resp[$field] = "The $field field contains a value that is not accepted";
                    break;
                case 'validate_street_address':
                    $resp[$field] = "The $field field needs to be a valid street address";
                    break;
                case 'validate_date':
                    $resp[$field] = "The $field field needs to be a valid date";
                    break;
                case 'validate_min_numeric':
                    $resp[$field] = "The $field field needs to be a numeric value, equal to, or higher than $param";
                    break;
                case 'validate_max_numeric':
                    $resp[$field] = "The $field field needs to be a numeric value, equal to, or lower than $param";
                    break;
                case 'validate_min_age':
                    $resp[$field] = "The $field field needs to have an age greater than or equal to $param";
                    break;
                case 'validate_unique':
                    $resp[$field] = "The $field field needs to have unique value";
                    break;
                default:
                    $resp[$field] = "The $field field is invalid";
            }
        }

        return $resp;
    }
468870
public function mapInboundPostVarsToEmail_messagesFields() {

        $data = [];

        $data['user_id']            = $this->getUserIdByMappedEmailAddress();

        $data['from_email_address'] = trim($this->request->input('sender'));
        $data['from_name']          = $this->genericWashText($this->request ->input('from'));
        $data['to_email_address']   = $this->setToEmailAddressField();
        $data['to_name']            = $this->setToField();
        $data['subject']            = $this->genericWashText($this->request->input('subject'));
        $data['body']               = $this->setBodyField();
        $data['message_header']     = json_decode($this->request->input('message-headers'));
        $data['recipient']          = $this->request->input('recipient');

        return $data;
    }