diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2018-09-25 16:26:53 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2018-09-25 16:26:53 -0700 |
commit | 96b6e7ce669cf412f931e700fafc99d6d7ef031a (patch) | |
tree | 9a83e0abace43c641edb41ca8906e08049e24b28 /app/models/action_mailroom | |
parent | 8eb239bd1a1350b151d57a639e589c68aed1f47a (diff) | |
download | rails-96b6e7ce669cf412f931e700fafc99d6d7ef031a.tar.gz rails-96b6e7ce669cf412f931e700fafc99d6d7ef031a.tar.bz2 rails-96b6e7ce669cf412f931e700fafc99d6d7ef031a.zip |
Extract and associate message_id with newly created inbound emails
Diffstat (limited to 'app/models/action_mailroom')
-rw-r--r-- | app/models/action_mailroom/inbound_email.rb | 17 |
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 |