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.
This commit is contained in:
Adrian C. (anrxc) 2009-09-08 22:46:59 +02:00
parent e5c980e58a
commit 161607e517
3 changed files with 74 additions and 3 deletions

21
README
View File

@ -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

55
gmail.lua Normal file
View File

@ -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 })

View File

@ -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")