Class: Fakemail::Mail

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

Instance Method Summary collapse

Constructor Details

#initialize(stream = nil) ⇒ Mail

Initialize a mail with input



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fakemail.rb', line 23

def initialize(stream=nil)
  headers = ''
  body = ''
  
  stream.each_line { |l| headers << l ; break if l.strip.empty? }
  stream.each_line { |l| body << l }
  
  format = headers =~ /text\/html/i ? 'html' : 'txt'
  filename = Time.now.to_i
  
  setup
  
  File.open("#{@dir}/#{filename}_headers.txt", "w") { |f| f.write(headers) }
  File.open("#{@dir}/#{filename}.#{format}", "w")   { |f| f.write(body) }
end

Instance Method Details

#setupObject

Setup an output path



41
42
43
44
# File 'lib/fakemail.rb', line 41

def setup
  @dir = Fakemail.output_path
  FileUtils.mkdir_p(@dir)
end