ProtectEmail
Questions answered by this recipe
How do I allow [[mailto:...]]
links on wiki pages
- but mangle the links so that spammers cannot read them?
- but they stay readable in the wiki source (mangling just during display)?
- Warning
- This recipe does not protect most email addresses. See Test.ProtectEmail for details.
Description
ProtectEmail is an email obfuscation add-on for PmWiki. It rewrites mailto: links during display into some javascript code which hides the email address.
While e-protect encodes mail addresses even in the Wiki code of a page, this add-on does not. Only while displaying mails are hidden. Be aware that this might require some protection of the actions edit, diff, source and so on if you want to protect your addresses from email grabbers.
Installation
- Copy the script protectemail.php to cookbook
- In your config.php file, add the following line:
include_once("$FarmD/cookbook/protectemail.php");
Usage
Just use [[mailto:...]]
links as usual, i.e. the following markups exist:
##[[mailto:target]]
Markup('protectedmailto','<links', "/\\[\\[mailto:([^\\s$UrlExcludeChars]*)\\s*\\]\\]($SuffixPattern)/e", "protectEmail('$1','',1)"); ##[[mailto:target | text]]
Markup('protectedmailto|','<links', "/\\[\\[mailto:([^\\s$UrlExcludeChars]*)\\s*\\|\\s*(.*?)\\s*\\]\\]($SuffixPattern)/e", "protectEmail('$1','$2',1)"); ##[[text -> mailto:target]]
Markup('-protectedmailto','<links', "/\\[\\[(.*?)\\s*-+>\\s*mailto:([^\\s$UrlExcludeChars]*)\\s*\\]\\]($SuffixPattern)/e", "protectEmail('$2','$1',0)");
The following version does not create a link to the email, only prints it:
## [[nolinkmailto:target]]
Markup('protectednolinkmailto','<links',
"/\\[\\[nolinkmailto:([^\\s$UrlExcludeChars]*)\\s*\\]\\]($SuffixPattern)/e",
"protectEmail('$1','',0)");
The rendered page code will look like this:
<script type='text/JavaScript'> <!-- Nix={map:null,convert:function(a){Nix.init();var s='';for(i=0;i<a.length;i++){var b=a.charAt(i);s+=((b>='A'&&b<='Z')||(b>='a'&&b<='z')?Nix.map[b]:b);}return s;},init:function(){if(Nix.map!=null)return;var map=new Array();var s='abcdefghijklmnopqrstuvwxyz';for(i=0;i<s.length;i++)map[s.charAt(i)]= s.charAt((i+13)%26);for(i=0;i<s.length;i++)map[s.charAt(i).toUpperCase()]= s.charAt((i+13)%26).toUpperCase();Nix.map=map;},decode:function(a){ document.write(Nix.convert(a));}} //--> </script> <script type='text/JavaScript'> <!-- Nix.decode("<n pynff='heyyvax' uers='znvygb:fgf@1fgrva.bet'>fgf@1fgrva.bet</n>"); //--> </script>
though the rendered version in the browser looks as expected:
foo@yahoo.net
Notes
Version in script does not match version on this pae, causing SiteAnalyzer to detect a difference
Release Notes
- 2024-03-03 compatibility update for php 5.5 changes (tested with php 8.1), see here: protectemail.php. Could be improved, to contain less copy/paste, but it works.
- 2006-11-29 fixed
[[foo -> mailto:foo@foo.com]]
, thanks to Roman - 2006-11-13
$RecipeInfo
line - 2006-10-31 remove whitespace before nolinkmailto addresses (thanks to Pierre Racine)
Comments
- Is it possible to provide support for mailto links which specify a subject? Eg.
[[mailto:foo@bar.com?subject=this is a subject]]
. It would be quite helpful for a site I'm helping some friends with. Thanks! -- Profiles.AdamShand 2007.01.05- Yes, it is possible. You just have to replace spaces by
%20
. Then it works fine, see http://1stein.org/SandBox/SandBox (the third address there). sts- Thanks for that, I tried it and it does work. I was thrown initially by the fact that the %20's show up in the web page but then I realized that I could make it a named link of whatever I wanted. Cheers! AdamShand
- Yes, it is possible. You just have to replace spaces by
- I would like to use
Attach:...
instead of the link replacement text to display an image linked tomailto:
. Unfortunately, this recipe displaysAttach:...
as page text. SteP - This is great, just what I need. Two enhancement suggestions if I could please
- many of my emails are in the format
mailto:foobar@example.com
(a previous obfuscation), would it be possible to allow html emtities? - some emails are in the form
[[(mailto:)foobar(@example.com)]]
, again
- many of my emails are in the format
- Nice, but testing the protection with http://aspirine.org/cgi-bin/trouvemail.pl?lang=en I found that protection was lacking, so I made a version that changed the rot13 encoding to a more random encoding that included the '@'. Work in progress protectemail2008.phpΔ - Damien October 02, 2008, at 02:44 AM
See Also
- EProtect - Email obfuscation via ROT13
- ObfuscateEmail - Prevent email addresses from being harvested from your site
- DeObMail - Unobtrusive e-mail link (de)obfuscator
- Graceful E-Mail Obfuscation
Contributors
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.