greylist_acl:
  # clean expired greylist records at 00 and 30 of all day minutes
  # does't really works
  # warn  condition       = ${if or {{eq {${substr{10}{2}{$tod_zulu}} }{00}}{eq {${substr{10}{2}{$tod_zulu}} }{30}} }{yes}{no}}
  #       condition       = ${lookup pgsql{GREYLIST_CLEAN}{yes}{yes}}
  #       condition       = ${lookup pgsql{GREYLIST_LOG_CLEAN}{yes}{yes}}
  #       log_message     = clean expired greylist records

  # Dumb cleanup
  warn    condition       = ${lookup pgsql{GREYLIST_CLEAN}{yes}{yes}}
  warn    condition       = ${lookup pgsql{GREYLIST_LOG_CLEAN}{yes}{yes}}


  # For regular deliveries, check greylist.

  # check greylist tuple, returning "accepted", "deferred" or "unknown"
  # in acl_m8, and the record id in acl_m9

  warn  set acl_m8       = ${lookup pgsql{GREYLIST_TEST}{$value}{result=unknown}}
        # here acl_m8 = "result=x id=y"
        set acl_m9       = ${extract{id}{$acl_m8}{$value}{-1}}
        # now acl_m9 contains the record id (or -1)
        set acl_m8       = ${extract{result}{$acl_m8}{$value}{unknown}}
        # now acl_m8 contains unknown/deferred/accepted
        log_message     = check greylist tuple, set '$acl_m8'

  # log anything
  .ifdef GREYLIST_ENABLED_LOG
  warn  condition        = ${lookup pgsql{GREYLIST_LOG}{yes}{no}}
  .endif

  # check if we know a certain triple, add and defer message if not
  accept
       # if above check returned unknown (no record yet)
       condition        = ${if eq {$acl_m8} {unknown}}
       # then also add a record
       condition        = ${lookup pgsql{GREYLIST_ADD}{yes}{no}}

  # check if the triple is still blocked
  accept
       # if above check returned deferred then defer
       condition        = ${if eq{$acl_m8} {deferred}}
       # and note it down
       condition        = ${lookup pgsql{GREYLIST_DEFER_HIT}{yes}{yes}}

  # use a warn verb to count records that were hit
  warn  condition        = ${lookup pgsql{GREYLIST_OK_COUNT}}

  # use a warn verb to set a new expire time on automatic records,
  # but only if the mail was not a bounce, otherwise set to now().
  warn  !senders         = : postmaster@* : Mailer-Daemon@*
        condition        = ${lookup pgsql{GREYLIST_OK_NEWTIME}}
  warn  senders          = : postmaster@* : Mailer-Daemon@*
        condition        = ${lookup pgsql{GREYLIST_OK_BOUNCE}}

  deny