aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/action_mailroom
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/action_mailroom')
-rw-r--r--app/models/action_mailroom/inbound_email.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/action_mailroom/inbound_email.rb b/app/models/action_mailroom/inbound_email.rb
index 8526b47e78..790e0ccc4f 100644
--- a/app/models/action_mailroom/inbound_email.rb
+++ b/app/models/action_mailroom/inbound_email.rb
@@ -9,7 +9,22 @@ class ActionMailroom::InboundEmail < ActiveRecord::Base
has_one_attached :raw_email
enum status: %i[ pending processing delivered failed bounced ]
+ class << self
+ def create_from_raw_email!(raw_email, **options)
+ create! raw_email: raw_email, message_id: extract_message_id(raw_email), **options
+ end
+
+ def mail_from_raw_content(raw_email_content)
+ Mail.new(Mail::Utilities.binary_unsafe_to_crlf(raw_email_content.to_s))
+ end
+
+ private
+ def extract_message_id(raw_email)
+ mail_from_raw_content(raw_email.read).message_id
+ end
+ end
+
def mail
- @mail ||= Mail.new(Mail::Utilities.binary_unsafe_to_crlf(raw_email.download))
+ @mail ||= self.class.mail_from_raw_content(raw_email.download)
end
end