aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/action_mailbox/inbound_email/incineratable/incineration.rb
blob: bd2bf7d91e9b6e34e38e5a047f557c39e21914f2 (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::InboundEmail::Incineratable::INCINERATABLE_AFTER.ago.end_of_day
    end

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