#!/bin/sh -e
#
# Test if the post office is working.

if test -r /etc/debian-edu/config ; then
    . /etc/debian-edu/config
fi

# Only Main-Server should implement mail server
if echo "$PROFILE" | grep -q Main-Server ; then
    enabled=true
fi

if [ true != "$enabled" ] ; then
    exit 0
fi

proto=tcp
retval=0

#for port in smtp imap2 imaps; do
for port in smtp imaps; do
    if netstat -a 2>&1 | grep ":$port " | grep -q "^$proto"; then
	echo "success: $0: postoffice is listening on $port/$proto."
    else
	echo "error: $0: postoffice is not listening on $port/$proto."
	retval=1
    fi
done

exit $retval
