crabmail

Static HTML email archive viewer in Rust
git clone git://git.alexwennerberg.com/crabmail
Log | Files | Refs | README | LICENSE

commit 6935e710016299698e33e56cb248069d6cdd8d92
parent 67418be03e9a3a509316ef600e1bea741e4ac31d
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun,  2 Jan 2022 11:43:22 -0800

Add IMAP NOTIFY script

Diffstat:
Amisc/imapwatch.sh | 48++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+), 0 deletions(-)

diff --git a/misc/imapwatch.sh b/misc/imapwatch.sh @@ -0,0 +1,48 @@ +# uses IMAP NOTIFY extension +# Derived from +# https://github.com/johan-adriaans/shell-imap-notify/blob/master/imap-notify + +if [ -z "$3" ]; then + echo "Imap idle listener" + echo "Usage: $0 user@domain.com server:993 /usr/bin/notify_command" + exit 1 +fi + +read_secret() +{ + stty -echo + trap 'stty echo' EXIT + read "$@" + stty echo + trap - EXIT + echo +} + +user=$1 +server=$2 +command=$3 +printf "Password:" +read_secret password + +start_idle () { + echo ". login \"$user\" \"$password\"" + echo ". select lists" + # Change lists to a different folder + echo ". notify set (subtree lists (MessageNew MessageExpunge))" + while true; do + sleep 600; + echo "done" + echo ". noop" + done +} + +# Start ssl connection +echo "Starting imap idle client, logging in as $user at $server" +while read -r line ; do + # Debug info, turn this off for silent operation + echo "$line" + if echo "$line" | grep -Eq ". STATUS .*"; then + echo "Message added or deleted, executing $command" + $command + fi +done < <(openssl s_client -crlf -quiet -connect "$server" 2>/dev/null < <(start_idle))