Module: MList::Util::TMailReaders

Included in:
Email, TMailBuilder
Defined in:
lib/mlist/util/tmail_methods.rb

Instance Method Summary collapse

Instance Method Details

#dateObject



5
6
7
8
9
# File 'lib/mlist/util/tmail_methods.rb', line 5

def date
  if date = tmail.header_string('date')
    Time.parse(date)
  end
end

#from_addressObject



11
12
13
# File 'lib/mlist/util/tmail_methods.rb', line 11

def from_address
  tmail.from.first.downcase
end

#htmlObject



15
16
17
18
19
20
21
22
23
# File 'lib/mlist/util/tmail_methods.rb', line 15

def html
  case tmail.content_type
  when 'text/html'
    tmail.body.strip
  when 'multipart/alternative'
    html_part = tmail.parts.detect {|part| part.content_type == 'text/html'}
    html_part.body.strip if html_part
  end
end

#identifierObject



25
26
27
# File 'lib/mlist/util/tmail_methods.rb', line 25

def identifier
  remove_brackets(tmail.header_string('message-id'))
end

#mailerObject



29
30
31
# File 'lib/mlist/util/tmail_methods.rb', line 29

def mailer
  tmail.header_string('x-mailer')
end

#textObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mlist/util/tmail_methods.rb', line 33

def text
  text_content = ''
  extract_text_content(tmail, text_content)
  return text_content unless text_content.blank?

  html_content = ''
  extract_html_content(tmail, html_content)
  return html_to_text(html_content) unless html_content.blank?

  return nil
end

#text_html_part(part = tmail) ⇒ Object

Answers the first text/html part it can find, the tmail itself if it’s content type is text/html.



48
49
50
51
52
53
54
55
# File 'lib/mlist/util/tmail_methods.rb', line 48

def text_html_part(part = tmail)
  case part.content_type
  when 'text/html'
    part
  when 'multipart/alternative'
    part.parts.detect {|part| text_html_part(part)}
  end
end

#text_plain_part(part = tmail) ⇒ Object

Answers the first text/plain part it can find, the tmail itself if it’s content type is text/plain.



60
61
62
63
64
65
66
67
# File 'lib/mlist/util/tmail_methods.rb', line 60

def text_plain_part(part = tmail)
  case part.content_type
  when 'text/plain'
    part
  when 'multipart/alternative'
    part.parts.detect {|part| text_plain_part(part)}
  end
end