You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.3 KiB
Plaintext

3 years ago
#!/bin/sh
# i3blocks mail module.
# Displays number of unread mail and an loading icon if updating.
# When clicked, brings up `neomutt`.
messageinfo() { notify-send --urgency=$urgency --app-name="📧 Mailbox" "📧 Mailbox:" "Acc: $to
From: <span foreground=\"#b8bb26\"><b>$from</b></span>
Subject: $subject
<span foreground=\"#a89984\">Reseved in $mailfolder</span>" ;}
notify(){
new=$(find $HOME/.local/share/mail/*/*/new/ -type f 2> /dev/null)
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
if [ "$newcount" -gt "0" ]; then
find $HOME/.local/share/mail/*/*/new/ -type f 2> /dev/null | while read file; do
# Extract subject and sender from mail.
to=$(echo "$file" | sed -E "s/\/home\/jasper\/.local\/share\/mail\/(.+)\/.*\/.*\/.*$/\1/")
mailfolder=$(echo $file | sed -E "s/\/home\/jasper\/.local\/share\/mail\/.*\/(.+)\/.*\/.*$/\1/")
from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//')
subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n 1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n')
case $mailfolder in
Spam ) urgency="low" ;;
Fritz-Box ) urgency="low" ;;
Schule ) urgency="critical" ;;
* ) urgency="normal" ;;
esac
case $to in
jspahl11@gmail.com ) urgency="low" ;;
* ) urgency=$urgency
esac
messageinfo &
done
fi
}
case $BLOCK_BUTTON in
1) setsid -f "$TERMINAL" -e neomutt & ;;
2) setsid -f mailsync >/dev/null & ;;
3) notify-send -t 1000 "📬 Mailbox module:" "\- Shows unread mail
- Shows 🔃 if syncing mail
- Left click opens neomutt
- Middle click syncs mail" && notify >/dev/null ;;
6) "$TERMINAL" -e "$EDITOR" "$0"&;;
esac
unread="$(find ${XDG_DATA_HOME:-$HOME/.local/share}/mail/*/*/new/* -type f | wc -l 2>/dev/null)"
icon="$(cat "/tmp/imapsyncicon_$USER")" 2>/dev/null
[ "$unread" = "0" ] && [ "$icon" = "" ] || echo "📬 $unread$(cat "/tmp/imapsyncicon_$USER" 2>/dev/null)"