36 lines
1.0 KiB
Bash
Executable File
36 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
cd -- "$(dirname -- "$0")"
|
|
_DIRNAME="$(pwd)"
|
|
|
|
source ~/.config/polybar/imap_creds
|
|
|
|
if [[ -n $1 ]] && [[ $1 == "count" ]]
|
|
then
|
|
_COUNT=$(curl -u "$_USER:$_PASSWD" "imaps://$_SERVER" -X "STATUS $_FOLDER (UNSEEN)" 2>/dev/null | \
|
|
sed -e 's/)\r//' -e 's/.*UNSEEN //')
|
|
printf "%s" "$_COUNT"
|
|
(( _COUNT == 0 )) && exit 0
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -n $1 ]] && [[ $1 == "fetch" ]]
|
|
then
|
|
_UNSEEN="$(curl -u \""$_USER":"$_PASSWD"\" "imaps://$_SERVER/$_FOLDER" -X "SEARCH UNSEEN" 2>/dev/null | \
|
|
sed -e "s/\\r//" -e "s/* SEARCH //" -e "s/ /,/g")"
|
|
_MAILS=$(curl -v -u "$_USER:$_PASSWD" "imaps://$_SERVER/$_FOLDER" -X "FETCH $_UNSEEN BODY.PEEK[HEADER.FIELDS (From Subject)]" 2>&1 | \
|
|
grep -E "From:|Subject:" | sed -e 's/< //' -e 's/Subject/\nSubject/')
|
|
dunstify -I ../icons/gmail.svg \
|
|
"" "$_MAILS"
|
|
printf "%s" "$_MAILS"
|
|
exit 0
|
|
fi
|
|
|
|
cat <<EOF
|
|
Usage:
|
|
mailbox.sh count => Count unseen mails in $_FOLDER
|
|
mailbox.sh fetch => Fetch "From:" and "Subject:" from unseen mails in $_FOLDER
|
|
EOF
|