# $Id: Portfile 87491 2011-11-23 15:41:23Z jmr@macports.org $

PortSystem          1.0
PortGroup           perl5 1.0

perl5.setup         Mail-SpamAssassin 3.2.5
revision            5
categories-append   mail
license             Apache-2
platforms           darwin
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            http://spamassassin.apache.org/

checksums           md5 7fdc1651d0371c4a7f95ac9ae6f828a6 \
                    sha1 14b1f6eae0221a152176f7f597f55581445e800a \
                    rmd160 5a72a97d124e72ff4da1627982748377f1e34128

if {${perl5.major} != ""} {
depends_lib-append  port:p${perl5.major}-digest-sha1 \
                    port:p${perl5.major}-html-parser \
                    port:p${perl5.major}-mailtools \
                    port:p${perl5.major}-mail-audit \
                    port:p${perl5.major}-net-dns \
                    port:p${perl5.major}-net-ident \
                    port:p${perl5.major}-archive-tar \
                    port:p${perl5.major}-io-zlib \
                    port:p${perl5.major}-io-compress \
                    port:p${perl5.major}-ip-country \
                    port:p${perl5.major}-time-hires \
                    port:p${perl5.major}-mail-dkim \
                    port:p${perl5.major}-mail-spf \
                    port:p${perl5.major}-libwww-perl

startupitem.create      yes
startupitem.name        spamd
if {[variant_isset vpopmail]} {
    startupitem.executable  ${prefix}/bin/spamd -l -v -u vpopmail
    patchfiles-append       patch-spamd.raw.diff
} else {
    startupitem.executable  ${prefix}/bin/spamd -l
}

patchfiles          patch-Makefile.PL.diff \
                    patch-FH_DATE_PAST_20XX_bug.diff

post-patch {
    reinplace "s|return ''|return 'PRIV'|" ${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}

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

post-install {
    ui_msg "****************************************************************"
    ui_msg "*                                                              *"
    ui_msg "* If you run spamassassin for the first time, you should copy  *"
    ui_msg "* the following configuration files and remove the .sample     *"
    ui_msg "* extension:                                                   *"
    ui_msg "*                                                              *"
    ui_msg "* cd ${prefix}/etc/mail/spamassassin                          *"
    foreach file ${conf_files} {
        ui_msg "* cp ${file}.sample ${file}                                  *"
    }
    ui_msg "*                                                              *"
    ui_msg "****************************************************************"
}


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

variant ssl description {Encrypt communication from spamc to spamd} {
    depends_lib-append      port: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
}
}
