Skip to content

Commit e2a8c00

Browse files
Rewrite email recognization algorithm.
1 parent 51edc14 commit e2a8c00

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/Model/CommentModel.php

+2-10
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,8 @@ private function checkCommentSimilarity(array $comments, Comment $comment): bool
171171
public function checkForEmailAddress(Comment $comment): bool
172172
{
173173
$commentText = $comment->getTextfree();
174-
$atPos = strpos($commentText, '@');
175-
$whiteSpaceBefore = strrpos(substr($commentText, 0, $atPos), ' ');
176-
$whiteSpaceAfter = strpos($commentText, ' ', $atPos);
177-
if (false === $whiteSpaceAfter) {
178-
$whiteSpaceAfter = strlen($commentText);
179-
}
180-
$potentialEmailAddress =
181-
substr($commentText, $whiteSpaceBefore + 1, $whiteSpaceAfter - $whiteSpaceBefore - 1);
182-
$emailAddressFound = filter_var($potentialEmailAddress, FILTER_VALIDATE_EMAIL) !== false;
174+
$count = preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $commentText, $matches);
183175

184-
return $emailAddressFound;
176+
return $count > 0;
185177
}
186178
}

0 commit comments

Comments
 (0)