Skip to content

Commit

Permalink
Rewrite email recognization algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismeonmounteverest committed May 12, 2024
1 parent 51edc14 commit e2a8c00
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/Model/CommentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit e2a8c00

Please sign in to comment.