#!/bin/sh

QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat @PREFIX@/var/qmail/control/concurrencyincoming`
LOCAL=`head -1 @PREFIX@/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 @PREFIX@/var/qmail/supervise/qmail-smtpd/run
  exit 1
fi

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

exec @PREFIX@/sbin/softlimit -m 30000000 \
  @PREFIX@/bin/tcpserver -v -R -l "$LOCAL" -x @PREFIX@/etc/tcp.smtp.cdb -c "$MAXSMTPD" \
  -u "$QMAILDUID" -g "$NOFILESGID" 0 smtp \
  @PREFIX@/bin/rblsmtpd -t 300 \
  -b -r safe.dnsbl.sorbs.net \
  -b -r zen.spamhaus.org \
  @PREFIX@/bin/fixcrio @PREFIX@/var/qmail/bin/qmail-smtpd 2>&1
