From 161607e5179fe3f8151d56752cf2d46963ff1aa3 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Tue, 8 Sep 2009 22:46:59 +0200 Subject: 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. --- README | 21 ++++++++++++++++++--- gmail.lua | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 1 + 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 gmail.lua 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. +---------------------------------------------------------- + +-- {{{ 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("([%d]+)") or mail["{count}"] + + -- Find subject tags + local title = line:match("(.*)") + -- 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") -- cgit v1.2.3