summaryrefslogtreecommitdiffstatshomepage
path: root/mbsync/.local
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-03-29 19:32:57 -0500
committerToby Vincent <tobyv13@gmail.com>2023-03-29 19:32:57 -0500
commitfdd531b4319aba6a800848dd15c0c9734a42f6a2 (patch)
tree98287bc9bf9a39c4b4da2428f7a8d41c09d5587e /mbsync/.local
parente9fd0daa3698fe28c272893cb982ffc4e58cfeba (diff)
feat(mbsync): add notify daemon service using inotifywatch
Diffstat (limited to 'mbsync/.local')
-rwxr-xr-xmbsync/.local/bin/maildir-notify20
1 files changed, 20 insertions, 0 deletions
diff --git a/mbsync/.local/bin/maildir-notify b/mbsync/.local/bin/maildir-notify
new file mode 100755
index 0000000..61b8d40
--- /dev/null
+++ b/mbsync/.local/bin/maildir-notify
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+if [ $# = 0 ]; then
+ set -- "$MAIL"
+fi
+
+for i; do
+ set -- "$@" "${i}/new"
+ shift
+done
+
+inotifywait --monitor --event create --event moved_to "$@" |
+ while read -r dir _action file; do
+ catagory="$(dirname "$dir" | xargs dirname | xargs basename)"
+ from="$(grep -m1 -oP '(?<=^From: ).*' "${dir}${file}")"
+ subject="$(grep -m1 -oP '(?<=^Subject: ).*' "${dir}${file}")"
+
+ echo "Catagory: $catagory, From: $from, Subject: $subject"
+ notify-send -a "Mail" -c "$catagory" "From: $from" "$subject"
+ done