# Template file for 'dovecot'
pkgname=dovecot
version=2.2.19
revision=3
build_pie=yes
build_style=gnu-configure
configure_args="--with-moduledir=/usr/lib/dovecot/modules --with-sql=plugin
 --disable-static --with-pam --with-mysql --with-pgsql --with-lucene
 --with-sqlite --with-ssl=openssl --with-ssldir=/etc/dovecot/ssl
 --with-gssapi --with-ldap=plugin --with-zlib --with-bzlib --with-lzma
 --with-lz4 --with-libcap --with-solr --with-docs --sbindir=/usr/bin"
short_desc="IMAP and POP3 server written with security primarily in mind"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
license="LGPL-2.1"
homepage="http://dovecot.org"
distfiles="${homepage}/releases/2.2/${pkgname}-${version}.tar.gz"
checksum=759e1e3f9d907cdaabad1f5fbacc793ca191d234c084bec3bba42966952a4e9f

makedepends="
 lz4-devel zlib-devel bzip2-devel liblzma-devel libressl-devel mit-krb5-devel
 libmysqlclient-devel postgresql-libs-devel sqlite-devel clucene-devel
 libldap-devel libcap-devel pam-devel libcurl-devel expat-devel"

if [ "$CROSS_BUILD" ]; then
	configure_args+="
		i_cv_epoll_works=yes
		i_cv_inotify_works=yes
		i_cv_posix_fallocate_works=yes
		i_cv_signed_size_t=no
		i_cv_gmtime_max_time_t=32
		i_cv_signed_time_t=yes
		i_cv_mmap_plays_with_write=yes
		i_cv_fd_passing=yes
		i_cv_c99_vsnprintf=yes
		i_cv_gssapi_spnego=yes
		lib_cv_va_copy=yes
		lib_cv___va_copy=yes
		lib_cv_va_val_copy=yes"
fi

# For SSL support.
depends="ca-certificates"
system_accounts="dovecot dovenull"
dovecot_homedir="/var/chroot"
dovenull_homedir="/var/chroot"
conf_files="
	/etc/dovecot/conf.d/10-auth.conf
	/etc/dovecot/conf.d/10-director.conf
	/etc/dovecot/conf.d/10-logging.conf
	/etc/dovecot/conf.d/10-mail.conf
	/etc/dovecot/conf.d/10-master.conf
	/etc/dovecot/conf.d/10-ssl.conf
	/etc/dovecot/conf.d/15-lda.conf
	/etc/dovecot/conf.d/20-imap.conf
	/etc/dovecot/conf.d/20-lmtp.conf
	/etc/dovecot/conf.d/20-pop3.conf
	/etc/dovecot/conf.d/90-acl.conf
	/etc/dovecot/conf.d/90-plugin.conf
	/etc/dovecot/conf.d/90-quota.conf
	/etc/dovecot/conf.d/auth-checkpassword.conf.ext
	/etc/dovecot/conf.d/auth-deny.conf.ext
	/etc/dovecot/conf.d/auth-master.conf.ext
	/etc/dovecot/conf.d/auth-passwdfile.conf.ext
	/etc/dovecot/conf.d/auth-sql.conf.ext
	/etc/dovecot/conf.d/auth-static.conf.ext
	/etc/dovecot/conf.d/auth-system.conf.ext
	/etc/dovecot/conf.d/auth-vpopmail.conf.ext
	/etc/dovecot/dovecot.conf
	/etc/ssl/dovecot-openssl.cnf"

post_install() {
	local econfdir=usr/share/doc/dovecot/example-config
	local econfdird=${econfdir}/conf.d

	# install example conf files and ssl.conf
	vmkdir etc/dovecot/conf.d
	install -m644 ${DESTDIR}/${econfdird}/*.conf \
		${DESTDIR}/etc/dovecot/conf.d
	install -m644 ${DESTDIR}/${econfdird}/*.conf.ext \
		${DESTDIR}/etc/dovecot/conf.d
	install -m644 ${DESTDIR}/${econfdir}/dovecot.conf ${DESTDIR}/etc/dovecot
	vinstall doc/dovecot-openssl.cnf 644 etc/ssl
	vinstall doc/mkcert.sh 755 usr/bin dovecot-mkcert.sh
	rm ${DESTDIR}/etc/dovecot/README

	vsv dovecot
}

dovecot-devel_package() {
	depends="dovecot>=${version}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/share/aclocal
		vmove usr/lib/dovecot/dovecot-config
	}
}
dovecot-plugin-ldap_package() {
	depends="dovecot>=${version}"
	short_desc+=" - LDAP plugin"
	conf_files="/etc/dovecot/conf.d/auth-ldap.conf.ext"
	pkg_install() {
		vmove usr/lib/dovecot/modules/auth/libauthdb_ldap.so
		vmove usr/share/doc/dovecot/example-config/conf.d/auth-ldap.conf.ext
		vmove etc/dovecot/conf.d/auth-ldap.conf.ext
	}
}
dovecot-plugin-lucene_package() {
	depends="dovecot>=${version}"
	short_desc+=" - Full Text Search plugin (Lucene)"
	pkg_install() {
		vmove usr/lib/dovecot/modules/doveadm/lib20_doveadm_fts_lucene_plugin.so
		vmove usr/lib/dovecot/modules/lib21_fts_lucene_plugin.so
	}
}
dovecot-plugin-mysql_package() {
	depends="dovecot>=${version}"
	short_desc+=" - MySQL plugin"
	pkg_install() {
		vmove usr/lib/dovecot/modules/auth/libdriver_mysql.so
		vmove usr/lib/dovecot/modules/dict/libdriver_mysql.so
		vmove usr/lib/dovecot/modules/libdriver_mysql.so
	}
}
dovecot-plugin-pgsql_package() {
	depends="dovecot>=${version}"
	short_desc+=" - PostgreSQL plugin"
	pkg_install() {
		vmove usr/lib/dovecot/modules/auth/libdriver_pgsql.so
		vmove usr/lib/dovecot/modules/dict/libdriver_pgsql.so
		vmove usr/lib/dovecot/modules/libdriver_pgsql.so
	}
}
dovecot-plugin-sqlite_package() {
	depends="dovecot>=${version}"
	short_desc+=" - SQLite plugin"
	pkg_install() {
		vmove usr/lib/dovecot/modules/auth/libdriver_sqlite.so
		vmove usr/lib/dovecot/modules/dict
		vmove usr/lib/dovecot/modules/libdriver_sqlite.so
	}
}
