class Mail2cb::EmailContent

Public Class Methods

new(email) click to toggle source
# File lib/mail2cb/email_content.rb, line 4
def initialize(email)
  @email = email

  if @email.multipart?
    parse_parts(@email.parts)
  else
    @text_body = @email.body.decoded.force_encoding("ASCII-8BIT").encode('UTF-8', undef: :replace, replace: '')
  end
  @body = @html_body || @text_body
end

Public Instance Methods

body() click to toggle source
# File lib/mail2cb/email_content.rb, line 36
def body
  @body
end
body=(value) click to toggle source
# File lib/mail2cb/email_content.rb, line 39
def body=(value)
  @body = value
end
html() click to toggle source
# File lib/mail2cb/email_content.rb, line 28
def html
  @html_body
end
parse_parts(parts) click to toggle source
# File lib/mail2cb/email_content.rb, line 15
def parse_parts(parts)
  parts.each do |part|
    content_type = part.content_type.split(";")[0]
    if content_type == "text/html"
      @html_body = part.body.decoded.force_encoding("ASCII-8BIT").encode('UTF-8', undef: :replace, replace: '')
    elsif content_type == "text/plain"
      @text_body = part.body.decoded.force_encoding("ASCII-8BIT").encode('UTF-8', undef: :replace, replace: '')
    elsif content_type == "multipart/related"
      parse_parts(part.parts)
    end
  end
end
text() click to toggle source
# File lib/mail2cb/email_content.rb, line 32
def text
  @text_body
end