# -*- ruby -*-

address_matcher = Milter::Manager::AddressMatcher.new

remote_network = Object.new
remote_network.instance_eval do
  @address_matcher = address_matcher
end

class << remote_network
  def add_local_address(address)
    @address_matcher.add_local_address(address)
  end

  def add_remote_address(address)
    @address_matcher.add_remote_address(address)
  end
end

singleton_class = class << self; self; end
singleton_class.send(:define_method, :remote_network) do
  remote_network
end

define_applicable_condition("Remote Network") do |condition|
  condition.description = "Apply milter only if connected from remote network"

  condition.define_connect_stopper do |context, host, address|
    !address_matcher.remote_address?(address)
  end
end
