# Maintainer: AndyRTR <andyrtr@archlinux.org>
# Contributor: tobias <tobias@archlinux.org>
# Contributor: Low Kian Seong <fastmail_low@speedymail.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - drop valgrind makedepend

pkgname=bogofilter
pkgver=1.2.5
pkgrel=2
pkgdesc="A fast Bayesian spam filtering tool"
arch=('x86_64')
license=('GPL3')
url="https://bogofilter.sourceforge.io/"
depends=('db' 'perl' 'gsl') # 'sqlite'
makedepends=('xmlto')
backup=('etc/bogofilter/bogofilter.cf')
source=(https://downloads.sourceforge.net/project/${pkgname}/${pkgname}-stable/${pkgname}-${pkgver}.tar.xz{,.asc}) # asc file doesn't  work with pacman
sha1sums=('c779c3afb3e57ae0208ee503a854aff716b0cafd'
          'SKIP')
validpgpkeys=('DC4A655BD993CD4871FA8210E412B156EFF3855A') # "Matthias Andree <mandree@FreeBSD.org>"

# keep Berkeley DB as backend for now
# sqlite3 based backend doesn't allow
# to use db-transaction option that is
# used to bf_compact the wordlist.db
# other backend aren't available 
# currently in Arch repos
# as of 1.2.5 new backend can be KyotoCabinet and lmdb

build() {
  cd "${pkgname}"-${pkgver}
  ./configure --prefix=/usr \
              --sysconfdir=/etc/bogofilter  \
              --localstatedir=/var \
              --enable-transactions \
              --with-database=db  #--help
  make
}

check() {
  cd "$pkgname"-$pkgver
  BF_RUN_VALGRIND=1 make -k -C src check || /bin/true
}

package() {
  cd "${pkgname}"-${pkgver}
  make DESTDIR="${pkgdir}" install

  mv "${pkgdir}/etc/bogofilter/bogofilter.cf.example" "${pkgdir}/etc/bogofilter/bogofilter.cf"

  install -dm755 "${pkgdir}/usr/share/${pkgname}/contrib"
  install -m644 contrib/* "${pkgdir}/usr/share/${pkgname}/contrib/"
}