actionmailbox 6.0.3.4 → 6.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -51
- data/MIT-LICENSE +1 -1
- data/app/controllers/action_mailbox/ingresses/mailgun/inbound_emails_controller.rb +31 -11
- data/app/controllers/action_mailbox/ingresses/postmark/inbound_emails_controller.rb +1 -1
- data/app/controllers/action_mailbox/ingresses/relay/inbound_emails_controller.rb +1 -1
- data/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb +16 -2
- data/app/controllers/rails/conductor/action_mailbox/inbound_emails/sources_controller.rb +13 -0
- data/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb +1 -1
- data/app/models/action_mailbox/inbound_email.rb +1 -1
- data/app/models/action_mailbox/inbound_email/message_id.rb +1 -1
- data/app/models/action_mailbox/record.rb +9 -0
- data/app/views/rails/conductor/action_mailbox/inbound_emails/index.html.erb +2 -1
- data/app/views/rails/conductor/action_mailbox/inbound_emails/new.html.erb +12 -7
- data/app/views/rails/conductor/action_mailbox/inbound_emails/sources/new.html.erb +12 -0
- data/config/routes.rb +3 -0
- data/lib/action_mailbox/gem_version.rb +3 -3
- data/lib/action_mailbox/router.rb +5 -5
- data/lib/action_mailbox/routing.rb +4 -0
- data/lib/action_mailbox/test_helper.rb +55 -7
- data/lib/generators/action_mailbox/install/install_generator.rb +28 -0
- data/lib/rails/generators/mailbox/USAGE +3 -3
- data/lib/tasks/install.rake +3 -17
- metadata +20 -17
- data/lib/rails/generators/installer.rb +0 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a2da3160e0a15c4d6264698db9762b686ba4aae4dea78c918bd6484ae7fbdd1
|
|
4
|
+
data.tar.gz: 4eb805e97dd25c645ca3ca6ce8fbaa9e2f24a39bc9bbe45b827b6338ba772084
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a29d6ff16b3c5962ac22feb8b3c0521bfa81ee4a03bac24ab249dc6ed8f70392ba714eb04d49ac701284c113726bb3cb30d5b06c593bef6ecba7c673cc0fdc3c
|
|
7
|
+
data.tar.gz: 4b7c313e609bd97e44d376f9c5efcd769df90ed222bbb046f0ef6ba0168632cc37a2fa9a9ad86fab460ac4d70f3b8356ba0cca3d3594a7b763c8169e7455560c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,83 +1,51 @@
|
|
|
1
|
-
## Rails 6.
|
|
1
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
|
2
2
|
|
|
3
3
|
* No changes.
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
## Rails 6.
|
|
6
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
|
7
7
|
|
|
8
8
|
* No changes.
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
## Rails 6.0
|
|
12
|
-
|
|
13
|
-
* No changes.
|
|
11
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
|
14
12
|
|
|
13
|
+
* Change default queue name of the incineration (`:action_mailbox_incineration`) and
|
|
14
|
+
routing (`:action_mailbox_routing`) jobs to be the job adapter's default (`:default`).
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
*Rafael Mendonça França*
|
|
17
17
|
|
|
18
|
-
*
|
|
18
|
+
* Sendgrid ingress now passes through the envelope recipient as `X-Original-To`.
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
## Rails 6.0.3 (May 06, 2020) ##
|
|
20
|
+
*Mark Haussmann*
|
|
22
21
|
|
|
23
22
|
* Update Mandrill inbound email route to respond appropriately to HEAD requests for URL health checks from Mandrill.
|
|
24
23
|
|
|
25
24
|
*Bill Cromie*
|
|
26
25
|
|
|
26
|
+
* Add way to deliver emails via source instead of filling out a form through the conductor interface.
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* No changes.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## Rails 6.0.2.1 (December 18, 2019) ##
|
|
34
|
-
|
|
35
|
-
* No changes.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## Rails 6.0.2 (December 13, 2019) ##
|
|
28
|
+
*DHH*
|
|
39
29
|
|
|
40
|
-
*
|
|
30
|
+
* Mailgun ingress now passes through the envelope recipient as `X-Original-To`.
|
|
41
31
|
|
|
32
|
+
*Rikki Pitt*
|
|
42
33
|
|
|
43
|
-
|
|
34
|
+
* Deprecate `Rails.application.credentials.action_mailbox.api_key` and `MAILGUN_INGRESS_API_KEY` in favor of `Rails.application.credentials.action_mailbox.signing_key` and `MAILGUN_INGRESS_SIGNING_KEY`.
|
|
44
35
|
|
|
45
|
-
*
|
|
36
|
+
*Matthijs Vos*
|
|
46
37
|
|
|
38
|
+
* Allow easier creation of multi-part emails from the `create_inbound_email_from_mail` and `receive_inbound_email_from_mail` test helpers.
|
|
47
39
|
|
|
48
|
-
|
|
40
|
+
*Michael Herold*
|
|
49
41
|
|
|
50
42
|
* Fix Bcc header not being included with emails from `create_inbound_email_from` test helpers.
|
|
51
43
|
|
|
52
44
|
*jduff*
|
|
53
45
|
|
|
46
|
+
* Add `ApplicationMailbox.mailbox_for` to expose mailbox routing.
|
|
54
47
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* No changes.
|
|
48
|
+
*James Dabbs*
|
|
58
49
|
|
|
59
50
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* No changes.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
|
66
|
-
|
|
67
|
-
* No changes.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
|
71
|
-
|
|
72
|
-
* Allow skipping incineration of processed emails.
|
|
73
|
-
|
|
74
|
-
This can be done by setting `config.action_mailbox.incinerate` to `false`.
|
|
75
|
-
|
|
76
|
-
*Pratik Naik*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
|
80
|
-
|
|
81
|
-
* Added to Rails.
|
|
82
|
-
|
|
83
|
-
*DHH*
|
|
51
|
+
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/actionmailbox/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
|
@@ -6,7 +6,7 @@ module ActionMailbox
|
|
|
6
6
|
# - +body-mime+: The full RFC 822 message
|
|
7
7
|
# - +timestamp+: The current time according to Mailgun as the number of seconds passed since the UNIX epoch
|
|
8
8
|
# - +token+: A randomly-generated, 50-character string
|
|
9
|
-
# - +signature+: A hexadecimal HMAC-SHA256 of the timestamp concatenated with the token, generated using the Mailgun
|
|
9
|
+
# - +signature+: A hexadecimal HMAC-SHA256 of the timestamp concatenated with the token, generated using the Mailgun Signing key
|
|
10
10
|
#
|
|
11
11
|
# Authenticates requests by validating their signatures.
|
|
12
12
|
#
|
|
@@ -16,21 +16,21 @@ module ActionMailbox
|
|
|
16
16
|
# - <tt>401 Unauthorized</tt> if the request's signature could not be validated, or if its timestamp is more than 2 minutes old
|
|
17
17
|
# - <tt>404 Not Found</tt> if Action Mailbox is not configured to accept inbound emails from Mailgun
|
|
18
18
|
# - <tt>422 Unprocessable Entity</tt> if the request is missing required parameters
|
|
19
|
-
# - <tt>500 Server Error</tt> if the Mailgun
|
|
19
|
+
# - <tt>500 Server Error</tt> if the Mailgun Signing key is missing, or one of the Active Record database,
|
|
20
20
|
# the Active Storage service, or the Active Job backend is misconfigured or unavailable
|
|
21
21
|
#
|
|
22
22
|
# == Usage
|
|
23
23
|
#
|
|
24
|
-
# 1. Give Action Mailbox your
|
|
24
|
+
# 1. Give Action Mailbox your Mailgun Signing key (which you can find under Settings -> Security & Users -> API security in Mailgun)
|
|
25
25
|
# so it can authenticate requests to the Mailgun ingress.
|
|
26
26
|
#
|
|
27
|
-
# Use <tt>rails credentials:edit</tt> to add your
|
|
28
|
-
# +action_mailbox.
|
|
27
|
+
# Use <tt>bin/rails credentials:edit</tt> to add your Signing key to your application's encrypted credentials under
|
|
28
|
+
# +action_mailbox.mailgun_signing_key+, where Action Mailbox will automatically find it:
|
|
29
29
|
#
|
|
30
30
|
# action_mailbox:
|
|
31
|
-
#
|
|
31
|
+
# mailgun_signing_key: ...
|
|
32
32
|
#
|
|
33
|
-
# Alternatively, provide your
|
|
33
|
+
# Alternatively, provide your Signing key in the +MAILGUN_INGRESS_SIGNING_KEY+ environment variable.
|
|
34
34
|
#
|
|
35
35
|
# 2. Tell Action Mailbox to accept emails from Mailgun:
|
|
36
36
|
#
|
|
@@ -46,10 +46,16 @@ module ActionMailbox
|
|
|
46
46
|
before_action :authenticate
|
|
47
47
|
|
|
48
48
|
def create
|
|
49
|
-
ActionMailbox::InboundEmail.create_and_extract_message_id!
|
|
49
|
+
ActionMailbox::InboundEmail.create_and_extract_message_id! mail
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
private
|
|
53
|
+
def mail
|
|
54
|
+
params.require("body-mime").tap do |raw_email|
|
|
55
|
+
raw_email.prepend("X-Original-To: ", params.require(:recipient), "\n") if params.key?(:recipient)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
53
59
|
def authenticate
|
|
54
60
|
head :unauthorized unless authenticated?
|
|
55
61
|
end
|
|
@@ -64,14 +70,28 @@ module ActionMailbox
|
|
|
64
70
|
).authenticated?
|
|
65
71
|
else
|
|
66
72
|
raise ArgumentError, <<~MESSAGE.squish
|
|
67
|
-
Missing required Mailgun
|
|
68
|
-
encrypted credentials or provide the
|
|
73
|
+
Missing required Mailgun Signing key. Set action_mailbox.mailgun_signing_key in your application's
|
|
74
|
+
encrypted credentials or provide the MAILGUN_INGRESS_SIGNING_KEY environment variable.
|
|
69
75
|
MESSAGE
|
|
70
76
|
end
|
|
71
77
|
end
|
|
72
78
|
|
|
73
79
|
def key
|
|
74
|
-
Rails.application.credentials.dig(:action_mailbox, :mailgun_api_key)
|
|
80
|
+
if Rails.application.credentials.dig(:action_mailbox, :mailgun_api_key)
|
|
81
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
|
82
|
+
Rails.application.credentials.action_mailbox.api_key is deprecated and will be ignored in Rails 6.2.
|
|
83
|
+
Use Rails.application.credentials.action_mailbox.signing_key instead.
|
|
84
|
+
MSG
|
|
85
|
+
Rails.application.credentials.dig(:action_mailbox, :mailgun_api_key)
|
|
86
|
+
elsif ENV["MAILGUN_INGRESS_API_KEY"]
|
|
87
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
|
88
|
+
The MAILGUN_INGRESS_API_KEY environment variable is deprecated and will be ignored in Rails 6.2.
|
|
89
|
+
Use MAILGUN_INGRESS_SIGNING_KEY instead.
|
|
90
|
+
MSG
|
|
91
|
+
ENV["MAILGUN_INGRESS_API_KEY"]
|
|
92
|
+
else
|
|
93
|
+
Rails.application.credentials.dig(:action_mailbox, :mailgun_signing_key) || ENV["MAILGUN_INGRESS_SIGNING_KEY"]
|
|
94
|
+
end
|
|
75
95
|
end
|
|
76
96
|
|
|
77
97
|
class Authenticator
|
|
@@ -27,7 +27,7 @@ module ActionMailbox
|
|
|
27
27
|
#
|
|
28
28
|
# 2. Generate a strong password that Action Mailbox can use to authenticate requests to the Postmark ingress.
|
|
29
29
|
#
|
|
30
|
-
# Use <tt>rails credentials:edit</tt> to add the password to your application's encrypted credentials under
|
|
30
|
+
# Use <tt>bin/rails credentials:edit</tt> to add the password to your application's encrypted credentials under
|
|
31
31
|
# +action_mailbox.ingress_password+, where Action Mailbox will automatically find it:
|
|
32
32
|
#
|
|
33
33
|
# action_mailbox:
|
|
@@ -27,7 +27,7 @@ module ActionMailbox
|
|
|
27
27
|
#
|
|
28
28
|
# 2. Generate a strong password that Action Mailbox can use to authenticate requests to the ingress.
|
|
29
29
|
#
|
|
30
|
-
# Use <tt>rails credentials:edit</tt> to add the password to your application's encrypted credentials under
|
|
30
|
+
# Use <tt>bin/rails credentials:edit</tt> to add the password to your application's encrypted credentials under
|
|
31
31
|
# +action_mailbox.ingress_password+, where Action Mailbox will automatically find it:
|
|
32
32
|
#
|
|
33
33
|
# action_mailbox:
|
|
@@ -27,7 +27,7 @@ module ActionMailbox
|
|
|
27
27
|
#
|
|
28
28
|
# 2. Generate a strong password that Action Mailbox can use to authenticate requests to the SendGrid ingress.
|
|
29
29
|
#
|
|
30
|
-
# Use <tt>rails credentials:edit</tt> to add the password to your application's encrypted credentials under
|
|
30
|
+
# Use <tt>bin/rails credentials:edit</tt> to add the password to your application's encrypted credentials under
|
|
31
31
|
# +action_mailbox.ingress_password+, where Action Mailbox will automatically find it:
|
|
32
32
|
#
|
|
33
33
|
# action_mailbox:
|
|
@@ -48,7 +48,21 @@ module ActionMailbox
|
|
|
48
48
|
before_action :authenticate_by_password
|
|
49
49
|
|
|
50
50
|
def create
|
|
51
|
-
ActionMailbox::InboundEmail.create_and_extract_message_id!
|
|
51
|
+
ActionMailbox::InboundEmail.create_and_extract_message_id! mail
|
|
52
|
+
rescue JSON::ParserError => error
|
|
53
|
+
logger.error error.message
|
|
54
|
+
head :unprocessable_entity
|
|
52
55
|
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
def mail
|
|
59
|
+
params.require(:email).tap do |raw_email|
|
|
60
|
+
envelope["to"].each { |to| raw_email.prepend("X-Original-To: ", to, "\n") } if params.key?(:envelope)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def envelope
|
|
65
|
+
JSON.parse(params.require(:envelope))
|
|
66
|
+
end
|
|
53
67
|
end
|
|
54
68
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rails
|
|
4
|
+
class Conductor::ActionMailbox::InboundEmails::SourcesController < Rails::Conductor::BaseController
|
|
5
|
+
def new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def create
|
|
9
|
+
inbound_email = ActionMailbox::InboundEmail.create_and_extract_message_id! params[:source]
|
|
10
|
+
redirect_to main_app.rails_conductor_inbound_email_url(inbound_email)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -20,7 +20,7 @@ module Rails
|
|
|
20
20
|
|
|
21
21
|
private
|
|
22
22
|
def new_mail
|
|
23
|
-
Mail.new(params.require(:mail).permit(:from, :to, :cc, :bcc, :in_reply_to, :subject, :body).to_h).tap do |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|
|
|
24
24
|
mail[:bcc]&.include_in_headers = true
|
|
25
25
|
params[:mail][:attachments].to_a.each do |attachment|
|
|
26
26
|
mail.add_file(filename: attachment.original_filename, content: attachment.read)
|
|
@@ -24,7 +24,7 @@ module ActionMailbox
|
|
|
24
24
|
#
|
|
25
25
|
# inbound_email.mail.from # => 'david@loudthinking.com'
|
|
26
26
|
# inbound_email.source # Returns the full rfc822 source of the email as text
|
|
27
|
-
class InboundEmail <
|
|
27
|
+
class InboundEmail < Record
|
|
28
28
|
self.table_name = "action_mailbox_inbound_emails"
|
|
29
29
|
|
|
30
30
|
include Incineratable, MessageId, Routable
|
|
@@ -10,7 +10,7 @@ module ActionMailbox::InboundEmail::MessageId
|
|
|
10
10
|
extend ActiveSupport::Concern
|
|
11
11
|
|
|
12
12
|
class_methods do
|
|
13
|
-
# Create a new +InboundEmail+ from the raw +source+ of the email, which
|
|
13
|
+
# Create a new +InboundEmail+ from the raw +source+ of the email, which is uploaded as an Active Storage
|
|
14
14
|
# attachment called +raw_email+. Before the upload, extract the Message-ID from the +source+ and set
|
|
15
15
|
# it as an attribute on the new +InboundEmail+.
|
|
16
16
|
def create_and_extract_message_id!(source, **options)
|
|
@@ -12,4 +12,5 @@
|
|
|
12
12
|
<% end %>
|
|
13
13
|
</table>
|
|
14
14
|
|
|
15
|
-
<%= link_to "
|
|
15
|
+
<%= link_to "New inbound email by form", main_app.new_rails_conductor_inbound_email_path %> |
|
|
16
|
+
<%= link_to "New inbound email by source", main_app.new_rails_conductor_inbound_email_source_path %>
|
|
@@ -5,37 +5,42 @@
|
|
|
5
5
|
<%= form_with(url: main_app.rails_conductor_inbound_emails_path, scope: :mail, local: true) do |form| %>
|
|
6
6
|
<div>
|
|
7
7
|
<%= form.label :from, "From" %><br>
|
|
8
|
-
<%= form.text_field :from %>
|
|
8
|
+
<%= form.text_field :from, value: params[:from] %>
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
11
|
<div>
|
|
12
12
|
<%= form.label :to, "To" %><br>
|
|
13
|
-
<%= form.text_field :to %>
|
|
13
|
+
<%= form.text_field :to, value: params[:to] %>
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
16
|
<div>
|
|
17
17
|
<%= form.label :cc, "CC" %><br>
|
|
18
|
-
<%= form.text_field :cc %>
|
|
18
|
+
<%= form.text_field :cc, value: params[:cc] %>
|
|
19
19
|
</div>
|
|
20
20
|
|
|
21
21
|
<div>
|
|
22
22
|
<%= form.label :bcc, "BCC" %><br>
|
|
23
|
-
<%= form.text_field :bcc %>
|
|
23
|
+
<%= form.text_field :bcc, value: params[:bcc] %>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div>
|
|
27
|
+
<%= form.label :x_original_to, "X-Original-To" %><br>
|
|
28
|
+
<%= form.text_field :x_original_to, value: params[:x_original_to] %>
|
|
24
29
|
</div>
|
|
25
30
|
|
|
26
31
|
<div>
|
|
27
32
|
<%= form.label :in_reply_to, "In-Reply-To" %><br>
|
|
28
|
-
<%= form.text_field :in_reply_to %>
|
|
33
|
+
<%= form.text_field :in_reply_to, value: params[:in_reply_to] %>
|
|
29
34
|
</div>
|
|
30
35
|
|
|
31
36
|
<div>
|
|
32
37
|
<%= form.label :subject, "Subject" %><br>
|
|
33
|
-
<%= form.text_field :subject %>
|
|
38
|
+
<%= form.text_field :subject, value: params[:subject] %>
|
|
34
39
|
</div>
|
|
35
40
|
|
|
36
41
|
<div>
|
|
37
42
|
<%= form.label :body, "Body" %><br>
|
|
38
|
-
<%= form.text_area :body, size: "40x20" %>
|
|
43
|
+
<%= form.text_area :body, size: "40x20", value: params[:body] %>
|
|
39
44
|
</div>
|
|
40
45
|
|
|
41
46
|
<div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<% provide :title, "Deliver new inbound email by source" %>
|
|
2
|
+
|
|
3
|
+
<h1>Deliver new inbound email by source</h1>
|
|
4
|
+
|
|
5
|
+
<%= form_with(url: main_app.rails_conductor_inbound_email_sources_path, local: true) do |form| %>
|
|
6
|
+
<div>
|
|
7
|
+
<%= form.label :source, "Source" %><br>
|
|
8
|
+
<%= form.text_area :source, size: "80x60" %>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<%= form.submit "Deliver inbound email" %>
|
|
12
|
+
<% end %>
|
data/config/routes.rb
CHANGED
|
@@ -17,6 +17,9 @@ Rails.application.routes.draw do
|
|
|
17
17
|
# TODO: Should these be mounted within the engine only?
|
|
18
18
|
scope "rails/conductor/action_mailbox/", module: "rails/conductor/action_mailbox" do
|
|
19
19
|
resources :inbound_emails, as: :rails_conductor_inbound_emails
|
|
20
|
+
get "inbound_emails/sources/new", to: "inbound_emails/sources#new", as: :new_rails_conductor_inbound_email_source
|
|
21
|
+
post "inbound_emails/sources", to: "inbound_emails/sources#create", as: :rails_conductor_inbound_email_sources
|
|
22
|
+
|
|
20
23
|
post ":inbound_email_id/reroute" => "reroutes#create", as: :rails_conductor_inbound_email_reroute
|
|
21
24
|
end
|
|
22
25
|
end
|
|
@@ -21,7 +21,7 @@ module ActionMailbox
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def route(inbound_email)
|
|
24
|
-
if mailbox =
|
|
24
|
+
if mailbox = mailbox_for(inbound_email)
|
|
25
25
|
mailbox.receive(inbound_email)
|
|
26
26
|
else
|
|
27
27
|
inbound_email.bounced!
|
|
@@ -30,12 +30,12 @@ module ActionMailbox
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def mailbox_for(inbound_email)
|
|
34
|
+
routes.detect { |route| route.match?(inbound_email) }&.mailbox_class
|
|
35
|
+
end
|
|
36
|
+
|
|
33
37
|
private
|
|
34
38
|
attr_reader :routes
|
|
35
|
-
|
|
36
|
-
def match_to_mailbox(inbound_email)
|
|
37
|
-
routes.detect { |route| route.match?(inbound_email) }.try(:mailbox_class)
|
|
38
|
-
end
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
@@ -10,11 +10,58 @@ module ActionMailbox
|
|
|
10
10
|
create_inbound_email_from_source file_fixture(fixture_name).read, status: status
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
#
|
|
13
|
+
# Creates an +InboundEmail+ by specifying through options or a block.
|
|
14
|
+
#
|
|
15
|
+
# ==== Options
|
|
16
|
+
#
|
|
17
|
+
# * <tt>:status</tt> - The +status+ to set for the created +InboundEmail+.
|
|
18
|
+
# For possible statuses, see {its documentation}[rdoc-ref:ActionMailbox::InboundEmail].
|
|
19
|
+
#
|
|
20
|
+
# ==== Creating a simple email
|
|
21
|
+
#
|
|
22
|
+
# When you only need to set basic fields like +from+, +to+, +subject+, and
|
|
23
|
+
# +body+, you can pass them directly as options.
|
|
14
24
|
#
|
|
15
25
|
# create_inbound_email_from_mail(from: "david@loudthinking.com", subject: "Hello!")
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
#
|
|
27
|
+
# ==== Creating a multi-part email
|
|
28
|
+
#
|
|
29
|
+
# When you need to create a more intricate email, like a multi-part email
|
|
30
|
+
# that contains both a plaintext version and an HTML version, you can pass a
|
|
31
|
+
# block.
|
|
32
|
+
#
|
|
33
|
+
# create_inbound_email_from_mail do
|
|
34
|
+
# to "David Heinemeier Hansson <david@loudthinking.com>"
|
|
35
|
+
# from "Bilbo Baggins <bilbo@bagend.com>"
|
|
36
|
+
# subject "Come down to the Shire!"
|
|
37
|
+
#
|
|
38
|
+
# text_part do
|
|
39
|
+
# body "Please join us for a party at Bag End"
|
|
40
|
+
# end
|
|
41
|
+
#
|
|
42
|
+
# html_part do
|
|
43
|
+
# body "<h1>Please join us for a party at Bag End</h1>"
|
|
44
|
+
# end
|
|
45
|
+
# end
|
|
46
|
+
#
|
|
47
|
+
# As with +Mail.new+, you can also use a block parameter to define the parts
|
|
48
|
+
# of the message:
|
|
49
|
+
#
|
|
50
|
+
# create_inbound_email_from_mail do |mail|
|
|
51
|
+
# mail.to "David Heinemeier Hansson <david@loudthinking.com>"
|
|
52
|
+
# mail.from "Bilbo Baggins <bilbo@bagend.com>"
|
|
53
|
+
# mail.subject "Come down to the Shire!"
|
|
54
|
+
#
|
|
55
|
+
# mail.text_part do |part|
|
|
56
|
+
# part.body "Please join us for a party at Bag End"
|
|
57
|
+
# end
|
|
58
|
+
#
|
|
59
|
+
# mail.html_part do |part|
|
|
60
|
+
# part.body "<h1>Please join us for a party at Bag End</h1>"
|
|
61
|
+
# end
|
|
62
|
+
# end
|
|
63
|
+
def create_inbound_email_from_mail(status: :processing, **mail_options, &block)
|
|
64
|
+
mail = Mail.new(mail_options, &block)
|
|
18
65
|
# Bcc header is not encoded by default
|
|
19
66
|
mail[:bcc].include_in_headers = true if mail[:bcc]
|
|
20
67
|
|
|
@@ -33,10 +80,11 @@ module ActionMailbox
|
|
|
33
80
|
create_inbound_email_from_fixture(*args).tap(&:route)
|
|
34
81
|
end
|
|
35
82
|
|
|
36
|
-
# Create an +InboundEmail+ using the same
|
|
37
|
-
#
|
|
38
|
-
|
|
39
|
-
|
|
83
|
+
# Create an +InboundEmail+ using the same options or block as
|
|
84
|
+
# {create_inbound_email_from_mail}[rdoc-ref:#create_inbound_email_from_mail],
|
|
85
|
+
# then immediately route it for processing.
|
|
86
|
+
def receive_inbound_email_from_mail(**kwargs, &block)
|
|
87
|
+
create_inbound_email_from_mail(**kwargs, &block).tap(&:route)
|
|
40
88
|
end
|
|
41
89
|
|
|
42
90
|
# Create an +InboundEmail+ using the same arguments as +create_inbound_email_from_source+ and immediately route it
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators/mailbox/mailbox_generator"
|
|
4
|
+
|
|
5
|
+
module ActionMailbox
|
|
6
|
+
module Generators
|
|
7
|
+
class InstallGenerator < ::Rails::Generators::Base
|
|
8
|
+
source_root Rails::Generators::MailboxGenerator.source_root
|
|
9
|
+
|
|
10
|
+
def create_action_mailbox_files
|
|
11
|
+
say "Copying application_mailbox.rb to app/mailboxes", :green
|
|
12
|
+
template "application_mailbox.rb", "app/mailboxes/application_mailbox.rb"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_action_mailbox_production_environment_config
|
|
16
|
+
environment <<~end_of_config, env: "production"
|
|
17
|
+
# Prepare the ingress controller used to receive mail
|
|
18
|
+
# config.action_mailbox.ingress = :relay
|
|
19
|
+
|
|
20
|
+
end_of_config
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def create_migrations
|
|
24
|
+
rails_command "railties:install:migrations FROM=active_storage,action_mailbox", inline: true
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Description:
|
|
2
2
|
============
|
|
3
|
-
|
|
3
|
+
Generates a new mailbox class in app/mailboxes and invokes your template
|
|
4
4
|
engine and test framework generators.
|
|
5
5
|
|
|
6
6
|
Example:
|
|
7
7
|
========
|
|
8
|
-
rails generate mailbox inbox
|
|
8
|
+
bin/rails generate mailbox inbox
|
|
9
9
|
|
|
10
|
-
creates
|
|
10
|
+
creates an InboxMailbox class and test:
|
|
11
11
|
Mailbox: app/mailboxes/inbox_mailbox.rb
|
|
12
12
|
Test: test/mailboxes/inbox_mailbox_test.rb
|
data/lib/tasks/install.rake
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
desc "Copy over the migration"
|
|
8
|
-
task install: %w[ environment run_installer copy_migrations ]
|
|
9
|
-
|
|
10
|
-
task :run_installer do
|
|
11
|
-
installer_template = File.expand_path("../rails/generators/installer.rb", __dir__)
|
|
12
|
-
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{installer_template}"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
task :copy_migrations do
|
|
16
|
-
Rake::Task["active_storage:install:migrations"].invoke
|
|
17
|
-
Rake::Task["railties:install:migrations"].reenable # Otherwise you can't run 2 migration copy tasks in one invocation
|
|
18
|
-
Rake::Task["action_mailbox:install:migrations"].invoke
|
|
19
|
-
end
|
|
3
|
+
desc "Installs Action Mailbox and its dependencies"
|
|
4
|
+
task "action_mailbox:install" do
|
|
5
|
+
Rails::Command.invoke :generate, ["action_mailbox:install"]
|
|
20
6
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: actionmailbox
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Heinemeier Hansson
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|
|
@@ -17,70 +17,70 @@ dependencies:
|
|
|
17
17
|
requirements:
|
|
18
18
|
- - '='
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version: 6.
|
|
20
|
+
version: 6.1.2
|
|
21
21
|
type: :runtime
|
|
22
22
|
prerelease: false
|
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
24
|
requirements:
|
|
25
25
|
- - '='
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
|
-
version: 6.
|
|
27
|
+
version: 6.1.2
|
|
28
28
|
- !ruby/object:Gem::Dependency
|
|
29
29
|
name: activerecord
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
|
32
32
|
- - '='
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: 6.
|
|
34
|
+
version: 6.1.2
|
|
35
35
|
type: :runtime
|
|
36
36
|
prerelease: false
|
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
38
|
requirements:
|
|
39
39
|
- - '='
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: 6.
|
|
41
|
+
version: 6.1.2
|
|
42
42
|
- !ruby/object:Gem::Dependency
|
|
43
43
|
name: activestorage
|
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
46
|
- - '='
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: 6.
|
|
48
|
+
version: 6.1.2
|
|
49
49
|
type: :runtime
|
|
50
50
|
prerelease: false
|
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
|
53
53
|
- - '='
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: 6.
|
|
55
|
+
version: 6.1.2
|
|
56
56
|
- !ruby/object:Gem::Dependency
|
|
57
57
|
name: activejob
|
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
|
60
60
|
- - '='
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
|
-
version: 6.
|
|
62
|
+
version: 6.1.2
|
|
63
63
|
type: :runtime
|
|
64
64
|
prerelease: false
|
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
|
66
66
|
requirements:
|
|
67
67
|
- - '='
|
|
68
68
|
- !ruby/object:Gem::Version
|
|
69
|
-
version: 6.
|
|
69
|
+
version: 6.1.2
|
|
70
70
|
- !ruby/object:Gem::Dependency
|
|
71
71
|
name: actionpack
|
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
|
73
73
|
requirements:
|
|
74
74
|
- - '='
|
|
75
75
|
- !ruby/object:Gem::Version
|
|
76
|
-
version: 6.
|
|
76
|
+
version: 6.1.2
|
|
77
77
|
type: :runtime
|
|
78
78
|
prerelease: false
|
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
|
80
80
|
requirements:
|
|
81
81
|
- - '='
|
|
82
82
|
- !ruby/object:Gem::Version
|
|
83
|
-
version: 6.
|
|
83
|
+
version: 6.1.2
|
|
84
84
|
- !ruby/object:Gem::Dependency
|
|
85
85
|
name: mail
|
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -112,6 +112,7 @@ files:
|
|
|
112
112
|
- app/controllers/action_mailbox/ingresses/postmark/inbound_emails_controller.rb
|
|
113
113
|
- app/controllers/action_mailbox/ingresses/relay/inbound_emails_controller.rb
|
|
114
114
|
- app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb
|
|
115
|
+
- app/controllers/rails/conductor/action_mailbox/inbound_emails/sources_controller.rb
|
|
115
116
|
- app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb
|
|
116
117
|
- app/controllers/rails/conductor/action_mailbox/reroutes_controller.rb
|
|
117
118
|
- app/controllers/rails/conductor/base_controller.rb
|
|
@@ -122,10 +123,12 @@ files:
|
|
|
122
123
|
- app/models/action_mailbox/inbound_email/incineratable/incineration.rb
|
|
123
124
|
- app/models/action_mailbox/inbound_email/message_id.rb
|
|
124
125
|
- app/models/action_mailbox/inbound_email/routable.rb
|
|
126
|
+
- app/models/action_mailbox/record.rb
|
|
125
127
|
- app/views/layouts/rails/conductor.html.erb
|
|
126
128
|
- app/views/rails/conductor/action_mailbox/inbound_emails/index.html.erb
|
|
127
129
|
- app/views/rails/conductor/action_mailbox/inbound_emails/new.html.erb
|
|
128
130
|
- app/views/rails/conductor/action_mailbox/inbound_emails/show.html.erb
|
|
131
|
+
- app/views/rails/conductor/action_mailbox/inbound_emails/sources/new.html.erb
|
|
129
132
|
- config/routes.rb
|
|
130
133
|
- db/migrate/20180917164000_create_action_mailbox_tables.rb
|
|
131
134
|
- lib/action_mailbox.rb
|
|
@@ -146,7 +149,7 @@ files:
|
|
|
146
149
|
- lib/action_mailbox/test_case.rb
|
|
147
150
|
- lib/action_mailbox/test_helper.rb
|
|
148
151
|
- lib/action_mailbox/version.rb
|
|
149
|
-
- lib/
|
|
152
|
+
- lib/generators/action_mailbox/install/install_generator.rb
|
|
150
153
|
- lib/rails/generators/mailbox/USAGE
|
|
151
154
|
- lib/rails/generators/mailbox/mailbox_generator.rb
|
|
152
155
|
- lib/rails/generators/mailbox/templates/application_mailbox.rb.tt
|
|
@@ -160,10 +163,10 @@ licenses:
|
|
|
160
163
|
- MIT
|
|
161
164
|
metadata:
|
|
162
165
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
|
163
|
-
changelog_uri: https://github.com/rails/rails/blob/v6.
|
|
164
|
-
documentation_uri: https://api.rubyonrails.org/v6.
|
|
166
|
+
changelog_uri: https://github.com/rails/rails/blob/v6.1.2/actionmailbox/CHANGELOG.md
|
|
167
|
+
documentation_uri: https://api.rubyonrails.org/v6.1.2/
|
|
165
168
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
|
166
|
-
source_code_uri: https://github.com/rails/rails/tree/v6.
|
|
169
|
+
source_code_uri: https://github.com/rails/rails/tree/v6.1.2/actionmailbox
|
|
167
170
|
post_install_message:
|
|
168
171
|
rdoc_options: []
|
|
169
172
|
require_paths:
|
|
@@ -179,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
179
182
|
- !ruby/object:Gem::Version
|
|
180
183
|
version: '0'
|
|
181
184
|
requirements: []
|
|
182
|
-
rubygems_version: 3.
|
|
185
|
+
rubygems_version: 3.2.3
|
|
183
186
|
signing_key:
|
|
184
187
|
specification_version: 4
|
|
185
188
|
summary: Inbound email handling framework.
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
say "Copying application_mailbox.rb to app/mailboxes"
|
|
4
|
-
copy_file "#{__dir__}/mailbox/templates/application_mailbox.rb", "app/mailboxes/application_mailbox.rb"
|
|
5
|
-
|
|
6
|
-
environment <<~end_of_config, env: "production"
|
|
7
|
-
# Prepare the ingress controller used to receive mail
|
|
8
|
-
# config.action_mailbox.ingress = :relay
|
|
9
|
-
|
|
10
|
-
end_of_config
|