Debian Codegraph @

lib/jwz/threadable.go

raw
1 // Author: Jim Idle - [email protected] / [email protected]
2 // SPDX-License-Identifier: Apache-2.0
3
4 package jwz
5
6 import "time"
7
8 // ThreadableRoot is an interface that supports traversing a set of Threadables in some arbitrary
9 // way - for instance if they are in some kind of tree structure, the traversal can be
10 // hidden behind the interface
11 //
12 // JI - Although it might be useful to support incoming tree structures, all the
13 // Next and Get are doing is keeping a pointer if the input is a []Threadable. So we also
14 // have a function that just accepts that as input as well as one that accepts a ThreadableRoot
15 type ThreadableRoot interface {
16 // Next causes an internal iterator over your internal representation of Threadable
17 // elements to either be created and pointing to the next element, or to simply
18 // advance to the next element if there is one. It returns true if another element
19 // is available and false if there are no more beans.
20 //
21 Next() bool
22
23 // Get returns the next available Threadable from your internal storage.
24 // Note that this func should not be called without a prior call to Next and your
25 // implementation can assume that.
26 //
27 Get() Threadable
28 }
29
30 // Threadable is an interface which can be implemented by any go type, which will then
31 // allow it to be threaded.
32 type Threadable interface {
33 // MessageThreadID returns a string identifying this message.
34 // Generally this will be a representation of the contents of the
35 // Message-ID header.
36 //
37 MessageThreadID() string
38
39 // MessageThreadReferences returns the IDs of the set of messages referenced by this one.
40 // This list should be ordered from oldest-ancestor to youngest-ancestor. However, the returned
41 // tree can be sorted however you like.
42 //
43 MessageThreadReferences() []string
44
45 // Subject returns the subject line of the threadable with no manipulation of Re: Re: etc.
46 //
47 Subject() string
48
49 // SimplifiedSubject - provides a threadable subject string.
50 //
51 // When no references are present, subjects will be used to thread together
52 // messages. This method should return a threadable subject: two messages
53 // with the same simplifiedSubject will be considered to belong to the same
54 // thread. This string should not have `Re:' on the front, and may have
55 // been simplified in whatever other ways seem appropriate.
56 //
57 // This is a String of Unicode characters, and should have had any encodings -
58 // such as RFC 2047 charset encodings - removed first.
59 //
60 // If you aren't interested in threading by subject at all, return "".
61 //
62 SimplifiedSubject() string
63
64 // SubjectIsReply indicates whether the original subject was one that appeared to be a reply
65 // I.E. it had a `Re:' or some other indicator that lets you determine that. When threading by subject,
66 // this property is used to tell whether two messages appear to be siblings,
67 // or in a parent/child relationship.
68 //
69 SubjectIsReply() bool
70
71 // SetNext is called after the proper thread order has been computed,
72 // and will be called on each Threadable in the chain, to set up the proper tree
73 // structure.
74 //
75 SetNext(next Threadable)
76
77 // SetChild is called after the proper thread order has been computed,
78 // and will be called on each Threadable in the chain, to set up the proper tree
79 // structure.
80 //
81 SetChild(kid Threadable)
82
83 // SetParent is not called by the jwz algorithm and if you do not need the pointer in your
84 // implementation, then you can implement it as a null function. It can be useful when using
85 // the Walk utility method though
86 //
87 SetParent(parent Threadable)
88
89 // GetNext just makes it easier to navigate through the threads after they are built,
90 // but you don't have to use this if you have a better way
91 //
92 GetNext() Threadable
93
94 // GetChild just makes it easier to navigate through the threads after they are built,
95 // but you don't have to use this if you have a better way
96 //
97 GetChild() Threadable
98
99 // GetParent just makes it easier to navigate through the threads after they are built,
100 // but you don't have to use this if you have no need for it
101 //
102 GetParent() Threadable
103
104 // GetDate is not used by the threading algorithm, but implementing this function may make
105 // your own tree walking routines and sorting methods easier to implement.
106 // It should return the Date associated with the Threadable
107 //
108 GetDate() time.Time
109
110 // MakeDummy creates a dummy parent object.
111 //
112 // With some set of messages, the only way to achieve proper threading is
113 // to introduce an element into the tree which represents messages which are
114 // not present in the set: for example, when two messages share a common
115 // ancestor, but that ancestor is not in the set. This method is used to
116 // make a placeholder for those sorts of ancestors. It should return
117 // a Threadable type. The SetNext() and SetChild() funcs
118 // will be used on this placeholder, as either the object or the argument,
119 // just as for other elements of the tree.
120 //
121 MakeDummy(forID string) Threadable
122
123 // IsDummy should return true of dummy messages, false otherwise.
124 // It is legal to pass dummy messages within your input;
125 // the isDummy() method is the mechanism by which they are noted and ignored.
126 //
127 IsDummy() bool
128 }