actionmailbox 0.1.0 → 6.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/{LICENSE → MIT-LICENSE} +1 -1
  4. data/README.md +2 -267
  5. data/app/controllers/action_mailbox/base_controller.rb +26 -31
  6. data/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb +48 -44
  7. data/app/controllers/action_mailbox/ingresses/mailgun/inbound_emails_controller.rb +88 -84
  8. data/app/controllers/action_mailbox/ingresses/mandrill/inbound_emails_controller.rb +64 -60
  9. data/app/controllers/action_mailbox/ingresses/postmark/inbound_emails_controller.rb +62 -0
  10. data/app/controllers/action_mailbox/ingresses/relay/inbound_emails_controller.rb +65 -0
  11. data/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb +51 -47
  12. data/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rb +27 -20
  13. data/app/controllers/rails/conductor/action_mailbox/reroutes_controller.rb +15 -11
  14. data/app/controllers/rails/conductor/base_controller.rb +12 -8
  15. data/app/jobs/action_mailbox/incineration_job.rb +17 -13
  16. data/app/jobs/action_mailbox/routing_job.rb +10 -6
  17. data/app/models/action_mailbox/inbound_email.rb +43 -37
  18. data/app/models/action_mailbox/inbound_email/incineratable.rb +5 -3
  19. data/app/models/action_mailbox/inbound_email/incineratable/incineration.rb +21 -17
  20. data/app/models/action_mailbox/inbound_email/message_id.rb +22 -20
  21. data/app/models/action_mailbox/inbound_email/routable.rb +7 -5
  22. data/app/views/rails/conductor/action_mailbox/inbound_emails/new.html.erb +5 -0
  23. data/config/routes.rb +2 -1
  24. data/db/migrate/20180917164000_create_action_mailbox_tables.rb +10 -4
  25. data/lib/action_mailbox.rb +2 -1
  26. data/lib/action_mailbox/base.rb +100 -93
  27. data/lib/action_mailbox/callbacks.rb +3 -1
  28. data/lib/action_mailbox/engine.rb +9 -1
  29. data/lib/action_mailbox/gem_version.rb +17 -0
  30. data/lib/action_mailbox/mail_ext.rb +2 -0
  31. data/lib/action_mailbox/mail_ext/address_equality.rb +7 -3
  32. data/lib/action_mailbox/mail_ext/address_wrapping.rb +7 -3
  33. data/lib/action_mailbox/mail_ext/addresses.rb +22 -18
  34. data/lib/action_mailbox/mail_ext/from_source.rb +2 -0
  35. data/lib/action_mailbox/mail_ext/recipients.rb +7 -3
  36. data/lib/action_mailbox/{postfix_relayer.rb → relayer.rb} +18 -10
  37. data/lib/action_mailbox/router.rb +30 -26
  38. data/lib/action_mailbox/router/route.rb +34 -30
  39. data/lib/action_mailbox/routing.rb +3 -1
  40. data/lib/action_mailbox/test_case.rb +4 -0
  41. data/lib/action_mailbox/test_helper.rb +8 -6
  42. data/lib/action_mailbox/version.rb +8 -1
  43. data/lib/rails/generators/installer.rb +10 -0
  44. data/lib/rails/generators/mailbox/USAGE +12 -0
  45. data/lib/rails/generators/mailbox/mailbox_generator.rb +32 -0
  46. data/lib/{templates/mailboxes/application_mailbox.rb → rails/generators/mailbox/templates/application_mailbox.rb.tt} +1 -1
  47. data/lib/rails/generators/mailbox/templates/mailbox.rb.tt +4 -0
  48. data/lib/rails/generators/test_unit/mailbox_generator.rb +20 -0
  49. data/lib/rails/generators/test_unit/templates/mailbox_test.rb.tt +13 -0
  50. data/lib/tasks/ingress.rake +53 -5
  51. data/lib/tasks/install.rake +1 -1
  52. metadata +66 -237
  53. data/.gitignore +0 -2
  54. data/Gemfile +0 -8
  55. data/Gemfile.lock +0 -159
  56. data/Rakefile +0 -27
  57. data/actionmailbox.gemspec +0 -27
  58. data/app/controllers/action_mailbox/ingresses/postfix/inbound_emails_controller.rb +0 -55
  59. data/bin/test +0 -5
  60. data/lib/templates/installer.rb +0 -4
  61. data/test/controllers/ingresses/amazon/inbound_emails_controller_test.rb +0 -20
  62. data/test/controllers/ingresses/mailgun/inbound_emails_controller_test.rb +0 -89
  63. data/test/controllers/ingresses/mandrill/inbound_emails_controller_test.rb +0 -58
  64. data/test/controllers/ingresses/postfix/inbound_emails_controller_test.rb +0 -54
  65. data/test/controllers/ingresses/sendgrid/inbound_emails_controller_test.rb +0 -44
  66. data/test/dummy/.babelrc +0 -18
  67. data/test/dummy/.gitignore +0 -3
  68. data/test/dummy/.postcssrc.yml +0 -3
  69. data/test/dummy/Rakefile +0 -6
  70. data/test/dummy/app/assets/config/manifest.js +0 -3
  71. data/test/dummy/app/assets/images/.keep +0 -0
  72. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  73. data/test/dummy/app/assets/stylesheets/scaffold.css +0 -80
  74. data/test/dummy/app/channels/application_cable/channel.rb +0 -4
  75. data/test/dummy/app/channels/application_cable/connection.rb +0 -4
  76. data/test/dummy/app/controllers/application_controller.rb +0 -2
  77. data/test/dummy/app/controllers/concerns/.keep +0 -0
  78. data/test/dummy/app/helpers/application_helper.rb +0 -2
  79. data/test/dummy/app/javascript/packs/application.js +0 -0
  80. data/test/dummy/app/jobs/application_job.rb +0 -2
  81. data/test/dummy/app/mailboxes/application_mailbox.rb +0 -2
  82. data/test/dummy/app/mailboxes/messages_mailbox.rb +0 -4
  83. data/test/dummy/app/mailers/application_mailer.rb +0 -4
  84. data/test/dummy/app/models/application_record.rb +0 -3
  85. data/test/dummy/app/models/concerns/.keep +0 -0
  86. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  87. data/test/dummy/app/views/layouts/mailer.html.erb +0 -13
  88. data/test/dummy/app/views/layouts/mailer.text.erb +0 -1
  89. data/test/dummy/bin/bundle +0 -3
  90. data/test/dummy/bin/rails +0 -4
  91. data/test/dummy/bin/rake +0 -4
  92. data/test/dummy/bin/setup +0 -36
  93. data/test/dummy/bin/update +0 -31
  94. data/test/dummy/bin/yarn +0 -11
  95. data/test/dummy/config.ru +0 -5
  96. data/test/dummy/config/application.rb +0 -19
  97. data/test/dummy/config/boot.rb +0 -5
  98. data/test/dummy/config/cable.yml +0 -10
  99. data/test/dummy/config/database.yml +0 -25
  100. data/test/dummy/config/environment.rb +0 -5
  101. data/test/dummy/config/environments/development.rb +0 -63
  102. data/test/dummy/config/environments/production.rb +0 -96
  103. data/test/dummy/config/environments/test.rb +0 -46
  104. data/test/dummy/config/initializers/application_controller_renderer.rb +0 -8
  105. data/test/dummy/config/initializers/assets.rb +0 -14
  106. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  107. data/test/dummy/config/initializers/content_security_policy.rb +0 -22
  108. data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
  109. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  110. data/test/dummy/config/initializers/inflections.rb +0 -16
  111. data/test/dummy/config/initializers/mime_types.rb +0 -4
  112. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  113. data/test/dummy/config/locales/en.yml +0 -33
  114. data/test/dummy/config/puma.rb +0 -34
  115. data/test/dummy/config/routes.rb +0 -4
  116. data/test/dummy/config/spring.rb +0 -6
  117. data/test/dummy/config/storage.yml +0 -35
  118. data/test/dummy/config/webpack/development.js +0 -3
  119. data/test/dummy/config/webpack/environment.js +0 -3
  120. data/test/dummy/config/webpack/production.js +0 -3
  121. data/test/dummy/config/webpack/test.js +0 -3
  122. data/test/dummy/config/webpacker.yml +0 -65
  123. data/test/dummy/db/migrate/20180208205311_create_action_mailroom_tables.rb +0 -11
  124. data/test/dummy/db/migrate/20180212164506_create_active_storage_tables.active_storage.rb +0 -26
  125. data/test/dummy/db/schema.rb +0 -43
  126. data/test/dummy/lib/assets/.keep +0 -0
  127. data/test/dummy/log/.keep +0 -0
  128. data/test/dummy/package.json +0 -11
  129. data/test/dummy/public/404.html +0 -67
  130. data/test/dummy/public/422.html +0 -67
  131. data/test/dummy/public/500.html +0 -66
  132. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  133. data/test/dummy/public/apple-touch-icon.png +0 -0
  134. data/test/dummy/public/favicon.ico +0 -0
  135. data/test/dummy/storage/.keep +0 -0
  136. data/test/dummy/yarn.lock +0 -6071
  137. data/test/fixtures/files/welcome.eml +0 -631
  138. data/test/jobs/incineration_job_test.rb +0 -17
  139. data/test/test_helper.rb +0 -54
  140. data/test/unit/inbound_email/incineration_test.rb +0 -45
  141. data/test/unit/inbound_email/message_id_test.rb +0 -13
  142. data/test/unit/inbound_email_test.rb +0 -13
  143. data/test/unit/mail_ext/address_equality_test.rb +0 -9
  144. data/test/unit/mail_ext/address_wrapping_test.rb +0 -11
  145. data/test/unit/mail_ext/recipients_test.rb +0 -33
  146. data/test/unit/mailbox/bouncing_test.rb +0 -29
  147. data/test/unit/mailbox/callbacks_test.rb +0 -75
  148. data/test/unit/mailbox/routing_test.rb +0 -30
  149. data/test/unit/mailbox/state_test.rb +0 -49
  150. data/test/unit/postfix_relayer_test.rb +0 -90
  151. data/test/unit/router_test.rb +0 -137
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class ActionMailbox::IncinerationJobTest < ActiveJob::TestCase
6
- setup { @inbound_email = receive_inbound_email_from_fixture("welcome.eml") }
7
-
8
- test "ignoring a missing inbound email" do
9
- @inbound_email.destroy!
10
-
11
- perform_enqueued_jobs do
12
- assert_nothing_raised do
13
- ActionMailbox::IncinerationJob.perform_later @inbound_email
14
- end
15
- end
16
- end
17
- end
@@ -1,54 +0,0 @@
1
- ENV["RAILS_ENV"] = "test"
2
- ENV["RAILS_INBOUND_EMAIL_PASSWORD"] = "tbsy84uSV1Kt3ZJZELY2TmShPRs91E3yL4tzf96297vBCkDWgL"
3
-
4
- require_relative "../test/dummy/config/environment"
5
- ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
6
- require "rails/test_help"
7
-
8
- require "byebug"
9
- require "webmock/minitest"
10
-
11
- Minitest.backtrace_filter = Minitest::BacktraceFilter.new
12
-
13
- require "rails/test_unit/reporter"
14
- Rails::TestUnitReporter.executable = 'bin/test'
15
-
16
- if ActiveSupport::TestCase.respond_to?(:fixture_path=)
17
- ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
18
- ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
19
- ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
20
- ActiveSupport::TestCase.fixtures :all
21
- end
22
-
23
- require "action_mailbox/test_helper"
24
-
25
- class ActiveSupport::TestCase
26
- include ActionMailbox::TestHelper, ActiveJob::TestHelper
27
- end
28
-
29
- class ActionDispatch::IntegrationTest
30
- private
31
- def credentials
32
- ActionController::HttpAuthentication::Basic.encode_credentials "actionmailbox", ENV["RAILS_INBOUND_EMAIL_PASSWORD"]
33
- end
34
-
35
- def switch_password_to(new_password)
36
- previous_password, ENV["RAILS_INBOUND_EMAIL_PASSWORD"] = ENV["RAILS_INBOUND_EMAIL_PASSWORD"], new_password
37
- yield
38
- ensure
39
- ENV["RAILS_INBOUND_EMAIL_PASSWORD"] = previous_password
40
- end
41
- end
42
-
43
- if ARGV.include?("-v")
44
- ActiveRecord::Base.logger = Logger.new(STDOUT)
45
- ActiveJob::Base.logger = Logger.new(STDOUT)
46
- end
47
-
48
- class BounceMailer < ActionMailer::Base
49
- def bounce(to:)
50
- mail from: "receiver@example.com", to: to, subject: "Your email was not delivered" do |format|
51
- format.html { render plain: "Sorry!" }
52
- end
53
- end
54
- end
@@ -1,45 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- class ActionMailbox::InboundEmail::IncinerationTest < ActiveSupport::TestCase
4
- test "incinerating 30 days after delivery" do
5
- freeze_time
6
-
7
- assert_enqueued_with job: ActionMailbox::IncinerationJob, at: 30.days.from_now do
8
- create_inbound_email_from_fixture("welcome.eml").delivered!
9
- end
10
-
11
- travel 30.days
12
-
13
- assert_difference -> { ActionMailbox::InboundEmail.count }, -1 do
14
- perform_enqueued_jobs only: ActionMailbox::IncinerationJob
15
- end
16
- end
17
-
18
- test "incinerating 30 days after bounce" do
19
- freeze_time
20
-
21
- assert_enqueued_with job: ActionMailbox::IncinerationJob, at: 30.days.from_now do
22
- create_inbound_email_from_fixture("welcome.eml").bounced!
23
- end
24
-
25
- travel 30.days
26
-
27
- assert_difference -> { ActionMailbox::InboundEmail.count }, -1 do
28
- perform_enqueued_jobs only: ActionMailbox::IncinerationJob
29
- end
30
- end
31
-
32
- test "incinerating 30 days after failure" do
33
- freeze_time
34
-
35
- assert_enqueued_with job: ActionMailbox::IncinerationJob, at: 30.days.from_now do
36
- create_inbound_email_from_fixture("welcome.eml").failed!
37
- end
38
-
39
- travel 30.days
40
-
41
- assert_difference -> { ActionMailbox::InboundEmail.count }, -1 do
42
- perform_enqueued_jobs only: ActionMailbox::IncinerationJob
43
- end
44
- end
45
- end
@@ -1,13 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- class ActionMailbox::InboundEmail::MessageIdTest < ActiveSupport::TestCase
4
- test "message id is extracted from raw email" do
5
- inbound_email = create_inbound_email_from_fixture("welcome.eml")
6
- assert_equal "0CB459E0-0336-41DA-BC88-E6E28C697DDB@37signals.com", inbound_email.message_id
7
- end
8
-
9
- test "message id is generated if its missing" do
10
- inbound_email = create_inbound_email_from_source "Date: Fri, 28 Sep 2018 11:08:55 -0700\r\nTo: a@example.com\r\nMime-Version: 1.0\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: 7bit\r\n\r\nHello!"
11
- assert_not_nil inbound_email.message_id
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- module ActionMailbox
4
- class InboundEmailTest < ActiveSupport::TestCase
5
- test "mail provides the parsed source" do
6
- assert_equal "Discussion: Let's debate these attachments", create_inbound_email_from_fixture("welcome.eml").mail.subject
7
- end
8
-
9
- test "source returns the contents of the raw email" do
10
- assert_equal file_fixture("welcome.eml").read, create_inbound_email_from_fixture("welcome.eml").source
11
- end
12
- end
13
- end
@@ -1,9 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- module MailExt
4
- class AddressEqualityTest < ActiveSupport::TestCase
5
- test "two addresses with the same address are equal" do
6
- assert_equal Mail::Address.new("david@basecamp.com"), Mail::Address.new("david@basecamp.com")
7
- end
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- module MailExt
4
- class AddressWrappingTest < ActiveSupport::TestCase
5
- test "wrap" do
6
- needing_wrapping = Mail::Address.wrap("david@basecamp.com")
7
- wrapping_not_needed = Mail::Address.wrap(Mail::Address.new("david@basecamp.com"))
8
- assert_equal needing_wrapping.address, wrapping_not_needed.address
9
- end
10
- end
11
- end
@@ -1,33 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- module MailExt
4
- class RecipientsTest < ActiveSupport::TestCase
5
- setup do
6
- @mail = Mail.new \
7
- to: "david@basecamp.com",
8
- cc: "jason@basecamp.com",
9
- bcc: "andrea@basecamp.com",
10
- x_original_to: "ryan@basecamp.com"
11
- end
12
-
13
- test "recipients include everyone from to, cc, bcc, and x-original-to" do
14
- assert_equal %w[ david@basecamp.com jason@basecamp.com andrea@basecamp.com ryan@basecamp.com ], @mail.recipients
15
- end
16
-
17
- test "recipients addresses use address objects" do
18
- assert_equal "basecamp.com", @mail.recipients_addresses.first.domain
19
- end
20
-
21
- test "to addresses use address objects" do
22
- assert_equal "basecamp.com", @mail.to_addresses.first.domain
23
- end
24
-
25
- test "cc addresses use address objects" do
26
- assert_equal "basecamp.com", @mail.cc_addresses.first.domain
27
- end
28
-
29
- test "bcc addresses use address objects" do
30
- assert_equal "basecamp.com", @mail.bcc_addresses.first.domain
31
- end
32
- end
33
- end
@@ -1,29 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- class BouncingWithReplyMailbox < ActionMailbox::Base
4
- def process
5
- bounce_with BounceMailer.bounce(to: mail.from)
6
- end
7
- end
8
-
9
- class ActionMailbox::Base::BouncingTest < ActiveSupport::TestCase
10
- include ActionMailer::TestHelper
11
-
12
- setup do
13
- @inbound_email = create_inbound_email_from_mail \
14
- from: "sender@example.com", to: "replies@example.com", subject: "Bounce me"
15
- end
16
-
17
- test "bouncing with a reply" do
18
- perform_enqueued_jobs only: ActionMailer::DeliveryJob do
19
- BouncingWithReplyMailbox.receive @inbound_email
20
- end
21
-
22
- assert @inbound_email.bounced?
23
- assert_emails 1
24
-
25
- mail = ActionMailer::Base.deliveries.last
26
- assert_equal %w[ sender@example.com ], mail.to
27
- assert_equal "Your email was not delivered", mail.subject
28
- end
29
- end
@@ -1,75 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- class CallbackMailbox < ActionMailbox::Base
4
- before_processing { $before_processing = "Ran that!" }
5
- after_processing { $after_processing = "Ran that too!" }
6
- around_processing ->(r, block) { block.call; $around_processing = "Ran that as well!" }
7
-
8
- def process
9
- $processed = mail.subject
10
- end
11
- end
12
-
13
- class BouncingCallbackMailbox < ActionMailbox::Base
14
- before_processing { $before_processing = [ "Pre-bounce" ] }
15
-
16
- before_processing do
17
- bounce_with BounceMailer.bounce(to: mail.from)
18
- $before_processing << "Bounce"
19
- end
20
-
21
- before_processing { $before_processing << "Post-bounce" }
22
-
23
- after_processing { $after_processing = true }
24
-
25
- def process
26
- $processed = true
27
- end
28
- end
29
-
30
- class DiscardingCallbackMailbox < ActionMailbox::Base
31
- before_processing { $before_processing = [ "Pre-discard" ] }
32
-
33
- before_processing do
34
- delivered!
35
- $before_processing << "Discard"
36
- end
37
-
38
- before_processing { $before_processing << "Post-discard" }
39
-
40
- after_processing { $after_processing = true }
41
-
42
- def process
43
- $processed = true
44
- end
45
- end
46
-
47
- class ActionMailbox::Base::CallbacksTest < ActiveSupport::TestCase
48
- setup do
49
- $before_processing = $after_processing = $around_processing = $processed = false
50
- @inbound_email = create_inbound_email_from_fixture("welcome.eml")
51
- end
52
-
53
- test "all callback types" do
54
- CallbackMailbox.receive @inbound_email
55
- assert_equal "Ran that!", $before_processing
56
- assert_equal "Ran that too!", $after_processing
57
- assert_equal "Ran that as well!", $around_processing
58
- end
59
-
60
- test "bouncing in a callback terminates processing" do
61
- BouncingCallbackMailbox.receive @inbound_email
62
- assert @inbound_email.bounced?
63
- assert_equal [ "Pre-bounce", "Bounce" ], $before_processing
64
- assert_not $processed
65
- assert_not $after_processing
66
- end
67
-
68
- test "marking the inbound email as delivered in a callback terminates processing" do
69
- DiscardingCallbackMailbox.receive @inbound_email
70
- assert @inbound_email.delivered?
71
- assert_equal [ "Pre-discard", "Discard" ], $before_processing
72
- assert_not $processed
73
- assert_not $after_processing
74
- end
75
- end
@@ -1,30 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- class ApplicationMailbox < ActionMailbox::Base
4
- routing "replies@example.com" => :replies
5
- end
6
-
7
- class RepliesMailbox < ActionMailbox::Base
8
- def process
9
- $processed = mail.subject
10
- end
11
- end
12
-
13
- class ActionMailbox::Base::RoutingTest < ActiveSupport::TestCase
14
- setup do
15
- $processed = false
16
- @inbound_email = create_inbound_email_from_fixture("welcome.eml")
17
- end
18
-
19
- test "string routing" do
20
- ApplicationMailbox.route @inbound_email
21
- assert_equal "Discussion: Let's debate these attachments", $processed
22
- end
23
-
24
- test "delayed routing" do
25
- perform_enqueued_jobs only: ActionMailbox::RoutingJob do
26
- create_inbound_email_from_fixture "welcome.eml", status: :pending
27
- assert_equal "Discussion: Let's debate these attachments", $processed
28
- end
29
- end
30
- end
@@ -1,49 +0,0 @@
1
- require_relative '../../test_helper'
2
-
3
- class SuccessfulMailbox < ActionMailbox::Base
4
- def process
5
- $processed = mail.subject
6
- end
7
- end
8
-
9
- class UnsuccessfulMailbox < ActionMailbox::Base
10
- rescue_from(RuntimeError) { $processed = :failure }
11
-
12
- def process
13
- raise "No way!"
14
- end
15
- end
16
-
17
- class BouncingMailbox < ActionMailbox::Base
18
- def process
19
- $processed = :bounced
20
- bounced!
21
- end
22
- end
23
-
24
-
25
- class ActionMailbox::Base::StateTest < ActiveSupport::TestCase
26
- setup do
27
- $processed = false
28
- @inbound_email = create_inbound_email_from_mail \
29
- to: "replies@example.com", subject: "I was processed"
30
- end
31
-
32
- test "successful mailbox processing leaves inbound email in delivered state" do
33
- SuccessfulMailbox.receive @inbound_email
34
- assert @inbound_email.delivered?
35
- assert_equal "I was processed", $processed
36
- end
37
-
38
- test "unsuccessful mailbox processing leaves inbound email in failed state" do
39
- UnsuccessfulMailbox.receive @inbound_email
40
- assert @inbound_email.failed?
41
- assert_equal :failure, $processed
42
- end
43
-
44
- test "bounced inbound emails are not delivered" do
45
- BouncingMailbox.receive @inbound_email
46
- assert @inbound_email.bounced?
47
- assert_equal :bounced, $processed
48
- end
49
- end
@@ -1,90 +0,0 @@
1
- require_relative '../test_helper'
2
-
3
- require 'action_mailbox/postfix_relayer'
4
-
5
- module ActionMailbox
6
- class PostfixRelayerTest < ActiveSupport::TestCase
7
- URL = "https://example.com/rails/action_mailbox/postfix/inbound_emails"
8
- INGRESS_PASSWORD = "secret"
9
-
10
- setup do
11
- @relayer = ActionMailbox::PostfixRelayer.new(url: URL, password: INGRESS_PASSWORD)
12
- end
13
-
14
- test "successfully relaying an email" do
15
- stub_request(:post, URL).to_return status: 204
16
-
17
- result = @relayer.relay(file_fixture("welcome.eml").read)
18
- assert_equal "2.0.0 Successfully relayed message to Postfix ingress", result.output
19
- assert result.success?
20
- assert_not result.failure?
21
-
22
- assert_requested :post, URL, body: file_fixture("welcome.eml").read,
23
- basic_auth: [ "actionmailbox", INGRESS_PASSWORD ],
24
- headers: { "Content-Type" => "message/rfc822", "User-Agent" => /\AAction Mailbox Postfix relayer v\d+\./ }
25
- end
26
-
27
- test "unsuccessfully relaying with invalid credentials" do
28
- stub_request(:post, URL).to_return status: 401
29
-
30
- result = @relayer.relay(file_fixture("welcome.eml").read)
31
- assert_equal "4.7.0 Invalid credentials for Postfix ingress", result.output
32
- assert_not result.success?
33
- assert result.failure?
34
- end
35
-
36
- test "unsuccessfully relaying due to an unspecified server error" do
37
- stub_request(:post, URL).to_return status: 500
38
-
39
- result = @relayer.relay(file_fixture("welcome.eml").read)
40
- assert_equal "4.0.0 HTTP 500", result.output
41
- assert_not result.success?
42
- assert result.failure?
43
- end
44
-
45
- test "unsuccessfully relaying due to a gateway timeout" do
46
- stub_request(:post, URL).to_return status: 504
47
-
48
- result = @relayer.relay(file_fixture("welcome.eml").read)
49
- assert_equal "4.0.0 HTTP 504", result.output
50
- assert_not result.success?
51
- assert result.failure?
52
- end
53
-
54
- test "unsuccessfully relaying due to ECONNRESET" do
55
- stub_request(:post, URL).to_raise Errno::ECONNRESET.new
56
-
57
- result = @relayer.relay(file_fixture("welcome.eml").read)
58
- assert_equal "4.4.2 Network error relaying to Postfix ingress: Connection reset by peer", result.output
59
- assert_not result.success?
60
- assert result.failure?
61
- end
62
-
63
- test "unsuccessfully relaying due to connection failure" do
64
- stub_request(:post, URL).to_raise SocketError.new("Failed to open TCP connection to example.com:443")
65
-
66
- result = @relayer.relay(file_fixture("welcome.eml").read)
67
- assert_equal "4.4.2 Network error relaying to Postfix ingress: Failed to open TCP connection to example.com:443", result.output
68
- assert_not result.success?
69
- assert result.failure?
70
- end
71
-
72
- test "unsuccessfully relaying due to client-side timeout" do
73
- stub_request(:post, URL).to_timeout
74
-
75
- result = @relayer.relay(file_fixture("welcome.eml").read)
76
- assert_equal "4.4.2 Timed out relaying to Postfix ingress", result.output
77
- assert_not result.success?
78
- assert result.failure?
79
- end
80
-
81
- test "unsuccessfully relaying due to an unhandled exception" do
82
- stub_request(:post, URL).to_raise StandardError.new("Something went wrong")
83
-
84
- result = @relayer.relay(file_fixture("welcome.eml").read)
85
- assert_equal "4.0.0 Error relaying to Postfix ingress: Something went wrong", result.output
86
- assert_not result.success?
87
- assert result.failure?
88
- end
89
- end
90
- end