slimta.relay.pipe

New in version 0.3.21.

Relays an Envelope locally to an external process. This functionality is modeled closely off the pipe daemon in postfix.

class slimta.relay.pipe.PipeRelay(args[, timeout=None[, **popen_kwargs]])

Bases: slimta.relay.Relay

When delivery attempts are made on this object, it will create a new subprocess and pipe envelope data to it. Delivery success or failure depends on the return code of the sub-process and error messages are pulled from standard error output.

To facilitate passing the Envelope metadata, the process’s command-line arguments can be populated with macros replaced using str.format() with corresponding keywords:

  • {sender}: The sender address.
  • {recipient}: The first address in the recipient last.
  • {message_id}: The Message-Id header.
  • {client_ip}: The client IP address string.
  • {client_host}: The reverse-lookup hostname of the client IP.
  • {client_ehlo}: The EHLO string given by the client.
  • {client_protocol}: The protocol used by the client.
  • {client_auth}: The authentication identity used by the client.
Parameters:
  • args – List of arguments used to spawn the external process, as you would provide them to the Popen constructor. Each argument has str.format() called on it, as described above.
  • timeout – The length of time a delivery is allowed to run before it fails transiently, default unlimited.
  • popen_kwargs – Extra keyword arguments passed in to the Popen.
per_recipient = True

If True, the process will be executed once per recipient.

raise_error(status, stdout, stderr)

This method may be over-ridden by sub-classes if you need to control how the relay error is generated. By default, the error raised is a TransientRelayError unless the process output begins with a 5.X.X enhanced status code. This behavior attempts to mimic the postfix pipe daemon.

This method is only called if the subprocess returns a non-zero exit status.

Parameters:
  • status – The non-zero exit status of the subprocess.
  • stdout (string) – The subprocess’s standard output, as received by communicate().
  • stderr (string) – The subprocess’s standard error output, as received by communicate().
Raises:

TransientRelayError, PermanentRelayError

attempt(envelope, attempts)

This method must be overridden by sub-classes in order to be passed in to the Queue constructor.

The result of a successful relay attempt is either None or a Reply object. The result of a failing relay attempt is either a PermanentRelayFailure or TransientRelayFailure error.

If the result applies to the entire envelope and all its recipients, implementations may return the successful result or raise the failure. If the result is different per-recipient, then implementations may return a dictionary where the key is a recipient from recipients and the value is the relay result (successful or failing).

Parameters:
  • envelopeEnvelope to attempt delivery for.
  • attempts – Number of times the envelope has attempted delivery.
Returns:

The relay result, as described above.

Raises:

PermanentRelayError, TransientRelayError

class slimta.relay.pipe.MaildropRelay([path=None[, timeout=None[, extra_args=None]]])

Bases: slimta.relay.pipe.PipeRelay

Variation of PipeRelay that is specifically tailored for calling courier-maildrop for local mail delivery.

Parameters:
  • path – The path to the maildrop command on the system. By default, $PATH is searched.
  • timeout – The length of time maildrop is allowed to run before it fails transiently, default unlimited.
  • extra_args – List of extra arguments, if any, to pass to maildrop. By default, only the sender is passed in with -f.
raise_error(status, stdout, stderr)

This method may be over-ridden by sub-classes if you need to control how the relay error is generated. By default, the error raised is a TransientRelayError unless the process output begins with a 5.X.X enhanced status code. This behavior attempts to mimic the postfix pipe daemon.

This method is only called if the subprocess returns a non-zero exit status.

Parameters:
  • status – The non-zero exit status of the subprocess.
  • stdout (string) – The subprocess’s standard output, as received by communicate().
  • stderr (string) – The subprocess’s standard error output, as received by communicate().
Raises:

TransientRelayError, PermanentRelayError

class slimta.relay.pipe.DovecotLdaRelay([path=None[, timeout=None[, extra_args=None]]])

Bases: slimta.relay.pipe.PipeRelay

Variation of PipeRelay that is specifically tailored for calling dovecot’s LDA for local mail delivery.

Parameters:
  • path – The path to the dovecot-lda command on the system. By default, $PATH is searched.
  • timeout – The length of time dovecot-lda is allowed to run before it fails transiently, default unlimited.
  • extra_args – List of extra arguments, if any, to pass to dovecot-lda. By default, only the sender and recipient are passed in with -f and -d, respectively.
raise_error(status, stdout, stderr)

This method may be over-ridden by sub-classes if you need to control how the relay error is generated. By default, the error raised is a TransientRelayError unless the process output begins with a 5.X.X enhanced status code. This behavior attempts to mimic the postfix pipe daemon.

This method is only called if the subprocess returns a non-zero exit status.

Parameters:
  • status – The non-zero exit status of the subprocess.
  • stdout (string) – The subprocess’s standard output, as received by communicate().
  • stderr (string) – The subprocess’s standard error output, as received by communicate().
Raises:

TransientRelayError, PermanentRelayError