diff --git a/app/models/ip_pool_rule.rb b/app/models/ip_pool_rule.rb index 5fc20a2..8a85a6b 100644 --- a/app/models/ip_pool_rule.rb +++ b/app/models/ip_pool_rule.rb @@ -68,18 +68,22 @@ class IPPoolRule < ApplicationRecord errors.add :ip_pool_id, "must belong to the organization" end - def self.address_matches?(condition, address) - address = Postal::Helpers.strip_name_from_address(address) - if condition =~ /@/ - parts = address.split("@") - domain = parts.pop - uname = parts.join("@") - uname, = uname.split("+", 2) - condition == "#{uname}@#{domain}" - else - # Match as a domain - condition == address.split("@").last + class << self + + def address_matches?(condition, address) + address = Postal::Helpers.strip_name_from_address(address) + if condition =~ /@/ + parts = address.split("@") + domain = parts.pop + uname = parts.join("@") + uname, = uname.split("+", 2) + condition == "#{uname}@#{domain}" + else + # Match as a domain + condition == address.split("@").last + end end + end end diff --git a/app/models/route.rb b/app/models/route.rb index 9d59f5c..3ef415c 100644 --- a/app/models/route.rb +++ b/app/models/route.rb @@ -219,12 +219,16 @@ class Route < ApplicationRecord errors.add :base, "Additional routes are not permitted unless the primary route is an actual endpoint" end - def self.find_by_name_and_domain(name, domain) - route = Route.includes(:domain).where(name: name, domains: { name: domain }).first - if route.nil? - route = Route.includes(:domain).where(name: "*", domains: { name: domain }).first + class << self + + def find_by_name_and_domain(name, domain) + route = Route.includes(:domain).where(name: name, domains: { name: domain }).first + if route.nil? + route = Route.includes(:domain).where(name: "*", domains: { name: domain }).first + end + route end - route + end end diff --git a/lib/postal/smtp_sender.rb b/lib/postal/smtp_sender.rb index dff04f4..3dfdf2f 100644 --- a/lib/postal/smtp_sender.rb +++ b/lib/postal/smtp_sender.rb @@ -252,39 +252,43 @@ module Postal records.first&.address&.to_s&.downcase end - def self.ssl_context_with_verify - @ssl_context_with_verify ||= begin - c = OpenSSL::SSL::SSLContext.new - c.verify_mode = OpenSSL::SSL::VERIFY_PEER - c.cert_store = OpenSSL::X509::Store.new - c.cert_store.set_default_paths - c + class << self + + def ssl_context_with_verify + @ssl_context_with_verify ||= begin + c = OpenSSL::SSL::SSLContext.new + c.verify_mode = OpenSSL::SSL::VERIFY_PEER + c.cert_store = OpenSSL::X509::Store.new + c.cert_store.set_default_paths + c + end end - end - def self.ssl_context_without_verify - @ssl_context_without_verify ||= begin - c = OpenSSL::SSL::SSLContext.new - c.verify_mode = OpenSSL::SSL::VERIFY_NONE - c + def ssl_context_without_verify + @ssl_context_without_verify ||= begin + c = OpenSSL::SSL::SSLContext.new + c.verify_mode = OpenSSL::SSL::VERIFY_NONE + c + end end - end - def self.default_helo_hostname - Postal.config.dns.helo_hostname || Postal.config.dns.smtp_server_hostname || "localhost" - end + def default_helo_hostname + Postal.config.dns.helo_hostname || Postal.config.dns.smtp_server_hostname || "localhost" + end - def self.relay_hosts - hosts = Postal.config.smtp_relays.map do |relay| - next unless relay.hostname.present? + def relay_hosts + hosts = Postal.config.smtp_relays.map do |relay| + next unless relay.hostname.present? + + { + hostname: relay.hostname, + port: relay.port, + ssl_mode: relay.ssl_mode + } + end.compact + hosts.empty? ? nil : hosts + end - { - hostname: relay.hostname, - port: relay.port, - ssl_mode: relay.ssl_mode - } - end.compact - hosts.empty? ? nil : hosts end end diff --git a/lib/postal/worker.rb b/lib/postal/worker.rb index 2d425a2..c9ef066 100644 --- a/lib/postal/worker.rb +++ b/lib/postal/worker.rb @@ -195,21 +195,25 @@ module Postal self.class.logger end - def self.logger - Postal.logger_for(:worker) - end + class << self - def self.job_channel - @channel ||= Postal::RabbitMQ.create_channel - end + def logger + Postal.logger_for(:worker) + end - def self.job_queue(name) - @job_queues ||= {} - @job_queues[name] ||= job_channel.queue("deliver-jobs-#{name}", durable: true, arguments: { "x-message-ttl" => 60_000 }) - end + def job_channel + @channel ||= Postal::RabbitMQ.create_channel + end + + def job_queue(name) + @job_queues ||= {} + @job_queues[name] ||= job_channel.queue("deliver-jobs-#{name}", durable: true, arguments: { "x-message-ttl" => 60_000 }) + end + + def local_ip?(ip) + !!(ip =~ /\A(127\.|fe80:|::)/) + end - def self.local_ip?(ip) - !!(ip =~ /\A(127\.|fe80:|::)/) end end