2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
2010-01-02 21:21:54 +01:00
|
|
|
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
2009-09-08 22:46:59 +02:00
|
|
|
|
|
|
|
-- {{{ Grab environment
|
2009-11-03 01:34:48 +01:00
|
|
|
local type = type
|
2009-10-26 20:32:48 +01:00
|
|
|
local tonumber = tonumber
|
2019-05-16 16:50:42 +02:00
|
|
|
local string = { match = string.match }
|
|
|
|
|
2009-09-08 22:46:59 +02:00
|
|
|
local helpers = require("vicious.helpers")
|
2019-05-16 16:50:42 +02:00
|
|
|
local spawn = require("vicious.spawn")
|
2009-09-08 22:46:59 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
2009-10-01 12:08:39 +02:00
|
|
|
-- Gmail: provides count of new and subject of last e-mail on Gmail
|
2012-06-15 18:07:05 +02:00
|
|
|
-- vicious.widgets.gmail
|
2017-01-25 17:51:41 +01:00
|
|
|
local gmail_all = {}
|
2009-09-08 22:46:59 +02:00
|
|
|
|
|
|
|
-- {{{ Gmail widget type
|
2019-05-16 16:50:42 +02:00
|
|
|
local function parse(warg, stdout, stderr, exitreason, exitcode)
|
|
|
|
local count = -- Count comes before messages and matches at least 0
|
|
|
|
tonumber(string.match(stdout, "<fullcount>([%d]+)</fullcount>")) or 0
|
2014-11-08 18:14:03 +01:00
|
|
|
|
|
|
|
-- Find subject tag
|
2019-05-16 16:50:42 +02:00
|
|
|
local title = string.match(stdout, "<entry>.-<title>(.-)</title>") or "N/A"
|
2014-11-08 18:14:03 +01:00
|
|
|
|
2019-05-16 16:50:42 +02:00
|
|
|
-- Check if we should scroll, or maybe truncate
|
|
|
|
if type(warg) == "number" then
|
|
|
|
title = helpers.truncate(title, warg)
|
|
|
|
elseif type(warg) == "table" then
|
|
|
|
title = helpers.scroll(title, warg[1], warg[2])
|
2009-09-08 22:46:59 +02:00
|
|
|
end
|
2014-11-08 18:14:03 +01:00
|
|
|
|
2019-05-16 16:50:42 +02:00
|
|
|
return { ["{count}"] = count, ["{subject}"] = title }
|
|
|
|
end
|
2009-09-08 22:46:59 +02:00
|
|
|
|
2019-05-16 16:50:42 +02:00
|
|
|
function gmail_all.async(format, warg, callback)
|
|
|
|
-- Get info from the Gmail atom feed using curl --netrc.
|
|
|
|
-- With username 'user' and password 'pass'
|
|
|
|
-- $HOME/.netrc should look similar to:
|
|
|
|
-- machine mail.google.com login user password pass
|
|
|
|
-- BE AWARE THAT MAKING THESE SETTINGS IS A SECURITY RISK!
|
|
|
|
spawn.easy_async("curl -fsn https://mail.google.com/mail/feed/atom",
|
|
|
|
function (...) callback(parse(warg, ...)) end)
|
2009-09-08 22:46:59 +02:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
2019-05-16 16:50:42 +02:00
|
|
|
return helpers.setasyncall(gmail_all)
|