# Contributor: Michael Mason <ms13sp@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=fetchmail
pkgver=6.5.2
pkgrel=0
pkgdesc="remote-mail retrieval and forwarding utility"
url="https://www.fetchmail.info/"
arch="all"
license="GPL-2.0-or-later WITH OpenSSL-Exception AND Public-Domain"
pkgusers="fetchmail"
pkggroups="fetchmail"
makedepends="openssl-dev>3 python3"
install="fetchmail.pre-install"
subpackages="
	$pkgname-doc
	$pkgname-openrc
	fetchmailconf::noarch
	"
source="https://downloads.sourceforge.net/fetchmail/fetchmail-$pkgver.tar.xz
	$pkgname.initd
	$pkgname.confd
	"

# secfixes:
#   6.4.22-r0:
#     - CVE-2021-39272
#   6.4.20-r0:
#     - CVE-2021-36386

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--with-ssl \
		--disable-nls \
		--enable-POP3 \
		--enable-IMAP \
		--without-hesiod \
		--enable-ETRN \
		--enable-NTLM \
		--enable-SDPS \
		--enable-RPA \
		--without-kerberos5 \
		--without-gssapi \
		--enable-fallback=no
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -o fetchmail -g fetchmail -d "$pkgdir"/var/lib/fetchmail \
		"$pkgdir"/var/run/fetchmail
}

fetchmailconf() {
	depends="python3 python3-tkinter"
	pkgdesc="GUI for generating fetchmail configuration files"
	install=""

	amove usr/bin/fetchmailconf*
	amove usr/lib/python3*/site-packages/fetchmailconf.py*
	amove usr/lib/python3*/site-packages/__pycache__/fetchmailconf*
}

sha512sums="
77c630919982b0e95d1f691f6fbdcee75582a072133a3fbcedf8cf9528b4148e75b66743ecac8948b7cb2304315af13b9dc30b2464d52143a3ab4d8afd7f0451  fetchmail-6.5.2.tar.xz
9520ec6616f4004d091b1c908d3ea38e104ad8f6595959a3cd3ef7544d05e3b75854631289e167ead08479250d04584d3f1855668a7a0ebd16a1ee9106f3b0b3  fetchmail.initd
6f031ec6bd4a3ae53cd04fbd8470f4d10bd46ca29cabffa634a6801aa2e7707169855fbc045ced3c9a69523e694511a3f076b611678143e49339c8ccac98074e  fetchmail.confd
"
