User Tools

Site Tools


zmaildir

With dovecots zlib plugin, it's possible to have compressed mails in the users maildir.

I've written a script to compress all mails on my mailserver:

#!/bin/sh

compress_maildir () {
cd $1
DIRS=`find -maxdepth 2 -type d -name cur`
for dir in $DIRS; do
  echo $dir
  cd $dir
  FILES=`find -type f -name „*,S=*“ -not -regex „.*:2,.*Z.*“`
  #compress all files
  for FILE in $FILES; do
  NEWFILE=../tmp/${FILE}
  #echo bzip $FILE $NEWFILE
  if ! bzip2 -9 $FILE -c > $NEWFILE; then
  echo compressing failed
  exit -1;
  fi
  #reset mtime
  if ! touch -r $FILE $NEWFILE; then
  echo setting time failed
  exit -1
  fi
  done
  echo Locking $dir/..
  if PID=`/usr/libexec/dovecot/maildirlock .. 120`; then
  #locking successfull, moving compressed files
  for FILE in $FILES; do
  NEWFILE=../tmp/${FILE}
  if [ -s $FILE ] && [ -s $NEWFILE ]; then
  echo mv $FILE $NEWFILE
  mv $FILE /tmp
  mv $NEWFILE ${FILE}Z
  else
  echo mv failed
  exit -1
  fi
  done
  kill $PID
  else
  echo lock failed
  exit -1
  fi
  cd - >/dev/null
done
}

compress_maildir /home/user/.maildir/
chown -R username:users /home/user/.maildir/
If using this script, please do it after an backup/copy of the maildir, the script is far away from being perfect :-)

If the Script is rerun, it checks the files for a Z at the end of the filename, so the file isn't recompressed.

With compressed mails i saved ~25% of space.

zmaildir.txt · Keista: 2015/02/25 17:03 vartotojo dalius