#!/bin/sh

export TARPITCOUNT="3"
export TARPITDELAY="10"
export MFDNSCHECK=""
QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat /opt/local/var/qmail/control/concurrencyincoming`
LOCAL=`head -1 /opt/local/var/qmail/control/me`

if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" -o -z "$LOCAL" ]; then
  echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in 
  echo /opt/local/var/qmail/supervise/qmail-smtpd/run
  exit 1
fi

if [ ! -f /opt/local/var/qmail/control/rcpthosts ]; then
  echo "No /opt/local/var/qmail/control/rcpthosts"
  echo "Refusing to start SMTP listener because it'll create an open relay"
  exit 1
fi

exec /opt/local/sbin/softlimit -m 30000000 \
  /opt/local/bin/tcpserver -v -R -l "$LOCAL" -x /opt/local/etc/tcp.smtp.cdb -c "$MAXSMTPD" \
  -u "$QMAILDUID" -g "$NOFILESGID" 0 smtp \
  /opt/local/bin/rblsmtpd -t 300 \
  -b -r l1.spews.dnsbl.sorbs.net \
  -b -r misc.dnsbl.sorbs.net \
  -b -r http.dnsbl.sorbs.net \
  -b -r socks.dnsbl.sorbs.net \
  -b -r smtp.dnsbl.sorbs.net \
  -b -r web.dnsbl.sorbs.net \
  -b -r zombie.dnsbl.sorbs.net \
  -b -r dul.dnsbl.sorbs.net \
  -b -r rhsbl.sorbs.net \
  -b -r sbl-xbl.spamhaus.org \
  /opt/local/bin/fixcrio /opt/local/var/qmail/bin/qmail-smtpd 2>&1
