1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Flesh out conductor interface

This commit is contained in:
David Heinemeier Hansson 2018-09-27 17:39:13 -07:00
parent ab92058bbd
commit e1486aa353
10 changed files with 87 additions and 43 deletions

View file

@ -2,38 +2,15 @@
# TODO: Spam/malware catching?
# TODO: Specific bounces for SMTP good citizenship: 200/404/400
class ActionMailroom::InboundEmailsController < ActionController::Base
layout "action_mailroom"
skip_forgery_protection
before_action :ensure_development_env, except: :create
before_action :require_rfc822_message, only: :create
def index
@inbound_emails = ActionMailroom::InboundEmail.order(created_at: :desc)
end
def new
end
def show
@inbound_email = ActionMailroom::InboundEmail.find(params[:id])
end
def create
ActionMailroom::InboundEmail.create_from_raw_email!(params[:message])
respond_to do |format|
format.html { redirect_to main_app.rails_new_inbound_email_url }
format.any { head :created }
end
head :created
end
private
# TODO: Should probably separate the admin interface and do more to ensure that it isn't exposed to the web
def ensure_development_env
head :forbidden unless Rails.env.development?
end
def require_rfc822_message
head :unsupported_media_type unless params.require(:message).content_type == 'message/rfc822'
end

View file

@ -0,0 +1,30 @@
class Rails::Conductor::ActionMailroom::InboundEmailsController < Rails::Conductor::BaseController
def index
@inbound_emails = ActionMailroom::InboundEmail.order(created_at: :desc)
end
def new
end
def show
@inbound_email = ActionMailroom::InboundEmail.find(params[:id])
end
def create
inbound_email = create_inbound_email(new_mail)
redirect_to main_app.rails_conductor_inbound_email_url(inbound_email)
end
private
def new_mail
Mail.new params.require(:mail).permit(:from, :to, :cc, :bcc, :subject, :body)
end
def create_inbound_email(mail)
ActionMailroom::InboundEmail.create! raw_email: new_raw_email(mail), message_id: mail.message_id
end
def new_raw_email(mail)
{ io: StringIO.new(new_mail.to_s), filename: 'inbound.eml', content_type: 'message/rfc822', identify: false }
end
end

View file

@ -0,0 +1,10 @@
# TODO: Move this to Rails::Conductor gem
class Rails::Conductor::BaseController < ActionController::Base
layout "rails/conductor"
before_action :ensure_development_env
private
def ensure_development_env
head :forbidden unless Rails.env.development?
end
end

View file

@ -1,8 +0,0 @@
<% provide :title, "Deliver new inbound email" %>
<h1>Deliver new inbound email</h1>
<%= form_with(url: main_app.rails_inbound_emails_url, remote: false) do |form| %>
<%= form.file_field :message, size: "150x50", autofocus: true %><br>
<%= form.submit "Deliver inbound email" %>
<% end %>

View file

@ -1,7 +0,0 @@
<html>
<head>
<title><%= yield :title %></title>
</head>
<body>
<%= yield %>
</html>

View file

@ -0,0 +1,7 @@
<html>
<head>
<title>Rails Conductor: <%= yield :title %></title>
</head>
<body>
<%= yield %>
</html>

View file

@ -6,10 +6,10 @@
<tr><th>Message ID</th><th>Status</th></tr>
<% @inbound_emails.each do |inbound_email| %>
<tr>
<td><%= link_to inbound_email.message_id, main_app.rails_inbound_email_path(inbound_email) %></td>
<td><%= link_to inbound_email.message_id, main_app.rails_conductor_inbound_email_path(inbound_email) %></td>
<td><%= inbound_email.status %></td>
</tr>
<% end %>
</table>
<%= link_to "Deliver new inbound email", main_app.new_rails_inbound_email_path %>
<%= link_to "Deliver new inbound email", main_app.new_rails_conductor_inbound_email_path %>

View file

@ -0,0 +1,27 @@
<% provide :title, "Deliver new inbound email" %>
<h1>Deliver new inbound email</h1>
<%= form_with(url: main_app.rails_conductor_inbound_emails_path, scope: :mail, local: true) do |form| %>
<div>
<%= form.label :from, "From" %><br>
<%= form.text_field :from %>
</div>
<div>
<%= form.label :to, "To" %><br>
<%= form.text_field :to %>
</div>
<div>
<%= form.label :subject, "Subject" %><br>
<%= form.text_field :subject %>
</div>
<div>
<%= form.label :body, "Body" %><br>
<%= form.text_area :body, size: "40x20" %>
</div>
<%= form.submit "Deliver inbound email" %>
<% end %>

View file

@ -6,3 +6,8 @@
<li>Retry</li>
<li>Incinerate</li>
</ul>
<details>
<summary>Full email source</summary>
<pre><%= @inbound_email.source %></pre>
</details>

View file

@ -1,7 +1,10 @@
# frozen_string_literal: true
Rails.application.routes.draw do
scope 'rails/action_mailroom', module: 'action_mailroom' do
resources :inbound_emails, as: :rails_inbound_emails
post "/rails/action_mailroom/inbound_emails" => "action_mailroom/inbound_emails#create", as: :rails_inbound_emails
# TODO: Should these be mounted within the engine only?
scope "rails/conductor/action_mailroom/", module: "rails/conductor/action_mailroom" do
resources :inbound_emails, as: :rails_conductor_inbound_emails
end
end