Class: Mail::Message
- Inherits:
-
Object
- Object
- Mail::Message
- Defined in:
- lib/extended_email_reply_parser/mail/message.rb
Instance Method Summary collapse
- #body_in_utf8 ⇒ Object
- #extract_html ⇒ Object
- #extract_html_body_content ⇒ Object
- #extract_text ⇒ Object
- #extract_text_or_html ⇒ Object
- #parse ⇒ Object
Instance Method Details
#body_in_utf8 ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/extended_email_reply_parser/mail/message.rb', line 10 def body_in_utf8 require 'charlock_holmes/string' body = self.body.decoded if body.present? encoding = body.detect_encoding[:encoding] body = body.force_encoding(encoding).encode('UTF-8') end return body end |
#extract_html ⇒ Object
24 25 26 |
# File 'lib/extended_email_reply_parser/mail/message.rb', line 24 def extract_html (self.html_part || (self if self.content_type.include?('text/html'))).try(:body_in_utf8) end |
#extract_html_body_content ⇒ Object
32 33 34 35 |
# File 'lib/extended_email_reply_parser/mail/message.rb', line 32 def extract_html_body_content # http://stackoverflow.com/a/356376/2066546 extract_html.match(/(.*<\s*body[^>]*>)(.*)(<\s*\/\s*body\s*\>.+)/m)[2] || extract_html end |
#extract_text ⇒ Object
20 21 22 |
# File 'lib/extended_email_reply_parser/mail/message.rb', line 20 def extract_text (self.text_part || (self if self.content_type.include?('text/plain'))).try(:body_in_utf8) end |
#extract_text_or_html ⇒ Object
28 29 30 |
# File 'lib/extended_email_reply_parser/mail/message.rb', line 28 def extract_text_or_html extract_text || extract_html_body_content end |
#parse ⇒ Object
37 38 39 |
# File 'lib/extended_email_reply_parser/mail/message.rb', line 37 def parse ExtendedEmailReplyParser.parse self end |