<?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>Involution &#187; GMail</title>
	<atom:link href="http://involution.com/category/gmail/feed/" rel="self" type="application/rss+xml" />
	<link>http://involution.com</link>
	<description>Tony Perrie&#039;s Weblog</description>
	<lastBuildDate>Fri, 19 Aug 2011 19:46:41 +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>Access Gmail from Ruby using Net::POP3 and Stunnel</title>
		<link>http://involution.com/2006/07/20/access-gmail-from-ruby-using-netpop3-and-stunnel/</link>
		<comments>http://involution.com/2006/07/20/access-gmail-from-ruby-using-netpop3-and-stunnel/#comments</comments>
		<pubDate>Thu, 20 Jul 2006 14:21:40 +0000</pubDate>
		<dc:creator>Tony Perrie</dc:creator>
				<category><![CDATA[GMail]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://involution.com/2006/07/20/access-gmail-from-ruby-using-netpop3-and-stunnel/</guid>
		<description><![CDATA[I Googled around for this at one point, however, all I could find were ill-fated attempts by a couple of tortured souls on ruby-talk. Google offers POP3S access to Gmail, but, unfortunately, Ruby&#8217;s Net::POP3S module is still under development. POP3S is the much reviled and revered Post Office Protocol tunneled over a thick blanket of [...]]]></description>
			<content:encoded><![CDATA[<p>I Googled around for this at one point, however, all I could find were ill-fated attempts by a couple of tortured souls on ruby-talk.  Google offers POP3S access to Gmail, but, unfortunately, Ruby&#8217;s Net::POP3S module is still under development.  POP3S is the much reviled and revered Post Office Protocol tunneled over a thick blanket of SSL obfuscation.  Fortunately, the good Stunnel folks have anticipated this kind of thing and they&#8217;re giving out some code that can encode and decode SSL to a standard socket.  </p>
<p>This was done on OS X, but Stunnel seems to work on most platforms.  However, I wasn&#8217;t finding it in ports or fink.  So, I had to roll my own stunnel binary.</p>
<p>
<pre><b>
wget http://www.stunnel.org/download/stunnel/src/stunnel-3.22.tar.gz
tar zxf stunnel-3.22.tar.gz
cd stunnel-3.22
./configure
make
sudo make install
</b></pre>
</p>
<p>Whew.  So, after you&#8217;ve installed stunnel, you need to invoke it to redirect a local port to Google&#8217;s secure POP3 port located at pop.gmail.com on port 995.  You can redirect any local port to Google&#8217;s pop server.  I chose to use port 42 because that&#8217;s as good as anything else.   Here&#8217;s my stunnel invocation.</p>
<p>
<pre><b>
sudo /usr/local/sbin/stunnel -c -d 42 -r pop.gmail.com:995
</b></pre>
</p>
<p>So, now you can use Ruby&#8217;s Net::POP3 to access your gmail from port 42 on your local machine.  Stunnel will handle the details of SSL. </p>
<pre style="color: #660000 !important;"><b>
require 'net/pop'

pop = Net::POP3.new('localhost', 42)
pop.start('mrbeastly', 'sUp3Rs3kRiT!')
  if pop.mails.empty?
    puts 'No mail.'
  else
    i = 0
    pop.each_mail do |m|
    exit if i > 20
    puts m.pop
    i=i+1
  end
end
</b></pre>
<p>Running this code will display the first 20 emails in Gmail to your terminal.  This is really a stopgap solution until the fabled POP3S patch gets accepted into Ruby&#8217;s Net library.  This is rumored to be soon.  So, I&#8217;ll keep my hopes up. </p>
]]></content:encoded>
			<wfw:commentRss>http://involution.com/2006/07/20/access-gmail-from-ruby-using-netpop3-and-stunnel/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

