Database Manager

The design of the database manager was inspired by alots database manager alot.db.DBManager.

class afew.Database.Database[source]

Convenience wrapper around notmuch.

add_message(path, sync_maildir_flags=False, new_mail_handler=None)[source]

Adds the given message to the notmuch index.

  • path (str) – path to the message
  • sync_maildir_flags (bool) – if True notmuch converts the standard maildir flags to tags
  • new_mail_handler (a function that is called with a notmuch.Message object as its only argument) – callback for new messages

notmuch.NotmuchError if adding the message fails


a notmuch.Message object


Closes the notmuch database if it has been opened.


Executes a notmuch query.

Parameters:query (str) – the query to execute
Returns:the query result
Return type:notmuch.Query
get_messages(query, full_thread=False)[source]

Get all messages mathing the given query.


an iterator over notmuch.Message objects

mail_bodies_matching(*args, **kwargs)[source]

Filters each message yielded from Database.get_messages() through afew.utils.extract_mail_body().

This functions accepts the same arguments as Database.get_messages().

Returns:an iterator over list of str

Remove the given message from the notmuch index.

Parameters:path (str) – path to the message

Returns all replies to the given message.

Parameters:message (notmuch.Message) – the message to start from
Returns:an iterator over notmuch.Message objects

Returns all messages in the given thread.

Parameters:message (notmuch.Thread) – the tread you are interested in
Returns:an iterator over notmuch.Message objects


Mail classification

class afew.DBACL.Classifier(categories, database_directory=u'/home/docs/.local/share/afew/categories')[source]
class afew.DBACL.DBACL(database_directory=u'/home/docs/.local/share/afew/categories')[source]

Configuration management

Miscellanious utility functions


Extract the plain text body of the message with signatures stripped off.

Parameters:message (notmuch.Message) – the message to extract the body from
Returns:the extracted text body
Return type:list of str

Compatibility wrapper for filter builtin.

The semantic of the filter builtin has been changed in python3.x. This is a temporary workaround to support both python versions in one code base.

afew.utils.strip_signatures(lines, max_signature_size=10)[source]

Strip signatures from a mail. Used to filter mails before classifying mails.

  • lines (list of str) – a mail split at newlines
  • max_signature_size (int) – consider message parts up to this size as signatures

the mail with signatures stripped off

Return type:

list of str

>>> strip_signatures([
...     'Huhu',
...     '--',
...     'Ikke',
... ])
>>> strip_signatures([
...     'Huhu',
...     '--',
...     'Ikke',
...     '**',
...     "Sponsored by PowerDoh\'",
...     "Sponsored by PowerDoh\'",
...     "Sponsored by PowerDoh\'",
...     "Sponsored by PowerDoh\'",
...     "Sponsored by PowerDoh\'",
... ], 5)