Class: Email::Processor

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mail, opts = {}) ⇒ Processor

Returns a new instance of Processor.



7
8
9
10
# File 'lib/email/processor.rb', line 7

def initialize(mail, opts = {})
  @mail = mail
  @opts = opts
end

Instance Attribute Details

#receiverObject (readonly)

Returns the value of attribute receiver.



5
6
7
# File 'lib/email/processor.rb', line 5

def receiver
  @receiver
end

Class Method Details

.process!(mail, opts = {}) ⇒ Object



12
13
14
# File 'lib/email/processor.rb', line 12

def self.process!(mail, opts = {})
  Email::Processor.new(mail, opts).process!
end

Instance Method Details

#process!Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/email/processor.rb', line 16

def process!
  begin
    @receiver = Email::Receiver.new(@mail, @opts)
    @receiver.process!
  rescue RateLimiter::LimitExceeded
    if @opts[:retry_on_rate_limit]
      Jobs.enqueue(:process_email, mail: @mail, source: @opts[:source])
    else
      raise
    end
  rescue => e
    return handle_bounce(e) if @receiver&.is_bounce?

    log_email_process_failure(@mail, e)
    incoming_email = @receiver.try(:incoming_email)
    rejection_message = handle_failure(@mail, e)
    if rejection_message.present?
      set_incoming_email_rejection_message(incoming_email, rejection_message.body.to_s)
    end
  end
end