diff options
-rw-r--r-- | Gemfile.lock | 18 | ||||
-rw-r--r-- | actionmailbox.gemspec | 1 | ||||
-rw-r--r-- | lib/tasks/ingress.rake | 38 |
3 files changed, 57 insertions, 0 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 2251704810..402a6e8a10 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -66,11 +66,14 @@ PATH remote: . specs: actionmailbox (0.1.0) + http (>= 4.0.0) rails (>= 5.2.0) GEM remote: https://rubygems.org/ specs: + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) aws-eventstream (1.0.1) aws-partitions (1.105.0) aws-sdk-core (3.30.0) @@ -86,9 +89,20 @@ GEM byebug (10.0.2) concurrent-ruby (1.0.5) crass (1.0.4) + domain_name (0.5.20180417) + unf (>= 0.0.5, < 1.0.0) erubi (1.7.1) globalid (0.4.1) activesupport (>= 4.2.0) + http (4.0.0) + addressable (~> 2.3) + http-cookie (~> 1.0) + http-form_data (~> 2.0) + http_parser.rb (~> 0.6.0) + http-cookie (1.0.3) + domain_name (~> 0.5) + http-form_data (2.1.1) + http_parser.rb (0.6.0) i18n (1.1.0) concurrent-ruby (~> 1.0) jmespath (1.4.0) @@ -107,6 +121,7 @@ GEM nio4r (2.3.1) nokogiri (1.8.5) mini_portile2 (~> 2.3.0) + public_suffix (3.0.3) rack (2.0.5) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -128,6 +143,9 @@ GEM thread_safe (0.3.6) tzinfo (1.2.5) thread_safe (~> 0.1) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.5) websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) diff --git a/actionmailbox.gemspec b/actionmailbox.gemspec index e413ac57f6..e3890ab574 100644 --- a/actionmailbox.gemspec +++ b/actionmailbox.gemspec @@ -16,6 +16,7 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 2.5.0" s.add_dependency "rails", ">= 5.2.0" + s.add_dependency "http", ">= 4.0.0" s.add_development_dependency "bundler", "~> 1.15" s.add_development_dependency "sqlite3" diff --git a/lib/tasks/ingress.rake b/lib/tasks/ingress.rake new file mode 100644 index 0000000000..051d7a6c94 --- /dev/null +++ b/lib/tasks/ingress.rake @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +namespace :action_mailbox do + namespace :ingress do + desc "Pipe an inbound email from STDIN to the Postfix ingress at the given URL" + task :postfix do + require "active_support" + require "active_support/core_ext/object/blank" + require "http" + + url, username, password = ENV.values_at("URL", "INGRESS_USERNAME", "INGRESS_PASSWORD") + + if url.blank? || username.blank? || password.blank? + abort "URL, INGRESS_USERNAME, and INGRESS_PASSWORD are required" + end + + begin + response = HTTP.basic_auth(user: username, pass: password) + .timeout(connect: 1, write: 10, read: 10) + .post(url, headers: { "Content-Type" => "message/rfc822", "User-Agent" => "Postfix" }, body: STDIN) + + if response.status.success? + puts "2.0.0 HTTP #{response.status}" + exit 0 + else + puts "4.6.0 HTTP #{response.status}" + exit 1 + end + rescue HTTP::ConnectionError => error + puts "4.4.2 Error connecting to the Postfix ingress: #{error.message}" + exit 1 + rescue HTTP::TimeoutError + puts "4.4.7 Timed out piping to the Postfix ingress" + exit 1 + end + end + end +end |