# Contributor: Shiz <hi@shiz.me>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=mailutils
pkgver=3.19
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="
	gnutls-dev
	libtool
	libunistring-dev
	readline-dev
	"
checkdepends="
	autoconf
	netcat-openbsd
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-libs
	$pkgname-mh
	$pkgname-servers
	"
source="https://ftp.gnu.org/gnu/mailutils/mailutils-$pkgver.tar.xz
	disable-koi8-r-test.patch
	format-security.patch
	"
# they pretty much all pass, but the test suite takes an hour
options="!check"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var
	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"
	# No need for these to be suid/sgid root.
	chmod -c u-s usr/sbin/mda
	chmod -c g-s usr/bin/dotlock
}

libs() {
	default_libs

	amove usr/lib/mailutils
}

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

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

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

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

sha512sums="
2c92ead287433e13ac66ad07bcc1b726568a6fcbbc3d26a73f7d168947b226d8c56e7472a065f10391353adf494d27a9df21b3b9914d1d8f3b9c1618dbe491f9  mailutils-3.19.tar.xz
fd628287a8b70b84e4fe477f3fed157308f1a0e803dfd65390d90a7ad40023155559b284e29ceb95dd3c854fce4e3a22a651d8de99b49db7c9d4b3682003cf2c  disable-koi8-r-test.patch
4a73fd79d01efcf94dd3f6853afc796521f2867f977b0579a94a81bfc4671bac9173ee2747f6c1296a5a8b1877881036cc31e6c67929b2b7d9c692f05cb9d180  format-security.patch
"
