emailreplyparser

package module
v0.0.0-...-c8d8e0a Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2015 License: MIT Imports: 4 Imported by: 0

README

Email Reply Parser for Go

Build Status GoDoc

A Go port of GitHub's Email Reply Parser library. The library parses an email body into fragments, marking the fragments as quoted or as part of a signature as appropriate.

The most common use case is to get the text of a reply while ignoring signatures and the quoted original email. It properly parses top, bottom and inline replies.

Installation

To install emailreplyparser run:

go get github.com/recapco/emailreplyparser

Usage

The library can be used to get the reply text from an email body as such:

reply, err := emailreplyparser.ParseReply(emailBody)

The library can also be used to retrieve the signature. For example:

func Signature(text string) (string, error) {
	email, err := emailreplyparser.Read(text)
	if err != nil {
		return "", err
	}

	for _, fragment := range email.Fragments {
		if fragment.Signature {
			return fragment.String(), nil
		}
	}

	return "", nil
}

The library can also help discover quoted segments in an email. For example:

func Quotes(text string) ([]string, error) {
	email, err := emailreplyparser.Read(text)
	if err != nil {
		return nil, err
	}

	var quotes []string
	for _, fragment := range email.Fragments {
		if fragment.Quoted {
			quotes = append(quotes, fragment.String())
		}
	}

	return quotes, nil
}

Building and Testing

Building and testing follow the normal Go conventions of go build and go test.

Contributing

Please feel free to submit pull requests and issues.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseReply

func ParseReply(text string) (string, error)

Parses an email body string and returns the parsed reply string.

Types

type Email

type Email struct {
	Fragments []*Fragment
	// contains filtered or unexported fields
}

Email is a container of text Fragments.

func Read

func Read(text string) (*Email, error)

Parses an email body string and creates a new Email struct.

func (*Email) VisibleText

func (e *Email) VisibleText() string

Returns the combined text of all non-hidden fragments in the email.

type Fragment

type Fragment struct {
	Quoted    bool
	Signature bool
	Hidden    bool
	// contains filtered or unexported fields
}

Fragment is a part of an email which can be marked as quoted, hidden, or as part of a signature.

func (*Fragment) String

func (f *Fragment) String() string

Returns the text content of a Fragment.

Jump to

Keyboard shortcuts

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