Add script to periodicaly watch imaps server. Some ergonomic improvements
This commit is contained in:
4
scripts/imap_creds.example
Normal file
4
scripts/imap_creds.example
Normal file
@@ -0,0 +1,4 @@
|
||||
_USER="user@example.com"
|
||||
_PASSWD="mypassword"
|
||||
_SERVER="example.com"
|
||||
_FOLDER="INBOX"
|
||||
35
scripts/mailbox.sh
Executable file
35
scripts/mailbox.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
cd -- "$(dirname -- "$0")"
|
||||
_DIRNAME="$(pwd)"
|
||||
|
||||
source ./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 'beastie:}q6658JD~{}{oiRWsb~Q{P@SV=Qsy,ae' "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
|
||||
Reference in New Issue
Block a user