module ExtendedEmailReplyParser

Usage:

ExtendedEmailReplyParser.parse "/path/to/email.eml"
ExtendedEmailReplyParser.parse mail_message
ExtendedEmailReplyParser.parse MyReplyModel.find(123).text_content

Constants

VERSION

Public Class Methods

extract_text(message_or_path) click to toggle source

Extract the body text from the given Mail::Message.

ExtendedEmailReplyParser.extract_text message
ExtendedEmailReplyParser.extract_text '/path/to/email.eml'

This is the same as:

message.extract_text
# File lib/extended_email_reply_parser.rb, line 53
def self.extract_text(message_or_path)
  if message_or_path.kind_of? Mail::Message
    message_or_path.extract_text
  elsif message_or_path.kind_of? String and File.file? message_or_path
    Mail.read(message_or_path).extract_text
  end
end
extract_text_or_html(message_or_path) click to toggle source

Extract the body text from the given Mail::Message. If there is no text part, extract the content of the body tag of the html part.

ExtendedEmailReplyParser.extract_text_or_html message
ExtendedEmailReplyParser.extract_text_or_html '/path/to/email.eml'

This is the same as:

message.extract_text_or_html
# File lib/extended_email_reply_parser.rb, line 72
def self.extract_text_or_html(message_or_path)
  if message_or_path.kind_of? Mail::Message
    message_or_path.extract_text_or_html
  elsif message_or_path.kind_of? String and File.file? message_or_path
    Mail.read(message_or_path).extract_text_or_html
  end
end
parse(object) click to toggle source

This parses the given object, i.e. removes quoted replies etc.

Examples:

ExtendedEmailReplyParser.parse "/path/to/email.eml"
ExtendedEmailReplyParser.parse mail_message
ExtendedEmailReplyParser.parse MyReplyModel.find(123).text_content
# File lib/extended_email_reply_parser.rb, line 88
def self.parse(object)
  if object.kind_of? String and File.file? object
    self.parse_file object
  elsif object.kind_of? String
    self.parse_text object
  elsif object.kind_of? Mail::Message
    self.parse_message object
  end
end
parse_file(file_path) click to toggle source
# File lib/extended_email_reply_parser.rb, line 98
def self.parse_file(file_path)
  self.parse_message Mail.read file_path
end
parse_message(message) click to toggle source
# File lib/extended_email_reply_parser.rb, line 102
def self.parse_message(message)
  self.parse_text(message.extract_text_or_html)
end
parse_text(text) click to toggle source
# File lib/extended_email_reply_parser.rb, line 106
def self.parse_text(text)
  parsed_text = text
  Parsers::Base.subclasses.each do |parser_class|
    parsed_text = parser_class.new(parsed_text).parse
  end
  parsed_text
end
read(email_file_path) click to toggle source

Read an email file and return a parsable `Mail::Message` object. `Mail::Message` is defined in github.com/mikel/mail and slightly extended in this gem.

Examples:

ExtendedEmailReplyParser.read "/path/to/email.eml"
ExtendedEmailReplyParser.read("/path/to/email.eml").parse
ExtendedEmailReplyParser.read("/path/to/email.eml").class   # => Mail::Message

or, maybe, you are looking for this:

ExtendedEmailReplyParser.parse "/path/to/email.eml"
# File lib/extended_email_reply_parser.rb, line 40
def self.read(email_file_path)
  Mail.read email_file_path
end