Ivaldi has become a part of ReMark! Read more about it here.

Compressed mail in Dovecot

For one of our clients, I had to compress mails stored by Dovecot (to save some diskspace on their mail server). In the Dovecot wiki you can find a pseudo script that can do this for you. I used that to write the following script.

#!/bin/bash
if [[ $1 == "" ]]; then
        echo $0 " "
        exit -1
fi

tocompress=`cd $1/cur/ && find . -iname '*,S=*[^Z]'`

for mail in $tocompress; do
        echo "gzipping $1/cur/$mail to $1/tmp/${mail}Z"
        gzip -S Z "$1/cur/$mail" -c > "$1/tmp/${mail}Z"
        echo "setting mtime"
        touch -r "$1/cur/$mail" "$1/tmp/${mail}Z"
done

echo "aquiring maildirlock"
if PID=`/usr/lib/dovecot/maildirlock $1/cur 20`; then
        #locking successfull, moving compressed files
        for mail in $tocompress; do
                mv $1/tmp/${mail}Z $1/cur/
                rm $1/cur/${mail}
        done
        kill $PID
else
        echo "lock failed"
        exit -1
fi

Make sure you enable the zlib plugin in your Dovecot config (as described in the wiki).

Ivaldi has become a part of ReMark! Read more about it here.