Email obfuscation helper

Hi guys, anyone knows a Middleman extension that has an email obfuscation helper? Like we used to have in Rails and now it was ported to this gem https://github.com/reed/actionview-encoded_mail_to

I know that there’s a Middleman extension called middleman-protect-emails https://github.com/amsardesai/middleman-protect-emails but I don’t like this solution.

Thanks!

Hi -
I’m not sure it answers your question (it is not a gem, after all), but I use the following code in config.rb

# obfuscate a mail address "email" # optional argument "string" is the text to show on the webpage # # Adapted from: # http://stackoverflow.com/questions/483212/effective-method-to-hide-email-from-spam-bots # MAIL_TO = 'mailto:' AT = '@' DOT = '.'

def mailto email="user@example.com", string=“contact me”
comp = email.split("@")

# process string, if it is an email address
if string.include?("@") then
  string.gsub!("@", AT + "‌").gsub!(".", DOT)
end

%|<a href="my email when you click"
       rel="nofollow"
       onclick="str1='#{comp[0]}';str2='#{comp[1]}';this.href='#{MAIL_TO}' + str1 + '@' + str2">#{string}</a>|

end

and then, in the views:

<%= mailto "info@example.com", "send me an mail" %>

concerning the robustness of the obfuscation, plase refer to the stackoverflow post where the obfuscation code is taken from.

1 Like

Thank you very much!

I made some tweaks and it’s working great! Here’s the gist https://gist.github.com/renatocarvalho/afda8238f57f57b94ae5