diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2018-09-17 16:55:07 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2018-09-17 16:55:07 -0700 |
commit | 627bbd34e142fa7caff49fd660a9a586f3ed6826 (patch) | |
tree | c068e6a777d7fd7441f7fb6c5cbfb9e6e3bf29c6 | |
parent | 52b1e2c6cfd5e76d72a6de09b28e51f2440c48c4 (diff) | |
download | rails-627bbd34e142fa7caff49fd660a9a586f3ed6826.tar.gz rails-627bbd34e142fa7caff49fd660a9a586f3ed6826.tar.bz2 rails-627bbd34e142fa7caff49fd660a9a586f3ed6826.zip |
Add inbound email
3 files changed, 37 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 diff --git a/db/migrate/20180917164000_create_action_mailbox_tables.rb b/db/migrate/20180917164000_create_action_mailbox_tables.rb new file mode 100644 index 0000000000..c2ba8f63b7 --- /dev/null +++ b/db/migrate/20180917164000_create_action_mailbox_tables.rb @@ -0,0 +1,10 @@ +class CreateActionMailboxTables < ActiveRecord::Migration[5.2] + def change + create_table :action_mailbox_inbound_emails do |t| + t.integer :status, default: 0, null: false + + t.datetime :created_at, precision: 6 + t.datetime :updated_at, precision: 6 + end + end +end |