salmon.queue module

Simpler queue management than the regular mailbox.Maildir stuff. You do get a lot more features from the Python library, so if you need to do some serious surgery go use that. This works as a good API for the 90% case of “put mail in, get mail out” queues.

class salmon.queue.Queue(queue_dir, safe=False, pop_limit=0, oversize_dir=None)[source]

Bases: object

Provides a simplified API for dealing with ‘queues’ in Salmon. It currently just supports Maildir queues since those are the most robust, but could implement others later.

This gives the Maildir queue directory to use, and whether you want this Queue to use the SafeMaildir variant which hashes the hostname so you can expose it publicly.

The pop_limit and oversize_queue both set a upper limit on the mail you pop out of the queue. The size is checked before any Salmon processing is done and is based on the size of the file on disk. The purpose is to prevent people from sending 10MB attachments. If a message is over the pop_limit then it is placed into the oversize_dir (which should be a Maildir).

The oversize protection only works on pop messages off, not putting them in, get, or any other call. If you use get you can use self.oversize to also check if it’s oversize manually.

clear()[source]

Clears out the contents of the entire queue.

Warning: This could be horribly inefficient since it pops messages until the queue is empty. It could also cause an infinite loop if another process is writing to messages to the Queue faster than we can pop.

count()

Returns the number of messages in the queue.

get(key)[source]

Get the specific message referenced by the key. The message is NOT removed from the queue.

keys()[source]

Returns the keys in the queue.

oversize(key)[source]
pop()[source]

Pops a message off the queue, order is not really maintained like a stack.

It returns a (key, message) tuple for that item.

push(message)[source]

Pushes the message onto the queue. Remember the order is probably not maintained. It returns the key that gets created.

remove(key)[source]

Removes the queue, but not returned.

exception salmon.queue.QueueError(msg, data)[source]

Bases: Exception

class salmon.queue.SafeMaildir(dirname, factory=None, create=True)[source]

Bases: mailbox.Maildir

Initialize a Maildir instance.