# Contributor: Markus M. May <triplem@tu.archserver.org>
# Maintainer: Daniel Moree <dmoree(AT)shadowbranch[DOT]com>

pkgbase=dovecot
pkgname=('dovecot' 'dovecot-mysql' 'dovecot-pgsql' 'dovecot-sqlite')
pkgver=1.2.16
pkgrel=1
arch=('i686' 'x86_64')
url="http://www.dovecot.org/"
license=('LGPL')
groups=()
depends=('bzip2' 'openssl')
makedepends=('postgresql' 'mysql' 'sqlite3' )
optdepends=()
conflicts=()
replaces=()
options=(!libtool)
install=dovecot.install
source=(http://dovecot.org/releases/1.2/dovecot-${pkgver}.tar.gz
        dovecot.sh)
noextract=()
md5sums=('8bbdf4e96e2e0f5749432ca9cb209a38'
         'ffe3e0d99eab157f58502d4946d06969')

build() {
  cd $srcdir/$pkgbase-$pkgver
  
  ./configure --prefix=/usr --sysconfdir=/etc/dovecot --localstatedir=/var \
	--libexecdir=/usr/lib  --with-moduledir=/usr/lib/dovecot/modules \
	--with-db --with-sql=plugin \
	--with-ssl=openssl --with-ssldir=/etc/dovecot/ssl \
	--with-docs --with-pgsql --with-mysql --with-sqlite
  
  make
}

package_dovecot() {
  backup=('etc/dovecot/dovecot.conf')
  depends=('bzip2' 'openssl')
  pkgdesc="Dovecot is an open source IMAP and POP3 server for Linux/UNIX-like systems, written with security primarily in mind."
  cd $srcdir/$pkgbase-$pkgver

  make DESTDIR=$pkgdir install

  # install the launch script
  install -D -m755 ${srcdir}/dovecot.sh ${pkgdir}/etc/rc.d/dovecot

  rm -rf $pkgdir/usr/lib/dovecot/modules/sql/*
  rm -rf $pkgdir/usr/lib/dovecot/modules/auth/*
}

package_dovecot-mysql() {
  depends=('dovecot' 'mysql')
  pkgdesc="Provides the Dovecot MySQL database driver"
  cd $srcdir/$pkgbase-$pkgver

  make DESTDIR=/tmp/$pkgdir install

  mkdir -p $pkgdir/usr/lib/dovecot/modules/sql
  mkdir -p $pkgdir/usr/lib/dovecot/modules/auth
  cp /tmp/$pkgdir/usr/lib/dovecot/modules/sql/*mysql* $pkgdir/usr/lib/dovecot/modules/sql/
  cp /tmp/$pkgdir/usr/lib/dovecot/modules/auth/*mysql* $pkgdir/usr/lib/dovecot/modules/auth/
}

package_dovecot-pgsql() {
  depends=('dovecot' 'postgresql')
  pkgdesc="Provides the Dovecot PostgreSQL database driver"
  cd $srcdir/dovecot-$pkgver

  make DESTDIR=/tmp/$pkgdir install

  mkdir -p $pkgdir/usr/lib/dovecot/modules/sql
  mkdir -p $pkgdir/usr/lib/dovecot/modules/auth
  cp /tmp/$pkgdir/usr/lib/dovecot/modules/sql/*pgsql* $pkgdir/usr/lib/dovecot/modules/sql/
  cp /tmp/$pkgdir/usr/lib/dovecot/modules/auth/*pgsql* $pkgdir/usr/lib/dovecot/modules/auth/
}

package_dovecot-sqlite() {
  depends=('dovecot' 'sqlite')
  pkgdesc="Provides the Dovecot SQLite 3 database driver"
  cd $srcdir/$pkgbase-$pkgver

  make DESTDIR=/tmp/$pkgdir install

  mkdir -p $pkgdir/usr/lib/dovecot/modules/sql
  mkdir -p $pkgdir/usr/lib/dovecot/modules/auth
  cp /tmp/$pkgdir/usr/lib/dovecot/modules/sql/*sqlite* $pkgdir/usr/lib/dovecot/modules/sql/
  cp /tmp/$pkgdir/usr/lib/dovecot/modules/auth/*sqlite* $pkgdir/usr/lib/dovecot/modules/auth/
}
