Encapsulating e-mails for usability and spam protection

Introduction

Having spam is something we as developers, must deal with daily, avoiding spam is a must that we should keep in mind in all our projects. The usual method of hiding an e-mail is to wrap it up with words like at and dot, this is a trend but when it comes to usability versus spam-fighting, users could get confused. Using the e-mail generation method of eZ Publish combined with jQuery leads us to a safer html code that will avoid further more e-mail-spam-grabbers and will bring up usability in our projects. Developers will gain protection for e-mails and users will rely on well written e-mail sequences.

 

Pre-requisites and target population

To understand this tutorial you will need a basic knowledge of jQuery (www.jquery.com) and knowledge on how to configure .ini files in an eZ Publish installation.

 

Step 1 : Setting up template.ini.append.php

Recently I wanted to make e-mail addresses "uncatchable" at a site to avoid crawlers that collect them, a solution was to configure sitesettings/your-site/template.ini.append.php and add under [WashSettings] the following:

# Replacements strings for the . and @ in an email
# Used to display emails in a way that SPAM engines
# cannot fetch automatically
EmailDotText= [punto] 
EmailAtText= [@]

Adding such definitions e-mail addresses become something like "myname [@] domain [punto] com", you can also change it to the conventional "at" and "dot".

Hint: You can leave spaces before and after each definition “ [punto] ” or “ [@] ” to achieve spaces within the e-mail sequence

The code generated as html by eZ Publish looks something like this:

<a href="mailto:myname@domain.com">myname [@] domain [punto] com</a>

This kind of sequence for an e-mail addresses is not always a straight-forward solution. Avoiding the mailto also keeps crawlers away, so with some jQuery code we can obtain a more interesting approach. You can still let the eZ Publish kernel handle the e-mail address generation but this time surrounded by the <div> that jQuery code will then handle later on when the page has loaded.

An example of template code :

{$owner_map.user_account.content.email|wash('email')}

Will generate something like this:

myname [@] domain [punto] com

Wrapped around the div and adding an id, this will become:

<div id="mail">myname [@] domain [punto] com</div>
 

Step 2 : Adding usability using jQuery

Enabling jQuery at an eZPublish project can be done by activating the eZ JS Core certified extension as you would with any extension in eZ Publish. For more information, see http://doc.ez.no/Extensions/eZ-JS-Core/. You could also add the jQuery JS code in your pagelayout (visit www.jquery.com).

The jQuery code that deals with the <div> is:

<script type="text/javascript">
$(function(){
                //scrambles mails with [@] and [punto]                
                var spt = $('div#mail');
                var at = " [@] ";
                var dot =" [punto] ";
                var addr = $(spt).text().replace(at,"@").replace(dot,".");
                
                $(spt).after( '<a href="mailto:' + addr + '" title="Send an email">' +  addr + '</a>' ).hover( 
                       function()
                       {
                           window.status = "Send a letter!";
                       },
                       function()
                       {
                          window.status="";
                       }
                      );
                $(spt).remove();              
});
</script>

You can also add within the js code some eZ code that fetches from the template.ini the values of EmailDotText and EmailAtText so whenever you change the definition at the .ini the jQuery works as well.

Once the jQuery runs you get a nicer and understandable e-mail "myname@domain.com" at the frontend site with its own “mailto” once you hover over the link, but this time crawlers will not see it at all as the code is not understandable for them, as for users they will get the well-known e-mail addresses sequence as it should always be.

 

Conclusion

Developers make projects for users, but not all of them have the knowledge enough to understand scrambled e-mail address sequences that should be interpreted as simple e-mails sequences and thus trust and click them. Usability is a must in the development of a project. In this tutorial we have learned how to achieve better code to protect our users from spam and an understandable e-mail address sequence for our users. Happy developer, happy user!

 

Resources

This tutorial is available for offline reading :
Jorge Estevez - Encapsulating e-mails for usability and spam protection - PDF Version

 

About the author : Jorge Estévez Rams

Jorge Estévez Rams is using eZ Publish since eZ Systems was founded; he leads a web development group in Havana, Cuba (www.elfosdesign.com).

 

License

This work is licensed under the Creative Commons – Share Alike license ( http://creativecommons.org/licenses/by-sa/3.0 ).

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 17 2025 20:50:00
Script start
Timing: Jan 17 2025 20:50:00
Module start 'layout'
Timing: Jan 17 2025 20:50:00
Module start 'content'
Timing: Jan 17 2025 20:50:00
Module end 'content'
Timing: Jan 17 2025 20:50:00
Script end

Main resources:

Total runtime0.0912 sec
Peak memory usage4,096.0000 KB
Database Queries39

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0043 597.6094152.1563
Module start 'layout' 0.00430.0024 749.765639.5391
Module start 'content' 0.00670.0833 789.3047762.1484
Module end 'content' 0.09000.0012 1,551.453114.1797
Script end 0.0912  1,565.6328 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00283.0299160.0002
Check MTime0.00121.3286160.0001
Mysql Total
Database connection0.00070.789110.0007
Mysqli_queries0.033636.8293390.0009
Looping result0.00030.2796370.0000
Template Total0.068675.120.0343
Template load0.00202.212620.0010
Template processing0.066572.918720.0333
Template load and register function0.00010.086510.0001
states
state_id_array0.00212.307230.0007
state_identifier_array0.00151.610040.0004
Override
Cache load0.00232.4901740.0000
Sytem overhead
Fetch class attribute name0.00151.659220.0008
Fetch class attribute can translate value0.00000.025310.0000
class_abstraction
Instantiating content class attribute0.00000.006820.0000
XML
Image XML parsing0.00040.460110.0004
General
dbfile0.00070.7632130.0001
String conversion0.00000.006340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/article.tplextension/sevenx/design/simple/override/templates/full/article.tplEdit templateOverride template
1content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/header.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/header.tplEdit templateOverride template
2content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
18content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/separator.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltags/separator.tplEdit templateOverride template
6content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
3content/datatype/view/ezxmltags/newpage.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/newpage.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/embed-inline.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/embed-inline.tplEdit templateOverride template
1content/view/embed-inline.tpl<No override>design/standard/templates/content/view/embed-inline.tplEdit templateOverride template
1content/datatype/view/ezxmltags/embed.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/embed.tplEdit templateOverride template
1content/view/embed.tplembed/image.tplextension/sevenx/design/simple/override/templates/embed/image.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 62
 Number of unique templates used: 18

Time used to render debug report: 0.0001 secs