Index: trunk/extensions/Notificator/Notificator.body.php |
— | — | @@ -22,8 +22,7 @@ |
23 | 23 | return array( $output, 'noparse' => true, 'isHTML' => true ); |
24 | 24 | } |
25 | 25 | |
26 | | - // Check whether the parameter is a valid e-mail address or not |
27 | | - if ( $receiver && Notificator::checkEmailAddress( $receiver ) ) { |
| 26 | + if ( Notificator::receiverIsValid( $receiver ) ) { |
28 | 27 | // Valid e-mail address available, so just show a button |
29 | 28 | $output = '<form action="' . $wgScript . |
30 | 29 | '/Special:Notificator" method="post" enctype="multipart/form-data"> |
— | — | @@ -65,55 +64,22 @@ |
66 | 65 | return $ret; |
67 | 66 | } |
68 | 67 | |
69 | | -public static function checkEmailAddress( $string ) { |
70 | | -// from http://www.linuxjournal.com/article/9585 |
71 | | - $isValid = true; |
72 | | - $atIndex = strrpos( $string, "@" ); |
73 | | - if ( is_bool( $atIndex ) && !$atIndex ) { |
74 | | - $isValid = false; |
| 68 | +public static function receiverIsValid( $receiver ) { |
| 69 | + // Returns true if the parameter is a valid e-mail address, false if not |
| 70 | + $receiverIsValid = false; |
| 71 | + |
| 72 | + // User::isValidEmailAddr() has been moved to Sanitizer::validateEmail as of |
| 73 | + // MediaWiki version 1.18 (I think). |
| 74 | + if ( method_exists( Sanitizer, validateEmail ) ) { |
| 75 | + if ( Sanitizer::validateEmail( $receiver ) ) { |
| 76 | + $receiverIsValid = true; |
| 77 | + } |
75 | 78 | } else { |
76 | | - $domain = substr( $string, $atIndex + 1 ); |
77 | | - $local = substr( $string, 0, $atIndex ); |
78 | | - $localLen = strlen( $local ); |
79 | | - $domainLen = strlen( $domain ); |
80 | | - if ( $localLen < 1 || $localLen > 64 ) { |
81 | | - // local part length exceeded |
82 | | - $isValid = false; |
| 79 | + if ( User::isValidEmailAddr( $receiver ) ) { |
| 80 | + $receiverIsValid = true; |
83 | 81 | } |
84 | | - elseif ( $domainLen < 1 || $domainLen > 255 ) { |
85 | | - // domain part length exceeded |
86 | | - $isValid = false; |
87 | | - } |
88 | | - elseif ( $local[0] == '.' || $local[$localLen -1] == '.' ) { |
89 | | - // local part starts or ends with '.' |
90 | | - $isValid = false; |
91 | | - } |
92 | | - elseif ( preg_match( '/\\.\\./', $local ) ) { |
93 | | - // local part has two consecutive dots |
94 | | - $isValid = false; |
95 | | - } |
96 | | - elseif ( !preg_match( '/^[A-Za-z0-9\\-\\.]+$/', $domain ) ) { |
97 | | - // character not valid in domain part |
98 | | - $isValid = false; |
99 | | - } |
100 | | - elseif ( preg_match( '/\\.\\./', $domain ) ) { |
101 | | - // domain part has two consecutive dots |
102 | | - $isValid = false; |
103 | | - } |
104 | | - elseif ( !preg_match( '/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', |
105 | | - str_replace( "\\\\", "", $local ) ) ) { |
106 | | - // character not valid in local part unless |
107 | | - // local part is quoted |
108 | | - if ( !preg_match( '/^"(\\\\"|[^"])+"$/', str_replace( "\\\\", "", $local ) ) ) { |
109 | | - $isValid = false; |
110 | | - } |
111 | | - } |
112 | | - if ( $isValid && !( checkdnsrr( $domain, "MX" ) || checkdnsrr( $domain, "A" ) ) ) { |
113 | | - // domain not found in DNS |
114 | | - $isValid = false; |
115 | | - } |
116 | 82 | } |
117 | | - return $isValid; |
| 83 | + return $receiverIsValid; |
118 | 84 | } |
119 | 85 | |
120 | 86 | public static function getLastNotifiedRevId( $pageId, $revId, $receiver ) { |
Index: trunk/extensions/Notificator/SpecialNotificator.php |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | $pageTitle = $titleObj->getFullText(); |
30 | 30 | $linkToPage = $titleObj->getFullURL(); |
31 | 31 | |
32 | | - if ( ! Notificator::checkEmailAddress( $receiver ) ) { |
| 32 | + if ( ! Notificator::receiverIsValid( $receiver ) ) { |
33 | 33 | $output = '<span class="error">' . wfMsg( 'notificator-e-mail-address-invalid' ) . ' ' . |
34 | 34 | wfMsg( 'notificator-notification-not-sent' ) . '</span>'; |
35 | 35 | $output .= Notificator::getReturnToText( $linkToPage, $pageTitle ); |