aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-09-08 22:46:59 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-09-08 22:46:59 +0200
commit161607e5179fe3f8151d56752cf2d46963ff1aa3 (patch)
treea3d7063932fe2a5f2c094b2d8f7beb32b8f5c874
parente5c980e58a3b6ca7f369ac87ab8f1fa897bb504d (diff)
downloadvicious-legacy-161607e5179fe3f8151d56752cf2d46963ff1aa3.tar.xz
Gmail widget included
Widget returns the count of new and subject of last e-mail in a Gmail inbox. Use ${count} and ${subject} in the format string to retrieve the values. Widget takes a table with login information as an argument. I don't like how gmail widgets handle sensitive data but I gave in seeing how popular they are. Better storing and handling of login information would be in order but this isn't Python and I'm out of ideas. For now use it on your own responsability, I would suggest to set login info directly in the widget and file as read-only by user.
-rw-r--r--README21
-rw-r--r--gmail.lua55
-rw-r--r--init.lua1
3 files changed, 74 insertions, 3 deletions
diff --git a/README b/README
index a3d3805..7b94998 100644
--- a/README
+++ b/README
@@ -145,6 +145,10 @@ vicious.widgets.mdir
structure
- takes the full path to the Maildir structure as an argument
+vicious.widgets.gmail
+ - provides count of new and subject of last e-mail in a Gmail inbox
+ - takes a table with Gmail login information as an argument
+
vicious.widgets.entropy
- provides available system entropy
- takes the poolsize as an argument, or fallbacks to Linux 2.6
@@ -153,7 +157,7 @@ vicious.widgets.entropy
vicious.widgets.org
- provides agenda statistics for Emacs org-mode
- takes a table with full paths to agenda files, that will be
- included, as an argument
+ parsed, as an argument
vicious.widgets.pacman
- provides number of pending updates on Arch Linux
@@ -187,8 +191,12 @@ Format functions
----------------
You can use a function instead of a string as the format parameter, so
you are able to check the value returned by the widget type and change
-it. You can change the color of a widget, i.e. on low battery, or hide
-widgets when they return a certain value, or...
+it. You can change the color of the battery widget when it goes below
+a certain point, or hide widgets when they return a certain value,
+or...
+
+ - do not confuse this with just coloring the widget, in those cases
+ standard markup can be inserted into the format string
The format function will get the widget as its first argument, and a
table with the values otherwise inserted into the format string as its
@@ -264,6 +272,13 @@ Mbox widget
- executed every 240 seconds, provides full path to the mbox as an
argument
+Gmail widget
+ gmailwidget = widget({ type = 'textbox', name = 'gmailwidget' })
+ vicious.register(gmailwidget, vicious.widgets.gmail, 'Mail: ${count}', 600, {'user', 'pass'})
+
+ - executed every 10 minutes, provides a table with login information
+ as an argument, prepends "Mail: " to the returned value
+
All other widgets are used in the same manner, read each widget you
are interested in to see what data it returns. You can also use
diff --git a/gmail.lua b/gmail.lua
new file mode 100644
index 0000000..98fb40d
--- /dev/null
+++ b/gmail.lua
@@ -0,0 +1,55 @@
+----------------------------------------------------------
+-- Licensed under the GNU General Public License version 2
+-- * Copyright (C) 2009 Adrian C. <anrxc_sysphere_org>
+----------------------------------------------------------
+
+-- {{{ Grab environment
+local io = { popen = io.popen }
+local setmetatable = setmetatable
+local helpers = require("vicious.helpers")
+-- }}}
+
+
+-- Gmail: provides count of new and subject of last e-mail in a Gmail inbox
+module("vicious.gmail")
+
+
+-- {{{ Gmail widget type
+local function worker(format, login)
+ -- Initialise tables
+ local mail = {
+ ["{count}"] = "0",
+ ["{subject}"] = "N/A"
+ }
+
+ -- Todo: find a safer way to do this
+ local auth = login[1] .. ":" .. login[2]
+
+ -- Get info from the Gmail atom feed
+ local f = io.popen("curl --max-time 3 -fsu "..auth.." https://mail.google.com/mail/feed/atom")
+
+ -- Could be huge don't read it all at once, info we are after is at the top
+ for line in f:lines() do
+ mail["{count}"] = line:match("<fullcount>([%d]+)</fullcount>") or mail["{count}"]
+
+ -- Find subject tags
+ local title = line:match("<title>(.*)</title>")
+ -- If the subject changed then break out of the loop
+ if title ~= nil and -- Ignore the feed title
+ title ~= "Gmail - Inbox for "..login[1].."@gmail.com" then
+ -- Spam sanitize the subject
+ title = helpers.escape(title)
+ -- Don't abuse the wibox, truncate, then store
+ mail["{subject}"] = helpers.truncate(title, 22)
+ -- By this point we have the count, it comes before
+ -- messages and always matches, at least 0
+ break
+ end
+ end
+ f:close()
+
+ return mail
+end
+-- }}}
+
+setmetatable(_M, { __call = function(_, ...) return worker(...) end })
diff --git a/init.lua b/init.lua
index 807df4a..bf22918 100644
--- a/init.lua
+++ b/init.lua
@@ -49,6 +49,7 @@ require("vicious.wifi")
require("vicious.mbox")
require("vicious.mboxc")
require("vicious.mdir")
+require("vicious.gmail")
require("vicious.entropy")
require("vicious.org")
require("vicious.pacman")