summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/mail.php13
-rw-r--r--inc/parser/handler.php4
-rw-r--r--inc/parser/parser.php3
3 files changed, 15 insertions, 5 deletions
diff --git a/inc/mail.php b/inc/mail.php
index a596c38f7..02434cf3c 100644
--- a/inc/mail.php
+++ b/inc/mail.php
@@ -144,14 +144,23 @@ function mail_encode_address($string,$header='',$names=true){
* Uses a regular expresion to check if a given mail address is valid
*
* May not be completly RFC conform!
+ * @link http://www.faqs.org/rfcs/rfc2822.html (paras 3.4.1 & 3.2.4)
*
- * @link http://www.webmasterworld.com/forum88/135.htm
+ * @author Chris Smith <chris@jalakai.co.uk>
*
* @param string $email the address to check
* @return bool true if address is valid
*/
+
+// patterns for use in email detection and validation
+// NOTE: there is an unquoted '/' in RFC2822_ATEXT, it must remain unquoted to be used in the parser
+// the pattern uses non-capturing groups as captured groups aren't allowed in the parser
+// select pattern delimiters with care!
+if (!defined('RFC2822_ATEXT')) define('RFC2822_ATEXT',"0-9A-Za-z!#$%&'*+/=?^_`{|}~-");
+if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '['.RFC2822_ATEXT.']+(?:\.['.RFC2822_ATEXT.']+)*@(?:[0-9A-Za-z][0-9A-Za-z-]*\.)+[A-Za-z]{2,4}');
+
function mail_isvalid($email){
- return eregi("^[0-9a-z]([+-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$", $email);
+ return preg_match('<^'.PREG_PATTERN_VALID_EMAIL.'$>', $email);
}
/**
diff --git a/inc/parser/handler.php b/inc/parser/handler.php
index 731d2ddea..01abf5876 100644
--- a/inc/parser/handler.php
+++ b/inc/parser/handler.php
@@ -457,8 +457,8 @@ class Doku_Handler {
array($link[0],$link[1]),
$pos
);
- }elseif ( preg_match('#([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i',$link[0]) ) {
- // E-Mail
+ }elseif ( preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link[0]) ) {
+ // E-Mail (pattern above is defined in inc/mail.php)
$this->_addCall(
'emaillink',
array($link[0],$link[1]),
diff --git a/inc/parser/parser.php b/inc/parser/parser.php
index 319dfdeed..3be908103 100644
--- a/inc/parser/parser.php
+++ b/inc/parser/parser.php
@@ -914,7 +914,8 @@ class Doku_Parser_Mode_windowssharelink extends Doku_Parser_Mode {
class Doku_Parser_Mode_emaillink extends Doku_Parser_Mode {
function connectTo($mode) {
- $this->Lexer->addSpecialPattern("<[\w0-9\-_.]+?@[\w\-]+\.[\w\-\.]+\.*[\w]+>",$mode,'emaillink');
+ // pattern below is defined in inc/mail.php
+ $this->Lexer->addSpecialPattern('<'.PREG_PATTERN_VALID_EMAIL.'>',$mode,'emaillink');
}
function getSort() {