# -*- 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                fetchmail
version             6.4.38
revision            0
categories          mail
license             {GPL-2 OpenSSLException}
maintainers         nomaintainer

description         Batch mail retrieval utility for IMAP, POP2, POP3, \
                    APOP, KPOP, ETRN, or ODMR
long_description \
    Fetchmail is a full-featured IMAP, POP2, POP3, \
    APOP, KPOP, ETRN, ODMR client with easy \
    configuration, daemon mode, forwarding via SMTP \
    or local MDA, and superior reply handling.  It \
    is used to handle intermittent email connections \
    by acting as a coupling that seamlessly batch \
    forwards fetched mail from your mail server to \
    your local delivery system, allowing you to read \
    your it with your favourite mail user agent. \
    Fetchmail also includes useful spam filtering \
    and multi-user functions.  \
    A typical use of fetchmail is to connect to your \
    normal POP3 server, downloading your mail into \
    the INBOX on your local computer.  You may then \
    read the mail, offline if you want, using Pine, \
    mutt, or any standard mail user agent.

if {${name} eq ${subport}} {
    checksums       rmd160  67ce54de96adb6e1f4548a1c25625af1e0f3409a \
                    sha256  a6cb4ea863ac61d242ffb2db564a39123761578d3e40d71ce7b6f2905be609d9 \
                    size    1220892

    conflicts       fetchmail-devel
}

subport fetchmail-devel {
    version         6.5.0.beta5
    revision        1

    checksums       rmd160  fd6ec69e643c538c626243f1592121859c78f6da \
                    sha256  25d8dcf6cbbccaf9f407cbcd85df7805b917a3ce9c5215011a719337a5bb86bc \
                    size    1251904

    conflicts       fetchmail
}

homepage            http://www.fetchmail.info
set branch          [join [lrange [split ${version} .] 0 1] .]
master_sites        sourceforge:project/${name}/branch_${branch}

use_xz              yes

set py_ver          3.12
set py_ver_nodot    [string map {. {}} ${py_ver}]

depends_build-append \
                    port:gettext \
                    port:python${py_ver_nodot}

depends_lib-append  port:gettext-runtime \
                    port:kerberos5 \
                    port:libiconv

configure.python    ${prefix}/bin/python${py_ver}

configure.args-append \
                    --mandir=${prefix}/share/man \
                    --with-gssapi \
                    --with-libiconv-prefix=${prefix} \
                    --with-kerberos5=${prefix} \
                    --without-ssl

default_variants    +ssl

build.env-append    PYTHON=${configure.python}

post-destroot {
    if {![variant_isset fetchmailconf]} {
        system "find ${destroot} -type f -iname '*fetchmailconf*' -delete"
    }
}

startupitem.create  yes
startupitem.start   "${prefix}/bin/fetchmail -f ${prefix}/etc/.fetchmail -d120"
startupitem.stop    "${prefix}/bin/fetchmail -quit"

variant fetchmailconf description "Install a graphical configurator" {
    depends_lib-append      port:py-tkinter
}

variant ntlm description "Enable NTLM authentication" {
    configure.args-append   --enable-NTLM
}

variant ssl description "Support secure connections using OpenSSL" {
    depends_lib-append      path:lib/libssl.dylib:openssl
    configure.args-delete   --without-ssl
    configure.args-append   --with-ssl=${prefix}
}

if {${name} eq ${subport}} {
    livecheck.regex fetchmail-(\\d+(?:\\.\\d+)*)${extract.suffix}
} else {
    livecheck.regex fetchmail-(\\d+(?:\\.\\d+)*(?:\\.beta\\d+)?)${extract.suffix}
}
