2018-09-18 01:15:27 -04:00
|
|
|
require "mail"
|
|
|
|
|
2018-09-17 19:56:55 -04:00
|
|
|
class ActionMailroom::InboundEmail < ActiveRecord::Base
|
2018-09-17 20:15:53 -04:00
|
|
|
self.table_name = "action_mailroom_inbound_emails"
|
2018-09-17 19:55:07 -04:00
|
|
|
|
2018-09-28 14:01:49 -04:00
|
|
|
include Incineratable, MessageId, Routable
|
2018-09-17 19:55:07 -04:00
|
|
|
|
2018-09-19 19:40:56 -04:00
|
|
|
has_one_attached :raw_email
|
2018-09-17 19:55:07 -04:00
|
|
|
enum status: %i[ pending processing delivered failed bounced ]
|
|
|
|
|
2018-09-28 14:01:49 -04:00
|
|
|
def self.mail_from_source(source)
|
|
|
|
Mail.new Mail::Utilities.binary_unsafe_to_crlf(source.to_s)
|
2018-09-25 19:26:53 -04:00
|
|
|
end
|
|
|
|
|
2018-09-17 19:55:07 -04:00
|
|
|
def mail
|
2018-09-27 20:37:34 -04:00
|
|
|
@mail ||= self.class.mail_from_source(source)
|
|
|
|
end
|
|
|
|
|
|
|
|
def source
|
|
|
|
@source ||= raw_email.download
|
2018-09-17 19:55:07 -04:00
|
|
|
end
|
|
|
|
end
|