Module: ExtendedEmailReplyParser
- Defined in:
- lib/extended_email_reply_parser.rb,
lib/extended_email_reply_parser/parsers.rb,
lib/extended_email_reply_parser/version.rb,
lib/extended_email_reply_parser/parsers/base.rb,
lib/extended_email_reply_parser/parsers/github.rb,
lib/extended_email_reply_parser/parsers/i18n_de.rb,
lib/extended_email_reply_parser/parsers/i18n_en.rb,
lib/extended_email_reply_parser/parsers/html_mails.rb
Overview
Defined Under Namespace
Modules: Parsers
Constant Summary collapse
- VERSION =
"0.5.1"
Class Method Summary collapse
-
.extract_text(message_or_path) ⇒ Object
Extract the body text from the given Mail::Message.
-
.extract_text_or_html(message_or_path) ⇒ Object
Extract the body text from the given Mail::Message.
-
.parse(object) ⇒ Object
This parses the given object, i.e.
- .parse_file(file_path) ⇒ Object
- .parse_message(message) ⇒ Object
- .parse_text(text) ⇒ Object
-
.read(email_file_path) ⇒ Object
Read an email file and return a parsable ‘Mail::Message` object.
Class Method Details
.extract_text(message_or_path) ⇒ Object
Extract the body text from the given Mail::Message.
ExtendedEmailReplyParser.extract_text
ExtendedEmailReplyParser.extract_text '/path/to/email.eml'
This is the same as:
.extract_text
53 54 55 56 57 58 59 |
# File 'lib/extended_email_reply_parser.rb', line 53 def self.extract_text() if .kind_of? Mail::Message .extract_text elsif .kind_of? String and File.file? Mail.read().extract_text end end |
.extract_text_or_html(message_or_path) ⇒ Object
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
ExtendedEmailReplyParser.extract_text_or_html '/path/to/email.eml'
This is the same as:
.extract_text_or_html
72 73 74 75 76 77 78 |
# File 'lib/extended_email_reply_parser.rb', line 72 def self.extract_text_or_html() if .kind_of? Mail::Message .extract_text_or_html elsif .kind_of? String and File.file? Mail.read().extract_text_or_html end end |
.parse(object) ⇒ Object
This parses the given object, i.e. removes quoted replies etc.
Examples:
ExtendedEmailReplyParser.parse "/path/to/email.eml"
ExtendedEmailReplyParser.parse
ExtendedEmailReplyParser.parse MyReplyModel.find(123).text_content
88 89 90 91 92 93 94 95 96 |
# 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. object end end |
.parse_file(file_path) ⇒ Object
98 99 100 |
# File 'lib/extended_email_reply_parser.rb', line 98 def self.parse_file(file_path) self. Mail.read file_path end |
.parse_message(message) ⇒ Object
102 103 104 |
# File 'lib/extended_email_reply_parser.rb', line 102 def self.() self.parse_text(.extract_text_or_html) end |
.parse_text(text) ⇒ Object
106 107 108 109 110 111 112 |
# 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) ⇒ Object
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"
40 41 42 |
# File 'lib/extended_email_reply_parser.rb', line 40 def self.read(email_file_path) Mail.read email_file_path end |