Class: Spreewald::MailToPlaintextConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/spreewald_support/mail_to_plaintext_converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(mail, type = '') ⇒ MailToPlaintextConverter

Returns a new instance of MailToPlaintextConverter.



5
6
7
8
# File 'lib/spreewald_support/mail_to_plaintext_converter.rb', line 5

def initialize(mail, type = '')
  @mail = mail
  @type = type
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/spreewald_support/mail_to_plaintext_converter.rb', line 10

def run
  body = ''
  if mail.multipart?
    body = if mail.html_part && type != 'plain-text'
      text_from_html(mail.html_part.body.to_s)
    elsif mail.text_part && type != 'HTML'
      mail.text_part.body.to_s
    else
      mail.body.to_s
    end
  else
    if body_text_html?
      body = text_from_html(mail.body.to_s)
    else
      body = mail.body.to_s
    end
  end
  body.gsub("\r\n", "\n") # The mail gem (>= 2.7.1) switched from \n to \r\n line breaks (LF to CRLF) in plain text mails.
end