# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Maintainer:  Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=spamassassin
_pkgreal=Mail-SpamAssassin
pkgver=3.4.1
pkgrel=8
pkgdesc="The Powerful #1 Open-Source Spam Filter"
url="http://search.cpan.org/dist/Mail-SpamAssassin/"
arch="all"
license="Apache-2.0"
cpandepends="perl-html-parser perl-digest-sha1 perl-netaddr-ip perl-net-dns perl-mail-dkim
	perl-mime-base64 perl-db_file perl-time-hires perl-libwww"
cpanmakedepends="$cpandepends"
depends="perl-mail-$pkgname curl"
makedepends="perl-dev $cpanmakedepends"
subpackages="$pkgname-doc $pkgname-client $pkgname-compiler perl-mail-$pkgname:cpan"
source="http://search.cpan.org/CPAN/authors/id/K/KM/KMCGRAIL/${_pkgreal#*-}/$_pkgreal-$pkgver.tar.gz
	spamd.initd
	spamd.confd
	spamd.crond
	net-dns-1.01-compat.patch
	Mail-SpamAssassin.patch
	bad-regexp-and-logic.patch
	"
builddir="$srcdir/$_pkgreal-$pkgver"

build() {
	cd "$builddir"
	rm t/dnsbl_subtests.t
	export CFLAGS="$(perl -MConfig -E 'say $Config{ccflags}')"
	PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor || return 1
	make
}

check() {
	cd "$builddir"
	make test
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install || return 1
	find "$pkgdir" \( -name perllocal.pod -o -name .packlist \) -delete
	install -Dm755 "$srcdir"/spamd.crond "$pkgdir"/etc/periodic/daily/$pkgname-update
	install -Dm755 "$srcdir"/spamd.initd "$pkgdir"/etc/init.d/spamd
	install -Dm644 "$srcdir"/spamd.confd "$pkgdir"/etc/conf.d/spamd
	mkdir -p "$pkgdir"/usr/sbin
	mv "$pkgdir"/usr/bin/spamd "$pkgdir"/usr/sbin/spamd
}

client() {
	depends=""
	pkgdesc="SpamAssassin client"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/spamc "$subpkgdir"/usr/bin
}

compiler() {
	pkgdesc="SpamAssassin rules compiler"
	depends="re2c gcc perl-dev perl-mail-$pkgname"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/sa-compile "$subpkgdir"/usr/bin/
}

cpan() {
	pkgdesc="SpamAssassin perl library"
	depends="perl gnupg $cpandepends"
	mkdir -p "$subpkgdir"/usr "$subpkgdir"/etc "$subpkgdir"/var/lib/$pkgname
	mv "$pkgdir"/etc/mail "$subpkgdir"/etc
	mv "$pkgdir"/usr/lib "$pkgdir"/usr/share "$subpkgdir"/usr
	find "$subpkgdir" -name *.pod -delete
	mv "$subpkgdir"/usr/share/$pkgname/user_prefs.template \
		"$subpkgdir"/etc/mail/$pkgname/user_prefs
	sed -i '/^#\*/d' "$subpkgdir"/etc/mail/$pkgname/user_prefs
}

sha512sums="6a074f1a4177e1969cef575fe3b1b844d27c813d48fe1e07a46f56ffa728fc780897597d00f11acb269317a6308f284f0dee544d504da874d93b0549d094a6a3  Mail-SpamAssassin-3.4.1.tar.gz
0a22933290a3abd147689bf3a9de4b6b277628c22966f353c5da932cd98560babf1d0bb9d92c456ea24decfb5af0bbc960192d29a90d9cab437e7986c75c8278  spamd.initd
274d3aa0d9aab05e83c8d5ad3e93a457649360021a67c8cb19088365bed681ebe26889cfa86f8c46a6044c7ee969231f2a71e3227adf8ad9e38d0286b9caf48d  spamd.confd
c8c00e4281cefd5e5e15507c8890264a25aa59663c57ccdf7a77905e2550999cfbbfa7271189a9491b0a0e98dff432361f13becdb99e1b583cd9d45d68022a47  spamd.crond
7651b0b6a13322ecc338cd43ef67246c02c846162d419e3d1586e2d53161fc055d1ba80800f5210658cc360ac3ccd3c2176f1463780b0486ec65c0bac3b338fd  net-dns-1.01-compat.patch
66a6daa7e9898864497e7d8e17efc6094aabc5a9a94afbc7da08acf4cf2430fad2cb0128b8db4be637f5dcabe3fa9f03490f9d7cbba3c1cc02b7824f63cd0965  Mail-SpamAssassin.patch
fef24813fd643bcc3d945b1d53145c9290e8567ea4ed9c39a31cc0b0381a3949ef82840383f0c7dd4ac641f9dace6c08e39cf39e32b9906dc865f2fce1770c06  bad-regexp-and-logic.patch"
