Class: BounceEmail::Mail

Inherits:
Object
  • Object
show all
Defined in:
lib/bounce-email.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mail) ⇒ Mail

You have to pass TMail object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bounce-email.rb', line 11

def initialize(mail) # You have to pass TMail object
    @isbounce = (check_if_bounce(mail)  ? true : false)

    if @isbounce
        if mail.subject.match(/auto.*reply|vacation|vocation|(out|away).*office|on holiday/i)
            @reason = "Vacation auto-reply"
        elsif !mail.parts.empty?
            @code = mail.parts[1].body.match(/Status: ([0-9.]{0,})/)
            @code = @code[1] if !@code.nil?
        end

        # Try to GET status code from txt
        @code = getStatusFromTxt(mail.body) if (@code.nil? || @code.blank?) && @reason.blank?
        @reason = "unknown" if @code.blank?

        if @reason.blank?
            @type = getTypeFromStatusCode(@code[0].chr.to_i)
            @reason = getReasonFromStatusCode(@code.gsub(/\./,'')[1..2])
        end
    end
    rescue
        @reason = "unknown"            
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



9
10
11
# File 'lib/bounce-email.rb', line 9

def code
  @code
end

#isbounceObject

Returns the value of attribute isbounce.



9
10
11
# File 'lib/bounce-email.rb', line 9

def isbounce
  @isbounce
end

#reasonObject

Returns the value of attribute reason.



9
10
11
# File 'lib/bounce-email.rb', line 9

def reason
  @reason
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/bounce-email.rb', line 9

def type
  @type
end