slimta.policy.forward

Implements a simple forwarding policy, to transform or replace recipients.

class slimta.policy.forward.Forward

Bases: slimta.policy.QueuePolicy

Each Envelope recipient is run through re.sub() to see if it is modified. If a recipient matches a mapping rule, no further mapping rules are processed. Mapping rules are checked in the order that they were added.

add_mapping(pattern, repl[, count=0])

Adds a mapping rule.

Parameters:
  • pattern (str or re.RegexObject) – Pattern to check recipient against.
  • repl (str or function) – Replacement for pattern matches, as described by re.sub().
  • count – Max number of replacements per recipient string.
apply(envelope)

QueuePolicy sub-classes must override this method, which will be called by the Queue before storage.

Parameters:envelope – The Envelope object the policy execution should apply any changes to. This envelope object may be modified, though if new envelopes are returned this object is discarded.
Returns:Optionally return or generate an iterable of Envelope objects to replace the given envelope going forward. Returning None or an empty list will keep using envelope.