mutt with new mail desktop notification
After some searching for an easy way to get desktop notifications with new mail on mutt, I wrote this small script based on one I saw.
It’s my first real script (though stupid it may seem) and so, improvable. Works, though. You need the notify-send command (libnotify-bin Debian package), and the program mailcheck. I hope to be able to use dbus-send directly so there is no need for any additional packages. I would also like to add a button to the popup to open mutt in a terminal, something just not possible with notify-send.
mailcheck is a very nice tool that works with different mail formats (imap, pop, maildir… ). It works perfectly with my offlineimap maildirs. Create .mailcheckrc
and insert the paths to the maildirs, for example /home/name/.mail/GMAIL/INBOX .
You can run the script as an autostart program, and get some notifications through Gnome’s default notification system, notify-osd, and other systems(?). Give it execute permissions (chmod +x mutt-notify), run with ./mutt-notify and you’re good to go :) WordPress code tags suck. Space indenting is gone.
#!/bin/bash
new_mail=0
last_sum=0
maildir=" "
while [ : ];
do
sum_mail=0
mailcheck | grep new 2>&1 >/dev/null
if [ $? -eq 0 ];
then
maildir=`mailcheck | grep new | awk '{ print $NF }' \
| sed 's/\// /g' | awk '{ print $NF }' \
| awk '{ printf "%s ", $0 }' | sed 's/ /, /g' \
| sed 's/, $//'`
new_mail=`mailcheck | grep new | awk '{ print $3 }'`
for N in `echo $new_mail`
do
sum_mail=`expr $sum_mail + $N`
done
if [ $sum_mail -ne $last_sum ];
then
if [ $sum_mail -eq 1 ] ;
then
notify-send -c email.arrived -u normal -i mail_new \
"You have $sum_mail new mail:" "$maildir"
else
notify-send -c email.arrived -u normal -i mail_new \
"You have $sum_mail new mails:" "$maildir"
fi
last_sum=$sum_mail
fi
fi
sleep 60
done
check out the inotify library. It’s a cleaner solution
matt
November 27, 2010 at 3:50 am
Via Cronjob:
#! /bin/bash
mail_count=`ls ~/Mail/*/INBOX/new/*|wc -l` # edit path to your maildir (e.g. offlineimap)
if [ $mail_count -gt 0 ]; then
/usr/bin/notify-send -t 5000 -i ~/art/Logos/mail.gif “You have $mail_count new mail/s”;
fi
Max
March 15, 2012 at 12:22 pm
Here is a bash script that you can run in the background that will notify you about new email in one or more mbox files.
#!/bin/bash
function get_file_size()
{
ls -l $1 | awk ‘{print $5}’
}
MAILBOX=”/home/user/mail/mbox1 /home/user/mail/mbox2″
declare -A map
for mailbox in $MAILBOX ; do
map[$mailbox]=`get_file_size $mailbox`
done
while [ 1 ] ; do
sleep 10
for mailbox in $MAILBOX ; do
OLD_SIZE=${map[$mailbox]}
NEW_SIZE=`get_file_size $mailbox`
if [ $NEW_SIZE -gt $OLD_SIZE ] ; then
notify-send “You have new email in $mailbox”
fi
map[$mailbox]=$NEW_SIZE;
done
done
Brian
Brian Masney
August 23, 2013 at 7:42 pm