Class: Sunabamail::Mail

Inherits:
Object
  • Object
show all
Defined in:
app/models/sunabamail/mail.rb

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Mail

Returns a new instance of Mail.



2
3
4
# File 'app/models/sunabamail/mail.rb', line 2

def initialize(raw)
  @mail_message = Mail::Message.new(raw.encoded)
end

Instance Method Details

#attachmentsObject



38
# File 'app/models/sunabamail/mail.rb', line 38

def attachments = mail_message.attachments

#has_html?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'app/models/sunabamail/mail.rb', line 12

def has_html?
  return true if html_part.present?

  "text/html" == content_type
end

#has_text?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'app/models/sunabamail/mail.rb', line 6

def has_text?
  return true if text_part.present?

  "text/plain" == content_type
end

#html_bodyObject



28
29
30
31
32
33
34
35
36
# File 'app/models/sunabamail/mail.rb', line 28

def html_body
  if multipart?
    part = html_part
    body = part.body
    body.to_s.force_encoding(part.charset)
  elsif "text/html" == content_type
    body.to_s.force_encoding(mail_message.charset)
  end
end

#text_bodyObject



18
19
20
21
22
23
24
25
26
# File 'app/models/sunabamail/mail.rb', line 18

def text_body
  if multipart?
    part = text_part
    body = part.body
    body.to_s.force_encoding(part.charset)
  elsif "text/plain" == content_type
    body.to_s.force_encoding(mail_message.charset)
  end
end