#!/bin/sh

# /etc/ppp/service/mails

# Purpose : look for mail waiting to be polled and send mail queued on this
# system, also poll and send in intervals while connected to the net
#
# NOTE : This script needs sendmail and fetchmail to work
#
# You'll need a user named poll, with a correctly set up .fetchmailrc in
# his home dir (for security reasons make sure, this user can't log in,
# use su instead). You also need a sendmail set up, in a way to collect
# outgoing email, so sendmail -q can send them out, when the link is 
# established.
#
# ToDo : 
# -create a lock file indicating that mail is currently transfered
#  so the link will not be shut down in transfer

if [ "$1" = "start" ] ; then

  # First test, if we are connected
  if test ! -e /var/lock/internet/ppp-is-up ; then 
    /bin/echo not linked to the internet
    exit 1
  fi
  
  /bin/echo mail exchange ... >>/var/log/internet-log
  /usr/sbin/sendmail -q
  /bin/su poll -s/usr/bin/fetchmail
  /bin/echo mail exchanged >>/var/log/internet-log
fi

if [ "$1" = "stop" ] ; then
   /usr/bin/killall fetchmail
   /usr/sbin/sendmail -q
fi
