From 80a590df282462bbe37e169741f36fcbb626d256 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Sun, 2 Dec 2018 12:36:50 +0100 Subject: [PATCH] Added links to check mails --- awesome-wm-widgets/email-widget/email.lua | 33 +++++++++++++++++++ .../email-widget/read_unread_emails.py | 23 ++++++------- rc.lua | 2 +- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/awesome-wm-widgets/email-widget/email.lua b/awesome-wm-widgets/email-widget/email.lua index 2071158..fc8710c 100644 --- a/awesome-wm-widgets/email-widget/email.lua +++ b/awesome-wm-widgets/email-widget/email.lua @@ -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 ) diff --git a/awesome-wm-widgets/email-widget/read_unread_emails.py b/awesome-wm-widgets/email-widget/read_unread_emails.py index acf6a9a..b91ebde 100755 --- a/awesome-wm-widgets/email-widget/read_unread_emails.py +++ b/awesome-wm-widgets/email-widget/read_unread_emails.py @@ -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() diff --git a/rc.lua b/rc.lua index 060b7a8..2be5560 100644 --- a/rc.lua +++ b/rc.lua @@ -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"}),