# -*- 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
# $Id: Portfile 88136 2011-12-20 17:00:37Z pixilla@macports.org $

PortSystem          1.0

name                amavisd-new
version             2.7.0
categories          mail
maintainers         pixilla openmaintainer
platforms           darwin
supported_archs     noarch

description         amavisd-new is a high-performance interface between mailer (MTA) and content \
                    checkers: virus scanners, and/or SpamAssassin.
long_description    ${description} It is written in Perl for maintainability, without paying a \
                    significant price for speed. It talks to MTA via (E)SMTP or LMTP, or by using \
                    helper programs. Best with Postfix, fine with dual-sendmail setup and Exim v4, \
                    works with sendmail/milter, or with any MTA as a SMTP relay. For Courier and \
                    qmail MTA integration there is a patch in the distributed package.
homepage            http://www.ijs.si/software/amavisd/
master_sites        ${homepage}

checksums           rmd160  b869dd41cfd56b1855a42edc285276016f663c5c \
                    sha256  534b3d91c31e0e87a73602c84dfeb4b30b4ea64dee99fcceabd59b1bc0082b0b

depends_run         port:perl5 \
                    port:p5.12-archive-zip \
                    port:p5.12-berkeleydb \
                    port:p5.12-convert-tnef \
                    port:p5.12-convert-uulib \
                    port:p5.12-digest-md5 \
                    port:p5.12-io-compress \
                    port:p5.12-io-stringy \
                    port:p5.12-mail-dkim \
                    port:p5.12-mailtools \
                    port:p5.12-mime-tools \
                    port:p5.12-mime-base64 \
                    port:p5.12-net-server \
                    port:p5.12-time-hires \
                    port:p5.12-unix-syslog \
                    port:p5.12-mail-spamassassin \
                    port:p5.12-dbd-mysql \
                    port:p5.12-mail-clamav \
                    port:clamav \
                    port:clamav-server

set daemon_user     _amavisd
set daemon_group    _amavisd
set amavisd_home    ${prefix}/var/amavis

post-patch {
    reinplace "s|#!/usr/bin/perl|#!${prefix}/bin/perl5.12|" \
              ${worksrcpath}/amavisd
    file copy ${worksrcpath}/amavisd.conf ${worksrcpath}/amavisd.conf.example
    reinplace "s|\$daemon_user\  =\ 'vscan'|\$daemon_user\  =\ '${daemon_user}'|" \
              ${worksrcpath}/amavisd.conf.example
    reinplace "s|\$daemon_group\ =\ 'vscan'|\$daemon_group\  =\ '${daemon_group}'|" \
              ${worksrcpath}/amavisd.conf.example
    reinplace "s|#\ \$MYHOME\ =\ '/var/amavis'|\$MYHOME\ =\ '${amavisd_home}'|" \
              ${worksrcpath}/amavisd.conf.example
    reinplace "s|\$QUARANTINEDIR\ =\ '/var/virusmails'|\$QUARANTINEDIR\ =\ '${amavisd_home}/quarantine'|" \
              ${worksrcpath}/amavisd.conf.example
}

use_configure       no

build               {}

destroot {
    if { ![existsgroup ${daemon_group}]} {
        addgroup ${daemon_group}
    }
    if { ![existsuser ${daemon_user}]} {
        set gid ${daemon_group}
        adduser ${daemon_user} gid=${gid} realname="AMaViS Daemon" home=${amavisd_home}
    }
    xinstall -m 750 -o ${daemon_user} -g ${daemon_group} \
        ${worksrcpath}/amavisd \
        ${destroot}${prefix}/sbin/amavisd
    xinstall -m 640 -o root -g ${daemon_group} \
        ${worksrcpath}/amavisd.conf.example \
        ${destroot}${prefix}/etc/amavisd.conf.example
    xinstall -m 750 -o ${daemon_user} -g ${daemon_group} -d \
        ${destroot}${amavisd_home} \
        ${destroot}${amavisd_home}/tmp \
        ${destroot}${amavisd_home}/var \
        ${destroot}${amavisd_home}/db \
        ${destroot}${amavisd_home}/home \
        ${destroot}${amavisd_home}/quarantine
    xinstall -m 640 -o ${daemon_user} -g ${daemon_group} \
        /dev/null \
        ${destroot}${amavisd_home}/tmp/.turd_${name}
    xinstall -m 640 -o ${daemon_user} -g ${daemon_group} \
        /dev/null \
        ${destroot}${amavisd_home}/var/.turd_${name}
    xinstall -m 640 -o ${daemon_user} -g ${daemon_group} \
        /dev/null \
        ${destroot}${amavisd_home}/db/.turd_${name}
    xinstall -m 640 -o ${daemon_user} -g ${daemon_group} \
        /dev/null \
        ${destroot}${amavisd_home}/home/.turd_${name}
    xinstall -m 640 -o ${daemon_user} -g ${daemon_group} \
        /dev/null \
        ${destroot}${amavisd_home}/quarantine/.turd_${name}
    copy ${worksrcpath} ${destroot}${prefix}/share/${name}
}

livecheck.url       ${master_sites}
livecheck.type      regex
livecheck.regex     "${name}-(\\d+\\.\\d+(\[0-9rc.\]+)?)${extract.suffix}"
