From e2a8c00bd2c718a9ffb0bf2e3d64ee3795c51a24 Mon Sep 17 00:00:00 2001 From: thisismeonmounteverest Date: Sun, 12 May 2024 11:33:04 +0200 Subject: [PATCH] Rewrite email recognization algorithm. --- src/Model/CommentModel.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Model/CommentModel.php b/src/Model/CommentModel.php index 70b8b5bdf..62231a352 100644 --- a/src/Model/CommentModel.php +++ b/src/Model/CommentModel.php @@ -171,16 +171,8 @@ private function checkCommentSimilarity(array $comments, Comment $comment): bool public function checkForEmailAddress(Comment $comment): bool { $commentText = $comment->getTextfree(); - $atPos = strpos($commentText, '@'); - $whiteSpaceBefore = strrpos(substr($commentText, 0, $atPos), ' '); - $whiteSpaceAfter = strpos($commentText, ' ', $atPos); - if (false === $whiteSpaceAfter) { - $whiteSpaceAfter = strlen($commentText); - } - $potentialEmailAddress = - substr($commentText, $whiteSpaceBefore + 1, $whiteSpaceAfter - $whiteSpaceBefore - 1); - $emailAddressFound = filter_var($potentialEmailAddress, FILTER_VALIDATE_EMAIL) !== false; + $count = preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $commentText, $matches); - return $emailAddressFound; + return $count > 0; } }