<commit_before>require "active_support/rescuable"

require "action_mailbox/callbacks"
require "action_mailbox/routing"

class ActionMailbox::Base
  include ActiveSupport::Rescuable
  include ActionMailbox::Callbacks, ActionMailbox::Routing

  attr_reader :inbound_email
  delegate :mail, :delivered!, :bounced!, to: :inbound_email

  delegate :logger, to: ActionMailbox

  def self.receive(inbound_email)
    new(inbound_email).perform_processing
  end

  def initialize(inbound_email)
    @inbound_email = inbound_email
  end

  def perform_processing
    run_callbacks :process do
      track_status_of_inbound_email do
        process
      end
    end
  rescue => exception
    # TODO: Include a reference to the inbound_email in the exception raised so error handling becomes easier
    rescue_with_handler(exception) || raise
  end

  def process
    # Overwrite in subclasses
  end

  def finished_processing?
    inbound_email.delivered? || inbound_email.bounced?
  end


  def bounce_with(message)
    inbound_email.bounced!
    message.deliver_later
  end

  private
    def track_status_of_inbound_email
      inbound_email.processing!
      yield
      inbound_email.delivered! unless inbound_email.bounced?
    rescue => exception
      inbound_email.failed!
      raise
    end
end
<commit_msg>Remove unnecessary TODO<commit_after>require "active_support/rescuable"

require "action_mailbox/callbacks"
require "action_mailbox/routing"

class ActionMailbox::Base
  include ActiveSupport::Rescuable
  include ActionMailbox::Callbacks, ActionMailbox::Routing

  attr_reader :inbound_email
  delegate :mail, :delivered!, :bounced!, to: :inbound_email

  delegate :logger, to: ActionMailbox

  def self.receive(inbound_email)
    new(inbound_email).perform_processing
  end

  def initialize(inbound_email)
    @inbound_email = inbound_email
  end

  def perform_processing
    run_callbacks :process do
      track_status_of_inbound_email do
        process
      end
    end
  rescue => exception
    rescue_with_handler(exception) || raise
  end

  def process
    # Overwrite in subclasses
  end

  def finished_processing?
    inbound_email.delivered? || inbound_email.bounced?
  end


  def bounce_with(message)
    inbound_email.bounced!
    message.deliver_later
  end

  private
    def track_status_of_inbound_email
      inbound_email.processing!
      yield
      inbound_email.delivered! unless inbound_email.bounced?
    rescue => exception
      inbound_email.failed!
      raise
    end
end

{'fraction_non_alphanumeric': 0.06041335453100159, 'fraction_numerical': 0.0, 'mean_word_length': 3.877906976744186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2236125', 'n_tokens_mistral': 797, 'n_tokens_neox': 769, 'n_words': 176}