2018-12-14 10:06:12 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-26 21:18:42 +00:00
|
|
|
module Rails
|
|
|
|
class Conductor::ActionMailbox::InboundEmailsController < Rails::Conductor::BaseController
|
|
|
|
def index
|
|
|
|
@inbound_emails = ActionMailbox::InboundEmail.order(created_at: :desc)
|
|
|
|
end
|
2018-09-28 00:39:13 +00:00
|
|
|
|
2018-12-26 21:18:42 +00:00
|
|
|
def new
|
|
|
|
end
|
2018-09-28 00:39:13 +00:00
|
|
|
|
2018-12-26 21:18:42 +00:00
|
|
|
def show
|
|
|
|
@inbound_email = ActionMailbox::InboundEmail.find(params[:id])
|
2018-09-28 00:39:13 +00:00
|
|
|
end
|
|
|
|
|
2018-12-26 21:18:42 +00:00
|
|
|
def create
|
|
|
|
inbound_email = create_inbound_email(new_mail)
|
|
|
|
redirect_to main_app.rails_conductor_inbound_email_url(inbound_email)
|
2018-09-28 00:39:13 +00:00
|
|
|
end
|
2018-12-26 21:18:42 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
def new_mail
|
2020-04-13 22:14:53 +00:00
|
|
|
Mail.new(params.require(:mail).permit(:from, :to, :cc, :bcc, :x_original_to, :in_reply_to, :subject, :body).to_h).tap do |mail|
|
2019-06-20 05:09:01 +00:00
|
|
|
mail[:bcc]&.include_in_headers = true
|
2019-01-06 22:05:39 +00:00
|
|
|
params[:mail][:attachments].to_a.each do |attachment|
|
2019-07-25 20:24:04 +00:00
|
|
|
mail.add_file(filename: attachment.original_filename, content: attachment.read)
|
2019-01-06 22:05:39 +00:00
|
|
|
end
|
|
|
|
end
|
2018-12-26 21:18:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_inbound_email(mail)
|
2019-01-17 20:19:37 +00:00
|
|
|
ActionMailbox::InboundEmail.create_and_extract_message_id!(mail.to_s)
|
2018-12-26 21:18:42 +00:00
|
|
|
end
|
|
|
|
end
|
2018-09-28 00:39:13 +00:00
|
|
|
end
|