chapps.actions module

Actions

These classes intepret policy manager output to produce instructions for Postfix.

class chapps.actions.PostfixActions[source]

Bases: object

Superclass for Postfix action adapters

static dunno(*args, **kwargs)[source]

Return the Postfix directive DUNNO

static okay(*args, **kwargs)[source]

Return the Postfix directive OK

static ok(*args, **kwargs)

ok() is an alias for okay()

static defer_if_permit(msg, *args, **kwargs)[source]

Return the Postfix DEFER_IF_PERMIT directive with the provided message

static reject(msg, *args, **kwargs)[source]

Return the Postfix REJECT directive along with the provided message

static prepend(*args, **kwargs)[source]

Return the Postfix PREPEND directive. Include the header to prepend as keyword-argument prepend

__init__(cfg=None)[source]

Optionally supply a chapps.config.CHAPPSConfig instance as the first argument.

action_for(*args, **kwargs)[source]

Abstract method which must be implemented in subclasses.

This method is intended to map responses from a policy manager onto Postfix directives.

Not all policy managers return only yes/no answers. Some, like chapps.spf_policy.SPFEnforcementPolicy, return a handful of different possible values, and so there must be a mechanism for allowing sites to determine what happens when each of those different outcomes occurs.

class chapps.actions.PostfixPassfailActions[source]

Bases: chapps.actions.PostfixActions

Postfix Actions adapter for PASS/FAIL policy responses.

Many policies return True if the email should be accepted/forwarded and return False if the email should be rejected/dropped. This class encapsulates the common case, and includes some logic to extract precise instructions from the config.

__init__(cfg=None)[source]

Optionally supply a chapps.config.CHAPPSConfig instance as the first argument.

action_for(pf_result)[source]

Return an action closure for a pass/fail policy

Evaluates its argument pf_result as a boolean and returns the action closure for ‘passing’ if True, otherwise the action closure for ‘fail’. To provide backwards-compatibility with older versions, and to allow for more descriptive configuration elements, the actions may be attached to keys named acceptance_message or rejection_message instead of passing and fail respectively. This is only true of policies with action factories inheriting from chapps.actions.PostfixPassfailActions

class chapps.actions.PostfixOQPActions[source]

Bases: chapps.actions.PostfixPassfailActions

Postfix Action translator for chapps.policy.OutboundQuotaPolicy

__init__(cfg=None)[source]

Optionally provide an instance of :py::class`chapps.config.CHAPPSConfig`.

All this class does is wire up self.config to point at the chapps.policy.OutboundQuotaPolicy config block.

class chapps.actions.PostfixGRLActions[source]

Bases: chapps.actions.PostfixPassfailActions

Postfix Action translator for chapps.policy.GreylistingPolicy

__init__(cfg=None)[source]

Optionally provide an instance of chapps.config.CHAPPSConfig.

All this class does is wire up self.config to point at the chapps.policy.GreylistingPolicy config block.

class chapps.actions.PostfixSPFActions[source]

Bases: chapps.actions.PostfixActions

Postfix Action translator for chapps.policy.SPFEnforcementPolicy

Caution

The SPF functionality of CHAPPS is not considered complete. YMMV

greylisting_policy = <chapps.policy.GreylistingPolicy object>

Reference to a class-global chapps.policy.GreylistingPolicy instance.

This implementation is poor and will change in future revisions.

static greylist(msg, *args, **kwargs)[source]

This method is meant to share the same signature as the other action methods, mainly defined on chapps.actions.PostfixActions

The greylist action causes the email in question to be greylisted, according to the policy. The msg is used as the message for the Postfix directive, or if the message has no contents and the email is being deferred, the string “due to SPF enforcement policy” is used. Because the greylisting policy’s message is prepended later, the actual message delivered by Postfix will look something like “greylisted due to SPF enforcement policy”.

Right now chapps.actions.PostfixSPFActions uses a declared class-global chapps.policy.GreylistingPolicy instance, which will change in a future revision so that an overriding config may be provided for initialization of that instance.

__init__(cfg=None)[source]

Optionally pass CHAPPSConfig override.

All this init routine needs to do is adjust self.config to refer to the [PostfixSPFActions] config block.

action_for(spf_result)[source]

Override chapps.actions.PostfixActions.action_for() to provide action closures for the different SPF results. The closures are memoized, so that they only need be constructed once per runtime.