Class: Malm::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



5
6
7
8
9
# File 'lib/malm/message.rb', line 5

def initialize
  @email_body = ""
  @rcpt_to = []
  @state = :init_state
end

Instance Attribute Details

#email_bodyObject (readonly)

Returns the value of attribute email_body.



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

def email_body
  @email_body
end

#mail_fromObject (readonly)

Returns the value of attribute mail_from.



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

def mail_from
  @mail_from
end

#rcpt_toObject (readonly)

Returns the value of attribute rcpt_to.



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

def rcpt_to
  @rcpt_to
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

Instance Method Details

#process_line(line = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/malm/message.rb', line 11

def process_line(line=nil)    
  if line =~ /QUIT/
    return quit!
  end
  
  # state machine pattern. Delegate to state handler for where we're at in SMTP conversation
  response = send(@state, line)
  return error! unless response
  
  # transition if state handler returned a new state
  new_state = response.delete(:state)
  @state = new_state if new_state
  
  response
end

#subjectObject



27
28
29
30
31
# File 'lib/malm/message.rb', line 27

def subject
  if @email_body =~ /^Subject\: (.+)$/
    $1.strip
  end
end