Skip to content

Instantly share code, notes, and snippets.

@kdwinter
Created February 15, 2009 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdwinter/64869 to your computer and use it in GitHub Desktop.
Save kdwinter/64869 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'net/https'
require 'rexml/document'
require 'time'
@username = "" # (without @gmail.com)
@password = ""
http = Net::HTTP.new('mail.google.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.ca_path = '/etc/ssl/certs'
request = Net::HTTP::Get.new('/mail/feed/atom')
request.basic_auth(@username, @password)
doc = REXML::Document.new(http.request(request).body)
begin
@messages = doc.elements.to_a("//entry").map do |e|
{:subject => e.elements["title"].text,
:summary => e.elements["summary"].text,
:from => e.elements.to_a["author"].map do |a|
{:name => a.elements["name"].text,
:email => a.elements["email"].text}
end[0],
:date => Time.xmlschema(e.elements["issued"].text),
:link => e.elements["link"].attributes["href"]}
end
rescue
end
@count = doc.root.elements["fullcount"].text.to_i
puts @count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment