| 1 |
//go:build notmuch |
| 2 |
// +build notmuch |
| 3 |
|
| 4 |
package notmuch |
| 5 |
|
| 6 |
/* |
| 7 |
#cgo LDFLAGS: -lnotmuch |
| 8 |
|
| 9 |
#include <notmuch.h> |
| 10 |
|
| 11 |
*/ |
| 12 |
import "C" |
| 13 |
|
| 14 |
type Messages struct { |
| 15 |
message *C.notmuch_message_t |
| 16 |
messages *C.notmuch_messages_t |
| 17 |
} |
| 18 |
|
| 19 |
// Next advances the Messages iterator to the next message. Next returns false if |
| 20 |
// no more messages are available |
| 21 |
func (m *Messages) Next() bool { |
| 22 |
if C.notmuch_messages_valid(m.messages) == 0 { |
| 23 |
return false |
| 24 |
} |
| 25 |
m.message = C.notmuch_messages_get(m.messages) |
| 26 |
C.notmuch_messages_move_to_next(m.messages) |
| 27 |
return true |
| 28 |
} |
| 29 |
|
| 30 |
// Message returns the current message in the iterator |
| 31 |
func (m *Messages) Message() Message { |
| 32 |
return Message{ |
| 33 |
message: m.message, |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
// Close frees memory associated with a Messages iterator. This method is not |
| 38 |
// strictly necessary to call, as the resources will be freed when the Query |
| 39 |
// associated with the Messages object is freed. |
| 40 |
func (m *Messages) Close() { |
| 41 |
C.notmuch_messages_destroy(m.messages) |
| 42 |
} |
| 43 |
|
| 44 |
// Tags returns a slice of all tags in the message list. WARNING: After calling |
| 45 |
// tags, the message list can no longer be iterated; a new list must be created |
| 46 |
// to iterate after calling Tags |
| 47 |
func (m *Messages) Tags() []string { |
| 48 |
cTags := C.notmuch_messages_collect_tags(m.messages) |
| 49 |
defer C.notmuch_tags_destroy(cTags) |
| 50 |
|
| 51 |
tags := []string{} |
| 52 |
for C.notmuch_tags_valid(cTags) > 0 { |
| 53 |
tag := C.notmuch_tags_get(cTags) |
| 54 |
tags = append(tags, C.GoString(tag)) |
| 55 |
C.notmuch_tags_move_to_next(cTags) |
| 56 |
} |
| 57 |
return tags |
| 58 |
} |