aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mbsync/.local/bin
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-03-30 14:42:49 -0500
committerToby Vincent <tobyv13@gmail.com>2023-03-30 14:42:49 -0500
commitbf63e1d8f48a2a0435c33c10cb55c25ae153c4c9 (patch)
tree25bee8c02015cde8c60ccab1346c1d9d365878ac /mbsync/.local/bin
parente27efbd103f5bb2547ac3c22557cae4c052bd7b7 (diff)
fix(mail): fix race condition in notification service
Diffstat (limited to 'mbsync/.local/bin')
-rwxr-xr-xmbsync/.local/bin/maildir-notify13
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