Sovite.Core.PolicyService (sovite v0.6.0)

Copy Markdown View Source

check_policy_service ADDRESS in the restriction chains: asks a Postfix policy server (https://www.postfix.org/SMTPD_POLICY_README.html) such as postgrey or policyd-spf, with Sovite.Policy.Client.

ADDRESS is inet:host:port, unix:/path, or spawn:/path/to/program args..., for programs that speak the protocol on their standard input and output, as Postfix's spawn(8) runs policyd-spf. Each request uses a new connection.

The request has the attributes Postfix sends; protocol_state is the stage (CONNECT, EHLO, MAIL, RCPT, DATA, END-OF-MESSAGE). The reply's action counts like an access rule (access(5)):

ActionEffect
OKAccept, ending the list.
DUNNO, DEFER_IF_REJECTGo on with the next check.
REJECT [text], DEFER [text], DEFER_IF_PERMIT [text]554 5.7.1, 450 4.7.1, 450 4.7.1.
4NN/5NN [x.y.z] textThat reply.
HOLD [text], DISCARD [text]Hold or drop the message.
WARN text, INFO textLog, and go on.
PREPEND name: valueAdd the header field at the top of the message.
REDIRECT addressDeliver the message to address only.
BCC addressAlso deliver it to address.
FILTER transport:nexthopSend it to that content filter (see smtp.content_filter).

When the server cannot be reached, does not answer within policy.timeout, or sends something else, policy.default_action applies (451 4.3.5 Server configuration problem by default), and the error is reported with [:sovite, :policy, :client, :error].

Summary

Types

A decision, as Sovite.Core.Restrictions checks make them.

What a check adds to the message, besides a decision.

Functions

Asks the server at address about stage. context is the restriction context: it has :policy (%{timeout, default_action}, the action already parsed) and :policy_request, a function that returns the attributes of the session.

The session part of a request, from what the SMTP handler knows. Values that are not known are left out.

Whether address is a policy server address.

Types

decision()

@type decision() ::
  :continue
  | :permit
  | {:reject, Sovite.SMTP.Reply.t()}
  | {:hold, String.t()}
  | {:discard, String.t()}
  | {:effect, effect()}

A decision, as Sovite.Core.Restrictions checks make them.

effect()

@type effect() ::
  {:prepend, String.t()}
  | {:redirect, String.t()}
  | {:bcc, String.t()}
  | {:filter, String.t()}

What a check adds to the message, besides a decision.

Functions

check(address, stage, context)

@spec check(String.t(), atom(), map()) :: decision()

Asks the server at address about stage. context is the restriction context: it has :policy (%{timeout, default_action}, the action already parsed) and :policy_request, a function that returns the attributes of the session.

request(info)

@spec request(map()) :: %{required(String.t()) => term()}

The session part of a request, from what the SMTP handler knows. Values that are not known are left out.

valid_address?(address)

@spec valid_address?(String.t()) :: boolean()

Whether address is a policy server address.