add script for offlineimap notifications
This commit is contained in:
parent
20b9578daf
commit
1b53be92e0
@ -1,7 +1,4 @@
|
|||||||
# simplify folder change
|
# simplify folder change
|
||||||
# cronjob for offlineimap
|
|
||||||
# also update when the cursor is not moving
|
|
||||||
# dunst notifications
|
|
||||||
# notmuch for searching
|
# notmuch for searching
|
||||||
|
|
||||||
# SMTP setting (smtp_pass is set in sourced file)
|
# SMTP setting (smtp_pass is set in sourced file)
|
||||||
|
41
offlineimap_notify.py
Normal file
41
offlineimap_notify.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import pynotify
|
||||||
|
import pyinotify
|
||||||
|
from os.path import expanduser, join
|
||||||
|
from mailbox import MaildirMessage
|
||||||
|
|
||||||
|
maildir = expanduser('~/Mail')
|
||||||
|
pynotify.init('offlineimap_notify')
|
||||||
|
|
||||||
|
with open(expanduser('~/.mutt/mailboxes')) as f:
|
||||||
|
mailboxes = f.read()
|
||||||
|
|
||||||
|
boxes = []
|
||||||
|
for m in mailboxes.strip('\n').split(" "):
|
||||||
|
if not m == 'mailboxes':
|
||||||
|
boxes.append(m.replace('"', '').replace('+', ''))
|
||||||
|
|
||||||
|
|
||||||
|
def new_mail(event):
|
||||||
|
with open(event.pathname, 'r') as f:
|
||||||
|
mail = MaildirMessage(message=f)
|
||||||
|
print(mail)
|
||||||
|
efrom = 'From: ' + mail['From']
|
||||||
|
print(efrom)
|
||||||
|
esubject = 'Subject: ' + mail['Subject']
|
||||||
|
print(esubject)
|
||||||
|
n = pynotify.Notification("New mail in " + '/'.join(
|
||||||
|
event.path.split('/')[-3:-1]), efrom + "\n" + esubject)
|
||||||
|
n.set_timeout(8000)
|
||||||
|
n.show()
|
||||||
|
|
||||||
|
|
||||||
|
watch_manager = pyinotify.WatchManager()
|
||||||
|
file_notifier = pyinotify.Notifier(watch_manager, new_mail)
|
||||||
|
|
||||||
|
for box in boxes:
|
||||||
|
watch_manager.add_watch(join(maildir, box, 'new'),
|
||||||
|
pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO)
|
||||||
|
|
||||||
|
file_notifier.loop()
|
Loading…
x
Reference in New Issue
Block a user