aboutsummaryrefslogtreecommitdiff
path: root/local/sbin/newmail-notify
blob: 7c6b803842dc029b270bf48150a71a0991608c3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash

cd ~/.mail

if [ -f notify-notified ]; then
	NOTIFIED=`cat notify-notified`
	rm notify-notified
fi

for account in `ls`; do
	if cd "$account"/INBOX/new; then
		for m in `ls`; do
			echo $m
			echo $m >> ~/.mail/notify-notified
			if echo "$NOTIFIED" | grep "$m" >/dev/null; then continue; fi
			FROM=`grep -E "^From: " "$m" | sed 's/^From: //' | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)'`
			TO=`grep -E "^To: " "$m" | sed 's/^To: //' | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)'`
			SUBJECT=`grep -E "^Subject: " "$m" | sed 's/^Subject: //' | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)'`
			notify-send "$TO: $FROM" "$SUBJECT"
		done
	fi
	cd ~/.mail
done