<?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&#039;s 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 Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<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>bseanvt</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 &#34;me@domain.com&#34;, &#34;My email&#34;, :encode =&#62; &#34;hex&#34; # =&#62; &#60;a href=&#34;mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d&#34;&#62;My email&#60;/a&#62; 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 [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Femail-obfuscation-and-extraction-from-text-with-rails%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Email Obfuscation and Extraction from Text with Rails" data-url="http://seanbehan.com/ruby-on-rails/email-obfuscation-and-extraction-from-text-with-rails/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>There is a helper method for handling the obfuscation of email addresses in Rails.</p>
<pre class="wp-code-highlight prettyprint">
mail_to &quot;me@domain.com&quot;, &quot;My email&quot;, :encode =&gt; &quot;hex&quot;
 # =&gt; &lt;a href=&quot;mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d&quot;&gt;My email&lt;/a&gt;
</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 class="wp-code-highlight prettyprint">
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(&quot;@&quot;, &quot;&lt;small&gt;[at]&lt;/small&gt;&quot;), :encode=&gt;: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 class="wp-code-highlight prettyprint">
text.gsub( /([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})/i, mail_to('\\1@\\2', '\\1@\\2', :encode=&gt;: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 class="wp-code-highlight prettyprint">
&lt;%= emailitize @job.how_to_apply %&gt;
</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>
]]></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>

