HEX
Server: Apache/2.2.34 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141
System: Linux Kou-Etsu-Dou 4.4.59+ #25556 SMP PREEMPT Thu Mar 4 18:03:46 CST 2021 x86_64
User: hosam (1026)
PHP: 7.2.29
Disabled: NONE
Upload Files
File: /volume1/@appstore/MailClient/scripts/mailclient_sync_callback.sh
#!/bin/sh

SYNOPKG_PKGNAME="MailClient"
PACKAGE_DIR="/var/packages/${SYNOPKG_PKGNAME}"
NOTIFY_DAEMON_BIN="${PACKAGE_DIR}/target/tool/notify_daemon"
PACKAGE_ENABLED="${PACKAGE_DIR}/enabled"

complete_sync_file=$1
user_id=$2
sync_type="sync"

RenameSyncFile()
{
	local temp=".tmp"
	local temp_len=${#temp}
	local len=${#complete_sync_file}
	local final_file=${complete_sync_file:0:(len-temp_len)}

	if [ -f ${final_file} ]; then
		/bin/rm ${final_file}
	fi

	/bin/mv ${complete_sync_file} ${final_file}
}

DoSync()
{
	if [ ! -f $PACKAGE_ENABLED ]; then
		return
	fi

	RenameSyncFile
	${NOTIFY_DAEMON_BIN} -u ${user_id} -t $1
}

DeleteVacationDb()
{
	local dir=$(dirname "${complete_sync_file}")
	rm -rf "${dir}/.vacation.db"
}

CheckSieveLink()
{
	local sieve_dir=$(dirname "${complete_sync_file}")
	local mail_home=$(dirname "${sieve_dir}")
	local link_path=".dovecot.sieve"
	local user=`/bin/ls -ld ${mail_home} | awk '{print $3}'`
	local gid=`id -g $user`

	pushd $mail_home
	if [ ! -f ${link_path} ]; then
		ln -s sieve/synomc.sieve $link_path
		chown -h "${user_id}:${gid}" $link_path
	fi
	popd
}

if [ -f ${complete_sync_file} ]; then

	case $3 in
		"addressbook")
			DoSync sync_addressbook
		;;
		"mail_settings")
			DoSync sync
		;;
		"auto_reply")
			DeleteVacationDb
		;;
		"sieve")
			CheckSieveLink
		;;
		*)
		;;
	esac

fi