slimta.queue.dict

Package implementing the slimta.queue system on top of a dict() backend. This backend can be implemented as a shelve to provide basic persistence.

class slimta.queue.dict.DictStorage([envelope_db=None[, meta_db=None]])

Bases: slimta.queue.QueueStorage

Stores Envelope and queue metadata in two basic dictionary objects.

Parameters
  • envelope_db – The dictionary object to hold Envelope objects, keyed by a unique string. Defaults to an empty dict().

  • meta_db – The dictionary object to hold envelope metadata, keyed by the same string as envelope_db. Defaults to an empty dict().

write(envelope, timestamp)

Writes the given envelope to storage, along with the timestamp of its next delivery attempt. The number of delivery attempts asociated with the message should start at zero.

Parameters
  • envelopeEnvelope object to write.

  • timestamp – Timestamp of message’s next delivery attempt.

Returns

Unique identifier string for the message in queue.

Raises

QueueError

set_timestamp(id, timestamp)

Sets a new timestamp for the message’s next delivery attempt.

Parameters
  • id – The unique identifier string for the message.

  • timestamp – The new delivery attempt timestamp.

Raises

QueueError

increment_attempts(id)

Increments the number of delivery attempts associated with the message.

Parameters

id – The unique identifier string for the message.

Returns

The new number of message delivery attempts.

Raises

QueueError

set_recipients_delivered(id, rcpt_indexes)

New in version 1.1.0.

Marks the given recipients from the original envelope as already-delivered, meaning they will be skipped by future relay attempts.

Parameters
  • id – The unique identifier string for the message.

  • rcpt_indexes – List of indexes in the original envelope’s recipients list to mark as delivered.

Raises

QueueError

load()

Loads all queued messages from the storage engine, such that the Queue can be aware of all upcoming delivery attempts.

Returns

Iterable that yields tuples of the form (timestamp, id) for each message in storage.

Raises

QueueError

get(id)

Returns the Envelope object associated with the given unique identifier sring.

The envelope’s recipients should not include those marked as delivered by set_recipients_delivered().

Parameters

id – The unique identifier string of the requested Envelope.

Returns

Tuple with the Envelope object and number of attempts.

Raises

KeyError, QueueError

remove(id)

Removes the Envelope associated with the given unique identifier string from queue storage. This is typically used when the message has been successfully delivered or delivery has permanently failed.

Parameters

id – The unique identifier string of the Envelope to remove.

Raises

QueueError

get_info()

New in version 0.3.20.

Queries the storage backend for relevant information about the contents of the queue. The result is a dict() containing required keys along with any other custom keys dependent on the particular backend.

Only one key is required in the result:

  • size: The number of messages currently in the queue.

Return type

dict()