# Maintainer: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Stéphane Gaudreault <stephane@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s@arch@gmail.com>
# Contributor: Andreas Wagner <Andreas.Wagner@em.uni-frankfurt.de>

pkgname=s-nail
pkgver=14.9.24
pkgrel=2
pkgdesc='Environment for sending and receiving mail'
url='https://www.sdaoden.eu/code.html#s-nail'
license=('custom:BSD')
arch=('x86_64')
depends=('openssl' 'krb5' 'libidn2')
optdepends=('smtp-forwarder: for sending mail')
validpgpkeys=('EE19E1C1F2F7054F8D3954D8308964B51883A0DD')
source=("https://www.sdaoden.eu/downloads/${pkgname}-${pkgver}.tar.xz"{,.asc})
sha512sums=('03f6a6f446391b6f91ed3c8875c3e7fdfac9d4e77ea1d52a7e98aa84cfd0edae137d5b9afba3bdc9a31ab67cee5237930b74b42ae3acb54aee4758553a4f1df2'
            'SKIP')

backup=('etc/mail.rc')
replaces=('mailx' 'mailx-heirloom' 'heirloom-mailx')
provides=('mailx' 'mailx-heirloom' 'heirloom-mailx')
conflicts=('mailx' 'mailx-heirloom' 'heirloom-mailx')

build() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	export CFLAGS+=" $CPPFLAGS"
	make \
		VAL_PREFIX=/usr \
		VAL_SYSCONFDIR=/etc \
		VAL_LIBEXECDIR=/usr/lib \
		VAL_MAIL=/var/spool/mail \
		VAL_SID= VAL_MAILX=mail \
		OPT_AUTOCC=0 \
		config

	make build
}

check() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	make test
}

package() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	make DESTDIR="${pkgdir}" install
	ln -sf mail "${pkgdir}"/usr/bin/mailx
	ln -sf mail.1.gz "${pkgdir}"/usr/share/man/man1/mailx.1.gz
	install -Dm644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}
