diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/action_mailbox/inbound_email.rb | 17 | ||||
-rw-r--r-- | app/models/jobs/action_mailbox/deliver_inbound_email_to_mailbox.rb | 10 |
2 files changed, 27 insertions, 0 deletions
diff --git a/app/models/action_mailbox/inbound_email.rb b/app/models/action_mailbox/inbound_email.rb new file mode 100644 index 0000000000..3e528b6642 --- /dev/null +++ b/app/models/action_mailbox/inbound_email.rb @@ -0,0 +1,17 @@ +class ActionMailbox::InboundEmail < ActiveRecord::Base + self.table_name = "action_mailbox_inbound_email" + + after_create_commit :deliver_to_mailroom_later + has_one_attached :raw_message + + enum status: %i[ pending processing delivered failed bounced ] + + def mail + @mail ||= Mail.new(Mail::Utilities.binary_unsafe_to_crlf(raw_message.download)) + end + + private + def deliver_to_mailroom_later + ActionMailbox::DeliverInboundEmailToMailroomJob.perform_later self + end +end diff --git a/app/models/jobs/action_mailbox/deliver_inbound_email_to_mailbox.rb b/app/models/jobs/action_mailbox/deliver_inbound_email_to_mailbox.rb new file mode 100644 index 0000000000..a5bd2c0f18 --- /dev/null +++ b/app/models/jobs/action_mailbox/deliver_inbound_email_to_mailbox.rb @@ -0,0 +1,10 @@ +class ActionMailbox::DeliverInboundEmailToMailroomJob < ApplicationJob + queue_as :action_mailbox_inbound_email + + # Occasional `SSL_read: decryption failed or bad record mac` that resolve on retry + retry_on OpenSSL::SSL::SSLError + + def perform(inbound_email) + ApplicationMailbox.receive inbound_email + end +end |