Skip to content

Instantly share code, notes, and snippets.

@edison23
Created June 12, 2015 17:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edison23/02aacf1361cea8fb49f8 to your computer and use it in GitHub Desktop.
Save edison23/02aacf1361cea8fb49f8 to your computer and use it in GitHub Desktop.
Mail notification for maildir maintained by Offlineimap
#!/bin/sh
# WHAT IS THIS SHIT?
# It's a script comprising of shitty regexes that notifies you,
# when there has been a change in you mailbox dir.
# Works best with offlineimap.
# PREREQUISITIES
# Depends on inotify-tools and libnotify
# THANKS
# to Nicolas.Estibals (https://bbs.archlinux.org/viewtopic.php?pid=933429#p933429)
# for inspiration.
# NOTE
# inotifywait output usually looks like /home/user/.mail/myname/INBOX/new/ CREATE 1434095160_4.29513.my-Computer\,U\=13529\,FMD5\=7e33429f656f1e6e9d79b29c3f82c57e\:2\,
# SETUP
MAILBOX="/home/edison23/.mail" # what's you maildir name
TIMOUT="7000" # notification timeout
# MAGIC WITH SHITTY REGEXES
while true; do
# watch for changes in folder
NOTIFY=`inotifywait -e create -e moved_to ${MAILBOX}/*/*/new 2> /dev/null`
# sed out stuff (folder name and file path) from inotifywait output and create popup
FILE=`echo $NOTIFY | sed -r "s/(.*?\/) .*? (.*)/\1\2/"`
FOLDER=`echo $NOTIFY | sed -r "s/.*?\/(.*\/.*)\/.*\/ .*/\1/"`
notify-send -t $TIMOUT "New mail in $FOLDER" "`grep -m 1 ^From: $FILE`\n`grep -m 1 ^Subject: $FILE`"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment