add script for offlineimap notifications

This commit is contained in:
Johannes Rothe 2018-05-20 22:20:51 +02:00
parent 20b9578daf
commit 1b53be92e0
2 changed files with 41 additions and 3 deletions

View File

@ -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
View 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()