[HACK] Encode Email-Addresses to prevent SPAM

Post Reply
User avatar
CrazyBread
Master Bludit
Posts: 73
Joined: Tue Jan 19, 2016 9:51 pm
Location: Germany
Has thanked: 4 times
Been thanked: 5 times
Contact:

Hi together,

I just extended the file '[ROOT]/kernel/abstract/content.class.php'

In the function "content" I call my function to find all mail-addresses in the text and then encode them.

Code: Select all

Line 103 $content = $this->getField('content');
Line 104 $content = $this->htmlizeEmails($content);
Here are my functions (paste them right after the function "content"):

Code: Select all

	//Finds email addresses in content
	//Replace every email address with HTML-ASCII Code
	private function htmlizeEmails($text)
	{
		preg_match_all('/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})/', $text, $potentialEmails, PREG_SET_ORDER);

		$potentialEmailsCount = count($potentialEmails);
		for ($i = 0; $i < $potentialEmailsCount; $i++) {
			if (filter_var($potentialEmails[$i][0], FILTER_VALIDATE_EMAIL)) {
				$ascii_mail_address = $this->encode_email_address($potentialEmails[$i][0]);
				$text = str_replace($potentialEmails[$i][0], $ascii_mail_address, $text);
			}
	    	}
	    return $text;
	}

	//Encode a given string in HTML-ASCII
	private function encode_email_address($email)
	{
		$result = '';
		for ($i = 0; $i < strlen($email); $i++)
		{
			$result .= '&#'.ord($email[$i]).';';
		}
		return $result;
	}
Works smart, I hope you like it and maybe it will be applied in the main-code.

Greetings,

CrazyBread
User avatar
CrazyBread
Master Bludit
Posts: 73
Joined: Tue Jan 19, 2016 9:51 pm
Location: Germany
Has thanked: 4 times
Been thanked: 5 times
Contact:

Plugin is now available:

https://github.com/dignajar/bludit-plugins

>> encodemail
Post Reply