diff options
Diffstat (limited to 'mbsync')
-rw-r--r-- | mbsync/.config/environment.d/20-mail.conf | 1 | ||||
-rw-r--r-- | mbsync/.config/systemd/user/maildir-notify.service | 10 | ||||
-rwxr-xr-x | mbsync/.local/bin/maildir-notify | 20 |
3 files changed, 31 insertions, 0 deletions
diff --git a/mbsync/.config/environment.d/20-mail.conf b/mbsync/.config/environment.d/20-mail.conf new file mode 100644 index 0000000..e3e2599 --- /dev/null +++ b/mbsync/.config/environment.d/20-mail.conf @@ -0,0 +1 @@ +MAIL=$XDG_DATA_HOME/mail/gmail/INBOX diff --git a/mbsync/.config/systemd/user/maildir-notify.service b/mbsync/.config/systemd/user/maildir-notify.service new file mode 100644 index 0000000..59dc969 --- /dev/null +++ b/mbsync/.config/systemd/user/maildir-notify.service @@ -0,0 +1,10 @@ +[Unit] +Description=Watches Maildir for new mail and sends notifications + +[Service] +Type=simple +ExecStart=%h/.local/bin/maildir-notify %h/.local/share/mail/gmail/INBOX %h/.local/share/mail/feeds/INBOX +RestartSec=10 + +[Install] +WantedBy=default.target 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 |