===============================================================================
COPYRIGHT AND DISCLAIMER
===============================================================================

This package is Copyright(C) 2010 Giam Teck Choon or CHOON.NET, and may be
copied according to the GNU GENERAL PUBLIC LICENSE (GPL) Version 2 or a later
version. A copy of this license is included with this package. This package
comes with no warranty of any kind.

YOU ARE FREE TO USE THIS SCRIPT/PATCHES/GUIDE BUT I AM NOT RESPONSIBLE FOR ANY
DAMAGE CAUSED! YOU HAVE BEEN WARNED!!!


===============================================================================
INTRODUCTION
===============================================================================

mailfront-imapfront-auth-dovecot is a program to modify the MAIL environment
variable according to dovecot imap requirements in order to access users
mail storage.

Dovecot uses colons as internal field separators; however, since v1.2rc6, it
allows colons occurrences via escaping (as : → ::). Before passing such
mailbox paths via MAIL environment variable to dovecot imap, this wrapper
performs such escaping.

From original MAIL environment variable:

/home/USERNAME/MAILDIR/mail:box:user

To:

maildir:/home/USERNAME/MAILDIR/mail::box::user

More information can be read at:

http://wiki.dovecot.org/MailLocation

References:

http://mij.oltrelinux.com/net/dovecot-qmail-vmailmgr/
http://wiki.dovecot.org/HowTo/VMailMgr

MANY THANKS TO mij@bitchx.it

===============================================================================
REQUIREMENTS
===============================================================================

* make
* gcc
* mailfront >= 1.16 (http://untroubled.org/mailfront/)
* dovecot >= 1.2rc6 (http://www.dovecot.org/)


===============================================================================
HOW TO COMPILE, INSTALL AND UNINSTALL?
===============================================================================

Run "make" to compile.

Run "make install" to install (default prefix: /usr/local). So
mailfront-imapfront-auth-dovecot will be installed in /usr/local/bin/ with
default prefix as /usr/local.  If you would like to install in other location,
i.e. in /usr instead of /usr/local:

make prefix=/usr install

Run "make uninstall" to uninstall.  If you install in other prefix such as
/usr instead of /usr/local, please pass the argument to make:

make prefix=/usr uninstall


===============================================================================
HOW TO USE?
===============================================================================

In your imapd run file, place mailfront-imapfront-auth-dovecot before dovecot
imap.  Example imapd/run file:

--------------------8<----------8<----------8<----------8<---------------------
#!/bin/sh

DOVECOTWRAPPER=""
# Default to support dovecot 1.0.x
if [ -x "/usr/libexec/dovecot/imap" ] ; then
	IMAPD=/usr/libexec/dovecot/imap
	if [ -x "/usr/bin/mailfront-imapfront-auth-dovecot" ] ; then
		DOVECOTWRAPPER=/usr/bin/mailfront-imapfront-auth-dovecot
		# uncomment the below if you want to debug
		#export IMAPFRONTAUTH_DOVECOT_DEBUG=1
	elif [ -x "/usr/local/bin/mailfront-imapfront-auth-dovecot" ] ; then
		# uncomment the below if you want to debug
		#export IMAPFRONTAUTH_DOVECOT_DEBUG=1
		DOVECOTWRAPPER=/usr/local/bin/mailfront-imapfront-auth-dovecot
	fi
elif [ -x "/usr/local/bin/imapd" ] ; then
	IMAPD=/usr/local/bin/imapd
elif [ -x "/usr/lib/courier-imap/bin/imapd" ] ; then
	IMAPD=/usr/lib/courier-imap/bin/imapd
else
	IMAPD=/usr/bin/imapd
fi

if [ -x "/usr/bin/imapfront-auth" ] ; then
	IMAPFRONT_AUTH=/usr/bin/imapfront-auth
else
	IMAPFRONT_AUTH=/usr/local/bin/imapfront-auth
fi

ulimitdata=500000000
concurrency=40

CVM_SASL_PLAIN=cvm-local:/tmp/.cvm-vmailmgr
CVM_SASL_LOGIN=cvm-local:/tmp/.cvm-vmailmgr
export CVM_SASL_PLAIN
export CVM_SASL_LOGIN

exec \
softlimit -m $ulimitdata \
tcpserver -DHRUvX -c "$concurrency" -l "`head -n 1 /var/qmail/control/me`" \
	-x /etc/tcpcontrol/imap.cdb 0 imap \
$IMAPFRONT_AUTH $DOVECOTWRAPPER \
$IMAPD 2>&1
--------------------8<----------8<----------8<----------8<---------------------
