電子メール アドレスを難読化してクローラー、スパムボット、メール ハーベスターから保護し、メール アドレスを収集してスパムを送信するために、Rails がどのような機能を提供しているのか疑問に思っていました。
間違ったキーワードを使用した可能性がありますが、本当に宝石を見つけることができませんでした.
メールアドレスをマスクするさまざまな方法を比較した統計を見つけました: http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/
上位 2 つの方法を組み合わせたスニペットを作成しました。
切り取られたものはまだ成熟していませんが、とにかく共有したいと思います。同じ問題に直面している他の人にとっての出発点になるかもしれません. (次のステップの 1 つは、既にリンクされているアドレスを不明瞭なプレーン テキストに置き換えることです。)
先に進む前に、Rails のベスト プラクティスについて知りたいと思います。これは一般的な問題であり、対処する宝石を見逃していたに違いありません!?
私のアプローチを使用する場合、アプリに統合/トリガーする最良の方法は何ですか?
どんな種類の before_filter ですか? レンダリング前??? そんな感じ?
または、私が現在行っているように、ビューで helper_methode として呼び出していますか?
文字列クラスに追加することもできます…</p>
私の中でapplication_helper.rb
def obfuscate_emails(content, domain_prefix = 'nirvana', clss = 'maildecode')
# This shall protect emails from spam spiders/crawlers gathering emails from webpages
# Add the following SASS to your Stylesheets
#
# span.maildecode
# direction: rtl
# unicode-bidi: bidi-override
#
# Further more you might want to use Javascript(.erb) to add links to the email addresses like this
#
# $(document).ready(function() {
# function link_emails(subdomain){
# console.log("Find an replace reverse emails, fake subdomain is "+subdomain);
# $(".maildecode").each(function() {
# email = $(this).text().replace('.'+subdomain,'').split("").reverse().join("");
# console.log("- clean email is "+email);
# // $(this).html($(this).text().replace('.'+subdomain,'')); // uncomment if you like to clean up the html a bit
# $(this).wrap('<a href="mailto:'+email+'">');
# });
# }
#
# link_emails('<%= ENV['OBFUSCATE_EMAIL_SUBDOMAIN'] %>');
# });
#
# Thanks to
# http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/
email_re = /[\w.!#\$%+-]+@[\w-]+(?:\.[\w-]+)+/
content.scan(email_re).each do |mail|
obfuscate_mail = "<span class='#{clss}'>#{mail.reverse.split('@')[0]}<span style='display: none;'>.#{domain_prefix}</span>@#{mail.reverse.split('@')[1]}</span>"
content = content.sub(mail, obfuscate_mail)
end
content # use raw(obfuscate_emails(content)) otherwise rails will escape the html
end