From dcea1b18dae59a371ef8ac32b4874f3daf748001 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Sun, 25 Nov 2018 21:35:27 -0500 Subject: YAGNI user agent customization --- lib/action_mailbox/postfix_relayer.rb | 15 +++++++++------ lib/tasks/ingress.rake | 11 +++++------ 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/action_mailbox/postfix_relayer.rb b/lib/action_mailbox/postfix_relayer.rb index ee18c8f6ba..268ca5661b 100644 --- a/lib/action_mailbox/postfix_relayer.rb +++ b/lib/action_mailbox/postfix_relayer.rb @@ -15,10 +15,13 @@ module ActionMailbox end end - attr_reader :uri, :username, :password, :user_agent + CONTENT_TYPE = "message/rfc822" + USER_AGENT = "Action Mailbox Postfix relayer" - def initialize(url:, username: "actionmailbox", password:, user_agent: nil) - @uri, @username, @password, @user_agent = URI(url), username, password, user_agent || "Postfix" + attr_reader :uri, :username, :password + + def initialize(url:, username: "actionmailbox", password:) + @uri, @username, @password = URI(url), username, password end def relay(source) @@ -40,9 +43,9 @@ module ActionMailbox private def post(source) - client.post uri.path, source, - "Content-Type" => "message/rfc822", - "User-Agent" => user_agent, + client.post uri, source, + "Content-Type" => CONTENT_TYPE, + "User-Agent" => USER_AGENT, "Authorization" => "Basic #{Base64.strict_encode64(username + ":" + password)}" end diff --git a/lib/tasks/ingress.rake b/lib/tasks/ingress.rake index 3f57b79caa..1253f94f71 100644 --- a/lib/tasks/ingress.rake +++ b/lib/tasks/ingress.rake @@ -8,18 +8,17 @@ namespace :action_mailbox do require "active_support/core_ext/object/blank" require "action_mailbox/postfix_relayer" - url, password, user_agent = ENV.values_at("URL", "INGRESS_PASSWORD", "USER_AGENT") + url, password = ENV.values_at("URL", "INGRESS_PASSWORD") if url.blank? || password.blank? print "4.3.5 URL and INGRESS_PASSWORD are required" exit 1 end - ActionMailbox::PostfixRelayer.new(url: url, password: password, user_agent: user_agent) - .relay(STDIN.read).tap do |result| - print result.output - exit result.success? ? 0 : 1 - end + ActionMailbox::PostfixRelayer.new(url: url, password: password).relay(STDIN.read).tap do |result| + print result.output + exit result.success? ? 0 : 1 + end end end end -- cgit v1.2.3