Jump to:

22970 Posts in 11572 Topics by 2823 members

General Questions

SilverStripe Forums » General Questions » E-mail obfuscation

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2068 Views
  • Romeo
    Avatar
    Community Member
    67 Posts

    E-mail obfuscation Link to this post

    When you add a mailto link using the TinyMCE editor, there is unfortunately no means of obfuscating it, with the result that the e-mail address gets happily snapped up by the spambots. I am thinking that there must be some simple automatic way to do this obfuscation, if only by converting to ASCII characters. And unfortunately if you paste an already ASCII-obfuscated link into TinyMCE, it converts it into spambot-friendly plaintext. Unless there's some way of preventing TinyMCE from doing this (any suggestions?), I'm looking at writing some code to post-process the content and obfuscate any mailto links it finds. It strikes me as such an obviously handy thing that I'm wondering if someone has already done this before. I don't want to do any wheel-reinvention if I can avoid it.

  • Romeo
    Avatar
    Community Member
    67 Posts

    Re: E-mail obfuscation Link to this post

    I quickly did this in fact, by adding this function to my Page_Controller.php class:

       function Content() {
        if (preg_match_all('/href="(mailto:.*?)"/', $this->Content, $matches)) {
        $searches=array();
        $replaces=array();
        for($i=0;$i<count($matches[0]);$i++){
          $link=$matches[1][$i];
          $obfuscatedLink = "";
          for ($j=0; $j<strlen($link); $j++){
           $obfuscatedLink .= "&#" . ord($link[$j]) . ";";
          }
          array_push($searches,$link);
          array_push($replaces,$obfuscatedLink);
        }
        return str_replace($searches,$replaces,$this->Content);
        } else {
        return $this->Content;
        }
       }
       

    I'm a PHP newbie (I'm a Java guy) so this is undoubtedly poor PHP (I'm sure there's a better way of doing the string replaces using preg functions), but it does the job. I suspect there's a more efficient way of doing it, though.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: E-mail obfuscation Link to this post

    I usually tell my clients to not use regular e-mail links, but write the e-mail in a semi-obfuscated manner, like this:
    mail(at)domain.xx

    Then I use a jQuery script like this one: http://www.ia-stud.hiof.no/~joakims/projects/defuscator/ to convert these addresses to working e-mail links.

    If you don't like the JavaScript route, I suggest you do your obfuscation in the onBeforeWrite method of your page class. Would result in slightly less computing overhead (obfuscation just takes place when page is being saved, instead of every page view).

  • Romeo
    Avatar
    Community Member
    67 Posts

    Re: E-mail obfuscation Link to this post

    Both great ideas, thanks! I'm still slowly getting my head around the Silverstripe way of doing things, so I'm always keen to hear of better, more idiomatic techniques.

  • ravid
    Avatar
    Community Member
    6 Posts
  • Butterfly
    Avatar
    Community Member
    3 Posts

    Re: E-mail obfuscation Link to this post

    omg, email obfuscation should really be included - this is something a framework should deliver out-of-the-box!

  • banal
    Avatar
    Community Member
    901 Posts

    Re: E-mail obfuscation Link to this post

    @Butterfly
    There are some e-mail obfuscating methods implemented in Email::obfuscate already.
    But there are many different needs and approaches to email obfuscation, each of them has its advantages/disadvantages. If you find the perfect solution, please provide a snippet on http://ssbits.com (or even write a module for it)

    2068 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.