Class: DataCommand

Inherits:
Struct
  • Object
show all
Defined in:
lib/drillmail/commands/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



4
5
6
# File 'lib/drillmail/commands/data.rb', line 4

def body
  @body
end

#sessionObject

Returns the value of attribute session

Returns:

  • (Object)

    the current value of session



4
5
6
# File 'lib/drillmail/commands/data.rb', line 4

def session
  @session
end

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/drillmail/commands/data.rb', line 5

def call
  if session.reverse_path and session.forward_path
    session.connection.puts session.reply(354)

    while line = session.connection.gets and not line =~ /^(\r\n)?\.\r\n$/
      puts "Recieved #{line}"
      session.message.push(line)
    end

    mail = Mail.new(session.message.join)

    puts "writing to #{mail.to.last}/#{mail.message_id}.eml"
    # this could be dangerous as fake messages could flood in
    # as we would just be committing them all to disk. Should do this
    # async?
    File.open("./#{mail.to.last}/#{mail.message_id}.eml", 'w') do |f|
      f.write(mail)
    end

    session.reply(250)
  else
    session.reply(451)
  end
end