/** * check to see that the format is valid and that the mx record exists * @param string $p_email * @return bool */ function email_is_valid($p_email) { # if we don't validate then just accept if (OFF == config_get('validate_email')) { return true; } if (ON == config_get('use_ldap_email')) { return true; } if (is_blank($p_email) && ON == config_get('allow_blank_email')) { return true; } # Use a regular expression to check to see if the email is in valid format # x-xx.xxx@yyy.zzz.abc etc. if (preg_match(email_regex_simple(), $p_email, $t_check)) { $t_local = $t_check[1]; $t_domain = $t_check[2]; # see if we're limited to one domain $t_limit_email_domain = config_get('limit_email_domain'); if ($t_limit_email_domain !== OFF) { if (0 != strcasecmp($t_limit_email_domain, $t_domain)) { return false; } } if (ON == config_get('check_mx_record')) { $temp = ''; # Check for valid mx records if (getmxrr($t_domain, $temp)) { return true; } else { $host = $t_domain . '.'; # for no mx record... try dns check if (checkdnsrr($host, 'ANY')) { return true; } } } else { # Email format was valid but did't check for valid mx records return true; } } # Everything failed. The email is invalid return false; }
/** * Detect URLs and email addresses in the string and replace them with href anchors * @param string $p_string String to be processed. * @return string */ function string_insert_hrefs($p_string) { static $s_url_regex = null; static $s_email_regex = null; static $s_anchor_regex = '/(<a[^>]*>.*?<\\/a>)/is'; if (!config_get('html_make_links')) { return $p_string; } $t_change_quotes = false; if (ini_get_bool('magic_quotes_sybase') && function_exists('ini_set')) { $t_change_quotes = true; ini_set('magic_quotes_sybase', false); } # Initialize static variables if (is_null($s_url_regex)) { # URL regex $t_url_protocol = '(?:[[:alpha:]][-+.[:alnum:]]*):\\/\\/'; # %2A notation in url's $t_url_hex = '%[[:digit:]A-Fa-f]{2}'; # valid set of characters that may occur in url scheme. Note: - should be first (A-F != -AF). $t_url_valid_chars = '-_.,!~*\';\\/?%^\\\\:@&={\\|}+$#[:alnum:]\\pL'; $t_url_chars = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\(\\)\\[\\]])"; $t_url_chars2 = "(?:{$t_url_hex}|[{$t_url_valid_chars}])"; $t_url_chars_in_brackets = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\(\\)])"; $t_url_chars_in_parens = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\[\\]])"; $t_url_part1 = "{$t_url_chars}"; $t_url_part2 = "(?:\\({$t_url_chars_in_parens}*\\)|\\[{$t_url_chars_in_brackets}*\\]|{$t_url_chars2})"; $s_url_regex = "/({$t_url_protocol}({$t_url_part1}*?{$t_url_part2}+))/su"; # e-mail regex $s_email_regex = substr_replace(email_regex_simple(), '(?:mailto:)?', 1, 0); } # Find any URL in a string and replace it by a clickable link $p_string = preg_replace_callback($s_url_regex, function ($p_match) { $t_url_href = 'href="' . rtrim($p_match[1], '.') . '"'; return "<a {$t_url_href}>{$p_match[1]}</a> [<a {$t_url_href} target=\"_blank\">^</a>]"; }, $p_string); if ($t_change_quotes) { ini_set('magic_quotes_sybase', true); } # Find any email addresses in the string and replace them with a clickable # mailto: link, making sure that we skip processing of any existing anchor # tags, to avoid parts of URLs such as https://user@example.com/ or # http://user:password@example.com/ to be not treated as an email. $t_pieces = preg_split($s_anchor_regex, $p_string, null, PREG_SPLIT_DELIM_CAPTURE); $p_string = ''; foreach ($t_pieces as $t_piece) { if (preg_match($s_anchor_regex, $t_piece)) { $p_string .= $t_piece; } else { $p_string .= preg_replace($s_email_regex, '<a href="mailto:\\0">\\0</a>', $t_piece); } } return $p_string; }
/** * Detect URLs and email addresses in the string and replace them with href anchors * @param string $p_string * @return string */ function string_insert_hrefs($p_string) { static $s_url_regex = null; static $s_email_regex = null; if (!config_get('html_make_links')) { return $p_string; } $t_change_quotes = false; if (ini_get_bool('magic_quotes_sybase') && function_exists('ini_set')) { $t_change_quotes = true; ini_set('magic_quotes_sybase', false); } # Find any URL in a string and replace it by a clickable link $t_url_protocol = '([[:alpha:]][-+.[:alnum:]]*):\\/\\/'; if (is_null($s_url_regex)) { # %2A notation in url's $t_url_hex = '%[[:digit:]A-Fa-f]{2}'; # valid set of characters that may occur in url scheme. Note: - should be first (A-F != -AF). $t_url_valid_chars = '-_.,!~*\';\\/?%^\\\\:@&={\\|}+$#[:alnum:]\\pL'; $t_url_chars = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\(\\)\\[\\]])"; $t_url_chars2 = "(?:{$t_url_hex}|[{$t_url_valid_chars}])"; $t_url_chars_in_brackets = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\(\\)])"; $t_url_chars_in_parens = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\[\\]])"; $t_url_part1 = "{$t_url_chars}"; $t_url_part2 = "(?:\\({$t_url_chars_in_parens}*\\)|\\[{$t_url_chars_in_brackets}*\\]|{$t_url_chars2})"; $s_url_regex = "/({$t_url_protocol}({$t_url_part1}*?{$t_url_part2}+))/sue"; } $p_string = preg_replace($s_url_regex, "'<a href=\"'.rtrim('\\1','.').'\">\\1</a> [<a href=\"'.rtrim('\\1','.').'\" target=\"_blank\">^</a>]'", $p_string); if ($t_change_quotes) { ini_set('magic_quotes_sybase', true); } # Find any email addresses in the string and replace them with a clickable # mailto: link, making sure that URLs such as http://user@example.com/ or # http://user:password@example.com/ are not processed as an email if (is_null($s_email_regex)) { $s_email_regex = email_regex_simple(); $s_email_regex = substr($s_email_regex, 0, 1) . '(' . $t_url_protocol . '.*?)?' . substr($s_email_regex, 1); } $p_string = preg_replace_callback($s_email_regex, create_function('$p_match', 'if( 0 === preg_match( "/' . $t_url_protocol . '/", $p_match[0] ) ) { return \'<a href="mailto:\' . $p_match[0] . \'">\' . $p_match[0] . \'</a>\'; } else { return $p_match[0]; }'), $p_string); return $p_string; }
private function prepare_realname($p_user_info, $p_username) { switch ($this->_mail_preferred_realname) { case 'email_address': $t_realname = $p_user_info['email']; break; case 'email_no_domain': if (preg_match(email_regex_simple(), $p_user_info['email'], $t_check)) { $t_local = $t_check[1]; $t_domain = $t_check[2]; $t_realname = $t_local; } break; case 'from_ldap': $t_realname = ldap_realname_from_username($p_username); break; case 'full_from': $t_realname = str_replace(array('<', '>'), array('(', ')'), $p_user_info['From']); break; case 'name': default: $t_realname = $p_user_info['name']; } $t_realname = string_normalize($t_realname); if (utf8_strlen($t_realname) > DB_FIELD_SIZE_REALNAME) { $t_realname = utf8_substr($t_realname, 0, DB_FIELD_SIZE_REALNAME); } if (user_is_realname_valid($t_realname) && user_is_realname_unique($p_username, $t_realname)) { return $t_realname; } return FALSE; }
/** * Detect URLs and email addresses in the string and replace them with href anchors * @param string $p_string * @return string */ function string_insert_hrefs($p_string) { static $s_url_regex = null; if (!config_get('html_make_links')) { return $p_string; } $t_change_quotes = false; if (ini_get_bool('magic_quotes_sybase') && function_exists('ini_set')) { $t_change_quotes = true; ini_set('magic_quotes_sybase', false); } # Find any URL in a string and replace it by a clickable link if (is_null($s_url_regex)) { # %2A notation in url's $t_url_hex = '%[[:digit:]A-Fa-f]{2}'; # valid set of characters that may occur in url scheme. Note: - should be first (A-F != -AF). $t_url_valid_chars = '-_.,!~*\';\\/?%^\\\\:@&={\\|}+$#[:alnum:]\\pL'; $t_url_chars = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\(\\)\\[\\]])"; $t_url_chars2 = "(?:{$t_url_hex}|[{$t_url_valid_chars}])"; $t_url_chars_in_brackets = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\(\\)])"; $t_url_chars_in_parens = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\[\\]])"; $t_url_part1 = "{$t_url_chars}"; $t_url_part2 = "(?:\\({$t_url_chars_in_parens}*\\)|\\[{$t_url_chars_in_brackets}*\\]|{$t_url_chars2})"; $s_url_regex = "/(([[:alpha:]][-+.[:alnum:]]*):\\/\\/({$t_url_part1}*?{$t_url_part2}+))/sue"; } $p_string = preg_replace($s_url_regex, "'<a href=\"'.rtrim('\\1','.').'\">\\1</a>'", $p_string); if ($t_change_quotes) { ini_set('magic_quotes_sybase', true); } $p_string = preg_replace(email_regex_simple(), '<a href="mailto:\\0">\\0</a>', $p_string); return $p_string; }
/** * Search email addresses and URLs for a few common protocols in the given * string, and replace occurences with href anchors. * @param string $p_string String to be processed. * @return string */ function string_insert_hrefs($p_string) { static $s_url_regex = null; static $s_email_regex = null; static $s_anchor_regex = '/(<a[^>]*>.*?<\\/a>)/is'; if (!config_get('html_make_links')) { return $p_string; } # Initialize static variables if (is_null($s_url_regex)) { # URL protocol. The regex accepts a small subset from the list of valid # IANA permanent and provisional schemes defined in # http://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml $t_url_protocol = '(?:https?|s?ftp|file|irc[6s]?|ssh|telnet|nntp|git|svn(?:\\+ssh)?|cvs):\\/\\/'; # %2A notation in url's $t_url_hex = '%[[:digit:]A-Fa-f]{2}'; # valid set of characters that may occur in url scheme. Note: - should be first (A-F != -AF). $t_url_valid_chars = '-_.,!~*\';\\/?%^\\\\:@&={\\|}+$#[:alnum:]\\pL'; $t_url_chars = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\(\\)\\[\\]])"; $t_url_chars2 = "(?:{$t_url_hex}|[{$t_url_valid_chars}])"; $t_url_chars_in_brackets = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\(\\)])"; $t_url_chars_in_parens = "(?:{$t_url_hex}|[{$t_url_valid_chars}\\[\\]])"; $t_url_part1 = $t_url_chars; $t_url_part2 = "(?:\\({$t_url_chars_in_parens}*\\)|\\[{$t_url_chars_in_brackets}*\\]|{$t_url_chars2})"; $s_url_regex = "/({$t_url_protocol}({$t_url_part1}*?{$t_url_part2}+))/su"; # e-mail regex $s_email_regex = substr_replace(email_regex_simple(), '(?:mailto:)?', 1, 0); } # Find any URL in a string and replace it by a clickable link $p_string = preg_replace_callback($s_url_regex, function ($p_match) { $t_url_href = 'href="' . rtrim($p_match[1], '.') . '"'; return "<a {$t_url_href}>{$p_match[1]}</a> [<a {$t_url_href} target=\"_blank\">^</a>]"; }, $p_string); # Find any email addresses in the string and replace them with a clickable # mailto: link, making sure that we skip processing of any existing anchor # tags, to avoid parts of URLs such as https://user@example.com/ or # http://user:password@example.com/ to be not treated as an email. $t_pieces = preg_split($s_anchor_regex, $p_string, null, PREG_SPLIT_DELIM_CAPTURE); $p_string = ''; foreach ($t_pieces as $t_piece) { if (preg_match($s_anchor_regex, $t_piece)) { $p_string .= $t_piece; } else { $p_string .= preg_replace($s_email_regex, '<a href="mailto:\\0">\\0</a>', $t_piece); } } return $p_string; }
function string_insert_hrefs($p_string) { if (!config_get('html_make_links')) { return $p_string; } $t_change_quotes = false; if (ini_get_bool('magic_quotes_sybase')) { $t_change_quotes = true; ini_set('magic_quotes_sybase', false); } # Find any URL in a string and replace it by a clickable link $p_string = preg_replace('/(([[:alpha:]][-+.[:alnum:]]*):\\/\\/(%[[:digit:]A-Fa-f]{2}|[-_.!~*\';\\/?%^\\\\:@&={\\|}+$#\\(\\),\\[\\][:alnum:]])+)/se', "'<a href=\"'.rtrim('\\1','.').'\">\\1</a> [<a href=\"'.rtrim('\\1','.').'\" target=\"_blank\">^</a>]'", $p_string); if ($t_change_quotes) { ini_set('magic_quotes_sybase', true); } $p_string = preg_replace('/\\b' . email_regex_simple() . '\\b/i', '<a href="mailto:\\0">\\0</a>', $p_string); return $p_string; }