Class: EmailReplyParser

Inherits:
Object
  • Object
show all
Defined in:
lib/email_reply_parser.rb

Overview

EmailReplyParser is a small library to parse plain text email content. The goal is to identify which fragments are quoted, part of a signature, or original body content. We want to support both top and bottom posters, so no simple “REPLY ABOVE HERE” content is used.

Beyond RFC 5322 (which is handled by the [Ruby mail gem]), there aren’t any real standards for how emails are created. This attempts to parse out common conventions for things like replies:

this is some text

On <date>, <author> wrote:
> blah blah
> blah blah

… and signatures:

this is some text

--
Bob
http://homepage.com/~bob

Each of these are parsed into Fragment objects.

EmailReplyParser also attempts to figure out which of these blocks should be hidden from users.

[mail]: github.com/mikel/mail

Defined Under Namespace

Classes: Email, Fragment

Constant Summary collapse

VERSION =
"0.6"

Class Method Summary collapse

Class Method Details

.parse_reply(text, from_address = "") ⇒ Object

Public: Get the text of the visible portions of the given email body.

text - A String email body. from_address - from address of the email (optional)

Returns a String.



51
52
53
# File 'lib/email_reply_parser.rb', line 51

def self.parse_reply(text, from_address = "")
  self.read(text.to_s, from_address).visible_text
end

.read(text, from_address = "") ⇒ Object

Public: Splits an email body into a list of Fragments.

text - A String email body. from_address - from address of the email (optional)

Returns an Email instance.



41
42
43
# File 'lib/email_reply_parser.rb', line 41

def self.read(text, from_address = "")
  Email.new.read(text, from_address)
end