Added links to check mails

This commit is contained in:
Thomas Forgione 2018-12-02 12:36:50 +01:00
parent 6a12e2bb9d
commit 80a590df28
No known key found for this signature in database
GPG Key ID: 63D3E1A00D54FD76
3 changed files with 46 additions and 12 deletions

View File

@ -16,6 +16,24 @@ email_icon:set_image(path_to_icons .. "/mail-mark-new.png")
local previous_value = 0
function split(str, delimiter)
if str == nil then
return {}
end
local ret = {''}
count = 1
for i = 1, string.len(str) do
local c = str:sub(i,i)
if c == delimiter then
count = count + 1
ret[count] = ''
else
ret[count] = ret[count] .. c
end
end
return ret
end
watch(
"bash -c " .. home .. "/.config/awesome/awesome-wm-widgets/email-widget/count_unread_emails.py", 60,
function(widget, stdout, stderr, exitreason, exitcode)
@ -39,11 +57,26 @@ watch(
function show_emails(timeout)
awful.spawn.easy_async_with_shell(home .. "/.config/awesome/awesome-wm-widgets/email-widget/read_unread_emails.py",
function(stdout, stderr, reason, exit_code)
s = split(stderr, '\n')
local actions = {}
if stderr ~= '' then
for index, line in pairs(s) do
if index > 1 then
actions["Check email from account " .. tostring(index - 1)] = function ()
awful.spawn.easy_async("firefox " .. s[index - 1])
end
end
end
end
naughty.notify{
text = stdout,
title = "Unread Emails",
timeout = timeout,
width = 400,
actions = actions,
}
end
)

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3
import sys
import imaplib
import email.header
import datetime
@ -13,13 +14,18 @@ def process_mailbox(mailbox, to = None):
rv, data = mailbox.search(None, "(UNSEEN)")
if rv != 'OK':
print("No messages found!")
return
return False
for num in data[0].split():
split = data[0].split()
if len(split) == 0:
return False
for num in split:
rv, data = mailbox.fetch(num, '(BODY.PEEK[])')
if rv != 'OK':
print("ERROR getting message", num)
return
return False
msg = email.message_from_string(data[0][1].decode())
@ -35,14 +41,8 @@ def process_mailbox(mailbox, to = None):
local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
print("Local Date:", local_date.strftime("%a, %d %b %Y %H:%M:%S"))
print()
# with code below you can process text of email
# if msg.is_multipart():
# for payload in msg.get_payload():
# if payload.get_content_maintype() == 'text':
# print(payload.get_payload())
# else:
# print(msg.get_payload())
return True
try:
import credentials
@ -58,7 +58,8 @@ for account in credentials.accounts:
rv, data = mailbox.select("INBOX")
if rv == 'OK':
process_mailbox(mailbox, account.email)
if process_mailbox(mailbox, account.email):
print(account.link, file=sys.stderr)
mailbox.close()
mailbox.logout()

2
rc.lua
View File

@ -497,7 +497,7 @@ globalkeys = awful.util.table.join(
end, {description="Disable the second screen", group="screen control"}),
awful.key({modkey}, "z", function()
awful.spawn.easy_async("firefox https://hangouts.google.com https://messenger.com https://web.telegram.org https://gitter.im https://vortex-n7.slack.com/ https://nextcloud.tforgione.fr/apps/calendar", function() end)
awful.spawn.easy_async(option.brower .. " https://hangouts.google.com https://messenger.com https://web.telegram.org https://gitter.im https://vortex-n7.slack.com/ https://nextcloud.tforgione.fr/apps/calendar", function() end)
naughty.notify({title = "Starting social media"})
end, {description="Open social media", group="shortcuts"}),