Sha256: ccf888e96760849a44d88dfcd236af08da6142806dc6a116702511c8873621c7

Contents?: true

Size: 939 Bytes

Versions: 1

Compression:

Stored size: 939 Bytes

Contents

# frozen_string_literals: true

module Jobshop
  module  Mailroom
    class BaseHandler
      attr_accessor :organization, :to, :from, :customer_contact, :customer,
        :subject, :content

      # Prefix for archive
      class_attribute :archive_prefix

      # Default From address when responding to incoming mail
      class_attribute :reply_as,
        default: Jobshop.configuration.smtp.default_from

      def initialize(message, mailman)
        self.organization = mailman.organization

        self.to   = Mail::Address.new(message.to.first)
        self.from = Mail::Address.new(message.from.first)

        self.customer_contact = organization.customer_contacts
          .find_by(email: from.address)

        self.customer = customer_contact&.customer ||
          organization.customers.find_by(from_domain)

        self.subject = message.subject
        self.content = parse_body(message)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jobshop-0.0.167 lib/jobshop/mailroom/base_handler.rb