Edit /etc/dovecot.conf, find:
after it, add:
Now use the following script to disable IMAP (or POP3 (replace IMAP with POP3 in the script)) access (usage: ./script allow/deny usename pop3/imap):
Code:
mechanisms = plain
Code:
passdb passwd-file {
args = /etc/dovecot-deny.%Ls
deny = yes
}
Code:
#!/bin/sh
#
# Script used to deny IMAP/POP3 access for a particular user
show_help()
{
echo "IMAP allow/deny script.";
echo "";
echo "Usage: $0 allow/deny username pop3/imap";
echo "";
}
if [ $# -eq 3 ]; then
echo "Using $2."
else
show_help;
exit 1;
fi
OS=`uname`;
if [ $1 = "allow" ]; then
OPTION=allow
else
OPTION=deny
fi
USER=$2
ACCESS=$3
if [ "${ACCESS}" != "imap" ] && [ "${ACCESS}" != "pop3" ]; then
echo "Wrong access type speficied: ${ACCESS}"
exit 1;
else
DENYFILE=/etc/dovecot-deny.${ACCESS}
if [ ! -e ${DENYFILE} ]; then
touch ${DENYFILE}
fi
fi
if [ ! -d /home/${USER} ]; then
echo "User ${USER} does not exist."
exit 1;
fi
if [ ${OPTION} = "allow" ]; then
if [ "`grep -c \"${USER}\" ${DENYFILE}`" = "0" ]; then
echo "User ${USER} is already allowed.";
exit 1;
fi
perl -pi -e "s/${USER}\n//g" ${DENYFILE}
fi
if [ ${OPTION} = "deny" ]; then
if [ "`grep -c \"${USER}\" ${DENYFILE}`" = "1" ]; then
echo "User ${USER} is already denied.";
exit 1;
fi
echo "$USER" >> ${DENYFILE}
fi
exit 0;
Last edited: