Categorygithub.com/gatherstars-com/jwz
modulepackage
1.4.0
Repository: https://github.com/gatherstars-com/jwz.git
Documentation: pkg.go.dev

# README

Go Report Card PkgGoDev Release Release Maintenance GitHub license GitHub stars

The JWZ Threading algorithm written in Go

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

Functionality

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.

Quick start

  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

# Packages

No description provided by the author

# Functions

Count will traverse the supplied Threadable and store the count of Threadables contained within it in the given counter location.
NewThreader returns an instance of the Threader struct, that is ready to attack your Threadable goland:noinspection GoUnusedExportedFunction.
Sort will create order from the chaos created by threading a set of emails, that even if given as input in a specific order, will be threaded in whatever order the go data structures happen to spit out - which will usually be a different order each time.
Walk allows the caller to execute some function against each node in the tree, while avoiding dealing with the internal structure of the Threadable tree.

# Structs

NoThreadableError indicates that the container was not in a valid state when a utility function was called against it .
Threader arranges a set of messages into a thread hierarchy, by references.

# Interfaces

Threadable is an interface which can be implemented by any go type, which will then allow it to be threaded.
ThreadableRoot is an interface that supports traversing a set of Threadables in some arbitrary way - for instance if they are in some kind of tree structure, the traversal can be hidden behind the interface JI - Although it might be useful to support incoming tree structures, all the Next and Get are doing is keeping a pointer if the input is a []Threadable.

# Type aliases

ThreadLess specifies the signature of a function that compares two Threadables in some way you define, such as comparing dates in the emails they contain.
WalkFunction specifies the signature of a function that can be called by the generic Walk utility function.