#!/bin/sh
#
# This script is called when ppp disconnects from the network.
#		 
# Here is where we'll stop sendmail if needed
#
# Written By Richard Nelson <cowboy@debian.org>
#
# NOTE: The following lines (without the #) must be in /etc/mail/sendmail.mc:
# include(`/etc/mail/dialup.m4')dnl
# include(`/etc/mail/provider.m4')dnl
#
# Exit by default, check for validity before commenting out the next line:
exit 0;

# Purge any latent host status that might cause us to *NOT* send mail
AM='-Am';
if [ ! -f /usr/share/sendmail/cf/feature/msp.m4 ]; then
	AM='';
	fi;
sendmail $AM -bH -O Timeout.hoststatus=1s;

# New mail will only be queued
file="/etc/mail/dialup.m4";
if [ -f "$file" ]; then
	cat <<-EOT > $file;
		LOCAL_CONFIG
		#------------------------------------------------------------
		#
		# Dynamic updates from $0
		#
		# NOTE: the following line *MUST* be in /etc/mail/sendmail.mc
		dnl include(\`/etc/mail/dialup.m4')dnl
		#
		# sendmail is to only queue messages until connected again
		define(\`confDELIVERY_MODE', \`deferred')dnl
		#
		# Allow the queue to age without carping every four hours
		define(\`confTO_QUEUEWARN',\`1d')dnl
		#
		# Don't keep host status while the network is down
		define(\`confHOST_STATUS_DIRECTORY')dnl
		#------------------------------------------------------------
		EOT
	fi;

# Build a new sendmail.cf from sendmail.mc, including our address.
# NOTE: The following line (without the #) must be in /etc/mail/sendmail.mc:
# include(`/etc/mail/dialup.m4')
m4 /etc/mail/sendmail.mc \
	> /etc/mail/sendmail.cf.pnew;
chmod 0644 /etc/mail/sendmail.cf.pnew;
chown mail:mail /etc/mail/sendmail.cf.pnew;
mv -f /etc/mail/sendmail.cf.pnew /etc/mail/sendmail.cf;

# Stop/reload sendmail daemon as needed
/etc/init.d/sendmail reload;
