2019-09-05 07:41:38 +02:00
|
|
|
-- new e-mails count and last e-mail subject on Gmail
|
|
|
|
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
|
|
|
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
|
|
|
-- Copyright (C) 2017 starenka <starenka0@gmail.com>
|
|
|
|
-- Copyright (C) 2018-2019 Nguyễn Gia Phong <vn.mcsinyx@gmail.com>
|
|
|
|
--
|
|
|
|
-- This file is part of Vicious.
|
|
|
|
--
|
|
|
|
-- Vicious is free software: you can redistribute it and/or modify
|
|
|
|
-- it under the terms of the GNU General Public License as
|
|
|
|
-- published by the Free Software Foundation, either version 2 of the
|
|
|
|
-- License, or (at your option) any later version.
|
|
|
|
--
|
|
|
|
-- Vicious is distributed in the hope that it will be useful,
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
-- GNU General Public License for more details.
|
|
|
|
--
|
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
|
-- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
|
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)
|