pymailq.control – Mails queue adminitrative operations

The control module define a basic python class to simplify administrative operations against the mails queue. This module is mainly based on the postsuper administrative tool functionnalities.

QueueControl Objects

class control.QueueControl[source]

Postfix queue control using postsuper command.

The QueueControl instance defines the following attributes:

use_sudo

Boolean to control the use of sudo to invoke Postfix command. Default is False

postsuper_cmd

Postfix command and arguments list() for mails queue administrative operations. Default is ["postsuper"]

known_operations

Known Postfix administrative operations dict to associate operations to command arguments. Known associations are:

 delete: -d
   hold: -h
release: -H
requeue: -r

Warning

Default known associations are provided for the default mails queue administrative command postsuper.

See also

Postfix manual:
postsuper – Postfix superintendent

The QueueControl instance provides the following methods:

static QueueControl.get_operation_cmd(operation)[source]

Get operation related command from configuration

This method use Postfix administrative commands defined in pymailq.CONFIG attribute under the key ‘list_queue’. Command and arguments list is build on call with the configuration data.

Command keys are built with the operation argument suffixed with _message. Example: hold_message for the hold command.

Parameters:operation (str) – Operation name
Returns:Command and arguments as list
Raises:KeyError – Operation is unknown
QueueControl._operate(*args, **kwargs)[source]

Generic method to lead operations messages from postfix mail queue.

Operations can be one of Postfix known operations stored in PyMailq module configuration.

Parameters:
  • operation (str) – Known operation from pymailq.CONFIG.
  • messages (list) – List of Mail objects targetted for operation.
Returns:

Command’s stderr output lines

Return type:

list()

QueueControl.delete_messages(messages)[source]

Delete several messages from postfix mail queue.

This method is a partial() wrapper on _operate(). Passed operation is delete

QueueControl.hold_messages(messages)[source]

Hold several messages from postfix mail queue.

This method is a partial() wrapper on _operate(). Passed operation is hold

QueueControl.release_messages(messages)[source]

Release several messages from postfix mail queue.

This method is a partial() wrapper on _operate(). Passed operation is release

QueueControl.requeue_messages(messages)[source]

Requeue several messages from postfix mail queue.

This method is a partial() wrapper on _operate(). Passed operation is requeue