# -*- 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
PortGroup           perl5 1.0

perl5.branches      5.28 5.30 5.32 5.34
perl5.setup         Mail-SpamAssassin 4.0.2
revision            1
categories-append   mail
license             Apache-2
maintainers         nomaintainer
description         mail filter to identify spam
long_description    SpamAssassin(tm) is a mail filter to identify spam. \
                    Using its rule base, it uses a wide range of \
                    heuristic tests on mail headers and body text to \
                    identify spam, also known as unsolicited commercial \
                    email.

homepage            https://spamassassin.apache.org/

checksums           rmd160 294deb37f1c5e1c51df8214e67188a978f5afec9\
                    sha256 c521be978cef3d49b1e139477ca60a0bd498345fc98274796e44161fae49a17f\
                    size   6833828

if {${perl5.major} != ""} {
    depends_build-append \
                    port:p${perl5.major}-devel-cycle \
                    port:p${perl5.major}-test-simple \
                    port:p${perl5.major}-text-diff

    depends_lib-append \
                    port:curl \
                    path:bin/gpg:gnupg2 \
                    port:re2c \
                    port:p${perl5.major}-archive-tar \
                    port:p${perl5.major}-berkeleydb \
                    port:p${perl5.major}-dbi \
                    port:p${perl5.major}-dbd-sqlite \
                    port:p${perl5.major}-encode-detect \
                    port:p${perl5.major}-email-address-xs \
                    port:p${perl5.major}-geo-ip \
                    port:p${perl5.major}-html-parser \
                    port:p${perl5.major}-io-compress \
                    port:p${perl5.major}-io-socket-ip \
                    port:p${perl5.major}-io-string \
                    port:p${perl5.major}-libwww-perl \
                    port:p${perl5.major}-lwp-protocol-https \
                    port:p${perl5.major}-mail-dkim \
                    port:p${perl5.major}-mail-spf \
                    port:p${perl5.major}-mime-base64 \
                    port:p${perl5.major}-net \
                    port:p${perl5.major}-netaddr-ip \
                    port:p${perl5.major}-net-cidr-lite \
                    port:p${perl5.major}-net-dns \
                    port:p${perl5.major}-net-libidn \
                    port:p${perl5.major}-net-libidn2 \
                    port:p${perl5.major}-net-patricia \
                    port:p${perl5.major}-time-hires \
                    port:p${perl5.major}-time-local

    startupitem.create      yes
    startupitem.name        spamd

    if {[variant_isset vpopmail]} {
        startupitem.executable  ${perl5.bindir}/spamd -l -v -u vpopmail
    } else {
        startupitem.executable  ${perl5.bindir}/spamd -l
    }

    patchfiles      patch-Makefile.PL.diff

    post-patch {
        reinplace "s|return ''|return 'PRIV'|" ${worksrcpath}/Makefile.PL
        reinplace "s|__MP_RE2C_BIN__|${prefix}/bin/re2c|" ${worksrcpath}/Makefile.PL
    }

    configure.args-append \
                    CONTACT_ADDRESS=root@localhost \
                    PREFIX=${prefix} \
                    SYSCONFDIR=${prefix}/etc \
                    DATADIR=${prefix}/share/spamassassin \
                    LOCALSTATEDIR=${prefix}/var/spamassassin \
                    CONFDIR=${prefix}/etc/mail/spamassassin

    destroot.target-append conf__install data__install

# All configuration files for spamassassin.
    set conf_files  {init.pre local.cf v310.pre v312.pre v320.pre v330.pre v340.pre v341.pre v342.pre}

    post-destroot {
        set etc ${destroot}${prefix}/etc/mail/spamassassin
        foreach file ${conf_files} {
            file rename ${etc}/${file} ${etc}/${file}.sample
        }

        set docdir ${prefix}/share/doc/spamassassin
        xinstall -d ${destroot}${docdir}
        xinstall -m 0644 -W ${worksrcpath} \
            README CREDITS INSTALL LICENSE NOTICE \
            PACKAGING TRADEMARK UPGRADE USAGE Changes \
            ${destroot}${docdir}
        xinstall -d ${destroot}${docdir}/sql
        xinstall -m 0644 -W ${worksrcpath}/sql \
            README README.awl README.bayes awl_mysql.sql awl_pg.sql \
            bayes_mysql.sql bayes_pg.sql userpref_mysql.sql userpref_pg.sql \
            ${destroot}${docdir}/sql

        set exdir ${prefix}/share/examples/spamassassin
        xinstall -d ${destroot}${exdir}
        xinstall -m 0644 -W ${worksrcpath} \
            procmailrc.example sample-nonspam.txt sample-spam.txt \
            ${destroot}${exdir}
    }

    set conf_file_notes {}
    foreach file ${conf_files} {
        append conf_file_notes "cp ${file}.sample ${file}\n"
    }

    notes "If you're running spamassassin for the first time, you should copy the\
following configuration files and remove the .sample extension:\n\ncd\
${prefix}/etc/mail/spamassassin\n${conf_file_notes}"

    variant razor description {Use Vipuls Razor module} {
        depends_lib-append      port:p${perl5.major}-razor2-client-agent
        configure.args-append   RUN_RAZOR_TESTS=yes
    }

    variant ssl description {Encrypt communication from spamc to spamd} {
        depends_lib-append  path:lib/libssl.dylib:openssl \
                            port:p${perl5.major}-io-socket-ssl
        configure.args-append ENABLE_SSL=yes
    }

    variant vpopmail description {Use Spamassassin with vpopmail} {
        depends_lib-append      port:vpopmail
    }

    default_variants +ssl
}
