emailthreads

package module
v0.0.0-...-75c4301 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 5 Imported by: 2

README

go-emailthreads

godocs.io

A Go library to parse email threads. Give it a list of emails that are part of the same thread and it'll organize the replies in a tree structure.

This is a port and enhancement of python-emailthreads.

Usage

See the documentation.

To quickly find out how the library parses an email thread, you can use:

go run ./cmd/emailthreads-parse <thread.mbox

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	// Replies to this block.
	Children []*Block

	// The message this block comes from.
	Source *Message
	// The region of this block's text in the source message.
	SourceStart, SourceEnd int

	// If this block is a reply to a particular chunk of the parent block,
	// ParentStart and ParentEnd indicate the region in the parent's body.
	// Otherwise, they are set to -1. ParentStart is an inclusive offset and
	// ParentEnd is an exclusive offset.
	ParentStart, ParentEnd int
}

Block is a block of text in the thread.

Blocks are parts of a message's body that aren't quotes of the parent message. A block can be a reply to a parent block, in which case the ParentStart and ParentEnd fields indicate which part of the parent message is replied to. A block can have replies, each of which will be represented by a block in the Children field.

func Parse

func Parse(msgs []Message) ([]*Block, error)

Parse builds a tree of blocks from a thread.

On success, it will always return a non-empty slice. The first element is the root block (whose body matches exactly the root message's). Subsequent blocks are chunks of child messages which aren't replies to another specific block.

func (*Block) Body

func (block *Block) Body() string

Body returns the block's plain-text content.

type Message

type Message struct {
	Header mail.Header
	Body   string
}

Message is a mail message used as input data for this package.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL