-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimap-notify
executable file
·39 lines (35 loc) · 918 Bytes
/
imap-notify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
if [ -z "$4" ]; then
echo "Imap idle listener"
echo "Usage: $0 [email protected] password server:993 /usr/bin/notify_command"
exit 1
fi
user=$1
password=$2
server=$3
command=$4
start_idle () {
echo ". login \"$user\" \"$password\""
echo ". select inbox"
echo ". idle"
while true; do
sleep 600;
echo "done"
echo ". noop"
echo ". idle"
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 ". [1-9][0-9]? EXISTS"; then
echo "New mail received, executing $command"
$command
fi
if echo "$line" | grep -Eq ". [1-9][0-9]? EXPUNGE"; then
echo "Mail removed from server, executing $command"
$command
fi
done < <(openssl s_client -crlf -quiet -connect "$server" 2>/dev/null < <(start_idle))