####  GREYLIST - OPCJE i MAKRA ####

# options
# these need to be valid as xxx in mysql's DATE_ADD(..,INTERVAL xxx)
# not valid, for example, are plurals: "2 HOUR" instead of "2 HOURS"

GREYLIST_INITIAL_DELAY = 10 MINUTE
GREYLIST_INITIAL_LIFETIME = 4 HOUR
GREYLIST_WHITE_LIFETIME = 36 DAY
GREYLIST_BOUNCE_LIFETIME = 0 HOUR

# you can change the table names
GREYLIST_TABLE=exim_greylist
GREYLIST_LOG_TABLE=exim_greylist_log


# below here, nothing should normally be edited

# database macros
GREYLIST_TEST = SELECT CASE WHEN now() > block_expires THEN "accepted" ELSE "deferred" END AS result, id \
		FROM GREYLIST_TABLE WHERE (now() < record_expires) AND (sender = '${quote_mysql:$sender_address}' \
		OR (type='MANUAL' AND (sender IS NULL OR sender = '${quote_mysql:@$sender_address_domain}' ) ) ) \
		AND (recipient = '${quote_mysql:$local_part@$domain}' OR (type = 'MANUAL' AND (recipient IS NULL \
		OR recipient = '${quote_mysql:$local_part@}' OR recipient = '${quote_mysql:@$domain}' ) ) ) \
		AND (relay_ip = '${quote_mysql:$sender_host_address}' OR (type='MANUAL' AND (relay_ip IS NULL \
		OR relay_ip = substring('${quote_mysql:$sender_host_address}',1,length(relay_ip)) ) ) ) \
		ORDER BY result DESC LIMIT 1

GREYLIST_ADD = INSERT INTO GREYLIST_TABLE (relay_ip, sender, recipient, block_expires, record_expires, create_time, type) \
		VALUES ( '${quote_mysql:$sender_host_address}', '${quote_mysql:$sender_address}', \
		'${quote_mysql:$local_part@$domain}', DATE_ADD(now(), INTERVAL GREYLIST_INITIAL_DELAY), \
		DATE_ADD(now(), INTERVAL GREYLIST_INITIAL_LIFETIME), now(), 'AUTO' )

GREYLIST_DEFER_HIT = UPDATE GREYLIST_TABLE SET blockcount=blockcount+1 WHERE id = $acl_m9

GREYLIST_OK_COUNT = UPDATE GREYLIST_TABLE SET passcount=passcount+1 WHERE id = $acl_m9

GREYLIST_OK_NEWTIME = UPDATE GREYLIST_TABLE SET record_expires = DATE_ADD(now(), INTERVAL GREYLIST_WHITE_LIFETIME) \
		      WHERE id = $acl_m9 AND type='AUTO'

GREYLIST_OK_BOUNCE = UPDATE GREYLIST_TABLE SET record_expires = DATE_ADD(now(), INTERVAL GREYLIST_BOUNCE_LIFETIME) \
		     WHERE id = $acl_m9 AND type='AUTO'

GREYLIST_LOG = INSERT INTO GREYLIST_LOG_TABLE (listid, timestamp, kind) VALUES ($acl_m9, now(), '$acl_m8')
