#!/bin/bash
# postinst script for open-xchange-imap
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/imap.properties \
    /opt/open-xchange/etc/imap.properties 6.20.99 open-xchange -- "$@"

. /opt/open-xchange/lib/oxfunctions.sh

postFix() {
    local version=${1%-*}
    version=${version//[-.]/}

    # prevent bash from expanding, see bug 13316
    GLOBIGNORE='*'

    PFILE=/opt/open-xchange/etc/imap.properties

    # SoftwareChange_Request-1142
    ox_add_property com.openexchange.imap.umlautFilterThreshold 50 $PFILE

    # SoftwareChange_Request-1215
    ox_add_property com.openexchange.imap.maxMailboxNameLength 60 $PFILE

    # SoftwareChange_Request-1470
    if ox_exists_property com.openexchange.imap.maxIMAPConnectionIdleTime $PFILE; then
        ox_remove_property com.openexchange.imap.maxIMAPConnectionIdleTime $PFILE
    fi

    # SoftwareChange_Request-1566
    ox_add_property com.openexchange.imap.invalidMailboxNameCharacters "" $PFILE

    # SoftwareChange_Request-1586
    ox_add_property com.openexchange.imap.allowFolderCaches true $PFILE

    # SoftwareChange_Request-1668
    ox_add_property com.openexchange.imap.storeContainerType boundary-aware $PFILE

    # SoftwareChange_Request-1931
    ox_add_property com.openexchange.imap.ssl.protocols "SSLv3 TLSv1" $PFILE

    # SoftwareChange_Request-1953
    VALUE=$(ox_read_property com.openexchange.imap.imapSearch $PFILE)
    ox_set_property com.openexchange.imap.imapSearch "$VALUE" $PFILE

    # SoftwareChange_Request-2016
    ox_add_property com.openexchange.imap.ssl.ciphersuites "" $PFILE

    # SoftwareChange_Request-2093
    ox_add_property com.openexchange.imap.namespacePerUser "true" $PFILE

    # SoftwareChange_Request-3134
    ox_add_property com.openexchange.imap.fallbackOnFailedSORT false $PFILE
}

case "$1" in
    configure)
        test -n "$2" && {
            # we are in update mode, run postFix to apply fixes
            postFix "$2"
        }
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac


# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
