2018-10-19 16:31:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
namespace :action_mailbox do
|
|
|
|
namespace :ingress do
|
2018-11-25 14:30:05 -05:00
|
|
|
desc "Pipe an inbound email from STDIN to the Postfix ingress (URL and INGRESS_PASSWORD required)"
|
2018-10-19 16:31:53 -04:00
|
|
|
task :postfix do
|
|
|
|
require "active_support"
|
|
|
|
require "active_support/core_ext/object/blank"
|
2018-11-25 19:26:00 -05:00
|
|
|
require "action_mailbox/postfix_relayer"
|
2018-10-19 16:31:53 -04:00
|
|
|
|
2018-11-25 21:35:27 -05:00
|
|
|
url, password = ENV.values_at("URL", "INGRESS_PASSWORD")
|
2018-10-19 16:31:53 -04:00
|
|
|
|
2018-11-08 07:30:37 -05:00
|
|
|
if url.blank? || password.blank?
|
2018-11-25 19:29:46 -05:00
|
|
|
print "4.3.5 URL and INGRESS_PASSWORD are required"
|
2018-11-14 20:47:40 -05:00
|
|
|
exit 1
|
2018-10-19 16:31:53 -04:00
|
|
|
end
|
|
|
|
|
2018-11-25 21:35:27 -05:00
|
|
|
ActionMailbox::PostfixRelayer.new(url: url, password: password).relay(STDIN.read).tap do |result|
|
|
|
|
print result.output
|
|
|
|
exit result.success? ? 0 : 1
|
|
|
|
end
|
2018-10-19 16:31:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|