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

name                imap-uw
version             2007f
revision            3
categories          mail
platforms           darwin
license             Apache-2
maintainers         nomaintainer

description         University of Washington IMAP daemon
long_description    IMAP (Internet Message Access Protocol) is a method \
                    of accessing electronic messages kept on a (possibly \
                    shared) mail server. This port provides the \
                    University of Washington IMAP toolkit (IMAP \
                    supporting software developed by the UW).

homepage            http://www.washington.edu/imap/
master_sites        ftp://ftp.cac.washington.edu/imap/ \
                    ftp://ftp.cac.washington.edu/imap/old/

distname            imap-${version}
extract.suffix      .tar.Z

checksums           rmd160  14f40284e9e164c0ed7677f1e5d8e3309c7c58c1 \
                    sha256  870e95f6bd19265832a88fd89b77c54c841c59022fd21e69254050c8b1005e3c \
                    size    2793529

depends_lib         port:gss \
                    lib:libgssapi_krb5:kerberos5 \
                    path:lib/libssl.dylib:openssl

patchfiles          patch-Makefile.diff
if {${os.platform} eq "darwin" && ${os.major} >= 10} {
    patchfiles-append   patch-snowleopard.diff
}
post-patch {
    reinplace s|SSLINCLUDE=\/usr|SSLINCLUDE=${prefix}|g ${worksrcpath}/Makefile
    reinplace s|SSLLIB=\/usr|SSLLIB=${prefix}|g ${worksrcpath}/Makefile
    reinplace s|GSSINCLUDE=\/usr|GSSINCLUDE=${prefix}|g ${worksrcpath}/Makefile
    reinplace s|GSSLIB=\/usr|GSSLIB=${prefix}|g ${worksrcpath}/Makefile
    reinplace s|SSLCERTS=\/System\/Library\/OpenSSL|SSLCERTS=${prefix}/etc/openssl|g ${worksrcpath}/Makefile
    reinplace s|SSLKEYS=\/System\/Library\/OpenSSL|SSLKEYS=${prefix}/etc/openssl|g ${worksrcpath}/Makefile
}

use_configure       no
use_parallel_build  no

build.target        osx
# Enable IPv6 support
build.args-append   IP6=6
# Ensure we're UsingTheRightCompiler
build.args-append   CC=${configure.cc}
# Force SSL connections: no unecrypted plaintext authenication
build.args          SSLTYPE=nopwd

variant ssl_plain description {Allow unencrypted plaintext authentication} {
    build.args-delete   SSLTYPE=nopwd
    build.args-append   SSLTYPE=unix
}

destroot {
    # Warn user if not running as root
    if {[geteuid] != 0} {
        ui_msg "-----------------------------------------------------------"
        ui_msg "Note that you are not running as root, so files installed"
        ui_msg "by this port will not end up with proper ownership and"
        ui_msg "will likely not work correctly."
        ui_msg "-----------------------------------------------------------"
    }
    xinstall -m 0755 -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0755 ${worksrcpath}/imapd/imapd ${destroot}${prefix}/libexec
    xinstall -m 0755 ${worksrcpath}/ipopd/ipop2d ${destroot}${prefix}/libexec
    xinstall -m 0755 ${worksrcpath}/ipopd/ipop3d ${destroot}${prefix}/libexec
    xinstall -m 0755 ${worksrcpath}/mailutil/mailutil ${destroot}${prefix}/bin
    xinstall -m 0755 ${worksrcpath}/tmail/tmail ${destroot}${prefix}/bin
    xinstall -m 0755 ${worksrcpath}/dmail/dmail ${destroot}${prefix}/bin
    xinstall -m 0755 ${worksrcpath}/mtest/mtest ${destroot}${prefix}/bin/mboxtest
    if {[geteuid] == 0} {
        xinstall -g mail -m 2711 ${worksrcpath}/mlock/mlock ${destroot}${prefix}/libexec
    } else {
        xinstall -m 0711 ${worksrcpath}/mlock/mlock ${destroot}${prefix}/libexec
    }
    xinstall -m 0755 ${worksrcpath}/src/imapd/imapd.8 ${destroot}${prefix}/share/man/man8
    xinstall -m 0755 ${worksrcpath}/src/ipopd/ipopd.8 ${destroot}${prefix}/share/man/man8
    xinstall -m 0755 ${worksrcpath}/src/mailutil/mailutil.1 ${destroot}${prefix}/share/man/man1
    xinstall -m 0755 ${worksrcpath}/src/tmail/tmail.1 ${destroot}${prefix}/share/man/man1
    xinstall -m 0755 ${worksrcpath}/src/dmail/dmail.1 ${destroot}${prefix}/share/man/man1
    xinstall -m 0644 ${worksrcpath}/docs/RELNOTES ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 ${worksrcpath}/docs/FAQ.html ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 {*}[glob ${worksrcpath}/docs/*.txt] ${destroot}${prefix}/share/doc/${name}
}

# Variant to set the default for creating new mailboxes to "mbx" format
variant mbx conflicts mix description { default new mailboxes to "mbx" format } {
    build.args-append   CREATEPROTO=mbxproto
}

# Variant to set the default for creating new mailboxes to "mix" format
variant mix conflicts mbx description { default new mailboxes to "mix" format } {
    build.args-append   CREATEPROTO=mixproto
}

# Variant to enable SSL with PAM support for Mac OS X
variant ssl_pam description { Enable PAM support } {
    build.target    oxp

    post-destroot {
        xinstall -m 0644 ${filespath}/README-MACOSX \
            ${filespath}/etc-pam.d-imap \
            ${filespath}/etc-xinetd.d-imap \
            ${filespath}/etc-xinetd.d-imaps \
            ${destroot}${prefix}/share/doc/${name}/
        reinplace "s|__PREFIX|${prefix}|" \
            ${filespath}/README-MACOSX \
            ${destroot}${prefix}/share/doc/${name}/etc-xinetd.d-imap \
            ${destroot}${prefix}/share/doc/${name}/etc-xinetd.d-imaps
    }
}

# Variant to set the default mail subdirectory name to "Mail"
variant subdir description { set the contents of ~/.imap/MailboxDir.rc or else "Mail" as subdirectory name } {
    patchfiles-append   patch-env_unix.c.diff
}

livecheck.type      regex
livecheck.url       ${homepage}documentation/RELNOTES.html
livecheck.regex     "imap-(\\d{4}.?) "