#!/bin/bash #Copyright 2002, William Stearns #Released under the GPL if [ -z "$HOME" ]; then HOME="/home/wstearns" fi #Kick out any messages waiting in the sendmail queue nice /usr/sbin/sendmail -q >> $HOME/autofetchmail.log 2>&1 & #I save any spams not caught by razor to the verified-spam folder. This runs razor-report #on that folder to send spam signatures to the razor database. The next "if" says we'll do #the report if I've saved spam to that folder since the last time I reported. if [ $HOME/mail/verified-spam -nt $HOME/.razor/last-verified-report ]; then touch $HOME/.razor/last-verified-report echo Reporting verified-spam. >> $HOME/autofetchmail.log 2>&1 nice razor-report -M $HOME/mail/verified-spam >> $HOME/autofetchmail.log 2>&1 else echo Verified-spam all caught up, not reporting. >> $HOME/autofetchmail.log 2>&1 fi #If there's a fetchmail already running, don't start another. #At some point I should replace this with a lockfile stored in $HOME if [ -n "`ps ax | grep 'fetchmail --all' | grep -v grep`" ]; then echo fetchmail already running, no new copy tripped. >> $HOME/autofetchmail.log 2>&1 else echo fetchmail not running, starting new run. >> $HOME/autofetchmail.log 2>&1 if [ -f $HOME/agent ]; then . $HOME/agent export SSH_AUTH_SOCK SSH_AGENT_PID SSH_ASKPASS else echo SSH agent info not in ~/agent, please place there. >> $HOME/autofetchmail.log 2>&1 fi #The next test is essentially "If we have a ppp connection or we have some default route (i.e., if we have an Internet connection) if [ -f /var/run/ppp0.pid ] || [ `/sbin/route -n | grep '^0\.0\.0\.0' | grep -v 'ppp[0-9]$' | grep -v 'sl[0-9]$' | grep -v 'tap[0-9]$' | wc -l` -gt 0 ]; then #The "--keep" leaves mail up on the mail server; good for testing. #/usr/bin/fetchmail --keep --limit 6000 >> $HOME/autofetchmail.log 2>&1 #First, get all messages under 80K; messages 80K and above just get left on the mail server for the moment. #After every block of 10 messages, tell the mail server to #delete those. If you set the expunge to a very low value, say 1-5, the mail server will have #lots of pauses as it rewrites you mail spool. If you set it too high, say, 200, you'll get lots #of duplicate messages if you disconnect and have to reconnect. #Set expunge low (10-30) if you stand a reasonably good chance of getting disconnected. Set #high if your connection is stable. nice /usr/bin/fetchmail --all --expunge 10 --limit 80000 >> $HOME/autofetchmail.log 2>&1 #Now we go back through and get all the messages, which may include some >80K. nice /usr/bin/fetchmail --all --expunge 10 >> $HOME/autofetchmail.log 2>&1 touch ~/last_mail_check fi fi