From bb4c0c93fc28aa1a43cf90e4f735ecfad5985f1d Mon Sep 17 00:00:00 2001 From: Gregor Feierabend <23300469@sun.ac.za> Date: Tue, 29 Jun 2021 01:49:08 +0200 Subject: [PATCH] notify update --- .config/i3/i3blocks.conf | 2 +- .scripts/mailnotify2.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 .scripts/mailnotify2.sh diff --git a/.config/i3/i3blocks.conf b/.config/i3/i3blocks.conf index 5a6a13b..ba03ce7 100644 --- a/.config/i3/i3blocks.conf +++ b/.config/i3/i3blocks.conf @@ -43,7 +43,7 @@ interval=10 color=#A4C2F4 [mail] -command=~/.scripts/mailnotify.sh +command=~/.scripts/mailnotify2.sh interval=60 color=#91E78B diff --git a/.scripts/mailnotify2.sh b/.scripts/mailnotify2.sh new file mode 100755 index 0000000..9e6aef5 --- /dev/null +++ b/.scripts/mailnotify2.sh @@ -0,0 +1,26 @@ +#!/bin/zsh + +#https://gist.github.com/john2x/f6d947362dae7c10f702 +function extract_sender { + grep -o '^From: \(.*\)$' $1 | sed "s/^From: //g" +} +function extract_subject { + grep -o '^Subject: \(.*\)$' $1 | sed "s/^Subject: //g" +} + +prevmsgs=/tmp/oimapprevmsg +ml="$(find $HOME/MAIL/offlineIMAP/*/INBOX/new -type f | wc -l)" +touch $prevmsgs +if (( ml > 0 )); then + for file in ~/MAIL/offlineIMAP/*/INBOX/new/* + do + if grep -Fxq "$file" "$prevmsgs"; then + else + notify-send "New Mail" "From: `extract_sender $file`\nSubject: `extract_subject $file`" + echo $file >> $prevmsgs + fi + done + echo $ml +else + echo "0" +fi