# Like the last router, this tries DNS lookups for vhost domains with no
# mailbox directory, and no default forwarding rule set up.
#
# This router will get run if any of
#
#  the message has a message ID already (i.e. it is already in the queue), or
#  the sender_host_address is empty (i.e. the message was accepted locally), or
#  the sender_host_address is allowed to relay, or
#  the message was sent by an authenticated user,
#
# are true, AND none of the following files exist
#
#  /srv/$domain/mailboxes
#  /srv/$domain/config/default_forward
#  /srv/$domain/config/aliases
#
#

vhost_no_local_mail:
  debug_print = "R: vhost_no_local_mail for $local_part@$domain"
  driver = dnslookup
  domains = +vhost_domains
  condition  = ${if and{ \
                 {or { \
                   {!eq{$message_exim_id}{}} \
                   {eq{$sender_host_address}{}} \
                   {match_ip{$sender_host_address}{+relay_from_hosts}} \
                   {!eq{$authenticated_id}{}} \
                 }} \
                 {!exists{VHOST_DIR/$domain/VHOST_MAILBOX_DIR/}} \
                 {!exists{VHOST_DIR/$domain/VHOST_CONFIG_DIR/default_forward}} \
                 {!exists{VHOST_DIR/$domain/VHOST_CONFIG_DIR/aliases}} \
                }}

  # Make sure that we only route domains that have MX records pointing
  # elsewhere, as we normally expect A records to point at this box.
  mx_domains = +vhost_domains
  transport = remote_smtp
  same_domain_copy_routing = yes
  ignore_target_hosts = +private_addresses
  no_more

