From c959ac45e74d6bcfea96fc78a832dc6f29efcde4 Mon Sep 17 00:00:00 2001 From: Dag Odenhall Date: Fri, 28 Mar 2008 20:52:52 +0100 Subject: [PATCH] GMail widget --- lib/amazing/widgets.rb | 1 + lib/amazing/widgets/gmail.rb | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 lib/amazing/widgets/gmail.rb diff --git a/lib/amazing/widgets.rb b/lib/amazing/widgets.rb index f2e87a9..295ef70 100644 --- a/lib/amazing/widgets.rb +++ b/lib/amazing/widgets.rb @@ -6,6 +6,7 @@ require 'amazing/widgets/battery' require 'amazing/widgets/clock' require 'amazing/widgets/file' require 'amazing/widgets/filesystem' +require 'amazing/widgets/gmail' require 'amazing/widgets/maildir' require 'amazing/widgets/memory' require 'amazing/widgets/moc' diff --git a/lib/amazing/widgets/gmail.rb b/lib/amazing/widgets/gmail.rb new file mode 100644 index 0000000..c39c45c --- /dev/null +++ b/lib/amazing/widgets/gmail.rb @@ -0,0 +1,47 @@ +# Copyright (C) 2008 Dag Odenhall +# Licensed under the Academic Free License version 3.0 + +require 'amazing/widget' + +module Amazing + module Widgets + class GMail < Widget + description "GMail checker" + dependency "net/https", "Ruby standard library" + dependency "rexml/document", "Ruby standard library" + dependency "time", "Ruby standard library" + option :username, "Username" + option :password, "Password" + option :certificates, "Path to SSL certificates", "/etc/ssl/certs" + option :verify, "Verify certificates", false + field :messages, "List of new messages" + field :count, "Number of new messages" + default "@count" + + init do + http = Net::HTTP.new("mail.google.com", 443) + http.use_ssl = true + if @verify + http.verify_mode = OpenSSL::SSL::VERIFY_PEER + http.ca_path = @certificates + else + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + request = Net::HTTP::Get.new("/mail/feed/atom") + request.basic_auth(@username, @password) + doc = REXML::Document.new(http.request(request).body) + @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 + @count = @messages.size + end + end + end +end -- 2.11.4.GIT