aws-actionmailbox-ses 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE +175 -0
- data/VERSION +1 -0
- data/app/controllers/action_mailbox/ingresses/ses/inbound_emails_controller.rb +79 -0
- data/config/routes.rb +7 -0
- data/lib/aws/action_mailbox/ses/engine.rb +21 -0
- data/lib/aws/action_mailbox/ses/rspec/email.rb +50 -0
- data/lib/aws/action_mailbox/ses/rspec/subscription_confirmation.rb +37 -0
- data/lib/aws/action_mailbox/ses/rspec.rb +70 -0
- data/lib/aws/action_mailbox/ses/s3_client.rb +28 -0
- data/lib/aws/action_mailbox/ses/sns_message_verifier.rb +18 -0
- data/lib/aws/action_mailbox/ses/sns_notification.rb +95 -0
- data/lib/aws-actionmailbox-ses.rb +14 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e479e69925ae410b04c11a78682c20190c820df0eab90a95b7044affad760d2b
|
4
|
+
data.tar.gz: 482a6e144f2def8dcbcca8312afc334488d12aaafea95ea22b3c4daf19db15ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f050f92ca327417764e4c8cd5819578662c148659180883680996c5fc2c63837f210e4742bb44f99a69f237a5995b58ce10debc7843a857b0f8c1dfd0c646fc3
|
7
|
+
data.tar.gz: 1e4598eabdd771eb50b2e5da42282fb7df9861ea88a685be8237c4625c9ebead1cd1025dbdf1769e8e09c76e8d2a4d972c529c45210fa9e8dab4829a22908627
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionMailbox
|
4
|
+
module Ingresses
|
5
|
+
module Ses
|
6
|
+
# Ingests inbound emails from Amazon SES/SNS and confirms subscriptions.
|
7
|
+
#
|
8
|
+
# Subscription requests must provide the following parameters in a JSON body:
|
9
|
+
#
|
10
|
+
# - +Message+: Notification content
|
11
|
+
# - +MessageId+: Notification unique identifier
|
12
|
+
# - +Timestamp+: iso8601 timestamp
|
13
|
+
# - +TopicArn+: Topic identifier
|
14
|
+
# - +Type+: Type of event ("Subscription")
|
15
|
+
#
|
16
|
+
# Inbound email events must provide the following parameters in a JSON body:
|
17
|
+
#
|
18
|
+
# - +Message+: Notification content
|
19
|
+
# - +MessageId+: Notification unique identifier
|
20
|
+
# - +Timestamp+: iso8601 timestamp
|
21
|
+
# - +SubscribeURL+: Topic identifier
|
22
|
+
# - +TopicArn+: Topic identifier
|
23
|
+
# - +Type+: Type of event ("SubscriptionConfirmation")
|
24
|
+
#
|
25
|
+
# All requests are authenticated by validating the provided AWS signature.
|
26
|
+
#
|
27
|
+
# Returns:
|
28
|
+
#
|
29
|
+
# - <tt>204 No Content</tt> if a request is successfully processed
|
30
|
+
# - <tt>401 Unauthorized</tt> if a request does not contain a valid signature
|
31
|
+
# - <tt>404 Not Found</tt> if the Amazon ingress has not been configured
|
32
|
+
# - <tt>422 Unprocessable Entity</tt> if a request provides invalid parameters
|
33
|
+
class InboundEmailsController < ActionMailbox::BaseController
|
34
|
+
before_action :verify_authenticity, :validate_topic, :confirm_subscription
|
35
|
+
|
36
|
+
def create
|
37
|
+
head :bad_request unless notification.message_content.present?
|
38
|
+
|
39
|
+
ActionMailbox::InboundEmail.create_and_extract_message_id!(notification.message_content)
|
40
|
+
head :no_content
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def verify_authenticity
|
46
|
+
head :bad_request unless notification.present?
|
47
|
+
head :unauthorized unless notification.verified?
|
48
|
+
end
|
49
|
+
|
50
|
+
def confirm_subscription
|
51
|
+
return unless notification.type == 'SubscriptionConfirmation'
|
52
|
+
return head :ok if notification.subscription_confirmed?
|
53
|
+
|
54
|
+
Rails.logger.error('SNS subscription confirmation request rejected.')
|
55
|
+
head :unprocessable_entity
|
56
|
+
end
|
57
|
+
|
58
|
+
def validate_topic
|
59
|
+
return if valid_topic == notification.topic
|
60
|
+
|
61
|
+
Rails.logger.warn("Ignoring unknown topic: #{topic}")
|
62
|
+
head :unauthorized
|
63
|
+
end
|
64
|
+
|
65
|
+
def notification
|
66
|
+
@notification ||= Aws::ActionMailbox::SES::SNSNotification.new(request.raw_post)
|
67
|
+
end
|
68
|
+
|
69
|
+
def topic
|
70
|
+
@topic ||= notification.topic
|
71
|
+
end
|
72
|
+
|
73
|
+
def valid_topic
|
74
|
+
::Rails.configuration.action_mailbox.ses.subscribed_topic
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'action_mailbox/engine'
|
4
|
+
|
5
|
+
module Aws
|
6
|
+
module ActionMailbox
|
7
|
+
module SES
|
8
|
+
# @api private
|
9
|
+
class Engine < ::Rails::Engine
|
10
|
+
config.action_mailbox.ses = ActiveSupport::OrderedOptions.new
|
11
|
+
config.action_mailbox.ses.s3_client_options ||= {}
|
12
|
+
|
13
|
+
initializer 'aws-sdk-rails.mount_engine' do |app|
|
14
|
+
app.routes.append do
|
15
|
+
mount Engine => '/'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module ActionMailbox
|
5
|
+
module SES
|
6
|
+
module RSpec
|
7
|
+
# @api private
|
8
|
+
class Email
|
9
|
+
def initialize(authentic: true, topic: 'topic:arn:default', mail: default_mail, message_params: {})
|
10
|
+
@authentic = authentic
|
11
|
+
@topic = topic
|
12
|
+
@mail = mail
|
13
|
+
@message_params = message_params
|
14
|
+
end
|
15
|
+
|
16
|
+
def headers
|
17
|
+
{ 'content-type' => 'application/json' }
|
18
|
+
end
|
19
|
+
|
20
|
+
def url
|
21
|
+
'/rails/action_mailbox/ses/inbound_emails'
|
22
|
+
end
|
23
|
+
|
24
|
+
def params
|
25
|
+
{
|
26
|
+
'Type' => 'Notification',
|
27
|
+
'TopicArn' => @topic,
|
28
|
+
'Message' => message_json
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def message_json
|
33
|
+
{
|
34
|
+
'notificationType' => 'Received',
|
35
|
+
'content' => @mail.encoded
|
36
|
+
}.merge(@message_params).to_json
|
37
|
+
end
|
38
|
+
|
39
|
+
def authentic?
|
40
|
+
@authentic
|
41
|
+
end
|
42
|
+
|
43
|
+
def default_mail
|
44
|
+
Mail.new
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module ActionMailbox
|
5
|
+
module SES
|
6
|
+
module RSpec
|
7
|
+
# @api private
|
8
|
+
class SubscriptionConfirmation
|
9
|
+
def initialize(authentic: true, topic: 'topic:arn:default')
|
10
|
+
@authentic = authentic
|
11
|
+
@topic = topic
|
12
|
+
end
|
13
|
+
|
14
|
+
def url
|
15
|
+
'/rails/action_mailbox/ses/inbound_emails'
|
16
|
+
end
|
17
|
+
|
18
|
+
def headers
|
19
|
+
{ 'content-type' => 'application/json' }
|
20
|
+
end
|
21
|
+
|
22
|
+
def params
|
23
|
+
{
|
24
|
+
'Type' => 'SubscriptionConfirmation',
|
25
|
+
'TopicArn' => @topic,
|
26
|
+
'SubscribeURL' => 'http://example.com/subscribe'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def authentic?
|
31
|
+
@authentic
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'rspec/email'
|
4
|
+
require_relative 'rspec/subscription_confirmation'
|
5
|
+
|
6
|
+
module Aws
|
7
|
+
module ActionMailbox
|
8
|
+
module SES
|
9
|
+
# RSpec extension for testing Amazon SES notifications. Include the
|
10
|
+
# `Aws::ActionMailbox::SES::RSpec` extension in your tests, like so:
|
11
|
+
#
|
12
|
+
# require 'aws/rails/action_mailbox/rspec'
|
13
|
+
# RSpec.configure do |config|
|
14
|
+
# config.include Aws::ActionMailbox::SES::RSpec
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
module RSpec
|
18
|
+
# Stubs the AWS SNS message verifier and delivers a subscription confirmation.
|
19
|
+
# @example
|
20
|
+
# it 'delivers a subscription notification' do
|
21
|
+
# action_mailbox_ses_deliver_subscription_confirmation
|
22
|
+
# expect(response).to have_http_status :ok
|
23
|
+
# end
|
24
|
+
def action_mailbox_ses_deliver_subscription_confirmation(options = {})
|
25
|
+
subscription_confirmation = SubscriptionConfirmation.new(**options)
|
26
|
+
stub_aws_sns_message_verifier(subscription_confirmation)
|
27
|
+
stub_aws_sns_subscription_request
|
28
|
+
|
29
|
+
post subscription_confirmation.url,
|
30
|
+
params: subscription_confirmation.params,
|
31
|
+
headers: subscription_confirmation.headers,
|
32
|
+
as: :json
|
33
|
+
end
|
34
|
+
|
35
|
+
# Stubs the AWS SNS message verifier and delivers an email.
|
36
|
+
# @example
|
37
|
+
# it 'delivers an email notification' do
|
38
|
+
# action_mailbox_ses_deliver_email(mail: Mail.new(to: 'user@example.com'))
|
39
|
+
# expect(ActionMailbox::InboundEmail.last.mail.recipients).to eql ['user@example.com']
|
40
|
+
# end
|
41
|
+
def action_mailbox_ses_deliver_email(options = {})
|
42
|
+
email = Email.new(**options)
|
43
|
+
stub_aws_sns_message_verifier(email)
|
44
|
+
|
45
|
+
post email.url,
|
46
|
+
params: email.params,
|
47
|
+
headers: email.headers,
|
48
|
+
as: :json
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def message_verifier(subscription_confirmation)
|
54
|
+
instance_double(Aws::SNS::MessageVerifier, authentic?: subscription_confirmation.authentic?)
|
55
|
+
end
|
56
|
+
|
57
|
+
def stub_aws_sns_message_verifier(notification)
|
58
|
+
allow(Aws::ActionMailbox::SES::SNSMessageVerifier).to receive(:verifier) { message_verifier(notification) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def stub_aws_sns_subscription_request
|
62
|
+
allow(Net::HTTP).to receive(:get_response).and_call_original
|
63
|
+
allow(Net::HTTP)
|
64
|
+
.to receive(:get_response)
|
65
|
+
.with(URI('http://example.com/subscribe')) { double(code: '200') }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aws-sdk-s3'
|
4
|
+
|
5
|
+
module Aws
|
6
|
+
module ActionMailbox
|
7
|
+
module SES
|
8
|
+
# @api private
|
9
|
+
class S3Client
|
10
|
+
class << self
|
11
|
+
def client
|
12
|
+
@client ||= build_client
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_client
|
18
|
+
client = Aws::S3::Client.new(
|
19
|
+
**::Rails.configuration.action_mailbox.ses.s3_client_options
|
20
|
+
)
|
21
|
+
client.config.user_agent_frameworks << 'aws-actionmailbox-ses'
|
22
|
+
client
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aws-sdk-sns'
|
4
|
+
|
5
|
+
module Aws
|
6
|
+
module ActionMailbox
|
7
|
+
module SES
|
8
|
+
# @api private
|
9
|
+
class SNSMessageVerifier
|
10
|
+
class << self
|
11
|
+
def verifier
|
12
|
+
@verifier ||= Aws::SNS::MessageVerifier.new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module ActionMailbox
|
5
|
+
module SES
|
6
|
+
# @api private
|
7
|
+
class SNSNotification
|
8
|
+
class MessageContentError < StandardError; end
|
9
|
+
|
10
|
+
def initialize(request_body)
|
11
|
+
@request_body = request_body
|
12
|
+
end
|
13
|
+
|
14
|
+
def subscription_confirmed?
|
15
|
+
(200..299).cover?(confirmation_response.code.to_i)
|
16
|
+
end
|
17
|
+
|
18
|
+
def verified?
|
19
|
+
SNSMessageVerifier.verifier.authentic?(@request_body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def topic
|
23
|
+
notification.fetch(:TopicArn)
|
24
|
+
end
|
25
|
+
|
26
|
+
def type
|
27
|
+
notification.fetch(:Type)
|
28
|
+
end
|
29
|
+
|
30
|
+
def message_content
|
31
|
+
raise MessageContentError, 'Incoming emails must have notificationType `Received`' unless receipt?
|
32
|
+
|
33
|
+
if content_in_s3?
|
34
|
+
s3_content
|
35
|
+
else
|
36
|
+
return message[:content] unless destination
|
37
|
+
|
38
|
+
"X-Original-To: #{destination}\n#{message[:content]}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def notification
|
45
|
+
@notification ||= JSON.parse(@request_body, symbolize_names: true)
|
46
|
+
rescue JSON::ParserError => e
|
47
|
+
Rails.logger.warn("Unable to parse SNS notification: #{e}")
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def s3_content
|
52
|
+
S3Client
|
53
|
+
.client
|
54
|
+
.get_object(key: key, bucket: bucket)
|
55
|
+
.body
|
56
|
+
.string
|
57
|
+
end
|
58
|
+
|
59
|
+
def message
|
60
|
+
@message ||= JSON.parse(notification[:Message], symbolize_names: true)
|
61
|
+
end
|
62
|
+
|
63
|
+
def destination
|
64
|
+
message.dig(:mail, :destination)&.first
|
65
|
+
end
|
66
|
+
|
67
|
+
def action
|
68
|
+
return unless message[:receipt]
|
69
|
+
|
70
|
+
message.fetch(:receipt).fetch(:action)
|
71
|
+
end
|
72
|
+
|
73
|
+
def bucket
|
74
|
+
action.fetch(:bucketName)
|
75
|
+
end
|
76
|
+
|
77
|
+
def key
|
78
|
+
action.fetch(:objectKey)
|
79
|
+
end
|
80
|
+
|
81
|
+
def content_in_s3?
|
82
|
+
action&.fetch(:type) == 'S3'
|
83
|
+
end
|
84
|
+
|
85
|
+
def receipt?
|
86
|
+
message.fetch(:notificationType) == 'Received'
|
87
|
+
end
|
88
|
+
|
89
|
+
def confirmation_response
|
90
|
+
@confirmation_response ||= Net::HTTP.get_response(URI(notification[:SubscribeURL]))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'aws/action_mailbox/ses/engine'
|
4
|
+
require_relative 'aws/action_mailbox/ses/s3_client'
|
5
|
+
require_relative 'aws/action_mailbox/ses/sns_message_verifier'
|
6
|
+
require_relative 'aws/action_mailbox/ses/sns_notification'
|
7
|
+
|
8
|
+
module Aws
|
9
|
+
module ActionMailbox
|
10
|
+
module SES
|
11
|
+
VERSION = File.read(File.expand_path('../VERSION', __dir__)).strip
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws-actionmailbox-ses
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Amazon Web Services
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-11-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-s3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.123.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.123.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: aws-sdk-sns
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.61.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.61.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: actionmailbox
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 7.1.0
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 7.1.0
|
67
|
+
description: Amazon Simple Email Service as an ActionMailbox router
|
68
|
+
email:
|
69
|
+
- aws-dr-rubygems@amazon.com
|
70
|
+
executables: []
|
71
|
+
extensions: []
|
72
|
+
extra_rdoc_files: []
|
73
|
+
files:
|
74
|
+
- CHANGELOG.md
|
75
|
+
- LICENSE
|
76
|
+
- VERSION
|
77
|
+
- app/controllers/action_mailbox/ingresses/ses/inbound_emails_controller.rb
|
78
|
+
- config/routes.rb
|
79
|
+
- lib/aws-actionmailbox-ses.rb
|
80
|
+
- lib/aws/action_mailbox/ses/engine.rb
|
81
|
+
- lib/aws/action_mailbox/ses/rspec.rb
|
82
|
+
- lib/aws/action_mailbox/ses/rspec/email.rb
|
83
|
+
- lib/aws/action_mailbox/ses/rspec/subscription_confirmation.rb
|
84
|
+
- lib/aws/action_mailbox/ses/s3_client.rb
|
85
|
+
- lib/aws/action_mailbox/ses/sns_message_verifier.rb
|
86
|
+
- lib/aws/action_mailbox/ses/sns_notification.rb
|
87
|
+
homepage: https://github.com/aws/aws-actionmailbox-ses-ruby
|
88
|
+
licenses:
|
89
|
+
- Apache-2.0
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '2.7'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubygems_version: 3.5.11
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: ActionMailbox integration with SES
|
110
|
+
test_files: []
|