1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
module EmailSpec
module Extractors
class Base
attr_accessor :mail
def initialize(mail)
@mail = mail
end
def call
part_body ? HTMLEntities.new.decode(part_body) : ''
end
private
def part_body
raise NotImplementedError
end
end
class DefaultPartBody < Base
private
def part_body
(mail.html_part || mail.text_part || mail).body
end
end
class HtmlPartBody < Base
private
def part_body
mail.html_part ? mail.html_part.body : nil
end
end
class TextPartBody < Base
private
def part_body
mail.text_part ? mail.text_part.body : nil
end
end
end
end
|