# Create postfix configuration for SAGATOR

if grep -q "^#begin: sagator" /etc/postfix/main.cf >/dev/null; then
  echo "Postfix main configuration already done."
else
  echo "Autoconfiguring postfix main.cf ..."
  echo -e \
    "#begin: sagator\ncontent_filter=smtp:[127.0.0.1]:27\n#end: sagator\n" \
    >> /etc/postfix/main.cf
fi
if grep -q "^#begin: sagator" /etc/postfix/master.cf >/dev/null; then
  echo "Postfix master configuration already done."
else
  echo "Autoconfiguring postfix master.cf ..."
  cat >> /etc/postfix/master.cf << EOF
#begin: sagator
127.0.0.1:26	inet n - n - 30 smtpd
  -o content_filter=
  -o myhostname=sagator.`hostname`
  -o in_flow_delay=0
  -o local_recipient_maps=  -o relay_recipient_maps=
  -o mynetworks=127.0.0.0/8  -o mynetworks_style=host
  -o smtpd_restriction_classes=  -o smtpd_client_restrictions=
  -o smtpd_helo_restrictions=  -o smtpd_sender_restrictions=
  -o smtpd_recipient_restrictions=permit_mynetworks,reject
  -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
#end: sagator
EOF
fi

# reload postfix
/etc/init.d/postfix reload || true
