aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/action_mailroom
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-09-27 17:59:20 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-09-27 17:59:20 -0700
commitcfb927ce754199e93740e53aee4e6b40acb396c5 (patch)
tree3188132fb619fdd1dfe5655b2cfcef13524fcf5f /app/models/action_mailroom
parent83a44867c7ead753a5014afa08f3f4ebf2efba77 (diff)
downloadrails-cfb927ce754199e93740e53aee4e6b40acb396c5.tar.gz
rails-cfb927ce754199e93740e53aee4e6b40acb396c5.tar.bz2
rails-cfb927ce754199e93740e53aee4e6b40acb396c5.zip
Ensure message id is present
Diffstat (limited to 'app/models/action_mailroom')
-rw-r--r--app/models/action_mailroom/inbound_email.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/action_mailroom/inbound_email.rb b/app/models/action_mailroom/inbound_email.rb
index 6dd643073a..1f086b24bf 100644
--- a/app/models/action_mailroom/inbound_email.rb
+++ b/app/models/action_mailroom/inbound_email.rb
@@ -8,6 +8,8 @@ class ActionMailroom::InboundEmail < ActiveRecord::Base
has_one_attached :raw_email
enum status: %i[ pending processing delivered failed bounced ]
+ before_save :generate_missing_message_id
+
class << self
def create_from_raw_email!(raw_email, **options)
create! raw_email: raw_email, message_id: extract_message_id(raw_email), **options
@@ -21,7 +23,7 @@ class ActionMailroom::InboundEmail < ActiveRecord::Base
def extract_message_id(raw_email)
mail_from_source(raw_email.read).message_id
rescue => e
- # TODO: Assign message id if it can't be extracted?
+ # FIXME: Add logging with "Couldn't extract Message ID, so will generating a new random ID instead"
end
end
@@ -32,4 +34,9 @@ class ActionMailroom::InboundEmail < ActiveRecord::Base
def source
@source ||= raw_email.download
end
+
+ private
+ def generate_missing_message_id
+ self.message_id ||= Mail::MessageIdField.new.message_id
+ end
end