| 1 |
//go:build notmuch |
| 2 |
// +build notmuch |
| 3 |
|
| 4 |
package notmuch |
| 5 |
|
| 6 |
/* |
| 7 |
#cgo LDFLAGS: -lnotmuch |
| 8 |
|
| 9 |
#include <stdlib.h> |
| 10 |
#include <notmuch.h> |
| 11 |
|
| 12 |
*/ |
| 13 |
import "C" |
| 14 |
import "time" |
| 15 |
|
| 16 |
type Thread struct { |
| 17 |
thread *C.notmuch_thread_t |
| 18 |
} |
| 19 |
|
| 20 |
// ID returns the thread ID |
| 21 |
func (t *Thread) ID() string { |
| 22 |
cID := C.notmuch_thread_get_thread_id(t.thread) |
| 23 |
return C.GoString(cID) |
| 24 |
} |
| 25 |
|
| 26 |
// TotalMessages returns the total number of messages in the thread |
| 27 |
func (t *Thread) TotalMessages() int { |
| 28 |
return int(C.notmuch_thread_get_total_messages(t.thread)) |
| 29 |
} |
| 30 |
|
| 31 |
// TotalMessages returns the total number of files in the thread |
| 32 |
func (t *Thread) TotalFiles() int { |
| 33 |
return int(C.notmuch_thread_get_total_files(t.thread)) |
| 34 |
} |
| 35 |
|
| 36 |
// TopLevelMessages returns an iterator over the top level messages in the |
| 37 |
// thread. Messages are sorted oldest-first |
| 38 |
func (t *Thread) TopLevelMessages() Messages { |
| 39 |
cMessages := C.notmuch_thread_get_toplevel_messages(t.thread) |
| 40 |
return Messages{ |
| 41 |
messages: cMessages, |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
// Messages returns an iterator over the messages in the thread. Messages are |
| 46 |
// sorted oldest-first |
| 47 |
func (t *Thread) Messages() Messages { |
| 48 |
cMessages := C.notmuch_thread_get_messages(t.thread) |
| 49 |
return Messages{ |
| 50 |
messages: cMessages, |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
// Matches returns the number of messages in the thread that matched the query |
| 55 |
func (t *Thread) Matches() int { |
| 56 |
return int(C.notmuch_thread_get_matched_messages(t.thread)) |
| 57 |
} |
| 58 |
|
| 59 |
// Returns a string of authors of the thread |
| 60 |
func (t *Thread) Authors() string { |
| 61 |
cAuthors := C.notmuch_thread_get_authors(t.thread) |
| 62 |
return C.GoString(cAuthors) |
| 63 |
} |
| 64 |
|
| 65 |
// Returns the subject of the thread |
| 66 |
func (t *Thread) Subject() string { |
| 67 |
cSubject := C.notmuch_thread_get_subject(t.thread) |
| 68 |
return C.GoString(cSubject) |
| 69 |
} |
| 70 |
|
| 71 |
// Returns the sent-date of the oldest message in the thread |
| 72 |
func (t *Thread) OldestDate() time.Time { |
| 73 |
cTime := C.notmuch_thread_get_oldest_date(t.thread) |
| 74 |
return time.Unix(int64(cTime), 0) |
| 75 |
} |
| 76 |
|
| 77 |
// Returns the sent-date of the newest message in the thread |
| 78 |
func (t *Thread) NewestDate() time.Time { |
| 79 |
cTime := C.notmuch_thread_get_newest_date(t.thread) |
| 80 |
return time.Unix(int64(cTime), 0) |
| 81 |
} |
| 82 |
|
| 83 |
// Tags returns a slice of all tags in the thread |
| 84 |
func (t *Thread) Tags() []string { |
| 85 |
cTags := C.notmuch_thread_get_tags(t.thread) |
| 86 |
defer C.notmuch_tags_destroy(cTags) |
| 87 |
|
| 88 |
tags := []string{} |
| 89 |
for C.notmuch_tags_valid(cTags) > 0 { |
| 90 |
tag := C.notmuch_tags_get(cTags) |
| 91 |
tags = append(tags, C.GoString(tag)) |
| 92 |
C.notmuch_tags_move_to_next(cTags) |
| 93 |
} |
| 94 |
return tags |
| 95 |
} |
| 96 |
|
| 97 |
func (t *Thread) Close() { |
| 98 |
C.notmuch_thread_destroy(t.thread) |
| 99 |
} |