#!/bin/sh

if test -d ~/Maildir; then
	MAIL=~/Maildir
fi

# This might work on local storage
# (one for dovecot 1.x and the other for 0.99.x)
#export MBOX_WRITE_LOCKS=fcntl
#export MBOX_LOCKS=fcntl

# Works for Dovecot 1.x over non-locking NFS
export LOCK_METHOD=dotlock
export MMAP_DISABLE=yes

#export DEFAULT_MAIL_ENV=maildir:~/Maildir:INDEX=MEMORY
#export INDEX=MEMORY

# Avoid noise to stderr
#export USE_SYSLOG=1
#export SYSLOG_FACILITY=mail
export LOGFILE="$HOME/dovecot.log"
#export LOGFILE="/dev/null"

# Avoid LOGFILE growing endlessly
if [ -f "$LOGFILE" ] && [ "`ls -s "$LOGFILE" | awk '{print $1}'`" -gt 500 ]; then
	mv -f "$LOGFILE" "$LOGFILE.bak"
fi

exec /usr/lib/dovecot/imap