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

. /usr/share/debian-edu-config/testsuite-lib.sh

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

retval=0

#for port in smtp imap2 imaps; do
for port in smtp imaps; do
    netstat_check $port tcp "postoffice" || retval=1
done

## send a test-email to root: 
cat << EOF | /usr/lib/sendmail root
Subject: Test-email sent by the debian-edu test-suite

Hello SysAdmin, 

welcome to the mail-system. Basic email delivery seems to work!
If you did not receive this email, report the failure to us. 

This email has been sent by the Debian-Edu test-suite. 

Regards,

    The Debian-Edu Developers

EOF

exit $retval
