# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           perl5 1.0

name                imapsync
version             2.264
categories          mail perl
platforms           any
maintainers         nomaintainer
license             Permissive
description         imapsync is an IMAP synchronization, copy or migration tool.
long_description    imapsync is an IMAP synchronization, copy or migration \
                    tool. Synchronize mailboxes between two IMAP servers. It \
                    is especially good at IMAP migration.

homepage            https://imapsync.lamiral.info/
master_sites        ${homepage}/dist/

checksums           rmd160  612bbbe7fabdf338d96565dfb924b71a509c1086 \
                    sha256  14469e2de0d8deba6195a63e388bc38a6b7000ff12220912bf8f01a5673d6c7d \
                    size    18343997

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_run         port:p${perl5.major}-crypt-openssl-rsa \
                    port:p${perl5.major}-data-uniqid \
                    port:p${perl5.major}-digest-md5 \
                    port:p${perl5.major}-digest-hmac \
                    port:p${perl5.major}-encode \
                    port:p${perl5.major}-encode-imaputf7 \
                    port:p${perl5.major}-file-copy-recursive \
                    port:p${perl5.major}-file-tail \
                    port:p${perl5.major}-html-parser \
                    port:p${perl5.major}-io-socket-inet6 \
                    port:p${perl5.major}-io-socket-ip \
                    port:p${perl5.major}-io-socket-ssl \
                    port:p${perl5.major}-io-tee \
                    port:p${perl5.major}-json \
                    port:p${perl5.major}-json-webtoken \
                    port:p${perl5.major}-json-xs \
                    port:p${perl5.major}-libwww-perl \
                    port:p${perl5.major}-mail-imapclient \
                    port:p${perl5.major}-net-server \
                    port:p${perl5.major}-net-ssleay \
                    port:p${perl5.major}-pod-escapes \
                    port:p${perl5.major}-pod-simple \
                    port:p${perl5.major}-podlators \
                    port:p${perl5.major}-readonly \
                    port:p${perl5.major}-regexp-common \
                    port:p${perl5.major}-sys-meminfo \
                    port:p${perl5.major}-term-readkey \
                    port:p${perl5.major}-text-parsewords \
                    port:p${perl5.major}-time-hires \
                    port:p${perl5.major}-unicode-string \
                    port:p${perl5.major}-uri

supported_archs     noarch

post-patch {
    reinplace -locale C "s|^#!.*|#!${perl5.bin}|g" \
        ${worksrcpath}/imapsync \
        ${worksrcpath}/webserver
}

use_configure       no

extract.suffix      .tgz

build               {}

test.run            yes
test.cmd            imapsync
test.target         --version

destroot {
    set share_root ${prefix}/share/${name}
    xinstall -d ${destroot}${share_root}
    foreach f { ChangeLog CREDITS doc examples FAQ.d imapsync LICENSE oauth2 \
        README S TODO VERSION webserver X } {
        copy ${worksrcpath}/${f} ${destroot}${share_root}
    }

    ln -sf ${share_root}/imapsync ${destroot}${prefix}/bin/imapsync

    # Create webserver launch script
    set webserver_script [open ${destroot}${prefix}/bin/imapsync-webserver w 0755]
    puts $webserver_script "#!/bin/sh"
    puts $webserver_script "(cd ${share_root} && exec ${share_root}/webserver $@)"
    close $webserver_script
}
