Class: Mail::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/extended_email_reply_parser/mail/message.rb

Instance Method Summary collapse

Instance Method Details

#body_in_utf8Object



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_htmlObject



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_contentObject



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_textObject



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_htmlObject



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

#parseObject



37
38
39
# File 'lib/extended_email_reply_parser/mail/message.rb', line 37

def parse
  ExtendedEmailReplyParser.parse self
end