Created
February 15, 2009 22:02
-
-
Save kdwinter/64869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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