# smtpd_sender_restrictions is not defined since all relevant checks have been moved to
# smtpd_recipient_restrictions (see below) and every mail has to pass smtpd_recipient_restrictions too.
#smtpd_sender_restrictions =

@!@
# get all recipient restrictions from UCR ==> [ (key, val), ... ]
ucrlist = [ x for x in configRegistry.items() if x[0].startswith('mail/postfix/smtpd/restrictions/recipient/') ]

# add listfilter if enabled by UCR with level "05" (Bug #17954)
if configRegistry.is_true("mail/postfix/policy/listfilter", False):
	ucrlist.append( ('mail/postfix/smtpd/restrictions/recipient/05-listfilter', 'check_policy_service unix:private/listfilter') )
if configRegistry.is_true("mail/postfix/greylisting", False):
	ucrlist.append( ('mail/postfix/smtpd/restrictions/recipient/40-greylisting', 'check_policy_service inet:127.0.0.1:10023') )
ucrlist.sort()
recipient_restrictions = [ x[1] for x in ucrlist ]

if configRegistry.is_true("mail/postfix/smtpd/restrictions/sender/reject_unknown_client_hostname") or \
	configRegistry.is_true("mail/postfix/smtpd/restrictions/sender/reject_unknown_reverse_client_hostname"):
	# insert reject_unknown_client_hostname and reject_unknown_reverse_client_hostname
	# after reject_unauth_destination
	for i, item in enumerate(recipient_restrictions):
		if "reject_unauth_destination" in item:
			if configRegistry.is_true('mail/postfix/smtpd/restrictions/sender/reject_unknown_reverse_client_hostname'):
				recipient_restrictions.insert(i+1, 'reject_unknown_reverse_client_hostname')
			if configRegistry.is_true('mail/postfix/smtpd/restrictions/sender/reject_unknown_client_hostname'):
				recipient_restrictions.insert(i+1, 'reject_unknown_client_hostname')
			break

print("smtpd_recipient_restrictions = %s" % ",\n        ".join(recipient_restrictions))

# get all recipient restrictions from UCR ==> [ (key, val), ... ]
ucrlist = [x for x in configRegistry.items() if x[0].startswith('mail/postfix/submission/restrictions/recipient/')]
ucrlist.sort()
submission_recipient_restrictions = [x[1] for x in ucrlist]

print('\n# special recipient_restrictions which may be used by smtps/submission services')
print('# (can be configured via UCR: mail/postfix/submission/restrictions/recipient/...)')
if submission_recipient_restrictions:
	print("submission_recipient_restrictions = %s" % ",\n        ".join(submission_recipient_restrictions))
else:
	print("# submission_recipient_restrictions =")
@!@

