mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
add attachments to the new inbound mail
This commit is contained in:
parent
1e09019088
commit
0419bc3504
5 changed files with 44 additions and 1 deletions
|
@ -20,7 +20,11 @@ module Rails
|
||||||
|
|
||||||
private
|
private
|
||||||
def new_mail
|
def new_mail
|
||||||
Mail.new params.require(:mail).permit(:from, :to, :cc, :bcc, :in_reply_to, :subject, :body).to_h
|
Mail.new(params.require(:mail).permit(:from, :to, :cc, :bcc, :in_reply_to, :subject, :body).to_h).tap do |mail|
|
||||||
|
params[:mail][:attachments].to_a.each do |attachment|
|
||||||
|
mail.attachments[attachment.original_filename] = { filename: attachment.path, content_type: attachment.content_type }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_inbound_email(mail)
|
def create_inbound_email(mail)
|
||||||
|
|
|
@ -38,5 +38,10 @@
|
||||||
<%= form.text_area :body, size: "40x20" %>
|
<%= form.text_area :body, size: "40x20" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= form.label :attachments, "Attachments" %><br>
|
||||||
|
<%= form.file_field :attachments, multiple: true %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<%= form.submit "Deliver inbound email" %>
|
<%= form.submit "Deliver inbound email" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class Rails::Conductor::ActionMailbox::InboundEmailsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
test "create inbound email" do
|
||||||
|
with_rails_env("development") do
|
||||||
|
assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do
|
||||||
|
post rails_conductor_inbound_emails_path, params: {
|
||||||
|
mail: {
|
||||||
|
from: "Jason Fried <jason@37signals.com>",
|
||||||
|
to: "Replies <replies@example.com>",
|
||||||
|
bcc: "",
|
||||||
|
in_reply_to: "<4e6e35f5a38b4_479f13bb90078178@small-app-01.mail>",
|
||||||
|
subject: "Discussion: Let's debate these attachments",
|
||||||
|
body: "Let's talk about these images:",
|
||||||
|
attachments: [fixture_file_upload("files/avatar1.jpeg"), fixture_file_upload("files/avatar2.jpeg")]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal 2, ActionMailbox::InboundEmail.last.mail.attachments.size
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def with_rails_env(env)
|
||||||
|
old_rails_env = Rails.env
|
||||||
|
Rails.env = env
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
Rails.env = old_rails_env
|
||||||
|
end
|
||||||
|
end
|
BIN
actionmailbox/test/fixtures/files/avatar1.jpeg
vendored
Normal file
BIN
actionmailbox/test/fixtures/files/avatar1.jpeg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
actionmailbox/test/fixtures/files/avatar2.jpeg
vendored
Normal file
BIN
actionmailbox/test/fixtures/files/avatar2.jpeg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Loading…
Reference in a new issue