eMail widget
This commit is contained in:
parent
99d8fdc9b3
commit
1c457ea987
|
@ -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()
|
|
@ -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()
|
||||
|
|
@ -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)
|
Binary file not shown.
After Width: | Height: | Size: 7.3 KiB |
Loading…
Reference in New Issue