Edit /etc/dovecot.conf, find:

mechanisms = plain

Add after:

passdb passwd-file {
args = /etc/dovecot-deny.%Ls
deny = yes
}

Now use the following script to disable IMAP (or POP3 (replace IMAP with POP3 in the script)) access (usage: ./script allow/deny usename):

#!/bin/sh
#
# Script used to deny IMAP access for a particular user

show_help()
{
echo “IMAP allow/deny script.”;
echo “”;
echo “Usage: $0 allow/deny username”;
echo “”;
}

if [ $# -eq 2 ]; then
echo “Using $2.”
else
show_help;
exit 1;
fi

IMAPDENY=/etc/dovecot-deny.imap

OS=`uname`;

if [ $1 = "allow" ]; then
OPTION=allow
else
OPTION=deny
fi

USER=$2

if [ ${OPTION} = "allow" ]; then
if [ "`grep -c \"${USER}\" ${IMAPDENY}`" = "0" ]; then
echo “User ${USER} is already allowed.”;
exit 1;
fi
fi

if [ ${OPTION} = "deny" ]; then
if [ "`grep -c \"${USER}\" ${IMAPDENY}`" = "1" ]; then
echo “User ${USER} is already denied.”;
exit 1;
fi
fi

if [ ! -d /home/${USER} ]; then
echo “User ${USER} does not exist.”
exit 1;
fi

if [ ${OPTION} = "allow" ]; then
perl -pi -e “s/${USER}\n//g” ${IMAPDENY}
fi

if [ ${OPTION} = "deny" ]; then
echo “$USER” >> ${IMAPDENY}
fi
exit 0;