diff --git a/awesome-wm-widgets/email-widget/count_unread_emails.py b/awesome-wm-widgets/email-widget/count_unread_emails.py index dc3328f..cdd78e7 100755 --- a/awesome-wm-widgets/email-widget/count_unread_emails.py +++ b/awesome-wm-widgets/email-widget/count_unread_emails.py @@ -2,6 +2,7 @@ import imaplib import email +import sys try: import credentials diff --git a/awesome-wm-widgets/email-widget/email.lua b/awesome-wm-widgets/email-widget/email.lua index 7f76151..672932c 100644 --- a/awesome-wm-widgets/email-widget/email.lua +++ b/awesome-wm-widgets/email-widget/email.lua @@ -16,6 +16,36 @@ email_icon:set_image(path_to_icons .. "/mail-mark-new.png") local previous_value = 0 +local password1 = '' +local password2 = '' +local password3 = '' + +awful.spawn.easy_async_with_shell('pass web/mail.ovh.com; pass web/webmail.gandi.net; pass web/inp-toulouse.fr;', function(stdout) + s = split(stdout, '\n') + password1 = s[1] + password2 = s[2] + password3 = s[3] + + watch( + "bash -c '" .. home .. "/.config/awesome/awesome-wm-widgets/email-widget/count_unread_emails.py " .. password1 .. " " .. password2 .. " " .. password3 .. "'", 60, + function(widget, stdout, stderr, exitreason, exitcode) + local unread_emails_num = tonumber(stdout) or 0 + + if previous_value < unread_emails_num then + previous_value = unread_emails_num + show_emails(10) + end + + email_widget:set_text(stdout) + if (unread_emails_num > 0) then + email_icon:set_image(path_to_icons .. "/mail-mark-unread.png") + elseif (unread_emails_num == 0) then + email_icon:set_image(path_to_icons .. "/mail-message-new.png") + end + end + ) +end) + function split(str, delimiter) if str == nil then return {} @@ -34,28 +64,8 @@ function split(str, delimiter) 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) - local unread_emails_num = tonumber(stdout) or 0 - - if previous_value < unread_emails_num then - previous_value = unread_emails_num - show_emails(10) - end - - email_widget:set_text(stdout) - if (unread_emails_num > 0) then - email_icon:set_image(path_to_icons .. "/mail-mark-unread.png") - elseif (unread_emails_num == 0) then - email_icon:set_image(path_to_icons .. "/mail-message-new.png") - end - end -) - - function show_emails(timeout) - awful.spawn.easy_async_with_shell(home .. "/.config/awesome/awesome-wm-widgets/email-widget/read_unread_emails.py", + awful.spawn.easy_async_with_shell(home .. "/.config/awesome/awesome-wm-widgets/email-widget/read_unread_emails.py " .. password1 .. " " .. password2 .. " " .. password3, function(stdout, stderr, reason, exit_code) s = split(stderr, '\n')