Enkoder Rails Plugin

Posting your email address on a website is a sure-fire way to get an inbox full of unsolicited email advertisements. The Enkoder helps protect email addresses by converting them into encrypted JavaScript code, hiding them from email-harvesting robots while revealing them to real people.

The Enkoder plugin provides an extension to the Rails TextHelper module that can be used to protect email addresses (or other information) by obfuscating them using JavaScript code.

The Enkoder uses a significantly different (and possibly more secure) algorithm than the built-in mail_to helper.

Note: while using the Enkoder is a good step in helping to protect your email address, the only way to be completely safe is to not publish your address at all.

Installation

You can download the Enkoder plugin as an archive. Then, just decompress and untar the archive and drop the enkoder folder it creates into your project’s vendor/plugins folder.

Usage

There are two methods:

enkode( html )

This method accepts a block of html (or any text) and returns an enkoded JavaScript.

The second method is:

enkode_mail( email, link_text, title_text, subject )

This method takes an email address, the text to show to the viewer, optional title text (what’s seen when somebody hovers over the link), and optional subject for the email, and returns an enkoded email address link.

Examples

To enkode a single email address, one could just do:

<%= enkode_mail('user@domain.com','click here') %>

And the following link would be returned (enkoded as JavaScript):

<a href="mailto:"user@domain.com" title="">click here</a>

Adding a title and subject text would require the second two optional fields:

<%=
  enkode_mail(
    'user@domain.com',
    'click here',
    'email me',
    'enkoder'
  )
%>

And we’d get back (enkoded as JavaScript):

<a
  href="mailto:"user@domain.com?subject=enkoder" 
  title="email me" 
>click here</a>

Of course we can also enkode many email addresses on the fly:

<% @users.each do |user| %>
  <p><%= enkode_mail(@user.email,@user.name) %></p>
<% end %>

To enkode a snippet of XHTML, we can do:

<%=
  enkode(
    "<p>This block will be hidden from spambots.</p>" 
  )
%>

We could protect a link or block of XHTML from being indexed like this:

<%=
  enkode(
    'Try and find <a href="secret.html">this</a>, google!'
  )
%>

We could have anything we wanted in that block, XHTML, links, email addresses, etc.

Special Thanks

I’d like to share my gratitude to The Guru, wherever he dwells, for his assistance with the latest Enkoder algorithm. Without his help, we’d still be in the stone-ages, using easily-decoded HTML entity conversions or performing voodoo rituals to try and ward-off spam.