A simple ruby email2rss example When I was searching for some basic ruby scripts to download pop email I came across the email 2 Rss project on Ruby forge. Since I noticed there was no code available for the project yet I figured I would make a quick version up and make the code available, so anyone else searching for similar examples would have a starting point. This code is just a functional example, but doesn’t have any real options or error checking so use at your own risk. Download the source to Ruby Email to RSS Feed <pre>require ‘net/pop’require ‘rss/maker’ version = “2.0” # [“0.9”, “1.0”, “2.0”]destination = “/archive/emailFeed.xml” # local file to write #create a new email Feedcontent = RSS::Maker.make(version) do rss rss.channel.title = “Dan Email Feed” rss.channel.link = “http://www.pretheory.com” rss.channel.description = “My newest emails” rss.items.do_sort = true # sort items by date Net::POP3.start(‘pop.yourDomain.com’, 110, ‘userName’, ‘myPass’) do pop if pop.mails.empty? puts ‘No mail.’ else i = 0 pop.each_mail do m # or “pop.mails.each …” subject = m.header.split(“\r\n”).grep(/^Subject: /)[0] subject = subject.gsub(“Subject: “,””) subject = subject.gsub(“:”,””) subject = subject[0,15] if(subject.length > 15) link = ‘http://www.gmail.com’ body = m.pop body = body[0,25] if(body.length > 25) #create feed item item = rss.items.new_item item.title = subject item.link = link item.date = Time.now item.description = body i += 1 end puts “#{pop.mails.size} mails popped.” end endend File.open(destination,”w”) do f f.write(content)end puts ‘Done. Thanks.’</pre>

blog comments powered by Disqus
Dan Mayer Profile Pic

I primary write about Ruby development, distributed teams, & dev/PM process. The archives go back to my first CS classes during college when I was learning to write software. I contribute to a few OSS projects and often work on my own projects. You can find my code on github.

Twitter @danmayer

Github @danmayer