Fix dotfiles structure
This commit is contained in:
36
.config/awesome/awesome-wm-widgets/email-widget/README.md
Executable file
36
.config/awesome/awesome-wm-widgets/email-widget/README.md
Executable file
@@ -0,0 +1,36 @@
|
||||
# Email widget
|
||||
|
||||
This widget consists of an icon with counter which shows number of unread emails: 
|
||||
and a popup message which appears when mouse hovers over an icon: 
|
||||
|
||||
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
||||
|
||||
## Installation
|
||||
|
||||
To install it put **email.lua** and **email-widget** folder under **~/.config/awesome**. Then
|
||||
|
||||
- in **email.lua** change path to python scripts;
|
||||
- in python scripts add your credentials (note that password should be encrypted using pgp for example);
|
||||
- add widget to awesome:
|
||||
|
||||
```lua
|
||||
local email_widget, email_icon = require("email")
|
||||
|
||||
...
|
||||
s.mytasklist, -- Middle widget
|
||||
{ -- Right widgets
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
...
|
||||
email_icon,
|
||||
email_widget,
|
||||
...
|
||||
```
|
||||
|
||||
## How it works
|
||||
|
||||
This widget uses the output of two python scripts, first is called every 20 seconds - it returns number of unread emails and second is called when mouse hovers over an icon and displays content of those emails. For both of them you'll need to provide your credentials and imap server. For testing, they can simply be called from console:
|
||||
|
||||
``` bash
|
||||
python ~/.config/awesome/email/count_unread_emails.py
|
||||
python ~/.config/awesome/email/read_emails.py
|
||||
```
|
||||
16
.config/awesome/awesome-wm-widgets/email-widget/count_unread_emails.py
Executable file
16
.config/awesome/awesome-wm-widgets/email-widget/count_unread_emails.py
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import imaplib
|
||||
import re
|
||||
|
||||
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 = re.search(r'UNSEEN\s(\d+)', counts[0].decode('utf-8')).group(1)
|
||||
else:
|
||||
unread = "N/A"
|
||||
|
||||
print(unread)
|
||||
BIN
.config/awesome/awesome-wm-widgets/email-widget/em-wid-1.png
Executable file
BIN
.config/awesome/awesome-wm-widgets/email-widget/em-wid-1.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
BIN
.config/awesome/awesome-wm-widgets/email-widget/em-wid-2.png
Executable file
BIN
.config/awesome/awesome-wm-widgets/email-widget/em-wid-2.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
44
.config/awesome/awesome-wm-widgets/email-widget/email.lua
Executable file
44
.config/awesome/awesome-wm-widgets/email-widget/email.lua
Executable file
@@ -0,0 +1,44 @@
|
||||
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/actions/22/"
|
||||
|
||||
local email_widget = wibox.widget.textbox()
|
||||
email_widget:set_font('Play 9')
|
||||
|
||||
local email_icon = wibox.widget.imagebox()
|
||||
email_icon:set_image(path_to_icons .. "/mail-mark-new.png")
|
||||
|
||||
watch(
|
||||
"python /home/<username>/.config/awesome/email-widget/count_unread_emails.py", 20,
|
||||
function(_, stdout)
|
||||
local unread_emails_num = tonumber(stdout) or 0
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
local function show_emails()
|
||||
awful.spawn.easy_async([[bash -c 'python /home/<username>/.config/awesome/email-widget/read_unread_emails.py']],
|
||||
function(stdout)
|
||||
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)
|
||||
|
||||
return email_widget, email_icon
|
||||
44
.config/awesome/awesome-wm-widgets/email-widget/read_unread_emails.py
Executable file
44
.config/awesome/awesome-wm-widgets/email-widget/read_unread_emails.py
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/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_bytes(data[0][1])
|
||||
for header in [ 'From', 'Subject', 'Date' ]:
|
||||
hdr = email.header.make_header(email.header.decode_header(msg[header]))
|
||||
if header == 'Date':
|
||||
date_tuple = email.utils.parsedate_tz(str(hdr))
|
||||
if date_tuple:
|
||||
local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
|
||||
print("{}: {}".format(header, local_date.strftime("%a, %d %b %Y %H:%M:%S")))
|
||||
else:
|
||||
print('{}: {}'.format(header, hdr))
|
||||
# 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()
|
||||
Reference in New Issue
Block a user