# $Id: Portfile,v 1.24 2006/08/08 07:07:53 yeled Exp $

PortSystem  1.0
name            postfix
version         2.2.5
categories      mail
maintainers     yeled@opendarwin.org
description     Fast and robust mail transfer agent
long_description    Postfix attempts to be fast, easy to administer, and \
            secure, while at the same time being \
            sendmail-compatible enough to not upset existing \
            users. It also offers QMQP and VERP support to let \
            Postfix act as delivery daemon for ezmlm-idx.
homepage        http://www.postfix.org/
platforms       darwin
checksums       md5 9c13d58494c64012bfd8ab0d6967305c
master_sites    ftp://ftp.tau.ac.il/pub/unix/mail/postfix/official/ \
    http://postfix.problemlos.ch/release/official/ \
    ftp://ftp.matrix.com.br/pub/postfix/official/ \
    ftp://ftp.its.cz/MIRRORS/ftp.porcupine.org/mirrors/postfix-release/official/\
    ftp://ftp.club-internet.fr/pub/mirrors/ftp.porcupine.org/postfix-release/official/\
    ftp://ftp.doc.cs.univ-paris8.fr/mirrors/ftp.porcupine.org/postfix-release/official/

patchfiles      patch-access.5 patch-flush.8 patch-master.8 \
        patch-regexp_table.5 patch-sys_defs.h patch-canonical.5 \
        patch-mail_params.h patch-pcre_table.5 patch-postdrop.1 \
        patch-postqueue.1 patch-relocated.5 patch-transport.5 \
        patch-cleanup.8 patch-main.cf patch-postfix-install \
        patch-proxymap.8 patch-sendmail.1 \
        patch-virtual.5
#patch-sample-misc.cf 

build.env   CCARGS=-DNO_PCRE

configure {
    cd ${worksrcpath}
    reinplace "s|__PREFIX|${prefix}|g" src/util/sys_defs.h
    reinplace "s|__PREFIX|${prefix}|g" conf/main.cf
    reinplace "s|__PREFIX|${prefix}|g" src/global/mail_params.h
    reinplace "s|__PREFIX|${prefix}|g" man/man1/postdrop.1
#   reinplace "s|__PREFIX|${prefix}|g" conf/sample-misc.cf
    reinplace "s|__PREFIX|${prefix}|g" man/man1/postqueue.1
    reinplace "s|__PREFIX|${prefix}|g" man/man1/sendmail.1
    reinplace "s|__PREFIX|${prefix}|g" man/man5/access.5
    reinplace "s|__PREFIX|${prefix}|g" man/man5/canonical.5
    reinplace "s|__PREFIX|${prefix}|g" man/man5/pcre_table.5
    reinplace "s|__PREFIX|${prefix}|g" man/man5/regexp_table.5
    reinplace "s|__PREFIX|${prefix}|g" man/man5/relocated.5
    reinplace "s|__PREFIX|${prefix}|g" man/man5/transport.5
    reinplace "s|__PREFIX|${prefix}|g" man/man5/virtual.5
    reinplace "s|__PREFIX|${prefix}|g" man/man8/cleanup.8
    reinplace "s|__PREFIX|${prefix}|g" man/man8/flush.8
    reinplace "s|__PREFIX|${prefix}|g" man/man8/master.8
    reinplace "s|__PREFIX|${prefix}|g" man/man8/proxymap.8
}

build.target

startupitem.create      yes
startupitem.start       ${prefix}/sbin/${name}
startupitem.stop        "/bin/kill \$(cat ${prefix}/var/run/${name}.pid)"

destroot {
    adduser postfix realname=Postfix\ Server
    addgroup postdrop
    cd ${worksrcpath}
    file mkdir ${destroot}${prefix}/etc/postfix
    file mkdir ${destroot}${prefix}/etc/rc.d
    file mkdir ${destroot}${prefix}/share/postfix
    xinstall -d -m 755 ${destroot}${prefix}/etc/rc.d
    xinstall -d -o postfix -g postdrop -m \
        710 ${destroot}${prefix}/var/spool/postfix/public
    xinstall -d -o postfix -g postdrop -m 730 \
        ${destroot}${prefix}/var/spool/postfix/maildrop
    destroot.keepdirs ${destroot}${prefix}/var/spool/postfix/public \
        ${destroot}${prefix}/var/spool/postfix/maildrop
    system "/bin/sh postfix-install -non-interactive \
        install_root=${destroot} \
        config_directory=${prefix}/etc/postfix \
        daemon_directory=${prefix}/libexec \
        command_directory=${prefix}/sbin \
        manpage_directory=${prefix}/share/man \
        queue_directory=${prefix}/var/spool/postfix \
        sendmail_path=${prefix}/sbin/sendmail \
        newaliases_path=${prefix}/bin/newaliases \
        mailq_path=${prefix}/bin/mailq \
        sample_directory=${prefix}/share/postfix/sample \
        readme_directory=${prefix}/share/postfix/readme"
    xinstall -m 755 -c ${portpath}/files/postfix.sh ${destroot}${prefix}/etc/rc.d
    reinplace "s|__PREFIX|${prefix}|g" ${destroot}${prefix}/etc/rc.d/postfix.sh
}
# This makes sure we don't overwrite user /etc files. This now breaks postfix
# "just working" on fresh installs.
# YOU MUST MOVE THE SAMPLE FILES TO THE CORRECT NAMESPACE.
# XXX unsure if this stilll an issue 07/07/05 yeled@
post-destroot { 
    file rename ${destroot}${prefix}/etc/postfix/main.cf \
        ${destroot}${prefix}/etc/postfix/main.cf.sample
    file rename ${destroot}${prefix}/etc/postfix/master.cf \
        ${destroot}${prefix}/etc/postfix/master.cf.sample
    file rename ${destroot}${prefix}/etc/postfix/aliases \
        ${destroot}${prefix}/etc/postfix/aliases.sample
}

post-install {
    # Tell the user about the renaming of the configuration files.
    ui_msg "To get postfix working, you need to copy sample configuration "
    ui_msg "files and to edit them (${prefix}/etc/postfix/*.sample)."
    ui_msg "You may also want to turn your system's MTA off."
}

variant pcre {
    depends_lib-append  lib:libpcre:pcre
    build.env-delete    CCARGS=-DNO_PCRE
}

platform darwin 7 {
    build.env-append CCARGS=-DBIND_8_COMPAT
}
