Skip to content

Commit

Permalink
[ci skip] Simplify Action Mailbox Forwards example
Browse files Browse the repository at this point in the history
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 #37736

[ Paul McMahon, Kasper Timm Hansen ]
  • Loading branch information
kaspth committed Nov 17, 2019
1 parent 25b35fd commit f128f88
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions guides/source/action_mailbox_basics.md
Expand Up @@ -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
```
Expand Down

0 comments on commit f128f88

Please sign in to comment.