Class: KNSEmailEndpoint::EmailEndpoint

Inherits:
Kynetx::Endpoint
  • Object
show all
Defined in:
lib/kns_email_endpoint/email_endpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, opts = {}, sender = nil) ⇒ EmailEndpoint

Returns a new instance of EmailEndpoint.



77
78
79
80
81
# File 'lib/kns_email_endpoint/email_endpoint.rb', line 77

def initialize(conn, opts={}, sender=nil)
  @conn = conn
  @sender = sender
  super(opts)
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



6
7
8
# File 'lib/kns_email_endpoint/email_endpoint.rb', line 6

def conn
  @conn
end

#message_stateObject (readonly)

Returns the value of attribute message_state.



6
7
8
# File 'lib/kns_email_endpoint/email_endpoint.rb', line 6

def message_state
  @message_state
end

Instance Method Details

#after_delete(d) ⇒ Object



31
32
33
# File 'lib/kns_email_endpoint/email_endpoint.rb', line 31

def after_delete(d)
  @message_state.delete
end

#after_forward(d) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/kns_email_endpoint/email_endpoint.rb', line 52

def after_forward(d)
  if d["to"] && @sender
    msg = params[:msg]
    f_msg = Mail.new do
      to d["to"]
      from msg.to
      subject d["subject"] ? d["subject"] : "Fwd: " + msg.subject.to_s
      body d["body"] ? d["body"] + msg[:body].to_s : msg.body.to_s
    end
    @sender.deliver!(f_msg)
    @message_state.state = :forwarded
  else
    @message_state.state = :error
  end

  if d["delete_message"] && status == :forwarded
    @message_state.delete
  end
end

#after_processed(d) ⇒ Object



73
74
75
# File 'lib/kns_email_endpoint/email_endpoint.rb', line 73

def after_processed(d)
  @message_state.state = :processed
end

#after_reply(d) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kns_email_endpoint/email_endpoint.rb', line 36

def after_reply(d)
  msg = params[:msg]
  r_msg = Mail.new(msg)
  r_msg.to = msg.from
  r_msg.from = msg.reply_to.nil? ? msg.to : msg.reply_to
  r_msg.subject = d["subject"] ? d["subject"] : "Re: " + msg.subject.to_s
  r_msg.body d["body"] ? d["body"] + msg[:body].to_s : msg.body.to_s
  @sender.deliver!(r_msg) if @sender
  @message_state.state = :replied

  if d["delete_message"]
    @message_state.delete
  end
end

#before_receivedObject



25
26
27
28
# File 'lib/kns_email_endpoint/email_endpoint.rb', line 25

def before_received
  @message_state = MessageState.new(@conn, params[:msg])
  @message_state.state = :processing
end

#statusObject



83
84
85
# File 'lib/kns_email_endpoint/email_endpoint.rb', line 83

def status
  @message_state.state
end