Documentation
¶
Overview ¶
Package notmuch provides a Go language binding to the notmuch mail library.
The design is similar enough to the underlying C library that familiarity with one will inform the other. There are some differences, however:
- The Go binding arranges for the garbage collector to deal with objects allocated by notmuch correctly. You should close the database manually, but everything else will be garbage collected when it becomes unreachable, and not before. Objects hold references to their parent objects to make this go smoothly.
- If notmuch returns NULL because of an out of memory error, Go will panic, as it does with other out of memory errors.
- Some of the names have been shortened or made more idiomatic. The documentation indends to make it obvious when this is the case.
- Functions which create a child object from a parent object are methods on the parent object, rather than stand-alone functions.
- Functions which in C return a status code and pass back a value via a pointer argument now return a (value, error) pair.
Index ¶
- Constants
- Variables
- func Compact(path, backup string) error
- type ConfigList
- type DB
- func (db *DB) AddMessage(filename string) (*Message, error)
- func (db *DB) Atomic(callback func(*DB)) error
- func (db *DB) Close() error
- func (db *DB) FindMessage(id string) (*Message, error)
- func (db *DB) FindMessageByFilename(filename string) (*Message, error)
- func (db *DB) GetConfig(key string) (string, error)
- func (db *DB) GetConfigList(prefix string) (*ConfigList, error)
- func (db *DB) LastStatus() string
- func (db *DB) NeedsUpgrade() bool
- func (db *DB) NewQuery(queryString string) *Query
- func (db *DB) Path() string
- func (db *DB) RemoveMessage(filename string) error
- func (db *DB) SetConfig(key, value string) error
- func (db *DB) Tags() (*Tags, error)
- func (db *DB) Upgrade() error
- func (db *DB) Version() int
- type DBMode
- type ExcludeMode
- type Filenames
- type Message
- func (m *Message) AddProperty(key string, value string) error
- func (m *Message) AddTag(tag string) error
- func (m *Message) Atomic(callback func(*Message)) error
- func (m *Message) Close() error
- func (m *Message) Date() time.Time
- func (m *Message) Filename() string
- func (m *Message) Filenames() *Filenames
- func (m *Message) Header(name string) string
- func (m *Message) ID() string
- func (m *Message) MaildirFlagsToTags() error
- func (m *Message) Properties(key string, exact bool) *MessageProperties
- func (m *Message) RemoveAllProperties(key string) error
- func (m *Message) RemoveAllTags() error
- func (m *Message) RemoveProperty(key string, value string) error
- func (m *Message) RemoveTag(tag string) error
- func (m *Message) Replies() (*Messages, error)
- func (m *Message) Tags() *Tags
- func (m *Message) TagsToMaildirFlags() error
- func (m *Message) ThreadID() string
- type MessageProperties
- type MessageProperty
- type Messages
- type Query
- func (q *Query) AddTagExclude(tag string) error
- func (q *Query) Close() error
- func (q *Query) CountMessages() int
- func (q *Query) CountThreads() int
- func (q *Query) Messages() (*Messages, error)
- func (q *Query) SetExcludeScheme(mode ExcludeMode)
- func (q *Query) SetSortScheme(mode SortMode)
- func (q *Query) String() string
- func (q *Query) Threads() (*Threads, error)
- type SortMode
- type Tag
- type Tags
- type Thread
- func (t *Thread) Authors() ([]string, []string)
- func (t *Thread) Close() error
- func (t *Thread) Count() int
- func (t *Thread) CountMatched() int
- func (t *Thread) ID() string
- func (t *Thread) Messages() *Messages
- func (t *Thread) NewestDate() time.Time
- func (t *Thread) OldestDate() time.Time
- func (t *Thread) Subject() string
- func (t *Thread) Tags() *Tags
- func (t *Thread) TopLevelMessages() *Messages
- type Threads
Constants ¶
const ( // DBReadOnly is the mode for opening the database in read only. DBReadOnly = C.NOTMUCH_DATABASE_MODE_READ_ONLY // DBReadWrite is the mode for opening the database in read write. DBReadWrite = C.NOTMUCH_DATABASE_MODE_READ_WRITE // TagMax is the maximum number of allowed tags. TagMax = C.NOTMUCH_TAG_MAX )
Variables ¶
var ( // ErrOutOfMemory is returned when an Out of memory occured. ErrOutOfMemory = statusErr(C.NOTMUCH_STATUS_OUT_OF_MEMORY) // ErrReadOnlyDB is returned when an attempt was made to write to a // database opened in read-only mode. ErrReadOnlyDB = statusErr(C.NOTMUCH_STATUS_READ_ONLY_DATABASE) // ErrXapianException is returned when a xapian exception occured. ErrXapianException = statusErr(C.NOTMUCH_STATUS_XAPIAN_EXCEPTION) // ErrFileError is returned when an error occurred trying to read or write to // a file (this could be file not found, permission denied, etc.) ErrFileError = statusErr(C.NOTMUCH_STATUS_FILE_ERROR) // ErrFileNotEmail is returned when a file was presented that doesn't appear // to be an email message. ErrFileNotEmail = statusErr(C.NOTMUCH_STATUS_FILE_NOT_EMAIL) // ErrDuplicateMessageID is returned when a file contains a message ID that // is identical to a message already in the database. ErrDuplicateMessageID = statusErr(C.NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) // ErrNullPointer is returned when the user erroneously passed a NULL pointer // to a notmuch function. ErrNullPointer = statusErr(C.NOTMUCH_STATUS_NULL_POINTER) // ErrTagTooLong is returned when a tag value is too long (exceeds TagMax) ErrTagTooLong = statusErr(C.NOTMUCH_STATUS_TAG_TOO_LONG) // ErrUnbalancedFreezeThaw is returned when Message.Thaw() was called more // times than Message.Freeze(). ErrUnbalancedFreezeThaw = statusErr(C.NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW) // ErrUnbalancedAtomic DB.EndAtomic() has been called more times than DB.BeginAtomic() ErrUnbalancedAtomic = statusErr(C.NOTMUCH_STATUS_UNBALANCED_ATOMIC) // ErrUnsupportedOperation is returned when the operation is not supported. ErrUnsupportedOperation = statusErr(C.NOTMUCH_STATUS_UNSUPPORTED_OPERATION) // ErrUpgradeRequired is returned when the database requires an upgrade. ErrUpgradeRequired = statusErr(C.NOTMUCH_STATUS_UPGRADE_REQUIRED) // ErrIgnored is returned if the operation was ignored ErrIgnored = statusErr(C.NOTMUCH_STATUS_IGNORED) // ErrNotFound is returned when Find* did not find the thread/message by id or filename. ErrNotFound = errors.New("not found") // ErrUnknownError is returned when notmuch returns NULL indicating an error. ErrUnknownError = errors.New("unknown error occured") // ErrNoRepliesOrPointerNotFromThread is returned if a message has no replies or if the message's C // pointer did not come from a thread. ErrNoRepliesOrPointerNotFromThread = errors.New("message has no replies or message's pointer not from a thread") )
Functions ¶
Types ¶
type ConfigList ¶
type ConfigList cStruct
Messages represents a notmuch config list
func (*ConfigList) Close ¶
func (cl *ConfigList) Close() error
func (*ConfigList) Next ¶
func (cl *ConfigList) Next(key, value *string) bool
Next retrieves the nex config pair from the ConfigList. Neither key, nor value may be nil, or this function will panic. Next returns true if a pair was successfully retrieved.
type DB ¶
type DB cStruct
DB represents a notmuch database.
func Open ¶
Open opens the database at the location path using mode. Caller is responsible for closing the database when done.
func OpenWithConfig ¶
OpenWithConfig opens the database at the location 'path' using 'mode' and the configuration in 'config'.
If 'path' is nil, use the location specified:
- in the environment variable $NOTMUCH_DATABASE, if non-empty
- in a configuration file, located as described in 'config'
- by $XDG_DATA_HOME/notmuch/<profile>, if profile argument is set
If 'path' is non-nil, but does not appear to be a Xapian database, check for a directory '.notmuch/xapian' below 'path'.
If 'config' is nil, it will look:
- the environment variable $NOTMUCH_CONFIG, if non-empty
- $XDG_CONFIG_HOME/notmuch
- $HOME/.notmuch-config
If 'config' is an empty string (""), then it will not open any configuration file.
If 'profile' is nil, it will use:
- the environment variable $NOTMUCH_PROFILE if defined
- otherwise 'default' for directories, and ” for paths
If 'profile' is non-nil, append to the directory / file path determined for 'config' and 'path'.
Caller is responsible for closing the database when done.
func (*DB) AddMessage ¶
AddMessage adds a new message to the current database or associate an additional filename with an existing message.
func (*DB) FindMessage ¶
FindMessage finds a message with the given message_id.
func (*DB) FindMessageByFilename ¶
FindMessageByFilename finds a message with the given filename.
func (*DB) GetConfigList ¶
func (db *DB) GetConfigList(prefix string) (*ConfigList, error)
GetConfigList returns the config list, which can be used to iterate over all set options starting with prefix.
func (*DB) LastStatus ¶
LastStatus retrieves last status string for the notmuch database.
func (*DB) NeedsUpgrade ¶
NeedsUpgrade returns true if the database can be upgraded. This will always return false if the database was opened with DBReadOnly.
If this function returns true then the caller may call Upgrade() to upgrade the database.
func (*DB) RemoveMessage ¶
RemoveMessage remove a message filename from the current database. If the message has no more filenames, remove the message.
type DBMode ¶
type DBMode C.notmuch_database_mode_t
DBMode is the mode of the database opening, DBReadOnly or DBReadWrite
type ExcludeMode ¶
type ExcludeMode C.notmuch_exclude_t
ExcludeMode represents the exclude behaviour of a query. One of EXCLUDE_{ALL,FLAG,TRUE,FALSE}.
var ( // Query.Messages and Query.Threads will return all matching // messages/threads regardless of exclude status. // The exclude flag will be set for any excluded message that is // returned by Query.SearchMessages, and the thread counts // for threads returned by Query.Threads will be the // number of non-excluded messages/matches. EXCLUDE_FLAG ExcludeMode = C.NOTMUCH_EXCLUDE_FLAG // Query.Messages and Query.Threads will return all matching // messages/threads regardless of exclude status. // The exclude status is completely ignored. EXCLUDE_FALSE ExcludeMode = C.NOTMUCH_EXCLUDE_FALSE // Query.Messages will omit excluded messages from the results, // and Query.Threads will omit threads that match only in excluded messages. // Query.Threads will include all messages in threads that // match in at least one non-excluded message. EXCLUDE_TRUE ExcludeMode = C.NOTMUCH_EXCLUDE_TRUE // Query.Messages will omit excluded messages from the results, // and Query.Threads will omit threads that match only in excluded messages. // Query.Threads will omit excluded messages from all threads. EXCLUDE_ALL ExcludeMode = C.NOTMUCH_EXCLUDE_ALL )
type Filenames ¶
type Filenames struct {
// contains filtered or unexported fields
}
Filenames is an iterator to get the message's filenames.
type Message ¶
type Message cStruct
Message represents a notmuch message.
func (*Message) AddProperty ¶
AddProperty adds a property to the message.
func (*Message) Filename ¶
Filename returns the absolute path of the email message.
Note: If this message corresponds to multiple files in the mail store, (that is, multiple files contain identical message IDs), this function will arbitrarily return a single one of those filenames. See Filenames for returning the complete list of filenames.
func (*Message) Filenames ¶
Filenames returns *Filenames an iterator to get the message's filenames. Each filename in the iterator is an absolute filename.
func (*Message) MaildirFlagsToTags ¶
MaildirFlagsToTags adds/removes tags according to maildir flags in the message filename(s). This function examines the filenames of 'message' for maildir flags, and adds or removes tags on 'message' as follows when these flags are present:
Flag Action if present ---- ----------------- 'D' Adds the "draft" tag to the message 'F' Adds the "flagged" tag to the message 'P' Adds the "passed" tag to the message 'R' Adds the "replied" tag to the message 'S' Removes the "unread" tag from the message
For each flag that is not present, the opposite action (add/remove) is performed for the corresponding tags.
Flags are identified as trailing components of the filename after a sequence of ":2,".
If there are multiple filenames associated with this message, the flag is considered present if it appears in one or more filenames. (That is, the flags from the multiple filenames are combined with the logical OR operator.)
A client can ensure that notmuch database tags remain synchronized with maildir flags by calling this function after each call to DB.AddMessage. See also Message.TagsToMaildirFlags for synchronizing tag changes back to maildir flags.
func (*Message) Properties ¶
func (m *Message) Properties(key string, exact bool) *MessageProperties
Properties returns the properties for the current message, returning a *MessageProperties which can be used to iterate over all properties using `MessageProperties.Next(MessageProperty)`
func (*Message) RemoveAllProperties ¶
RemoveAllProperties removes all properties with key from the message.
func (*Message) RemoveAllTags ¶
RemoveAllTags removes all tags from the message.
func (*Message) RemoveProperty ¶
RemoveProperty removes a key/value pair from the message properties.
func (*Message) Tags ¶
Tags returns the tags for the current message, returning a *Tags which can be used to iterate over all tags using `Tags.Next(Tag)`
func (*Message) TagsToMaildirFlags ¶
TagsToMaildirFlags renames message filename(s) to encode tags as maildir flags. Specifically, for each filename corresponding to this message:
If the filename is not in a maildir directory, do nothing. (A maildir directory is determined as a directory named "new" or "cur".) Similarly, if the filename has invalid maildir info, (repeated or outof-ASCII-order flag characters after ":2,"), then do nothing.
If the filename is in a maildir directory, rename the file so that its filename ends with the sequence ":2," followed by zero or more of the following single-character flags (in ASCII order):
- flag 'D' if the message has the "draft" tag
- flag 'F' if the message has the "flagged" tag
- flag 'P' if the message has the "passed" tag
- flag 'R' if the message has the "replied" tag
- flag 'S' if the message does not have the "unread" tag
Any existing flags unmentioned in the list above will be preserved in the renaming.
Also, if this filename is in a directory named "new", rename it to be within the neighboring directory named "cur".
A client can ensure that maildir filename flags remain synchronized with notmuch database tags by calling this function after changing tags. See also Message.MaildirFlagsToTags for synchronizing maildir flag changes back to tags.
type MessageProperties ¶
type MessageProperties cStruct
MessageProperties represent a notmuch properties type.
func (*MessageProperties) Close ¶
func (props *MessageProperties) Close() error
func (*MessageProperties) Next ¶
func (props *MessageProperties) Next(p **MessageProperty) bool
Next retrieves the next prop from the result set. Next returns true if a prop was successfully retrieved.
type MessageProperty ¶
MessageProperty represents a property in the database.
func (*MessageProperty) String ¶
func (p *MessageProperty) String() string
type Messages ¶
type Messages cStruct
Messages represents notmuch messages.
func (*Messages) Next ¶
Next retrieves the next message from the result set. Next returns true if a message was successfully retrieved.
func (*Messages) Tags ¶
Tags return a list of tags from all messages.
WARNING: You can no longer iterate over messages after calling this function, because the iterator will point at the end of the list. We do not have a function to reset the iterator yet and the only way how you can iterate over the list again is to recreate the message list.
type Query ¶
type Query cStruct
Query represents a notmuch query.
func (*Query) AddTagExclude ¶
AddTagExclude adds a tag that will be excluded from the query results by default. Note that this function returns ErrIgnored if the provided tag appears in the query
func (*Query) CountMessages ¶
CountMessages returns the number of messages for the current query.
func (*Query) CountThreads ¶
CountThreads returns the number of messages for the current query.
func (*Query) SetExcludeScheme ¶
func (q *Query) SetExcludeScheme(mode ExcludeMode)
SetExcludeScheme is used to set the exclude scheme on a query.
func (*Query) SetSortScheme ¶
SetSortScheme is used to set the sort scheme on a query.
type SortMode ¶
type SortMode C.notmuch_sort_t
SortMode represents the sort behaviour of a query. One of SORT_{OLDEST_FIRST,NEWEST_FIRST,MESSAGE_ID,UNSORTED}
var ( SORT_OLDEST_FIRST SortMode = C.NOTMUCH_SORT_OLDEST_FIRST SORT_NEWEST_FIRST SortMode = C.NOTMUCH_SORT_NEWEST_FIRST SORT_MESSAGE_ID SortMode = C.NOTMUCH_SORT_MESSAGE_ID SORT_UNSORTED SortMode = C.NOTMUCH_SORT_UNSORTED )
type Tag ¶
type Tag struct { Value string // contains filtered or unexported fields }
Tag represents a tag in the database.
type Thread ¶
type Thread cStruct
Thread represents a notmuch thread.
func (*Thread) Authors ¶
Authors returns the list of authors, the first are the authors that matched the query whilst the second return are the rest of the authors. All authors are ordered by date.
func (*Thread) CountMatched ¶
CountMatched returns the total number of messages in the current thread that matched the search.
func (*Thread) Messages ¶
Messages returns an iterator for all messages in the current thread in oldest-first order.
func (*Thread) NewestDate ¶
NewestDate returns the date of the oldest message in the thread.
func (*Thread) OldestDate ¶
OldestDate returns the date of the oldest message in the thread.
func (*Thread) Tags ¶
Tags returns the tags for the current thread, returning a *Tags which can be used to iterate over all tags using `Tags.Next(Tag)`
Note: In the Notmuch database, tags are stored on individual messages, not on threads. So the tags returned here will be all tags of the messages which matched the search and which belong to this thread.
func (*Thread) TopLevelMessages ¶
TopLevelMessages returns an iterator for the top-level messages in the current thread in oldest-first order.