Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment