summaryrefslogtreecommitdiff
path: root/email-widget
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@gmail.com>2017-01-30 21:38:50 -0500
committerstreetturtle <streetturtle@gmail.com>2017-01-30 21:40:01 -0500
commitc4826fd21340d34e3592b0c8ca24fc068e52c6ef (patch)
treedbbc8fd3df693cfc57cbc1ff5246164f8fc41c01 /email-widget
parenta079c79ab81a4bc2f7cf7971db6373fefe1e6110 (diff)
new widgets added
Diffstat (limited to 'email-widget')
-rw-r--r--email-widget/count_unread_emails.py16
-rw-r--r--email-widget/email.lua42
-rw-r--r--email-widget/read_unread_emails.py42
3 files changed, 100 insertions, 0 deletions
diff --git a/email-widget/count_unread_emails.py b/email-widget/count_unread_emails.py
new file mode 100644
index 0000000..f4d2b86
--- /dev/null
+++ b/email-widget/count_unread_emails.py
@@ -0,0 +1,16 @@
+#!/usr/bin/python
+
+import imaplib
+import email
+
+M=imaplib.IMAP4_SSL("mail.teenagemutantninjaturtles.com", 993)
+M.login("mickey@tmnt.com","cowabunga")
+
+status, counts = M.status("INBOX","(MESSAGES UNSEEN)")
+
+if status == "OK":
+ unread = counts[0].split()[4][:-1]
+else:
+ unread = "N/A"
+
+print(unread) \ No newline at end of file
diff --git a/email-widget/email.lua b/email-widget/email.lua
new file mode 100644
index 0000000..22a7b6d
--- /dev/null
+++ b/email-widget/email.lua
@@ -0,0 +1,42 @@
+local wibox = require("wibox")
+local awful = require("awful")
+local naughty = require("naughty")
+local watch = require("awful.widget.watch")
+
+local path_to_icons = "/usr/share/icons/Arc-Icons/actions/22/"
+
+email_widget = wibox.widget.textbox()
+email_widget:set_font('Play 9')
+
+email_icon = wibox.widget.imagebox()
+email_icon:set_image(path_to_icons .. "/mail-mark-new.png")
+
+watch(
+ "python /home/<username>/.config/awesome/email/count_unread_emails.py", 20,
+ function(widget, stdout, stderr, exitreason, exitcode)
+ local unread_emails_num = tonumber(stdout)
+ if (unread_emails_num > 0) then
+ email_icon:set_image(path_to_icons .. "/mail-mark-unread.png")
+ email_widget:set_text(stdout)
+ elseif (unread_emails_num == 0) then
+ email_icon:set_image(path_to_icons .. "/mail-message-new.png")
+ email_widget:set_text("")
+ end
+ end
+)
+
+
+function show_emails()
+ awful.spawn.easy_async([[bash -c 'python /home/<username>/.config/awesome/email/read_unread_emails.py']],
+ function(stdout, stderr, reason, exit_code)
+ naughty.notify{
+ text = stdout,
+ title = "Unread Emails",
+ timeout = 5, hover_timeout = 0.5,
+ width = 400,
+ }
+ end
+ )
+end
+
+email_icon:connect_signal("mouse::enter", function() show_emails() end) \ No newline at end of file
diff --git a/email-widget/read_unread_emails.py b/email-widget/read_unread_emails.py
new file mode 100644
index 0000000..343fe66
--- /dev/null
+++ b/email-widget/read_unread_emails.py
@@ -0,0 +1,42 @@
+#!/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, '(BODY.PEEK[])')
+ 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")
+ # 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()
+
+
+M=imaplib.IMAP4_SSL("mail.teenagemutantninjaturtles.com", 993)
+M.login("mickey@tmnt.com","cowabunga")
+
+rv, data = M.select("INBOX")
+if rv == 'OK':
+ process_mailbox(M)
+M.close()
+M.logout() \ No newline at end of file