Class: AlchemyCrm::BouncedDelivery

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attr_namesObject

Returns the value of attribute attr_names.



5
6
7
# File 'lib/alchemy_crm/bounced_delivery.rb', line 5

def attr_names
  @attr_names
end

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/alchemy_crm/bounced_delivery.rb', line 6

def message
  @message
end

#original_message_idObject

Returns the value of attribute original_message_id.



4
5
6
# File 'lib/alchemy_crm/bounced_delivery.rb', line 4

def original_message_id
  @original_message_id
end

#status_infoObject

Returns the value of attribute status_info.



4
5
6
# File 'lib/alchemy_crm/bounced_delivery.rb', line 4

def status_info
  @status_info
end

Class Method Details

.from_email(email) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/alchemy_crm/bounced_delivery.rb', line 8

def self.from_email(email)
  returning(bounce = self.new) do
    plain_part = email.parts.detect do |part|
      part.content_type == 'text/plain'
    end
    bounce.message = plain_part.body.strip

    status_part = email.parts.detect do |part|
      part.content_type == "message/delivery-status"
    end
    statuses = status_part.body.split(/\n/)

    bounce.status_info = statuses.inject({}) do |hash, line|
      key, value = line.split(/:/)
      hash[key] = value.strip rescue nil
      hash
    end
    original_message_part = email.parts.detect do |part|
      part.content_type == "message/rfc822" or
      part.content_type == "text/rfc822-headers"
    end
    parsed_msg = Mail.parse(original_message_part.body)
    bounce.original_message_id = parsed_msg.message_id
  end
end

Instance Method Details

#statusObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/alchemy_crm/bounced_delivery.rb', line 34

def status
  case status_info['Status']
  when /^5/
    'Failure'
  when /^4/
    'Temporary Failure'
  when /^2/
    'Success'
  end
end