Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Possible new extension - Email obfuscator

StashStash
edited January 2007 in Vanilla 1.0 Help
Is there interest in an extension that takes email addresses and obfuscates them so that spam bots have a harder time harvesting them? I was thinking about doing something like this and wondered if anyone else thinks it's a good idea.

Comments

  • You mean like it already is done in the account profiles, but in comments instead?
  • Basically, yes. Although I was thinking about a PHP based one so that it would function even when JS is off. Perhaps even allow the admin the option of which one they'd like to use.
  • NickENickE New
    edited January 2007
    Something like this should work with the vast majority of email addresses:
    <?php
    /*
    Extension Name: Email Obfuscator
    Extension Url: http://lussumo.com/docs/
    Description: Obfuscates emails in the default formatter
    Version: 1.0
    Author: SirNotAppearingOnThisForum
    Author Url: N/A
    */
    
    /*
    	this value can be one of the following:
    	default - hooks only the default formatter
    	all - hooks all of the formatters
    	formatter - hooks only into specified formatter (eg. Html)
    */
    define('EO_HOOK_WHICH_FORMATTER',		'default');
    
    $EmailRegex = "/
    (?<=[^A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~])
    (
    	(
    		(
    			[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~]
    			[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~.]{0,63}?
    		) | 
    		(
    			\"[^\\\"]{1,62}?\"
    		)
    	)
    	@
    	(
    		(
    			[0-9]{1,3}\.
    			[0-9]{1,3}\.
    			[0-9]{1,3}\.
    			[0-9]{1,3}
    		) | 
    		(
    			[A-Za-z0-9]
    			[A-Za-z0-9\-.]{0,244}\.
    			[A-Za-z]{2,10}
    		)
    	)
    )
    (?=[^\w])
    /isx";
    $EmailReplace = 'YOUR OBFUSCATION METHOD HERE; \\2 = local, \\5 = domain';
    
    if(@$Context->StringManipulator)
    {
    	class EmailObfuscator extends StringFormatter
    	{
    		function Parse($str, $obj, $purpose)
    		{
    			if($purpose == FORMAT_STRING_FOR_DISPLAY) 
    				return preg_replace($GLOBALS['EmailRegex'], $GLOBALS['EmailReplace'], $str);
    			else return $str;
    		}
    	}
    	
    	$EmailObfuscator = $Context->ObjectFactory->NewObject($Context, 'EmailObfuscator');
    	
    	if(EO_HOOK_WHICH_FORMATTER == 'default')
    		$Context->StringManipulator->Formatters[$Configuration['DEFAULT_FORMAT_TYPE']]->
    			AddChildFormatter($EmailObfuscator);
    	else if(EO_HOOK_WHICH_FORMATTER == 'all')
    	{
    		while(list(, $o) = each($Context->StringManipulator->Formatters))
    			$o->AddChildFormatter($EmailObfuscator);
    		
    		reset($Context->StringManipulator->Formatters);
    	}
    	else if(isset($Context->StringManipulator->Formatters[EO_HOOK_WHICH_FORMATTER]))
    		$Context->StringManipulator->Formatters[EO_HOOK_WHICH_FORMATTER]->
    			AddChildFormatter($EmailObfuscator);
    }
    
    ?>
  • StashStash
    edited January 2007
    I can't seem to get that working SirNot. I've tried it using all combinations of 2, 5 for the EmailReplace function eg:$EmailReplace = '5';and$EmailReplace = '5';
    and all the options for the EO_HOOK_WHICH_FORMATTER eg:defaultandallandHtml
    In fact, when I set it to 5 and Html I end up with my email address being replaced with:<a href="mailto:5">5<a/>

    Edit: why is my text coming out bold here?

    Is something ballsed up with the code above? Has some essential stuff been stripped out? Is that what's causing my text above to be bold and for the extension to not work?
  • What if you were to make the extension make the obfuscated email a link then automatically undo the obfuscation on the fly?
  • I'm not sure I understand what you're asking y2kbg.
  • NickENickE New
    edited January 2007
    if you just wanted to display the email address as a link, it'd look like this:$EmailReplace = '<a href="mailto:\\2@\\5">clicky</a>';I'm not sure why it's coming out bold, though, I'll look into that...
    Ah, I see what happened. You misspelled one of your <strong> tags as <stong>, so the html formatter though you had an unclosed <stong> and an orphaned </strong> :-P
  • Ah thanks for that SirNot, I'll give that a try :)

    Rock on me with the typos :P (that hasn't been the only one to cause trouble today)
  • Using this:<a href="mailto:\\2@\\5">\\2@\\5</a>

    And this:<a href="mailto:email@server.com">email@server.com<a/>
    Gives me this:<a href="mailto:<a href="mailto:email@server.com">email@server.com</a>"><a href="mailto:email@server.com">email@server.com</a><a/>
  • NickENickE New
    edited January 2007
    You misunderstand how it works. It goes through and finds every email address (be it in a tag or not) in the message. I left, however, the replacement string empty so you could implement your own obfuscation method (but remember it could be in a tag); to make things simpler, I told you which references were what, ie. \\2 = local part of email address, and \\5 = domain part of email address. here's a really simple example:$EmailReplace = '\\2 AT \\5';
  • Sorry for being dumb. Like I said, you're too clever for me...
This discussion has been closed.