You are not logged in.
Pages: 1
Here is my quick&dirty but very effective script:
#!/bin/sh
while true; do
mb=`inotifywait -e create -e moved_to ~/Mail/*/*/new 2> /dev/null | cut -f 1 -d " " | cut -d "/" -f 5-6`
notify-send -t 15000 -i '/usr/share/icons/oxygen/32x32/status/mail-unread-new.png' "New mail in $mb" " "
done
You'll need to install community/inotify-tools and extra/libnotify to use this. If you want to use the icon, tou'll also need extra/oxygen-icons for the image (you may also use another one.)
Quick explanation of the script:
I use inotifywait to watch creation of mail in my different Maildir (they are in ~/Mail/<account>/<dir>). When there is a mail, inotifywait terminates and I send a notification through the desktop notification system (I use awesome but it schould work with every wm that respects this freedesktop standart.)
Enjoy !
Last edited by Nicolas.Estibals (2011-05-13 13:11:59)
Offline
More feratures, less dirty:
#!/bin/bash
while true; do
ev=`inotifywait -e create -e moved_to ~/Mail/*/*/new 2> /dev/null`
pa=${ev/ */}
f="$pa/${ev/* /}"
bo=${pa/\/new/}
bo=${bo/*Mail\//}
notify-send -t 12000 -i '/usr/share/icons/oxygen/32x32/status/mail-unread-new.png' "New mail in $bo" "`grep -m 1 ^From: $f`\n`grep -m 1 ^Subject: $f`"
done
Offline
New version of the notifier: go to python for easy header decoding and get the list of the list of the mailboxes from ~/.mutt/mailboxes file.
#!/usr/bin/env python2
# -*- coding: utf-8; mode: python -*-
import pyinotify
import pynotify
from os.path import expanduser
from mailbox import MaildirMessage
from email.header import decode_header
from gtk.gdk import pixbuf_new_from_file
# Getting the path of all the boxes
fd = open(expanduser("~/.mutt/mailboxes"), 'r')
boxes = [expanduser(b[1:-1]) for b in fd.readline()[10:-1].split(' ')]
fd.close()
pynotify.init('email_notifier.py')
# Handling a new mail
icon = pixbuf_new_from_file("/usr/share/icons/oxygen/32x32/status/mail-unread-new.png")
dec_header = lambda h : ' '.join(unicode(s, e if bool(e) else 'ascii') for s, e in decode_header(h))
def newfile(event):
fd = open(event.pathname, 'r')
mail = MaildirMessage(message=fd)
From = "From: " + dec_header(mail['From'])
Subject = "Subject: " + dec_header(mail['Subject'])
n = pynotify.Notification("New mail in "+'/'.join(event.path.split('/')[-3:-1]),
From+ "\n"+ Subject)
fd.close()
n.set_icon_from_pixbuf(icon)
n.set_timeout(12000)
n.show()
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm, newfile)
for box in boxes:
wm.add_watch(box+"/new", pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO)
notifier.loop()
Offline
Wow nice. inotifywait is a really cool tool. This inspired me to write my own script that also prints mail subject and trimmed body (works good with dunst).
Offline
I know this is kind of an old thread, but... here is an updated version of post #3 that handles mailboxes with spaces in the name:
https://gist.github.com/bhundven/27a1eea9f1d01056ebb0
Offline
Pages: 1