This is an open source Go implementation of the widely known JWZ message threading algorithm originally written by Jamie Zawinsky. See his explanation here
You will find an example of implementing the interface(s) needed to operate this package in the /examples/visualize
directory.
See the godoc for examples in documentation form, and the example in examples\visualize
The package provides the original JWZ algorithm to implementors of the Threadable
interface. It has been tested against
many thousands of emails. The interface provides a few extra features over the original Java version, but these are
additions and enhancements to the interface, not algorithmic changes.
As well as providing the threading capability itself, the package also provides:
- A generic walker, to which you can provide a function to operate upon the nodes in the threaded tree.
- A generic sorter, to which you can provide your own comparison function (a byDate example is provided)
Feel free to report any issues and offer any additions by pull requests.
include "github.com/gatherstars-com/jwz"
~/myproject $ go mod tidy
// Use the enmime package to build all the emails we find under the given directory and store them in a slice
// of structs which implement the Threadable interface
//
//
threadables, err := buildEnvelopes(testData, sizeHint)
if err != nil {
log.Printf("Unable to walk the eml directory: %#v", err)
os.Exit(1)
}
// Now we have a big slice of all the emails, lets use our jwz algorithm to place them in to a thread tree
//
threader := jwz.NewThreader()
sliceRoot, err := threader.ThreadSlice(threadables)
if err != nil {
log.Fatalf("Email threading operation return fatal error: %#v", err)
}
// Sort it Rodney!
//
x := jwz.Sort(sliceRoot, byDate)
An implementation of buildEnvelopes can be found in examples\visualizer\handlers.go