From f128f88e2a79fb694be065fb2bf4520f15f619ae Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 17 Nov 2019 20:26:44 +0100 Subject: [PATCH] [ci skip] Simplify Action Mailbox Forwards example Keep the example complex enough to showcase involving Action Mailers to either: bounce and halt processing or finish the email processing by asking for more information. Closes https://github.com/rails/rails/pull/37736 [ Paul McMahon, Kasper Timm Hansen ] --- guides/source/action_mailbox_basics.md | 29 +++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/guides/source/action_mailbox_basics.md b/guides/source/action_mailbox_basics.md index de92401226098..b0f9662d256d1 100644 --- a/guides/source/action_mailbox_basics.md +++ b/guides/source/action_mailbox_basics.md @@ -288,37 +288,36 @@ $ bin/rails generate mailbox forwards # app/mailboxes/forwards_mailbox.rb class ForwardsMailbox < ApplicationMailbox # Callbacks specify prerequisites to processing - before_processing :require_forward + before_processing :require_projects def process - if forwarder.buckets.one? + # Record the forward on the one project, or… + if forwarder.projects.one? record_forward else - stage_forward_and_request_more_details + # …involve a second Action Mailer to ask which project to forward into. + request_forwarding_project end end private - def require_forward - unless message.forward? + def require_projects + if forwarder.projects.none? # Use Action Mailers to bounce incoming emails back to sender – this halts processing - bounce_with Forwards::BounceMailer.missing_forward( - inbound_email, forwarder: forwarder - ) + bounce_with Forwards::BounceMailer.no_projects(inbound_email, forwarder: forwarder) end end - def forwarder - @forwarder ||= Person.where(email_address: mail.from) + def record_forward + forwarder.forwards.create subject: mail.subject, content: mail.content end - def record_forward - forwarder.buckets.first.record \ - Forward.new forwarder: forwarder, subject: message.subject, content: mail.content + def request_forwarding_project + Forwards::RoutingMailer.choose_project(inbound_email, forwarder: forwarder).deliver_now end - def stage_forward_and_request_more_details - Forwards::RoutingMailer.choose_project(mail).deliver_now + def forwarder + @forwarder ||= User.find_by(email_address: mail.from) end end ```