You are not logged in.

#1 2011-05-13 09:56:31

Nicolas.Estibals
Member
Registered: 2011-05-13
Posts: 3

Notifier for mutt & offlineimap

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

#2 2011-05-14 06:41:50

Nicolas.Estibals
Member
Registered: 2011-05-13
Posts: 3

Re: Notifier for mutt & offlineimap

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

#3 2011-07-18 17:40:56

Nicolas.Estibals
Member
Registered: 2011-05-13
Posts: 3

Re: Notifier for mutt & offlineimap

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

#4 2012-08-31 15:34:32

erikw
Member
From: Lund, Sweden
Registered: 2012-07-17
Posts: 17
Website

Re: Notifier for mutt & offlineimap

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).

https://github.com/erikw/dotfiles/blob/ … r_watch.sh

Offline

#5 2015-11-20 02:01:56

bhundven
Member
From: Seattle, WA
Registered: 2015-11-20
Posts: 2

Re: Notifier for mutt & offlineimap

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

Board footer

Powered by FluxBB