Email antispam protection

Posted on Friday, December 19th, 2008 under , ,

Spamming is by far the most idiotic of all computer related activities, and I doubt that there is a single person that din’t find junk mail in his/her inbox. But how do you get on a spammer list and most important, what can you do to prevent this?

Spammers use specific software – known as crawlers – to harvest email addresses from the net. These programs surf the web by following links from one page to another and save all the email addresses they encounter in large databases. The emails are recognized by using mathematical patterns known as regular expressions. You can read more about these here.

If you need to post your email address on a public web-page and you don’t want to buy manhood enlargement pills, get home loans or help nigerian dictators to get their wealth out of Swiss banks, you really need to hide your email from these harvesters. And it’s not such a hard task to perform…

Let’s analyze an email link. It looks like:

<a href="mailto:foo@bar.com">foo@bar.com</a>

First of all, let’s hide the first occurrence of the email address behind a simple javascript function:

noSpam = function( user, domain ) {
	document.location = 'mailto:' + user + '@' + domain;
}

The link will now become:

<a href="javascript:noSpam( 'foo', 'bar.com' )">foo@bar.com</a>

But this alone won’t help much, because the address foo@bar.com appears in clear text in the page’s source code and it will be picked up by the crawler’s RegEx engine. Therefor, this address will also need to be scrambled.

The CSS based solution

A decent level of scrambling can be achieved by writing the email backwards – moc.rab@oof – so the link will become:

<a href="javascript:noSpam( 'foo', 'bar.com' )" class="email">moc.rab@oof</a>

And then, by using this nifty piece of CSS, we can rest assured that the email is displayed correctly to the user.

a.email {
	direction:rtl;
	unicode-bidi: bidi-override;
}

Related posts

5 Responses to “Email antispam protection”

  1. • Justin •

    I tested this and it doesn’t seem to work on Mac OS X 10.4.10 using Safari 2.0.4. It appears that there is no support for the unicode-bidi in Safari for Mac, see http://developer.apple.com/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html for more info on Safari support. Is there another way to accommodate Safari for Mac with this method?

  2. Tudor

    I don’t own a Mac, so I haven’t tested it in Safari. Thanks for pointing it out for me…I’ll look into it!

  3. • dfsdfs •

    but safari exists for windows tudor ;) 3.1.2 actually :)

  4. Tudor

    No doubt about that…but I’m using Linux

    Anyway, Justin, you could try to do some javascript browser sniffing and if it’s Safari, parse the whole document with js and write all the links backwards. Won’t work if the user disables the js support…

  5. Andrei

    Another way of doing it even though is not DOM compliant

    function noSpam( user, domain ) {
        document.write ('<a href="mailto:' + user + '@' + domain + '" rel="nofollow">' + user + '@' + domain + '</a>');
    }

    I know you’ll write the DOM compliant one using document.createElement, setAttribute and such

Leave a Reply