@%@UCRWARNING=# @%@
@!@
from os.path import exists

SimpleIntChars = set('0123456789')


def escapeString(string):
	return string.replace("'", "'\\''")


def GetSimpleIntUcr(UCRkey, default):
	string = configRegistry.get(UCRkey, '-')
	for char in string:
		if char not in SimpleIntChars:
			return default
	return int(string)


POSTGREY_OPTS = ['--inet=10023']
POSTGREY_OPTS.append('--delay=%d' % GetSimpleIntUcr('mail/postfix/greylisting/delay', 300))
POSTGREY_OPTS.append('--max-age=%d' % GetSimpleIntUcr('mail/postfix/greylisting/max-age', 35))
POSTGREY_OPTS.append('--retry-window=%dh' % GetSimpleIntUcr('mail/postfix/greylisting/retry-window', 48))
POSTGREY_OPTS.append('--auto-whitelist-clients=%d' % GetSimpleIntUcr('mail/postfix/greylisting/client/whitelist/auto', 5))

if configRegistry.get('mail/postfix/greylisting/lookup', 'host').lower() == 'subnet':
	POSTGREY_OPTS.append('--lookup-by-subnet')
else:
	POSTGREY_OPTS.append('--lookup-by-host')

if configRegistry.is_true('mail/postfix/greylisting/privacy', True):
	POSTGREY_OPTS.append('--privacy')

if 'mail/postfix/greylisting/client/whitelist' in configRegistry:
	for filename in configRegistry['mail/postfix/greylisting/client/whitelist'].split():
		if exists(filename):
			POSTGREY_OPTS.append('--whitelist-clients=%s' % filename)

if 'mail/postfix/greylisting/recipient/whitelist' in configRegistry:
	for filename in configRegistry['mail/postfix/greylisting/recipient/whitelist'].split():
		if exists(filename):
			POSTGREY_OPTS.append('--whitelist-recipients=%s' % filename)

print("POSTGREY_OPTS='%s'" % escapeString(' '.join(POSTGREY_OPTS)))

if 'mail/postfix/greylisting/text' in configRegistry:
	print("POSTGREY_TEXT='%s'" % escapeString(configRegistry['mail/postfix/greylisting/text']))
@!@
