#!/bin/bash
# postinst script for open-xchange-core
#
# 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

DIVERTFILES="outlook2003.de_DE.properties outlook2003.en_EN.properties outlook2003.fr_FR.properties outlook2003.nl_NL.properties"

for FILE in ${DIVERTFILES}; do
    if dpkg-divert --list | grep $FILE; then
        dpkg-divert --package open-xchange --rename --remove /opt/open-xchange/importCSV/${FILE}
    fi
done

dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/filestorage.properties \
      /opt/open-xchange/etc/filestorage.properties 6.20.99 open-xchange-file-storage-config \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-file-storage-config)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/folderjson.properties \
      /opt/open-xchange/etc/folderjson.properties 6.20.99 open-xchange-folder-json \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-folder-json)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/common/i18n.properties \
      /opt/open-xchange/etc/i18n.properties 6.20.99 open-xchange-i18n \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-i18n)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/mail-push.properties \
      /opt/open-xchange/etc/mail-push.properties 6.20.99 open-xchange-push \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-push)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/messaging.properties \
      /opt/open-xchange/etc/messaging.properties 6.20.99 open-xchange-messaging \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-messaging)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/publications.properties \
      /opt/open-xchange/etc/publications.properties  6.20.99 open-xchange-publish-basic \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-publish-basic)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/push.properties \
      /opt/open-xchange/etc/push-udp.properties 6.20.99 open-xchange-push-udp \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-push-udp)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/secret.properties \
      /opt/open-xchange/etc/secret.properties 6.20.99 open-xchange-secret \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-secret)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/secrets \
      /opt/open-xchange/etc/secrets 6.20.99 open-xchange-secret \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-secret)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/threadpool.properties \
      /opt/open-xchange/etc/threadpool.properties  6.20.99 open-xchange-threadpool \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-threadpool)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/meta/ui.yml \
      /opt/open-xchange/etc/meta/ui.yml 6.20.99 open-xchange-settings-extensions \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-settings-extensions)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/settings/themes.properties \
      /opt/open-xchange/etc/settings/themes.properties 6.20.99 open-xchange-settings-extensions \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-settings-extensions)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/settings/ui.properties \
      /opt/open-xchange/etc/settings/ui.properties 6.20.99 open-xchange-settings-extensions \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-settings-extensions)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/management.properties \
      /opt/open-xchange/etc/management.properties 6.20.99 open-xchange-management \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-management)
dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/templating.properties \
      /opt/open-xchange/etc/templating.properties 6.20.99 open-xchange-templating \
      -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange-templating)

COMMONCONFFILES="excludedupdatetasks.properties foldercache.properties transport.properties"

for FILE in ${COMMONCONFFILES}; do
    dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/common/${FILE} \
        /opt/open-xchange/etc/${FILE} 6.20.99 open-xchange -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange)
done

GWCONFFILES="attachment.properties cache.ccf calendar.properties configdb.properties contact.properties event.properties file-logging.properties HTMLEntities.properties importerExporter.xml import.properties infostore.properties javamail.properties ldap.properties login.properties mailcache.ccf mail.properties mime.types noipcheck.cnf notification.properties ox-scriptconf.sh participant.properties passwordchange.properties server.properties sessiond.properties smtp.properties system.properties user.properties whitelist.properties folder-reserved-names"

for FILE in ${GWCONFFILES}; do
    dpkg-maintscript-helper mv_conffile /opt/open-xchange/etc/groupware/${FILE} \
        /opt/open-xchange/etc/${FILE} 6.20.99 open-xchange -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange)
done
# SoftwareChange_Request-1297

if [ -e /opt/open-xchange/etc/sessioncache.ccf ]; then
    dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/sessioncache.ccf -- "$@"
fi

# SoftwareChange_Request-1094
dpkg-maintscript-helper rm_conffile \
    /opt/open-xchange/etc/groupware/mailjsoncache.properties 6.20.99 open-xchange -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange)

# SoftwareChange_Request-1091
dpkg-maintscript-helper rm_conffile \
    /opt/open-xchange/etc/groupware/TidyConfiguration.properties 6.20.99 open-xchange -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange)
dpkg-maintscript-helper rm_conffile \
    /opt/open-xchange/etc/groupware/TidyMessages.properties 6.20.99 open-xchange -- $1 $(dpkg-query -W -f='${Config-Version}' open-xchange)

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

pfile=/opt/open-xchange/etc/ox-scriptconf.sh
if grep COMMONPROPERTIESDIR $pfile >/dev/null; then
    ox_remove_property COMMONPROPERTIESDIR $pfile
    # without original values, we're lost...
    if [ -e ${pfile}.dpkg-new ]; then
       CHECKPROPS="LIBPATH PROPERTIESDIR LOGGINGPROPERTIES OSGIPATH"
       grep JAVA_OXCMD_OPTS $pfile > /dev/null || CHECKPROPS="$CHECKPROPS JAVA_OXCMD_OPTS" && true
       for prop in $CHECKPROPS; do
           oval=$(ox_read_property $prop ${pfile}.dpkg-new)
           if [ -n "$oval" ]; then
              ox_set_property $prop "$oval" $pfile
           fi
       done
    fi
fi

# SoftwareChange_Request-1559
pfile=/opt/open-xchange/etc/mail.properties
VALUE=$(ox_read_property com.openexchange.mail.mailAccessCacheIdleSeconds $pfile)
if [ "$VALUE" == "7" ]; then
    ox_set_property com.openexchange.mail.mailAccessCacheIdleSeconds 4 $pfile
fi

# SoftwareChange_Request-1557
pfile=/opt/open-xchange/etc/mail.properties
if ! ox_exists_property com.openexchange.mail.maxForwardCount $pfile; then
    ox_set_property com.openexchange.mail.maxForwardCount 8 $pfile
fi

# SoftwareChange_Request-1518
pfile=/opt/open-xchange/etc/mail.properties
if ! ox_exists_property com.openexchange.mail.hideDetailsForDefaultAccount $pfile; then
    ox_set_property com.openexchange.mail.hideDetailsForDefaultAccount false $pfile
fi

# SoftwareChange_Request-1497
pfile=/opt/open-xchange/etc/hazelcast.properties
if ! ox_exists_property com.openexchange.hazelcast.logging.enabled $pfile; then
    ox_set_property com.openexchange.hazelcast.logging.enabled true $pfile
fi

# SoftwareChange_Request-1492
pfile=/opt/open-xchange/etc/server.properties
for key in com.openexchange.json.poolEnabled com.openexchange.json.poolSize com.openexchange.json.poolCharArrayLength; do
    if ox_exists_property $key $pfile; then
       ox_remove_property $key $pfile
    fi
done

# SoftwareChange_Request-1483
pfile=/opt/open-xchange/etc/server.properties
if ! ox_exists_property com.openexchange.servlet.maxRateTimeWindow $pfile; then
    ox_set_property com.openexchange.servlet.maxRateTimeWindow 300000 $pfile
fi
if ! ox_exists_property com.openexchange.servlet.maxRate $pfile; then
    ox_set_property com.openexchange.servlet.maxRate 1500 $pfile
fi
if ! ox_exists_property com.openexchange.servlet.maxRateLenientClients $pfile; then
    ox_set_property com.openexchange.servlet.maxRateLenientClients '"Open-Xchange .NET HTTP Client*", "Open-Xchange USM HTTP Client*", "Jakarta Commons-HttpClient*"' $pfile
fi
if ! ox_exists_property com.openexchange.servlet.maxRateKeyPartProviders $pfile; then
    ox_set_property com.openexchange.servlet.maxRateKeyPartProviders '' $pfile
fi

# SoftwareChange_Request-1459
pfile=/opt/open-xchange/etc/mail.properties
if ! ox_exists_property com.openexchange.mail.supportMsisdnAddresses $pfile; then
    ox_set_property com.openexchange.mail.supportMsisdnAddresses false $pfile
fi

# SoftwareChange_Request-1458
pfile=/opt/open-xchange/etc/mail.properties
if ! ox_exists_property com.openexchange.mail.maxMailSize $pfile; then
    ox_set_property com.openexchange.mail.maxMailSize -1 $pfile
fi

# SoftwareChange_Request-1455
pfile=/opt/open-xchange/etc/sessiond.properties
if ! ox_exists_property com.openexchange.sessiond.asyncPutToSessionStorage $pfile; then
    ox_set_property com.openexchange.sessiond.asyncPutToSessionStorage false $pfile
fi

# SoftwareChange_Request-1448
ox_set_property com.openexchange.push.udp.pushEnabled false /opt/open-xchange/etc/push-udp.properties
ox_set_property com.openexchange.push.udp.registerDistributionEnabled false /opt/open-xchange/etc/push-udp.properties
ox_set_property com.openexchange.push.udp.eventDistributionEnabled false /opt/open-xchange/etc/push-udp.properties
ox_set_property com.openexchange.push.udp.multicastEnabled false /opt/open-xchange/etc/push-udp.properties

# SoftwareChange_Request-1446
pfile=/opt/open-xchange/etc/server.properties
VALUE=$(ox_read_property MAX_UPLOAD_SIZE $pfile)
if [ "$VALUE" == "0" ]; then
    ox_set_property MAX_UPLOAD_SIZE 104857600 $pfile
fi
VALUE=$(ox_read_property com.openexchange.defaultMaxConcurrentAJAXRequests $pfile)
if [ "$VALUE" == "250" ]; then
    ox_set_property com.openexchange.defaultMaxConcurrentAJAXRequests 100 $pfile
fi
VALUE=$(ox_read_property com.openexchange.servlet.maxActiveSessions $pfile)
if [ "$VALUE" == "-1" ]; then
    ox_set_property com.openexchange.servlet.maxActiveSessions 250000 $pfile
fi
pfile=/opt/open-xchange/etc/sessiond.properties
VALUE=$(ox_read_property com.openexchange.sessiond.maxSession $pfile)
if [ "$VALUE" == "5000" ]; then
    ox_set_property com.openexchange.sessiond.maxSession 50000 $pfile
fi
VALUE=$(ox_read_property com.openexchange.sessiond.randomTokenTimeout $pfile)
if [ "$VALUE" == "1M" ]; then
    ox_set_property com.openexchange.sessiond.randomTokenTimeout 30000 $pfile
fi

# SoftwareChange_Request-1445
pfile=/opt/open-xchange/etc/hazelcast.properties
if ! ox_exists_property com.openexchange.hazelcast.maxOperationTimeout $pfile; then
    ox_set_property com.openexchange.hazelcast.maxOperationTimeout 300000 $pfile
fi

# SoftwareChange_Request-1426
pfile=/opt/open-xchange/etc/server.properties
if ! ox_exists_property com.openexchange.log.maxMessageLength $pfile; then
    ox_set_property com.openexchange.log.maxMessageLength -1 $pfile
fi

# SoftwareChange_Request-1365
pfile=/opt/open-xchange/etc/configdb.properties
if ! ox_exists_property com.openexchange.database.replicationMonitor $pfile; then
    ox_set_property com.openexchange.database.replicationMonitor true $pfile
fi

# SoftwareChange_Request-1389
# -----------------------------------------------------------------------
pfile=/opt/open-xchange/etc/foldercache.properties
if ! ox_exists_property com.openexchange.folderstorage.database.preferDisplayName $pfile; then
    ox_set_property com.openexchange.folderstorage.database.preferDisplayName false $pfile
fi

# SoftwareChange_Request-1335
pfile=/opt/open-xchange/etc/paths.perfMap
if ! grep "modules/mail/defaultaddress" $pfile > /dev/null; then
   ptmp=${pfile}.$$
   cp $pfile $ptmp
   cat<<EOF >> $ptmp
modules/mail/defaultaddress > io.ox/mail//defaultaddress
modules/mail/sendaddress > io.ox/mail//sendaddress
EOF
   if [ -s $ptmp ]; then
      cp $ptmp $pfile
   fi
   rm -f $ptmp
fi

# SoftwareChange_Request-1330
pfile=/opt/open-xchange/etc/mime.types
if ! grep docm $pfile > /dev/null; then
   ptmp=${pfile}.$$
   cp $pfile $ptmp
   cat<<EOF >> $ptmp
application/vnd.ms-word.document.macroEnabled.12 docm
application/vnd.ms-word.template dotm
application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
application/vnd.ms-powerpoint.presentation.macroEnabled.12 potm
application/vnd.openxmlformats-officedocument.presentationml.template potx
application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
EOF
   if [ -s $ptmp ]; then
      cp $ptmp $pfile
   fi
   rm -f $ptmp
fi

# SoftwareChange_Request-1324
# -----------------------------------------------------------------------
pfile=/opt/open-xchange/etc/hazelcast.properties
if ! ox_exists_property com.openexchange.hazelcast.enableIPv6Support $pfile; then
    ox_set_property com.openexchange.hazelcast.enableIPv6Support false $pfile
fi

# SoftwareChange_Request-1308
# -----------------------------------------------------------------------
pfile=/opt/open-xchange/etc/hazelcast.properties
if ! ox_exists_property com.openexchange.hazelcast.networkConfig.port $pfile; then
    ox_set_property com.openexchange.hazelcast.networkConfig.port 5701 $pfile
fi
if ! ox_exists_property com.openexchange.hazelcast.networkConfig.portAutoIncrement $pfile; then
    ox_set_property com.openexchange.hazelcast.networkConfig.portAutoIncrement true $pfile
fi
if ! ox_exists_property com.openexchange.hazelcast.networkConfig.outboundPortDefinitions $pfile; then
    ox_set_property com.openexchange.hazelcast.networkConfig.outboundPortDefinitions '' $pfile
fi

# SoftwareChange_Request-1307
pfile=/opt/open-xchange/etc/server.properties
if ! ox_exists_property com.openexchange.server.considerXForwards $pfile; then
    ox_set_property com.openexchange.server.considerXForwards false $pfile
fi
if ! ox_exists_property com.openexchange.server.forHeader $pfile; then
    ox_set_property com.openexchange.server.forHeader X-Forwarded-For $pfile
fi
if ! ox_exists_property com.openexchange.server.knownProxies $pfile; then
    ox_set_property com.openexchange.server.knownProxies '' $pfile
fi

# SoftwareChange_Request-1296
# -----------------------------------------------------------------------
pfile=/opt/open-xchange/etc/cache.properties
if ! ox_exists_property com.openexchange.caching.jcs.eventInvalidation $pfile; then
    ox_set_property com.openexchange.caching.jcs.eventInvalidation true $pfile
fi

# SoftwareChange_Request-1302
# -----------------------------------------------------------------------
pfile=/opt/open-xchange/etc/user.properties
if ! ox_exists_property com.openexchange.user.maxClientCount $pfile; then
    ox_set_property com.openexchange.user.maxClientCount -1 $pfile
fi

# SoftwareChange_Request-1252
# -----------------------------------------------------------------------
pfile=/opt/open-xchange/etc/whitelist.properties
if ! grep -E '^html.tag.div.*bgcolor' $pfile > /dev/null; then
    oval=$(ox_read_property html.tag.div ${pfile})
    oval=${oval//\"/}
    ox_set_property html.tag.div \""${oval}bgcolor,"\" $pfile
fi

# SoftwareChange_Request-1247
# -----------------------------------------------------------------------
pfile=/opt/open-xchange/etc/hazelcast.properties
if ! ox_exists_property com.openexchange.hazelcast.enabled $pfile; then
    ox_set_property com.openexchange.hazelcast.enabled true $pfile
fi

# SoftwareChange_Request-1223
# SoftwareChange_Request-1237
# SoftwareChange_Request-1243
# SoftwareChange_Request-1245
# SoftwareChange_Request-1392
# SoftwareChange_Request-1468
# SoftwareChange_Request-1498
# -----------------------------------------------------------------------
pfile=/opt/open-xchange/etc/ox-scriptconf.sh
jopts=$(eval ox_read_property JAVA_XTRAOPTS $pfile)
jopts=${jopts//\"/}
nopts=$jopts
# -----------------------------------------------------------------------
permval=$(echo $nopts | sed 's;^.*MaxPermSize=\([0-9]*\).*$;\1;')
if [ $permval -lt 256 ]; then
    nopts=$(echo $nopts | sed "s;\(^.*MaxPermSize=\)[0-9]*\(.*$\);\1256\2;")
fi
# -----------------------------------------------------------------------
for opt in "-XX:+DisableExplicitGC" "-server" "-Djava.awt.headless=true" \
    "-XX:+UseConcMarkSweepGC" "-XX:+UseParNewGC" "-XX:CMSInitiatingOccupancyFraction=" \
    "-XX:+UseCMSInitiatingOccupancyOnly" "-XX:NewRatio=" "-XX:+UseTLAB" \
    "-XX:-OmitStackTraceInFastThrow"; do
    if ! echo $nopts | grep -- $opt > /dev/null; then
        if [ "$opt" = "-XX:CMSInitiatingOccupancyFraction=" ]; then
            opt="-XX:CMSInitiatingOccupancyFraction=75"
        elif [ "$opt" = "-XX:NewRatio=" ]; then
            opt="-XX:NewRatio=3"
        fi
        if [ "$opt" == "-XX:+UseConcMarkSweepGC" -o "$opt" == "-XX:+UseParNewGC" -o "$opt" == "-XX:CMSInitiatingOccupancyFraction=75" -o "$opt" == "-XX:+UseCMSInitiatingOccupancyOnly" ]; then
            if ! echo $nopts | grep -- "-XX:+UseParallelGC" > /dev/null && ! echo $nopts | grep -- "-XX:+UseParallelOldGC" > /dev/null; then
                nopts="$nopts $opt"
            fi
        else
            nopts="$nopts $opt"
        fi
    fi
done
# -----------------------------------------------------------------------
for opt in "-XX:+UnlockExperimentalVMOptions" "-XX:+UseG1GC" "-XX:+CMSClassUnloadingEnabled"; do
    if echo $nopts | grep -- $opt > /dev/null; then
	nopts=$(echo $nopts | sed "s;$opt;;")
    fi
done
if [ "$jopts" != "$nopts" ]; then
   ox_set_property JAVA_XTRAOPTS \""$nopts"\" $pfile
fi

# SoftwareChange_Request-1141
pfile=/opt/open-xchange/etc/mime.types
if ! grep font-woff $pfile > /dev/null; then
   ptmp=${pfile}.$$
   cp $pfile $ptmp
   cat<<EOF >> $ptmp
application/font-woff woff
text/cache-manifest appcache
text/javascript js
EOF
   if [ -s $ptmp ]; then
      cp $ptmp $pfile
   fi
   rm -f $ptmp
fi
if grep -E "application\/javascript.*js" $pfile > /dev/null; then
   ptmp=${pfile}.$$
   grep -vE "^application\/.*javascript" $pfile > $ptmp
   cat<<EOF >> $ptmp
application/javascript
application/x-javascript
EOF
   if [ -s $ptmp ]; then
      cp $ptmp $pfile
   fi
   rm -f $ptmp
fi

# SoftwareChange_Request-1212
pfile=/opt/open-xchange/etc/foldercache.properties
if ! ox_exists_property com.openexchange.folderstorage.outlook.showPersonalBelowInfoStore $pfile; then
    ox_set_property com.openexchange.folderstorage.outlook.showPersonalBelowInfoStore true $pfile
fi

# SoftwareChange_Request-1196
pfile=/opt/open-xchange/etc/import.properties
if ! ox_exists_property com.openexchange.import.ical.limit $pfile; then
    ox_set_property com.openexchange.import.ical.limit 10000 $pfile
fi

# SoftwareChange_Request-1220
# obsoletes SoftwareChange_Request-1068
# -----------------------------------------------------------------------
pfile=/opt/open-xchange/etc/ox-scriptconf.sh
jopts=$(eval ox_read_property JAVA_XTRAOPTS $pfile)
jopts=${jopts//\"/}
if echo $jopts | grep "osgi.compatibility.bootdelegation" > /dev/null; then
    jopts=$(echo $jopts | sed 's;-Dosgi.compatibility.bootdelegation=true;-Dosgi.compatibility.bootdelegation=false;')
    ox_set_property JAVA_XTRAOPTS \""$jopts"\" $pfile
fi

# SoftwareChange_Request-1135
pfile=/opt/open-xchange/etc/contact.properties
for key in scale_images scale_image_width scale_image_height; do
    if ox_exists_property $key $pfile; then
       ox_remove_property $key $pfile
    fi
done

# SoftwareChange_Request-1124
pfile=/opt/open-xchange/etc/server.properties
if ! ox_exists_property com.openexchange.ajax.response.includeStackTraceOnError $pfile; then
    ox_set_property com.openexchange.ajax.response.includeStackTraceOnError false $pfile
fi

# SoftwareChange_Request-1117
pfile=/opt/open-xchange/etc/server.properties
if ! ox_exists_property com.openexchange.webdav.disabled $pfile; then
    ox_set_property com.openexchange.webdav.disabled false $pfile
fi

# SoftwareChange_Request-1105
pfile=/opt/open-xchange/etc/cache.ccf
ptmp=${pfile}.$$
if grep -E "^jcs.region.OXIMAPConCache" $pfile > /dev/null; then
    grep -vE "^jcs.region.OXIMAPConCache" $pfile > $ptmp
    if [ -s $ptmp ]; then
        cp $ptmp $pfile
    fi
    rm -f $ptmp
fi

# SoftwareChange_Request-1091
pfile=/opt/open-xchange/etc/contact.properties
if ox_exists_property contactldap.configuration.path $pfile; then
    ox_remove_property contactldap.configuration.path $pfile
fi

# SoftwareChange_Request-1101
pfile=/opt/open-xchange/etc/configdb.properties
if ox_exists_property writeOnly $pfile; then
    ox_remove_property writeOnly $pfile
fi
# SoftwareChange_Request-1091
if ox_exists_property useSeparateWrite $pfile; then
    ox_remove_property useSeparateWrite $pfile
fi

# SoftwareChange_Request-1091
pfile=/opt/open-xchange/etc/system.properties
for prop in Calendar Infostore Attachment Notification ServletMappingDir CONFIGPATH \
    AJPPROPERTIES IMPORTEREXPORTER LDAPPROPERTIES EVENTPROPERTIES PUSHPROPERTIES \
    UPDATETASKSCFG HTMLEntities MailCacheConfig TidyMessages TidyConfiguration Whitelist; do
    if ox_exists_property $prop $pfile; then
       ox_remove_property $prop $pfile
    fi
done

if grep -E '^com.openexchange.caching.configfile.*/' $pfile >/dev/null; then
    ox_set_property com.openexchange.caching.configfile cache.ccf $pfile
fi
if ox_exists_property MimeTypeFile $pfile; then
    ox_set_property MimeTypeFileName mime.types $pfile
    ox_remove_property MimeTypeFile $pfile
fi
pfile=/opt/open-xchange/etc/import.properties
if ! ox_exists_property com.openexchange.import.mapper.path $pfile; then
    ox_set_property com.openexchange.import.mapper.path /opt/open-xchange/importCSV $pfile
fi
pfile=/opt/open-xchange/etc/mail.properties
if ! ox_exists_property com.openexchange.mail.JavaMailProperties $pfile || grep -E '^com.openexchange.mail.JavaMailProperties.*/' $pfile >/dev/null; then
    ox_set_property com.openexchange.mail.JavaMailProperties javamail.properties $pfile
fi
pfile=/opt/open-xchange/etc/sessiond.properties
if ox_exists_property com.openexchange.sessiond.sessionCacheConfig $pfile; then
    ox_remove_property com.openexchange.sessiond.sessionCacheConfig $pfile
fi

# SoftwareChange_Request-1024
pfile=/opt/open-xchange/etc/server.properties
if ! ox_exists_property com.openexchange.IPMaskV4 $pfile; then
    ox_set_property com.openexchange.IPMaskV4 "" $pfile
fi
if ! ox_exists_property com.openexchange.IPMaskV6 $pfile; then
    ox_set_property com.openexchange.IPMaskV6 "" $pfile
fi

# SoftwareChange_Request-1027
pfile=/opt/open-xchange/etc/server.properties
if ! ox_exists_property com.openexchange.dispatcher.prefix $pfile; then
    ox_set_property com.openexchange.dispatcher.prefix "/ajax/" $pfile
fi

# SoftwareChange_Request-1167
pfile=/opt/open-xchange/etc/contact.properties
if ! ox_exists_property "com.openexchange.contact.scaleVCardImages" $pfile; then
   ox_set_property "com.openexchange.contact.scaleVCardImages" "200x200" $pfile
fi

# SoftwareChange_Request-1148
pfile=/opt/open-xchange/etc/whitelist.properties
if ! ox_exists_property "html.style.word-break" $pfile; then
   ox_set_property "html.style.word-break" '"break-all"' $pfile
fi
if ! ox_exists_property "html.style.word-wrap" $pfile; then
   ox_set_property "html.style.word-wrap" '"break-word"' $pfile
fi

# SoftwareChange_Request-1125
pfile=/opt/open-xchange/etc/contactcollector.properties
if ! ox_exists_property com.openexchange.contactcollector.folder.deleteDenied $pfile; then
   ox_set_property com.openexchange.contactcollector.folder.deleteDenied false $pfile
fi

# SoftwareChange_Request-1540
pfile=/opt/open-xchange/etc/permissions.properties
if ! grep "com.openexchange.capability.boring" >/dev/null $pfile; then
    echo -e "\n# Mark this installation as boring, i.e. disable an easter egg\n" >> $pfile
    echo "# com.openexchange.capability.boring=true" >> $pfile
fi

# SoftwareChange_Request-1556
pfile=/opt/open-xchange/etc/excludedupdatetasks.properties
if ! grep "com.openexchange.groupware.tasks.database.TasksModifyCostColumnTask" >/dev/null $pfile; then
    echo -e "\n# v7.4.0 update tasks start here\n" >> $pfile
    echo "# Changes the columns actual_costs and target_costs for tasks from float to NUMERIC(12, 2)" >> $pfile
    echo "!com.openexchange.groupware.tasks.database.TasksModifyCostColumnTask" >> $pfile
fi

# SoftwareChange_Request-1558
pfile=/opt/open-xchange/etc/import.properties
if ! grep "com.openexchange.import.contacts.limit" >/dev/null $pfile; then
    echo -e "\n# sets the limit on how many contacts can be imported at once\n" >> $pfile
    echo "# -1 means unlimited, defaults to -1" >> $pfile
    echo "# com.openexchange.import.contacts.limit=-1" >> $pfile
fi

# SoftwareChange_Request-1564
VALUE=""
[ -e /opt/open-xchange/etc/cluster.properties ] && VALUE=$(ox_read_property com.openexchange.cluster.name /opt/open-xchange/etc/cluster.properties)
[ -e /opt/open-xchange/etc/cluster.properties.dpkg-remove ] && VALUE=$(ox_read_property com.openexchange.cluster.name /opt/open-xchange/etc/cluster.properties)
[ -e /opt/open-xchange/etc/cluster.properties.dpkg-backup ] && VALUE=$(ox_read_property com.openexchange.cluster.name /opt/open-xchange/etc/cluster.properties)
[ -e /opt/open-xchange/etc/cluster.properties.dpkg-bak ] && VALUE=$(ox_read_property com.openexchange.cluster.name /opt/open-xchange/etc/cluster.properties)
TOVALUE=$(ox_read_property com.openexchange.hazelcast.group.name /opt/open-xchange/etc/hazelcast.properties)
if [ -n "$VALUE" -a -z "$TOVALUE" ]; then
    ox_set_property com.openexchange.hazelcast.group.name "$VALUE" /opt/open-xchange/etc/hazelcast.properties
fi
dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/cluster.properties 7.4.0-5 -- "$@"
[ -e /opt/open-xchange/etc/static-cluster-discovery.properties ] && VALUE=$(ox_read_property com.openexchange.cluster.discovery.static.nodes /opt/open-xchange/etc/static-cluster-discovery.properties)
TOVALUE=$(ox_read_property com.openexchange.hazelcast.network.join.static.nodes /opt/open-xchange/etc/hazelcast.properties)
if [ -n "$VALUE" -a -z "$TOVALUE" ]; then
    ox_set_property com.openexchange.hazelcast.network.join.static.nodes "$VALUE" /opt/open-xchange/etc/hazelcast.properties
fi
pfile=/opt/open-xchange/etc/hazelcast.properties
OLDNAMES=( com.openexchange.hazelcast.interfaces com.openexchange.hazelcast.mergeFirstRunDelay com.openexchange.hazelcast.mergeRunDelay com.openexchange.hazelcast.networkConfig.port com.openexchange.hazelcast.networkConfig.portAutoIncrement com.openexchange.hazelcast.networkConfig.outboundPortDefinitions com.openexchange.hazelcast.enableIPv6Support )
NEWNAMES=( com.openexchange.hazelcast.network.interfaces com.openexchange.hazelcast.merge.firstRunDelay com.openexchange.hazelcast.merge.runDelay com.openexchange.hazelcast.network.port com.openexchange.hazelcast.network.portAutoIncrement com.openexchange.hazelcast.network.outboundPortDefinitions com.openexchange.hazelcast.network.enableIPv6Support )
DEFAULTS=( 127.0.0.1 120s 120s 5701 true "" false )
for I in $(seq 1 ${#OLDNAMES[@]}); do
    OLDNAME=${OLDNAMES[$I-1]}
    NEWNAME=${NEWNAMES[$I-1]}
    VALUE=$(ox_read_property $OLDNAME $pfile)
    if ox_exists_property $OLDNAME $pfile; then
        ox_remove_property $OLDNAME $pfile
    fi
    if [ -z "$VALUE" ]; then
        VALUE="${DEFAULTS[$I-1]}"
    fi
    if ! ox_exists_property $NEWNAME $pfile; then
        ox_set_property $NEWNAME "$VALUE" $pfile
    fi
done
NEWPROPS=( com.openexchange.hazelcast.jmxDetailed com.openexchange.hazelcast.network.join.multicast.group com.openexchange.hazelcast.network.join.multicast.port com.openexchange.hazelcast.group.password com.openexchange.hazelcast.memcache.enabled com.openexchange.hazelcast.rest.enabled com.openexchange.hazelcast.socket.bindAny )
DEFAULTS=( false 224.2.2.3 54327 'wtV6$VQk8#+3ds!a' false false false )
for I in $(seq 1 ${#NEWPROPS[@]}); do
    NEWPROP=${NEWPROPS[$I-1]}
    DEFAULT=${DEFAULTS[$I-1]}
    if ! ox_exists_property $NEWPROP $pfile; then
        ox_set_property $NEWPROP "$DEFAULT" $pfile
    fi
done

# SoftwareChange_Request-1601
ox_set_property com.openexchange.server.considerXForwards "true" /opt/open-xchange/etc/server.properties

# SoftwareChange_Request-1607
pfile=/opt/open-xchange/etc/preview.properties
VALUE=$(ox_read_property com.openexchange.preview.cache.quota $pfile)
if [ "$VALUE" == "0" ]; then
    ox_set_property com.openexchange.preview.cache.quota 10485760 $pfile
fi
VALUE=$(ox_read_property com.openexchange.preview.cache.quotaPerDocument $pfile)
if [ "$VALUE" == "0" ]; then
    ox_set_property com.openexchange.preview.cache.quotaPerDocument 524288 $pfile
fi
if ! ox_exists_property com.openexchange.preview.cache.type $pfile; then
    ox_set_property com.openexchange.preview.cache.type "FS" $pfile
fi
if ! ox_exists_property com.openexchange.preview.cache.quotaAware $pfile; then
    ox_set_property com.openexchange.preview.cache.quotaAware false $pfile
fi

# SoftwareChange_Request-1610
pfile=/opt/open-xchange/etc/templating.properties
if ! ox_exists_property com.openexchange.templating.trusted $pfile; then
    ox_set_property com.openexchange.templating.trusted server $pfile
fi

# SoftwareChange_Request-1635
PFILE=/opt/open-xchange/etc/permissions.properties
if ! ox_exists_property com.openexchange.capability.filestore $PFILE; then
    ox_set_property com.openexchange.capability.filestore true $PFILE
fi

# SoftwareChange_Request-1643
PFILE=/opt/open-xchange/etc/login.properties
if ! ox_exists_property com.openexchange.ajax.login.randomToken $PFILE; then
    ox_set_property com.openexchange.ajax.login.randomToken false $PFILE
fi

# SoftwareChange_Request-1645
PFILE=/opt/open-xchange/etc/server.properties
if ! ox_exists_property com.openexchange.cookie.hash.salt $PFILE; then
    ox_set_property com.openexchange.cookie.hash.salt replaceMe1234567890 $PFILE
fi

# SoftwareChange_Request-1646
PFILE=/opt/open-xchange/etc/configdb.properties
if ! ox_exists_property com.openexchange.database.checkWriteCons $PFILE; then
    ox_set_property com.openexchange.database.checkWriteCons false $PFILE
fi

# SoftwareChange_Request-1648
PFILE=/opt/open-xchange/etc/server.properties
if ! ox_exists_property com.openexchange.servlet.maxRateLenientModules $PFILE; then
    ox_set_property com.openexchange.servlet.maxRateLenientModules "rt, system" $PFILE
fi

# SoftwareChange_Request-1667
ox_add_property com.openexchange.html.css.parse.timeout 4 /opt/open-xchange/etc/server.properties

# SoftwareChange_Request-1684
ox_add_property com.openexchange.templating.usertemplating false /opt/open-xchange/etc/templating.properties

# SoftwareChange_Request-1702
ox_add_property com.openexchange.mail.transport.removeMimeVersionInSubParts false /opt/open-xchange/etc/transport.properties

# SoftwareChange_Request-1707
ox_add_property com.openexchange.servlet.contentSecurityPolicy '""' /opt/open-xchange/etc/server.properties

PFILE=/opt/open-xchange/etc/excludedupdatetasks.properties
if ! grep "com.openexchange.groupware.update.tasks.FolderExtendNameTask" >/dev/null $PFILE; then
    cat >> $PFILE <<EOF

# v7.4.2 update tasks start here

# Extends the size of the 'fname' column in the 'oxfolder_tree' table, as well as the 'name' column in the 'virtualTree' table.
!com.openexchange.groupware.update.tasks.FolderExtendNameTask
EOF
fi

# SoftwareChange_Request-1747
ox_add_property com.openexchange.log.suppressedCategories USER_INPUT /opt/open-xchange/etc/server.properties

# SoftwareChange_Request-1760
ox_add_property com.openexchange.mail.account.blacklist "" /opt/open-xchange/etc/mail.properties

# SoftwareChange_Request-1772
if [ ! -e /opt/open-xchange/etc/log4j.xml ]; then
    # Configuration has been modified after installation. Try to migrate.
    if [ -e /opt/open-xchange/etc/file-logging.properties.dpkg-backup ]; then
        TMPFILE=$(mktemp)
        /opt/open-xchange/sbin/extractJULModifications -i /opt/open-xchange/etc/file-logging.properties.dpkg-backup | /opt/open-xchange/sbin/convertJUL2Logback -o $TMPFILE
        /opt/open-xchange/sbin/xmlModifier -i /opt/open-xchange/etc/logback.xml -o /opt/open-xchange/etc/logback.xml.new -x /configuration/logger -r $TMPFILE -d @name
        cat /opt/open-xchange/etc/logback.xml.new >/opt/open-xchange/etc/logback.xml
        /opt/open-xchange/sbin/xmlModifier -i /opt/open-xchange/etc/logback.xml -o /opt/open-xchange/etc/logback.xml.new -x /configuration/root -r $TMPFILE
        cat /opt/open-xchange/etc/logback.xml.new >/opt/open-xchange/etc/logback.xml
        rm -f /opt/open-xchange/etc/logback.xml.new $TMPFILE
    fi

    if [ -e /opt/open-xchange/etc/file-logging.properties.dpkg-backup ] || [ -e /opt/open-xchange/etc/file-logging.properties.dpkg-remove ]; then
        cat <<EOF | /opt/open-xchange/sbin/xmlModifier -i /opt/open-xchange/etc/logback.xml -o /opt/open-xchange/etc/logback.xml.new -x /configuration/appender[@name=\'ASYNC\']/appender-ref -r -
<configuration>
    <appender name="ASYNC">
        <appender-ref ref="FILE_COMPAT"/>
    </appender>
</configuration>
EOF
        cat /opt/open-xchange/etc/logback.xml.new >/opt/open-xchange/etc/logback.xml
        rm -f /opt/open-xchange/etc/logback.xml.new
    fi
fi
dpkg-maintscript-helper rm_conffile /opt/open-xchange/etc/file-logging.properties 7.4.2~ -- "$@"

# SoftwareChange_Request-1773
ox_add_property com.openexchange.hazelcast.network.symmetricEncryption false /opt/open-xchange/etc/hazelcast.properties
ox_add_property com.openexchange.hazelcast.network.symmetricEncryption.algorithm PBEWithMD5AndDES /opt/open-xchange/etc/hazelcast.properties
ox_add_property com.openexchange.hazelcast.network.symmetricEncryption.salt 2mw67LqNDEb3 /opt/open-xchange/etc/hazelcast.properties
ox_add_property com.openexchange.hazelcast.network.symmetricEncryption.password D2xhL8mPkjsF /opt/open-xchange/etc/hazelcast.properties
ox_add_property com.openexchange.hazelcast.network.symmetricEncryption.iterationCount 19 /opt/open-xchange/etc/hazelcast.properties

# SoftwareChange_Request-1786
ox_add_property com.openexchange.threadpool.keepAliveThreshold 1000 /opt/open-xchange/etc/threadpool.properties

# SoftwareChange_Request-1823
ox_add_property com.openexchange.preview.cache.enabled true /opt/open-xchange/etc/preview.properties

# SoftwareChange_Request-1828
ox_add_property com.openexchange.capability.alone false /opt/open-xchange/etc/permissions.properties

# SoftwareChange_Request-1832
ox_set_property readProperty.5 autoReconnect=false /opt/open-xchange/etc/configdb.properties
ox_set_property writeProperty.5 autoReconnect=false /opt/open-xchange/etc/configdb.properties

# Change jolokia.properties comment by reloading properties
pfile=/opt/open-xchange/etc/jolokia.properties
VALUE=$(ox_read_property com.openexchange.jolokia.user $pfile)
if [ -n "$VALUE" ]; then
    ox_set_property com.openexchange.jolokia.user "$VALUE" $pfile
else
    ox_set_property com.openexchange.jolokia.user "" $pfile
fi
VALUE=$(ox_read_property com.openexchange.jolokia.password $pfile)
if [ -n "$VALUE" ]; then
    ox_set_property com.openexchange.jolokia.password "$VALUE" $pfile
else
    ox_set_property com.openexchange.jolokia.password "" $pfile
fi

# SoftwareChange_Request-1865
PFILE=/opt/open-xchange/etc/whitelist.properties
if [ -n "$(ox_read_property html.tag.base $PFILE)" ]; then
    ox_comment html.tag.base= add /opt/open-xchange/etc/whitelist.properties
fi
if [ -n "$(ox_read_property html.tag.meta $PFILE)" ]; then
    ox_comment html.tag.meta= add $PFILE
fi

# SoftwareChange_Request-1886
PFILE=/opt/open-xchange/etc/server.properties
if ox_exists_property com.openexchange.server.fullPrimaryKeySupport $PFILE; then
    ox_remove_property com.openexchange.server.fullPrimaryKeySupport $PFILE
fi

# SoftwareChange_Request-1956
ox_add_property com.openexchange.ajax.login.formatstring.login "" /opt/open-xchange/etc/login.properties
ox_add_property com.openexchange.ajax.login.formatstring.logout "" /opt/open-xchange/etc/login.properties

# SoftwareChange_Request-1959
VALUE=$(ox_read_property com.openexchange.servlet.maxInactiveInterval /opt/open-xchange/etc/server.properties)
ox_set_property com.openexchange.servlet.maxInactiveInterval "$VALUE" /opt/open-xchange/etc/server.properties

# SoftwareChange_Request-1968
VALUE=$(ox_read_property com.openexchange.sessiond.sessionDefaultLifeTime /opt/open-xchange/etc/sessiond.properties)
ox_set_property com.openexchange.sessiond.sessionDefaultLifeTime "$VALUE" /opt/open-xchange/etc/sessiond.properties

# SoftwareChange_Request-1980
VALUE=$(ox_read_property com.openexchange.jolokia.restrict.to.localhost /opt/open-xchange/etc/jolokia.properties)
ox_set_property com.openexchange.jolokia.restrict.to.localhost "$VALUE" /opt/open-xchange/etc/jolokia.properties

# SoftwareChange_Request-1985
ox_remove_property com.openexchange.log.propertyNames /opt/open-xchange/etc/server.properties

# SoftwareChange_Request-1987
cat <<EOF | /opt/open-xchange/sbin/xmlModifier -i /opt/open-xchange/etc/logback.xml -o /opt/open-xchange/etc/logback.xml.new -x /configuration/define -d @name -r -
<configuration>
    <define name="syslogPatternLayoutActivator" class="com.openexchange.logback.extensions.SyslogPatternLayoutActivator"/>
</configuration>
EOF
cat /opt/open-xchange/etc/logback.xml.new >/opt/open-xchange/etc/logback.xml
rm -f /opt/open-xchange/etc/logback.xml.new

# SoftwareChange_Request-1990
ox_add_property com.openexchange.quota.attachment -1 /opt/open-xchange/etc/quota.properties

# SoftwareChagne_Request-2002
ox_add_property com.openexchange.infostore.zipDocumentsCompressionLevel -1 /opt/open-xchange/etc/infostore.properties

# SoftwareChange_Request-2027
pfile=/opt/open-xchange/etc/whitelist.properties
if ! grep -E '^html.tag.table.*height' $pfile > /dev/null; then
    oval=$(ox_read_property html.tag.table ${pfile})
    oval=${oval//\"/}
    ox_set_property html.tag.table \""${oval}height,"\" $pfile
fi
if ! grep -E '^html.style.combimap.background.*radial-gradient' $pfile > /dev/null; then
    oval=$(ox_read_property html.style.combimap.background ${pfile})
    oval=${oval//\"/}
    ox_set_property html.style.combimap.background \""${oval}radial-gradient,"\" $pfile
fi

# SoftwareChange_Request-2036
VALUE=$(ox_read_property com.openexchange.hazelcast.network.symmetricEncryption /opt/open-xchange/etc/hazelcast.properties)
ox_set_property com.openexchange.hazelcast.network.symmetricEncryption "$VALUE" /opt/open-xchange/etc/hazelcast.properties

# SoftwareChange_Request-2037
PFILE=/opt/open-xchange/etc/sessiond.properties
ox_comment com.openexchange.sessiond.remoteParameterNames= add $PFILE

# SoftwareChange_Request-2055
ox_add_property com.openexchange.rest.services.basic-auth.login "" /opt/open-xchange/etc/server.properties
ox_add_property com.openexchange.rest.services.basic-auth.password "" /opt/open-xchange/etc/server.properties

# SoftwareChange_Request-2079
ox_add_property com.openexchange.passwordchange.allowedPattern "" /opt/open-xchange/etc/passwordchange.properties
ox_add_property com.openexchange.passwordchange.allowedPatternHint "" /opt/open-xchange/etc/passwordchange.properties

# SoftwareChange_Request-2081
PFILE=/opt/open-xchange/etc/configdb.properties
KEY=minIdle
if ox_exists_property $KEY $PFILE; then
    ox_remove_property $KEY $PFILE
fi

# SoftwareChange_Request-2094
PFILE=/opt/open-xchange/etc/mail.properties
KEY=com.openexchange.mail.imageHost
ox_add_property $KEY "" $PFILE

# SoftwareChange_Request-2108
pfile=/opt/open-xchange/etc/mime.types
if ! grep vnd.openxmlformats-officedocument.spreadsheetml.template $pfile > /dev/null; then
   ptmp=${pfile}.$$
   cp $pfile $ptmp
   cat<<EOF >> $ptmp
application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
application/vnd.openxmlformats-officedocument.presentationml.slide sldx
application/vnd.ms-excel.addin.macroEnabled.12 xlam
application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
EOF
   if [ -s $ptmp ]; then
      cp $ptmp $pfile
   fi
   rm -f $ptmp
fi

# SoftwareChange_Request-2110
ox_add_property html.tag.strike '""' /opt/open-xchange/etc/whitelist.properties

# SoftwareChange_Request-2148
ox_add_property com.openexchange.mail.enforceSecureConnection false /opt/open-xchange/etc/mail.properties

# SoftwareChange_Request-2171
PFILE=/opt/open-xchange/etc/server.properties
VALUE=$(ox_read_property com.openexchange.rest.services.basic-auth.login $PFILE)
if [ "open-xchange" = "$VALUE" ]; then
    ox_set_property com.openexchange.rest.services.basic-auth.login "" $PFILE
fi
VALUE=$(ox_read_property com.openexchange.rest.services.basic-auth.password $PFILE)
if [ "secret" = "$VALUE" ]; then
    ox_set_property com.openexchange.rest.services.basic-auth.password "" $PFILE
fi

# SoftwareChange_Request-2177
ox_add_property com.openexchange.preview.thumbnail.blockingWorker false /opt/open-xchange/etc/server.properties

# SoftwareChange_Request-2190
pfile=/opt/open-xchange/etc/cache.ccf
if ! grep "jcs.region.UserPermissionBits=LTCP" > /dev/null $pfile; then
    echo -e "\n# Pre-defined cache for user configuration" >> $pfile
    echo "jcs.region.UserPermissionBits=LTCP" >> $pfile
    echo "jcs.region.UserPermissionBits.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes" >> $pfile
    echo "jcs.region.UserPermissionBits.cacheattributes.MaxObjects=20000" >> $pfile
    echo "jcs.region.UserPermissionBits.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache" >> $pfile
    echo "jcs.region.UserPermissionBits.cacheattributes.UseMemoryShrinker=true" >> $pfile
    echo "jcs.region.UserPermissionBits.cacheattributes.MaxMemoryIdleTimeSeconds=360" >> $pfile
    echo "jcs.region.UserPermissionBits.cacheattributes.ShrinkerIntervalSeconds=60" >> $pfile
    echo "jcs.region.UserPermissionBits.cacheattributes.MaxSpoolPerRun=500" >> $pfile
    echo "jcs.region.UserPermissionBits.elementattributes=org.apache.jcs.engine.ElementAttributes" >> $pfile
    echo "jcs.region.UserPermissionBits.elementattributes.IsEternal=false" >> $pfile
    echo "jcs.region.UserPermissionBits.elementattributes.MaxLifeSeconds=-1" >> $pfile
    echo "jcs.region.UserPermissionBits.elementattributes.IdleTime=360" >> $pfile
    echo "jcs.region.UserPermissionBits.elementattributes.IsSpool=false" >> $pfile
    echo "jcs.region.UserPermissionBits.elementattributes.IsRemote=false" >> $pfile
    echo -e "jcs.region.UserPermissionBits.elementattributes.IsLateral=false\n" >> $pfile
fi

# SoftwareChange_Request-2197
PFILE=/opt/open-xchange/etc/cache.ccf
NAMES=( jcs.region.OXFolderCache.cacheattributes.MaxMemoryIdleTimeSeconds jcs.region.OXFolderCache.elementattributes.MaxLifeSeconds jcs.region.OXFolderCache.elementattributes.IdleTime jcs.region.OXFolderQueryCache.cacheattributes.MaxMemoryIdleTimeSeconds jcs.region.OXFolderQueryCache.elementattributes.MaxLifeSeconds jcs.region.OXFolderQueryCache.elementattributes.IdleTime jcs.region.UserSettingMail.cacheattributes.MaxMemoryIdleTimeSeconds jcs.region.UserSettingMail.elementattributes.MaxLifeSeconds jcs.region.UserSettingMail.elementattributes.IdleTime jcs.region.MailAccount.cacheattributes.MaxMemoryIdleTimeSeconds jcs.region.MailAccount.elementattributes.MaxLifeSeconds jcs.region.MailAccount.elementattributes.IdleTime jcs.region.GlobalFolderCache.cacheattributes.MaxMemoryIdleTimeSeconds jcs.region.GlobalFolderCache.elementattributes.MaxLifeSeconds jcs.region.GlobalFolderCache.elementattributes.IdleTime )
OLDDEFAULTS=( 180 300 180 150 300 150 180 300 180 180 300 180 180 300 180 )
NEWDEFAULTS=( 360 -1 360 360 -1 360 360 -1 360 360 -1 360 360 -1 360 )
for I in $(seq 1 ${#NAMES[@]}); do
    VALUE=$(ox_read_property ${NAMES[$I-1]} $PFILE)
    if [ "${VALUE}" = "${OLDDEFAULTS[$I-1]}" ]; then
        ox_set_property ${NAMES[$I-1]} "${NEWDEFAULTS[$I-1]}" $PFILE
    fi
done

# SoftwareChange_Request-2199
ox_add_property com.openexchange.servlet.maxRateLenientRemoteAddresses "" /opt/open-xchange/etc/server.properties

# SoftwareChange_Request-2204
ox_add_property com.openexchange.webdav.recursiveMarshallingLimit 250000 /opt/open-xchange/etc/server.properties

# SoftwareChange_Request-2206
NAMES=( com.openexchange.quota.calendar com.openexchange.quota.task com.openexchange.quota.contact com.openexchange.quota.infostore com.openexchange.quota.attachment )
for I in "${NAMES[@]}"; do
    VALUE=$(ox_read_property $I /opt/open-xchange/etc/quota.properties)
    ox_set_property $I "$VALUE" /opt/open-xchange/etc/quota.properties
done

# SoftwareChange_Request-2219
VALUE=$(ox_read_property com.openexchange.servlet.maxRate /opt/open-xchange/etc/server.properties)
if [ "1500" = "${VALUE}" ]; then
    ox_set_property com.openexchange.servlet.maxRate 500 /opt/open-xchange/etc/server.properties
fi

# SoftwareChange_Request-2243
VALUE=$(ox_read_property com.openexchange.servlet.maxRate /opt/open-xchange/etc/server.properties)
if [ "500" = "${VALUE}" ]; then
    ox_set_property com.openexchange.servlet.maxRate 1500 /opt/open-xchange/etc/server.properties
fi
# SoftwareChange_Request-2249
ox_add_property com.openexchange.requestwatcher.usm.ignore.path /syncUpdate /opt/open-xchange/etc/requestwatcher.properties

# SoftwareChange_Request-2250
ox_add_property com.openexchange.requestwatcher.eas.ignore.cmd sync,ping /opt/open-xchange/etc/requestwatcher.properties

# SoftwareChange_Request-2342
PFILE=/opt/open-xchange/etc/excludedupdatetasks.properties
if ! grep "com.openexchange.groupware.update.tasks.CheckForPresetMessageFormatInJSLob" >/dev/null $PFILE; then
    cat >> $PFILE <<EOF

# Check for possibly preset message format preference in JSLob and aligns the DB value accordingly
!com.openexchange.groupware.update.tasks.CheckForPresetMessageFormatInJSLob
EOF
fi

# SoftwareChange_Request-2379
ox_add_property html.tag.center '""' /opt/open-xchange/etc/whitelist.properties

# SoftwareChange_Request-2456
ox_add_property com.openexchange.caching.jcs.remoteInvalidationForPersonalFolders false /opt/open-xchange/etc/cache.properties

setConfigFilePermissions() {
    PROTECT="configdb.properties mail.properties management.properties oauth-provider.properties secret.properties secrets sessiond.properties tokenlogin-secrets"
    for FILE in $PROTECT
    do
        ox_update_permissions "/opt/open-xchange/etc/$FILE" root:open-xchange 640
    done
    ox_update_permissions "/opt/open-xchange/etc/ox-scriptconf.sh" root:root 644
    ox_update_permissions "/opt/open-xchange/osgi" open-xchange:root 750
    ox_update_permissions "/var/spool/open-xchange/uploads" open-xchange:root 750
    ox_update_permissions "/var/log/open-xchange" open-xchange:root 750
}

case "$1" in
    configure)
        setConfigFilePermissions
    ;;

    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
