aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/action_mailbox/inbound_email/incineratable/incineration.rb
blob: ab9311edfb4c40b634b01b6c58f29f396fe921cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class ActionMailbox::InboundEmail::Incineratable::Incineration
  def initialize(inbound_email)
    @inbound_email = inbound_email
  end

  def run
    @inbound_email.destroy if due? && processed?
  end

  private
    def due?
      @inbound_email.updated_at < ActionMailbox.incinerate_after.ago.end_of_day
    end

    def processed?
      @inbound_email.delivered? || @inbound_email.bounced? || @inbound_email.failed?
    end
end