dotfiles/.config/i3/scripts/mailnotify.sh

27 lines
662 B
Bash
Raw Normal View History

2021-06-29 01:49:08 +02:00
#!/bin/zsh
#https://gist.github.com/john2x/f6d947362dae7c10f702
function extract_sender {
grep -o '^From: \(.*\)$' $1 | sed "s/^From: //g"
}
function extract_subject {
2021-07-09 20:09:48 +02:00
~/.config/i3/scripts/decode_header.py `grep -o '^Subject: \(.*\)$' $1 | sed "s/^Subject: //g"`
2021-06-29 01:49:08 +02:00
}
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