query=select value from objectproperty where objectid=(select objectid from objectproperty where value='%s' limit 1) and propname='loginname';
EOF
chmod 600 /etc/postfix/mysql-aliases.cf
cat <<EOF > /etc/postfix/mysql-groups.cf
user=$SERVER_MYSQL_USER
password=$SERVER_MYSQL_PASSWORD
hosts=$SERVER_MYSQL_HOST
dbname=$SERVER_MYSQL_DATABASE
query=select value from objectproperty where objectid in (select objectid from objectrelation where parentobjectid in (select objectid from objectproperty where value='%s' and propname='emailaddress') and relationtype=1) and propname='emailaddress';
EOF
chmod 600 /etc/postfix/mysql-groups.cf
# enable sasl authentication.
sed -i "s/^START=no/START=yes/" /etc/default/saslauthd
sed -i 's/^MECHANISMS="pam"/MECHANISMS="rimap"/' /etc/default/saslauthd
sed -i 's/^MECH_OPTIONS=""/MECH_OPTIONS="127.0.0.1"/' /etc/default/saslauthd
sed -i "s/^THREADS=5/THREADS=0/" /etc/default/saslauthd
sed -i 's@^OPTIONS="-c -m /var/run/saslauthd"@OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"@' /etc/default/saslauthd