# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                courier-imap
version             6.0.1
revision            0
categories          mail
license             {GPL-3 OpenSSLException}
maintainers         nomaintainer
description         IMAP server
long_description    This package contains the standalone Courier IMAP server, \
                    which is used to provide IMAP access to local mailboxes. \
                    Courier-IMAP is provided here as a separate package that \
                    can be used with other mail servers as well.

homepage            https://www.courier-mta.org/imap
master_sites        sourceforge:project/courier/imap/${version} freebsd
use_bzip2           yes
checksums           rmd160  f3e3ec44a9624a07eeab144bd37d70a22bc1a939 \
                    sha256  3f422328e2ad6e9ad5bcabcc8034810630be0001820111ec5a4af045874a9de2 \
                    size    3747961

compiler.cxx_standard   2017

patchfiles-append   patch-makefile.diff

# https://github.com/svarshavchik/courier/issues/79
patchfiles-append   patch-maildircache.h.diff

depends_build-append \
                    path:bin/pkg-config:pkgconfig \
                    path:libexec/coreutils/libstdbuf.so:coreutils

depends_lib-append  port:courier-authlib \
                    port:db48 \
                    port:libidn2 \
                    path:lib/libssl.dylib:openssl

set authdaemondir   ${prefix}/var/run/authdaemon.courier-imap

configure.args      --bindir=${prefix}/bin \
                    --datadir=${prefix}/share/${name} \
                    --disable-root-check \
                    --enable-unicode \
                    --localstatedir=${prefix}/var/run \
                    --mandir=${prefix}/share/man \
                    --sysconfdir=${prefix}/etc/${name} \
                    --with-authdaemonvar=${authdaemondir} \
                    --with-db=db \
                    --with-notice=unicode \
                    --with-piddir=${prefix}/var/run

configure.cflags    "-I${prefix}/include/db48 -I${prefix}/include"
configure.cppflags  "-I${prefix}/include/db48 -I${prefix}/include"
configure.ldflags   "-L${prefix}/lib/db48 -L${prefix}/lib"

destroot.target     install install-configure

post-destroot {
    xinstall -m 0755 -d ${destroot}${authdaemondir}
    destroot.keepdirs ${destroot}${authdaemondir}
}

startupitem.create  yes
startupitem.init    \
". ${prefix}/etc/courier-imap/imapd\n. ${prefix}/etc/courier-imap/imapd-ssl\n"
startupitem.start   "${prefix}/libexec/imapd-ssl.rc start"
startupitem.stop    "${prefix}/libexec/imapd-ssl.rc stop"

test.run            no
test.ignore_archs   yes

# Limit the length of the minor and patch version components to avoid picking
# up development versions (that contain a YYYYMMDD timestamp).
livecheck.regex     "[quotemeta ${name}]-(\\d+(\\.\\d{1,7})*)[quotemeta ${extract.suffix}]"
