From cfb927ce754199e93740e53aee4e6b40acb396c5 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 27 Sep 2018 17:59:20 -0700 Subject: Ensure message id is present --- app/models/action_mailroom/inbound_email.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/models/action_mailroom') 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 -- cgit v1.2.3