The python bindings to libnotmuch define notmuch.Thread and notmuch.Message, which unfortunately are very fragile. Alot defines the wrapper classes alot.db.Thread and alot.db.Message that use an manager.DBManager instance to transparently provide persistent objects.
alot.db.Message moreover contains convenience methods to extract information about the message like reformated header values, a summary, decoded and interpreted body text and a list of Attachments.
The central UI instance carries around a DBManager object that is used for any lookups or modifications of the email base. DBManager can directly look up Thread and Message objects and is able to postpone/cache/retry writing operations in case the Xapian index is locked by another process.
Keeps track of your index parameters, maintains a write-queue and lets you look up threads and messages directly to the persistent wrapper classes.
Parameters: |
---|
Adds a file to the notmuch index.
Parameters: |
|
---|
return a pair (pipe, process) so that the process writes fun(a) to the pipe for each element a in the iterable returned by the callable cbl.
Parameters: | |
---|---|
Return type: | (multiprocessing.Pipe, multiprocessing.Process) |
returns number of messages that match querystring
returns number of threads that match querystring
write out all queued write-commands in order, each one in a separate atomic transaction.
If this fails the current action is rolled back, stays in the write queue and an exception is raised. You are responsible to retry flushing at a later time if you want to ensure that the cached changes are applied to the database.
Exception: | DatabaseROError if db is opened read-only |
---|---|
Exception: | DatabaseLockedError if db is locked |
returns all tagsstrings used in the database :rtype: list of str
asynchronously look up thread ids matching querystring.
Parameters: |
|
---|---|
Returns: | a pipe together with the process that asynchronously writes to it. |
Return type: | (multiprocessing.Pipe, multiprocessing.Process) |
terminate all search processes that originate from this managers get_threads().
creates notmuch.Query objects on demand
Parameters: | querystring – The query string to use for the lookup |
---|---|
Returns: | notmuch.Query – the query object. |
Remove a message from the notmuch index
Parameters: |
|
---|
returns the ids of all threads that match the querystring This copies! all integer thread ids into an new list.
Returns: | list of str |
---|
add tags to messages matching querystring. This appends a tag operation to the write queue and raises DatabaseROError if in read only mode.
Parameters: | |
---|---|
Exception: |
Note
This only adds the requested operation to the write queue. You need to call DBManager.flush() to actually write out.
removes tags from messages that match querystring. This appends an untag operation to the write queue and raises DatabaseROError if in read only mode.
Parameters: | |
---|---|
Exception: |
Note
This only adds the requested operation to the write queue. You need to call DBManager.flush() to actually write out.
cannot write to read-only database
cannot write to locked index
requested thread or message does not exist in the index
A wrapper around a notmuch mailthread (notmuch.database.Thread) that ensures persistence of the thread: It can be safely read multiple times, its manipulation is done via a alot.db.DBManager and it can directly provide contained messages as Message.
Parameters: |
|
---|
add tags to all messages in this thread
Note
This only adds the requested operation to this objects DBManager's write queue. You need to call DBManager.flush to actually write out.
Parameters: |
---|
returns a list of authors (name, addr) of the messages. The authors are ordered by msg date and unique (by addr).
Return type: | list of (str, str) |
---|
returns a string of comma-separated authors Depending on settings, it will substitute “me” for author name if address is user’s own.
Parameters: |
|
---|---|
Return type: | str |
returns all messages in this thread as dict mapping all contained messages to their direct responses.
Return type: | dict mapping Message to a list of Message. |
---|
returns all replies to the given message contained in this thread.
Parameters: | msg (Message) – parent message to look up |
---|---|
Returns: | list of Message or None |
returns subject string
returns tagsstrings attached to this thread
Parameters: | intersection (bool) – return tags present in all contained messages instead of in at least one (union) |
---|---|
Return type: | set of str |
returns id of this thread
returns all toplevel messages contained in this thread. This are all the messages without a parent message (identified by ‘in-reply-to’ or ‘references’ header.
Return type: | list of Message |
---|
returns number of contained messages
Check if this thread matches the given notmuch query.
Parameters: | query (string) – The query to check against |
---|---|
Returns: | True if this thread matches the given query, False otherwise |
Return type: | bool |
refresh thread metadata from the index
remove tags (list of str) from all messages in this thread
Note
This only adds the requested operation to this objects DBManager's write queue. You need to call DBManager.flush to actually write out.
Parameters: |
|
---|
a persistent notmuch message object. It it uses a DBManager for cached manipulation and lazy lookups.
Parameters: |
|
---|
returns bodystring extracted from this mail
adds tags to message
Note
This only adds the requested operation to this objects DBManager's write queue. You need to call flush() to write out.
Parameters: |
---|
returns messages attachments
Derived from the leaves of the email mime tree that and are not part of RFC 2015 syntax for encrypted/signed mails and either have Content-Disposition attachment or have Content-Disposition inline but specify a filename (as parameter to Content-Disposition).
Return type: | list of Attachment |
---|
returns realname and address of this messages author
Return type: | (str,str) |
---|
returns reformated datestring for this message.
It uses SettingsManager.represent_datetime() to represent this messages Date header
Return type: | str |
---|
returns email.Message for this message
returns absolute path of message files location
returns subset of this messages headers as human-readable format: all header values are decoded, the resulting string has one line “KEY: VALUE” for each requested header present in the mail.
Parameters: | headers (list of str) – headers to extract |
---|
returns messages id (str)
returns a list of all body parts of this message
returns replies to this message as list of Message
returns tags attached to this message as list of strings
returns id (str) of the thread this message belongs to
returns true if this message has at least one reply
tests if this messages is in the resultset for querystring
remove tags from message
Note
This only adds the requested operation to this objects DBManager's write queue. You need to call flush() to actually out.
Parameters: |
|
---|
represents a mail attachment
Parameters: | emailpart (email.message.Message) – a non-multipart email that is the attachment |
---|
mime type of the attachment part
return data blob from wrapped file
return name of attached file. If the content-disposition header contains no file name, this returns None
returns mime part that constitutes this attachment
returns attachments size in bytes
save the attachment to disk. Uses get_filename() in case path is a directory
writes content to a given filehandle
a message that is not yet sent and still editable. It holds references to unencoded! body text and mail headers among other things. Envelope implements the python container API for easy access of header values. So e[‘To’], e[‘To’] = ‘foo@bar.baz’ and ‘e.get_all(‘To’)’ would work for an envelope e..
Parameters: |
|
---|
add header value
attach a file
Parameters: |
|
---|
compiles the information contained in this envelope into a email.Message.
secure getter for header values that allows specifying a fallback return string (defaults to None). This returns the first matching value and doesn’t raise KeyErrors
returns all header values for given key
parses a template or user edited string to fills this envelope.
Parameters: |
---|
list of Attachments
mail body as unicode string
dict containing the mail headers (a list of strings for each header key)
tags to add after successful sendout
template text for initial content
Add pseudo headers to the mail indicating whether the signature verification was successful.
Parameters: |
|
---|
decode a header value to a unicode string
values are usually a mixture of different substrings encoded in quoted printable using different encodings. This turns it into a single unicode string
Parameters: | |
---|---|
Return type: | unicode |
encodes a unicode string as a valid header value
Parameters: |
---|
returns a body text string for given mail. If types is None, text/* is used: The exact preferred type is specified by the prefer_plaintext config option which defaults to text/html.
Parameters: |
|
---|
returns subset of this messages headers as human-readable format: all header values are decoded, the resulting string has one line “KEY: VALUE” for each requested header present in the mail.
Parameters: |
|
---|
Get Content-Type parameters as dict.
RFC 2045 specifies that parameter names are case-insensitive, so we normalize them here.
Parameters: |
|
---|---|
Returns: | a dict containing the parameters |
Reads a mail from the given file-like object and returns an email object, very much like email.message_from_file. In addition to that OpenPGP encrypted data is detected and decrypted. If this succeeds, any mime messages found in the recovered plaintext message are added to the returned message object.
Parameters: | handle – a file-like object |
---|---|
Returns: | email.message.Message possibly augmented with decrypted data |
Reads a mail from the given string. This is the equivalent of email.message_from_string() which does nothing but to wrap the given string in a StringIO object and to call email.message_from_file().
Please refer to the documentation of message_from_file() for details.