pymailq.selector – Mails queue filtering

The selector module mainly provide a selector class to interact with structures from the store module.

MailSelector Objects

class selector.MailSelector(store)[source]

Mail selector class to request mails from store matching criterias.

The MailSelector instance provides the following attributes:

mails

Currently selected Mail objects list()

store

Linked PostqueueStore at the MailSelector instance initialization.

filters

Applied filters list() on current selection. Filters list entries are tuples containing (function.__name__, args, kwargs) for each applied filters. This list is filled by the filter_registration() decorator while calling filtering methods. It is possible to replay registered filter using replay_filters() method.

The MailSelector instance provides the following methods:

MailSelector.filter_registration(function)[source]

Decorator to register applied filter.

This decorated is used to wrap selection methods lookup_*. It registers a (function.__name__, args, kwargs) tuple() in the filters attribute.

MailSelector.reset()[source]

Reset mail selector with initial store mails list.

Selected Mail objects are deleted and the mails attribute is removed for memory releasing purpose (with help of gc.collect()). Attribute mails is then reinitialized a copy of store’s mails attribute.

Registered filters are also emptied.

MailSelector.replay_filters()[source]

Reset selection with store content and replay registered filters.

Like with the reset() method, selected Mail objects are deleted and reinitialized with a copy of store’s mails attribute.

However, registered filters are kept and replayed on resetted selection. Use this method to refresh your store content while keeping your filters.

MailSelector.get_mails_by_qids(qids)[source]

Get mails with specified IDs.

This function is not registered as filter.

Parameters:qids (list) – List of mail IDs.
Returns:List of newly selected Mail objects
Return type:list()
MailSelector.lookup_qids(*args, **kwargs)[source]

Lookup mails with specified IDs.

Parameters:qids (list) – List of mail IDs.
Returns:List of newly selected Mail objects
Return type:list()
MailSelector.lookup_status(*args, **kwargs)[source]

Lookup mails with specified postqueue status.

Parameters:status (list) – List of matching status to filter on.
Returns:List of newly selected Mail objects
Return type:list()
MailSelector.lookup_sender(*args, **kwargs)[source]

Lookup mails send from a specific sender.

Optionnal parameter partial allow lookup of partial sender like @domain.com or sender@. By default, partial is False and selection is made on exact sender.

Note

Matches are made against Mail.sender attribute instead of real mail header Sender.

Parameters:
  • sender (str) – Sender address to lookup in Mail objects selection.
  • exact (bool) – Allow lookup with partial or exact match
Returns:

List of newly selected Mail objects

Return type:

list()

MailSelector.lookup_recipient(*args, **kwargs)[source]

Lookup mails send to a specific recipient.

Optionnal parameter partial allow lookup of partial sender like @domain.com or sender@. By default, partial is False and selection is made on exact sender.

Note

Matches are made against Mail.recipients attribute instead of real mail header To.

Parameters:
  • recipient (str) – Recipient address to lookup in Mail objects selection.
  • exact (bool) – Allow lookup with partial or exact match
Returns:

List of newly selected Mail objects

Return type:

list()

MailSelector.lookup_error(*args, **kwargs)[source]

Lookup mails with specific error message (message may be partial).

Parameters:error_msg (str) – Error message to filter on
Returns:List of newly selected Mail objects`
Return type:list()
MailSelector.lookup_date(*args, **kwargs)[source]

Lookup mails send on specific date range(s).

Parameters:
Returns:

List of newly selected Mail objects

Return type:

list()

MailSelector.lookup_size(*args, **kwargs)[source]

Lookup mails send with specific size.

Both arguments smin and smax are optionnal and default is set to 0. Maximum size is ignored if setted to 0. If both smin and smax are setted to 0, no filtering is done and the entire Mail objects selection is returned.

Parameters:
  • smin (int) – Minimum size (Default: 0)
  • smax (int) – Maximum size (Default: 0)
Returns:

List of newly selected Mail objects

Return type:

list()