Module: ActionMailer::Text

Defined in:
lib/actionmailer-text/text.rb,
lib/actionmailer-text/version.rb,
lib/actionmailer-text/html_to_plain_text.rb

Defined Under Namespace

Modules: HtmlToPlainText

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



3
4
5
6
7
# File 'lib/actionmailer-text/text.rb', line 3

def self.included(klass)
  klass.class_eval do
    include ActionMailer::Text::HtmlToPlainText
  end
end

Instance Method Details

#collect_responses(headers) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/actionmailer-text/text.rb', line 9

def collect_responses(headers)
  responses = super headers
  html_part = responses.detect { |response| response[:content_type] == 'text/html' }
  text_part = responses.detect { |response| response[:content_type] == 'text/plain' }
  if html_part && !text_part
    responses.insert 0, content_type: 'text/plain', body: convert_to_text(html_part[:body], nil)
    headers[:parts_order] = ['text/plain'] + headers[:parts_order] unless headers[:parts_order].include?('text/plain')
  end
  responses
end