actionmailbox 6.0.6.1 → 6.1.7.6

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.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +58 -45
  3. data/MIT-LICENSE +1 -1
  4. data/app/controllers/action_mailbox/ingresses/mailgun/inbound_emails_controller.rb +31 -11
  5. data/app/controllers/action_mailbox/ingresses/postmark/inbound_emails_controller.rb +1 -1
  6. data/app/controllers/action_mailbox/ingresses/relay/inbound_emails_controller.rb +1 -1
  7. data/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb +16 -2
  8. data/app/controllers/rails/conductor/action_mailbox/inbound_emails/sources_controller.rb +13 -0
  9. data/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb +6 -2
  10. data/app/models/action_mailbox/inbound_email/message_id.rb +1 -1
  11. data/app/models/action_mailbox/inbound_email.rb +2 -2
  12. data/app/models/action_mailbox/record.rb +9 -0
  13. data/app/views/rails/conductor/action_mailbox/inbound_emails/index.html.erb +2 -1
  14. data/app/views/rails/conductor/action_mailbox/inbound_emails/new.html.erb +12 -7
  15. data/app/views/rails/conductor/action_mailbox/inbound_emails/sources/new.html.erb +12 -0
  16. data/config/routes.rb +3 -0
  17. data/lib/action_mailbox/gem_version.rb +3 -3
  18. data/lib/action_mailbox/mail_ext.rb +1 -1
  19. data/lib/action_mailbox/mail_with_error_handling.rb +10 -0
  20. data/lib/action_mailbox/router.rb +5 -5
  21. data/lib/action_mailbox/routing.rb +4 -0
  22. data/lib/action_mailbox/test_helper.rb +55 -7
  23. data/lib/generators/action_mailbox/install/install_generator.rb +28 -0
  24. data/lib/rails/generators/mailbox/USAGE +3 -3
  25. data/lib/tasks/install.rake +3 -17
  26. metadata +21 -17
  27. data/lib/rails/generators/installer.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d00281a6983c176229ac802d85296f5c4e4b0f5d660f40b0691bb663d670e83
4
- data.tar.gz: af54f053968f0641a2d6e6e5dae9551ba7897a03dff4abfa429cfd3628ee4109
3
+ metadata.gz: b570090bfd86e555b5122cebf8d0a47f2143a901277b6bc74a05225c4eaffa1b
4
+ data.tar.gz: 5163708ed18a936c80fb9fa3be0111e27cde6e421fc0176e88afd097df952704
5
5
  SHA512:
6
- metadata.gz: f56a3f0e48b5c34335d49523ad6f2bdeacf8cafac042c19174a504bf2065b74f66c4b086aaff96780c61032855918a3bc0b914d3434ef5ad1e714e6268d9a5c8
7
- data.tar.gz: db4dc8e66f36e674393335737d121c1746fafb0f0bde99034fad306c689d954fa394928a57d4957cde3eae606324a2879e9577598ec943b2fda268b4d185040b
6
+ metadata.gz: d97364c97debe528145cc6b5904aa4ac6b4bc1f3738069bbd7d0e5a66bec73f605ebc429cf0f647d10e5e0a0da47f5b3df8845bf92259bfe4a3020141c7f0613
7
+ data.tar.gz: 4d5bf08f3fd05d14e2493c86e6f381541d6d3efc83a38604d861e6e1427e729027902d7a3168651974977e70415ae31ac70b81f578b408af956e28932ef2c535
data/CHANGELOG.md CHANGED
@@ -1,163 +1,176 @@
1
- ## Rails 6.0.6.1 (January 17, 2023) ##
1
+ ## Rails 6.1.7.6 (August 22, 2023) ##
2
2
 
3
3
  * No changes.
4
4
 
5
5
 
6
- ## Rails 6.0.6 (September 09, 2022) ##
6
+ ## Rails 6.1.7.5 (August 22, 2023) ##
7
7
 
8
8
  * No changes.
9
9
 
10
10
 
11
- ## Rails 6.0.5.1 (July 12, 2022) ##
11
+ ## Rails 6.1.7.4 (June 26, 2023) ##
12
12
 
13
13
  * No changes.
14
14
 
15
15
 
16
- ## Rails 6.0.5 (May 09, 2022) ##
16
+ ## Rails 6.1.7.3 (March 13, 2023) ##
17
17
 
18
18
  * No changes.
19
19
 
20
20
 
21
- ## Rails 6.0.4.8 (April 26, 2022) ##
21
+ ## Rails 6.1.7.2 (January 24, 2023) ##
22
22
 
23
23
  * No changes.
24
24
 
25
25
 
26
- ## Rails 6.0.4.7 (March 08, 2022) ##
26
+ ## Rails 6.1.7.1 (January 17, 2023) ##
27
27
 
28
28
  * No changes.
29
29
 
30
30
 
31
- ## Rails 6.0.4.6 (February 11, 2022) ##
31
+ ## Rails 6.1.7 (September 09, 2022) ##
32
32
 
33
33
  * No changes.
34
34
 
35
35
 
36
- ## Rails 6.0.4.5 (February 11, 2022) ##
36
+ ## Rails 6.1.6.1 (July 12, 2022) ##
37
37
 
38
38
  * No changes.
39
39
 
40
40
 
41
- ## Rails 6.0.4.4 (December 15, 2021) ##
41
+ ## Rails 6.1.6 (May 09, 2022) ##
42
42
 
43
43
  * No changes.
44
44
 
45
45
 
46
- ## Rails 6.0.4.3 (December 14, 2021) ##
46
+ ## Rails 6.1.5.1 (April 26, 2022) ##
47
47
 
48
48
  * No changes.
49
49
 
50
50
 
51
- ## Rails 6.0.4.2 (December 14, 2021) ##
51
+ ## Rails 6.1.5 (March 09, 2022) ##
52
52
 
53
- * No changes.
53
+ * Add `attachments` to the list of permitted parameters for inbound emails conductor.
54
54
 
55
+ When using the conductor to test inbound emails with attachments, this prevents an
56
+ unpermitted parameter warning in default configurations, and prevents errors for
57
+ applications that set:
55
58
 
56
- ## Rails 6.0.4.1 (August 19, 2021) ##
59
+ ```ruby
60
+ config.action_controller.action_on_unpermitted_parameters = :raise
61
+ ```
57
62
 
58
- * No changes.
63
+ *David Jones*, *Dana Henke*
59
64
 
60
65
 
61
- ## Rails 6.0.4 (June 15, 2021) ##
66
+ ## Rails 6.1.4.7 (March 08, 2022) ##
62
67
 
63
68
  * No changes.
64
69
 
65
70
 
66
- ## Rails 6.0.3.7 (May 05, 2021) ##
71
+ ## Rails 6.1.4.6 (February 11, 2022) ##
67
72
 
68
73
  * No changes.
69
74
 
70
75
 
71
- ## Rails 6.0.3.6 (March 26, 2021) ##
76
+ ## Rails 6.1.4.5 (February 11, 2022) ##
72
77
 
73
78
  * No changes.
74
79
 
75
80
 
76
- ## Rails 6.0.3.5 (February 10, 2021) ##
81
+ ## Rails 6.1.4.4 (December 15, 2021) ##
77
82
 
78
83
  * No changes.
79
84
 
80
85
 
81
- ## Rails 6.0.3.4 (October 07, 2020) ##
86
+ ## Rails 6.1.4.3 (December 14, 2021) ##
82
87
 
83
88
  * No changes.
84
89
 
85
90
 
86
- ## Rails 6.0.3.3 (September 09, 2020) ##
91
+ ## Rails 6.1.4.2 (December 14, 2021) ##
87
92
 
88
93
  * No changes.
89
94
 
90
95
 
91
- ## Rails 6.0.3.2 (June 17, 2020) ##
96
+ ## Rails 6.1.4.1 (August 19, 2021) ##
92
97
 
93
98
  * No changes.
94
99
 
95
100
 
96
- ## Rails 6.0.3.1 (May 18, 2020) ##
101
+ ## Rails 6.1.4 (June 24, 2021) ##
97
102
 
98
103
  * No changes.
99
104
 
100
105
 
101
- ## Rails 6.0.3 (May 06, 2020) ##
106
+ ## Rails 6.1.3.2 (May 05, 2021) ##
102
107
 
103
- * Update Mandrill inbound email route to respond appropriately to HEAD requests for URL health checks from Mandrill.
108
+ * No changes.
104
109
 
105
- *Bill Cromie*
106
110
 
111
+ ## Rails 6.1.3.1 (March 26, 2021) ##
107
112
 
108
- ## Rails 6.0.2.2 (March 19, 2020) ##
113
+ * No changes.
114
+
115
+
116
+ ## Rails 6.1.3 (February 17, 2021) ##
109
117
 
110
118
  * No changes.
111
119
 
112
120
 
113
- ## Rails 6.0.2.1 (December 18, 2019) ##
121
+ ## Rails 6.1.2.1 (February 10, 2021) ##
114
122
 
115
123
  * No changes.
116
124
 
117
125
 
118
- ## Rails 6.0.2 (December 13, 2019) ##
126
+ ## Rails 6.1.2 (February 09, 2021) ##
119
127
 
120
128
  * No changes.
121
129
 
122
130
 
123
- ## Rails 6.0.1 (November 5, 2019) ##
131
+ ## Rails 6.1.1 (January 07, 2021) ##
124
132
 
125
133
  * No changes.
126
134
 
127
135
 
128
- ## Rails 6.0.0 (August 16, 2019) ##
136
+ ## Rails 6.1.0 (December 09, 2020) ##
129
137
 
130
- * Fix Bcc header not being included with emails from `create_inbound_email_from` test helpers.
138
+ * Change default queue name of the incineration (`:action_mailbox_incineration`) and
139
+ routing (`:action_mailbox_routing`) jobs to be the job adapter's default (`:default`).
131
140
 
132
- *jduff*
141
+ *Rafael Mendonça França*
133
142
 
143
+ * Sendgrid ingress now passes through the envelope recipient as `X-Original-To`.
134
144
 
135
- ## Rails 6.0.0.rc2 (July 22, 2019) ##
145
+ *Mark Haussmann*
136
146
 
137
- * No changes.
147
+ * Update Mandrill inbound email route to respond appropriately to HEAD requests for URL health checks from Mandrill.
138
148
 
149
+ *Bill Cromie*
139
150
 
140
- ## Rails 6.0.0.rc1 (April 24, 2019) ##
151
+ * Add way to deliver emails via source instead of filling out a form through the conductor interface.
141
152
 
142
- * No changes.
153
+ *DHH*
143
154
 
155
+ * Mailgun ingress now passes through the envelope recipient as `X-Original-To`.
144
156
 
145
- ## Rails 6.0.0.beta3 (March 11, 2019) ##
157
+ *Rikki Pitt*
146
158
 
147
- * No changes.
159
+ * 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`.
148
160
 
161
+ *Matthijs Vos*
149
162
 
150
- ## Rails 6.0.0.beta2 (February 25, 2019) ##
163
+ * Allow easier creation of multi-part emails from the `create_inbound_email_from_mail` and `receive_inbound_email_from_mail` test helpers.
151
164
 
152
- * Allow skipping incineration of processed emails.
165
+ *Michael Herold*
153
166
 
154
- This can be done by setting `config.action_mailbox.incinerate` to `false`.
167
+ * Fix Bcc header not being included with emails from `create_inbound_email_from` test helpers.
155
168
 
156
- *Pratik Naik*
169
+ *jduff*
157
170
 
171
+ * Add `ApplicationMailbox.mailbox_for` to expose mailbox routing.
158
172
 
159
- ## Rails 6.0.0.beta1 (January 18, 2019) ##
173
+ *James Dabbs*
160
174
 
161
- * Added to Rails.
162
175
 
163
- *DHH*
176
+ Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/actionmailbox/CHANGELOG.md) for previous changes.
data/MIT-LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 Basecamp, LLC
3
+ Copyright (c) 2018-2022 Basecamp, LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -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 API key
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 API key is missing, or one of the Active Record database,
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 {Mailgun API key}[https://help.mailgun.com/hc/en-us/articles/203380100-Where-can-I-find-my-API-key-and-SMTP-credentials-]
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 API key to your application's encrypted credentials under
28
- # +action_mailbox.mailgun_api_key+, where Action Mailbox will automatically find it:
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
- # mailgun_api_key: ...
31
+ # mailgun_signing_key: ...
32
32
  #
33
- # Alternatively, provide your API key in the +MAILGUN_INGRESS_API_KEY+ environment variable.
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! params.require("body-mime")
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 API key. Set action_mailbox.mailgun_api_key in your application's
68
- encrypted credentials or provide the MAILGUN_INGRESS_API_KEY environment variable.
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) || ENV["MAILGUN_INGRESS_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 7.0.
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 7.0.
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! params.require(:email)
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,14 +20,18 @@ 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(mail_params.except(:attachments).to_h).tap do |mail|
24
24
  mail[:bcc]&.include_in_headers = true
25
- params[:mail][:attachments].to_a.each do |attachment|
25
+ mail_params[:attachments].to_a.each do |attachment|
26
26
  mail.add_file(filename: attachment.original_filename, content: attachment.read)
27
27
  end
28
28
  end
29
29
  end
30
30
 
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
+
31
35
  def create_inbound_email(mail)
32
36
  ActionMailbox::InboundEmail.create_and_extract_message_id!(mail.to_s)
33
37
  end
@@ -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 be uploaded as a Active Storage
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)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "mail"
3
+ require "action_mailbox/mail_with_error_handling"
4
4
 
5
5
  module ActionMailbox
6
6
  # The +InboundEmail+ is an Active Record that keeps a reference to the raw email stored in Active Storage
@@ -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 < ActiveRecord::Base
27
+ class InboundEmail < Record
28
28
  self.table_name = "action_mailbox_inbound_emails"
29
29
 
30
30
  include Incineratable, MessageId, Routable
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionMailbox
4
+ class Record < ActiveRecord::Base #:nodoc:
5
+ self.abstract_class = true
6
+ end
7
+ end
8
+
9
+ ActiveSupport.run_load_hooks :action_mailbox_record, ActionMailbox::Record
@@ -12,4 +12,5 @@
12
12
  <% end %>
13
13
  </table>
14
14
 
15
- <%= link_to "Deliver new inbound email", main_app.new_rails_conductor_inbound_email_path %>
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
@@ -8,9 +8,9 @@ module ActionMailbox
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 6
11
- MINOR = 0
12
- TINY = 6
13
- PRE = "1"
11
+ MINOR = 1
12
+ TINY = 7
13
+ PRE = "6"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "mail"
3
+ require "action_mailbox/mail_with_error_handling"
4
4
 
5
5
  # The hope is to upstream most of these basic additions to the Mail gem's Mail object. But until then, here they lay!
6
6
  Dir["#{File.expand_path(File.dirname(__FILE__))}/mail_ext/*"].each { |path| require "action_mailbox/mail_ext/#{File.basename(path)}" }
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "mail"
5
+ rescue LoadError => error
6
+ if error.message.match?(/net\/smtp/)
7
+ $stderr.puts "You don't have net-smtp installed in your application. Please add it to your Gemfile and run bundle install"
8
+ raise
9
+ end
10
+ end
@@ -21,7 +21,7 @@ module ActionMailbox
21
21
  end
22
22
 
23
23
  def route(inbound_email)
24
- if mailbox = match_to_mailbox(inbound_email)
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
 
@@ -17,6 +17,10 @@ module ActionMailbox
17
17
  def route(inbound_email)
18
18
  router.route(inbound_email)
19
19
  end
20
+
21
+ def mailbox_for(inbound_email)
22
+ router.mailbox_for(inbound_email)
23
+ end
20
24
  end
21
25
  end
22
26
  end
@@ -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
- # Create an +InboundEmail+ by specifying it using +Mail.new+ options. Example:
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
- def create_inbound_email_from_mail(status: :processing, **mail_options)
17
- mail = Mail.new(mail_options)
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 arguments as +create_inbound_email_from_mail+ and immediately route it to
37
- # processing.
38
- def receive_inbound_email_from_mail(**kwargs)
39
- create_inbound_email_from_mail(**kwargs).tap(&:route)
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
- Stubs out a new mailbox class in app/mailboxes and invokes your template
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 a InboxMailbox class and test:
10
+ creates an InboxMailbox class and test:
11
11
  Mailbox: app/mailboxes/inbox_mailbox.rb
12
12
  Test: test/mailboxes/inbox_mailbox_test.rb
@@ -1,20 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- namespace :action_mailbox do
4
- # Prevent migration installation task from showing up twice.
5
- Rake::Task["install:migrations"].clear_comments
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.0.6.1
4
+ version: 6.1.7.6
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: 2023-01-17 00:00:00.000000000 Z
12
+ date: 2023-08-22 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.0.6.1
20
+ version: 6.1.7.6
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.0.6.1
27
+ version: 6.1.7.6
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.0.6.1
34
+ version: 6.1.7.6
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.0.6.1
41
+ version: 6.1.7.6
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.0.6.1
48
+ version: 6.1.7.6
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.0.6.1
55
+ version: 6.1.7.6
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.0.6.1
62
+ version: 6.1.7.6
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.0.6.1
69
+ version: 6.1.7.6
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.0.6.1
76
+ version: 6.1.7.6
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.0.6.1
83
+ version: 6.1.7.6
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
@@ -139,6 +142,7 @@ files:
139
142
  - lib/action_mailbox/mail_ext/addresses.rb
140
143
  - lib/action_mailbox/mail_ext/from_source.rb
141
144
  - lib/action_mailbox/mail_ext/recipients.rb
145
+ - lib/action_mailbox/mail_with_error_handling.rb
142
146
  - lib/action_mailbox/relayer.rb
143
147
  - lib/action_mailbox/router.rb
144
148
  - lib/action_mailbox/router/route.rb
@@ -146,7 +150,7 @@ files:
146
150
  - lib/action_mailbox/test_case.rb
147
151
  - lib/action_mailbox/test_helper.rb
148
152
  - lib/action_mailbox/version.rb
149
- - lib/rails/generators/installer.rb
153
+ - lib/generators/action_mailbox/install/install_generator.rb
150
154
  - lib/rails/generators/mailbox/USAGE
151
155
  - lib/rails/generators/mailbox/mailbox_generator.rb
152
156
  - lib/rails/generators/mailbox/templates/application_mailbox.rb.tt
@@ -160,10 +164,10 @@ licenses:
160
164
  - MIT
161
165
  metadata:
162
166
  bug_tracker_uri: https://github.com/rails/rails/issues
163
- changelog_uri: https://github.com/rails/rails/blob/v6.0.6.1/actionmailbox/CHANGELOG.md
164
- documentation_uri: https://api.rubyonrails.org/v6.0.6.1/
167
+ changelog_uri: https://github.com/rails/rails/blob/v6.1.7.6/actionmailbox/CHANGELOG.md
168
+ documentation_uri: https://api.rubyonrails.org/v6.1.7.6/
165
169
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
166
- source_code_uri: https://github.com/rails/rails/tree/v6.0.6.1/actionmailbox
170
+ source_code_uri: https://github.com/rails/rails/tree/v6.1.7.6/actionmailbox
167
171
  rubygems_mfa_required: 'true'
168
172
  post_install_message:
169
173
  rdoc_options: []
@@ -180,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
184
  - !ruby/object:Gem::Version
181
185
  version: '0'
182
186
  requirements: []
183
- rubygems_version: 3.4.3
187
+ rubygems_version: 3.3.3
184
188
  signing_key:
185
189
  specification_version: 4
186
190
  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