# $Id: Portfile 62397 2010-01-06 14:48:18Z ryandesign@macports.org $

PortSystem          1.0
PortGroup           perl5 1.0

perl5.setup         Mail-SpamAssassin 3.2.5
revision            3
categories-append   mail
platforms           darwin
maintainers         simon openmaintainer
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

depends_lib-append  port:p5-digest-sha1 \
                    port:p5-html-parser \
                    port:p5-mailtools \
                    port:p5-mail-audit \
                    port:p5-net-dns \
                    port:p5-net-ident \
                    port:p5-archive-tar \
                    port:p5-io-zlib \
                    port:p5-io-compress \
                    port:p5-ip-country \
                    port:p5-time-hires \
                    port:p5-mail-dkim \
                    port:p5-mail-spf \
                    port:p5-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:p5-razor-agents
    configure.args-append   RUN_RAZOR_TESTS=yes
}

variant ssl description {Encrypt communication from spamc to spamd} {
    depends_lib-append      port:openssl \
                            port:p5-io-socket-ssl
    configure.args-append   ENABLE_SSL=yes
}

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