[gmail] Switch to awful.spawn.easy_async
This commit is contained in:
parent
6f002577b9
commit
383d91399f
|
@ -16,7 +16,7 @@ Added:
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
|
|
||||||
- [volume] Deprecate `io.popen`
|
- [volume,gmail] Deprecate `io.popen`
|
||||||
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
||||||
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
||||||
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)
|
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)
|
||||||
|
|
|
@ -6,12 +6,10 @@
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local type = type
|
local type = type
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local io = { popen = io.popen }
|
local string = { match = string.match }
|
||||||
local setmetatable = setmetatable
|
|
||||||
local helpers = require("vicious.helpers")
|
local helpers = require("vicious.helpers")
|
||||||
local string = {
|
local spawn = require("vicious.spawn")
|
||||||
match = string.match
|
|
||||||
}
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,59 +17,33 @@ local string = {
|
||||||
-- vicious.widgets.gmail
|
-- vicious.widgets.gmail
|
||||||
local gmail_all = {}
|
local gmail_all = {}
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Variable definitions
|
|
||||||
local rss = {
|
|
||||||
inbox = "https://mail.google.com/mail/feed/atom",
|
|
||||||
unread = "https://mail.google.com/mail/feed/atom/unread",
|
|
||||||
--labelname = "https://mail.google.com/mail/feed/atom/labelname",
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Default is just Inbox
|
|
||||||
local feed = rss.inbox
|
|
||||||
local mail = {
|
|
||||||
["{count}"] = 0,
|
|
||||||
["{subject}"] = "N/A"
|
|
||||||
}
|
|
||||||
-- }}}
|
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Gmail widget type
|
-- {{{ Gmail widget type
|
||||||
local function worker(format, warg)
|
local function parse(warg, stdout, stderr, exitreason, exitcode)
|
||||||
-- Get info from the Gmail atom feed
|
local count = -- Count comes before messages and matches at least 0
|
||||||
local f = io.popen("curl --connect-timeout 1 -m 3 -fsn " .. helpers.shellquote(feed))
|
tonumber(string.match(stdout, "<fullcount>([%d]+)</fullcount>")) or 0
|
||||||
|
|
||||||
-- Could be huge don't read it all at once, info we are after is at the top
|
|
||||||
local xml = f:read(2000)
|
|
||||||
|
|
||||||
if xml == nil then
|
|
||||||
return mail
|
|
||||||
end
|
|
||||||
|
|
||||||
mail["{count}"] = -- Count comes before messages and matches at least 0
|
|
||||||
tonumber(string.match(xml, "<fullcount>([%d]+)</fullcount>")) or mail["{count}"]
|
|
||||||
|
|
||||||
-- Find subject tag
|
-- Find subject tag
|
||||||
local title = string.match(xml, "<entry>.-<title>(.-)</title>")
|
local title = string.match(stdout, "<entry>.-<title>(.-)</title>") or "N/A"
|
||||||
|
|
||||||
if title ~= nil then
|
|
||||||
-- Check if we should scroll, or maybe truncate
|
-- Check if we should scroll, or maybe truncate
|
||||||
if warg then
|
if type(warg) == "number" then
|
||||||
if type(warg) == "table" then
|
|
||||||
title = helpers.scroll(title, warg[1], warg[2])
|
|
||||||
else
|
|
||||||
title = helpers.truncate(title, warg)
|
title = helpers.truncate(title, warg)
|
||||||
end
|
elseif type(warg) == "table" then
|
||||||
|
title = helpers.scroll(title, warg[1], warg[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Spam sanitize the subject and store
|
return { ["{count}"] = count, ["{subject}"] = title }
|
||||||
mail["{subject}"] = title
|
end
|
||||||
end
|
|
||||||
|
|
||||||
f:close()
|
function gmail_all.async(format, warg, callback)
|
||||||
|
-- Get info from the Gmail atom feed using curl --netrc.
|
||||||
return mail
|
-- 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)
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
return setmetatable(gmail_all, { __call = function(_, ...) return worker(...) end })
|
return helpers.setasyncall(gmail_all)
|
||||||
|
|
Loading…
Reference in New Issue