diff options
Diffstat (limited to 'mbsync/.local/bin/maildir-notify')
-rwxr-xr-x | mbsync/.local/bin/maildir-notify | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/mbsync/.local/bin/maildir-notify b/mbsync/.local/bin/maildir-notify index 61b8d40..198046e 100755 --- a/mbsync/.local/bin/maildir-notify +++ b/mbsync/.local/bin/maildir-notify @@ -11,10 +11,21 @@ done inotifywait --monitor --event create --event moved_to "$@" | while read -r dir _action file; do - catagory="$(dirname "$dir" | xargs dirname | xargs basename)" + inbox="$(dirname "$dir")" + catagory="$(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 "Catagory: $catagory, From: $from, Subject: $subject" notify-send -a "Mail" -c "$catagory" "From: $from" "$subject" done |