# -*- 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.21
revision            1
categories          mail
platforms           darwin
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  c8c7e9ca1840e2f78a52b55a3db0eb10f35196a0 \
                    sha256  6a459c1cafd7a1daa5cd137140da60c18c84b5699cd8e7249a79c33342c99d1d

    conflicts       fetchmail-devel
}

subport fetchmail-devel {
    version         6.5.0.beta5
    revision        1

    checksums       rmd160  fd6ec69e643c538c626243f1592121859c78f6da \
                    sha256  25d8dcf6cbbccaf9f407cbcd85df7805b917a3ce9c5215011a719337a5bb86bc

    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

depends_lib         port:gettext \
                    port:kerberos5

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

default_variants    +ssl

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}
}
