rules {
  QUARANTINE {
    backend = "http";
    url = "http://nginx:9081/pipe.php";
    selector = "reject_no_global_bl";
    formatter = "default";
    meta_headers = true;
  }
	RLINFO {
		backend = "http";
		url = "http://nginx:9081/pipe_rl.php";
		selector = "ratelimited";
		formatter = "json";
	}
  PUSHOVERMAIL {
    backend = "http";
    url = "http://nginx:9081/pushover.php";
    selector = "mailcow_rcpt";
    formatter = "json";
    meta_headers = true;
  }
}

custom_select {
  mailcow_rcpt = <<EOD
return function(task)
  local action = task:get_metric_action('default')
  if task:has_symbol('NO_LOG_STAT') or (action == 'soft reject' or action == 'reject' or action == 'add header' or action == 'rewrite subject') then
    return false
  else
    if task:get_symbol("RCPT_MAILCOW_DOMAIN") then
      return true
    end
    return false
  end
end
EOD;
  ratelimited = <<EOD
return function(task)
  local ratelimited = task:get_symbol("RATELIMITED")
  if ratelimited then
    return true
  end
  return false
end
EOD;
  reject_no_global_bl = <<EOD
return function(task)
  if not task:has_symbol('GLOBAL_SMTP_FROM_BL')
    and not task:has_symbol('GLOBAL_MIME_FROM_BL')
    and not task:has_symbol('LOCAL_BL_ASN')
    and not task:has_symbol('GLOBAL_RCPT_BL')
    and not task:has_symbol('BAD_SUBJECT_00')
    and not task:has_symbol('MAILCOW_BLACK') then
      local action = task:get_metric_action('default')
      if action == 'reject' or action == 'add header' or action == 'rewrite subject' then
        return true
      end
  end
  return false
end
EOD;
}

custom_format {
  msgid = <<EOD
return function(task)
  return task:get_message_id()
end
EOD;
}

