postageapp 1.2.5 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +10 -30
  4. data/{LICENSE → LICENSE.md} +1 -1
  5. data/README.md +118 -68
  6. data/Rakefile +15 -4
  7. data/VERSION +1 -0
  8. data/app/ingresses/action_mailbox/ingresses/postage_app.rb +2 -0
  9. data/app/ingresses/action_mailbox/ingresses/postage_app/inbound_emails_controller.rb +50 -0
  10. data/config/routes.rb +6 -0
  11. data/doc/RAILS2.md +54 -0
  12. data/doc/RAILS3.md +15 -0
  13. data/exe/postageapp +37 -0
  14. data/generators/postageapp/templates/postageapp_tasks.rake +25 -8
  15. data/lib/generators/postageapp/postageapp_generator.rb +9 -6
  16. data/lib/postageapp.rb +59 -30
  17. data/lib/postageapp/cli.rb +14 -0
  18. data/lib/postageapp/cli/command.rb +110 -0
  19. data/lib/postageapp/cli/command/config.rb +74 -0
  20. data/lib/postageapp/cli/command/create_mailbox.rb +21 -0
  21. data/lib/postageapp/cli/command/env.rb +58 -0
  22. data/lib/postageapp/cli/command/get_project_info.rb +3 -0
  23. data/lib/postageapp/configuration.rb +267 -63
  24. data/lib/postageapp/diagnostics.rb +30 -0
  25. data/lib/postageapp/engine.rb +9 -0
  26. data/lib/postageapp/env.rb +9 -0
  27. data/lib/postageapp/failed_request.rb +2 -0
  28. data/lib/postageapp/http.rb +32 -0
  29. data/lib/postageapp/logger.rb +2 -0
  30. data/lib/postageapp/mail.rb +1 -1
  31. data/lib/postageapp/mailer.rb +2 -11
  32. data/lib/postageapp/mailer/mailer_4.rb +29 -15
  33. data/lib/postageapp/rails/railtie.rb +1 -3
  34. data/lib/postageapp/request.rb +27 -11
  35. data/lib/postageapp/response.rb +22 -8
  36. data/lib/postageapp/utils.rb +0 -11
  37. data/log/.gitignore +1 -0
  38. data/postageapp.gemspec +16 -17
  39. data/script/with +3 -3
  40. data/test/gemfiles/Gemfile.rails-2.3.x +1 -1
  41. data/test/gemfiles/Gemfile.rails-3.0.x +1 -1
  42. data/test/gemfiles/Gemfile.rails-3.1.x +1 -1
  43. data/test/gemfiles/Gemfile.rails-3.2.x +1 -1
  44. data/test/gemfiles/Gemfile.rails-4.0.x +1 -1
  45. data/test/gemfiles/Gemfile.rails-4.1.x +1 -1
  46. data/test/gemfiles/Gemfile.rails-4.2.x +1 -2
  47. data/test/gemfiles/Gemfile.rails-5.0.x +12 -0
  48. data/test/gemfiles/Gemfile.rails-5.2.x +12 -0
  49. data/test/gemfiles/Gemfile.rails-6.0.x +12 -0
  50. data/test/gemfiles/Gemfile.rails-6.1.x +12 -0
  51. data/test/gemfiles/Gemfile.ruby +2 -3
  52. data/test/helper.rb +6 -17
  53. data/test/log/.gitignore +1 -0
  54. data/test/mailer/action_mailer_3/notifier.rb +10 -10
  55. data/test/tmp/.gitignore +1 -0
  56. data/test/travis_test.rb +58 -40
  57. data/test/{configuration_test.rb → unit/configuration_test.rb} +35 -22
  58. data/test/{failed_request_test.rb → unit/failed_request_test.rb} +6 -6
  59. data/test/{live_test.rb → unit/live_test.rb} +33 -43
  60. data/test/{mail_delivery_method_test.rb → unit/mail_delivery_method_test.rb} +1 -1
  61. data/test/{mailer_4_test.rb → unit/mailer_4_test.rb} +2 -2
  62. data/test/{mailer_helper_methods_test.rb → unit/mailer_helper_methods_test.rb} +4 -4
  63. data/test/{postageapp_test.rb → unit/postageapp_test.rb} +10 -1
  64. data/test/{rails_initialization_test.rb → unit/rails_initialization_test.rb} +2 -2
  65. data/test/{request_test.rb → unit/request_test.rb} +24 -23
  66. data/test/{response_test.rb → unit/response_test.rb} +4 -4
  67. data/test/unit/tmp/.gitignore +1 -0
  68. data/tmp/.gitignore +1 -0
  69. metadata +60 -68
  70. data/lib/postageapp/mailer/mailer_2.rb +0 -140
  71. data/lib/postageapp/mailer/mailer_3.rb +0 -190
  72. data/lib/postageapp/version.rb +0 -3
  73. data/test/mailer/action_mailer_2/notifier.rb +0 -76
  74. data/test/mailer/action_mailer_2/notifier/with_body_and_attachment.erb +0 -1
  75. data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.html.erb +0 -1
  76. data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.plain.erb +0 -1
  77. data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.html.erb +0 -1
  78. data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.plain.erb +0 -1
  79. data/test/mailer/action_mailer_2/notifier/with_simple_view.erb +0 -1
  80. data/test/mailer/action_mailer_2/notifier/with_text_only_view.text.plain.erb +0 -1
  81. data/test/mailer_2_test.rb +0 -95
  82. data/test/mailer_3_test.rb +0 -118
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b142c061512b3ef0ff5d1d18d436de9796b772793e6ed10d1267d506c0577d54
4
+ data.tar.gz: 1f028542353d6cb55ca037f431a68ee1f2820833cc7bce8b5b5fd72f46345365
5
+ SHA512:
6
+ metadata.gz: 615475381e51dfbdb59e6966381e9c09f95c76e2d625c3983c5fbe7955765f42e85ecd76e3e4a2249bd55638ab70a3bd5153e7715fcf6ed2b0607e108ead503e
7
+ data.tar.gz: 295a8585e182f43e92447188eed75af8f447083d7c0186076a2f425eed22f86a36d7788974095f49ab0a4807191c4d743113d6c25eaa5efe1b65f70cf1aefa28
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ /.bundle
2
+
1
3
  .DS_Store
2
4
  coverage
3
5
  rdoc
@@ -8,3 +10,7 @@ test/gemfiles/*.lock
8
10
  Gemfile.lock
9
11
  .ruby-version
10
12
  *.gem
13
+
14
+ .env
15
+
16
+ .vscode
data/.travis.yml CHANGED
@@ -3,35 +3,15 @@ before_install: "WITH_VERBOSE=1 script/with current bootstrap"
3
3
  install: "WITH_VERBOSE=1 script/with current bundle install"
4
4
  script: "WITH_VERBOSE=1 script/with current bundle exec rake test"
5
5
  rvm:
6
- - 1.9.3-p551
7
- - 2.0.0-p598
8
- - 2.1.5
9
- - 2.2.0
10
- - 2.3.0
6
+ - 2.5.9
7
+ - 2.6.7
8
+ - 2.7.3
9
+ - 3.0.1
10
+ - jruby-9.1.17.0
11
+ - jruby-9.2.17.0
11
12
  gemfile:
12
13
  - test/gemfiles/Gemfile.ruby
13
- - test/gemfiles/Gemfile.rails-2.3.x
14
- - test/gemfiles/Gemfile.rails-3.0.x
15
- - test/gemfiles/Gemfile.rails-3.1.x
16
- - test/gemfiles/Gemfile.rails-3.2.x
17
- - test/gemfiles/Gemfile.rails-4.0.x
18
- - test/gemfiles/Gemfile.rails-4.1.x
19
- - test/gemfiles/Gemfile.rails-4.2.x
20
- matrix:
21
- exclude:
22
- - rvm: 2.0.0-p598
23
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
24
- - rvm: 2.1.5
25
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
26
- - rvm: 2.2.0
27
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
28
- - rvm: 2.3.0
29
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
30
- - rvm: 1.9.3-p551
31
- gemfile: test/gemfiles/Gemfile.rails-2.3.x
32
- - rvm: 1.9.3-p551
33
- gemfile: test/gemfiles/Gemfile.rails-4.0.x
34
- - rvm: 1.9.3-p551
35
- gemfile: test/gemfiles/Gemfile.rails-4.1.x
36
- - rvm: 1.9.3-p551
37
- gemfile: test/gemfiles/Gemfile.rails-4.2.x
14
+ - test/gemfiles/Gemfile.rails-5.0.x
15
+ - test/gemfiles/Gemfile.rails-5.2.x
16
+ - test/gemfiles/Gemfile.rails-6.0.x
17
+ - test/gemfiles/Gemfile.rails-6.1.x
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2015 Scott Tadman, Oleg Khabarov, The Working Group, Inc
1
+ Copyright (c) 2011-2019 Scott Tadman, Oleg Khabarov, PostageApp Ltd.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
- # [PostageApp](http://postageapp.com) Ruby Gem [![Build Status](https://secure.travis-ci.org/postageapp/postageapp-ruby.png)](http://travis-ci.org/postageapp/postageapp-ruby)
1
+ # [PostageApp](https://postageapp.com/) Ruby Gem [![Build Status](https://secure.travis-ci.org/postageapp/postageapp-ruby.png)](http://travis-ci.org/postageapp/postageapp-ruby)
2
2
 
3
- This gem is used to integrate Ruby apps with [PostageApp](http://postageapp.com/)
3
+ This gem is used to integrate Ruby apps with [PostageApp](https://postageapp.com/)
4
4
  service. Personalized high-volume email sending can be offloaded to PostageApp
5
- via a simple [JSON-based API](http://dev.postageapp.com/api.html).
5
+ via a simple [JSON-based API](https://dev.postageapp.com/api).
6
6
 
7
- ### [API Documentation](http://help.postageapp.com/kb/api/api-overview) • [Knowledge Base](http://help.postageapp.com/kb) • [Help Portal](http://help.postageapp.com/)
7
+ ### [API Documentation](https://dev.postageapp.com/api/)
8
8
 
9
9
  # Installation
10
10
 
11
- ### Rails 4.x
11
+ ## Rails 5.2 and newer
12
12
 
13
13
  Add the `postageapp` gem to your Gemfile:
14
14
 
@@ -17,9 +17,20 @@ Add the `postageapp` gem to your Gemfile:
17
17
  Then from the Rails project's root run:
18
18
 
19
19
  bundle install
20
- bin/rails generate postageapp --api-key PROJECT_API_KEY
21
20
 
22
- ### Rails 3.x
21
+ For authentication, add your project's PostageApp credentials to the
22
+ Rails Encrypted Credentials:
23
+
24
+ rails credentials:edit
25
+
26
+ The format of this entry should be:
27
+
28
+ postageapp:
29
+ api_key: __PROJECT_API_KEY__
30
+
31
+ Where that will be picked up by the plugin when Rails starts.
32
+
33
+ ## Rails 4.x and newer
23
34
 
24
35
  Add the `postageapp` gem to your Gemfile:
25
36
 
@@ -28,25 +39,22 @@ Add the `postageapp` gem to your Gemfile:
28
39
  Then from the Rails project's root run:
29
40
 
30
41
  bundle install
31
- script/rails generate postageapp --api-key PROJECT_API_KEY
32
-
33
- ### Rails 2.x
42
+ bin/rails generate postageapp --api-key PROJECT_API_KEY
34
43
 
35
- In `config/environment.rb` add the following:
44
+ ## Legacy Versions of Rails
36
45
 
37
- config.gem 'postageapp'
46
+ * [Rails 3.x](doc/RAILS3.md)
47
+ * [Rails 2.3.x](doc/RAILS2.md)
38
48
 
39
- Then from the Rails project's root run:
49
+ ## Sinatra / Rack / Others
40
50
 
41
- rake gems:install
42
- rake gems:unpack GEM=postageapp
43
- script/generate postageapp --api-key PROJECT_API_KEY
51
+ Add the `postageapp` gem to your Gemfile:
44
52
 
45
- ### Sinatra / Rack / Others
53
+ gem 'postageapp'
46
54
 
47
- You'll need to install the gem first:
55
+ Then from the project's root run:
48
56
 
49
- $ sudo gem install postageapp
57
+ bundle install
50
58
 
51
59
  The configuration will need to be loaded before executing any API calls:
52
60
 
@@ -63,7 +71,8 @@ with the appropriate API key will also work.
63
71
 
64
72
  # Usage
65
73
 
66
- Here's an example of sending a message ([See full API documentation](http://help.postageapp.com/faqs/api/send_message)):
74
+ Here's an example of sending a message using the
75
+ [`send_message`](https://dev.postageapp.com/api/send_message) API call:
67
76
 
68
77
  ```ruby
69
78
  request = PostageApp::Request.new(
@@ -80,7 +89,7 @@ request = PostageApp::Request.new(
80
89
  },
81
90
  attachments: {
82
91
  'document.pdf' => {
83
- content_type: application/pdf',
92
+ content_type: 'application/pdf',
84
93
  content: Base64.encode64(File.open('/path/to/document.pdf', 'rb').read)
85
94
  }
86
95
  }
@@ -107,7 +116,7 @@ Response usually comes back with data:
107
116
  >> response.data
108
117
  => { 'message' => { 'id' => '12345' }}
109
118
 
110
- ### Recipient Override
119
+ # Recipient Override
111
120
 
112
121
  Sometimes you don't want to send emails to real people in your application. For
113
122
  that there's an ability to override to what address all emails will be
@@ -138,7 +147,7 @@ require 'postageapp/mailer'
138
147
  There are custom methods that allow setting of `template` and `variables` parts
139
148
  of the API call. They are `postageapp_template` and `postageapp_variables`.
140
149
  Examples how they are used are below. For details what they do please see
141
- [documentation](http://help.postageapp.com/faqs)
150
+ [documentation](https://dev.postageapp.com/api/)
142
151
 
143
152
  Please note that `deliver` method will return `PostageApp::Response` object.
144
153
  This way you can immediately check the status of the delivery. For example:
@@ -147,9 +156,9 @@ This way you can immediately check the status of the delivery. For example:
147
156
  response.ok?
148
157
  # => true
149
158
 
150
- ### Rails 3 / 4
159
+ ## Mailer Base Class
151
160
 
152
- Here's an example of a mailer in Rails 3 environment:
161
+ Here's an example of a mailer using the `PostageApp::Mailer` base class:
153
162
 
154
163
  ```ruby
155
164
  require 'postageapp/mailer'
@@ -194,7 +203,8 @@ class Notifier < PostageApp::Mailer
194
203
  def signup_notification
195
204
  from 'sender@example.com'
196
205
  subject 'Test Email'
197
- recipients 'recipient@example.com'
206
+
207
+ mail(to: 'recipient@example.com')
198
208
  end
199
209
  end
200
210
  ```
@@ -217,44 +227,6 @@ class DevelopmentPostageappInterceptor
217
227
  end
218
228
  ```
219
229
 
220
- ### Rails 2
221
-
222
- Here's an example of a mailer you'd set in in a Rails 2 environment:
223
-
224
- ```ruby
225
- require 'postageapp/mailer'
226
-
227
- class Notifier < PostageApp::Mailer
228
- def signup_notification
229
- from 'system@example.com'
230
- subject 'New Account Information'
231
-
232
- # Recipients can be in any format API allows.
233
- # Here's an example of a hash format
234
- recipients(
235
- 'recipient_1@example.com' => {
236
- 'variable_name_1' => 'value',
237
- 'variable_name_2' => 'value'
238
- },
239
- 'recipient_2@example.com' => {
240
- 'variable_name_1' => 'value',
241
- 'variable_name_2' => 'value'
242
- },
243
- )
244
-
245
- attachment(
246
- :content_type => 'application/zip',
247
- :filename => 'example.zip',
248
- :body => File.read('/path/to/example.zip'
249
- )
250
-
251
- # PostageApp specific elements:
252
- postageapp_template 'example_template'
253
- postageapp_variables 'global_variable' => 'value'
254
- end
255
- end
256
- ```
257
-
258
230
  # Automatic resending in case of failure
259
231
 
260
232
  For those rare occasions when the API is not reachable or unresponsive,
@@ -267,11 +239,89 @@ For projects other than Rails you'll need to tell where the `project_root` is:
267
239
 
268
240
  ```ruby
269
241
  PostageApp.configure do |config|
270
- config.api_key = 'PROJECT_API_KEY'
242
+ config.api_key = 'PROJECT_API_KEY'
271
243
  config.project_root = "/path/to/your/project"
272
244
  end
273
245
  ```
274
246
 
275
- # Copyright
276
-
277
- (C) 2011-2016 Scott Tadman, Oleg Khabarov, [PostageApp](http://www.postageapp.com/)
247
+ # Configuration Details
248
+
249
+ Configuration can be done either via Ruby code directly, by environment
250
+ variables, or by a combination of both. Where both are supplied, the
251
+ Ruby setting will take precedence.
252
+
253
+ ## Configuration Arguments
254
+
255
+ These can all be set with `PostageApp.config`:
256
+
257
+ * `api_key`: Project API key to use (required for project API functions)
258
+ * `account_api_key`: Account API key to use (required for account API functions)
259
+ * `postback_secret`: Secret to use for validating ActionMailbox requests (optional)
260
+ * `project_root`: Project root for logging purposes (default: current working directory)
261
+ * `recipient_override`: Override sender on `send_message` calls (optional)
262
+ * `logger`: Logger instance to use (optional)
263
+ * `secure`: Enable verifying TLS connections (default: `true`)
264
+ * `verify_tls`: Enable TLS certificate verification (default: `true`)
265
+ * `verify_certificate`: Alias for `verify_tls`
266
+ * `host`: API host to contact (default: `api.postageapp.com`)
267
+ * `port`: API port to contact (default: `443`)
268
+ * `scheme`: HTTP scheme to use (default: `https`)
269
+ * `protocol`: Alias for `scheme`
270
+ * `proxy_username`: SOCKS5 proxy username (optional)
271
+ * `proxy_user`: Alias for `proxy_username`
272
+ * `proxy_password`: SOCKS5 proxy password (optional)
273
+ * `proxy_pass`: Alias for `proxy_password`
274
+ * `proxy_host`: SOCKS5 proxy host (optional)
275
+ * `proxy_port`: SOCKS5 proxy port (default: `1080`)
276
+ * `open_timeout`: Timeout in seconds when initiating requests (default: `5`)
277
+ * `http_open_timeout`: Alias for `open_timeout`
278
+ * `read_timeout`: Timeout in seconds when awaiting responses (default: `10`)
279
+ * `http_read_timeout`: Alias for `read_timeout`
280
+ * `retry_methods`: Which API calls to retry, comma and/or space separated (default: `send_message`)
281
+ * `requests_to_resend`: Alias for `retry_methods`
282
+ * `framework`: Framework used (default: `Ruby`)
283
+ * `environment`: Environment to use (default: `production`)
284
+
285
+ A typical configuration involves setting the project API key:
286
+
287
+ PostageApp.config do |config|
288
+ config.api_key = 'PROJECT_API_KEY'
289
+ end
290
+
291
+ Where additional settings can be applied as necessary.
292
+
293
+ ## Environment Variables
294
+
295
+ Most configuration parameters can be set via the environment:
296
+
297
+ * `POSTAGEAPP_API_KEY`: Project API key to use (required for project API functions)
298
+ * `POSTAGEAPP_ACCOUNT_API_KEY`: Account API key to use (required for account API functions)
299
+ * `POSTAGEAPP_POSTBACK_SECRET`: Secret to use for validating ActionMailbox requests (optional)
300
+ * `POSTAGEAPP_PROJECT_ROOT`: Project root for logging purposes (default: current working directory)
301
+ * `POSTAGEAPP_RECIPIENT_OVERRIDE`: Override sender on `send_message` calls (optional)
302
+ * `POSTAGEAPP_VERIFY_TLS`: (default: `true`)
303
+ * `POSTAGEAPP_VERIFY_CERTIFICATE`: Alias for `POSTAGEAPP_VERIFY_TLS`
304
+ * `POSTAGEAPP_HOST`: API host to contact (default: `api.postageapp.com`)
305
+ * `POSTAGEAPP_PORT`: API port to contact (default: `443`)
306
+ * `POSTAGEAPP_SCHEME`: HTTP scheme to use (default: `https`)
307
+ * `POSTAGEAPP_PROTOCOL`: Alias for `POSTAGEAPP_SCHEME`
308
+ * `POSTAGEAPP_PROXY_USERNAME`: SOCKS5 proxy username (optional)
309
+ * `POSTAGEAPP_PROXY_USER`: Alias for `POSTAGEAPP_PROXY_USERNAME`
310
+ * `POSTAGEAPP_PROXY_PASSWORD`: SOCKS5 proxy password (optional)
311
+ * `POSTAGEAPP_PROXY_PASS`: Alias for `POSTAGEAPP_PROXY_PASSWORD`
312
+ * `POSTAGEAPP_PROXY_HOST`: SOCKS5 proxy host (optional)
313
+ * `POSTAGEAPP_PROXY_PORT`: SOCKS5 proxy port (default: `1080`)
314
+ * `POSTAGEAPP_OPEN_TIMEOUT`: Timeout in seconds when initiating requests (default: `5`)
315
+ * `POSTAGEAPP_HTTP_OPEN_TIMEOUT`: Alias for `POSTAGEAPP_OPEN_TIMEOUT`
316
+ * `POSTAGEAPP_READ_TIMEOUT`: Timeout in seconds when awaiting responses (default: `10`)
317
+ * `POSTAGEAPP_HTTP_READ_TIMEOUT`: Alias for `POSTAGEAPP_READ_TIMEOUT`
318
+ * `POSTAGEAPP_RETRY_METHODS`: Which API calls to retry, comma and/or space separated (default: `send_message`)
319
+ * `POSTAGEAPP_REQUESTS_TO_RESEND`: Alias for `POSTAGEAPP_RETRY_METHODS`
320
+ * `POSTAGEAPP_FRAMEWORK`: Framework used (default: `Ruby`)
321
+ * `POSTAGEAPP_ENVIRONMENT`: Environment to use (default: `production`)
322
+
323
+ # Copyright and Licensing
324
+
325
+ (C) 2011-2019 Scott Tadman, Oleg Khabarov, [PostageApp](https://postageapp.com/)
326
+
327
+ This is released under the [MIT License](LICENSE.md).
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
- require 'bundler/setup'
1
+ # Avoid contaminating ENV with lots of BUNDLER_ variables
2
+ # require 'bundler/setup'
2
3
 
3
4
  require 'rake/testtask'
4
5
 
@@ -11,17 +12,27 @@ end
11
12
  namespace :travis do
12
13
  desc "Run tests across different environments, simulating Travis"
13
14
  task :test do
14
- require File.expand_path('test/travis_test', File.dirname(__FILE__))
15
+ require_relative './test/travis_test'
15
16
 
16
17
  TravisTest.run!
17
18
  end
18
19
 
19
20
  desc "Report on which versions of Ruby are installed"
20
21
  task :versions do
21
- require File.expand_path('test/travis_test', File.dirname(__FILE__))
22
+ require_relative './test/travis_test'
22
23
 
23
24
  TravisTest.validate_ruby_versions!
24
25
  end
25
26
  end
26
27
 
27
- task :default => :test
28
+ task default: :test
29
+
30
+ namespace :test do
31
+ task :rails do
32
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('./test/gemfiles/Gemfile.rails-6.1.x', __dir__)
33
+
34
+ require 'bundler/setup'
35
+
36
+ p Rails
37
+ end
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.4.0
@@ -0,0 +1,2 @@
1
+ module ActionMailbox::Ingresses::PostageApp
2
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ActionMailbox::Ingresses::PostageApp::InboundEmailsController < ActionMailbox::BaseController
4
+ before_action :hmac_authenticate
5
+
6
+ def create
7
+ ActionMailbox::InboundEmail.create_and_extract_message_id!(message_param)
8
+
9
+ head(:ok)
10
+
11
+ rescue JSON::ParserError => e
12
+ logger.error(e.message)
13
+
14
+ head(:unprocessable_entity)
15
+ end
16
+
17
+ private
18
+ def message_param
19
+ params.require(:inbound_email).require(:message)
20
+ end
21
+
22
+ def hmac_authenticate
23
+ return if (hmac_authenticated?)
24
+
25
+ head(:unauthorized)
26
+ end
27
+
28
+ def hmac_authenticated?
29
+ if (PostageApp.config.postback_secret.present?)
30
+ ActiveSupport::SecurityUtils.secure_compare(
31
+ request.headers["X-PostageApp-Signature"],
32
+ hmac_signature(message_param, PostageApp.config.postback_secret)
33
+ )
34
+ else
35
+ raise ArgumentError, <<~END.squish
36
+ Missing required PostageApp "postback secret" which can be set as
37
+ in the Rails Encypted Credentials, as POSTAGEAPP_API_POSTBACK_SECRET
38
+ in the environment, or via a config/initializer script using the
39
+ PostageApp.config method.
40
+ END
41
+ end
42
+ end
43
+
44
+ private
45
+ def hmac_signature(*content)
46
+ Base64.strict_encode64(
47
+ OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, *content)
48
+ )
49
+ end
50
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ PostageApp::Engine.routes.draw do
2
+ scope "/rails/action_mailbox", module: "action_mailbox/ingresses" do
3
+ post "/postageapp/inbound_emails" => "postage_app/inbound_emails#create",
4
+ as: :rails_postageapp_inbound_emails
5
+ end
6
+ end