A simple Django app providing template tags that attempt to obfuscate raw e-mail addresses to make them ever so slightly more difficult to scrape.
To be less-obtrusive, JavaScript is used to translate mangled source into a normal e-mail address. If JavaScript is not present, the reCAPTCHA mailhide service is offered to deobfuscate the addresses.
Using images, LTR-RTL hacks, or forcing reCAPTCHA access might be better at keeping your address safe from bots, but it's annoying for legitimate users. By using JavaScript, hopefully we can thwart some of the dumbest bots into farming someone else's email address without much of a usability hit.
In your Django's settings:
Add
'mailmangler'
toINSTALLED_APPS
.Define
MAILMANGLE_PUBLIC
andMAILMANGLE_SECRET
with keys from the reCAPTCHA Mailhide API, e.g.MAILMANGLE_PUBLIC = 'your-key...==' MAILMANGLE_SECRET = '123789...abcd'
Load the tags and filters in your template with
{% load mailmangler %}
In the
<head>
of your template, add{% mailmangle_js %}
. (The JS deobfuscator uses inlinedocument.write
's, so by loading the code early, hopefully this will avoid any rendering delays.)Pipe (filter) email addresses through
mailmangle
ormailmangle_linked
, e.g.{{ my_email_var|mailmangle }} {{ "[email protected]"|mailmangle }} {{ "[email protected]"|mailmangle_linked }}
will produce:
- A JS obfuscated, unlinked string of whatever
my_email_var
was. - A JS obfuscated, unlinked string of "[email protected]"
- A JS obfuscated, string with mailto link of "[email protected]"
If JS is not present, a reCAPTCHA mailhide link is available in
<noscript>
tags.- A JS obfuscated, unlinked string of whatever