Method: Fakemail::Mail#initialize
- Defined in:
- lib/fakemail.rb
#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 |