#!/bin/sh if [ $# = 0 ]; then for d in "$XDG_DATA_HOME"/mail/*; do set -- "$@" "${d}/INBOX" done fi for i; do set -- "$@" "${i}/new" shift done echo "Watching $*" inotifywait --monitor --event create --event moved_to "$@" | while read -r dir _action file; do inbox="$(dirname "$dir")" category="$(dirname "$inbox" | xargs basename)" from="$(grep -m1 -oP '(?<=^From: ).*' "${dir}${file}")" subject="$(grep -m1 -oP '(?<=^Subject: ).*' "${dir}${file}")" if [ ! -e "$inbox/new/$file" ]; then if [ -e "$inbox/cur/$file" ]; then from="$(grep -m1 -oP '(?<=^From: ).*' "$inbox/cur/$file")" subject="$(grep -m1 -oP '(?<=^Subject: ).*' "$inbox/cur/$file")" else echo "Failed to read message. File: $file" continue fi fi echo "Category: $category, From: $from, Subject: $subject" notify-send -a "Mail" -c "$category" "From: $from" "$subject" done