# Contributor: Shiz <hi@shiz.me>
# Maintainer: Shiz <hi@shiz.me>
pkgname=mailutils
pkgver=3.17
pkgrel=0
pkgdesc="GNU swiss army knife of electronic mail handling"
url="https://mailutils.org/"
arch="all"
license="GPL-3.0-or-later"
replaces="mailx"
depends_dev="$pkgname-libs=$pkgver-r$pkgrel"
makedepends="
	libunistring-dev
	libtool
	gnutls-dev
	readline-dev
	"
checkdepends="autoconf netcat-openbsd"
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs $pkgname-servers $pkgname-mh"
source="https://ftp.gnu.org/gnu/mailutils/mailutils-$pkgver.tar.xz
	disable-koi8-r-test.patch
	"
# they pretty much all pass, but the test suite takes an hour
options="!check"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr
	make
}

check() {
	# Exclude imap4d tests as they require chdir("/root") which won't work.
	sed -i 's/$(IMAP4D_DIR)/# $(IMAP4D_DIR)/g' Makefile
	make check
}

package() {
	# re-enable imap4d subdirectory for install
	sed -i 's/# $(IMAP4D_DIR)/$(IMAP4D_DIR)/g' Makefile
	make DESTDIR="$pkgdir" install

	cd "$pkgdir"
	# rm usr/lib/charset.alias
	# No need for these to be suid/sgid root.
	chmod u-s usr/sbin/mda
	chmod g-s usr/bin/dotlock
}

libs() {
	pkgdesc="$pkgdesc (libraries)"

	amove usr/lib
}

servers() {
	pkgdesc="$pkgdesc (servers)"

	amove \
		usr/sbin/pop3d \
		usr/sbin/imap4d \
		usr/sbin/comsatd
}

mh() {
	pkgdesc="$pkgdesc (MH compatibility)"

	amove usr/bin/mu-mh \
		usr/share/mailutils/mh
}

sha512sums="
e4080d9674444c3e077aa72f825a0373a4750d187a04a488449e89f6fec19d9309a118412e91745575eb90d05fa541f8d2626a8fd5e8ac10710aa1f7a0ff3193  mailutils-3.17.tar.xz
fd628287a8b70b84e4fe477f3fed157308f1a0e803dfd65390d90a7ad40023155559b284e29ceb95dd3c854fce4e3a22a651d8de99b49db7c9d4b3682003cf2c  disable-koi8-r-test.patch
"
