diff options
author | Pavel Makhov <pavel.makhov@cern.ch> | 2015-08-29 09:18:20 +0200 |
---|---|---|
committer | Pavel Makhov <pavel.makhov@cern.ch> | 2015-08-29 09:18:20 +0200 |
commit | 1c457ea987c06db8e3d6965906ed3d98cf68dabc (patch) | |
tree | b5ac0105d9dfd09cd26a7c6f6979bbbb71273696 /EmailWidget | |
parent | 99d8fdc9b3627d526e500be2fac972b4c5069220 (diff) |
eMail widget
Diffstat (limited to 'EmailWidget')
-rw-r--r-- | EmailWidget/email.lua | 40 | ||||
-rw-r--r-- | EmailWidget/getUnreadEmails.py | 39 | ||||
-rw-r--r-- | EmailWidget/getUnreadEmailsNum.py | 16 | ||||
-rw-r--r-- | EmailWidget/mail.png | bin | 0 -> 7465 bytes |
4 files changed, 95 insertions, 0 deletions
diff --git a/EmailWidget/email.lua b/EmailWidget/email.lua new file mode 100644 index 0000000..3f486cf --- /dev/null +++ b/EmailWidget/email.lua @@ -0,0 +1,40 @@ +local wibox = require("wibox") +local awful = require("awful") +local naughty = require("naughty") + +function showEmailWidgetPopup() + local save_offset = offset + local popuptext = "test" + naughty.notify({ + title = "Unread emails", + text = awful.util.pread("python /home/username/.config/awesome/getUnreadEmails.py"), + timeout = 10, + width = 300, + fg = "#ffffff", + bg = "#333333aa", + }) +end + +-- Icon which shows unread emails when hover +emailIcon = wibox.widget.imagebox() +emailIcon:set_image("/home/username/.config/awesome/mail.png") +emailIcon:connect_signal("mouse::enter", function() showEmailWidgetPopup() end) + +dbus.request_name("session", "ru.console.df") +dbus.add_match("session", "interface='ru.console.df', member='fsValue' " ) +dbus.connect_signal("ru.console.df", + function (...) + local data = {...} + local dbustext = data[2] + emailCount:set_text(dbustext) + end) + +-- Counter which shows number of unread emails +emailCount = wibox.widget.textbox() + +emailCountTimer = timer ({timeout = 5}) +emailCountTimer:connect_signal ("timeout", + function () + awful.util.spawn_with_shell("dbus-send --session --dest=org.naquadah.awesome.awful /ru/console/df ru.console.df.fsValue string:$(python /home/username/.config/awesome/getUnreadEmailsNum.py)" ) + end) +emailCountTimer:start() diff --git a/EmailWidget/getUnreadEmails.py b/EmailWidget/getUnreadEmails.py new file mode 100644 index 0000000..8b4714a --- /dev/null +++ b/EmailWidget/getUnreadEmails.py @@ -0,0 +1,39 @@ +#!/usr/bin/python + +import imaplib +import email +import datetime + +def process_mailbox(M): + rv, data = M.search(None, "UNSEEN") + if rv != 'OK': + print "No messages found!" + return + + for num in data[0].split(): + # rv, data = M.fetch(num, '(RFC822)') # mark us read + rv, data = M.fetch(num, '(BODY.PEEK[])') # don't mark us read + if rv != 'OK': + print "ERROR getting message", num + return + + msg = email.message_from_string(data[0][1]) + print 'From:', msg['From'] + print 'Subject: %s' % (msg['Subject']) + date_tuple = email.utils.parsedate_tz(msg['Date']) + if date_tuple: + 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 + +M=imaplib.IMAP4_SSL("imap.whatever.com", 993) +M.login("username","password") + +rv, data = M.select("INBOX") +if rv == 'OK': + process_mailbox(M) + M.close() + +M.logout() + diff --git a/EmailWidget/getUnreadEmailsNum.py b/EmailWidget/getUnreadEmailsNum.py new file mode 100644 index 0000000..5599f2e --- /dev/null +++ b/EmailWidget/getUnreadEmailsNum.py @@ -0,0 +1,16 @@ +#!/usr/bin/python + +import imaplib +import email + +M=imaplib.IMAP4_SSL("imap.whatever.com", 993) +M.login("username","password") + +status, counts = M.status("INBOX","(MESSAGES UNSEEN)") + +if status == "OK": + unread = int(counts[0].split()[4][:-1]) +else: + unread = "N/A" + +print(unread) diff --git a/EmailWidget/mail.png b/EmailWidget/mail.png Binary files differnew file mode 100644 index 0000000..1df6fae --- /dev/null +++ b/EmailWidget/mail.png |