<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean Behan&#039;s Web Development Portfolio and Blog &#187; obfuscation</title>
	<atom:link href="http://seanbehan.com/tag/obfuscation/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Development, Wordpress, Moodle, Ruby on Rails and Design in Burlington, Vermont</description>
	<lastBuildDate>Fri, 30 Jul 2010 17:17:12 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Email Obfuscation and Extraction from Text with Rails</title>
		<link>http://seanbehan.com/ruby-on-rails/email-obfuscation-and-extraction-from-text-with-rails/</link>
		<comments>http://seanbehan.com/ruby-on-rails/email-obfuscation-and-extraction-from-text-with-rails/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 16:50:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[hyperlinking]]></category>
		<category><![CDATA[obfuscation]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[recipes]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=423</guid>
		<description><![CDATA[There is a helper method for handling the obfuscation of email addresses in Rails. 

mail_to "me@domain.com", "My email", :encode => "hex"
 # => My email

If you want to then extract an email address(or all email addresses) from a block of text here is the code. I created a helper function called &#8220;emailitize&#8221; and put it [...]


Related posts:<ol><li><a href='http://seanbehan.com/programming/carrier-email-addresses-for-sending-sms-over-email/' rel='bookmark' title='Permanent Link: Carrier Email Addresses for Sending SMS over Email'>Carrier Email Addresses for Sending SMS over Email</a></li>
<li><a href='http://seanbehan.com/programming/sending-email-with-rails-on-mac-os-x-development-environment/' rel='bookmark' title='Permanent Link: Sending eMail with Rails on Mac OS X Development Environment'>Sending eMail with Rails on Mac OS X Development Environment</a></li>
<li><a href='http://seanbehan.com/programming/yield-a-block-within-rails-helper-method-with-multiple-content_tags-using-concat/' rel='bookmark' title='Permanent Link: Yield a Block within Rails Helper Method with Multiple Content_tags Using Concat'>Yield a Block within Rails Helper Method with Multiple Content_tags Using Concat</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>There is a helper method for handling the obfuscation of email addresses in Rails. </p>
<pre>
mail_to "me@domain.com", "My email", :encode => "hex"
 # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
</pre>
<p>If you want to then extract an email address(or all email addresses) from a block of text here is the code. I created a helper function called &#8220;emailitize&#8221; and put it in the ApplicationHelper module inside helpers/application_helper.rb </p>
<pre>
module ApplicationHelper
  #takes a string and will return the same string but with email addresses encoded and hyperlinked
  def emailitize(text)
    text.gsub(/([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})/i) {|m|
        mail_to(m, m.gsub("@", "<small>[at]</small>"), :encode=>:hex)
    }
  end
end
</pre>
<p>It&#8217;s important to remember that you&#8217;ll need to pass a block to the gsub method. You can&#8217;t do something like this instead</p>
<pre>
text.gsub( /([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})/i, mail_to('\\1@\\2', '\\1@\\2', :encode=>:hex) )
</pre>
<p>It will work except the encode will fail. It will evaluate the &#8216;\\1@\\2&#8242; strings rather than as dynamic variables. </p>
<p>You can then use this function in your views </p>
<pre>
<%= emailitize @job.how_to_apply %>
</pre>
<p>More information is available in the Rails and Ruby docs: </p>
<p>http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001887</p>
<p>http://ruby-doc.org/core/classes/String.html#M000817</p>


<p>Related posts:<ol><li><a href='http://seanbehan.com/programming/carrier-email-addresses-for-sending-sms-over-email/' rel='bookmark' title='Permanent Link: Carrier Email Addresses for Sending SMS over Email'>Carrier Email Addresses for Sending SMS over Email</a></li>
<li><a href='http://seanbehan.com/programming/sending-email-with-rails-on-mac-os-x-development-environment/' rel='bookmark' title='Permanent Link: Sending eMail with Rails on Mac OS X Development Environment'>Sending eMail with Rails on Mac OS X Development Environment</a></li>
<li><a href='http://seanbehan.com/programming/yield-a-block-within-rails-helper-method-with-multiple-content_tags-using-concat/' rel='bookmark' title='Permanent Link: Yield a Block within Rails Helper Method with Multiple Content_tags Using Concat'>Yield a Block within Rails Helper Method with Multiple Content_tags Using Concat</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/email-obfuscation-and-extraction-from-text-with-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
