From e94a80e55108b0bf35caf9f6aba5dbd768e15f3a Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Fri, 15 Aug 2014 00:40:31 +0400 Subject: [PATCH] MyMail icon added --- mymail_unread.py | 32 ++++++++++++++++++++++++++++++++ rc.lua | 23 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 mymail_unread.py diff --git a/mymail_unread.py b/mymail_unread.py new file mode 100755 index 0000000..dda0d43 --- /dev/null +++ b/mymail_unread.py @@ -0,0 +1,32 @@ +#!/usr/bin/python + +# Create credentials.py with mymail_login, mymail_password, mymail_server, mymail_port variables + +import imaplib,ssl + +# http://stackoverflow.com/questions/9713055/certificate-authority-for-imaplib-and-poplib-python +import imaplib,ssl +def IMAP_starttls(self, keyfile=None, certfile=None,cert_reqs=ssl.CERT_NONE,ca_certs=None): + if not 'STARTTLS' in self.capabilities: + raise self.error("STARTTLS extension not supported by server.") + (resp, reply) = self._simple_command("STARTTLS") + self.sock = ssl.wrap_socket(self.sock, keyfile, certfile,cert_reqs=cert_reqs,ca_certs=ca_certs) + self.file = self.sock.makefile('rb') + +imaplib.IMAP4.__dict__['starttls']=IMAP_starttls +imaplib.Commands['STARTTLS']=('NONAUTH',) + +# read credentials +from credentials import mymail_server,mymail_port,mymail_login,mymail_password + +M=imaplib.IMAP4(mymail_server, mymail_port) +M.starttls() +M.login(mymail_login,mymail_password) + +status, counts = M.status("Inbox","(MESSAGES UNSEEN)") + +unread = counts[0].split()[4][:-1] + +print(int(unread)) + +M.logout() diff --git a/rc.lua b/rc.lua index d00b6c4..4f55103 100644 --- a/rc.lua +++ b/rc.lua @@ -222,6 +222,26 @@ mytasklist.buttons = awful.util.table.join( if client.focus then client.focus:raise() end end)) +-- My MyMail updater widget +function mymail_count() + os.execute("~/.config/awesome/mymail_unread.py > ~/.mymail_count") + local f = io.open(os.getenv("HOME") .. "/.mymail_count") + local l = nil + if f ~= nil then + l = f:read() + else + l = "?" + end + f:close() + return l +end +mymail_mail = wibox.widget.textbox( mymail_count() ) +mymail_mail.timer = timer{timeout=60} +mymail_mail.timer:connect_signal("timeout", function () mymail_mail:set_text ( mymail_count() ) end) +mymail_mail.timer:start() +mymailicon = wibox.widget.imagebox() +mymailicon:set_image(beautiful.widget_mymail) + -- My GMail updater widget function gmail_count() os.execute("~/.config/awesome/gmail_unread.py > ~/.gmail_count") @@ -294,6 +314,9 @@ for s = 1, screen.count() do right_layout:add(spacer) right_layout:add(mymailicon) + right_layout:add(mymail_mail) + myslash = wibox.widget.textbox("+") + right_layout:add(myslash) right_layout:add(gmail_mail) right_layout:add(spacer)