<commit_before>require 'mail'
require 'erb'
require 'exceptioner/transport/base'
require 'exceptioner/transport/helper'

module Exceptioner::Transport

  class Mail < Base
    DEFAULT_SENDER_ADDRESS = '<EMAIL>'

    cattr_accessor :delivery_method

    cattr_accessor :delivery_options

    def self.deliver(exception, options = {})
      mail = prepare_mail(exception, options)
      mail.deliver
    end

    def self.render(exception, options = {})
      ERB.new(template, nil, '>').result(binding)
    end

    def self.template
      @template ||= File.read(File.expand_path(File.join(File.dirname(__FILE__), 'templates', 'exception.erb')))
    end
    
    def self.determine_mail_options(exception, mail_options)
      options = {}
      options[:from]    ||= options[:sender]
      options[:to]      ||= options[:recipients]
      options[:subject] ||= prefixed_subject(exception, options)
      options[:body]    ||= render(exception, mail_options)
      options.merge!(default_options)
    end

    protected
    def self.default_options
      super.merge(
        :delivery_method => delivery_method,
        :delivery_options => delivery_options,
        :sender => DEFAULT_SENDER_ADDRESS
      )
    end

    def self.prepare_mail(exception, mail_options)
      options = mail_options.dup<commit_msg>use inherited rendering features<commit_after>require 'mail'
require 'erb'
require 'exceptioner/transport/base'
require 'exceptioner/transport/helper'

module Exceptioner::Transport

  class Mail < Base
    DEFAULT_SENDER_ADDRESS = '<EMAIL>'

    cattr_accessor :delivery_method

    cattr_accessor :delivery_options

    def self.deliver(exception, options = {})
      mail = prepare_mail(exception, options)
      mail.deliver
    end

    def self.determine_mail_options(exception, mail_options)
      options = {}
      options[:from]    ||= options[:sender]
      options[:to]      ||= options[:recipients]
      options[:subject] ||= prefixed_subject(exception, options)
      options[:body]    ||= render(exception, mail_options)
      options.merge!(default_options)
    end

    protected
    def self.default_options
      super.merge(
        :delivery_method => delivery_method,
        :delivery_options => delivery_options,
        :sender => DEFAULT_SENDER_ADDRESS
      )
    end

    def self.prepare_mail(exception, mail_options)
      options = mail_options.dup
{'fraction_non_alphanumeric': 0.10530714584203928, 'fraction_numerical': 0.0, 'mean_word_length': 3.3846153846153846, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '3938240', 'n_tokens_mistral': 708, 'n_tokens_neox': 693, 'n_words': 134}