# -*- 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

name                postgrey
version             1.37
revision            0
categories          mail
license             GPL-2
maintainers         nomaintainer
description         Postfix policy server implementing greylisting
long_description    When a request for delivery of a mail is received by \
                    Postfix via SMTP, the triplet CLIENT_IP / SENDER / RECIPIENT \
                    is built. If it is the first time that this triplet is seen, \
                    or if the triplet was first seen, less than 5 minutes ago, \
                    then the mail gets rejected with a temporary error. Hopefully\
                    spammers or viruses will not try again later, as it is \
                    however required per RFC.
supported_archs     noarch
platforms           any
homepage            http://postgrey.schweikert.ch/
master_sites        ${homepage}pub \
                    ${homepage}pub/old

checksums           rmd160  ec148e96d3d70e26d25f12f8fdf842f8c7444e60 \
                    sha256  ff4d9543f8f5cb0356c30ffe22255d942ac6128da734c376de211c02630fa5f7 \
                    size    41815

perl5.require_variant   yes
perl5.conflict_variants yes
perl5.branches          5.28 5.30 5.32 5.34
perl5.default_branch    5.34
perl5.create_variants   ${perl5.branches}

depends_lib-append  port:p${perl5.major}-berkeleydb \
                    port:p${perl5.major}-io-multiplex \
                    port:p${perl5.major}-net-server

startupitem.create  yes
startupitem.start   "${prefix}/share/postgrey/postgrey.sh start"
startupitem.stop    "${prefix}/share/postgrey/postgrey.sh stop"

configure {
    system "echo all: > ${worksrcpath}/Makefile"
    reinplace "s|/usr/bin/perl|${perl5.bin}|g" \
        ${worksrcpath}/postgrey \
        ${worksrcpath}/contrib/postgreyreport
    reinplace -locale C "s|/etc/postfix|${prefix}/etc/postgrey|g" \
        ${worksrcpath}/postgrey \
        ${worksrcpath}/postgrey_whitelist_clients \
        ${worksrcpath}/postgrey_whitelist_recipients \
        ${worksrcpath}/contrib/postgreyreport
    reinplace "s|/etc/main.cf|postfix's main.cf|g" \
        ${worksrcpath}/postgrey
    reinplace "s|/var/spool/postfix/postgrey|${prefix}/var/spool/postgrey|g" \
        ${worksrcpath}/postgrey \
        ${worksrcpath}/contrib/postgreyreport
}

build.target

add_users   postgrey group=postgrey realname=Postgrey\ Server

destroot {
    file mkdir ${destroot}${prefix}/etc/postgrey
    file mkdir ${destroot}${prefix}/share/postgrey
    file mkdir ${destroot}${prefix}/share/doc/postgrey
    file mkdir ${destroot}${prefix}/share/man/man1
    file mkdir ${destroot}${prefix}/share/man/man8
    xinstall -d -o postgrey -g postgrey -m 750 \
        ${destroot}${prefix}/var/spool/postgrey
    xinstall -d -o postgrey -g postgrey -m 750 \
        ${destroot}${prefix}/var/run/postgrey
    destroot.keepdirs ${destroot}${prefix}/var/spool/postgrey \
        ${destroot}${prefix}/var/run/postgrey \
        ${destroot}${prefix}/etc/postgrey
    system "${prefix}/bin/pod2man-${perl5.major} --section=8 ${worksrcpath}/postgrey > \
        ${destroot}${prefix}/share/man/man8/postgrey.8"
    system "${prefix}/bin/pod2man-${perl5.major} --section=1 ${worksrcpath}/contrib/postgreyreport > \
        ${destroot}${prefix}/share/man/man1/postgreyreport.1"
    xinstall -m 755 -c ${worksrcpath}/contrib/postgreyreport \
        ${destroot}${prefix}/bin/postgreyreport
    xinstall -m 644 -c ${worksrcpath}/README \
        ${worksrcpath}/README.exim \
        ${worksrcpath}/Changes \
        ${worksrcpath}/COPYING \
        ${destroot}${prefix}/share/doc/postgrey
    xinstall -m 644 -c ${filespath}/postgrey.conf \
        ${destroot}${prefix}/etc/postgrey/postgrey.conf.sample
    xinstall -m 755 -c ${filespath}/postgrey.sh \
        ${destroot}${prefix}/share/postgrey
    reinplace "s|__PREFIX|${prefix}|g" \
        ${destroot}${prefix}/share/postgrey/postgrey.sh
    xinstall -m 4755 -o postgrey -g postgrey -c \
        ${worksrcpath}/postgrey \
        ${destroot}${prefix}/sbin/postgrey
    xinstall -m 644 -c \
        ${worksrcpath}/postgrey_whitelist_clients \
        ${destroot}${prefix}/etc/postgrey
    xinstall -m 644 -c \
        ${worksrcpath}/postgrey_whitelist_recipients \
        ${destroot}${prefix}/etc/postgrey/postgrey_whitelist_recipients.default
}

notes "
Postgrey will be running with following default parameters:
  user        : postgrey
  group       : postgrey
  tcp binding : localhost
  tcp port    : 60000

You will find configuration in ${prefix}/etc/postgrey
  postgrey.conf                         : launch options
  postgrey_whitelist_clients            : default clients whitelist
  postgrey_whitelist_clients.local      : customisable clients whitelist
  postgrey_whitelist_recipients         : customisable recipients whitelist
  postgrey_whitelist_recipients.default : default recipients whitelist (unused)

If you are using postfix, you should add to your main.cf a line:
  check_policy_service inet:127.0.0.1:60000
in the smtpd_recipient_restrictions configuration (after
reject_unauth_destination and other rules) and reload postfix daemon.
"
