Class: InlineStyle::Mail::Interceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/inline-style/mail-interceptor.rb

Constant Summary collapse

INLINE_MIME_TYPES =

The mime types we should inline. Basically HTML and XHTML. If you have something else you can just push it onto the list

%w(text/html application/xhtml+xml)

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Interceptor

Save the options to later pass to InlineStyle.process



20
21
22
# File 'lib/inline-style/mail-interceptor.rb', line 20

def initialize(options={})
  @options = options
end

Instance Method Details

#delivering_email(part) ⇒ Object

Mail callback where we actually inline the styles



25
26
27
28
29
30
31
32
33
# File 'lib/inline-style/mail-interceptor.rb', line 25

def delivering_email(part)
  if part.multipart?
    for part in part.parts
      delivering_email part
    end
  elsif INLINE_MIME_TYPES.any? {|m| part.content_type.starts_with? m}
    part.body = InlineStyle.process(part.body.to_s, @options)
  end
end