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;
}