Class: EmailSpy::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/email_spy/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location, email, part = nil) ⇒ Message

Returns a new instance of Message.



6
7
8
# File 'lib/email_spy/message.rb', line 6

def initialize(location, email, part = nil)
  @location, @email, @part, @attachments = location, email, part, []
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



4
5
6
# File 'lib/email_spy/message.rb', line 4

def attachments
  @attachments
end

#emailObject (readonly)

Returns the value of attribute email.



3
4
5
# File 'lib/email_spy/message.rb', line 3

def email
  @email
end

Instance Method Details

#bodyObject



27
28
29
# File 'lib/email_spy/message.rb', line 27

def body
  @body ||= (@part && @part.body || @email.body).to_s
end

#content_typeObject



23
24
25
# File 'lib/email_spy/message.rb', line 23

def content_type
  @part && @part.content_type || @email.content_type
end

#encodingObject



43
44
45
# File 'lib/email_spy/message.rb', line 43

def encoding
  if body.respond_to? :encoding then body.encoding else "utf-8" end
end

#filepathObject



19
20
21
# File 'lib/email_spy/message.rb', line 19

def filepath
  File.join @location, "#{type}.html"
end

#fromObject



31
32
33
# File 'lib/email_spy/message.rb', line 31

def from
  @from ||= Array(@email.from).join ", "
end

#renderObject



10
11
12
13
# File 'lib/email_spy/message.rb', line 10

def render
  create_attachments unless email.attachments.empty?
  create_templates filepath, binding
end

#reply_toObject



35
36
37
# File 'lib/email_spy/message.rb', line 35

def reply_to
  @reply_to ||= Array(@email.reply_to).join ", "
end

#templateObject



15
16
17
# File 'lib/email_spy/message.rb', line 15

def template
  File.read File.expand_path File.join("..", "message.html.erb"), __FILE__
end

#typeObject



39
40
41
# File 'lib/email_spy/message.rb', line 39

def type
  if content_type =~ /html/ then "rich" else "plain" end
end