#! /bin/sh
-date >> ~/.fetchmail/log
-fetchmail >> ~/.fetchmail/log
+if [ -f ~/.nomail ] && [ "$1" != --force ]; then
+ exit 0
+fi
+
+loadavg="$(cut -d. -f1 /proc/loadavg)"
+if [ "$loadavg" -ge 5 ]; then
+ # System load is too high. Don't contribute to it.
+ exit 0
+fi
+
bsmtp-pull gluck
+hour="$(date +%H)"
+case $hour in
+ 0[0-289]|[12]*)
+ date >> ~/.fetchmail/log
+ fetchmail >> ~/.fetchmail/log
+ logrotate -s ~/.fetchmail/logrotate.status ~/.fetchmail/logrotate.conf
+ ;;
+esac
+
exit 0