A Go port of GitHub's Email Reply Parser library. The library is used to strip away non essential content from email bodies. An example use case is to allow email replies to comments without including signatures or extra noise.
To install emailreplyparser
run the standard installation:
go get github.com/recapco/emailreplyparser
The library can be used to get the essential text of body with following example:
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 quotes in an email. For example:
func Quotes(text string) ([]string, error) {
email, err := emailreplyparser.Read(text)
if err != nil {
return [], err
}
var quotes []string
for _, fragment := range email.Fragments {
if fragment.Quoted {
quotes = append(quotes, fragment.String())
}
}
return quotes, nil
}
Building and testing follow the normal Go conventions of go build
and
go test
.
Please feel to submit Pull Requests and Issues.