Implementation¶
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.
Parameters: Raises: notmuch.NotmuchError
if adding the message failsReturns: a
notmuch.Message
object
-
do_query
(query)[source]¶ 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.
Parameters: - query (str) – the query to execute using
Database.do_query()
- full_thread (bool) – return all messages from mathing threads
Returns: an iterator over
notmuch.Message
objects- query (str) – the query to execute using
-
mail_bodies_matching
(*args, **kwargs)[source]¶ Filters each message yielded from
Database.get_messages()
throughafew.utils.extract_mail_body()
.This functions accepts the same arguments as
Database.get_messages()
.Returns: an iterator over list
ofstr
-
remove_message
(path)[source]¶ Remove the given message from the notmuch index.
Parameters: path (str) – path to the message
-
Filter¶
Mail classification¶
Configuration management¶
Miscellanious utility functions¶
-
afew.utils.
extract_mail_body
(message)[source]¶ Extract the plain text body of the message with signatures stripped off.
Parameters: message ( notmuch.Message
) – the message to extract the body fromReturns: the extracted text body Return type: list
ofstr
-
afew.utils.
filter_compat
(*args)[source]¶ 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.
Parameters: - lines (
list
ofstr
) – a mail split at newlines - max_signature_size (int) – consider message parts up to this size as signatures
Returns: the mail with signatures stripped off
Return type: list
ofstr
>>> strip_signatures([ ... 'Huhu', ... '--', ... 'Ikke', ... ]) ['Huhu'] >>> strip_signatures([ ... 'Huhu', ... '--', ... 'Ikke', ... '**', ... "Sponsored by PowerDoh\'", ... "Sponsored by PowerDoh\'", ... "Sponsored by PowerDoh\'", ... "Sponsored by PowerDoh\'", ... "Sponsored by PowerDoh\'", ... ], 5) ['Huhu']
- lines (