Skip to content

Commit c903dfe

Browse files
authored
Merge pull request rails#42395 from chexology/fix-file-upload-in-action_mailbox-conductor
Permit attachments in inbound email conductor mail params
2 parents 6741222 + c6c53a0 commit c903dfe

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

actionmailbox/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
* Add `attachments` to the list of permitted parameters for inbound emails conductor.
2+
3+
When using the conductor to test inbound emails with attachments, this prevents an
4+
unpermitted parameter warning in default configurations, and prevents errors for
5+
applications that set:
6+
7+
```ruby
8+
config.action_controller.action_on_unpermitted_parameters = :raise
9+
```
10+
11+
*David Jones*, *Dana Henke*
12+
113
* Add ability to configure ActiveStorage service
214
for storing email raw source.
315

actionmailbox/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ def create
2020

2121
private
2222
def new_mail
23-
Mail.new(params.require(:mail).permit(:from, :to, :cc, :bcc, :x_original_to, :in_reply_to, :subject, :body).to_h).tap do |mail|
23+
Mail.new(mail_params.except(:attachments).to_h).tap do |mail|
2424
mail[:bcc]&.include_in_headers = true
25-
params[:mail][:attachments].to_a.each do |attachment|
25+
mail_params[:attachments].to_a.each do |attachment|
2626
mail.add_file(filename: attachment.original_filename, content: attachment.read)
2727
end
2828
end
2929
end
3030

31+
def mail_params
32+
params.require(:mail).permit(:from, :to, :cc, :bcc, :x_original_to, :in_reply_to, :subject, :body, attachments: [])
33+
end
34+
3135
def create_inbound_email(mail)
3236
ActionMailbox::InboundEmail.create_and_extract_message_id!(mail.to_s)
3337
end

actionmailbox/test/dummy/config/environments/test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@
4646

4747
# Annotate rendered view with file names
4848
# config.action_view.annotate_rendered_view_with_filenames = true
49+
50+
# Raise error if unpermitted parameters are sent
51+
config.action_controller.action_on_unpermitted_parameters = :raise
4952
end

0 commit comments

Comments
 (0)