1 // Wrapper around the notmuch library
14 // Status codes used for the return values of most functions
15 type Status C.notmuch_status_t
17 STATUS_SUCCESS Status = 0
19 STATUS_READ_ONLY_DATABASE
20 STATUS_XAPIAN_EXCEPTION
23 STATUS_DUPLICATE_MESSAGE_ID
26 STATUS_UNBALANCED_FREEZE_THAW
31 func (self Status) String() string {
35 p = C.notmuch_status_to_string(C.notmuch_status_t(self))
43 /* Various opaque data types. For each notmuch_<foo>_t see the various
44 * notmuch_<foo> functions below. */
46 type Database struct {
47 db *C.notmuch_database_t
51 query *C.notmuch_query_t
55 threads *C.notmuch_threads_t
59 thread *C.notmuch_thread_t
62 type Messages struct {
63 messages *C.notmuch_messages_t
67 message *C.notmuch_message_t
71 tags *C.notmuch_tags_t
74 type Directory struct {
75 dir *C.notmuch_directory_t
78 type Filenames struct {
79 fnames *C.notmuch_filenames_t
82 type DatabaseMode C.notmuch_database_mode_t
84 DATABASE_MODE_READ_ONLY DatabaseMode = 0
85 DATABASE_MODE_READ_WRITE
88 // Create a new, empty notmuch database located at 'path'
89 func NewDatabase(path string) (*Database, Status) {
91 var c_path *C.char = C.CString(path)
92 defer C.free(unsafe.Pointer(c_path))
95 return nil, STATUS_OUT_OF_MEMORY
98 self := &Database{db:nil}
99 st := Status(C.notmuch_database_create(c_path, &self.db))
100 if st != STATUS_SUCCESS {
106 /* Open an existing notmuch database located at 'path'.
108 * The database should have been created at some time in the past,
109 * (not necessarily by this process), by calling
110 * notmuch_database_create with 'path'. By default the database should be
111 * opened for reading only. In order to write to the database you need to
112 * pass the NOTMUCH_DATABASE_MODE_READ_WRITE mode.
114 * An existing notmuch database can be identified by the presence of a
115 * directory named ".notmuch" below 'path'.
117 * The caller should call notmuch_database_destroy when finished with
120 * In case of any failure, this function returns NULL, (after printing
121 * an error message on stderr).
123 func OpenDatabase(path string, mode DatabaseMode) (*Database, Status) {
125 var c_path *C.char = C.CString(path)
126 defer C.free(unsafe.Pointer(c_path))
129 return nil, STATUS_OUT_OF_MEMORY
132 self := &Database{db:nil}
133 st := Status(C.notmuch_database_open(c_path, C.notmuch_database_mode_t(mode), &self.db))
134 if st != STATUS_SUCCESS {
140 /* Close the given notmuch database, freeing all associated
141 * resources. See notmuch_database_open. */
142 func (self *Database) Close() {
143 C.notmuch_database_destroy(self.db)
146 /* Return the database path of the given database.
148 func (self *Database) GetPath() string {
150 /* The return value is a string owned by notmuch so should not be
151 * modified nor freed by the caller. */
152 var p *C.char = C.notmuch_database_get_path(self.db)
160 /* Return the database format version of the given database. */
161 func (self *Database) GetVersion() uint {
162 return uint(C.notmuch_database_get_version(self.db))
165 /* Does this database need to be upgraded before writing to it?
167 * If this function returns TRUE then no functions that modify the
168 * database (notmuch_database_add_message, notmuch_message_add_tag,
169 * notmuch_directory_set_mtime, etc.) will work unless the function
170 * notmuch_database_upgrade is called successfully first. */
171 func (self *Database) NeedsUpgrade() bool {
172 do_upgrade := C.notmuch_database_needs_upgrade(self.db)
179 // TODO: notmuch_database_upgrade
182 /* Retrieve a directory object from the database for 'path'.
184 * Here, 'path' should be a path relative to the path of 'database'
185 * (see notmuch_database_get_path), or else should be an absolute path
186 * with initial components that match the path of 'database'.
188 * Can return NULL if a Xapian exception occurs.
190 func (self *Database) GetDirectory(path string) *Directory {
191 var c_path *C.char = C.CString(path)
192 defer C.free(unsafe.Pointer(c_path))
198 c_dir := C.notmuch_database_get_directory(self.db, c_path)
202 return &Directory{dir:c_dir}
205 /* Add a new message to the given notmuch database.
207 * Here,'filename' should be a path relative to the path of
208 * 'database' (see notmuch_database_get_path), or else should be an
209 * absolute filename with initial components that match the path of
212 * The file should be a single mail message (not a multi-message mbox)
213 * that is expected to remain at its current location, (since the
214 * notmuch database will reference the filename, and will not copy the
215 * entire contents of the file.
217 * If 'message' is not NULL, then, on successful return '*message'
218 * will be initialized to a message object that can be used for things
219 * such as adding tags to the just-added message. The user should call
220 * notmuch_message_destroy when done with the message. On any failure
221 * '*message' will be set to NULL.
225 * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
227 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,
230 * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message
231 * ID as another message already in the database. The new
232 * filename was successfully added to the message in the database
233 * (if not already present).
235 * NOTMUCH_STATUS_FILE_ERROR: an error occurred trying to open the
236 * file, (such as permission denied, or file not found,
237 * etc.). Nothing added to the database.
239 * NOTMUCH_STATUS_FILE_NOT_EMAIL: the contents of filename don't look
240 * like an email message. Nothing added to the database.
242 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
243 * mode so no message can be added.
246 (self *Database) AddMessage(fname string) (*Message, Status) {
247 var c_fname *C.char = C.CString(fname)
248 defer C.free(unsafe.Pointer(c_fname))
251 return nil, STATUS_OUT_OF_MEMORY
254 var c_msg *C.notmuch_message_t = new(C.notmuch_message_t)
255 st := Status(C.notmuch_database_add_message(self.db, c_fname, &c_msg))
257 return &Message{message:c_msg}, st
260 /* Remove a message from the given notmuch database.
262 * Note that only this particular filename association is removed from
263 * the database. If the same message (as determined by the message ID)
264 * is still available via other filenames, then the message will
265 * persist in the database for those filenames. When the last filename
266 * is removed for a particular message, the database content for that
267 * message will be entirely removed.
271 * NOTMUCH_STATUS_SUCCESS: The last filename was removed and the
272 * message was removed from the database.
274 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,
275 * message not removed.
277 * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: This filename was removed but
278 * the message persists in the database with at least one other
281 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
282 * mode so no message can be removed.
284 func (self *Database) RemoveMessage(fname string) Status {
286 var c_fname *C.char = C.CString(fname)
287 defer C.free(unsafe.Pointer(c_fname))
290 return STATUS_OUT_OF_MEMORY
293 st := C.notmuch_database_remove_message(self.db, c_fname)
297 /* Find a message with the given message_id.
299 * If the database contains a message with the given message_id, then
300 * a new notmuch_message_t object is returned. The caller should call
301 * notmuch_message_destroy when done with the message.
303 * This function returns NULL in the following situations:
305 * * No message is found with the given message_id
306 * * An out-of-memory situation occurs
307 * * A Xapian exception occurs
309 func (self *Database) FindMessage(message_id string) (*Message, Status) {
311 var c_msg_id *C.char = C.CString(message_id)
312 defer C.free(unsafe.Pointer(c_msg_id))
315 return nil, STATUS_OUT_OF_MEMORY
318 msg := &Message{message:nil}
319 st := Status(C.notmuch_database_find_message(self.db, c_msg_id, &msg.message))
320 if st != STATUS_SUCCESS {
326 /* Return a list of all tags found in the database.
328 * This function creates a list of all tags found in the database. The
329 * resulting list contains all tags from all messages found in the database.
331 * On error this function returns NULL.
333 func (self *Database) GetAllTags() *Tags {
334 tags := C.notmuch_database_get_all_tags(self.db)
338 return &Tags{tags:tags}
341 /* Create a new query for 'database'.
343 * Here, 'database' should be an open database, (see
344 * notmuch_database_open and notmuch_database_create).
346 * For the query string, we'll document the syntax here more
347 * completely in the future, but it's likely to be a specialized
348 * version of the general Xapian query syntax:
350 * http://xapian.org/docs/queryparser.html
352 * As a special case, passing either a length-zero string, (that is ""),
353 * or a string consisting of a single asterisk (that is "*"), will
354 * result in a query that returns all messages in the database.
356 * See notmuch_query_set_sort for controlling the order of results.
357 * See notmuch_query_search_messages and notmuch_query_search_threads
358 * to actually execute the query.
360 * User should call notmuch_query_destroy when finished with this
363 * Will return NULL if insufficient memory is available.
365 func (self *Database) CreateQuery(query string) *Query {
367 var c_query *C.char = C.CString(query)
368 defer C.free(unsafe.Pointer(c_query))
374 q := C.notmuch_query_create(self.db, c_query)
378 return &Query{query:q}
381 /* Sort values for notmuch_query_set_sort */
382 type Sort C.notmuch_sort_t
384 SORT_OLDEST_FIRST Sort = 0
390 /* Return the query_string of this query. See notmuch_query_create. */
391 func (self *Query) String() string {
392 // FIXME: do we own 'q' or not ?
393 q := C.notmuch_query_get_query_string(self.query)
394 //defer C.free(unsafe.Pointer(q))
404 /* Specify the sorting desired for this query. */
405 func (self *Query) SetSort(sort Sort) {
406 C.notmuch_query_set_sort(self.query, C.notmuch_sort_t(sort))
409 /* Return the sort specified for this query. See notmuch_query_set_sort. */
410 func (self *Query) GetSort() Sort {
411 return Sort(C.notmuch_query_get_sort(self.query))
414 /* Execute a query for threads, returning a notmuch_threads_t object
415 * which can be used to iterate over the results. The returned threads
416 * object is owned by the query and as such, will only be valid until
417 * notmuch_query_destroy.
419 * Typical usage might be:
421 * notmuch_query_t *query;
422 * notmuch_threads_t *threads;
423 * notmuch_thread_t *thread;
425 * query = notmuch_query_create (database, query_string);
427 * for (threads = notmuch_query_search_threads (query);
428 * notmuch_threads_valid (threads);
429 * notmuch_threads_move_to_next (threads))
431 * thread = notmuch_threads_get (threads);
433 * notmuch_thread_destroy (thread);
436 * notmuch_query_destroy (query);
438 * Note: If you are finished with a thread before its containing
439 * query, you can call notmuch_thread_destroy to clean up some memory
440 * sooner (as in the above example). Otherwise, if your thread objects
441 * are long-lived, then you don't need to call notmuch_thread_destroy
442 * and all the memory will still be reclaimed when the query is
445 * Note that there's no explicit destructor needed for the
446 * notmuch_threads_t object. (For consistency, we do provide a
447 * notmuch_threads_destroy function, but there's no good reason
448 * to call it if the query is about to be destroyed).
450 * If a Xapian exception occurs this function will return NULL.
452 func (self *Query) SearchThreads() *Threads {
453 threads := C.notmuch_query_search_threads(self.query)
457 return &Threads{threads:threads}
460 /* Execute a query for messages, returning a notmuch_messages_t object
461 * which can be used to iterate over the results. The returned
462 * messages object is owned by the query and as such, will only be
463 * valid until notmuch_query_destroy.
465 * Typical usage might be:
467 * notmuch_query_t *query;
468 * notmuch_messages_t *messages;
469 * notmuch_message_t *message;
471 * query = notmuch_query_create (database, query_string);
473 * for (messages = notmuch_query_search_messages (query);
474 * notmuch_messages_valid (messages);
475 * notmuch_messages_move_to_next (messages))
477 * message = notmuch_messages_get (messages);
479 * notmuch_message_destroy (message);
482 * notmuch_query_destroy (query);
484 * Note: If you are finished with a message before its containing
485 * query, you can call notmuch_message_destroy to clean up some memory
486 * sooner (as in the above example). Otherwise, if your message
487 * objects are long-lived, then you don't need to call
488 * notmuch_message_destroy and all the memory will still be reclaimed
489 * when the query is destroyed.
491 * Note that there's no explicit destructor needed for the
492 * notmuch_messages_t object. (For consistency, we do provide a
493 * notmuch_messages_destroy function, but there's no good
494 * reason to call it if the query is about to be destroyed).
496 * If a Xapian exception occurs this function will return NULL.
498 func (self *Query) SearchMessages() *Messages {
499 msgs := C.notmuch_query_search_messages(self.query)
503 return &Messages{messages:msgs}
506 /* Destroy a notmuch_query_t along with any associated resources.
508 * This will in turn destroy any notmuch_threads_t and
509 * notmuch_messages_t objects generated by this query, (and in
510 * turn any notmuch_thread_t and notmuch_message_t objects generated
511 * from those results, etc.), if such objects haven't already been
514 func (self *Query) Destroy() {
515 if self.query != nil {
516 C.notmuch_query_destroy(self.query)
520 /* Return an estimate of the number of messages matching a search
522 * This function performs a search and returns Xapian's best
523 * guess as to number of matching messages.
525 * If a Xapian exception occurs, this function may return 0 (after
526 * printing a message).
528 func (self *Query) CountMessages() uint {
529 return uint(C.notmuch_query_count_messages(self.query))
532 // TODO: wrap threads and thread
534 /* Is the given 'threads' iterator pointing at a valid thread.
536 * When this function returns TRUE, notmuch_threads_get will return a
537 * valid object. Whereas when this function returns FALSE,
538 * notmuch_threads_get will return NULL.
540 * See the documentation of notmuch_query_search_threads for example
541 * code showing how to iterate over a notmuch_threads_t object.
543 func (self *Threads) Valid() bool {
544 if self.threads == nil {
547 valid := C.notmuch_threads_valid(self.threads)
554 /* Destroy a notmuch_threads_t object.
556 * It's not strictly necessary to call this function. All memory from
557 * the notmuch_threads_t object will be reclaimed when the
558 * containg query object is destroyed.
560 func (self *Threads) Destroy() {
561 if self.threads != nil {
562 C.notmuch_threads_destroy(self.threads)
566 /* Is the given 'messages' iterator pointing at a valid message.
568 * When this function returns TRUE, notmuch_messages_get will return a
569 * valid object. Whereas when this function returns FALSE,
570 * notmuch_messages_get will return NULL.
572 * See the documentation of notmuch_query_search_messages for example
573 * code showing how to iterate over a notmuch_messages_t object.
575 func (self *Messages) Valid() bool {
576 if self.messages == nil {
579 valid := C.notmuch_messages_valid(self.messages)
586 /* Get the current message from 'messages' as a notmuch_message_t.
588 * Note: The returned message belongs to 'messages' and has a lifetime
589 * identical to it (and the query to which it belongs).
591 * See the documentation of notmuch_query_search_messages for example
592 * code showing how to iterate over a notmuch_messages_t object.
594 * If an out-of-memory situation occurs, this function will return
597 func (self *Messages) Get() *Message {
598 if self.messages == nil {
601 msg := C.notmuch_messages_get(self.messages)
605 return &Message{message:msg}
608 /* Move the 'messages' iterator to the next message.
610 * If 'messages' is already pointing at the last message then the
611 * iterator will be moved to a point just beyond that last message,
612 * (where notmuch_messages_valid will return FALSE and
613 * notmuch_messages_get will return NULL).
615 * See the documentation of notmuch_query_search_messages for example
616 * code showing how to iterate over a notmuch_messages_t object.
618 func (self *Messages) MoveToNext() {
619 if self.messages == nil {
622 C.notmuch_messages_move_to_next(self.messages)
625 /* Destroy a notmuch_messages_t object.
627 * It's not strictly necessary to call this function. All memory from
628 * the notmuch_messages_t object will be reclaimed when the containing
629 * query object is destroyed.
631 func (self *Messages) Destroy() {
632 if self.messages != nil {
633 C.notmuch_messages_destroy(self.messages)
637 /* Return a list of tags from all messages.
639 * The resulting list is guaranteed not to contain duplicated tags.
641 * WARNING: You can no longer iterate over messages after calling this
642 * function, because the iterator will point at the end of the list.
643 * We do not have a function to reset the iterator yet and the only
644 * way how you can iterate over the list again is to recreate the
647 * The function returns NULL on error.
649 func (self *Messages) CollectTags() *Tags {
650 if self.messages == nil {
653 tags := C.notmuch_messages_collect_tags(self.messages)
657 return &Tags{tags:tags}
660 /* Get the message ID of 'message'.
662 * The returned string belongs to 'message' and as such, should not be
663 * modified by the caller and will only be valid for as long as the
664 * message is valid, (which is until the query from which it derived
667 * This function will not return NULL since Notmuch ensures that every
668 * message has a unique message ID, (Notmuch will generate an ID for a
669 * message if the original file does not contain one).
671 func (self *Message) GetMessageId() string {
673 if self.message == nil {
676 id := C.notmuch_message_get_message_id(self.message)
678 // defer C.free(unsafe.Pointer(id))
682 return C.GoString(id)
685 /* Get the thread ID of 'message'.
687 * The returned string belongs to 'message' and as such, should not be
688 * modified by the caller and will only be valid for as long as the
689 * message is valid, (for example, until the user calls
690 * notmuch_message_destroy on 'message' or until a query from which it
691 * derived is destroyed).
693 * This function will not return NULL since Notmuch ensures that every
694 * message belongs to a single thread.
696 func (self *Message) GetThreadId() string {
698 if self.message == nil {
701 id := C.notmuch_message_get_thread_id(self.message)
703 // defer C.free(unsafe.Pointer(id))
709 return C.GoString(id)
712 /* Get a notmuch_messages_t iterator for all of the replies to
715 * Note: This call only makes sense if 'message' was ultimately
716 * obtained from a notmuch_thread_t object, (such as by coming
717 * directly from the result of calling notmuch_thread_get_
718 * toplevel_messages or by any number of subsequent
719 * calls to notmuch_message_get_replies).
721 * If 'message' was obtained through some non-thread means, (such as
722 * by a call to notmuch_query_search_messages), then this function
725 * If there are no replies to 'message', this function will return
726 * NULL. (Note that notmuch_messages_valid will accept that NULL
727 * value as legitimate, and simply return FALSE for it.)
729 func (self *Message) GetReplies() *Messages {
730 if self.message == nil {
733 msgs := C.notmuch_message_get_replies(self.message)
737 return &Messages{messages:msgs}
740 /* Get a filename for the email corresponding to 'message'.
742 * The returned filename is an absolute filename, (the initial
743 * component will match notmuch_database_get_path() ).
745 * The returned string belongs to the message so should not be
746 * modified or freed by the caller (nor should it be referenced after
747 * the message is destroyed).
749 * Note: If this message corresponds to multiple files in the mail
750 * store, (that is, multiple files contain identical message IDs),
751 * this function will arbitrarily return a single one of those
754 func (self *Message) GetFileName() string {
755 if self.message == nil {
758 fname := C.notmuch_message_get_filename(self.message)
760 // defer C.free(unsafe.Pointer(fname))
766 return C.GoString(fname)
769 type Flag C.notmuch_message_flag_t
771 MESSAGE_FLAG_MATCH Flag = 0
774 /* Get a value of a flag for the email corresponding to 'message'. */
775 func (self *Message) GetFlag(flag Flag) bool {
776 if self.message == nil {
779 v := C.notmuch_message_get_flag(self.message, C.notmuch_message_flag_t(flag))
786 /* Set a value of a flag for the email corresponding to 'message'. */
787 func (self *Message) SetFlag(flag Flag, value bool) {
788 if self.message == nil {
791 var v C.notmuch_bool_t = 0
795 C.notmuch_message_set_flag(self.message, C.notmuch_message_flag_t(flag), v)
798 // TODO: wrap notmuch_message_get_date
800 /* Get the value of the specified header from 'message'.
802 * The value will be read from the actual message file, not from the
803 * notmuch database. The header name is case insensitive.
805 * The returned string belongs to the message so should not be
806 * modified or freed by the caller (nor should it be referenced after
807 * the message is destroyed).
809 * Returns an empty string ("") if the message does not contain a
810 * header line matching 'header'. Returns NULL if any error occurs.
812 func (self *Message) GetHeader(header string) string {
813 if self.message == nil {
817 var c_header *C.char = C.CString(header)
818 defer C.free(unsafe.Pointer(c_header))
820 /* we dont own value */
821 value := C.notmuch_message_get_header(self.message, c_header)
826 return C.GoString(value)
829 /* Get the tags for 'message', returning a notmuch_tags_t object which
830 * can be used to iterate over all tags.
832 * The tags object is owned by the message and as such, will only be
833 * valid for as long as the message is valid, (which is until the
834 * query from which it derived is destroyed).
836 * Typical usage might be:
838 * notmuch_message_t *message;
839 * notmuch_tags_t *tags;
842 * message = notmuch_database_find_message (database, message_id);
844 * for (tags = notmuch_message_get_tags (message);
845 * notmuch_tags_valid (tags);
846 * notmuch_result_move_to_next (tags))
848 * tag = notmuch_tags_get (tags);
852 * notmuch_message_destroy (message);
854 * Note that there's no explicit destructor needed for the
855 * notmuch_tags_t object. (For consistency, we do provide a
856 * notmuch_tags_destroy function, but there's no good reason to call
857 * it if the message is about to be destroyed).
859 func (self *Message) GetTags() *Tags {
860 if self.message == nil {
863 tags := C.notmuch_message_get_tags(self.message)
867 return &Tags{tags:tags}
870 /* The longest possible tag value. */
873 /* Add a tag to the given message.
877 * NOTMUCH_STATUS_SUCCESS: Tag successfully added to message
879 * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL
881 * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long
882 * (exceeds NOTMUCH_TAG_MAX)
884 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
885 * mode so message cannot be modified.
887 func (self *Message) AddTag(tag string) Status {
888 if self.message == nil {
889 return STATUS_NULL_POINTER
891 c_tag := C.CString(tag)
892 defer C.free(unsafe.Pointer(c_tag))
894 return Status(C.notmuch_message_add_tag(self.message, c_tag))
897 /* Remove a tag from the given message.
901 * NOTMUCH_STATUS_SUCCESS: Tag successfully removed from message
903 * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL
905 * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long
906 * (exceeds NOTMUCH_TAG_MAX)
908 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
909 * mode so message cannot be modified.
911 func (self *Message) RemoveTag(tag string) Status {
912 if self.message == nil {
913 return STATUS_NULL_POINTER
915 c_tag := C.CString(tag)
916 defer C.free(unsafe.Pointer(c_tag))
918 return Status(C.notmuch_message_remove_tag(self.message, c_tag))
921 /* Remove all tags from the given message.
923 * See notmuch_message_freeze for an example showing how to safely
924 * replace tag values.
926 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
927 * mode so message cannot be modified.
929 func (self *Message) RemoveAllTags() Status {
930 if self.message == nil {
931 return STATUS_NULL_POINTER
933 return Status(C.notmuch_message_remove_all_tags(self.message))
936 /* Freeze the current state of 'message' within the database.
938 * This means that changes to the message state, (via
939 * notmuch_message_add_tag, notmuch_message_remove_tag, and
940 * notmuch_message_remove_all_tags), will not be committed to the
941 * database until the message is thawed with notmuch_message_thaw.
943 * Multiple calls to freeze/thaw are valid and these calls will
944 * "stack". That is there must be as many calls to thaw as to freeze
945 * before a message is actually thawed.
947 * The ability to do freeze/thaw allows for safe transactions to
948 * change tag values. For example, explicitly setting a message to
949 * have a given set of tags might look like this:
951 * notmuch_message_freeze (message);
953 * notmuch_message_remove_all_tags (message);
955 * for (i = 0; i < NUM_TAGS; i++)
956 * notmuch_message_add_tag (message, tags[i]);
958 * notmuch_message_thaw (message);
960 * With freeze/thaw used like this, the message in the database is
961 * guaranteed to have either the full set of original tag values, or
962 * the full set of new tag values, but nothing in between.
964 * Imagine the example above without freeze/thaw and the operation
965 * somehow getting interrupted. This could result in the message being
966 * left with no tags if the interruption happened after
967 * notmuch_message_remove_all_tags but before notmuch_message_add_tag.
971 * NOTMUCH_STATUS_SUCCESS: Message successfully frozen.
973 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
974 * mode so message cannot be modified.
976 func (self *Message) Freeze() Status {
977 if self.message == nil {
978 return STATUS_NULL_POINTER
980 return Status(C.notmuch_message_freeze(self.message))
983 /* Thaw the current 'message', synchronizing any changes that may have
984 * occurred while 'message' was frozen into the notmuch database.
986 * See notmuch_message_freeze for an example of how to use this
987 * function to safely provide tag changes.
989 * Multiple calls to freeze/thaw are valid and these calls with
990 * "stack". That is there must be as many calls to thaw as to freeze
991 * before a message is actually thawed.
995 * NOTMUCH_STATUS_SUCCESS: Message successfully thawed, (or at least
996 * its frozen count has successfully been reduced by 1).
998 * NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: An attempt was made to thaw
999 * an unfrozen message. That is, there have been an unbalanced
1000 * number of calls to notmuch_message_freeze and
1001 * notmuch_message_thaw.
1003 func (self *Message) Thaw() Status {
1004 if self.message == nil {
1005 return STATUS_NULL_POINTER
1008 return Status(C.notmuch_message_thaw(self.message))
1011 /* Destroy a notmuch_message_t object.
1013 * It can be useful to call this function in the case of a single
1014 * query object with many messages in the result, (such as iterating
1015 * over the entire database). Otherwise, it's fine to never call this
1016 * function and there will still be no memory leaks. (The memory from
1017 * the messages get reclaimed when the containing query is destroyed.)
1019 func (self *Message) Destroy() {
1020 if self.message == nil {
1023 C.notmuch_message_destroy(self.message)
1026 /* Is the given 'tags' iterator pointing at a valid tag.
1028 * When this function returns TRUE, notmuch_tags_get will return a
1029 * valid string. Whereas when this function returns FALSE,
1030 * notmuch_tags_get will return NULL.
1032 * See the documentation of notmuch_message_get_tags for example code
1033 * showing how to iterate over a notmuch_tags_t object.
1035 func (self *Tags) Valid() bool {
1036 if self.tags == nil {
1039 v := C.notmuch_tags_valid(self.tags)
1046 /* Get the current tag from 'tags' as a string.
1048 * Note: The returned string belongs to 'tags' and has a lifetime
1049 * identical to it (and the query to which it ultimately belongs).
1051 * See the documentation of notmuch_message_get_tags for example code
1052 * showing how to iterate over a notmuch_tags_t object.
1054 func (self *Tags) Get() string {
1055 if self.tags == nil {
1058 s := C.notmuch_tags_get(self.tags)
1061 return C.GoString(s)
1063 func (self *Tags) String() string {
1067 /* Move the 'tags' iterator to the next tag.
1069 * If 'tags' is already pointing at the last tag then the iterator
1070 * will be moved to a point just beyond that last tag, (where
1071 * notmuch_tags_valid will return FALSE and notmuch_tags_get will
1074 * See the documentation of notmuch_message_get_tags for example code
1075 * showing how to iterate over a notmuch_tags_t object.
1077 func (self *Tags) MoveToNext() {
1078 if self.tags == nil {
1081 C.notmuch_tags_move_to_next(self.tags)
1084 /* Destroy a notmuch_tags_t object.
1086 * It's not strictly necessary to call this function. All memory from
1087 * the notmuch_tags_t object will be reclaimed when the containing
1088 * message or query objects are destroyed.
1090 func (self *Tags) Destroy() {
1091 if self.tags == nil {
1094 C.notmuch_tags_destroy(self.tags)
1097 // TODO: wrap notmuch_directory_<fct>
1099 /* Destroy a notmuch_directory_t object. */
1100 func (self *Directory) Destroy() {
1101 if self.dir == nil {
1104 C.notmuch_directory_destroy(self.dir)
1107 // TODO: wrap notmuch_filenames_<fct>
1109 /* Destroy a notmuch_filenames_t object.
1111 * It's not strictly necessary to call this function. All memory from
1112 * the notmuch_filenames_t object will be reclaimed when the
1113 * containing directory object is destroyed.
1115 * It is acceptable to pass NULL for 'filenames', in which case this
1116 * function will do nothing.
1118 func (self *Filenames) Destroy() {
1119 if self.fnames == nil {
1122 C.notmuch_filenames_destroy(self.fnames)